source
int64 2
2
| difficulty
int64 7
25
| name
stringlengths 9
60
| description
stringlengths 164
7.12k
| public_tests
dict | private_tests
dict | cf_rating
int64 0
3.5k
| cf_points
float64 0
4k
|
---|---|---|---|---|---|---|---|
2 | 11 | 1037_E. Trips | There are n persons who initially don't know each other. On each morning, two of them, who were not friends before, become friends.
We want to plan a trip for every evening of m days. On each trip, you have to select a group of people that will go on the trip. For every person, one of the following should hold:
* Either this person does not go on the trip,
* Or at least k of his friends also go on the trip.
Note that the friendship is not transitive. That is, if a and b are friends and b and c are friends, it does not necessarily imply that a and c are friends.
For each day, find the maximum number of people that can go on the trip on that day.
Input
The first line contains three integers n, m, and k (2 β€ n β€ 2 β
10^5, 1 β€ m β€ 2 β
10^5, 1 β€ k < n) β the number of people, the number of days and the number of friends each person on the trip should have in the group.
The i-th (1 β€ i β€ m) of the next m lines contains two integers x and y (1β€ x, yβ€ n, xβ y), meaning that persons x and y become friends on the morning of day i. It is guaranteed that x and y were not friends before.
Output
Print exactly m lines, where the i-th of them (1β€ iβ€ m) contains the maximum number of people that can go on the trip on the evening of the day i.
Examples
Input
4 4 2
2 3
1 2
1 3
1 4
Output
0
0
3
3
Input
5 8 2
2 1
4 2
5 4
5 2
4 3
5 1
4 1
3 2
Output
0
0
0
3
3
4
4
5
Input
5 7 2
1 5
3 2
2 5
3 4
1 2
5 3
1 3
Output
0
0
0
0
3
4
4
Note
In the first example,
* 1,2,3 can go on day 3 and 4.
In the second example,
* 2,4,5 can go on day 4 and 5.
* 1,2,4,5 can go on day 6 and 7.
* 1,2,3,4,5 can go on day 8.
In the third example,
* 1,2,5 can go on day 5.
* 1,2,3,5 can go on day 6 and 7. | {
"input": [
"4 4 2\n2 3\n1 2\n1 3\n1 4\n",
"5 8 2\n2 1\n4 2\n5 4\n5 2\n4 3\n5 1\n4 1\n3 2\n",
"5 7 2\n1 5\n3 2\n2 5\n3 4\n1 2\n5 3\n1 3\n"
],
"output": [
"0\n0\n3\n3\n",
"0\n0\n0\n3\n3\n4\n4\n5\n",
"0\n0\n0\n0\n3\n4\n4\n"
]
} | {
"input": [
"16 20 2\n10 3\n5 3\n10 5\n12 7\n7 6\n9 12\n9 6\n1 10\n11 16\n11 1\n16 2\n10 2\n14 4\n15 14\n4 13\n13 15\n1 8\n7 15\n1 7\n8 15\n",
"2 1 1\n2 1\n"
],
"output": [
"0\n0\n3\n3\n3\n3\n7\n7\n7\n7\n7\n11\n11\n11\n11\n15\n15\n15\n15\n16\n",
"2\n"
]
} | 2,200 | 2,250 |
2 | 7 | 1060_A. Phone Numbers | Let's call a string a phone number if it has length 11 and fits the pattern "8xxxxxxxxxx", where each "x" is replaced by a digit.
For example, "80123456789" and "80000000000" are phone numbers, while "8012345678" and "79000000000" are not.
You have n cards with digits, and you want to use them to make as many phone numbers as possible. Each card must be used in at most one phone number, and you don't have to use all cards. The phone numbers do not necessarily have to be distinct.
Input
The first line contains an integer n β the number of cards with digits that you have (1 β€ n β€ 100).
The second line contains a string of n digits (characters "0", "1", ..., "9") s_1, s_2, β¦, s_n. The string will not contain any other characters, such as leading or trailing spaces.
Output
If at least one phone number can be made from these cards, output the maximum number of phone numbers that can be made. Otherwise, output 0.
Examples
Input
11
00000000008
Output
1
Input
22
0011223344556677889988
Output
2
Input
11
31415926535
Output
0
Note
In the first example, one phone number, "8000000000", can be made from these cards.
In the second example, you can make two phone numbers from the cards, for example, "80123456789" and "80123456789".
In the third example you can't make any phone number from the given cards. | {
"input": [
"22\n0011223344556677889988\n",
"11\n00000000008\n",
"11\n31415926535\n"
],
"output": [
"2\n",
"1\n",
"0\n"
]
} | {
"input": [
"51\n882889888888689888850888388887688788888888888858888\n",
"55\n7271714707719515303911625619272900050990324951111943573\n",
"72\n888488888888823288848804883838888888887888888888228888218488897809784868\n",
"65\n44542121362830719677175203560438858260878894083124543850593761845\n",
"54\n438283821340622774637957966575424773837418828888614203\n",
"100\n1976473621569903172721407763737179639055561746310369779167351419713916160700096173622427077757986026\n",
"100\n2833898888858387469888804083887280788584887487186899808436848018181838884988432785338497585788803883\n",
"42\n885887846290886288816884858898812858495482\n",
"75\n878909759892888846183608689257806813376950958863798487856148633095072259838\n",
"11\n55814018693\n",
"31\n0868889888343881888987888838808\n",
"21\n888888888888000000000\n",
"62\n18888883884288488882387888486858887882838885288886472818688888\n",
"77\n11111111111111111111111111111111111111111111111111111111111111111111111111111\n",
"30\n888888888888888888888888888888\n",
"64\n8885984815868480968883818886281846682409262501034555933863969284\n",
"44\n15920309219313427633220119270900111650391207\n",
"97\n4088468966684435599488804806521288358953088399738904557539253573051442198885776802972628197705081\n",
"100\n8800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\n",
"50\n88888888888888888888888888888888888888888888888888\n",
"20\n88888888888888888888\n",
"32\n88888888888888888888888888888888\n",
"82\n8889809888888888485881851986857288588888888881988888868888836888887858888888888878\n",
"91\n8828880888888884883888488888888888888881888888888884888888848588888808888888888888888880888\n",
"87\n311753415808202195240425076966761033489788093280714672959929008324554784724650182457298\n",
"85\n6888887655188885918863889822590788834182048952565514598298586848861396753319582883848\n",
"100\n8088888818885808888888848829886788884187188858898888888788988688884828586988888888288078638898728181\n",
"21\n888111111111111111111\n",
"1\n8\n",
"93\n888088898748888038885888818882806848806887888888882087481868888888177809288888889648468888188\n",
"77\n11233392925013001334679215120076714945221576003953746107506364475115045309091\n",
"40\n8888888888888888888888888888888888888888\n",
"33\n888800000000000000000000000000000\n",
"21\n881234567900123456790\n",
"98\n87247250157776241281197787785951754485531639139778166755966603305697265958800376912432893847612736\n",
"90\n888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\n",
"22\n4215079217017196952791\n",
"99\n509170332523502565755650047942914747120102240396245453406790272793996913905060450414255616791704320\n",
"96\n812087553199958040928832802441581868680188987878748641868838838835609806814288472573117388803351\n",
"1\n0\n",
"100\n8888888888828188888888888888888808888888888888888888891888888768888888888288888885886888838888888888\n",
"11\n80000000000\n",
"86\n84065885114540280210185082984888812185222886689129308815942798404861082196041321701260\n",
"92\n86888880558884738878888381088888888895888881888888888368878888888884888768881888888888808888\n",
"76\n7900795570936733366353829649382870728119825830883973668601071678041634916557\n",
"32\n88000000000000000000000000000000\n",
"70\n8888888888888888888888888888888888888888888888888888888888888888888888\n",
"11\n88888888888\n",
"21\n888000000000000000000\n",
"66\n747099435917145962031075767196746707764157706291155762576312312094\n",
"22\n8899999999999999999999\n",
"11\n81234567123\n",
"41\n78888884888874788841882882888088888588888\n",
"10\n8888888888\n",
"100\n2867878187889776883889958480848802884888888878218089281860321588888888987288888884288488988628618888\n",
"66\n157941266854773786962397310504192100434183957442977444078457168272\n",
"44\n30153452341853403190257244993442815171970194\n",
"63\n728385948188688801288285888788852829888898565895847689806684688\n",
"100\n1835563855281170226095294644116563180561156535623048783710060508361834822227075869575873675232708159\n",
"21\n888888555555555555555\n",
"100\n8881888389882878867888888888888888888886388888888870888884878888089888883898887888808688888487888888\n",
"53\n85838985300863473289888099788588319484149888886832906\n",
"60\n888888888888888888888888888888888888888888888888888888888888\n",
"100\n8820286285185244938452488887088871457098945874486988698468788381417332842888928188688887641132194956\n",
"11\n24572366390\n",
"84\n181288888282608548858058871581888853888486785801381108858832882809848798828837386086\n",
"32\n88257478884887437239023185588797\n",
"99\n097167815527663544905782574817314139311067328533970663873718450545467450059059869618211361469505108\n",
"43\n7404899846883344886153727489084158470112581\n",
"100\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008\n",
"8\n12345678\n",
"88\n2694079127792970410465292300936220976260790323517221561516591792566791677970332966660472\n",
"21\n582586788289484878588\n",
"33\n270375004567749549929235905225024\n",
"50\n88000000000000000000000000000000000000000000000000\n",
"33\n429980628264468835720540136177288\n",
"27\n888000000000000000000000000\n",
"10\n8000000000\n",
"74\n70988894874867688968816582886488688881063425288316858438189808828755218508\n",
"22\n6188156585823394680191\n",
"81\n808888883488887888888808888888888888188888888388888888888888868688888488888882888\n",
"57\n888888888888888888888888888888888888888888888888888888888\n",
"100\n6451941807833681891890004306065158148809856572066617888008875119881621810329816763604830895480467878\n",
"83\n88584458884288808888588388818938838468960248387898182887888867888888888886088895788\n",
"11\n81234567090\n",
"21\n880000000000000000000\n",
"94\n8188948828818938226378510887848897889883818858778688882933888883888898198978868888808082461388\n",
"52\n8878588869084488848898838898788838337877898817818888\n",
"61\n8880888836888988888988888887388888888888868898887888818888888\n",
"71\n88888888888888888888888188888805848888788088888883888883187888838888888\n",
"95\n29488352815808808845913584782288724288898869488882098428839370889284838688458247785878848884289\n",
"73\n2185806538483837898808836883483888818818988881880688028788888081888907898\n",
"80\n88888888888888888888888888888888888888888888888888888888888888888888888888888888\n",
"55\n3982037603326093160114589190899881252765957832414122484\n",
"100\n8888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888\n"
],
"output": [
"4\n",
"0\n",
"6\n",
"5\n",
"4\n",
"1\n",
"9\n",
"3\n",
"6\n",
"1\n",
"2\n",
"1\n",
"5\n",
"0\n",
"2\n",
"5\n",
"0\n",
"8\n",
"2\n",
"4\n",
"1\n",
"2\n",
"7\n",
"8\n",
"7\n",
"7\n",
"9\n",
"1\n",
"0\n",
"8\n",
"0\n",
"3\n",
"3\n",
"1\n",
"8\n",
"8\n",
"0\n",
"0\n",
"8\n",
"0\n",
"9\n",
"1\n",
"7\n",
"8\n",
"6\n",
"2\n",
"6\n",
"1\n",
"1\n",
"0\n",
"2\n",
"1\n",
"3\n",
"0\n",
"9\n",
"5\n",
"2\n",
"5\n",
"9\n",
"1\n",
"9\n",
"4\n",
"5\n",
"9\n",
"0\n",
"7\n",
"2\n",
"9\n",
"3\n",
"1\n",
"0\n",
"0\n",
"1\n",
"0\n",
"2\n",
"3\n",
"2\n",
"0\n",
"6\n",
"2\n",
"7\n",
"5\n",
"9\n",
"7\n",
"1\n",
"1\n",
"8\n",
"4\n",
"5\n",
"6\n",
"8\n",
"6\n",
"7\n",
"5\n",
"9\n"
]
} | 800 | 500 |
2 | 7 | 1101_A. Minimum Integer | You are given q queries in the following form:
Given three integers l_i, r_i and d_i, find minimum positive integer x_i such that it is divisible by d_i and it does not belong to the segment [l_i, r_i].
Can you answer all the queries?
Recall that a number x belongs to segment [l, r] if l β€ x β€ r.
Input
The first line contains one integer q (1 β€ q β€ 500) β the number of queries.
Then q lines follow, each containing a query given in the format l_i r_i d_i (1 β€ l_i β€ r_i β€ 10^9, 1 β€ d_i β€ 10^9). l_i, r_i and d_i are integers.
Output
For each query print one integer: the answer to this query.
Example
Input
5
2 4 2
5 10 4
3 10 1
1 2 3
4 6 5
Output
6
4
1
3
10 | {
"input": [
"5\n2 4 2\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n"
],
"output": [
"6\n4\n1\n3\n10\n"
]
} | {
"input": [
"20\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n1 1000000000 2\n",
"1\n78 79 79\n",
"1\n6 6 6\n",
"20\n1 1 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n1 999999999 1\n",
"1\n78 1000 1\n",
"1\n77 10000 1\n",
"20\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n",
"10\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n",
"1\n78 80 1\n",
"20\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n1 1000000000 3\n",
"1\n1 1 123456789\n",
"1\n80 100 1\n",
"5\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n1000000000 1000000000 1\n",
"1\n78 10000 1\n",
"1\n79 80 100\n",
"5\n1 1000000000 1\n1 999999999 1\n1 999999998 1\n1 999999997 1\n1 999999996 1\n",
"5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n",
"30\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n1 999999999 2\n",
"1\n78 89 34\n",
"1\n1 1 1\n",
"1\n1 3 2\n",
"10\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n1 999999998 1\n",
"4\n1 999999999 1\n1 999999998 1\n1 999999997 1\n1 999999996 1\n",
"5\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n",
"2\n1 1 2\n1 1 2\n",
"1\n80 100 80\n",
"25\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n1 1000000000 1\n1 1000000000 1000000000\n2 1000000000 1\n1 999999999 1000000000\n5 6 5\n",
"30\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n",
"16\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n1 1000000000 1\n",
"1\n1 1000000000 6\n",
"1\n5 5 5\n",
"1\n2 5 6\n",
"8\n1 999999998 1\n1 999999997 1\n1 999999996 1\n1 999999995 1\n1 999999994 1\n1 999999993 1\n1 999999992 1\n1 999999991 1\n",
"5\n80 100 10\n5 10 4\n3 10 1\n1 2 3\n4 6 5\n",
"1\n1 1000000000 1017\n",
"1\n1 1000000000 2\n"
],
"output": [
"1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n",
"158\n",
"12\n",
"2\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n",
"1\n",
"1\n",
"1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n",
"1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n",
"1\n",
"1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n1000000002\n",
"123456789\n",
"1\n",
"1\n1\n1\n1\n1\n",
"1\n",
"100\n",
"1000000001\n1000000000\n999999999\n999999998\n999999997\n",
"1000000001\n2000000000\n1\n1000000000\n10\n",
"1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n1000000000\n",
"34\n",
"2\n",
"4\n",
"999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n999999999\n",
"1000000000\n999999999\n999999998\n999999997\n",
"1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n",
"2\n2\n",
"160\n",
"1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n1000000001\n2000000000\n1\n1000000000\n10\n",
"1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n",
"1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n1000000001\n",
"1000000002\n",
"10\n",
"6\n",
"999999999\n999999998\n999999997\n999999996\n999999995\n999999994\n999999993\n999999992\n",
"10\n4\n1\n3\n10\n",
"1000000845\n",
"1000000002\n"
]
} | 1,000 | 0 |
2 | 10 | 1189_D1. Add on a Tree | Note that this is the first problem of the two similar problems. You can hack this problem only if you solve both problems.
You are given a tree with n nodes. In the beginning, 0 is written on all edges. In one operation, you can choose any 2 distinct leaves u, v and any real number x and add x to values written on all edges on the simple path between u and v.
For example, on the picture below you can see the result of applying two operations to the graph: adding 2 on the path from 7 to 6, and then adding -0.5 on the path from 4 to 5.
<image>
Is it true that for any configuration of real numbers written on edges, we can achieve it with a finite number of operations?
Leaf is a node of a tree of degree 1. Simple path is a path that doesn't contain any node twice.
Input
The first line contains a single integer n (2 β€ n β€ 10^5) β the number of nodes.
Each of the next n-1 lines contains two integers u and v (1 β€ u, v β€ n, u β v), meaning that there is an edge between nodes u and v. It is guaranteed that these edges form a tree.
Output
If there is a configuration of real numbers written on edges of the tree that we can't achieve by performing the operations, output "NO".
Otherwise, output "YES".
You can print each letter in any case (upper or lower).
Examples
Input
2
1 2
Output
YES
Input
3
1 2
2 3
Output
NO
Input
5
1 2
1 3
1 4
2 5
Output
NO
Input
6
1 2
1 3
1 4
2 5
2 6
Output
YES
Note
In the first example, we can add any real x to the value written on the only edge (1, 2).
<image>
In the second example, one of configurations that we can't reach is 0 written on (1, 2) and 1 written on (2, 3).
<image>
Below you can see graphs from examples 3, 4:
<image> <image> | {
"input": [
"2\n1 2\n",
"3\n1 2\n2 3\n",
"5\n1 2\n1 3\n1 4\n2 5\n",
"6\n1 2\n1 3\n1 4\n2 5\n2 6\n"
],
"output": [
"YES",
"NO",
"NO",
"YES"
]
} | {
"input": [
"50\n16 4\n17 9\n31 19\n22 10\n8 1\n40 30\n3 31\n20 29\n47 27\n22 25\n32 34\n12 15\n40 32\n10 33\n47 12\n6 24\n46 41\n14 23\n12 35\n31 42\n46 28\n31 20\n46 37\n1 39\n29 49\n37 47\n40 6\n42 36\n47 2\n24 46\n2 13\n8 45\n41 3\n32 17\n4 7\n47 26\n28 8\n41 50\n34 44\n33 21\n25 5\n16 40\n3 14\n8 18\n28 11\n32 22\n2 38\n3 48\n44 43\n",
"10\n8 1\n1 2\n8 9\n8 5\n1 3\n1 10\n1 6\n1 7\n8 4\n",
"5\n5 1\n5 4\n4 3\n1 2\n",
"7\n1 2\n2 3\n1 4\n1 5\n3 6\n3 7\n",
"3\n1 3\n2 3\n",
"60\n26 6\n59 30\n31 12\n31 3\n38 23\n59 29\n53 9\n38 56\n53 54\n29 21\n17 55\n59 38\n26 16\n24 59\n24 25\n17 35\n24 41\n30 15\n31 27\n8 44\n26 5\n26 48\n8 32\n53 17\n3 34\n3 51\n30 28\n47 10\n53 60\n36 42\n24 53\n59 22\n53 40\n26 52\n36 4\n59 8\n29 37\n36 20\n17 47\n53 18\n3 50\n30 2\n17 7\n8 58\n59 1\n31 11\n24 26\n24 43\n53 57\n59 45\n47 13\n26 46\n17 33\n30 31\n26 39\n26 19\n24 36\n8 49\n38 14\n",
"7\n1 2\n2 3\n3 4\n3 5\n1 6\n1 7\n",
"20\n19 16\n19 18\n20 7\n9 4\n6 17\n14 2\n9 15\n2 13\n5 11\n19 12\n12 20\n16 9\n11 8\n19 5\n3 1\n19 14\n5 3\n12 10\n19 6\n",
"7\n1 2\n1 3\n2 4\n2 5\n3 6\n3 7\n",
"10\n9 5\n7 1\n9 10\n7 2\n5 4\n9 6\n2 9\n10 8\n1 3\n",
"4\n2 4\n2 3\n2 1\n",
"4\n1 4\n3 2\n1 3\n",
"3\n1 2\n1 3\n",
"5\n1 2\n1 5\n1 3\n1 4\n",
"20\n14 9\n12 13\n10 15\n2 1\n20 19\n16 6\n16 3\n17 14\n3 5\n2 11\n3 10\n15 8\n14 2\n6 4\n3 20\n5 18\n1 7\n1 16\n4 12\n",
"20\n7 5\n14 13\n17 6\n3 8\n16 12\n18 9\n3 18\n14 1\n17 3\n15 2\n17 4\n9 11\n2 7\n15 17\n3 20\n16 10\n17 14\n2 16\n1 19\n",
"8\n1 2\n2 3\n3 4\n1 7\n1 8\n4 5\n4 6\n",
"5\n5 1\n5 2\n5 3\n5 4\n",
"50\n49 6\n43 7\n1 27\n19 35\n15 37\n16 12\n19 21\n16 28\n49 9\n48 39\n13 1\n2 48\n9 50\n44 3\n41 32\n48 31\n49 33\n6 11\n13 20\n49 22\n13 41\n48 29\n13 46\n15 47\n34 2\n49 13\n48 14\n34 24\n16 36\n13 40\n49 34\n49 17\n43 25\n11 23\n10 15\n19 26\n34 44\n16 42\n19 18\n46 8\n29 38\n1 45\n12 43\n13 16\n46 30\n15 5\n49 10\n11 19\n32 4\n",
"20\n13 1\n18 2\n3 7\n18 5\n20 16\n3 12\n18 9\n3 10\n18 11\n13 6\n3 18\n20 15\n20 17\n3 13\n3 4\n13 14\n3 20\n18 8\n3 19\n",
"10\n8 2\n5 6\n1 8\n2 9\n1 4\n8 10\n10 5\n2 7\n2 3\n"
],
"output": [
"NO",
"YES",
"NO",
"NO",
"NO",
"YES",
"NO",
"NO",
"NO",
"NO",
"YES",
"NO",
"NO",
"YES",
"NO",
"NO",
"NO",
"YES",
"NO",
"YES",
"NO"
]
} | 1,600 | 250 |
2 | 10 | 1208_D. Restore Permutation | An array of integers p_{1},p_{2}, β¦,p_{n} is called a permutation if it contains each number from 1 to n exactly once. For example, the following arrays are permutations: [3,1,2], [1], [1,2,3,4,5] and [4,3,1,2]. The following arrays are not permutations: [2], [1,1], [2,3,4].
There is a hidden permutation of length n.
For each index i, you are given s_{i}, which equals to the sum of all p_{j} such that j < i and p_{j} < p_{i}. In other words, s_i is the sum of elements before the i-th element that are smaller than the i-th element.
Your task is to restore the permutation.
Input
The first line contains a single integer n (1 β€ n β€ 2 β
10^{5}) β the size of the permutation.
The second line contains n integers s_{1}, s_{2}, β¦, s_{n} (0 β€ s_{i} β€ (n(n-1))/(2)).
It is guaranteed that the array s corresponds to a valid permutation of length n.
Output
Print n integers p_{1}, p_{2}, β¦, p_{n} β the elements of the restored permutation. We can show that the answer is always unique.
Examples
Input
3
0 0 0
Output
3 2 1
Input
2
0 1
Output
1 2
Input
5
0 1 1 1 10
Output
1 4 3 2 5
Note
In the first example for each i there is no index j satisfying both conditions, hence s_i are always 0.
In the second example for i = 2 it happens that j = 1 satisfies the conditions, so s_2 = p_1.
In the third example for i = 2, 3, 4 only j = 1 satisfies the conditions, so s_2 = s_3 = s_4 = 1. For i = 5 all j = 1, 2, 3, 4 are possible, so s_5 = p_1 + p_2 + p_3 + p_4 = 10. | {
"input": [
"3\n0 0 0\n",
"5\n0 1 1 1 10\n",
"2\n0 1\n"
],
"output": [
"3 2 1 ",
"1 4 3 2 5 ",
"1 2 "
]
} | {
"input": [
"100\n0 0 57 121 57 0 19 251 19 301 19 160 57 578 664 57 19 50 0 621 91 5 263 34 5 96 713 649 22 22 22 5 108 198 1412 1147 84 1326 1777 0 1780 132 2000 479 1314 525 68 690 1689 1431 1288 54 1514 1593 1037 1655 807 465 1674 1747 1982 423 837 139 1249 1997 1635 1309 661 334 3307 2691 21 3 533 1697 250 3920 0 343 96 242 2359 3877 3877 150 1226 96 358 829 228 2618 27 2854 119 1883 710 0 4248 435\n",
"20\n0 1 7 15 30 15 59 42 1 4 1 36 116 36 16 136 10 36 46 36\n",
"1\n0\n",
"15\n0 0 3 3 13 3 6 34 47 12 20 6 6 21 55\n"
],
"output": [
"94 57 64 90 58 19 53 71 50 67 38 56 45 86 89 42 31 36 5 68 37 10 49 24 7 32 65 59 14 12 11 6 27 34 91 72 21 87 98 3 97 25 100 46 85 48 18 51 88 83 70 13 79 82 62 80 55 43 73 76 81 40 52 22 60 77 69 61 47 35 92 84 9 4 41 66 28 99 2 33 17 26 74 96 95 20 54 15 29 44 23 75 8 78 16 63 39 1 93 30 ",
"1 6 8 15 17 12 18 16 3 4 2 14 20 13 7 19 5 10 11 9 ",
"1 ",
"2 1 15 10 12 3 6 13 14 8 9 5 4 7 11 "
]
} | 1,900 | 2,000 |
2 | 10 | 1227_D1. Optimal Subsequences (Easy Version) | This is the easier version of the problem. In this version 1 β€ n, m β€ 100. You can hack this problem only if you solve and lock both problems.
You are given a sequence of integers a=[a_1,a_2,...,a_n] of length n. Its subsequence is obtained by removing zero or more elements from the sequence a (they do not necessarily go consecutively). For example, for the sequence a=[11,20,11,33,11,20,11]:
* [11,20,11,33,11,20,11], [11,20,11,33,11,20], [11,11,11,11], [20], [33,20] are subsequences (these are just some of the long list);
* [40], [33,33], [33,20,20], [20,20,11,11] are not subsequences.
Suppose that an additional non-negative integer k (1 β€ k β€ n) is given, then the subsequence is called optimal if:
* it has a length of k and the sum of its elements is the maximum possible among all subsequences of length k;
* and among all subsequences of length k that satisfy the previous item, it is lexicographically minimal.
Recall that the sequence b=[b_1, b_2, ..., b_k] is lexicographically smaller than the sequence c=[c_1, c_2, ..., c_k] if the first element (from the left) in which they differ less in the sequence b than in c. Formally: there exists t (1 β€ t β€ k) such that b_1=c_1, b_2=c_2, ..., b_{t-1}=c_{t-1} and at the same time b_t<c_t. For example:
* [10, 20, 20] lexicographically less than [10, 21, 1],
* [7, 99, 99] is lexicographically less than [10, 21, 1],
* [10, 21, 0] is lexicographically less than [10, 21, 1].
You are given a sequence of a=[a_1,a_2,...,a_n] and m requests, each consisting of two numbers k_j and pos_j (1 β€ k β€ n, 1 β€ pos_j β€ k_j). For each query, print the value that is in the index pos_j of the optimal subsequence of the given sequence a for k=k_j.
For example, if n=4, a=[10,20,30,20], k_j=2, then the optimal subsequence is [20,30] β it is the minimum lexicographically among all subsequences of length 2 with the maximum total sum of items. Thus, the answer to the request k_j=2, pos_j=1 is the number 20, and the answer to the request k_j=2, pos_j=2 is the number 30.
Input
The first line contains an integer n (1 β€ n β€ 100) β the length of the sequence a.
The second line contains elements of the sequence a: integer numbers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9).
The third line contains an integer m (1 β€ m β€ 100) β the number of requests.
The following m lines contain pairs of integers k_j and pos_j (1 β€ k β€ n, 1 β€ pos_j β€ k_j) β the requests.
Output
Print m integers r_1, r_2, ..., r_m (1 β€ r_j β€ 10^9) one per line: answers to the requests in the order they appear in the input. The value of r_j should be equal to the value contained in the position pos_j of the optimal subsequence for k=k_j.
Examples
Input
3
10 20 10
6
1 1
2 1
2 2
3 1
3 2
3 3
Output
20
10
20
10
20
10
Input
7
1 2 1 3 1 2 1
9
2 1
2 2
3 1
3 2
3 3
1 1
7 1
7 7
7 4
Output
2
3
2
3
2
3
1
1
3
Note
In the first example, for a=[10,20,10] the optimal subsequences are:
* for k=1: [20],
* for k=2: [10,20],
* for k=3: [10,20,10]. | {
"input": [
"3\n10 20 10\n6\n1 1\n2 1\n2 2\n3 1\n3 2\n3 3\n",
"7\n1 2 1 3 1 2 1\n9\n2 1\n2 2\n3 1\n3 2\n3 3\n1 1\n7 1\n7 7\n7 4\n"
],
"output": [
"20\n10\n20\n10\n20\n10\n",
"2\n3\n2\n3\n2\n3\n1\n1\n3\n"
]
} | {
"input": [
"2\n1 10\n3\n2 2\n2 1\n1 1\n",
"2\n3922 3922\n3\n2 2\n2 1\n1 1\n",
"1\n1000000000\n1\n1 1\n",
"1\n1\n3\n1 1\n1 1\n1 1\n",
"5\n3 1 4 1 2\n15\n5 5\n5 4\n5 3\n5 2\n5 1\n4 4\n4 3\n4 2\n4 1\n3 3\n3 2\n3 1\n2 2\n2 1\n1 1\n",
"2\n392222 322\n3\n2 2\n2 1\n1 1\n"
],
"output": [
"10\n1\n10\n",
"3922\n3922\n3922\n",
"1000000000\n",
"1\n1\n1\n",
"2\n1\n4\n1\n3\n2\n4\n1\n3\n2\n4\n3\n4\n3\n4\n",
"322\n392222\n392222\n"
]
} | 1,600 | 500 |
2 | 11 | 1269_E. K Integers | You are given a permutation p_1, p_2, β¦, p_n.
In one move you can swap two adjacent values.
You want to perform a minimum number of moves, such that in the end there will exist a subsegment 1,2,β¦, k, in other words in the end there should be an integer i, 1 β€ i β€ n-k+1 such that p_i = 1, p_{i+1} = 2, β¦, p_{i+k-1}=k.
Let f(k) be the minimum number of moves that you need to make a subsegment with values 1,2,β¦,k appear in the permutation.
You need to find f(1), f(2), β¦, f(n).
Input
The first line of input contains one integer n (1 β€ n β€ 200 000): the number of elements in the permutation.
The next line of input contains n integers p_1, p_2, β¦, p_n: given permutation (1 β€ p_i β€ n).
Output
Print n integers, the minimum number of moves that you need to make a subsegment with values 1,2,β¦,k appear in the permutation, for k=1, 2, β¦, n.
Examples
Input
5
5 4 3 2 1
Output
0 1 3 6 10
Input
3
1 2 3
Output
0 0 0 | {
"input": [
"3\n1 2 3\n",
"5\n5 4 3 2 1\n"
],
"output": [
"0 0 0\n",
"0 1 3 6 10\n"
]
} | {
"input": [
"1\n1\n",
"100\n98 52 63 2 18 96 31 58 84 40 41 45 66 100 46 71 26 48 81 20 73 91 68 76 13 93 17 29 64 95 79 21 55 75 19 85 54 51 89 78 15 87 43 59 36 1 90 35 65 56 62 28 86 5 82 49 3 99 33 9 92 32 74 69 27 22 77 16 44 94 34 6 57 70 23 12 61 25 8 11 67 47 83 88 10 14 30 7 97 60 42 37 24 38 53 50 4 80 72 39\n",
"10\n5 1 6 2 8 3 4 10 9 7\n"
],
"output": [
"0\n",
"0 42 52 101 101 117 146 166 166 188 194 197 249 258 294 298 345 415 445 492 522 529 540 562 569 628 628 644 684 699 765 766 768 774 791 812 828 844 863 931 996 1011 1036 1040 1105 1166 1175 1232 1237 1251 1282 1364 1377 1409 1445 1455 1461 1534 1553 1565 1572 1581 1664 1706 1715 1779 1787 1837 1841 1847 1909 1919 1973 1976 2010 2060 2063 2087 2125 2133 2192 2193 2196 2276 2305 2305 2324 2327 2352 2361 2417 2418 2467 2468 2510 2598 2599 2697 2697 2770\n",
"0 1 2 3 8 9 12 12 13 13\n"
]
} | 2,300 | 1,500 |
2 | 11 | 1291_E. Prefix Enlightenment | There are n lamps on a line, numbered from 1 to n. Each one has an initial state off (0) or on (1).
You're given k subsets A_1, β¦, A_k of \{1, 2, ..., n\}, such that the intersection of any three subsets is empty. In other words, for all 1 β€ i_1 < i_2 < i_3 β€ k, A_{i_1} β© A_{i_2} β© A_{i_3} = β
.
In one operation, you can choose one of these k subsets and switch the state of all lamps in it. It is guaranteed that, with the given subsets, it's possible to make all lamps be simultaneously on using this type of operation.
Let m_i be the minimum number of operations you have to do in order to make the i first lamps be simultaneously on. Note that there is no condition upon the state of other lamps (between i+1 and n), they can be either off or on.
You have to compute m_i for all 1 β€ i β€ n.
Input
The first line contains two integers n and k (1 β€ n, k β€ 3 β
10^5).
The second line contains a binary string of length n, representing the initial state of each lamp (the lamp i is off if s_i = 0, on if s_i = 1).
The description of each one of the k subsets follows, in the following format:
The first line of the description contains a single integer c (1 β€ c β€ n) β the number of elements in the subset.
The second line of the description contains c distinct integers x_1, β¦, x_c (1 β€ x_i β€ n) β the elements of the subset.
It is guaranteed that:
* The intersection of any three subsets is empty;
* It's possible to make all lamps be simultaneously on using some operations.
Output
You must output n lines. The i-th line should contain a single integer m_i β the minimum number of operations required to make the lamps 1 to i be simultaneously on.
Examples
Input
7 3
0011100
3
1 4 6
3
3 4 7
2
2 3
Output
1
2
3
3
3
3
3
Input
8 6
00110011
3
1 3 8
5
1 2 5 6 7
2
6 8
2
3 5
2
4 7
1
2
Output
1
1
1
1
1
1
4
4
Input
5 3
00011
3
1 2 3
1
4
3
3 4 5
Output
1
1
1
1
1
Input
19 5
1001001001100000110
2
2 3
2
5 6
2
8 9
5
12 13 14 15 16
1
19
Output
0
1
1
1
2
2
2
3
3
3
3
4
4
4
4
4
4
4
5
Note
In the first example:
* For i = 1, we can just apply one operation on A_1, the final states will be 1010110;
* For i = 2, we can apply operations on A_1 and A_3, the final states will be 1100110;
* For i β₯ 3, we can apply operations on A_1, A_2 and A_3, the final states will be 1111111.
In the second example:
* For i β€ 6, we can just apply one operation on A_2, the final states will be 11111101;
* For i β₯ 7, we can apply operations on A_1, A_3, A_4, A_6, the final states will be 11111111. | {
"input": [
"5 3\n00011\n3\n1 2 3\n1\n4\n3\n3 4 5\n",
"8 6\n00110011\n3\n1 3 8\n5\n1 2 5 6 7\n2\n6 8\n2\n3 5\n2\n4 7\n1\n2\n",
"19 5\n1001001001100000110\n2\n2 3\n2\n5 6\n2\n8 9\n5\n12 13 14 15 16\n1\n19\n",
"7 3\n0011100\n3\n1 4 6\n3\n3 4 7\n2\n2 3\n"
],
"output": [
"1\n1\n1\n1\n1\n",
"1\n1\n1\n1\n1\n1\n4\n4\n",
"0\n1\n1\n1\n2\n2\n2\n3\n3\n3\n3\n4\n4\n4\n4\n4\n4\n4\n5\n",
"1\n2\n3\n3\n3\n3\n3\n"
]
} | {
"input": [
"1 1\n1\n1\n1\n"
],
"output": [
"0\n"
]
} | 2,400 | 1,750 |
2 | 10 | 1334_D. Minimum Euler Cycle | You are given a complete directed graph K_n with n vertices: each pair of vertices u β v in K_n have both directed edges (u, v) and (v, u); there are no self-loops.
You should find such a cycle in K_n that visits every directed edge exactly once (allowing for revisiting vertices).
We can write such cycle as a list of n(n - 1) + 1 vertices v_1, v_2, v_3, ..., v_{n(n - 1) - 1}, v_{n(n - 1)}, v_{n(n - 1) + 1} = v_1 β a visiting order, where each (v_i, v_{i + 1}) occurs exactly once.
Find the lexicographically smallest such cycle. It's not hard to prove that the cycle always exists.
Since the answer can be too large print its [l, r] segment, in other words, v_l, v_{l + 1}, ..., v_r.
Input
The first line contains the single integer T (1 β€ T β€ 100) β the number of test cases.
Next T lines contain test cases β one per line. The first and only line of each test case contains three integers n, l and r (2 β€ n β€ 10^5, 1 β€ l β€ r β€ n(n - 1) + 1, r - l + 1 β€ 10^5) β the number of vertices in K_n, and segment of the cycle to print.
It's guaranteed that the total sum of n doesn't exceed 10^5 and the total sum of r - l + 1 doesn't exceed 10^5.
Output
For each test case print the segment v_l, v_{l + 1}, ..., v_r of the lexicographically smallest cycle that visits every edge exactly once.
Example
Input
3
2 1 3
3 3 6
99995 9998900031 9998900031
Output
1 2 1
1 3 2 3
1
Note
In the second test case, the lexicographically minimum cycle looks like: 1, 2, 1, 3, 2, 3, 1.
In the third test case, it's quite obvious that the cycle should start and end in vertex 1. | {
"input": [
"3\n2 1 3\n3 3 6\n99995 9998900031 9998900031\n"
],
"output": [
"1 2 1 \n1 3 2 3 \n1 \n"
]
} | {
"input": [
"1\n2 2 3\n",
"1\n4 13 13\n",
"1\n3 1 1\n",
"10\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n2 1 3\n",
"1\n3 7 7\n",
"1\n25 30 295\n",
"1\n4 12 13\n",
"5\n3 7 7\n4 13 13\n5 21 21\n6 31 31\n7 42 43\n",
"1\n5 4 4\n"
],
"output": [
"2 1 \n",
"1 \n",
"1 \n",
"1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n1 2 1 \n",
"1 \n",
"16 1 17 1 18 1 19 1 20 1 21 1 22 1 23 1 24 1 25 2 3 2 4 2 5 2 6 2 7 2 8 2 9 2 10 2 11 2 12 2 13 2 14 2 15 2 16 2 17 2 18 2 19 2 20 2 21 2 22 2 23 2 24 2 25 3 4 3 5 3 6 3 7 3 8 3 9 3 10 3 11 3 12 3 13 3 14 3 15 3 16 3 17 3 18 3 19 3 20 3 21 3 22 3 23 3 24 3 25 4 5 4 6 4 7 4 8 4 9 4 10 4 11 4 12 4 13 4 14 4 15 4 16 4 17 4 18 4 19 4 20 4 21 4 22 4 23 4 24 4 25 5 6 5 7 5 8 5 9 5 10 5 11 5 12 5 13 5 14 5 15 5 16 5 17 5 18 5 19 5 20 5 21 5 22 5 23 5 24 5 25 6 7 6 8 6 9 6 10 6 11 6 12 6 13 6 14 6 15 6 16 6 17 6 18 6 19 6 20 6 21 6 22 6 23 6 24 6 25 7 8 7 9 7 10 7 11 7 12 7 13 7 14 7 15 7 16 7 17 7 18 7 19 7 20 7 21 7 22 7 23 7 24 7 25 8 \n",
"4 1 \n",
"1 \n1 \n1 \n1 \n7 1 \n",
"3 \n"
]
} | 1,800 | 0 |
2 | 12 | 1354_F. Summoning Minions | Polycarp plays a computer game. In this game, the players summon armies of magical minions, which then fight each other.
Polycarp can summon n different minions. The initial power level of the i-th minion is a_i, and when it is summoned, all previously summoned minions' power levels are increased by b_i. The minions can be summoned in any order.
Unfortunately, Polycarp cannot have more than k minions under his control. To get rid of unwanted minions after summoning them, he may destroy them. Each minion can be summoned (and destroyed) only once.
Polycarp's goal is to summon the strongest possible army. Formally, he wants to maximize the sum of power levels of all minions under his control (those which are summoned and not destroyed).
Help Polycarp to make up a plan of actions to summon the strongest possible army!
Input
The first line contains one integer T (1 β€ T β€ 75) β the number of test cases.
Each test case begins with a line containing two integers n and k (1 β€ k β€ n β€ 75) β the number of minions availible for summoning, and the maximum number of minions that can be controlled by Polycarp, respectively.
Then n lines follow, the i-th line contains 2 integers a_i and b_i (1 β€ a_i β€ 10^5, 0 β€ b_i β€ 10^5) β the parameters of the i-th minion.
Output
For each test case print the optimal sequence of actions as follows:
Firstly, print m β the number of actions which Polycarp has to perform (0 β€ m β€ 2n). Then print m integers o_1, o_2, ..., o_m, where o_i denotes the i-th action as follows: if the i-th action is to summon the minion x, then o_i = x, and if the i-th action is to destroy the minion x, then o_i = -x. Each minion can be summoned at most once and cannot be destroyed before being summoned (and, obviously, cannot be destroyed more than once). The number of minions in Polycarp's army should be not greater than k after every action.
If there are multiple optimal sequences, print any of them.
Example
Input
3
5 2
5 3
7 0
5 0
4 0
10 0
2 1
10 100
50 10
5 5
1 5
2 4
3 3
4 2
5 1
Output
4
2 1 -1 5
1
2
5
5 4 3 2 1
Note
Consider the example test.
In the first test case, Polycarp can summon the minion 2 with power level 7, then summon the minion 1, which will increase the power level of the previous minion by 3, then destroy the minion 1, and finally, summon the minion 5. After this, Polycarp will have two minions with power levels of 10.
In the second test case, Polycarp can control only one minion, so he should choose the strongest of them and summon it.
In the third test case, Polycarp is able to summon and control all five minions. | {
"input": [
"3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n"
],
"output": [
"8\n2 3 -3 4 -4 1 -1 5\n3\n1 -1 2\n5\n5 4 3 2 1\n"
]
} | {
"input": [
"3\n5 2\n5 3\n7 0\n5 0\n4 0\n10 0\n2 1\n10 100\n50 10\n5 5\n1 5\n2 4\n3 3\n4 2\n5 1\n"
],
"output": [
"8\n2 3 -3 4 -4 1 -1 5\n3\n1 -1 2\n5\n5 4 3 2 1\n"
]
} | 2,500 | 0 |
2 | 11 | 1374_E1. Reading Books (easy version) | Easy and hard versions are actually different problems, so read statements of both problems completely and carefully.
Summer vacation has started so Alice and Bob want to play and joy, but... Their mom doesn't think so. She says that they have to read some amount of books before all entertainments. Alice and Bob will read each book together to end this exercise faster.
There are n books in the family library. The i-th book is described by three integers: t_i β the amount of time Alice and Bob need to spend to read it, a_i (equals 1 if Alice likes the i-th book and 0 if not), and b_i (equals 1 if Bob likes the i-th book and 0 if not).
So they need to choose some books from the given n books in such a way that:
* Alice likes at least k books from the chosen set and Bob likes at least k books from the chosen set;
* the total reading time of these books is minimized (they are children and want to play and joy as soon a possible).
The set they choose is the same for both Alice an Bob (it's shared between them) and they read all books together, so the total reading time is the sum of t_i over all books that are in the chosen set.
Your task is to help them and find any suitable set of books or determine that it is impossible to find such a set.
Input
The first line of the input contains two integers n and k (1 β€ k β€ n β€ 2 β
10^5).
The next n lines contain descriptions of books, one description per line: the i-th line contains three integers t_i, a_i and b_i (1 β€ t_i β€ 10^4, 0 β€ a_i, b_i β€ 1), where:
* t_i β the amount of time required for reading the i-th book;
* a_i equals 1 if Alice likes the i-th book and 0 otherwise;
* b_i equals 1 if Bob likes the i-th book and 0 otherwise.
Output
If there is no solution, print only one integer -1. Otherwise print one integer T β the minimum total reading time of the suitable set of books.
Examples
Input
8 4
7 1 1
2 1 1
4 0 1
8 1 1
1 0 1
1 1 1
1 0 1
3 0 0
Output
18
Input
5 2
6 0 0
9 0 0
1 0 1
2 1 1
5 1 0
Output
8
Input
5 3
3 0 0
2 1 0
3 1 0
5 0 1
3 0 1
Output
-1 | {
"input": [
"8 4\n7 1 1\n2 1 1\n4 0 1\n8 1 1\n1 0 1\n1 1 1\n1 0 1\n3 0 0\n",
"5 2\n6 0 0\n9 0 0\n1 0 1\n2 1 1\n5 1 0\n",
"5 3\n3 0 0\n2 1 0\n3 1 0\n5 0 1\n3 0 1\n"
],
"output": [
"18\n",
"8\n",
"-1\n"
]
} | {
"input": [
"2 1\n7 1 1\n2 1 1\n",
"5 1\n2 1 0\n2 0 1\n1 0 1\n1 1 0\n1 0 1\n",
"6 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n",
"3 1\n3 0 1\n3 1 0\n3 0 0\n",
"6 3\n7 1 1\n8 0 0\n9 1 1\n6 1 0\n10 1 1\n5 0 0\n",
"8 4 3\n1 1 1\n3 1 1\n12 1 1\n12 1 1\n4 0 0\n4 0 0\n5 1 0\n5 0 1\n",
"6 3 1\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n",
"3 3 1\n27 0 0\n28 0 0\n11 0 0\n",
"1 1 1\n3 0 1\n",
"8 5 1\n43 0 1\n5 0 1\n23 1 1\n55 0 1\n19 1 1\n73 1 1\n16 1 1\n42 1 1\n",
"6 3 2\n6 0 0\n11 1 0\n9 0 1\n21 1 1\n10 1 0\n8 0 1\n",
"9 2 2\n74 0 0\n78 1 0\n21 1 0\n47 1 0\n20 0 0\n22 0 1\n52 0 0\n78 0 0\n90 0 0\n",
"3 2 1\n3 0 1\n3 1 0\n3 0 0\n",
"27 5 1\n232 0 1\n72 0 1\n235 0 1\n2 0 1\n158 0 0\n267 0 0\n242 0 1\n1 0 0\n64 0 0\n139 1 1\n250 0 1\n208 0 1\n127 0 1\n29 0 1\n53 0 1\n100 0 1\n52 0 1\n229 0 0\n1 0 1\n29 0 0\n17 0 1\n74 0 1\n211 0 1\n248 0 1\n15 0 0\n252 0 0\n159 0 1\n",
"6 4 3\n19 0 0\n6 1 1\n57 1 0\n21 0 1\n53 1 1\n9 1 1\n"
],
"output": [
"2\n",
"2\n",
"38\n",
"6\n",
"26\n",
"-1",
"-1",
"-1\n",
"-1\n",
"-1",
"-1",
"-1\n",
"-1\n",
"-1\n",
"-1"
]
} | 1,600 | 0 |
2 | 7 | 1398_A. Bad Triangle | You are given an array a_1, a_2, ... , a_n, which is sorted in non-decreasing order (a_i β€ a_{i + 1}).
Find three indices i, j, k such that 1 β€ i < j < k β€ n and it is impossible to construct a non-degenerate triangle (a triangle with nonzero area) having sides equal to a_i, a_j and a_k (for example it is possible to construct a non-degenerate triangle with sides 3, 4 and 5 but impossible with sides 3, 4 and 7). If it is impossible to find such triple, report it.
Input
The first line contains one integer t (1 β€ t β€ 1000) β the number of test cases.
The first line of each test case contains one integer n (3 β€ n β€ 5 β
10^4) β the length of the array a.
The second line of each test case contains n integers a_1, a_2, ... , a_n (1 β€ a_i β€ 10^9; a_{i - 1} β€ a_i) β the array a.
It is guaranteed that the sum of n over all test cases does not exceed 10^5.
Output
For each test case print the answer to it in one line.
If there is a triple of indices i, j, k (i < j < k) such that it is impossible to construct a non-degenerate triangle having sides equal to a_i, a_j and a_k, print that three indices in ascending order. If there are multiple answers, print any of them.
Otherwise, print -1.
Example
Input
3
7
4 6 11 11 15 18 20
4
10 10 10 11
3
1 1 1000000000
Output
2 3 6
-1
1 2 3
Note
In the first test case it is impossible with sides 6, 11 and 18. Note, that this is not the only correct answer.
In the second test case you always can construct a non-degenerate triangle. | {
"input": [
"3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n"
],
"output": [
"1 2 7\n-1\n1 2 3\n"
]
} | {
"input": [
"3\n7\n4 6 11 11 15 18 20\n4\n10 10 10 11\n3\n1 1 1000000000\n",
"1\n6\n1 1 1 2 2 3\n",
"1\n3\n21 78868 80000\n",
"1\n14\n1 2 2 2 2 2 2 2 2 2 2 2 2 4\n",
"1\n3\n78788 78788 157577\n",
"1\n3\n5623 5624 10000000\n",
"1\n10\n1 7 7 7 7 9 9 9 9 9\n",
"1\n3\n5739271 5739272 20000000\n",
"1\n3\n1 65535 10000000\n",
"1\n3\n78788 78788 100000\n",
"1\n15\n3 4 7 8 9 10 11 12 13 14 15 16 32 36 39\n"
],
"output": [
"1 2 7\n-1\n1 2 3\n",
"1 2 6\n",
"1 2 3\n",
"1 2 14\n",
"1 2 3\n",
"1 2 3\n",
"1 2 10\n",
"1 2 3\n",
"1 2 3\n",
"-1\n",
"1 2 15\n"
]
} | 800 | 0 |
2 | 8 | 1421_B. Putting Bricks in the Wall | Pink Floyd are pulling a prank on Roger Waters. They know he doesn't like [walls](https://www.youtube.com/watch?v=YR5ApYxkU-U), he wants to be able to walk freely, so they are blocking him from exiting his room which can be seen as a grid.
Roger Waters has a square grid of size nΓ n and he wants to traverse his grid from the upper left (1,1) corner to the lower right corner (n,n). Waters can move from a square to any other square adjacent by a side, as long as he is still in the grid. Also except for the cells (1,1) and (n,n) every cell has a value 0 or 1 in it.
Before starting his traversal he will pick either a 0 or a 1 and will be able to only go to cells values in which are equal to the digit he chose. The starting and finishing cells (1,1) and (n,n) are exempt from this rule, he may go through them regardless of picked digit. Because of this the cell (1,1) takes value the letter 'S' and the cell (n,n) takes value the letter 'F'.
For example, in the first example test case, he can go from (1, 1) to (n, n) by using the zeroes on this path: (1, 1), (2, 1), (2, 2), (2, 3), (3, 3), (3, 4), (4, 4)
The rest of the band (Pink Floyd) wants Waters to not be able to do his traversal, so while he is not looking they will invert at most two cells in the grid (from 0 to 1 or vice versa). They are afraid they will not be quick enough and asked for your help in choosing the cells. Note that you cannot invert cells (1, 1) and (n, n).
We can show that there always exists a solution for the given constraints.
Also note that Waters will pick his digit of the traversal after the band has changed his grid, so he must not be able to reach (n,n) no matter what digit he picks.
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 50). Description of the test cases follows.
The first line of each test case contains one integers n (3 β€ n β€ 200).
The following n lines of each test case contain the binary grid, square (1, 1) being colored in 'S' and square (n, n) being colored in 'F'.
The sum of values of n doesn't exceed 200.
Output
For each test case output on the first line an integer c (0 β€ c β€ 2) β the number of inverted cells.
In i-th of the following c lines, print the coordinates of the i-th cell you inverted. You may not invert the same cell twice. Note that you cannot invert cells (1, 1) and (n, n).
Example
Input
3
4
S010
0001
1000
111F
3
S10
101
01F
5
S0101
00000
01111
11111
0001F
Output
1
3 4
2
1 2
2 1
0
Note
For the first test case, after inverting the cell, we get the following grid:
S010
0001
1001
111F
| {
"input": [
"3\n4\nS010\n0001\n1000\n111F\n3\nS10\n101\n01F\n5\nS0101\n00000\n01111\n11111\n0001F\n"
],
"output": [
"1\n3 4\n2\n1 2\n2 1\n0\n"
]
} | {
"input": [
"1\n3\nS01\n111\n00F\n",
"1\n5\nS0000\n00000\n00000\n00000\n0000F\n",
"1\n3\nS10\n010\n11F\n",
"1\n3\nS11\n011\n01F\n",
"1\n3\nS10\n010\n01F\n",
"1\n10\nS000000000\n0000000000\n0000000000\n0000000000\n0000001000\n0000000101\n0000000000\n0000000000\n0000000000\n000000000F\n"
],
"output": [
"2\n1 2\n2 3\n",
"2\n1 2\n2 1\n",
"2\n1 2\n2 3\n",
"1\n1 2\n",
"2\n1 2\n2 3\n",
"2\n1 2\n2 1\n"
]
} | 1,100 | 1,000 |
2 | 7 | 143_A. Help Vasilisa the Wise 2 | Vasilisa the Wise from the Kingdom of Far Far Away got a magic box with a secret as a present from her friend Hellawisa the Wise from the Kingdom of A Little Closer. However, Vasilisa the Wise does not know what the box's secret is, since she cannot open it again. She hopes that you will help her one more time with that.
The box's lock looks as follows: it contains 4 identical deepenings for gems as a 2 Γ 2 square, and some integer numbers are written at the lock's edge near the deepenings. The example of a lock is given on the picture below.
<image>
The box is accompanied with 9 gems. Their shapes match the deepenings' shapes and each gem contains one number from 1 to 9 (each number is written on exactly one gem). The box will only open after it is decorated with gems correctly: that is, each deepening in the lock should be filled with exactly one gem. Also, the sums of numbers in the square's rows, columns and two diagonals of the square should match the numbers written at the lock's edge. For example, the above lock will open if we fill the deepenings with gems with numbers as is shown on the picture below.
<image>
Now Vasilisa the Wise wants to define, given the numbers on the box's lock, which gems she should put in the deepenings to open the box. Help Vasilisa to solve this challenging task.
Input
The input contains numbers written on the edges of the lock of the box. The first line contains space-separated integers r1 and r2 that define the required sums of numbers in the rows of the square. The second line contains space-separated integers c1 and c2 that define the required sums of numbers in the columns of the square. The third line contains space-separated integers d1 and d2 that define the required sums of numbers on the main and on the side diagonals of the square (1 β€ r1, r2, c1, c2, d1, d2 β€ 20). Correspondence between the above 6 variables and places where they are written is shown on the picture below. For more clarifications please look at the second sample test that demonstrates the example given in the problem statement.
<image>
Output
Print the scheme of decorating the box with stones: two lines containing two space-separated integers from 1 to 9. The numbers should be pairwise different. If there is no solution for the given lock, then print the single number "-1" (without the quotes).
If there are several solutions, output any.
Examples
Input
3 7
4 6
5 5
Output
1 2
3 4
Input
11 10
13 8
5 16
Output
4 7
9 1
Input
1 2
3 4
5 6
Output
-1
Input
10 10
10 10
10 10
Output
-1
Note
Pay attention to the last test from the statement: it is impossible to open the box because for that Vasilisa the Wise would need 4 identical gems containing number "5". However, Vasilisa only has one gem with each number from 1 to 9. | {
"input": [
"1 2\n3 4\n5 6\n",
"11 10\n13 8\n5 16\n",
"3 7\n4 6\n5 5\n",
"10 10\n10 10\n10 10\n"
],
"output": [
"-1\n",
"4 7\n9 1\n",
"1 2\n3 4\n",
"-1\n"
]
} | {
"input": [
"3 14\n8 9\n10 7\n",
"12 11\n11 12\n16 7\n",
"12 17\n10 19\n13 16\n",
"9 12\n3 17\n10 10\n",
"10 7\n4 13\n11 6\n",
"7 9\n4 12\n5 11\n",
"2 4\n1 5\n3 3\n",
"13 8\n15 6\n11 10\n",
"8 10\n9 9\n13 5\n",
"12 7\n5 14\n8 11\n",
"9 6\n5 10\n3 12\n",
"16 5\n13 8\n10 11\n",
"14 16\n16 14\n18 12\n",
"8 12\n5 15\n11 9\n",
"3 8\n2 9\n6 5\n",
"16 10\n16 10\n12 14\n",
"5 14\n10 9\n10 9\n",
"13 6\n10 9\n6 13\n",
"11 9\n12 8\n11 9\n",
"10 8\n10 8\n4 14\n",
"13 7\n10 10\n5 15\n",
"7 8\n8 7\n12 3\n",
"12 14\n11 15\n9 17\n",
"14 8\n11 11\n13 9\n",
"10 6\n6 10\n4 12\n",
"12 12\n14 10\n16 8\n",
"5 9\n7 7\n8 6\n",
"11 11\n17 5\n12 10\n",
"3 8\n4 6\n5 5\n",
"5 13\n8 10\n11 7\n",
"10 16\n14 12\n14 12\n",
"18 10\n16 12\n12 16\n",
"14 11\n16 9\n13 12\n",
"6 5\n2 9\n5 6\n",
"12 11\n13 10\n10 13\n",
"15 11\n16 10\n9 17\n",
"14 13\n9 18\n14 13\n",
"17 16\n14 19\n18 15\n",
"12 8\n14 6\n8 12\n",
"14 11\n9 16\n16 9\n",
"11 13\n19 5\n12 12\n",
"14 17\n18 13\n15 16\n",
"8 5\n11 2\n8 5\n",
"16 14\n15 15\n17 13\n",
"7 11\n7 11\n6 12\n",
"9 14\n8 15\n8 15\n",
"13 10\n11 12\n7 16\n",
"13 7\n9 11\n14 6\n"
],
"output": [
"2 1\n6 8\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"9 4\n6 2\n",
"6 2\n3 7\n",
"3 9\n2 5\n",
"1 8\n4 2\n",
"9 7\n4 1\n",
"-1\n",
"2 6\n3 9\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"4 9\n6 1\n",
"-1\n",
"3 9\n8 6\n",
"8 6\n3 5\n",
"-1\n",
"9 3\n5 7\n",
"3 2\n4 5\n",
"9 2\n8 3\n",
"-1\n",
"3 2\n5 8\n",
"-1\n",
"-1\n",
"9 5\n7 4\n",
"-1\n",
"-1\n",
"7 8\n9 2\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"9 7\n6 8\n",
"-1\n",
"-1\n",
"4 9\n7 3\n",
"8 5\n1 6\n"
]
} | 1,000 | 500 |
2 | 12 | 1466_F. Euclid's nightmare | You may know that Euclid was a mathematician. Well, as it turns out, Morpheus knew it too. So when he wanted to play a mean trick on Euclid, he sent him an appropriate nightmare.
In his bad dream Euclid has a set S of n m-dimensional vectors over the Z_2 field and can perform vector addition on them. In other words he has vectors with m coordinates, each one equal either 0 or 1. Vector addition is defined as follows: let u+v = w, then w_i = (u_i + v_i) mod 2.
Euclid can sum any subset of S and archive another m-dimensional vector over Z_2. In particular, he can sum together an empty subset; in such a case, the resulting vector has all coordinates equal 0.
Let T be the set of all the vectors that can be written as a sum of some vectors from S. Now Euclid wonders the size of T and whether he can use only a subset S' of S to obtain all the vectors from T. As it is usually the case in such scenarios, he will not wake up until he figures this out. So far, things are looking rather grim for the philosopher. But there is hope, as he noticed that all vectors in S have at most 2 coordinates equal 1.
Help Euclid and calculate |T|, the number of m-dimensional vectors over Z_2 that can be written as a sum of some vectors from S. As it can be quite large, calculate it modulo 10^9+7. You should also find S', the smallest such subset of S, that all vectors in T can be written as a sum of vectors from S'. In case there are multiple such sets with a minimal number of elements, output the lexicographically smallest one with respect to the order in which their elements are given in the input.
Consider sets A and B such that |A| = |B|. Let a_1, a_2, ... a_{|A|} and b_1, b_2, ... b_{|B|} be increasing arrays of indices elements of A and B correspondingly. A is lexicographically smaller than B iff there exists such i that a_j = b_j for all j < i and a_i < b_i.
Input
In the first line of input, there are two integers n, m (1 β€ n, m β€ 5 β
10^5) denoting the number of vectors in S and the number of dimensions.
Next n lines contain the description of the vectors in S. In each of them there is an integer k (1 β€ k β€ 2) and then follow k distinct integers x_1, ... x_k (1 β€ x_i β€ m). This encodes an m-dimensional vector having 1s on coordinates x_1, ... x_k and 0s on the rest of them.
Among the n vectors, no two are the same.
Output
In the first line, output two integers: remainder modulo 10^9+7 of |T| and |S'|. In the second line, output |S'| numbers, indices of the elements of S' in ascending order. The elements of S are numbered from 1 in the order they are given in the input.
Examples
Input
3 2
1 1
1 2
2 2 1
Output
4 2
1 2
Input
2 3
2 1 3
2 1 2
Output
4 2
1 2
Input
3 5
2 1 2
1 3
1 4
Output
8 3
1 2 3
Note
In the first example we are given three vectors:
* 10
* 01
* 11
It turns out that we can represent all vectors from our 2-dimensional space using these vectors:
* 00 is a sum of the empty subset of above vectors;
* 01 = 11 + 10, is a sum of the first and third vector;
* 10 = 10, is just the first vector;
* 11 = 10 + 01, is a sum of the first and the second vector.
Hence, T = \{00, 01, 10, 11\}. We can choose any two of the three vectors from S and still be able to obtain all the vectors in T. In such a case, we choose the two vectors which appear first in the input. Since we cannot obtain all vectors in T using only a single vector from S, |S'| = 2 and S' = \{10, 01\} (indices 1 and 2), as set \{1, 2 \} is lexicographically the smallest. We can represent all vectors from T, using only vectors from S', as shown below:
* 00 is a sum of the empty subset;
* 01 = 01 is just the second vector;
* 10 = 10 is just the first vector;
* 11 = 10 + 01 is a sum of the first and the second vector. | {
"input": [
"3 2\n1 1\n1 2\n2 2 1\n",
"3 5\n2 1 2\n1 3\n1 4\n",
"2 3\n2 1 3\n2 1 2\n"
],
"output": [
"\n4 2\n1 2 \n",
"\n8 3\n1 2 3 \n",
"\n4 2\n1 2 \n"
]
} | {
"input": [
"50 5000\n2 35 46\n2 43 92\n2 16 88\n2 67 99\n2 36 93\n2 12 20\n2 33 96\n2 55 82\n2 18 32\n2 48 87\n2 29 83\n2 19 37\n2 68 100\n2 13 76\n2 73 90\n2 25 86\n2 17 61\n2 10 27\n2 70 94\n2 28 41\n2 14 53\n2 15 72\n2 8 95\n2 23 60\n2 3 98\n2 6 34\n2 44 56\n2 2 66\n2 5 91\n2 49 74\n2 38 77\n2 64 71\n2 65 89\n2 7 75\n2 30 57\n2 4 40\n2 1 97\n2 11 78\n2 39 63\n2 26 50\n2 24 81\n2 21 59\n2 51 80\n2 22 85\n2 52 79\n2 9 45\n2 47 62\n2 31 54\n2 58 69\n2 42 84\n",
"1 1\n1 1\n",
"7 8\n2 4 5\n2 1 5\n2 2 8\n2 5 8\n2 2 3\n2 2 7\n2 4 6\n",
"50 500000\n2 57 94\n2 1 10\n2 97 98\n2 15 86\n2 66 84\n2 40 100\n2 8 27\n2 14 43\n2 55 75\n2 25 90\n2 22 69\n2 9 12\n2 32 34\n2 24 48\n2 54 88\n2 13 50\n2 30 56\n2 38 77\n2 4 70\n2 39 92\n2 23 72\n2 17 36\n2 20 29\n2 6 51\n2 11 87\n2 21 68\n2 59 80\n2 52 61\n2 26 42\n2 2 37\n2 45 62\n2 28 83\n2 41 73\n2 46 71\n2 78 99\n2 49 58\n2 3 53\n2 67 95\n2 31 93\n2 5 44\n2 7 47\n2 65 79\n2 82 85\n2 89 96\n2 35 76\n2 60 64\n2 18 19\n2 63 81\n2 33 91\n2 16 74\n",
"50 50\n2 12 48\n2 36 44\n2 12 41\n2 10 36\n2 2 13\n2 34 36\n2 4 20\n2 3 12\n2 43 48\n2 6 12\n2 11 27\n2 30 47\n2 16 33\n2 15 42\n2 3 25\n2 1 31\n2 15 23\n2 12 40\n2 6 39\n2 6 20\n2 12 32\n2 9 50\n2 7 10\n2 11 12\n2 11 13\n2 23 49\n2 42 47\n2 13 22\n2 24 36\n2 21 35\n2 1 19\n2 14 44\n2 7 45\n2 10 26\n2 23 31\n2 7 18\n2 38 47\n2 34 37\n2 28 35\n2 29 40\n2 10 46\n2 10 12\n2 8 20\n2 9 36\n2 15 35\n2 5 12\n2 6 33\n2 5 42\n2 15 17\n2 23 48\n",
"48 50\n2 4 10\n2 16 26\n2 6 16\n2 16 28\n2 8 9\n2 20 22\n2 7 36\n2 24 39\n2 8 22\n2 5 35\n2 27 33\n2 15 17\n2 6 37\n2 25 40\n2 13 20\n2 19 30\n2 2 28\n2 7 26\n2 21 28\n2 17 36\n2 3 11\n2 12 27\n2 6 20\n2 23 38\n2 20 32\n2 20 34\n2 27 40\n2 10 29\n2 9 29\n2 22 27\n2 5 14\n2 20 21\n2 28 40\n2 15 39\n2 30 40\n2 9 16\n2 25 31\n2 26 36\n2 18 21\n2 26 28\n2 1 31\n2 9 39\n2 31 34\n2 11 34\n2 17 24\n2 31 32\n2 2 19\n2 13 30\n"
],
"output": [
"898961331 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \n",
"2 1\n1 \n",
"128 7\n1 2 3 4 5 6 7 \n",
"898961331 50\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \n",
"949480669 49\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 \n",
"438952513 37\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 34 35 37 39 41 44 \n"
]
} | 2,100 | 1,750 |
2 | 9 | 1513_C. Add One | You are given an integer n. You have to apply m operations to it.
In a single operation, you must replace every digit d of the number with the decimal representation of integer d + 1. For example, 1912 becomes 21023 after applying the operation once.
You have to find the length of n after applying m operations. Since the answer can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer t (1 β€ t β€ 2 β
10^5) β the number of test cases.
The only line of each test case contains two integers n (1 β€ n β€ 10^9) and m (1 β€ m β€ 2 β
10^5) β the initial number and the number of operations.
Output
For each test case output the length of the resulting number modulo 10^9+7.
Example
Input
5
1912 1
5 6
999 1
88 2
12 100
Output
5
2
6
4
2115
Note
For the first test, 1912 becomes 21023 after 1 operation which is of length 5.
For the second test, 5 becomes 21 after 6 operations which is of length 2.
For the third test, 999 becomes 101010 after 1 operation which is of length 6.
For the fourth test, 88 becomes 1010 after 2 operations which is of length 4. | {
"input": [
"5\n1912 1\n5 6\n999 1\n88 2\n12 100\n"
],
"output": [
"\n5\n2\n6\n4\n2115\n"
]
} | {
"input": [
"5\n90 94\n26 25\n64 84\n14 6\n20 96\n"
],
"output": [
"1842\n12\n1015\n3\n1908\n"
]
} | 1,600 | 1,500 |
2 | 9 | 1540_C1. Converging Array (Easy Version) | This is the easy version of the problem. The only difference is that in this version q = 1. You can make hacks only if both versions of the problem are solved.
There is a process that takes place on arrays a and b of length n and length n-1 respectively.
The process is an infinite sequence of operations. Each operation is as follows:
* First, choose a random integer i (1 β€ i β€ n-1).
* Then, simultaneously set a_i = min\left(a_i, \frac{a_i+a_{i+1}-b_i}{2}\right) and a_{i+1} = max\left(a_{i+1}, \frac{a_i+a_{i+1}+b_i}{2}\right) without any rounding (so values may become non-integer).
See notes for an example of an operation.
It can be proven that array a converges, i. e. for each i there exists a limit a_i converges to. Let function F(a, b) return the value a_1 converges to after a process on a and b.
You are given array b, but not array a. However, you are given a third array c. Array a is good if it contains only integers and satisfies 0 β€ a_i β€ c_i for 1 β€ i β€ n.
Your task is to count the number of good arrays a where F(a, b) β₯ x for q values of x. Since the number of arrays can be very large, print it modulo 10^9+7.
Input
The first line contains a single integer n (2 β€ n β€ 100).
The second line contains n integers c_1, c_2 β¦, c_n (0 β€ c_i β€ 100).
The third line contains n-1 integers b_1, b_2, β¦, b_{n-1} (0 β€ b_i β€ 100).
The fourth line contains a single integer q (q=1).
The fifth line contains q space separated integers x_1, x_2, β¦, x_q (-10^5 β€ x_i β€ 10^5).
Output
Output q integers, where the i-th integer is the answer to the i-th query, i. e. the number of good arrays a where F(a, b) β₯ x_i modulo 10^9+7.
Example
Input
3
2 3 4
2 1
1
-1
Output
56
Note
The following explanation assumes b = [2, 1] and c=[2, 3, 4] (as in the sample).
Examples of arrays a that are not good:
* a = [3, 2, 3] is not good because a_1 > c_1;
* a = [0, -1, 3] is not good because a_2 < 0.
One possible good array a is [0, 2, 4]. We can show that no operation has any effect on this array, so F(a, b) = a_1 = 0.
Another possible good array a is [0, 1, 4]. In a single operation with i = 1, we set a_1 = min((0+1-2)/(2), 0) and a_2 = max((0+1+2)/(2), 1). So, after a single operation with i = 1, a becomes equal to [-1/2, 3/2, 4]. We can show that no operation has any effect on this array, so F(a, b) = -1/2. | {
"input": [
"3\n2 3 4\n2 1\n1\n-1\n"
],
"output": [
"56\n"
]
} | {
"input": [
"100\n95 54 23 27 51 58 94 34 29 95 53 53 8 5 64 32 17 62 14 37 26 95 27 85 94 37 85 72 88 69 43 9 60 3 48 26 81 48 89 56 34 28 2 63 26 6 13 19 99 41 70 24 92 41 9 73 52 42 34 98 16 82 7 81 28 80 18 33 90 69 19 13 51 96 8 21 86 32 96 7 5 42 52 87 24 82 14 88 4 69 7 69 4 16 55 14 27 89 32 42\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1\n44\n",
"50\n22 43 83 63 10 95 45 4 6 73 41 86 77 90 0 79 44 9 95 40 79 81 95 39 52 36 49 25 24 17 50 46 69 92 22 20 22 48 76 36 39 27 73 37 9 95 59 49 26 32\n3 4 5 2 3 1 5 5 3 5 4 3 4 2 2 1 2 2 2 1 1 2 4 5 2 1 4 4 4 5 1 2 3 2 0 0 0 1 1 1 0 0 0 1 5 5 2 5 1\n1\n-62\n",
"20\n88 74 27 3 73 12 63 14 8 33 27 57 49 91 81 1 69 45 21 100\n1 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0\n1\n-100000\n",
"20\n12 46 89 16 75 93 35 2 43 68 24 37 83 46 82 49 49 25 4 53\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1\n-50\n",
"30\n62 48 36 36 7 90 52 14 100 3 90 79 79 1 69 100 74 69 93 65 11 98 50 54 61 31 38 65 14 98\n3 0 3 2 1 2 2 3 0 2 3 2 0 0 1 2 3 3 0 2 0 3 1 3 1 1 0 0 2\n1\n-20\n",
"2\n7 28\n83\n1\n-46\n",
"20\n54 52 44 46 92 3 45 82 95 6 72 86 37 55 91 55 65 85 52 6\n1 1 1 1 0 0 0 1 1 0 1 1 1 1 1 1 0 0 0\n1\n24\n",
"40\n48 62 9 44 65 93 94 54 41 44 37 43 78 79 74 56 81 95 10 64 50 6 5 86 57 90 27 12 75 41 71 15 35 42 65 73 67 45 15 25\n0 3 3 3 3 4 1 1 4 2 2 4 2 2 3 4 2 3 1 2 4 4 4 4 2 1 4 3 1 3 0 4 0 4 3 4 3 0 1\n1\n-44\n",
"60\n99 63 10 93 9 69 81 82 41 3 52 49 6 72 61 95 86 44 20 83 50 52 41 20 22 94 33 79 40 31 22 89 92 69 78 82 87 98 14 55 100 62 77 83 63 70 14 65 17 69 23 73 55 76 30 70 67 26 63 68\n1 2 0 3 1 1 2 2 5 1 0 0 5 0 2 4 5 1 1 1 5 2 3 1 0 0 1 4 1 4 0 3 4 2 5 2 5 1 5 0 0 2 1 4 1 3 5 1 4 5 1 5 4 2 1 2 5 1 3\n1\n-11\n",
"20\n48 55 46 38 12 63 24 34 54 97 35 68 36 74 12 95 34 33 7 59\n3 5 2 3 3 0 0 5 2 0 5 5 5 4 4 6 3 1 6\n1\n2\n",
"10\n26 10 19 71 11 48 81 100 96 85\n3 0 5 5 0 4 4 1 0\n1\n-12\n",
"20\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n2 1 3 1 3 3 3 3 0 3 0 2 2 1 1 3 1 2 2\n1\n100000\n",
"20\n17 83 51 51 66 64 2 18 64 70 22 92 96 23 61 2 100 7 60 79\n4 3 0 5 6 4 9 8 8 9 4 4 1 0 5 6 4 9 5\n1\n-15\n",
"20\n42 69 54 74 18 35 55 12 43 49 20 35 71 91 23 45 70 66 57 11\n1 0 1 0 0 1 1 0 1 1 1 1 0 1 0 0 0 0 1\n1\n-2\n",
"70\n40 75 61 51 0 1 60 90 99 23 62 45 60 56 49 36 8 86 92 36 86 8 49 2 20 82 74 71 92 24 72 14 51 75 63 53 32 51 33 33 42 53 47 91 31 35 26 63 7 32 63 49 2 11 93 41 79 67 24 39 33 54 21 8 64 44 11 78 1 84\n1 0 0 1 4 1 0 3 4 2 2 5 5 1 5 0 4 5 0 3 2 0 4 2 1 2 5 0 0 1 0 4 2 5 5 1 4 3 2 1 2 5 2 4 2 5 5 5 5 0 4 0 1 4 0 5 0 5 4 0 4 0 2 0 5 0 3 0 2\n1\n-41\n",
"40\n37 40 93 32 34 41 79 65 48 36 25 77 18 14 0 41 60 81 9 51 46 35 2 92 1 48 13 81 41 73 50 81 16 25 64 89 61 60 62 94\n3 2 2 4 4 4 4 2 0 0 2 1 1 4 4 1 3 4 4 1 1 1 1 4 1 1 2 1 4 1 2 1 0 2 3 2 4 2 4\n1\n-3\n",
"100\n45 21 34 56 15 0 46 59 40 39 78 83 29 77 19 30 60 39 90 64 11 47 10 47 35 79 30 13 21 31 26 68 0 67 52 43 29 94 100 76 16 61 74 34 62 63 4 41 78 31 77 21 90 2 43 70 53 15 53 29 47 87 33 20 23 30 55 57 13 25 19 89 10 17 92 24 47 6 4 91 52 9 11 25 81 14 82 75 46 49 66 62 28 84 88 57 0 19 34 94\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1\n21\n",
"20\n33 94 53 35 47 78 90 32 54 98 3 65 12 12 21 55 94 5 36 83\n0 0 0 2 2 2 2 2 1 2 2 2 1 0 0 1 1 0 2\n1\n19\n",
"20\n57 42 39 79 84 90 23 96 40 18 65 1 90 67 0 27 48 32 55 86\n8 4 4 8 1 5 7 4 2 8 6 10 9 7 6 4 2 10 5\n1\n-23\n",
"100\n17 9 8 16 34 17 52 66 41 2 43 16 18 2 6 16 73 35 48 79 31 13 74 63 91 87 14 49 18 61 94 2 76 97 40 100 32 53 33 31 64 96 12 53 64 71 25 85 44 6 93 88 32 17 90 65 14 70 45 5 11 86 58 58 83 92 24 4 90 25 14 45 24 42 37 4 35 79 30 31 88 13 68 56 3 58 64 75 1 8 9 90 74 77 29 97 36 69 17 88\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n1\n1\n",
"70\n53 6 86 15 90 85 33 71 97 20 63 86 77 74 73 6 39 35 40 25 79 85 60 66 39 37 0 83 94 86 96 93 5 72 36 57 10 80 84 54 22 9 23 74 74 45 76 74 42 30 21 36 36 32 25 19 77 27 0 53 29 26 52 92 94 88 61 37 21 14\n4 1 3 4 0 2 3 0 2 0 4 3 3 5 3 5 3 3 3 0 5 4 1 1 4 2 3 1 4 2 4 2 5 0 0 5 2 0 5 2 3 5 2 4 5 0 4 5 5 5 2 5 2 1 3 4 3 0 1 5 3 0 1 1 2 3 5 3 5\n1\n-85\n",
"100\n45 4 100 7 62 78 23 54 97 21 41 14 0 20 23 85 30 94 26 23 38 15 9 48 72 54 21 52 28 11 98 47 17 77 29 10 95 31 26 24 67 27 50 91 37 52 93 58 18 33 73 40 43 51 31 96 68 85 97 10 80 49 51 70 6 8 35 44 49 72 79 62 13 97 6 69 40 70 10 22 59 71 94 53 16 47 28 51 73 69 41 51 6 59 90 24 97 12 72 8\n0 1 0 0 1 0 1 0 0 1 1 1 1 1 1 0 1 1 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 1 0 1 1 0 1 0 0 0 1 1 1 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 0 0 1 1 0 0 1 0 1 1 1 0 0 1 0 1 0 1 1 1 1 0 0 1 0 1 1 0 1 1 1 1 1 0 1 1 0 0 0\n1\n5\n",
"20\n97 76 80 25 49 7 76 39 49 19 67 25 68 31 46 45 31 32 5 88\n1 1 1 0 1 1 0 1 1 0 0 1 0 1 1 0 1 1 1\n1\n36\n",
"20\n79 33 19 90 72 83 79 78 81 59 33 91 13 76 81 28 76 90 71 41\n0 1 10 1 8 2 9 8 0 4 5 5 2 2 5 0 9 9 2\n1\n-9\n",
"10\n4 56 67 26 94 57 56 67 84 76\n0 5 2 1 3 0 5 0 2\n1\n4\n",
"10\n77 16 42 68 100 38 40 99 75 67\n0 1 0 2 1 1 0 0 0\n1\n43\n",
"100\n31 4 40 53 75 6 10 72 62 52 92 37 63 19 12 52 21 63 90 78 32 7 98 68 53 60 26 68 40 62 2 47 44 40 43 12 74 76 87 61 52 40 59 86 44 17 12 17 39 77 94 22 61 43 98 15 93 51 57 12 70 3 1 17 84 96 13 7 12 12 70 84 0 51 23 58 92 62 63 64 82 87 82 10 8 20 39 25 85 17 38 63 17 73 94 28 34 21 27 2\n0 0 1 1 0 0 1 1 1 1 1 0 1 1 0 0 0 1 1 0 1 0 1 0 0 0 1 0 0 1 0 1 1 1 1 1 0 0 1 1 1 1 0 0 0 1 1 0 1 0 0 1 0 1 0 0 0 1 0 1 1 1 1 0 0 1 0 0 1 1 1 0 0 1 1 0 0 0 1 1 1 1 1 1 1 1 0 0 1 1 1 1 1 0 1 0 1 1 0\n1\n-11\n",
"2\n8 70\n90\n1\n-10044\n",
"15\n32 93 82 70 57 2 54 62 31 40 45 23 49 51 24\n2 1 2 1 1 2 1 2 1 0 1 0 1 0\n1\n30\n",
"20\n39 6 41 50 22 11 24 35 4 46 23 80 88 33 63 3 71 97 76 91\n5 0 0 5 0 3 4 7 3 1 2 5 6 0 2 3 0 5 1\n1\n4\n",
"20\n70 79 36 48 68 10 79 84 96 72 35 89 39 5 92 96 38 12 56 3\n2 4 3 2 4 1 2 3 1 2 5 3 3 3 2 3 5 2 0\n1\n5\n",
"10\n8 39 84 74 25 3 75 39 19 51\n1 2 2 2 2 2 1 0 0\n1\n-6\n",
"30\n45 63 41 0 9 11 50 83 33 74 62 85 42 29 17 26 4 0 33 85 16 11 46 98 87 81 70 50 0 22\n1 3 0 1 2 2 0 1 2 1 3 2 0 1 1 2 0 0 2 1 0 2 0 1 3 1 0 3 1\n1\n19\n",
"60\n29 25 14 70 34 23 42 4 23 89 57 5 0 9 75 24 54 14 61 51 66 90 19 89 5 37 25 76 91 31 16 3 42 47 8 86 52 26 96 28 83 61 22 67 79 40 92 3 87 9 13 33 62 95 1 47 43 50 82 47\n5 2 4 2 0 2 4 0 2 0 2 3 1 0 2 5 0 4 3 1 2 3 4 1 0 3 5 5 4 2 0 4 5 3 5 0 3 5 5 0 5 2 4 2 1 1 4 4 1 0 4 5 3 5 1 4 3 3 3\n1\n-65\n",
"2\n73 16\n25\n1\n9988\n",
"100\n63 7 18 73 45 1 30 16 100 61 76 95 15 3 4 15 1 46 100 34 72 36 15 67 44 65 27 46 79 91 71 0 23 80 45 37 3 12 6 61 93 19 66 73 42 24 48 55 52 18 25 67 8 18 20 72 58 17 70 35 39 8 89 53 88 76 67 93 1 53 42 33 82 26 24 10 14 7 24 81 23 48 58 71 42 17 91 89 78 93 97 20 13 79 39 31 7 9 9 97\n1 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 1 0 1 0 0 1 1 0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 1 1 1 1 0 0 1 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 1 1 0 0 1 1 0 0 0 0 1 1 1 0 1 1 1 0 1 1 1 0 0 1 0 1 1 0 0 0 0 1 1\n1\n-18\n",
"2\n9 59\n22\n1\n9\n",
"20\n24 80 16 48 46 37 91 66 37 13 2 77 97 15 61 97 98 69 4 26\n3 3 0 4 4 4 2 1 4 0 3 0 3 0 3 1 0 4 2\n1\n8\n",
"20\n79 3 74 58 91 63 79 83 12 22 3 9 21 13 41 65 1 48 20 38\n1 0 2 2 0 2 2 3 2 1 3 2 1 0 3 1 0 0 1\n1\n17\n",
"50\n41 51 1 29 15 13 7 83 74 32 55 69 16 44 41 11 38 6 96 28 29 94 15 98 84 4 35 89 82 67 31 16 79 33 80 59 81 53 7 89 96 67 12 85 12 9 52 94 57 15\n5 4 3 2 0 3 1 3 2 3 5 1 5 4 3 5 5 0 5 0 2 1 2 3 1 5 4 2 5 1 2 2 1 2 4 3 2 4 5 2 1 0 3 4 3 5 0 4 4\n1\n-28\n",
"15\n1 90 89 8 53 49 67 44 96 10 25 22 93 77 24\n1 2 0 0 1 2 1 0 2 0 2 0 1 2\n1\n-4\n"
],
"output": [
"907807822\n",
"408830248\n",
"789889900\n",
"123629641\n",
"832833773\n",
"232\n",
"57024642\n",
"306268707\n",
"517730103\n",
"614879607\n",
"367574431\n",
"0\n",
"970766156\n",
"3235671\n",
"6060798\n",
"398097764\n",
"505914704\n",
"114801142\n",
"218316571\n",
"590810078\n",
"128076327\n",
"181290753\n",
"725187430\n",
"492539982\n",
"57117241\n",
"764609643\n",
"227004414\n",
"639\n",
"414551113\n",
"819983018\n",
"580682236\n",
"682295888\n",
"286438863\n",
"354295915\n",
"0\n",
"388832500\n",
"29\n",
"618918958\n",
"190959448\n",
"119200780\n",
"225489981\n"
]
} | 2,700 | 1,500 |
2 | 7 | 168_A. Wizards and Demonstration | Some country is populated by wizards. They want to organize a demonstration.
There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration.
So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets.
Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people.
Input
The first line contains three space-separated integers, n, x, y (1 β€ n, x, y β€ 104, x β€ n) β the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly.
Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n).
Output
Print a single integer β the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population).
Examples
Input
10 1 14
Output
1
Input
20 10 50
Output
0
Input
1000 352 146
Output
1108
Note
In the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone.
In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones. | {
"input": [
"1000 352 146\n",
"10 1 14\n",
"20 10 50\n"
],
"output": [
"1108\n",
"1\n",
"0\n"
]
} | {
"input": [
"7879 2590 2818\n",
"78 28 27\n",
"9178 2255 7996\n",
"6571 6449 8965\n",
"6151 6148 3746\n",
"6487 5670 8\n",
"4890 1112 5\n",
"4909 2111 8860\n",
"10000 10000 10000\n",
"78 55 96\n",
"3271 5 50\n",
"1 1 10000\n",
"8484 6400 547\n",
"10000 10000 1\n",
"9678 6173 5658\n",
"8403 7401 4769\n",
"10000 1 10000\n",
"7261 5328 10\n",
"2379 1436 9663\n",
"11 9 60\n",
"71 49 65\n",
"3871 3795 7\n",
"10000 1 1\n",
"54 4 38\n",
"78 73 58\n",
"3 1 69\n",
"1 1 1\n",
"8890 5449 8734\n",
"7835 6710 1639\n",
"4470 2543 6\n",
"68 65 20\n",
"7878 4534 9159\n",
"67 1 3\n",
"70 38 66\n",
"1138 570 6666\n",
"2765 768 9020\n",
"3478 1728 9727\n",
"7754 204 9038\n",
"9620 6557 6\n"
],
"output": [
"219441\n",
"0\n",
"731618\n",
"582642\n",
"224269\n",
"0\n",
"0\n",
"432827\n",
"990000\n",
"20\n",
"1631\n",
"99\n",
"40008\n",
"0\n",
"541409\n",
"393339\n",
"999999\n",
"0\n",
"228447\n",
"0\n",
"0\n",
"0\n",
"99\n",
"17\n",
"0\n",
"2\n",
"0\n",
"771004\n",
"121706\n",
"0\n",
"0\n",
"717013\n",
"2\n",
"9\n",
"75290\n",
"248635\n",
"336578\n",
"700603\n",
"0\n"
]
} | 900 | 500 |
2 | 8 | 20_B. Equation | You are given an equation:
Ax2 + Bx + C = 0.
Your task is to find the number of distinct roots of the equation and print all of them in ascending order.
Input
The first line contains three integer numbers A, B and C ( - 105 β€ A, B, C β€ 105). Any coefficient may be equal to 0.
Output
In case of infinite root count print the only integer -1. In case of no roots print the only integer 0. In other cases print the number of root on the first line and the roots on the following lines in the ascending order. Print roots with at least 5 digits after the decimal point.
Examples
Input
1 -5 6
Output
2
2.0000000000
3.0000000000 | {
"input": [
"1 -5 6\n"
],
"output": [
"2\n2.000000\n3.000000\n"
]
} | {
"input": [
"0 -2 0\n",
"1223 -23532 1232\n",
"0 1 0\n",
"-1 10 20\n",
"0 3431 43123\n",
"-50000 100000 -50000\n",
"1 1 0\n",
"50000 100000 50000\n",
"0 -2 1\n",
"0 -4 -4\n",
"1 1 1\n",
"1 -100000 0\n",
"-2 -5 0\n",
"0 1 -1\n",
"1 0 0\n",
"-2 -4 0\n",
"-2 0 0\n",
"-1 -2 -1\n",
"1 100000 -100000\n",
"1 -2 1\n",
"0 0 1\n",
"0 0 -100000\n",
"5 0 5\n",
"1000 -5000 6000\n",
"0 0 0\n",
"0 -100000 0\n",
"0 10000 -100000\n",
"1 2 1\n",
"100 200 100\n",
"1 0 1\n"
],
"output": [
"1\n0.000000",
"2\n0.052497\n19.188713\n",
"1\n-0.000000",
"2\n-1.708204\n11.708204\n",
"1\n-12.568639",
"1\n1.000000",
"2\n-1.000000\n0.000000\n",
"1\n-1.000000",
"1\n0.500000",
"1\n-1.000000",
"0\n",
"2\n0.000000\n100000.000000\n",
"2\n-2.500000\n-0.000000\n",
"1\n1.000000",
"1\n0.000000",
"2\n-2.000000\n-0.000000\n",
"1\n-0.000000",
"1\n-1.000000",
"2\n-100000.999990\n0.999990\n",
"1\n1.000000",
"0\n",
"0\n",
"0\n",
"2\n2.000000\n3.000000\n",
"-1\n",
"1\n0.000000",
"1\n10.000000",
"1\n-1.000000",
"1\n-1.000000",
"0\n"
]
} | 2,000 | 1,000 |
2 | 8 | 260_B. Ancient Prophesy | A recently found Ancient Prophesy is believed to contain the exact Apocalypse date. The prophesy is a string that only consists of digits and characters "-".
We'll say that some date is mentioned in the Prophesy if there is a substring in the Prophesy that is the date's record in the format "dd-mm-yyyy". We'll say that the number of the date's occurrences is the number of such substrings in the Prophesy. For example, the Prophesy "0012-10-2012-10-2012" mentions date 12-10-2012 twice (first time as "0012-10-2012-10-2012", second time as "0012-10-2012-10-2012").
The date of the Apocalypse is such correct date that the number of times it is mentioned in the Prophesy is strictly larger than that of any other correct date.
A date is correct if the year lies in the range from 2013 to 2015, the month is from 1 to 12, and the number of the day is strictly more than a zero and doesn't exceed the number of days in the current month. Note that a date is written in the format "dd-mm-yyyy", that means that leading zeroes may be added to the numbers of the months or days if needed. In other words, date "1-1-2013" isn't recorded in the format "dd-mm-yyyy", and date "01-01-2013" is recorded in it.
Notice, that any year between 2013 and 2015 is not a leap year.
Input
The first line contains the Prophesy: a non-empty string that only consists of digits and characters "-". The length of the Prophesy doesn't exceed 105 characters.
Output
In a single line print the date of the Apocalypse. It is guaranteed that such date exists and is unique.
Examples
Input
777-444---21-12-2013-12-2013-12-2013---444-777
Output
13-12-2013 | {
"input": [
"777-444---21-12-2013-12-2013-12-2013---444-777\n"
],
"output": [
"13-12-2013\n"
]
} | {
"input": [
"12-12-201312-12-201312-12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-201313--12-2013\n",
"01--01--2013-12-2013-01--01--2013\n",
"01-04-201425-08-201386-04-201525-10-2014878-04-20102-06-201501-04-2014-08-20159533-45-00-1212\n",
"00-12-2014-00-12-2014-00-12-2014-12-12-2014\n",
"23-11-201413-07-201412-06-2015124-03-20140-19-201323-11-201424-03-2014537523-11-20143575015-10-2014\n",
"32-13-2100-32-13-2100-32-13-2100-12-12-2013\n",
"14-08-201314-08-201314-08-201381-16-20172406414-08-201314-08-201314-08-20134237014-08-201314-08-2013\n",
"14-01-201402-04-201514-01-201485-26-1443948-14-278314-01-2014615259-09-178413-06-201314-05-2014\n",
"30-12-201429-15-208830-12-2014\n",
"29-02-2014--29-02-2014--28-02-2014\n",
"15-04-201413-08-201589-09-201013-08-20130-74-28-201620-8497-14-1063713-08-2013813-02-201513-08-2013\n",
"29-02-201329-02-201321-12-2013\n",
"19-07-201419-07-201424-06-201719-07-201419-07-201413-10-201419-07-201468-01-201619-07-20142\n",
"01-2-02013---01-2-02013----13-02-2014\n",
"15-11-201413-02-20147-86-25-298813-02-201413-02-201434615-11-201415-11-201415-11-201415-11-2014\n",
"13-05-201412-11-2013-12-11-201314-12-201329-05-201306-24-188814-07-201312-11-201312-04-2010\n",
"20-12-2012----20-12-2012-----01-01-2013\n",
"120110201311-10-20151201102013\n",
"29-02-2013-02-2013-29-02-2013\n",
"01-01-2014\n",
"21-12-201221-12-201221-12-201221-12-201213-12-2013\n",
"11111111111111111111---21-12-2013\n",
"10-10-2023-10-10-2023-10-10-2013\n",
"31-08-2013---31-08-2013---03-03-2013\n",
"31-12-201331-11-201331-11-2013\n",
"15-1--201315-1--201301-01-2013\n"
],
"output": [
"12-12-2013\n",
"13-12-2013\n",
"01-04-2014\n",
"12-12-2014\n",
"23-11-2014\n",
"12-12-2013\n",
"14-08-2013\n",
"14-01-2014\n",
"30-12-2014\n",
"28-02-2014\n",
"13-08-2013\n",
"21-12-2013\n",
"19-07-2014\n",
"13-02-2014\n",
"15-11-2014\n",
"12-11-2013\n",
"01-01-2013\n",
"11-10-2015\n",
"13-02-2013\n",
"01-01-2014\n",
"13-12-2013\n",
"21-12-2013\n",
"10-10-2013\n",
"31-08-2013\n",
"31-12-2013\n",
"01-01-2013\n"
]
} | 1,600 | 1,000 |
2 | 8 | 284_B. Cows and Poker Game | There are n cows playing poker at a table. For the current betting phase, each player's status is either "ALLIN", "IN", or "FOLDED", and does not change throughout the phase. To increase the suspense, a player whose current status is not "FOLDED" may show his/her hand to the table. However, so as not to affect any betting decisions, he/she may only do so if all other players have a status of either "ALLIN" or "FOLDED". The player's own status may be either "ALLIN" or "IN".
Find the number of cows that can currently show their hands without affecting any betting decisions.
Input
The first line contains a single integer, n (2 β€ n β€ 2Β·105). The second line contains n characters, each either "A", "I", or "F". The i-th character is "A" if the i-th player's status is "ALLIN", "I" if the i-th player's status is "IN", or "F" if the i-th player's status is "FOLDED".
Output
The first line should contain a single integer denoting the number of players that can currently show their hands.
Examples
Input
6
AFFAAA
Output
4
Input
3
AFI
Output
1
Note
In the first sample, cows 1, 4, 5, and 6 can show their hands. In the second sample, only cow 3 can show her hand. | {
"input": [
"3\nAFI\n",
"6\nAFFAAA\n"
],
"output": [
"1",
"4"
]
} | {
"input": [
"2\nFF\n",
"5\nIIIIF\n",
"5\nFAFFF\n",
"2\nFA\n",
"3\nAAA\n",
"5\nFAIAF\n",
"5\nAIFFF\n",
"3\nFFF\n",
"3\nFIF\n",
"3\nIII\n",
"5\nFAAII\n",
"2\nIF\n",
"8\nAFFFFIAF\n",
"5\nIIIII\n",
"3\nIAA\n",
"10\nAAAAAAAAAA\n",
"3\nIIF\n",
"8\nIAAIFFFI\n",
"3\nAFF\n",
"3\nIIA\n",
"5\nAFAFA\n",
"5\nAAAAI\n",
"5\nAIAIF\n",
"100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n"
],
"output": [
"0",
"0",
"1",
"1",
"3",
"1",
"1",
"0",
"1",
"0",
"0",
"1",
"1",
"0",
"1",
"10",
"0",
"0",
"1",
"0",
"3",
"1",
"0",
"100"
]
} | 1,000 | 1,000 |
2 | 7 | 379_A. New Year Candles | Vasily the Programmer loves romance, so this year he decided to illuminate his room with candles.
Vasily has a candles.When Vasily lights up a new candle, it first burns for an hour and then it goes out. Vasily is smart, so he can make b went out candles into a new candle. As a result, this new candle can be used like any other new candle.
Now Vasily wonders: for how many hours can his candles light up the room if he acts optimally well? Help him find this number.
Input
The single line contains two integers, a and b (1 β€ a β€ 1000; 2 β€ b β€ 1000).
Output
Print a single integer β the number of hours Vasily can light up the room for.
Examples
Input
4 2
Output
7
Input
6 3
Output
8
Note
Consider the first sample. For the first four hours Vasily lights up new candles, then he uses four burned out candles to make two new ones and lights them up. When these candles go out (stop burning), Vasily can make another candle. Overall, Vasily can light up the room for 7 hours. | {
"input": [
"4 2\n",
"6 3\n"
],
"output": [
"7\n",
"8\n"
]
} | {
"input": [
"5 3\n",
"1000 3\n",
"777 17\n",
"4 3\n",
"2 2\n",
"100 4\n",
"10 4\n",
"999 2\n",
"6 4\n",
"1 2\n",
"17 3\n",
"1 4\n",
"26 8\n",
"91 5\n",
"1 3\n",
"1000 2\n",
"20 3\n",
"9 4\n",
"123 5\n",
"1000 1000\n",
"3 2\n",
"3 3\n",
"80 970\n",
"1000 4\n",
"1 1000\n"
],
"output": [
"7\n",
"1499\n",
"825\n",
"5\n",
"3\n",
"133\n",
"13\n",
"1997\n",
"7\n",
"1\n",
"25\n",
"1\n",
"29\n",
"113\n",
"1\n",
"1999\n",
"29\n",
"11\n",
"153\n",
"1001\n",
"5\n",
"4\n",
"80\n",
"1333\n",
"1\n"
]
} | 1,000 | 500 |
2 | 14 | 39_H. Multiplication Table | Petya studies positional notations. He has already learned to add and subtract numbers in the systems of notations with different radices and has moved on to a more complicated action β multiplication. To multiply large numbers one has to learn the multiplication table. Unfortunately, in the second grade students learn only the multiplication table of decimals (and some students even learn it in the first grade). Help Petya make a multiplication table for numbers in the system of notations with the radix k.
Input
The first line contains a single integer k (2 β€ k β€ 10) β the radix of the system.
Output
Output the multiplication table for the system of notations with the radix k. The table must contain k - 1 rows and k - 1 columns. The element on the crossing of the i-th row and the j-th column is equal to the product of i and j in the system of notations with the radix k. Each line may have any number of spaces between the numbers (the extra spaces in the samples are put for clarity).
Examples
Input
10
Output
1 2 3 4 5 6 7 8 9
2 4 6 8 10 12 14 16 18
3 6 9 12 15 18 21 24 27
4 8 12 16 20 24 28 32 36
5 10 15 20 25 30 35 40 45
6 12 18 24 30 36 42 48 54
7 14 21 28 35 42 49 56 63
8 16 24 32 40 48 56 64 72
9 18 27 36 45 54 63 72 81
Input
3
Output
1 2
2 11 | {
"input": [
"10\n",
"3\n"
],
"output": [
"1 2 3 4 5 6 7 8 9 \n2 4 6 8 10 12 14 16 18 \n3 6 9 12 15 18 21 24 27 \n4 8 12 16 20 24 28 32 36 \n5 10 15 20 25 30 35 40 45 \n6 12 18 24 30 36 42 48 54 \n7 14 21 28 35 42 49 56 63 \n8 16 24 32 40 48 56 64 72 \n9 18 27 36 45 54 63 72 81 \n",
"1 2 \n2 11 \n"
]
} | {
"input": [
"9\n",
"8\n",
"6\n",
"4\n",
"7\n",
"5\n",
"2\n"
],
"output": [
"1 2 3 4 5 6 7 8 \n2 4 6 8 11 13 15 17 \n3 6 10 13 16 20 23 26 \n4 8 13 17 22 26 31 35 \n5 11 16 22 27 33 38 44 \n6 13 20 26 33 40 46 53 \n7 15 23 31 38 46 54 62 \n8 17 26 35 44 53 62 71 \n",
"1 2 3 4 5 6 7 \n2 4 6 10 12 14 16 \n3 6 11 14 17 22 25 \n4 10 14 20 24 30 34 \n5 12 17 24 31 36 43 \n6 14 22 30 36 44 52 \n7 16 25 34 43 52 61 \n",
"1 2 3 4 5 \n2 4 10 12 14 \n3 10 13 20 23 \n4 12 20 24 32 \n5 14 23 32 41 \n",
"1 2 3 \n2 10 12 \n3 12 21 \n",
"1 2 3 4 5 6 \n2 4 6 11 13 15 \n3 6 12 15 21 24 \n4 11 15 22 26 33 \n5 13 21 26 34 42 \n6 15 24 33 42 51 \n",
"1 2 3 4 \n2 4 11 13 \n3 11 14 22 \n4 13 22 31 \n",
"1 \n"
]
} | 1,300 | 0 |
2 | 8 | 44_B. Cola | To celebrate the opening of the Winter Computer School the organizers decided to buy in n liters of cola. However, an unexpected difficulty occurred in the shop: it turned out that cola is sold in bottles 0.5, 1 and 2 liters in volume. At that, there are exactly a bottles 0.5 in volume, b one-liter bottles and c of two-liter ones. The organizers have enough money to buy any amount of cola. What did cause the heated arguments was how many bottles of every kind to buy, as this question is pivotal for the distribution of cola among the participants (and organizers as well).
Thus, while the organizers are having the argument, discussing different variants of buying cola, the Winter School can't start. Your task is to count the number of all the possible ways to buy exactly n liters of cola and persuade the organizers that this number is too large, and if they keep on arguing, then the Winter Computer School will have to be organized in summer.
All the bottles of cola are considered indistinguishable, i.e. two variants of buying are different from each other only if they differ in the number of bottles of at least one kind.
Input
The first line contains four integers β n, a, b, c (1 β€ n β€ 10000, 0 β€ a, b, c β€ 5000).
Output
Print the unique number β the solution to the problem. If it is impossible to buy exactly n liters of cola, print 0.
Examples
Input
10 5 5 5
Output
9
Input
3 0 0 2
Output
0 | {
"input": [
"10 5 5 5\n",
"3 0 0 2\n"
],
"output": [
"9\n",
"0\n"
]
} | {
"input": [
"10 20 10 5\n",
"20 1 2 3\n",
"7 2 2 2\n",
"25 10 5 10\n",
"999 999 899 299\n",
"10000 5000 0 5000\n",
"2 2 2 2\n",
"1 0 2 0\n",
"3 3 2 1\n",
"1 1 0 0\n",
"1 0 0 1\n",
"20 10 20 30\n",
"505 142 321 12\n",
"101 10 10 50\n",
"10 19 15 100\n",
"10000 5000 5000 0\n",
"1234 645 876 1000\n",
"3 10 10 10\n",
"1 0 1 0\n",
"7 3 0 5\n",
"101 10 0 50\n",
"1 0 0 0\n",
"10 0 8 10\n",
"1 2 0 0\n",
"5 2 1 1\n",
"8765 2432 2789 4993\n",
"8987 4000 2534 4534\n",
"10000 5000 5000 5000\n",
"10000 5000 2500 2500\n",
"10000 0 5000 5000\n",
"10000 4999 2500 2500\n",
"5 5000 5000 5000\n",
"10000 4534 2345 4231\n",
"5643 1524 1423 2111\n",
"7777 4444 3333 2222\n",
"2500 5000 5000 5000\n",
"10000 2500 2500 2500\n",
"5000 5000 5000 5000\n"
],
"output": [
"36\n",
"0\n",
"1\n",
"12\n",
"145000\n",
"1251\n",
"3\n",
"1\n",
"3\n",
"0\n",
"0\n",
"57\n",
"0\n",
"33\n",
"35\n",
"0\n",
"141636\n",
"6\n",
"1\n",
"1\n",
"3\n",
"0\n",
"5\n",
"1\n",
"0\n",
"1697715\n",
"2536267\n",
"6253751\n",
"1\n",
"2501\n",
"0\n",
"12\n",
"2069003\n",
"146687\n",
"1236544\n",
"1565001\n",
"0\n",
"4691251\n"
]
} | 1,500 | 0 |
2 | 8 | 519_B. A and B and Compilation Errors | A and B are preparing themselves for programming contests.
B loves to debug his code. But before he runs the solution and starts debugging, he has to first compile the code.
Initially, the compiler displayed n compilation errors, each of them is represented as a positive integer. After some effort, B managed to fix some mistake and then another one mistake.
However, despite the fact that B is sure that he corrected the two errors, he can not understand exactly what compilation errors disappeared β the compiler of the language which B uses shows errors in the new order every time! B is sure that unlike many other programming languages, compilation errors for his programming language do not depend on each other, that is, if you correct one error, the set of other error does not change.
Can you help B find out exactly what two errors he corrected?
Input
The first line of the input contains integer n (3 β€ n β€ 105) β the initial number of compilation errors.
The second line contains n space-separated integers a1, a2, ..., an (1 β€ ai β€ 109) β the errors the compiler displayed for the first time.
The third line contains n - 1 space-separated integers b1, b2, ..., bn - 1 β the errors displayed at the second compilation. It is guaranteed that the sequence in the third line contains all numbers of the second string except for exactly one.
The fourth line contains n - 2 space-separated integers Ρ1, Ρ2, ..., Ρn - 2 β the errors displayed at the third compilation. It is guaranteed that the sequence in the fourth line contains all numbers of the third line except for exactly one.
Output
Print two numbers on a single line: the numbers of the compilation errors that disappeared after B made the first and the second correction, respectively.
Examples
Input
5
1 5 8 123 7
123 7 5 1
5 1 7
Output
8
123
Input
6
1 4 3 3 5 7
3 7 5 4 3
4 3 7 5
Output
1
3
Note
In the first test sample B first corrects the error number 8, then the error number 123.
In the second test sample B first corrects the error number 1, then the error number 3. Note that if there are multiple errors with the same number, B can correct only one of them in one step. | {
"input": [
"6\n1 4 3 3 5 7\n3 7 5 4 3\n4 3 7 5\n",
"5\n1 5 8 123 7\n123 7 5 1\n5 1 7\n"
],
"output": [
"1\n3\n",
"8\n123\n"
]
} | {
"input": [
"3\n1 2 3\n3 2\n2\n",
"3\n84 30 9\n9 84\n9\n",
"4\n1 5 7 8\n1 5 7\n1 5\n",
"3\n796067435 964699482 819602309\n964699482 796067435\n964699482\n",
"10\n460626451 802090732 277246428 661369649 388684428 784303821 376287098 656422756 9301599 25720377\n277246428 388684428 661369649 460626451 656422756 802090732 9301599 784303821 376287098\n376287098 802090732 388684428 9301599 656422756 784303821 460626451 277246428\n",
"6\n5 4 3 3 5 5\n3 5 5 4 3\n3 5 4 3\n",
"3\n168638990 939116221 323703261\n168638990 323703261\n168638990\n",
"3\n77 77 77\n77 77\n77\n",
"3\n374054998 726316780 902899520\n902899520 726316780\n726316780\n"
],
"output": [
"1\n3\n",
"30\n84\n",
"8\n7\n",
"819602309\n796067435\n",
"25720377\n661369649\n",
"5\n5\n",
"939116221\n323703261\n",
"77\n77\n",
"374054998\n902899520\n"
]
} | 1,100 | 1,000 |
2 | 9 | 545_C. Woodcutters | Little Susie listens to fairy tales before bed every day. Today's fairy tale was about wood cutters and the little girl immediately started imagining the choppers cutting wood. She imagined the situation that is described below.
There are n trees located along the road at points with coordinates x1, x2, ..., xn. Each tree has its height hi. Woodcutters can cut down a tree and fell it to the left or to the right. After that it occupies one of the segments [xi - hi, xi] or [xi;xi + hi]. The tree that is not cut down occupies a single point with coordinate xi. Woodcutters can fell a tree if the segment to be occupied by the fallen tree doesn't contain any occupied point. The woodcutters want to process as many trees as possible, so Susie wonders, what is the maximum number of trees to fell.
Input
The first line contains integer n (1 β€ n β€ 105) β the number of trees.
Next n lines contain pairs of integers xi, hi (1 β€ xi, hi β€ 109) β the coordinate and the height of the Ρ-th tree.
The pairs are given in the order of ascending xi. No two trees are located at the point with the same coordinate.
Output
Print a single number β the maximum number of trees that you can cut down by the given rules.
Examples
Input
5
1 2
2 1
5 10
10 9
19 1
Output
3
Input
5
1 2
2 1
5 10
10 9
20 1
Output
4
Note
In the first sample you can fell the trees like that:
* fell the 1-st tree to the left β now it occupies segment [ - 1;1]
* fell the 2-nd tree to the right β now it occupies segment [2;3]
* leave the 3-rd tree β it occupies point 5
* leave the 4-th tree β it occupies point 10
* fell the 5-th tree to the right β now it occupies segment [19;20]
In the second sample you can also fell 4-th tree to the right, after that it will occupy segment [10;19]. | {
"input": [
"5\n1 2\n2 1\n5 10\n10 9\n20 1\n",
"5\n1 2\n2 1\n5 10\n10 9\n19 1\n"
],
"output": [
"4\n",
"3\n"
]
} | {
"input": [
"4\n10 4\n15 1\n19 3\n20 1\n",
"2\n1 999999999\n1000000000 1000000000\n",
"67\n1 1\n3 8\n4 10\n7 8\n9 2\n10 1\n11 5\n12 8\n13 4\n16 6\n18 3\n19 3\n22 5\n24 6\n27 5\n28 3\n29 3\n30 5\n32 5\n33 10\n34 7\n35 8\n36 5\n41 3\n42 2\n43 5\n46 4\n48 4\n49 9\n52 4\n53 9\n55 1\n56 4\n59 7\n68 7\n69 4\n71 9\n72 10\n74 5\n76 4\n77 9\n80 7\n81 9\n82 5\n83 5\n84 9\n85 7\n86 9\n87 4\n88 7\n89 10\n90 3\n91 5\n92 10\n93 5\n94 8\n95 4\n96 2\n97 10\n98 1\n99 3\n100 1\n101 5\n102 4\n103 8\n104 8\n105 8\n",
"10\n999999900 1000000000\n999999901 1000000000\n999999902 1000000000\n999999903 1000000000\n999999904 1000000000\n999999905 1000000000\n999999906 1000000000\n999999907 1000000000\n999999908 1000000000\n999999909 1000000000\n",
"35\n1 7\n3 11\n6 12\n7 6\n8 5\n9 11\n15 3\n16 10\n22 2\n23 3\n25 7\n27 3\n34 5\n35 10\n37 3\n39 4\n40 5\n41 1\n44 1\n47 7\n48 11\n50 6\n52 5\n57 2\n58 7\n60 4\n62 1\n67 3\n68 12\n69 8\n70 1\n71 5\n72 5\n73 6\n74 4\n",
"1\n1000000000 1000000000\n",
"2\n100000000 1000000000\n1000000000 1000000000\n",
"10\n7 12\n10 2\n12 2\n15 1\n19 2\n20 1\n53 25\n63 10\n75 12\n87 1\n",
"3\n1 1\n1000 1000\n1000000000 1000000000\n",
"40\n1 1\n2 1\n3 1\n4 1\n5 1\n6 1\n7 1\n8 1\n9 1\n10 1\n11 1\n12 1\n13 1\n14 1\n15 1\n16 1\n17 1\n18 1\n19 1\n20 1\n21 1\n22 1\n23 1\n24 1\n25 1\n26 1\n27 1\n28 1\n29 1\n30 1\n31 1\n32 1\n33 1\n34 1\n35 1\n36 1\n37 1\n38 1\n39 1\n40 1\n"
],
"output": [
"4\n",
"2\n",
"5\n",
"2\n",
"10\n",
"1\n",
"2\n",
"9\n",
"3\n",
"2\n"
]
} | 1,500 | 1,750 |
2 | 9 | 593_C. Beautiful Function | Every day Ruslan tried to count sheep to fall asleep, but this didn't help. Now he has found a more interesting thing to do. First, he thinks of some set of circles on a plane, and then tries to choose a beautiful set of points, such that there is at least one point from the set inside or on the border of each of the imagined circles.
Yesterday Ruslan tried to solve this problem for the case when the set of points is considered beautiful if it is given as (xt = f(t), yt = g(t)), where argument t takes all integer values from 0 to 50. Moreover, f(t) and g(t) should be correct functions.
Assume that w(t) and h(t) are some correct functions, and c is an integer ranging from 0 to 50. The function s(t) is correct if it's obtained by one of the following rules:
1. s(t) = abs(w(t)), where abs(x) means taking the absolute value of a number x, i.e. |x|;
2. s(t) = (w(t) + h(t));
3. s(t) = (w(t) - h(t));
4. s(t) = (w(t) * h(t)), where * means multiplication, i.e. (w(t)Β·h(t));
5. s(t) = c;
6. s(t) = t;
Yesterday Ruslan thought on and on, but he could not cope with the task. Now he asks you to write a program that computes the appropriate f(t) and g(t) for any set of at most 50 circles.
In each of the functions f(t) and g(t) you are allowed to use no more than 50 multiplications. The length of any function should not exceed 100Β·n characters. The function should not contain spaces.
Ruslan can't keep big numbers in his memory, so you should choose f(t) and g(t), such that for all integer t from 0 to 50 value of f(t) and g(t) and all the intermediate calculations won't exceed 109 by their absolute value.
Input
The first line of the input contains number n (1 β€ n β€ 50) β the number of circles Ruslan thinks of. Next follow n lines, each of them containing three integers xi, yi and ri (0 β€ xi, yi β€ 50, 2 β€ ri β€ 50) β the coordinates of the center and the raduis of the i-th circle.
Output
In the first line print a correct function f(t). In the second line print a correct function g(t). The set of the points (xt = f(t), yt = g(t)) (0 β€ t β€ 50) must satisfy the condition, that there is at least one point inside or on the border of each of the circles, Ruslan thinks of at the beginning.
Examples
Input
3
0 10 4
10 0 4
20 10 4
Output
t
abs((t-10))
Note
Correct functions:
1. 10
2. (1+2)
3. ((t-3)+(t*4))
4. abs((t-10))
5. (abs((((23-t)*(t*t))+((45+12)*(t*t))))*((5*t)+((12*t)-13)))
6. abs((t-(abs((t*31))+14))))
Incorrect functions:
1. 3+5+7 (not enough brackets, it should be ((3+5)+7) or (3+(5+7)))
2. abs(t-3) (not enough brackets, it should be abs((t-3))
3. 2+(2-3 (one bracket too many)
4. 1(t+5) (no arithmetic operation between 1 and the bracket)
5. 5000*5000 (the number exceeds the maximum)
<image> The picture shows one of the possible solutions | {
"input": [
"3\n0 10 4\n10 0 4\n20 10 4\n"
],
"output": [
"(((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(5*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(10*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((5*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(5*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n"
]
} | {
"input": [
"3\n9 5 8\n8 9 10\n9 5 2\n",
"50\n48 45 42\n32 45 8\n15 41 47\n32 29 38\n7 16 48\n19 9 21\n18 40 5\n39 40 7\n37 0 6\n42 15 37\n9 33 37\n40 41 33\n25 43 2\n23 21 38\n30 20 32\n28 15 5\n47 9 19\n47 22 26\n26 9 18\n24 23 24\n11 29 5\n38 44 9\n49 22 42\n1 15 32\n18 25 21\n8 48 39\n48 7 26\n3 30 26\n34 21 47\n34 14 4\n36 43 40\n49 19 12\n33 8 30\n42 35 28\n47 21 14\n36 11 27\n40 46 17\n7 12 32\n47 5 4\n9 33 43\n35 31 3\n3 48 43\n2 19 9\n29 15 36\n1 13 2\n28 28 19\n31 33 21\n9 33 18\n7 12 22\n45 14 23\n",
"3\n3 3 3\n5 9 3\n49 1 7\n",
"5\n0 0 2\n1 1 2\n3 3 2\n40 40 2\n50 50 50\n",
"3\n0 10 4\n10 0 4\n20 10 4\n",
"50\n1 1 2\n1 1 42\n0 0 46\n1 1 16\n1 0 9\n0 0 43\n1 0 39\n1 1 41\n1 1 6\n1 1 43\n0 1 25\n0 1 40\n0 0 11\n0 1 27\n1 0 5\n1 0 9\n1 1 49\n0 0 25\n0 0 32\n0 1 6\n0 1 31\n1 1 22\n0 0 47\n0 1 6\n0 0 6\n0 1 49\n1 0 44\n0 0 50\n1 0 3\n0 1 15\n1 0 37\n0 0 14\n1 1 28\n1 1 49\n1 0 9\n0 1 12\n0 0 35\n1 0 42\n1 1 28\n0 1 20\n1 1 24\n1 1 33\n0 0 38\n1 0 17\n0 1 21\n0 0 22\n1 1 37\n0 1 34\n0 1 46\n1 1 21\n",
"5\n2 0 4\n5 6 10\n7 2 8\n3 10 8\n8 2 9\n",
"49\n48 9 48\n9 38 8\n27 43 43\n19 48 2\n35 3 11\n25 3 37\n26 40 20\n30 28 46\n19 35 44\n20 28 43\n34 40 37\n12 45 47\n28 2 38\n13 32 31\n50 10 28\n12 6 19\n31 50 5\n38 22 8\n25 33 50\n32 1 42\n8 37 26\n31 27 25\n21 4 25\n3 1 47\n21 15 42\n40 21 27\n43 20 9\n9 29 21\n15 35 36\n9 30 6\n46 39 22\n41 40 47\n11 5 32\n12 47 23\n24 2 27\n15 9 24\n0 8 45\n4 11 3\n28 13 27\n12 43 30\n23 42 40\n38 24 9\n13 46 42\n20 50 41\n29 32 11\n35 21 12\n10 34 47\n24 29 3\n46 4 7\n",
"10\n7 3 5\n2 1 6\n8 6 2\n1 2 6\n2 0 9\n10 9 2\n2 6 4\n10 3 6\n4 6 3\n9 9 2\n",
"50\n7 13 2\n41 17 2\n49 32 2\n22 16 2\n11 16 2\n2 10 2\n15 2 2\n8 12 2\n1 17 2\n22 44 2\n10 1 2\n18 45 2\n11 31 2\n4 43 2\n26 14 2\n33 47 2\n3 5 2\n49 22 2\n44 3 2\n3 41 2\n0 26 2\n30 1 2\n37 6 2\n10 48 2\n11 47 2\n5 41 2\n2 46 2\n32 3 2\n37 42 2\n25 17 2\n18 32 2\n47 21 2\n46 24 2\n7 2 2\n14 2 2\n17 17 2\n13 30 2\n23 19 2\n43 40 2\n42 26 2\n20 20 2\n17 5 2\n43 38 2\n4 32 2\n48 4 2\n1 3 2\n4 41 2\n49 36 2\n7 10 2\n9 6 2\n",
"49\n36 12 10\n50 6 19\n13 31 36\n15 47 9\n23 43 11\n31 17 14\n25 28 7\n2 20 50\n42 7 4\n7 12 43\n20 33 34\n27 44 26\n19 39 21\n40 29 16\n37 1 2\n13 27 26\n2 4 47\n49 30 13\n4 14 36\n21 36 18\n42 32 22\n21 22 18\n23 35 43\n15 31 27\n17 46 8\n22 3 34\n3 50 19\n47 47 9\n18 42 20\n30 26 42\n44 32 47\n29 20 42\n35 33 20\n43 16 9\n45 24 12\n11 1 21\n32 50 9\n38 19 48\n21 31 7\n5 42 5\n23 0 21\n39 50 8\n42 21 12\n21 20 41\n43 44 23\n43 34 4\n31 2 28\n7 0 38\n28 35 46\n",
"1\n50 50 50\n",
"3\n0 0 2\n5 7 5\n20 25 10\n",
"50\n10 26 2\n20 36 2\n32 43 2\n34 6 2\n19 37 2\n20 29 2\n31 12 2\n30 9 2\n31 5 2\n23 6 2\n0 44 2\n5 36 2\n34 22 2\n6 39 2\n19 18 2\n9 50 2\n40 11 2\n32 4 2\n42 46 2\n22 45 2\n28 2 2\n34 4 2\n16 30 2\n17 47 2\n14 46 2\n32 36 2\n43 11 2\n22 34 2\n34 9 2\n2 4 2\n18 15 2\n48 38 2\n27 28 2\n24 38 2\n33 32 2\n11 7 2\n37 35 2\n50 23 2\n25 28 2\n25 50 2\n28 26 2\n20 31 2\n12 31 2\n15 2 2\n31 45 2\n14 12 2\n16 18 2\n23 30 2\n16 26 2\n30 0 2\n",
"49\n33 40 10\n30 24 11\n4 36 23\n38 50 18\n23 28 29\n9 39 21\n47 15 35\n2 41 27\n1 45 28\n39 15 24\n7 7 28\n1 34 6\n47 17 43\n20 28 12\n23 22 15\n33 41 23\n34 3 44\n39 37 25\n41 49 39\n13 14 26\n4 35 18\n17 8 45\n23 23 16\n37 48 40\n12 48 29\n16 5 6\n29 1 5\n1 18 27\n37 11 3\n46 11 44\n9 25 40\n26 1 17\n12 26 45\n3 18 19\n15 32 38\n41 8 27\n8 39 35\n42 35 13\n5 19 43\n31 47 4\n16 47 38\n12 9 23\n10 23 3\n49 43 16\n38 28 6\n3 46 38\n13 27 28\n0 26 3\n23 1 15\n",
"1\n0 0 2\n",
"50\n34 7 2\n18 14 2\n15 24 2\n2 24 2\n27 2 2\n50 45 2\n49 19 2\n7 23 2\n16 22 2\n23 25 2\n18 23 2\n11 29 2\n22 14 2\n31 15 2\n10 42 2\n8 11 2\n9 33 2\n15 0 2\n30 25 2\n12 4 2\n14 13 2\n5 16 2\n13 43 2\n1 8 2\n26 34 2\n44 13 2\n10 17 2\n40 5 2\n48 39 2\n39 23 2\n19 10 2\n22 17 2\n36 26 2\n2 34 2\n11 42 2\n14 37 2\n25 7 2\n11 35 2\n22 34 2\n22 25 2\n12 36 2\n18 6 2\n2 47 2\n47 29 2\n13 37 2\n8 46 2\n9 4 2\n11 34 2\n12 31 2\n7 16 2\n",
"49\n9 43 6\n23 35 9\n46 39 11\n34 14 12\n30 8 4\n10 32 7\n43 10 45\n30 34 27\n27 26 21\n7 31 14\n38 13 33\n34 11 46\n33 31 32\n38 31 7\n3 24 13\n38 12 41\n21 26 32\n33 0 43\n17 44 25\n11 21 27\n27 43 28\n45 8 38\n47 50 47\n49 45 8\n2 9 34\n34 32 49\n21 30 9\n13 19 38\n8 45 32\n16 47 35\n45 28 14\n3 25 43\n45 7 32\n49 35 12\n22 35 35\n14 33 42\n19 23 10\n49 4 2\n44 37 40\n27 17 15\n7 37 30\n38 50 39\n32 12 19\n3 48 9\n26 36 27\n38 18 39\n25 40 50\n45 3 2\n23 40 36\n",
"50\n47 43 2\n31 38 2\n35 21 2\n18 41 2\n24 33 2\n35 0 2\n15 41 2\n6 3 2\n23 40 2\n11 29 2\n48 46 2\n33 45 2\n28 18 2\n31 14 2\n14 4 2\n35 18 2\n50 11 2\n10 28 2\n23 9 2\n43 25 2\n34 21 2\n19 49 2\n40 37 2\n22 27 2\n7 1 2\n37 24 2\n14 26 2\n18 46 2\n40 50 2\n21 40 2\n19 26 2\n35 2 2\n19 27 2\n13 23 2\n9 50 2\n38 9 2\n44 22 2\n5 30 2\n36 7 2\n10 26 2\n21 30 2\n19 6 2\n21 13 2\n5 3 2\n9 41 2\n10 17 2\n1 11 2\n5 6 2\n40 17 2\n6 7 2\n",
"10\n1 9 2\n3 10 2\n7 7 2\n6 12 2\n14 15 2\n2 12 2\n8 0 2\n0 12 2\n4 11 2\n15 9 2\n",
"7\n13 15 5\n2 10 3\n12 12 8\n9 12 11\n10 3 10\n9 6 13\n11 10 3\n",
"50\n0 1 2\n1 0 2\n1 1 2\n1 1 2\n1 1 2\n1 1 2\n0 1 2\n0 1 2\n0 0 2\n1 0 2\n1 1 2\n1 0 2\n1 0 2\n1 0 2\n1 0 2\n0 0 2\n0 1 2\n1 0 2\n1 0 2\n0 0 2\n0 1 2\n0 1 2\n0 1 2\n0 1 2\n0 1 2\n1 0 2\n0 0 2\n1 1 2\n0 0 2\n0 1 2\n0 0 2\n1 0 2\n1 1 2\n0 0 2\n0 0 2\n1 1 2\n0 1 2\n0 1 2\n1 0 2\n0 0 2\n1 0 2\n0 1 2\n0 0 2\n1 1 2\n1 1 2\n0 1 2\n0 0 2\n0 0 2\n0 0 2\n0 0 2\n",
"49\n22 28 2\n37 8 19\n17 36 19\n50 31 10\n26 39 17\n46 37 45\n8 33 30\n29 14 19\n34 42 37\n20 35 34\n17 10 39\n6 28 16\n38 35 27\n39 4 41\n8 37 7\n39 21 4\n12 28 20\n28 27 29\n36 28 10\n41 16 22\n21 0 20\n6 15 4\n48 43 21\n19 12 18\n10 27 15\n27 44 12\n25 14 19\n43 8 43\n1 31 26\n49 11 4\n45 18 7\n16 35 48\n2 8 21\n8 0 30\n20 42 5\n39 30 2\n13 36 34\n43 50 50\n7 9 43\n17 42 10\n15 5 21\n39 25 18\n25 29 35\n12 46 15\n48 41 6\n41 13 17\n16 46 15\n38 27 39\n50 25 16\n",
"1\n1 1 32\n",
"50\n21 22 2\n4 16 2\n19 29 2\n37 7 2\n31 47 2\n38 15 2\n32 24 2\n7 18 2\n9 7 2\n36 48 2\n14 26 2\n40 12 2\n18 10 2\n29 42 2\n32 27 2\n34 3 2\n44 33 2\n19 49 2\n12 39 2\n33 10 2\n21 8 2\n44 9 2\n13 0 2\n6 16 2\n18 15 2\n50 1 2\n31 31 2\n36 43 2\n30 2 2\n7 33 2\n18 22 2\n9 7 2\n3 25 2\n17 18 2\n13 10 2\n41 41 2\n32 44 2\n17 40 2\n7 11 2\n31 50 2\n3 40 2\n17 30 2\n10 5 2\n13 30 2\n44 33 2\n6 50 2\n45 49 2\n18 9 2\n35 46 2\n8 50 2\n",
"4\n0 0 2\n50 50 2\n50 0 2\n0 50 2\n"
],
"output": [
"(((4*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(4*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((2*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(2*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((24*((1-abs((t-0)))+abs((abs((t-0))-1))))+(16*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(7*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(16*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(3*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(9*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(9*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(19*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(18*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(21*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(4*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(20*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(12*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(11*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(15*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(14*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(23*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(23*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(13*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(12*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(5*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(19*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(24*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(9*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(4*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(24*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(1*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(17*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(17*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(18*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(24*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(16*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(21*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(23*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(18*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(20*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(3*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(23*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(4*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(17*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(1*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(1*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(14*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(0*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(14*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(15*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(4*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(3*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(22*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((22*((1-abs((t-0)))+abs((abs((t-0))-1))))+(22*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(20*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(14*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(8*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(4*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(20*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(20*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(7*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(16*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(20*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(21*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(10*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(10*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(7*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(4*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(11*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(4*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(11*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(14*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(22*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(11*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(7*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(12*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(24*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(3*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(15*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(10*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(7*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(21*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(9*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(4*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(17*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(10*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(5*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(23*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(6*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(2*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(16*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(15*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(24*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(9*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(7*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(6*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(14*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(16*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(16*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(6*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(7*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"(((1*((1-abs((t-0)))+abs((abs((t-0))-1))))+(2*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(24*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((1*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(0*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n",
"(((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(1*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(20*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(25*((1-abs((t-4)))+abs((abs((t-4))-1)))))\n(((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(1*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(20*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(25*((1-abs((t-4)))+abs((abs((t-4))-1)))))\n",
"(((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(5*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(10*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((5*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(5*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(0*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(0*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(0*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(0*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(0*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(0*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(0*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(0*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(0*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(0*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(0*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(0*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(0*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(0*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(0*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(0*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(0*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(0*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(0*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(0*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(0*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(0*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(0*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(0*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(0*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(0*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(0*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(0*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(0*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(0*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(0*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(0*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(0*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(0*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(0*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(0*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(0*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(0*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(0*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(0*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(0*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(0*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(0*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(0*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(0*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(0*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(0*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(0*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(0*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(0*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(0*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(0*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(0*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(0*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(0*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(0*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(0*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(0*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(0*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(0*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(0*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(0*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(0*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(0*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(0*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(0*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(0*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(0*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(0*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(0*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(0*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(0*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(0*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(0*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(0*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(0*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(0*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(0*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(0*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(0*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(0*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(0*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(0*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(0*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(0*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(0*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(0*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(0*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(0*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(0*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(0*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(0*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"(((((1*((1-abs((t-0)))+abs((abs((t-0))-1))))+(2*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(3*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(1*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(4*((1-abs((t-4)))+abs((abs((t-4))-1)))))\n(((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(3*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(1*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(5*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(1*((1-abs((t-4)))+abs((abs((t-4))-1)))))\n",
"(((((((((((((((((((((((((((((((((((((((((((((((((24*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(13*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(9*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(17*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(12*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(13*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(15*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(9*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(10*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(17*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(6*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(14*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(6*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(25*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(6*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(15*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(19*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(12*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(16*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(4*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(15*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(10*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(1*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(10*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(20*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(21*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(4*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(7*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(4*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(23*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(20*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(5*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(6*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(12*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(7*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(0*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(2*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(14*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(6*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(11*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(19*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(6*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(10*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(14*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(17*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(5*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(12*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(23*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n(((((((((((((((((((((((((((((((((((((((((((((((((4*((1-abs((t-0)))+abs((abs((t-0))-1))))+(19*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(21*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(24*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(1*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(1*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(20*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(14*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(17*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(14*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(20*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(22*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(1*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(16*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(5*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(3*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(25*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(11*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(16*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(0*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(18*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(13*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(2*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(7*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(10*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(10*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(14*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(17*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(15*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(19*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(20*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(2*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(23*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(1*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(4*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(4*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(5*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(6*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(21*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(21*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(12*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(23*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(25*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(16*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(10*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(17*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(14*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(2*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n",
"((((((((((3*((1-abs((t-0)))+abs((abs((t-0))-1))))+(1*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(4*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(0*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(1*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(5*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(1*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(5*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(2*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(4*((1-abs((t-9)))+abs((abs((t-9))-1)))))\n((((((((((1*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(3*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(1*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(0*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(4*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(3*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(1*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(3*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(4*((1-abs((t-9)))+abs((abs((t-9))-1)))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((3*((1-abs((t-0)))+abs((abs((t-0))-1))))+(20*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(24*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(11*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(5*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(1*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(7*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(4*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(11*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(5*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(9*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(5*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(2*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(13*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(16*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(1*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(24*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(22*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(1*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(0*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(15*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(18*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(5*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(5*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(2*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(1*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(16*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(18*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(12*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(9*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(23*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(23*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(3*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(7*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(8*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(6*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(11*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(21*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(21*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(10*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(8*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(21*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(2*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(24*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(0*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(2*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(24*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(3*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(4*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((6*((1-abs((t-0)))+abs((abs((t-0))-1))))+(8*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(16*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(8*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(8*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(5*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(1*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(6*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(8*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(22*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(0*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(22*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(15*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(21*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(7*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(23*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(2*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(11*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(1*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(20*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(13*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(0*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(3*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(24*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(23*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(20*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(23*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(1*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(21*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(8*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(16*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(10*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(12*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(1*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(1*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(8*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(15*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(9*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(20*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(13*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(10*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(2*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(19*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(16*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(2*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(1*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(20*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(18*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(5*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(3*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"(((((((((((((((((((((((((((((((((((((((((((((((((18*((1-abs((t-0)))+abs((abs((t-0))-1))))+(25*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(6*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(7*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(11*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(15*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(12*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(1*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(21*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(3*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(10*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(13*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(9*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(20*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(18*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(6*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(1*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(24*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(2*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(10*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(21*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(10*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(11*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(7*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(8*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(11*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(1*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(23*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(9*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(15*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(22*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(14*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(17*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(21*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(22*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(5*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(16*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(19*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(10*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(2*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(11*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(19*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(21*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(10*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(21*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(21*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(15*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(3*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(14*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n(((((((((((((((((((((((((((((((((((((((((((((((((6*((1-abs((t-0)))+abs((abs((t-0))-1))))+(3*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(15*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(23*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(21*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(8*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(14*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(10*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(3*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(6*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(16*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(22*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(19*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(14*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(0*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(13*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(2*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(15*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(7*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(18*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(16*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(11*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(17*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(15*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(23*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(1*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(25*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(23*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(21*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(13*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(16*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(10*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(16*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(8*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(12*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(0*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(25*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(9*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(15*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(21*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(0*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(25*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(10*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(10*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(22*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(17*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(1*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(0*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(17*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n",
"(25*((1-abs((t-0)))+abs((abs((t-0))-1))))\n(25*((1-abs((t-0)))+abs((abs((t-0))-1))))\n",
"(((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(2*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(10*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n(((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(3*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(12*((1-abs((t-2)))+abs((abs((t-2))-1)))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((5*((1-abs((t-0)))+abs((abs((t-0))-1))))+(10*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(16*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(17*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(9*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(10*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(15*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(15*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(15*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(11*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(0*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(2*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(17*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(3*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(9*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(4*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(20*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(16*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(21*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(11*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(14*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(17*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(8*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(8*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(7*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(16*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(21*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(11*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(17*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(1*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(9*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(24*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(13*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(12*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(16*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(5*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(18*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(25*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(12*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(12*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(14*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(10*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(6*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(7*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(15*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(7*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(8*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(11*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(8*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(15*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((13*((1-abs((t-0)))+abs((abs((t-0))-1))))+(18*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(21*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(3*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(18*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(14*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(6*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(4*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(2*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(3*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(22*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(18*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(11*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(19*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(9*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(25*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(5*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(2*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(23*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(22*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(1*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(2*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(15*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(23*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(23*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(18*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(5*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(17*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(4*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(2*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(7*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(19*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(14*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(19*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(16*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(3*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(17*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(11*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(14*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(25*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(13*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(15*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(15*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(1*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(22*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(6*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(9*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(15*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(13*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(0*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"(((((((((((((((((((((((((((((((((((((((((((((((((16*((1-abs((t-0)))+abs((abs((t-0))-1))))+(15*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(2*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(19*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(11*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(4*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(23*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(1*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(19*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(3*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(0*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(23*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(10*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(11*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(16*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(17*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(19*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(20*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(6*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(2*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(8*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(11*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(18*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(6*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(8*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(14*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(0*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(18*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(23*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(4*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(13*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(6*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(1*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(7*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(20*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(4*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(21*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(2*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(15*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(8*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(6*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(5*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(24*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(19*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(1*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(6*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(0*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(11*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n(((((((((((((((((((((((((((((((((((((((((((((((((20*((1-abs((t-0)))+abs((abs((t-0))-1))))+(12*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(18*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(25*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(14*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(19*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(7*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(20*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(22*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(7*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(3*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(17*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(8*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(14*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(11*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(20*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(1*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(18*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(24*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(7*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(17*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(4*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(11*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(24*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(24*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(2*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(0*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(9*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(5*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(5*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(12*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(0*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(13*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(9*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(16*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(4*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(19*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(17*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(9*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(23*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(23*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(4*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(11*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(21*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(14*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(23*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(13*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(13*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(0*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n",
"(0*((1-abs((t-0)))+abs((abs((t-0))-1))))\n(0*((1-abs((t-0)))+abs((abs((t-0))-1))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((17*((1-abs((t-0)))+abs((abs((t-0))-1))))+(9*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(7*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(1*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(13*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(25*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(24*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(3*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(8*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(11*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(9*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(5*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(11*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(15*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(5*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(4*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(4*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(7*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(15*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(6*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(7*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(2*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(6*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(13*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(22*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(5*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(20*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(24*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(19*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(9*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(11*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(18*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(1*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(5*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(7*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(12*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(5*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(11*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(11*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(6*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(9*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(1*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(23*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(6*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(4*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(4*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(5*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(6*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(3*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((3*((1-abs((t-0)))+abs((abs((t-0))-1))))+(7*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(12*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(12*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(1*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(22*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(9*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(11*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(11*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(12*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(11*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(14*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(7*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(7*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(21*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(5*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(16*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(0*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(12*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(2*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(6*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(8*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(21*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(4*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(17*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(6*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(8*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(2*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(19*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(11*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(5*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(8*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(13*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(17*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(21*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(18*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(3*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(17*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(17*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(12*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(18*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(3*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(23*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(14*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(18*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(23*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(2*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(17*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(15*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(8*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"(((((((((((((((((((((((((((((((((((((((((((((((((4*((1-abs((t-0)))+abs((abs((t-0))-1))))+(11*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(23*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(17*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(15*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(5*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(21*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(15*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(13*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(3*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(19*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(17*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(16*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(19*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(1*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(19*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(10*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(16*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(8*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(5*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(13*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(22*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(23*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(24*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(1*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(17*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(10*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(6*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(4*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(8*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(22*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(1*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(22*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(24*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(11*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(7*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(9*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(24*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(22*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(13*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(3*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(19*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(16*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(1*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(13*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(19*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(12*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(22*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(11*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n(((((((((((((((((((((((((((((((((((((((((((((((((21*((1-abs((t-0)))+abs((abs((t-0))-1))))+(17*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(19*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(7*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(4*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(16*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(5*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(17*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(13*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(15*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(6*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(5*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(15*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(15*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(12*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(6*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(13*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(0*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(22*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(10*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(21*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(4*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(25*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(22*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(4*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(16*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(15*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(9*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(22*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(23*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(14*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(12*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(3*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(17*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(17*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(16*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(11*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(2*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(18*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(8*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(18*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(25*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(6*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(24*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(18*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(9*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(20*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(1*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(20*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((23*((1-abs((t-0)))+abs((abs((t-0))-1))))+(15*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(17*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(9*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(12*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(17*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(7*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(3*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(11*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(5*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(24*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(16*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(14*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(15*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(7*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(17*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(25*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(5*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(11*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(21*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(17*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(9*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(20*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(11*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(3*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(18*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(7*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(9*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(20*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(10*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(9*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(17*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(9*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(6*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(4*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(19*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(22*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(2*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(18*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(5*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(10*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(9*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(10*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(2*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(4*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(5*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(0*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(2*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(20*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(3*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((21*((1-abs((t-0)))+abs((abs((t-0))-1))))+(19*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(10*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(20*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(16*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(0*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(20*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(1*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(20*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(14*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(23*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(22*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(9*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(7*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(2*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(9*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(5*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(14*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(4*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(12*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(10*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(24*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(18*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(13*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(0*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(12*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(13*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(23*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(25*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(20*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(13*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(1*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(13*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(11*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(25*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(4*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(11*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(15*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(3*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(13*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(15*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(3*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(6*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(1*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(20*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(8*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(5*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(3*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(8*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(3*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"((((((((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(1*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(3*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(3*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(7*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(1*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(4*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(0*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(2*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(7*((1-abs((t-9)))+abs((abs((t-9))-1)))))\n((((((((((4*((1-abs((t-0)))+abs((abs((t-0))-1))))+(5*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(3*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(6*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(7*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(6*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(0*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(6*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(5*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(4*((1-abs((t-9)))+abs((abs((t-9))-1)))))\n",
"(((((((6*((1-abs((t-0)))+abs((abs((t-0))-1))))+(1*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(6*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(4*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(5*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(4*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(5*((1-abs((t-6)))+abs((abs((t-6))-1)))))\n(((((((7*((1-abs((t-0)))+abs((abs((t-0))-1))))+(5*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(6*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(6*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(1*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(3*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(5*((1-abs((t-6)))+abs((abs((t-6))-1)))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(0*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(0*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(0*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(0*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(0*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(0*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(0*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(0*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(0*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(0*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(0*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(0*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(0*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(0*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(0*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(0*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(0*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(0*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(0*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(0*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(0*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(0*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(0*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(0*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(0*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(0*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(0*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(0*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(0*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(0*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(0*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(0*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(0*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(0*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(0*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(0*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(0*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(0*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(0*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(0*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(0*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(0*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(0*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(0*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(0*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(0*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(0*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(0*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(0*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(0*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(0*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(0*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(0*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(0*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(0*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(0*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(0*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(0*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(0*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(0*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(0*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(0*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(0*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(0*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(0*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(0*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(0*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(0*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(0*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(0*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(0*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(0*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(0*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(0*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(0*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(0*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(0*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(0*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(0*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(0*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(0*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(0*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(0*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(0*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(0*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(0*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(0*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(0*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(0*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(0*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(0*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(0*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(0*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(0*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(0*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"(((((((((((((((((((((((((((((((((((((((((((((((((11*((1-abs((t-0)))+abs((abs((t-0))-1))))+(18*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(8*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(25*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(13*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(23*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(4*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(14*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(17*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(10*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(8*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(3*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(19*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(19*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(4*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(19*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(6*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(14*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(18*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(20*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(10*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(3*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(24*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(9*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(5*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(13*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(12*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(21*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(0*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(24*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(22*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(8*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(1*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(4*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(10*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(19*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(6*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(21*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(3*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(8*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(7*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(19*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(12*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(6*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(24*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(20*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(8*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(19*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(25*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n(((((((((((((((((((((((((((((((((((((((((((((((((14*((1-abs((t-0)))+abs((abs((t-0))-1))))+(4*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(18*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(15*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(19*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(18*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(16*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(7*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(21*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(17*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(5*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(14*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(17*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(2*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(18*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(10*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(14*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(13*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(14*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(8*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(0*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(7*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(21*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(6*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(13*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(22*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(7*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(4*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(15*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(5*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(9*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(17*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(4*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(0*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(21*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(15*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(18*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(25*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(4*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(21*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(2*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(12*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(14*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(23*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(20*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(6*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(23*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(13*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(12*((1-abs((t-48)))+abs((abs((t-48))-1)))))\n",
"(0*((1-abs((t-0)))+abs((abs((t-0))-1))))\n(0*((1-abs((t-0)))+abs((abs((t-0))-1))))\n",
"((((((((((((((((((((((((((((((((((((((((((((((((((10*((1-abs((t-0)))+abs((abs((t-0))-1))))+(2*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(9*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(18*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(15*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(19*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(16*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(3*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(4*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(18*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(7*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(20*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(9*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(14*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(16*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(17*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(22*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(9*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(6*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(16*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(10*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(22*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(6*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(3*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(9*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(25*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(15*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(18*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(15*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(3*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(9*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(4*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(1*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(8*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(6*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(20*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(16*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(8*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(3*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(15*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(1*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(8*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(5*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(6*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(22*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(3*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(22*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(9*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(17*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(4*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n((((((((((((((((((((((((((((((((((((((((((((((((((11*((1-abs((t-0)))+abs((abs((t-0))-1))))+(8*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(14*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(3*((1-abs((t-3)))+abs((abs((t-3))-1)))))+(23*((1-abs((t-4)))+abs((abs((t-4))-1)))))+(7*((1-abs((t-5)))+abs((abs((t-5))-1)))))+(12*((1-abs((t-6)))+abs((abs((t-6))-1)))))+(9*((1-abs((t-7)))+abs((abs((t-7))-1)))))+(3*((1-abs((t-8)))+abs((abs((t-8))-1)))))+(24*((1-abs((t-9)))+abs((abs((t-9))-1)))))+(13*((1-abs((t-10)))+abs((abs((t-10))-1)))))+(6*((1-abs((t-11)))+abs((abs((t-11))-1)))))+(5*((1-abs((t-12)))+abs((abs((t-12))-1)))))+(21*((1-abs((t-13)))+abs((abs((t-13))-1)))))+(13*((1-abs((t-14)))+abs((abs((t-14))-1)))))+(1*((1-abs((t-15)))+abs((abs((t-15))-1)))))+(16*((1-abs((t-16)))+abs((abs((t-16))-1)))))+(24*((1-abs((t-17)))+abs((abs((t-17))-1)))))+(19*((1-abs((t-18)))+abs((abs((t-18))-1)))))+(5*((1-abs((t-19)))+abs((abs((t-19))-1)))))+(4*((1-abs((t-20)))+abs((abs((t-20))-1)))))+(4*((1-abs((t-21)))+abs((abs((t-21))-1)))))+(0*((1-abs((t-22)))+abs((abs((t-22))-1)))))+(8*((1-abs((t-23)))+abs((abs((t-23))-1)))))+(7*((1-abs((t-24)))+abs((abs((t-24))-1)))))+(0*((1-abs((t-25)))+abs((abs((t-25))-1)))))+(15*((1-abs((t-26)))+abs((abs((t-26))-1)))))+(21*((1-abs((t-27)))+abs((abs((t-27))-1)))))+(1*((1-abs((t-28)))+abs((abs((t-28))-1)))))+(16*((1-abs((t-29)))+abs((abs((t-29))-1)))))+(11*((1-abs((t-30)))+abs((abs((t-30))-1)))))+(3*((1-abs((t-31)))+abs((abs((t-31))-1)))))+(12*((1-abs((t-32)))+abs((abs((t-32))-1)))))+(9*((1-abs((t-33)))+abs((abs((t-33))-1)))))+(5*((1-abs((t-34)))+abs((abs((t-34))-1)))))+(20*((1-abs((t-35)))+abs((abs((t-35))-1)))))+(22*((1-abs((t-36)))+abs((abs((t-36))-1)))))+(20*((1-abs((t-37)))+abs((abs((t-37))-1)))))+(5*((1-abs((t-38)))+abs((abs((t-38))-1)))))+(25*((1-abs((t-39)))+abs((abs((t-39))-1)))))+(20*((1-abs((t-40)))+abs((abs((t-40))-1)))))+(15*((1-abs((t-41)))+abs((abs((t-41))-1)))))+(2*((1-abs((t-42)))+abs((abs((t-42))-1)))))+(15*((1-abs((t-43)))+abs((abs((t-43))-1)))))+(16*((1-abs((t-44)))+abs((abs((t-44))-1)))))+(25*((1-abs((t-45)))+abs((abs((t-45))-1)))))+(24*((1-abs((t-46)))+abs((abs((t-46))-1)))))+(4*((1-abs((t-47)))+abs((abs((t-47))-1)))))+(23*((1-abs((t-48)))+abs((abs((t-48))-1)))))+(25*((1-abs((t-49)))+abs((abs((t-49))-1)))))\n",
"((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(25*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(25*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(0*((1-abs((t-3)))+abs((abs((t-3))-1)))))\n((((0*((1-abs((t-0)))+abs((abs((t-0))-1))))+(25*((1-abs((t-1)))+abs((abs((t-1))-1)))))+(0*((1-abs((t-2)))+abs((abs((t-2))-1)))))+(25*((1-abs((t-3)))+abs((abs((t-3))-1)))))\n"
]
} | 2,200 | 3,000 |
2 | 7 | 615_A. Bulbs | Vasya wants to turn on Christmas lights consisting of m bulbs. Initially, all bulbs are turned off. There are n buttons, each of them is connected to some set of bulbs. Vasya can press any of these buttons. When the button is pressed, it turns on all the bulbs it's connected to. Can Vasya light up all the bulbs?
If Vasya presses the button such that some bulbs connected to it are already turned on, they do not change their state, i.e. remain turned on.
Input
The first line of the input contains integers n and m (1 β€ n, m β€ 100) β the number of buttons and the number of bulbs respectively.
Each of the next n lines contains xi (0 β€ xi β€ m) β the number of bulbs that are turned on by the i-th button, and then xi numbers yij (1 β€ yij β€ m) β the numbers of these bulbs.
Output
If it's possible to turn on all m bulbs print "YES", otherwise print "NO".
Examples
Input
3 4
2 1 4
3 1 3 1
1 2
Output
YES
Input
3 3
1 1
1 2
1 1
Output
NO
Note
In the first sample you can press each button once and turn on all the bulbs. In the 2 sample it is impossible to turn on the 3-rd lamp. | {
"input": [
"3 4\n2 1 4\n3 1 3 1\n1 2\n",
"3 3\n1 1\n1 2\n1 1\n"
],
"output": [
"YES\n",
"NO\n"
]
} | {
"input": [
"3 4\n1 1\n1 2\n1 3\n",
"1 100\n99 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\n",
"2 5\n4 3 1 4 2\n4 2 3 4 5\n",
"1 1\n0\n",
"5 6\n3 1 2 6\n3 1 2 6\n1 1\n2 3 4\n3 1 5 6\n",
"2 4\n3 2 3 4\n1 1\n",
"1 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 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\n",
"1 5\n5 1 1 1 1 5\n",
"1 5\n5 4 4 1 2 3\n",
"1 10\n10 1 2 3 4 5 6 7 8 9 10\n",
"1 4\n3 2 3 4\n",
"5 1\n0\n0\n0\n0\n0\n",
"2 4\n3 1 2 3\n1 4\n",
"5 7\n2 6 7\n5 1 1 1 1 1\n3 6 5 4\n0\n4 4 3 2 1\n",
"1 3\n3 1 2 1\n",
"5 2\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"100 100\n0\n0\n0\n1 53\n0\n0\n1 34\n1 54\n0\n1 14\n0\n1 33\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 82\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n1 26\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 34\n0\n0\n0\n0\n0\n1 3\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n0\n1 40\n0\n0\n0\n1 26\n0\n0\n0\n0\n0\n1 97\n0\n1 5\n0\n0\n0\n0\n0\n",
"1 4\n3 1 2 3\n",
"1 1\n1 1\n",
"100 100\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\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\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\n0\n0\n0\n0\n0\n0\n0\n",
"1 5\n5 1 2 3 4 5\n"
],
"output": [
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n"
]
} | 800 | 500 |
2 | 9 | 634_C. Factory Repairs | A factory produces thimbles in bulk. Typically, it can produce up to a thimbles a day. However, some of the machinery is defective, so it can currently only produce b thimbles each day. The factory intends to choose a k-day period to do maintenance and construction; it cannot produce any thimbles during this time, but will be restored to its full production of a thimbles per day after the k days are complete.
Initially, no orders are pending. The factory receives updates of the form di, ai, indicating that ai new orders have been placed for the di-th day. Each order requires a single thimble to be produced on precisely the specified day. The factory may opt to fill as many or as few of the orders in a single batch as it likes.
As orders come in, the factory owner would like to know the maximum number of orders he will be able to fill if he starts repairs on a given day pi. Help the owner answer his questions.
Input
The first line contains five integers n, k, a, b, and q (1 β€ k β€ n β€ 200 000, 1 β€ b < a β€ 10 000, 1 β€ q β€ 200 000) β the number of days, the length of the repair time, the production rates of the factory, and the number of updates, respectively.
The next q lines contain the descriptions of the queries. Each query is of one of the following two forms:
* 1 di ai (1 β€ di β€ n, 1 β€ ai β€ 10 000), representing an update of ai orders on day di, or
* 2 pi (1 β€ pi β€ n - k + 1), representing a question: at the moment, how many orders could be filled if the factory decided to commence repairs on day pi?
It's guaranteed that the input will contain at least one query of the second type.
Output
For each query of the second type, print a line containing a single integer β the maximum number of orders that the factory can fill over all n days.
Examples
Input
5 2 2 1 8
1 1 2
1 5 3
1 2 1
2 2
1 4 2
1 3 2
2 1
2 3
Output
3
6
4
Input
5 4 10 1 6
1 1 5
1 5 5
1 3 2
1 5 2
2 1
2 2
Output
7
1
Note
Consider the first sample.
We produce up to 1 thimble a day currently and will produce up to 2 thimbles a day after repairs. Repairs take 2 days.
For the first question, we are able to fill 1 order on day 1, no orders on days 2 and 3 since we are repairing, no orders on day 4 since no thimbles have been ordered for that day, and 2 orders for day 5 since we are limited to our production capacity, for a total of 3 orders filled.
For the third question, we are able to fill 1 order on day 1, 1 order on day 2, and 2 orders on day 5, for a total of 4 orders. | {
"input": [
"5 4 10 1 6\n1 1 5\n1 5 5\n1 3 2\n1 5 2\n2 1\n2 2\n",
"5 2 2 1 8\n1 1 2\n1 5 3\n1 2 1\n2 2\n1 4 2\n1 3 2\n2 1\n2 3\n"
],
"output": [
"7\n1\n",
"3\n6\n4\n"
]
} | {
"input": [
"1 1 2 1 1\n2 1\n"
],
"output": [
"0\n"
]
} | 1,700 | 1,000 |
2 | 7 | 663_A. Rebus | You are given a rebus of form ? + ? - ? + ? = n, consisting of only question marks, separated by arithmetic operation '+' and '-', equality and positive integer n. The goal is to replace each question mark with some positive integer from 1 to n, such that equality holds.
Input
The only line of the input contains a rebus. It's guaranteed that it contains no more than 100 question marks, integer n is positive and doesn't exceed 1 000 000, all letters and integers are separated by spaces, arithmetic operations are located only between question marks.
Output
The first line of the output should contain "Possible" (without quotes) if rebus has a solution and "Impossible" (without quotes) otherwise.
If the answer exists, the second line should contain any valid rebus with question marks replaced by integers from 1 to n. Follow the format given in the samples.
Examples
Input
? + ? - ? + ? + ? = 42
Output
Possible
9 + 13 - 39 + 28 + 31 = 42
Input
? - ? = 1
Output
Impossible
Input
? = 1000000
Output
Possible
1000000 = 1000000 | {
"input": [
"? - ? = 1\n",
"? + ? - ? + ? + ? = 42\n",
"? = 1000000\n"
],
"output": [
"Impossible\n",
"Possible\n40 + 1 - 1 + 1 + 1 = 42\n",
"Possible\n1000000 = 1000000\n"
]
} | {
"input": [
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 33\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? = 999999\n",
"? - ? + ? - ? + ? + ? + ? + ? = 2\n",
"? - ? + ? + ? + ? + ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? + ? + ? + ? - ? + ? + ? + ? - ? + ? + ? - ? + ? - ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? + ? + ? - ? - ? - ? - ? + ? - ? - ? + ? + ? - ? + ? + ? - ? - ? - ? + ? + ? - ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? + ? - ? + ? - ? + ? + ? + ? - ? + ? + ? - ? - ? + ? = 123456\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 19\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 100\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 93\n",
"? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? + ? + ? + ? + ? - ? - ? + ? + ? - ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? - ? + ? + ? + ? + ? - ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? = 3\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 43386\n",
"? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 57\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? = 5\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 32\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 9\n",
"? + ? - ? - ? - ? + ? + ? - ? + ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? = 5\n",
"? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? - ? - ? + ? - ? + ? + ? + ? + ? - ? - ? + ? + ? - ? - ? + ? = 1000000\n",
"? + ? - ? + ? + ? = 42\n",
"? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? = 15\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 37\n",
"? + ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? + ? - ? - ? - ? + ? - ? - ? + ? - ? - ? + ? - ? + ? + ? - ? + ? - ? - ? + ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? + ? - ? - ? + ? - ? - ? - ? - ? + ? + ? - ? + ? + ? - ? + ? - ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? = 837454\n",
"? + ? + ? + ? + ? - ? = 3\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? + ? + ? - ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? - ? + ? - ? + ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? + ? - ? - ? = 4\n",
"? + ? - ? + ? + ? - ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? - ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? - ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? - ? + ? + ? = 4\n",
"? + ? + ? + ? - ? = 2\n",
"? + ? + ? + ? + ? - ? - ? = 2\n",
"? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? + ? - ? - ? - ? + ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? - ? = 31\n",
"? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? - ? - ? + ? + ? - ? - ? + ? + ? + ? - ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? + ? + ? - ? + ? + ? - ? - ? + ? - ? + ? + ? + ? = 4\n",
"? - ? + ? - ? + ? + ? - ? + ? - ? + ? + ? - ? + ? - ? - ? + ? - ? - ? + ? - ? + ? - ? - ? - ? - ? - ? + ? - ? + ? + ? + ? + ? + ? + ? + ? + ? - ? - ? + ? - ? + ? + ? - ? + ? - ? + ? - ? - ? + ? - ? - ? + ? - ? - ? - ? + ? - ? - ? + ? - ? + ? + ? - ? - ? + ? - ? - ? + ? + ? - ? + ? - ? + ? + ? + ? + ? + ? - ? - ? + ? - ? - ? - ? + ? = 254253\n",
"? + ? - ? = 1\n",
"? + ? - ? + ? + ? = 2\n"
],
"output": [
"Possible\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 - 33 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 33\n",
"Possible\n999999 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 98 - 1 - 1 = 999999\n",
"Possible\n1 - 2 + 1 - 2 + 1 + 1 + 1 + 1 = 2\n",
"Possible\n123456 - 1 + 2 + 1 + 1 + 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 + 1 - 1 + 1 + 1 + 1 - 1 + 1 + 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 - 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 + 1 + 1 + 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 + 1 + 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 + 1 + 1 - 1 + 1 + 1 - 1 - 1 - 1 + 1 + 1 - 1 - 1 + 1 - 1 - 1 + 1 - 1 + 1 - 1 - 1 - 1 - 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 - 1 + 1 + 1 - 1 - 1 + 1 = 123456\n",
"Possible\n19 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 19 - 1 - 1 - 1 - 1 + 11 - 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 19\n",
"Possible\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 = 100\n",
"Impossible\n",
"Impossible\n",
"Impossible\n",
"Possible\n57 - 1 + 18 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 57\n",
"Possible\n1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 5 = 5\n",
"Possible\n32 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 32 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 32 - 1 - 1 - 1 - 1 + 32 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 32\n",
"Impossible\n",
"Possible\n5 + 5 - 1 - 1 - 1 + 5 + 5 - 1 + 5 + 5 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 - 1 + 5 - 1 - 1 + 2 - 1 + 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 5\n",
"Possible\n999963 - 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 + 1 - 1 + 1 + 1 - 1 + 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 - 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 - 1 - 1 + 1 + 1 - 1 - 1 + 1 = 1000000\n",
"Possible\n40 + 1 - 1 + 1 + 1 = 42\n",
"Possible\n1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 15 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 15 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 15 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 15 + 1 + 1 - 14 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 15\n",
"Possible\n37 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 37 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 37 - 1 - 1 - 1 + 20 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 = 37\n",
"Possible\n837454 + 28 + 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 - 1 - 1 - 1 + 1 - 1 - 1 + 1 - 1 - 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 - 1 + 1 + 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 + 1 - 1 - 1 + 1 - 1 - 1 - 1 - 1 + 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 = 837454\n",
"Possible\n1 + 1 + 1 + 1 + 1 - 2 = 3\n",
"Impossible\n",
"Possible\n1 + 1 - 4 + 1 + 1 - 4 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 - 4 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 - 4 + 1 - 4 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 - 4 - 4 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 - 3 - 1 + 1 + 1 = 4\n",
"Possible\n1 + 1 + 1 + 1 - 2 = 2\n",
"Possible\n1 + 1 + 1 + 1 + 1 - 2 - 1 = 2\n",
"Impossible\n",
"Possible\n1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 - 4 - 4 + 1 + 1 - 4 - 4 + 1 + 1 + 1 - 4 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 - 4 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 4 - 4 + 1 + 1 + 1 - 4 + 1 + 1 - 4 - 4 + 1 - 4 + 1 + 1 + 1 = 4\n",
"Possible\n254253 - 1 + 2 - 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 - 1 + 1 - 1 - 1 + 1 - 1 + 1 - 1 - 1 - 1 - 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 - 1 - 1 + 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 - 1 - 1 + 1 - 1 - 1 + 1 - 1 - 1 - 1 + 1 - 1 - 1 + 1 - 1 + 1 + 1 - 1 - 1 + 1 - 1 - 1 + 1 + 1 - 1 + 1 - 1 + 1 + 1 + 1 + 1 + 1 - 1 - 1 + 1 - 1 - 1 - 1 + 1 = 254253\n",
"Possible\n1 + 1 - 1 = 1\n",
"Possible\n1 + 1 - 2 + 1 + 1 = 2\n"
]
} | 1,800 | 500 |
2 | 16 | 730_J. Bottles | Nick has n bottles of soda left after his birthday. Each bottle is described by two values: remaining amount of soda ai and bottle volume bi (ai β€ bi).
Nick has decided to pour all remaining soda into minimal number of bottles, moreover he has to do it as soon as possible. Nick spends x seconds to pour x units of soda from one bottle to another.
Nick asks you to help him to determine k β the minimal number of bottles to store all remaining soda and t β the minimal time to pour soda into k bottles. A bottle can't store more soda than its volume. All remaining soda should be saved.
Input
The first line contains positive integer n (1 β€ n β€ 100) β the number of bottles.
The second line contains n positive integers a1, a2, ..., an (1 β€ ai β€ 100), where ai is the amount of soda remaining in the i-th bottle.
The third line contains n positive integers b1, b2, ..., bn (1 β€ bi β€ 100), where bi is the volume of the i-th bottle.
It is guaranteed that ai β€ bi for any i.
Output
The only line should contain two integers k and t, where k is the minimal number of bottles that can store all the soda and t is the minimal time to pour the soda into k bottles.
Examples
Input
4
3 3 4 3
4 7 6 5
Output
2 6
Input
2
1 1
100 100
Output
1 1
Input
5
10 30 5 6 24
10 41 7 8 24
Output
3 11
Note
In the first example Nick can pour soda from the first bottle to the second bottle. It will take 3 seconds. After it the second bottle will contain 3 + 3 = 6 units of soda. Then he can pour soda from the fourth bottle to the second bottle and to the third bottle: one unit to the second and two units to the third. It will take 1 + 2 = 3 seconds. So, all the soda will be in two bottles and he will spend 3 + 3 = 6 seconds to do it. | {
"input": [
"2\n1 1\n100 100\n",
"5\n10 30 5 6 24\n10 41 7 8 24\n",
"4\n3 3 4 3\n4 7 6 5\n"
],
"output": [
"1 1\n",
"3 11\n",
"2 6\n"
]
} | {
"input": [
"30\n10 1 8 10 2 6 45 7 3 7 1 3 1 1 14 2 5 19 4 1 13 3 5 6 1 5 1 1 23 1\n98 4 43 41 56 58 85 51 47 55 20 85 93 12 49 15 95 72 20 4 68 24 16 97 21 52 18 69 89 15\n",
"20\n8 1 44 1 12 1 9 11 1 1 5 2 9 16 16 2 1 5 4 1\n88 2 80 33 55 3 74 61 17 11 11 16 42 81 88 14 4 81 60 10\n",
"40\n31 72 17 63 89 13 72 42 39 30 23 29 5 61 88 37 7 23 49 32 41 25 17 15 9 25 30 61 29 66 24 40 75 67 69 22 61 22 13 35\n32 73 20 68 98 13 74 79 41 33 27 85 5 68 95 44 9 24 95 36 45 26 20 31 10 53 37 72 51 84 24 59 80 75 74 22 72 27 13 39\n",
"2\n1 1\n100 1\n",
"40\n9 18 41 31 27 24 76 32 4 38 1 35 21 3 26 32 31 13 41 31 39 14 45 15 12 5 7 14 3 14 19 11 1 81 1 4 7 28 4 62\n70 21 95 63 66 30 100 42 4 80 83 39 34 6 27 55 72 38 43 48 81 53 54 30 63 23 9 59 3 83 83 95 1 81 30 40 35 58 8 66\n",
"90\n1 9 3 3 14 3 2 32 17 3 1 1 4 1 18 1 1 21 9 1 2 10 6 9 27 15 5 1 3 37 1 2 1 12 6 1 8 4 1 5 1 3 8 9 1 9 23 1 1 2 1 2 2 19 2 6 5 6 1 7 12 35 1 2 8 1 11 32 7 4 12 9 18 8 9 27 31 15 16 4 16 13 2 2 1 4 12 17 10 1\n8 52 13 56 42 40 8 98 64 47 84 11 12 1 97 8 8 66 35 4 6 62 22 38 68 57 50 28 28 88 7 57 9 81 14 37 71 57 33 24 2 21 54 58 58 27 79 3 55 13 2 95 17 97 61 22 28 85 78 72 68 80 12 41 98 18 35 70 40 22 98 85 51 70 79 100 68 29 73 45 89 64 53 6 16 29 73 53 24 69\n",
"69\n24 32 19 37 36 7 15 10 54 12 15 46 3 25 12 16 3 8 55 21 23 57 17 45 11 4 25 35 39 3 69 24 78 40 12 39 1 44 4 75 53 60 1 6 30 7 6 39 44 13 31 6 4 4 32 11 52 58 81 2 33 7 29 19 21 26 22 60 24\n57 56 50 64 40 58 31 20 81 14 43 64 48 38 56 71 58 26 98 92 52 88 71 93 11 20 79 39 56 7 92 54 88 58 19 85 12 71 4 87 78 90 29 18 89 13 86 71 100 24 65 95 46 8 91 35 62 66 96 36 80 24 81 58 53 86 89 67 73\n",
"38\n2 1 1 1 1 9 5 2 1 3 4 3 1 7 4 4 8 7 1 5 4 9 1 6 3 4 1 4 1 5 5 1 8 3 1 3 6 3\n2 1 6 2 9 10 6 2 1 5 4 6 1 7 4 6 10 8 8 6 4 10 1 6 4 4 6 4 4 8 5 2 10 7 3 5 6 3\n",
"1\n1\n1\n",
"32\n4 1 1 6 2 5 8 6 5 6 3 2 1 3 1 9 1 2 1 5 2 1 6 5 3 7 3 3 2 5 1 1\n8 1 3 6 4 7 9 8 6 8 10 2 5 3 2 10 1 10 9 5 4 1 8 7 8 7 4 10 4 6 9 2\n",
"86\n5 1 3 1 1 1 1 9 4 1 3 1 4 6 3 2 2 7 1 1 3 1 2 1 1 5 4 3 6 3 3 4 8 2 1 3 1 2 7 2 5 4 2 1 1 2 1 3 2 9 1 4 2 1 1 9 6 1 8 1 7 9 4 3 4 1 3 1 1 3 1 1 3 1 1 10 7 7 4 1 1 3 1 6 1 3\n10 2 5 7 1 4 7 9 4 7 3 1 5 6 3 8 4 10 5 1 9 3 4 2 1 5 7 4 7 7 7 5 9 5 3 3 6 4 7 2 9 7 3 4 2 3 1 5 6 9 10 4 8 10 10 9 7 8 10 1 7 10 10 7 8 5 8 2 1 4 1 2 3 8 1 10 9 7 4 2 1 3 4 9 2 3\n",
"60\n3 3 22 46 23 19 2 27 3 26 34 18 8 50 13 18 23 26 9 14 7 2 17 12 63 25 4 71 14 47 70 13 6 38 28 22 94 10 51 7 29 1 54 12 8 5 4 34 11 24 2 14 54 65 11 30 3 23 12 11\n4 54 69 97 45 53 2 41 4 74 78 66 85 59 19 38 82 28 11 41 15 43 41 43 77 77 50 75 46 66 97 93 50 44 69 22 94 23 61 27 44 1 56 25 31 63 8 37 23 57 6 17 54 68 14 40 43 31 31 60\n",
"1\n100\n100\n",
"73\n69 67 34 35 10 27 30 27 31 48 25 18 81 54 32 54 5 62 20 4 94 2 60 4 6 11 62 68 14 18 42 18 33 71 72 2 29 7 36 60 10 25 17 2 38 77 34 36 74 76 63 32 42 29 22 14 5 1 6 2 14 19 20 19 41 31 16 17 50 49 2 22 51\n73 70 58 54 10 71 59 35 91 61 52 65 90 70 37 80 12 94 78 34 97 4 62 95 10 11 93 100 14 38 56 42 96 96 84 71 69 43 50 79 11 83 95 76 39 79 61 42 89 90 71 62 43 38 39 21 5 40 27 13 21 73 30 46 47 34 23 22 57 59 6 25 72\n",
"70\n13 42 8 56 21 58 39 2 49 39 15 26 62 45 26 8 47 40 9 36 41 2 4 38 6 55 2 41 72 18 10 2 6 11 4 39 19 39 14 59 5 42 19 79 12 3 1 1 21 6 5 9 36 6 38 2 7 26 8 15 66 7 1 30 93 34 45 24 12 20\n26 56 25 60 26 79 99 7 68 92 99 32 81 48 39 97 49 95 18 82 59 4 99 41 10 63 43 54 76 97 73 7 17 43 4 84 35 86 20 63 8 59 87 80 34 3 8 13 49 55 14 11 68 8 41 33 14 39 43 31 89 13 7 88 93 51 84 73 26 30\n",
"81\n21 13 1 25 14 33 33 41 53 89 2 18 61 8 3 35 15 59 2 2 3 5 75 37 1 34 7 12 33 66 6 4 14 78 3 16 12 45 3 2 1 17 17 45 4 30 68 40 44 3 1 21 64 63 14 19 75 63 7 9 12 75 20 28 16 20 53 26 13 46 18 8 28 32 9 29 1 11 75 4 21\n45 90 21 31 36 68 71 47 59 89 61 32 98 67 7 53 90 86 6 28 4 83 93 62 8 56 18 35 33 92 36 37 23 98 44 21 23 79 10 4 2 18 48 87 29 86 79 74 45 3 6 23 79 71 17 39 88 73 50 15 13 92 33 47 83 48 73 33 15 63 43 14 90 72 9 95 1 22 83 20 29\n",
"90\n4 2 21 69 53 39 2 2 8 58 7 5 2 82 7 9 13 10 2 44 1 7 2 1 50 42 36 17 14 46 19 1 50 20 51 46 9 59 73 61 76 4 19 22 1 43 53 2 5 5 32 7 5 42 30 14 32 6 6 15 20 24 13 8 5 19 9 9 7 20 7 2 55 36 5 33 64 20 22 22 9 30 67 38 68 2 13 19 2 9\n48 4 39 85 69 70 11 42 65 77 61 6 60 84 67 15 99 12 2 84 51 17 10 3 50 45 57 53 20 52 64 72 74 44 80 83 70 61 82 81 88 17 22 53 1 44 66 21 10 84 39 11 5 77 93 74 90 17 83 85 70 36 28 87 6 48 22 23 100 22 97 64 96 89 52 49 95 93 34 37 18 69 69 43 83 70 14 54 2 30\n",
"60\n70 19 46 34 43 19 75 42 47 14 66 64 63 58 55 79 38 45 49 80 72 54 96 26 63 41 12 55 14 56 79 51 12 9 14 77 70 75 46 27 45 10 76 59 40 67 55 24 26 90 50 75 12 93 27 39 46 58 66 31\n73 23 48 49 53 23 76 62 65 14 67 89 66 71 59 90 40 47 68 82 81 61 96 48 99 53 13 60 21 63 83 75 15 12 16 80 74 87 66 31 45 12 76 61 45 88 55 32 28 90 50 75 12 94 29 51 57 85 84 38\n",
"1\n50\n100\n",
"20\n59 35 29 57 85 70 26 53 56 3 11 56 43 20 81 72 77 72 36 61\n67 53 80 69 100 71 30 63 60 3 20 56 75 23 97 80 81 85 49 80\n",
"1\n1\n2\n",
"10\n5 12 10 18 10 9 2 20 5 20\n70 91 36 94 46 15 10 73 55 43\n",
"63\n8 23 6 19 1 34 23 1 15 58 22 10 5 14 41 1 16 48 68 5 13 19 1 4 35 2 42 8 45 24 52 44 59 78 5 11 14 41 10 26 60 26 9 15 34 1 14 5 2 6 19 7 4 26 49 39 13 40 18 62 66 8 4\n17 25 39 45 2 44 40 1 82 68 80 27 7 58 90 20 100 80 79 21 53 62 2 11 51 98 78 55 48 37 89 74 83 91 64 30 20 50 24 74 81 94 33 64 56 28 57 9 27 50 81 34 18 33 53 61 39 89 44 77 86 40 89\n",
"80\n11 6 9 6 5 18 21 11 6 6 2 9 4 1 10 12 2 9 1 14 6 12 16 14 4 5 1 16 3 4 6 1 11 30 2 4 1 11 1 6 1 3 2 14 6 14 13 1 10 2 4 14 11 8 28 2 2 3 1 6 26 3 11 4 1 1 29 4 5 4 3 5 1 4 2 12 59 3 18 1\n94 43 36 86 12 75 50 80 55 14 5 97 17 25 28 86 51 56 17 88 48 40 31 39 51 58 4 75 70 30 11 8 61 88 10 25 35 46 31 51 20 79 22 54 19 67 31 89 42 70 30 37 35 78 95 31 31 51 31 50 54 90 63 27 6 2 92 80 48 9 27 33 61 63 30 38 95 46 86 45\n",
"10\n96 4 51 40 89 36 35 38 4 82\n99 8 56 42 94 46 35 43 4 84\n",
"70\n20 7 5 7 3 10 1 14 33 1 5 3 4 21 7 7 1 2 2 2 8 15 18 2 7 1 1 1 15 2 27 2 6 21 4 2 7 5 1 6 13 36 13 1 10 5 8 13 24 2 10 16 11 9 4 1 1 8 6 26 9 3 3 2 8 5 17 9 1 13\n85 36 76 36 65 24 37 56 78 42 33 13 29 93 31 38 1 59 71 31 28 55 70 14 33 9 1 5 41 22 86 41 92 89 88 10 39 54 6 32 58 82 49 22 62 44 29 19 54 12 59 54 51 80 66 16 22 74 8 68 35 34 24 8 22 14 55 76 32 75\n",
"33\n33 20 33 40 58 50 5 6 13 12 4 33 11 50 12 19 16 36 68 57 23 17 6 22 39 58 49 21 10 35 35 17 12\n62 22 53 44 66 60 97 7 33 18 10 59 33 77 55 63 91 86 87 86 27 62 65 53 46 69 64 63 10 53 52 23 24\n",
"2\n1 1\n1 1\n",
"50\n2 1 2 2 38 19 1 2 7 1 2 5 5 1 14 53 21 1 17 9 4 1 24 8 1 1 1 5 4 14 37 1 15 1 4 15 1 3 3 16 17 1 10 18 36 14 25 8 8 48\n45 24 8 12 83 37 6 20 88 9 10 11 28 9 60 98 76 20 84 95 15 45 74 48 37 2 46 34 99 57 94 70 31 22 11 88 58 25 20 73 64 64 81 80 59 64 92 31 43 89\n",
"50\n72 9 46 38 43 75 63 73 70 11 9 48 32 93 33 24 46 44 27 78 43 2 26 84 42 78 35 34 76 36 67 79 82 63 17 26 30 43 35 34 54 37 13 65 8 37 8 8 70 79\n96 19 54 54 44 75 66 80 71 12 9 54 38 95 39 25 48 52 39 86 44 2 27 99 54 99 35 44 80 36 86 93 98 73 27 30 39 43 80 34 61 38 13 69 9 37 8 9 75 97\n",
"1\n1\n100\n",
"80\n2 8 36 12 22 41 1 42 6 66 62 94 37 1 5 1 82 8 9 31 14 8 15 5 21 8 5 22 1 17 1 44 1 12 8 45 37 38 13 4 13 4 8 8 3 15 13 53 22 8 19 14 16 7 7 49 1 10 31 33 7 47 61 6 9 48 6 25 16 4 43 1 5 34 8 22 31 38 59 45\n33 90 47 22 28 67 4 44 13 76 65 94 40 8 12 21 88 15 74 37 37 22 19 53 91 26 88 99 1 61 3 75 2 14 8 96 41 76 13 96 41 44 66 48 40 17 41 60 48 9 62 46 56 46 31 63 6 84 68 43 7 88 62 36 52 92 23 27 46 87 52 9 50 44 33 30 33 63 79 72\n",
"20\n24 22 4 34 76 13 78 1 81 51 72 11 25 46 22 33 60 42 25 19\n40 81 10 34 84 16 90 38 99 81 100 19 79 65 26 80 62 47 76 47\n",
"30\n33 4 1 42 86 85 35 51 45 88 23 35 79 92 81 46 47 32 41 17 18 36 28 58 31 15 17 38 49 78\n36 4 1 49 86 86 43 51 64 93 24 42 82 98 92 47 56 41 41 25 20 53 32 61 53 26 20 38 49 98\n",
"2\n1 1\n1 100\n",
"10\n18 42 5 1 26 8 40 34 8 29\n18 71 21 67 38 13 99 37 47 76\n",
"35\n9 7 34 3 2 6 36 3 26 12 17 8 5 32 55 10 24 19 2 3 30 17 14 1 33 36 42 14 51 1 2 22 13 34 28\n9 9 55 17 16 12 37 14 27 58 51 16 10 37 69 15 43 26 14 60 86 34 54 1 37 50 58 18 92 66 7 24 25 92 30\n",
"60\n9 9 11 16 58 6 25 6 3 23 1 14 1 8 4 2 1 18 10 1 13 4 23 1 38 6 1 13 5 1 1 1 2 1 1 17 1 24 18 20 2 1 9 26 1 12 3 6 7 17 18 1 2 9 3 6 3 30 7 12\n47 82 78 52 99 51 90 23 58 49 2 98 100 60 25 60 6 69 79 6 91 47 69 18 99 46 30 51 11 3 42 17 33 61 14 81 16 76 72 94 13 5 51 88 26 43 80 31 26 70 93 76 18 67 25 86 60 81 40 38\n",
"30\n29 3 2 13 3 12 73 22 37 48 59 17 2 13 69 43 32 14 4 2 61 22 40 30 1 4 46 5 65 17\n55 3 3 92 25 27 97 40 55 74 91 31 7 33 72 62 61 40 16 2 70 61 67 72 8 5 48 9 75 84\n",
"77\n44 2 13 14 8 46 65 14 1 39 12 18 15 10 2 40 71 40 17 1 16 72 13 7 41 23 81 12 4 1 19 18 41 35 23 56 21 5 17 47 88 1 24 15 48 15 1 13 50 5 31 16 21 47 4 1 49 2 15 23 46 47 27 22 23 40 29 4 30 50 51 12 20 14 41 25 12\n57 16 72 59 28 80 74 19 4 60 52 52 97 20 5 69 84 66 63 38 50 79 24 84 58 92 99 36 38 97 66 79 41 48 26 95 28 38 28 72 95 71 30 15 63 17 7 69 90 29 89 40 21 83 73 24 51 14 15 74 100 88 74 27 46 61 38 4 32 52 52 51 47 51 81 75 19\n",
"70\n17 70 52 31 15 51 8 38 3 43 2 34 7 16 58 29 73 23 41 88 9 24 24 90 33 84 10 29 67 17 47 72 11 79 22 5 8 65 23 7 29 31 11 42 11 14 9 3 54 22 38 34 2 4 39 13 11 34 3 35 22 18 3 57 23 21 13 23 78 7\n18 72 58 55 87 56 9 39 60 79 74 82 9 39 66 32 89 25 46 95 26 31 28 94 36 96 19 37 77 61 50 82 22 81 37 9 11 96 33 12 90 74 11 42 88 86 24 3 85 31 82 81 3 7 69 47 27 51 49 98 33 40 5 94 83 35 21 24 89 49\n",
"50\n48 29 72 22 99 27 40 23 39 4 46 29 39 16 47 35 79 7 15 23 50 34 35 22 9 2 51 10 2 42 4 3 30 2 72 19 50 20 11 29 1 2 1 7 7 6 7 75 40 69\n81 36 76 26 100 41 99 39 52 73 83 51 54 86 73 49 79 27 83 90 100 40 49 81 22 54 85 21 26 79 36 96 73 10 98 31 65 39 89 39 1 32 5 20 71 39 87 80 60 86\n",
"40\n10 32 10 7 10 6 25 3 18 4 24 4 8 14 6 15 11 8 2 8 2 5 19 9 5 5 3 34 5 1 6 6 1 4 5 26 34 2 21 1\n35 66 54 11 58 68 75 12 69 94 80 33 23 48 45 66 94 53 25 53 83 30 64 49 69 84 73 85 26 41 10 65 23 56 58 93 58 7 100 7\n",
"35\n21 2 68 56 41 25 42 17 21 20 29 26 38 37 29 77 43 13 32 48 38 31 15 8 52 6 63 45 70 2 21 13 3 14 47\n46 83 100 87 59 95 47 33 56 60 38 76 63 75 60 92 65 43 56 94 70 80 46 40 64 6 83 50 75 19 52 66 13 88 62\n",
"77\n19 34 39 56 1 2 47 8 17 28 23 45 18 7 5 3 11 20 30 24 13 34 11 1 4 14 68 23 13 33 3 8 1 5 8 23 12 1 19 14 22 67 26 55 10 1 63 82 82 6 38 5 6 11 1 62 1 12 5 40 19 20 37 9 5 3 2 44 13 20 44 32 11 29 12 19 35\n28 41 43 68 1 36 57 13 84 89 26 92 47 19 7 94 79 75 74 42 32 44 46 23 96 46 82 86 91 33 25 11 12 68 22 31 89 14 81 32 50 94 27 66 50 39 98 90 91 11 69 6 45 19 15 74 22 31 7 92 23 98 88 32 8 4 2 51 79 69 70 43 16 60 29 20 98\n",
"90\n9 2 2 3 4 1 9 8 3 3 1 1 1 1 2 2 1 3 4 8 8 1 2 7 3 4 5 6 1 2 9 4 2 5 6 1 1 2 6 5 1 4 3 2 4 1 1 3 1 1 3 1 8 3 1 4 1 2 2 3 5 2 8 6 2 5 2 1 4 2 1 5 4 2 1 1 2 1 1 6 4 4 3 4 1 4 4 6 2 3\n10 6 2 3 10 1 10 10 6 4 1 3 6 1 2 5 3 7 7 9 9 2 3 8 3 4 9 7 8 4 10 7 8 10 9 5 1 4 6 5 1 9 10 4 6 4 1 3 3 1 6 1 9 4 1 6 4 5 5 10 7 9 9 10 4 5 2 1 4 2 1 7 6 5 3 9 2 5 1 8 6 4 6 10 1 7 5 9 6 4\n",
"90\n1 43 87 1 6 12 49 6 3 9 38 1 64 49 11 18 5 1 46 25 30 82 17 4 8 9 5 5 4 1 10 4 13 42 44 90 1 11 27 23 25 4 12 19 48 3 59 48 39 14 1 5 64 46 39 24 28 77 25 20 3 14 28 2 20 63 2 1 13 11 44 49 61 76 20 1 3 42 38 8 69 17 27 18 29 54 2 1 2 7\n8 96 91 1 11 20 83 34 41 88 54 4 65 82 48 60 62 18 76 74 75 89 87 8 11 32 67 7 5 1 92 88 57 92 76 95 35 58 68 23 30 25 12 31 85 5 89 84 71 23 1 5 76 56 57 57 76 94 33 34 66 20 54 5 22 69 2 19 28 62 74 88 91 86 30 6 3 48 80 10 84 20 44 37 81 100 12 3 6 8\n",
"80\n36 80 23 45 68 72 2 69 84 33 3 43 6 64 82 54 15 15 17 4 3 29 74 14 53 50 52 27 32 18 60 62 50 29 28 48 77 11 24 17 3 55 58 20 4 32 55 16 27 60 5 77 23 31 11 60 21 65 38 39 82 58 51 78 24 30 75 79 5 41 94 10 14 7 1 26 21 41 6 52\n37 93 24 46 99 74 2 93 86 33 3 44 6 71 88 65 15 19 24 4 3 40 82 14 62 81 56 30 33 30 62 62 70 29 31 53 78 13 27 31 3 65 61 20 5 41 58 25 27 61 6 87 26 31 13 62 25 71 44 45 82 75 62 95 24 44 82 94 6 50 94 10 15 15 1 29 35 60 8 68\n",
"83\n13 20 5 29 48 53 88 17 11 5 44 15 85 13 2 55 6 16 57 29 12 15 12 92 21 25 1 2 4 5 2 22 8 18 22 2 3 10 43 71 3 41 1 73 6 18 32 63 26 13 6 75 19 10 41 30 15 12 14 8 15 77 73 7 5 39 83 19 2 2 3 61 53 43 3 15 76 29 8 46 19 3 8\n54 34 15 58 50 67 100 43 30 15 46 26 94 75 2 58 85 38 68 98 83 51 82 100 61 27 5 5 41 89 17 34 10 48 48 4 15 13 71 75 4 44 2 82 18 82 59 96 26 13 66 95 81 33 85 45 16 92 41 37 85 78 83 17 7 72 83 38 69 24 18 76 71 66 3 66 78 31 73 72 43 89 49\n",
"70\n67 38 59 72 9 64 12 3 51 58 50 4 16 46 62 77 58 73 7 92 48 9 90 50 35 9 61 57 50 20 48 61 27 77 47 6 83 28 78 14 68 32 2 2 22 57 34 71 26 74 3 76 41 66 30 69 34 16 29 7 14 19 11 5 13 66 19 19 17 55\n69 41 84 91 10 77 12 7 70 74 55 7 30 63 66 79 89 88 10 93 89 15 91 81 41 26 65 67 55 37 73 94 34 94 47 6 90 31 100 25 69 33 2 3 43 97 37 95 35 85 3 78 50 86 30 73 34 21 32 13 21 32 11 5 13 80 23 20 17 58\n",
"85\n20 47 52 6 5 15 35 42 5 84 4 8 61 47 7 50 20 24 15 27 86 28 1 39 1 2 63 2 31 33 47 4 33 68 20 4 4 42 20 67 7 10 46 4 22 36 30 40 4 15 51 2 39 50 65 48 34 6 50 19 32 48 8 23 42 70 69 8 29 81 5 1 7 21 3 30 78 6 2 1 3 69 34 34 18\n74 64 89 61 5 17 75 43 13 87 30 51 93 54 7 76 44 44 98 77 86 97 1 41 1 3 69 3 80 87 67 6 90 100 31 5 7 46 99 67 9 44 56 7 39 39 55 80 80 33 77 9 89 79 86 53 49 49 72 87 43 84 24 23 43 94 74 17 54 96 28 64 14 42 91 60 87 69 20 1 30 95 44 50 20\n"
],
"output": [
"3 122\n",
"2 90\n",
"24 290\n",
"1 1\n",
"11 560\n",
"8 562\n",
"22 801\n",
"19 40\n",
"1 0\n",
"13 46\n",
"32 101\n",
"19 535\n",
"1 0\n",
"30 808\n",
"21 867\n",
"26 754\n",
"25 955\n",
"42 368\n",
"1 0\n",
"13 187\n",
"1 0\n",
"2 71\n",
"18 638\n",
"8 434\n",
"8 8\n",
"7 426\n",
"13 356\n",
"2 0\n",
"6 337\n",
"34 283\n",
"1 0\n",
"21 909\n",
"9 217\n",
"22 123\n",
"1 1\n",
"3 100\n",
"10 307\n",
"7 368\n",
"10 310\n",
"24 932\n",
"26 756\n",
"17 563\n",
"5 281\n",
"14 432\n",
"19 937\n",
"35 109\n",
"26 899",
"50 363",
"26 944",
"38 484",
"29 987"
]
} | 1,900 | 0 |
2 | 7 | 776_A. A Serial Killer | Our beloved detective, Sherlock is currently trying to catch a serial killer who kills a person each day. Using his powers of deduction, he came to know that the killer has a strategy for selecting his next victim.
The killer starts with two potential victims on his first day, selects one of these two, kills selected victim and replaces him with a new person. He repeats this procedure each day. This way, each day he has two potential victims to choose from. Sherlock knows the initial two potential victims. Also, he knows the murder that happened on a particular day and the new person who replaced this victim.
You need to help him get all the pairs of potential victims at each day so that Sherlock can observe some pattern.
Input
First line of input contains two names (length of each of them doesn't exceed 10), the two initials potential victims. Next line contains integer n (1 β€ n β€ 1000), the number of days.
Next n lines contains two names (length of each of them doesn't exceed 10), first being the person murdered on this day and the second being the one who replaced that person.
The input format is consistent, that is, a person murdered is guaranteed to be from the two potential victims at that time. Also, all the names are guaranteed to be distinct and consists of lowercase English letters.
Output
Output n + 1 lines, the i-th line should contain the two persons from which the killer selects for the i-th murder. The (n + 1)-th line should contain the two persons from which the next victim is selected. In each line, the two names can be printed in any order.
Examples
Input
ross rachel
4
ross joey
rachel phoebe
phoebe monica
monica chandler
Output
ross rachel
joey rachel
joey phoebe
joey monica
joey chandler
Input
icm codeforces
1
codeforces technex
Output
icm codeforces
icm technex
Note
In first example, the killer starts with ross and rachel.
* After day 1, ross is killed and joey appears.
* After day 2, rachel is killed and phoebe appears.
* After day 3, phoebe is killed and monica appears.
* After day 4, monica is killed and chandler appears. | {
"input": [
"icm codeforces\n1\ncodeforces technex\n",
"ross rachel\n4\nross joey\nrachel phoebe\nphoebe monica\nmonica chandler\n"
],
"output": [
"icm codeforces\nicm technex\n",
"ross rachel\njoey rachel\njoey phoebe\njoey monica\njoey chandler\n"
]
} | {
"input": [
"wwwww w\n8\nwwwww wwwwwwww\nwwwwwwww wwwwwwwww\nwwwwwwwww wwwwwwwwww\nw www\nwwwwwwwwww wwww\nwwww ww\nwww wwwwww\nwwwwww wwwwwww\n",
"k d\n17\nk l\nd v\nv z\nl r\nz i\nr s\ns p\np w\nw j\nj h\ni c\nh m\nm q\nc o\no g\nq x\nx n\n",
"wxz hbeqwqp\n7\nhbeqwqp cpieghnszh\ncpieghnszh tlqrpd\ntlqrpd ttwrtio\nttwrtio xapvds\nxapvds zk\nwxz yryk\nzk b\n",
"ze udggmyop\n4\nze szhrbmft\nudggmyop mjorab\nszhrbmft ojdtfnzxj\nojdtfnzxj yjlkg\n",
"bwyplnjn zkms\n26\nzkms nzmcsytxh\nnzmcsytxh yujsb\nbwyplnjn gtbzhudpb\ngtbzhudpb hpk\nyujsb xvy\nhpk wrwnfokml\nwrwnfokml ndouuikw\nndouuikw ucgrja\nucgrja tgfmpldz\nxvy nycrfphn\nnycrfphn quvs\nquvs htdy\nhtdy k\ntgfmpldz xtdpkxm\nxtdpkxm suwqxs\nk fv\nsuwqxs qckllwy\nqckllwy diun\nfv lefa\nlefa gdoqjysx\ndiun dhpz\ngdoqjysx bdmqdyt\ndhpz dgz\ndgz v\nbdmqdyt aswy\naswy ydkayhlrnm\n",
"iii iiiiii\n7\niii iiiiiiiiii\niiiiiiiiii iiii\niiii i\niiiiii iiiiiiii\niiiiiiii iiiiiiiii\ni iiiii\niiiii ii\n",
"wced gnsgv\n23\ngnsgv japawpaf\njapawpaf nnvpeu\nnnvpeu a\na ddupputljq\nddupputljq qyhnvbh\nqyhnvbh pqwijl\nwced khuvs\nkhuvs bjkh\npqwijl ysacmboc\nbjkh srf\nsrf jknoz\njknoz hodf\nysacmboc xqtkoyh\nhodf rfp\nxqtkoyh bivgnwqvoe\nbivgnwqvoe nknf\nnknf wuig\nrfp e\ne bqqknq\nwuig sznhhhu\nbqqknq dhrtdld\ndhrtdld n\nsznhhhu bguylf\n",
"a b\n3\na c\nb d\nd e\n",
"q s\n10\nq b\nb j\ns g\nj f\nf m\ng c\nc a\nm d\nd z\nz o\n",
"qqqqqqqqqq qqqqqqqq\n3\nqqqqqqqq qqqqqqqqq\nqqqqqqqqq qqqqq\nqqqqq q\n"
],
"output": [
"wwwww w\nwwwwwwww w\nwwwwwwwww w\nwwwwwwwwww w\nwwwwwwwwww www\nwwww www\nww www\nww wwwwww\nww wwwwwww\n",
"k d\nl d\nl v\nl z\nr z\nr i\ns i\np i\nw i\nj i\nh i\nh c\nm c\nq c\nq o\nq g\nx g\nn g\n",
"wxz hbeqwqp\nwxz cpieghnszh\nwxz tlqrpd\nwxz ttwrtio\nwxz xapvds\nwxz zk\nyryk zk\nyryk b\n",
"ze udggmyop\nszhrbmft udggmyop\nszhrbmft mjorab\nojdtfnzxj mjorab\nyjlkg mjorab\n",
"bwyplnjn zkms\nbwyplnjn nzmcsytxh\nbwyplnjn yujsb\ngtbzhudpb yujsb\nhpk yujsb\nhpk xvy\nwrwnfokml xvy\nndouuikw xvy\nucgrja xvy\ntgfmpldz xvy\ntgfmpldz nycrfphn\ntgfmpldz quvs\ntgfmpldz htdy\ntgfmpldz k\nxtdpkxm k\nsuwqxs k\nsuwqxs fv\nqckllwy fv\ndiun fv\ndiun lefa\ndiun gdoqjysx\ndhpz gdoqjysx\ndhpz bdmqdyt\ndgz bdmqdyt\nv bdmqdyt\nv aswy\nv ydkayhlrnm\n",
"iii iiiiii\niiiiiiiiii iiiiii\niiii iiiiii\ni iiiiii\ni iiiiiiii\ni iiiiiiiii\niiiii iiiiiiiii\nii iiiiiiiii\n",
"wced gnsgv\nwced japawpaf\nwced nnvpeu\nwced a\nwced ddupputljq\nwced qyhnvbh\nwced pqwijl\nkhuvs pqwijl\nbjkh pqwijl\nbjkh ysacmboc\nsrf ysacmboc\njknoz ysacmboc\nhodf ysacmboc\nhodf xqtkoyh\nrfp xqtkoyh\nrfp bivgnwqvoe\nrfp nknf\nrfp wuig\ne wuig\nbqqknq wuig\nbqqknq sznhhhu\ndhrtdld sznhhhu\nn sznhhhu\nn bguylf\n",
"a b\nc b\nc d\nc e\n",
"q s\nb s\nj s\nj g\nf g\nm g\nm c\nm a\nd a\nz a\no a\n",
"qqqqqqqqqq qqqqqqqq\nqqqqqqqqqq qqqqqqqqq\nqqqqqqqqqq qqqqq\nqqqqqqqqqq q\n"
]
} | 900 | 500 |
2 | 8 | 7_B. Memory Manager | There is little time left before the release of the first national operating system BerlOS. Some of its components are not finished yet β the memory manager is among them. According to the developers' plan, in the first release the memory manager will be very simple and rectilinear. It will support three operations:
* alloc n β to allocate n bytes of the memory and return the allocated block's identifier x;
* erase x β to erase the block with the identifier x;
* defragment β to defragment the free memory, bringing all the blocks as close to the beginning of the memory as possible and preserving their respective order;
The memory model in this case is very simple. It is a sequence of m bytes, numbered for convenience from the first to the m-th.
The first operation alloc n takes as the only parameter the size of the memory block that is to be allocated. While processing this operation, a free block of n successive bytes is being allocated in the memory. If the amount of such blocks is more than one, the block closest to the beginning of the memory (i.e. to the first byte) is prefered. All these bytes are marked as not free, and the memory manager returns a 32-bit integer numerical token that is the identifier of this block. If it is impossible to allocate a free block of this size, the function returns NULL.
The second operation erase x takes as its parameter the identifier of some block. This operation frees the system memory, marking the bytes of this block as free for further use. In the case when this identifier does not point to the previously allocated block, which has not been erased yet, the function returns ILLEGAL_ERASE_ARGUMENT.
The last operation defragment does not have any arguments and simply brings the occupied memory sections closer to the beginning of the memory without changing their respective order.
In the current implementation you are to use successive integers, starting with 1, as identifiers. Each successful alloc operation procession should return following number. Unsuccessful alloc operations do not affect numeration.
You are to write the implementation of the memory manager. You should output the returned value for each alloc command. You should also output ILLEGAL_ERASE_ARGUMENT for all the failed erase commands.
Input
The first line of the input data contains two positive integers t and m (1 β€ t β€ 100;1 β€ m β€ 100), where t β the amount of operations given to the memory manager for processing, and m β the available memory size in bytes. Then there follow t lines where the operations themselves are given. The first operation is alloc n (1 β€ n β€ 100), where n is an integer. The second one is erase x, where x is an arbitrary 32-bit integer numerical token. The third operation is defragment.
Output
Output the sequence of lines. Each line should contain either the result of alloc operation procession , or ILLEGAL_ERASE_ARGUMENT as a result of failed erase operation procession. Output lines should go in the same order in which the operations are processed. Successful procession of alloc operation should return integers, starting with 1, as the identifiers of the allocated blocks.
Examples
Input
6 10
alloc 5
alloc 3
erase 1
alloc 6
defragment
alloc 6
Output
1
2
NULL
3 | {
"input": [
"6 10\nalloc 5\nalloc 3\nerase 1\nalloc 6\ndefragment\nalloc 6\n"
],
"output": [
"1\n2\nNULL\n3\n"
]
} | {
"input": [
"3 1\nerase -1\nerase 0\nerase -2147483648\n",
"26 25\ndefragment\nerase 1\nerase -1560200883\nalloc 44\ndefragment\nalloc 75\nalloc 22\ndefragment\nerase 4\ndefragment\nalloc 57\nalloc 53\nerase 4\nerase -1639632026\nerase -2121605039\nerase 3\nalloc 51\nalloc 65\ndefragment\nerase 2\nerase 4\nalloc 52\nerase 3\ndefragment\nerase -1842529282\nerase 3\n",
"12 40\nerase 1\nalloc 21\nalloc 5\nalloc 7\ndefragment\ndefragment\nerase 2\nalloc 83\nerase 4\ndefragment\nalloc 59\ndefragment\n",
"44 46\nalloc 28\nalloc 36\ndefragment\nerase -937404236\nalloc 71\ndefragment\nalloc 81\nalloc 51\nerase 3\ndefragment\nalloc 48\nerase 1\ndefragment\nalloc 36\ndefragment\ndefragment\nerase 1\ndefragment\ndefragment\nerase -1173350787\nalloc 94\nerase 5\ndefragment\nerase 9\nalloc 98\nerase 7\ndefragment\nerase 5\nerase 1\ndefragment\nerase 2\ndefragment\nerase 4\ndefragment\nerase 9\nalloc 8\ndefragment\nerase 9\ndefragment\ndefragment\ndefragment\nerase 1\nalloc 70\nerase 9\n",
"7 6\nalloc 1\nalloc 2\nalloc 3\nerase 1\ndefragment\nerase 3\nalloc 4\n",
"47 43\nerase 1\nalloc 95\nalloc 53\nerase 2\ndefragment\nalloc 100\nerase 4\nerase 2\nerase -849472053\ndefragment\nerase -638355221\nalloc 90\nerase 3\nerase 2\ndefragment\nalloc 17\nerase 5\ndefragment\nerase 6\ndefragment\nerase 3\ndefragment\ndefragment\nalloc 99\nalloc 69\nalloc 80\nerase 9\nerase 5\ndefragment\nerase 7\ndefragment\nalloc 93\ndefragment\ndefragment\nalloc 25\ndefragment\nalloc 14\nerase 8\nerase 4\ndefragment\ndefragment\nalloc 96\nerase 9\nalloc 63\nerase 8\ndefragment\nerase 10\n",
"8 50\nalloc 51\ndefragment\nalloc 100\ndefragment\nerase 1\nalloc 50\ndefragment\nalloc 50\n",
"6 1\ndefragment\nalloc 10\nalloc 1\nerase -1\nerase 1\nerase 1\n",
"26 25\nalloc 25\nerase 1\nalloc 24\nerase 2\nalloc 23\nerase 3\nalloc 24\nerase 4\nalloc 24\nerase 5\nalloc 21\nerase 6\nalloc 24\nerase 7\nalloc 25\nerase 8\nalloc 25\nerase 9\nalloc 24\nerase 10\nalloc 25\nerase 11\nalloc 25\nerase 12\nalloc 25\nerase 13\n",
"10 10\nalloc 10\nerase -1\nerase 1\nalloc 5\nerase -1\nalloc 5\nerase 0\nalloc 5\nerase 0\nalloc 5\n",
"37 74\nalloc 11\ndefragment\nerase 1\ndefragment\nerase 2\ndefragment\nalloc 90\nerase 3\nerase 2\nerase 3\nerase 1\nerase 1\nalloc 38\nalloc 19\nerase 1\nerase 3\ndefragment\nalloc 93\nerase 5\nerase 4\nalloc 66\nalloc 71\nerase 5\ndefragment\ndefragment\ndefragment\ndefragment\nerase 7\nalloc 47\nerase -95616683\nerase 2\nalloc 28\nalloc 32\nerase 11\nalloc 50\ndefragment\ndefragment\n",
"19 46\nalloc 21\nerase 2\nerase 1\ndefragment\nalloc 4\ndefragment\ndefragment\nalloc 40\nerase 1\ndefragment\ndefragment\nalloc 68\nerase -388966015\nalloc 85\nalloc 53\nerase 4\ndefragment\nalloc 49\nalloc 88\n",
"12 10\nalloc 6\nalloc 2\nerase 1\nalloc 4\nalloc 2\nerase 3\nalloc 2\nalloc 3\nalloc 1\nalloc 1\nalloc 1\nalloc 1\n",
"16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 2\ndefragment\nalloc 6\n",
"14 100\nalloc 99\nalloc 1\nalloc 1\nerase 2\nalloc 1\nerase 4\nerase 1\nalloc 100\nalloc 1\nalloc 99\ndefragment\nerase 4\nalloc 100\nalloc 99\n",
"22 9\nalloc 9\nerase 1\nalloc 9\nerase 2\nalloc 9\nerase 3\nalloc 9\nerase 4\nalloc 9\nerase 5\nalloc 9\nerase 6\nalloc 9\nerase 7\nalloc 9\nerase 8\nalloc 9\nerase 9\nalloc 9\nerase 10\nalloc 9\nerase 11\n",
"42 98\ndefragment\ndefragment\ndefragment\ndefragment\ndefragment\nalloc 5\nalloc 66\ndefragment\nerase 3\nalloc 53\ndefragment\nerase 4\nerase 2\nalloc 70\nerase 3\ndefragment\ndefragment\nerase 2\nerase 3\nerase -1327931832\nalloc 93\nalloc 64\nerase 7\nerase 6\nerase 3\nalloc 61\nalloc 12\nalloc 65\nerase 2\nalloc 46\nerase 11\nerase 9\nerase 9\nerase 6\nalloc 2\nalloc 78\ndefragment\nerase 13\nerase 6\nerase 10\nalloc 53\nalloc 46\n",
"16 10\nalloc 10\ndefragment\ndefragment\ndefragment\nalloc 10\nerase 1\nerase 2\nalloc 6\ndefragment\ndefragment\nalloc 4\ndefragment\ndefragment\nerase 3\ndefragment\nalloc 6\n",
"38 18\nalloc 72\nerase 2\nalloc 50\ndefragment\nerase 3\ndefragment\nalloc 43\nalloc 41\ndefragment\ndefragment\nalloc 26\nalloc 46\nalloc 16\nalloc 15\ndefragment\ndefragment\nalloc 95\nerase 7\nerase 7\nerase 5\nerase 2\nerase 9\nerase 7\nalloc 43\ndefragment\nerase 7\ndefragment\nalloc 48\nalloc 77\nerase 10\nerase 11\nalloc 16\nalloc 84\nerase 1\ndefragment\nalloc 86\ndefragment\nerase 13\n",
"16 49\nerase -751005193\ndefragment\nalloc 37\nalloc 82\nerase 3\nerase 1\nalloc 80\nalloc 51\ndefragment\nalloc 74\nerase 1\nalloc 91\ndefragment\ndefragment\nalloc 98\ndefragment\n",
"22 9\nerase 1\nalloc 6\nalloc 65\nerase 1\nalloc 87\nerase -1638927047\nalloc 5\nerase 2\nalloc 70\ndefragment\nalloc 20\nalloc 48\nerase -69401977\nalloc 20\ndefragment\nerase 7\ndefragment\nerase 9\nerase 7\nerase 4\ndefragment\nalloc 66\n",
"7 100\nalloc 100\nerase 2147483647\nerase 1\nalloc 50\nalloc 50\nerase 3\nerase -2147483648\n"
],
"output": [
"ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n",
"ILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n1\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n",
"ILLEGAL_ERASE_ARGUMENT\n1\n2\n3\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n",
"1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n",
"1\n2\n3\n4\n",
"ILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\n2\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n",
"NULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n1\nNULL\n",
"NULL\n1\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n",
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n",
"1\nILLEGAL_ERASE_ARGUMENT\n2\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\n",
"1\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n4\n5\nILLEGAL_ERASE_ARGUMENT\nNULL\n",
"1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n",
"1\n2\n3\n4\n5\nNULL\n6\n7\n8\n9\n",
"1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\n4\n",
"1\n2\nNULL\n3\nILLEGAL_ERASE_ARGUMENT\nNULL\n4\nNULL\nNULL\nNULL\n",
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n",
"1\n2\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\n3\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\n4\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n",
"1\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\n3\nNULL\n",
"NULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nNULL\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n",
"ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nNULL\n",
"ILLEGAL_ERASE_ARGUMENT\n1\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\n2\nNULL\nNULL\nNULL\nILLEGAL_ERASE_ARGUMENT\nNULL\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nILLEGAL_ERASE_ARGUMENT\nNULL\n",
"1\nILLEGAL_ERASE_ARGUMENT\n2\n3\nILLEGAL_ERASE_ARGUMENT\n"
]
} | 1,600 | 0 |
2 | 10 | 820_D. Mister B and PR Shifts | Some time ago Mister B detected a strange signal from the space, which he started to study.
After some transformation the signal turned out to be a permutation p of length n or its cyclic shift. For the further investigation Mister B need some basis, that's why he decided to choose cyclic shift of this permutation which has the minimum possible deviation.
Let's define the deviation of a permutation p as <image>.
Find a cyclic shift of permutation p with minimum possible deviation. If there are multiple solutions, print any of them.
Let's denote id k (0 β€ k < n) of a cyclic shift of permutation p as the number of right shifts needed to reach this shift, for example:
* k = 0: shift p1, p2, ... pn,
* k = 1: shift pn, p1, ... pn - 1,
* ...,
* k = n - 1: shift p2, p3, ... pn, p1.
Input
First line contains single integer n (2 β€ n β€ 106) β the length of the permutation.
The second line contains n space-separated integers p1, p2, ..., pn (1 β€ pi β€ n) β the elements of the permutation. It is guaranteed that all elements are distinct.
Output
Print two integers: the minimum deviation of cyclic shifts of permutation p and the id of such shift. If there are multiple solutions, print any of them.
Examples
Input
3
1 2 3
Output
0 0
Input
3
2 3 1
Output
0 1
Input
3
3 2 1
Output
2 1
Note
In the first sample test the given permutation p is the identity permutation, that's why its deviation equals to 0, the shift id equals to 0 as well.
In the second sample test the deviation of p equals to 4, the deviation of the 1-st cyclic shift (1, 2, 3) equals to 0, the deviation of the 2-nd cyclic shift (3, 1, 2) equals to 4, the optimal is the 1-st cyclic shift.
In the third sample test the deviation of p equals to 4, the deviation of the 1-st cyclic shift (1, 3, 2) equals to 2, the deviation of the 2-nd cyclic shift (2, 1, 3) also equals to 2, so the optimal are both 1-st and 2-nd cyclic shifts. | {
"input": [
"3\n3 2 1\n",
"3\n1 2 3\n",
"3\n2 3 1\n"
],
"output": [
"2 1\n",
"0 0\n",
"0 1\n"
]
} | {
"input": [
"4\n1 2 4 3\n",
"4\n2 1 4 3\n",
"10\n1 2 10 9 7 4 8 3 6 5\n",
"10\n1 7 10 6 5 2 3 8 9 4\n",
"4\n4 3 2 1\n",
"4\n2 1 3 4\n",
"10\n1 10 9 5 3 2 4 7 8 6\n",
"4\n2 3 1 4\n",
"4\n2 4 3 1\n",
"10\n1 5 10 8 4 3 9 2 7 6\n",
"4\n1 4 3 2\n",
"10\n1 8 10 6 2 4 9 3 7 5\n",
"4\n2 3 4 1\n",
"10\n2 6 10 1 9 7 4 8 5 3\n",
"4\n4 1 2 3\n",
"10\n1 9 10 5 6 7 3 8 4 2\n",
"4\n4 2 1 3\n",
"4\n3 1 4 2\n",
"10\n1 2 3 4 6 5 7 9 10 8\n",
"4\n4 3 1 2\n",
"4\n1 3 4 2\n",
"10\n2 5 10 3 6 4 9 1 8 7\n",
"10\n2 1 10 5 8 4 9 3 7 6\n",
"4\n3 1 2 4\n",
"10\n1 6 10 7 9 5 3 8 4 2\n",
"2\n1 2\n",
"10\n1 3 10 9 4 7 5 8 6 2\n",
"4\n1 3 2 4\n",
"4\n4 2 3 1\n",
"4\n3 2 1 4\n",
"4\n3 2 4 1\n",
"4\n1 2 3 4\n",
"10\n2 7 10 1 6 3 4 8 9 5\n",
"2\n2 1\n",
"4\n3 4 2 1\n",
"4\n3 4 1 2\n",
"10\n10 1 9 2 8 3 7 4 6 5\n",
"10\n1 4 10 8 9 2 3 6 7 5\n",
"10\n2 3 10 5 4 8 6 9 7 1\n",
"108\n1 102 33 99 6 83 4 20 61 100 76 71 44 9 24 87 57 2 81 82 90 85 12 30 66 53 47 36 43 29 31 64 96 84 77 23 93 78 58 68 42 55 13 70 62 19 92 14 10 65 63 75 91 48 11 105 37 50 32 94 18 26 52 89 104 106 86 97 80 95 17 72 40 22 79 103 25 101 35 51 15 98 67 5 34 69 54 27 45 88 56 16 46 60 74 108 21 41 73 39 107 59 3 8 28 49 7 38\n",
"4\n4 1 3 2\n",
"4\n2 4 1 3\n",
"10\n2 4 10 3 9 1 5 7 8 6\n",
"4\n1 4 2 3\n"
],
"output": [
"2 0\n",
"4 0\n",
"26 5\n",
"26 6\n",
"4 1\n",
"2 0\n",
"20 7\n",
"4 0\n",
"2 1\n",
"26 6\n",
"4 0\n",
"24 6\n",
"0 1\n",
"28 1\n",
"0 3\n",
"26 1\n",
"2 3\n",
"4 1\n",
"6 0\n",
"2 2\n",
"2 1\n",
"28 0\n",
"28 0\n",
"2 3\n",
"24 4\n",
"0 0\n",
"22 1\n",
"2 0\n",
"4 1\n",
"4 0\n",
"2 1\n",
"0 0\n",
"20 7\n",
"0 1\n",
"2 2\n",
"0 2\n",
"24 7\n",
"20 5\n",
"14 1\n",
"3428 30\n",
"2 3\n",
"2 2\n",
"28 0\n",
"4 0\n"
]
} | 1,900 | 1,000 |
2 | 11 | 846_E. Chemistry in Berland | Igor is a post-graduate student of chemistry faculty in Berland State University (BerSU). He needs to conduct a complicated experiment to write his thesis, but laboratory of BerSU doesn't contain all the materials required for this experiment.
Fortunately, chemical laws allow material transformations (yes, chemistry in Berland differs from ours). But the rules of transformation are a bit strange.
Berland chemists are aware of n materials, numbered in the order they were discovered. Each material can be transformed into some other material (or vice versa). Formally, for each i (2 β€ i β€ n) there exist two numbers xi and ki that denote a possible transformation: ki kilograms of material xi can be transformed into 1 kilogram of material i, and 1 kilogram of material i can be transformed into 1 kilogram of material xi. Chemical processing equipment in BerSU allows only such transformation that the amount of resulting material is always an integer number of kilograms.
For each i (1 β€ i β€ n) Igor knows that the experiment requires ai kilograms of material i, and the laboratory contains bi kilograms of this material. Is it possible to conduct an experiment after transforming some materials (or none)?
Input
The first line contains one integer number n (1 β€ n β€ 105) β the number of materials discovered by Berland chemists.
The second line contains n integer numbers b1, b2... bn (1 β€ bi β€ 1012) β supplies of BerSU laboratory.
The third line contains n integer numbers a1, a2... an (1 β€ ai β€ 1012) β the amounts required for the experiment.
Then n - 1 lines follow. j-th of them contains two numbers xj + 1 and kj + 1 that denote transformation of (j + 1)-th material (1 β€ xj + 1 β€ j, 1 β€ kj + 1 β€ 109).
Output
Print YES if it is possible to conduct an experiment. Otherwise print NO.
Examples
Input
3
1 2 3
3 2 1
1 1
1 1
Output
YES
Input
3
3 2 1
1 2 3
1 1
1 2
Output
NO | {
"input": [
"3\n3 2 1\n1 2 3\n1 1\n1 2\n",
"3\n1 2 3\n3 2 1\n1 1\n1 1\n"
],
"output": [
"NO\n",
"YES\n"
]
} | {
"input": [
"5\n27468 7465 74275 40573 40155\n112071 76270 244461 264202 132397\n1 777133331\n2 107454154\n3 652330694\n4 792720519\n",
"5\n78188 56310 79021 70050 65217\n115040 5149 128449 98357 36580\n1 451393770\n2 574046602\n3 590130784\n4 112514248\n",
"7\n1 1 1 1 1 1 1\n1 3000000000 3000000000 3000000000 1000000000 1000000000 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n",
"10\n2 8 6 1 2 7 6 9 2 8\n4 9 4 3 5 2 9 3 7 3\n1 8\n2 8\n3 8\n4 10\n5 1\n6 4\n7 3\n8 10\n9 2\n",
"11\n1 1 1 1 1 1 1 1 1 1 1\n1 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001 1000000001\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n",
"5\n2 1 1 2 3\n1 2 2 2 1\n1 2\n1 3\n2 4\n1 4\n"
],
"output": [
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n"
]
} | 2,300 | 0 |
2 | 7 | 868_A. Bark to Unlock | As technologies develop, manufacturers are making the process of unlocking a phone as user-friendly as possible. To unlock its new phone, Arkady's pet dog Mu-mu has to bark the password once. The phone represents a password as a string of two lowercase English letters.
Mu-mu's enemy Kashtanka wants to unlock Mu-mu's phone to steal some sensible information, but it can only bark n distinct words, each of which can be represented as a string of two lowercase English letters. Kashtanka wants to bark several words (not necessarily distinct) one after another to pronounce a string containing the password as a substring. Tell if it's possible to unlock the phone in this way, or not.
Input
The first line contains two lowercase English letters β the password on the phone.
The second line contains single integer n (1 β€ n β€ 100) β the number of words Kashtanka knows.
The next n lines contain two lowercase English letters each, representing the words Kashtanka knows. The words are guaranteed to be distinct.
Output
Print "YES" if Kashtanka can bark several words in a line forming a string containing the password, and "NO" otherwise.
You can print each letter in arbitrary case (upper or lower).
Examples
Input
ya
4
ah
oy
to
ha
Output
YES
Input
hp
2
ht
tp
Output
NO
Input
ah
1
ha
Output
YES
Note
In the first example the password is "ya", and Kashtanka can bark "oy" and then "ah", and then "ha" to form the string "oyahha" which contains the password. So, the answer is "YES".
In the second example Kashtanka can't produce a string containing password as a substring. Note that it can bark "ht" and then "tp" producing "http", but it doesn't contain the password "hp" as a substring.
In the third example the string "hahahaha" contains "ah" as a substring. | {
"input": [
"ah\n1\nha\n",
"ya\n4\nah\noy\nto\nha\n",
"hp\n2\nht\ntp\n"
],
"output": [
"YES",
"YES",
"NO"
]
} | {
"input": [
"ab\n2\nbb\nbc\n",
"bc\n1\nab\n",
"th\n1\nth\n",
"bn\n100\ndf\nyb\nze\nml\nyr\nof\nnw\nfm\ndw\nlv\nzr\nhu\nzt\nlw\nld\nmo\nxz\ntp\nmr\nou\nme\npx\nvp\nes\nxi\nnr\nbx\nqc\ngm\njs\nkn\ntw\nrq\nkz\nuc\nvc\nqr\nab\nna\nro\nya\nqy\ngu\nvk\nqk\ngs\nyq\nop\nhw\nrj\neo\nlz\nbh\nkr\nkb\nma\nrd\nza\nuf\nhq\nmc\nmn\nti\nwn\nsh\nax\nsi\nnd\ntz\ndu\nfj\nkl\nws\now\nnf\nvr\nye\nzc\niw\nfv\nkv\noo\nsm\nbc\nrs\nau\nuz\nuv\ngh\nsu\njn\ndz\nrl\nwj\nbk\nzl\nas\nms\nit\nwu\n",
"ke\n20\nzk\nra\nbq\nqz\nwt\nzg\nmz\nuk\nge\nuv\nud\nfd\neh\ndm\nsk\nki\nfv\ntp\nat\nfb\n",
"ab\n2\nab\ncd\n",
"bb\n1\naa\n",
"ya\n1\nya\n",
"ha\n1\nha\n",
"hp\n1\nhp\n",
"if\n100\njd\nbc\nje\nhi\nga\nde\nkb\nfc\ncd\ngd\naj\ncb\nei\nbf\ncf\ndk\ndb\ncg\nki\ngg\nkg\nfa\nkj\nii\njf\njg\ngb\nbh\nbg\neh\nhj\nhb\ndg\ndj\njc\njb\nce\ndi\nig\nci\ndf\nji\nhc\nfk\naf\nac\ngk\nhd\nae\nkd\nec\nkc\neb\nfh\nij\nie\nca\nhh\nkf\nha\ndd\nif\nef\nih\nhg\nej\nfe\njk\nea\nib\nck\nhf\nak\ngi\nch\ndc\nba\nke\nad\nka\neg\njh\nja\ngc\nfd\ncc\nab\ngj\nik\nfg\nbj\nhe\nfj\nge\ngh\nhk\nbk\ned\nid\nfi\n",
"ba\n1\ncc\n",
"ab\n5\nca\nda\nea\nfa\nka\n",
"hh\n50\nag\nhg\ndg\nfh\neg\ngh\ngd\nda\nbh\nab\nhf\ndc\nhb\nfe\nad\nec\nac\nfd\nca\naf\ncg\nhd\neb\nce\nhe\nha\ngb\nea\nae\nfb\nff\nbe\nch\nhh\nee\nde\nge\ngf\naa\ngg\neh\ned\nbf\nfc\nah\nga\nbd\ncb\nbg\nbc\n",
"ha\n2\nha\nzz\n",
"ac\n1\nac\n",
"ab\n1\naa\n",
"ta\n1\nta\n",
"ma\n1\nma\n",
"az\n1\nby\n",
"rn\n50\nba\nec\nwg\nao\nlk\nmz\njj\ncf\nfa\njk\ndy\nsz\njs\nzr\nqv\ntx\nwv\nrd\nqw\nls\nrr\nvt\nrx\nkc\neh\nnj\niq\nyi\nkh\nue\nnv\nkz\nrn\nes\nua\nzf\nvu\nll\neg\nmj\ncz\nzj\nxz\net\neb\nci\nih\nig\nam\nvd\n",
"kd\n100\nek\nea\nha\nkf\nkj\ngh\ndl\nfj\nal\nga\nlj\nik\ngd\nid\ncb\nfh\ndk\nif\nbh\nkb\nhc\nej\nhk\ngc\ngb\nef\nkk\nll\nlf\nkh\ncl\nlh\njj\nil\nhh\nci\ndb\ndf\ngk\njg\nch\nbd\ncg\nfg\nda\neb\nlg\ndg\nbk\nje\nbg\nbl\njl\ncj\nhb\nei\naa\ngl\nka\nfa\nfi\naf\nkc\nla\ngi\nij\nib\nle\ndi\nck\nag\nlc\nca\nge\nie\nlb\nke\nii\nae\nig\nic\nhe\ncf\nhd\nak\nfb\nhi\ngf\nad\nba\nhg\nbi\nkl\nac\ngg\ngj\nbe\nlk\nld\naj\n",
"ee\n100\nah\nfb\ncd\nbi\nii\nai\nid\nag\nie\nha\ndi\nec\nae\nce\njb\ndg\njg\ngd\ngf\nda\nih\nbd\nhj\ngg\nhb\ndf\ned\nfh\naf\nja\nci\nfc\nic\nji\nac\nhi\nfj\nch\nbc\njd\naa\nff\nad\ngj\nej\nde\nee\nhe\ncf\nga\nia\ncg\nbb\nhc\nbe\ngi\njf\nbg\naj\njj\nbh\nfe\ndj\nef\ngb\nge\ndb\nig\ncj\ndc\nij\njh\nei\ndd\nib\nhf\neg\nbf\nfg\nab\ngc\nfd\nhd\ngh\neh\njc\neb\nhh\nca\nje\nbj\nif\nea\nhg\nfa\ncc\nba\ndh\ncb\nfi\n",
"la\n1\nla\n",
"yo\n1\nyo\n",
"ok\n1\nok\n",
"ab\n2\nxa\nza\n",
"aa\n2\nca\ncc\n",
"ab\n1\nab\n",
"ah\n2\nap\nhp\n",
"hi\n1\nhi\n",
"ca\n3\nbc\nbd\nca\n",
"ez\n1\njl\n",
"aa\n2\nab\nac\n",
"ag\n1\nag\n",
"mq\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm\n",
"sh\n1\nsh\n",
"as\n1\nas\n",
"sb\n1\nsb\n",
"ah\n1\nah\n",
"ha\n3\ndd\ncc\nha\n",
"fc\n20\nca\nbb\nce\nfd\nde\nfa\ncc\nec\nfb\nfc\nff\nbe\ncf\nba\ndb\ned\naf\nae\nda\nef\n",
"ah\n2\nba\nha\n",
"ab\n2\nza\nbz\n",
"ax\n2\nii\nxa\n",
"pg\n4\nzl\nxs\ndi\nxn\n",
"ca\n20\ndc\naf\ndf\neg\naa\nbc\nea\nbd\nab\ndb\ngc\nfb\nba\nbe\nee\ngf\ncf\nag\nga\nca\n",
"fa\n1\nfa\n",
"bb\n1\nbb\n",
"fe\n50\nje\nbi\nbg\ngc\nfb\nig\ndf\nji\ndg\nfe\nfc\ncf\ngf\nai\nhe\nac\nch\nja\ngh\njf\nge\ncb\nij\ngb\ncg\naf\neh\nee\nhd\njd\njb\nii\nca\nci\nga\nab\nhi\nag\nfj\nej\nfi\nie\ndj\nfg\nef\njc\njg\njh\nhf\nha\n",
"ab\n2\nba\ntt\n",
"qc\n2\nyc\nkr\n",
"dd\n2\nac\ndc\n",
"oo\n1\nox\n",
"dd\n3\nmt\nrg\nxl\n",
"ab\n1\nbb\n",
"ah\n2\nbb\nha\n",
"ww\n4\nuw\now\npo\nko\n",
"xy\n2\nxy\naa\n",
"ay\n1\nay\n",
"sa\n2\nxx\nas\n",
"ya\n42\nab\nac\nad\nae\naf\nag\nah\nai\nak\naj\nba\nbc\nbd\nbe\nbf\nbg\nbh\nbi\nbk\nbj\ncb\nca\ncd\nce\ncf\ncg\nch\nci\nck\ncj\ndb\ndc\nda\nde\ndf\ndg\ndh\ndi\ndk\ndj\nef\nek\n",
"ab\n2\nax\nbx\n",
"aa\n2\nab\nba\n",
"bk\n1\nbk\n",
"aa\n3\nba\nbb\nab\n",
"ca\n3\naa\nbb\nab\n",
"ba\n1\nbb\n",
"ay\n1\nyb\n",
"ba\n1\nba\n",
"be\n20\nad\ncd\ncb\ndb\ndd\naa\nab\nca\nae\ned\ndc\nbb\nba\nda\nee\nea\ncc\nac\nec\neb\n",
"bc\n1\nbc\n",
"ba\n4\ncd\nad\ncc\ncb\n",
"qw\n1\nqw\n",
"bb\n4\nba\nab\naa\nbb\n",
"ab\n2\net\nab\n",
"ab\n2\nab\ncc\n",
"az\n1\nzz\n",
"bc\n4\nca\nba\nbb\ncc\n",
"id\n50\nhi\ndc\nfg\nee\ngi\nhc\nac\nih\ndg\nfc\nde\ned\nie\neb\nic\ncf\nib\nfa\ngc\nba\nbe\nga\nha\nhg\nia\ndf\nab\nei\neh\nad\nii\nci\ndh\nec\nif\ndi\nbg\nag\nhe\neg\nca\nae\ndb\naa\nid\nfh\nhh\ncc\nfb\ngb\n",
"ab\n3\nab\nxx\nyy\n",
"ab\n2\nab\nde\n",
"aa\n1\naa\n",
"tb\n1\ntb\n",
"ap\n1\nap\n",
"qm\n25\nqw\nwe\ner\nrt\nty\nyu\nui\nio\nop\npa\nas\nsd\ndf\nfg\ngh\nhj\njk\nkl\nlz\nzx\nxc\ncv\nvb\nbn\nnm\n"
],
"output": [
"NO",
"NO",
"YES",
"YES",
"YES",
"YES",
"NO",
"YES",
"YES",
"YES",
"YES",
"NO",
"NO",
"YES",
"YES",
"YES",
"NO",
"YES",
"YES",
"NO",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"NO",
"NO",
"YES",
"NO",
"YES",
"YES",
"NO",
"NO",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"NO",
"YES",
"YES",
"YES",
"YES",
"YES",
"NO",
"NO",
"NO",
"NO",
"NO",
"YES",
"NO",
"YES",
"YES",
"YES",
"NO",
"NO",
"YES",
"YES",
"YES",
"NO",
"NO",
"NO",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"NO",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"YES",
"NO"
]
} | 900 | 250 |
2 | 10 | 893_D. Credit Card | 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 ai occurs. If ai > 0, then ai bourles are deposited to Luba's account. If ai < 0, then ai bourles are withdrawn. And if ai = 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 ai = 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!
Input
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 a1, a2, ... an ( - 104 β€ ai β€ 104), where ai represents the transaction in i-th day.
Output
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.
Examples
Input
5 10
-1 5 0 -5 3
Output
0
Input
3 4
-10 0 20
Output
-1
Input
5 10
-5 0 10 -11 0
Output
2 | {
"input": [
"5 10\n-5 0 10 -11 0\n",
"5 10\n-1 5 0 -5 3\n",
"3 4\n-10 0 20\n"
],
"output": [
"2\n",
"0\n",
"-1\n"
]
} | {
"input": [
"9 13\n6 14 19 5 -5 6 -10 20 8\n",
"8 9\n6 -1 5 -5 -8 -7 -8 -7\n",
"10 7\n-9 3 -4 -22 4 -17 0 -14 3 -2\n",
"6 2\n-2 3 0 -2 0 0\n",
"5 10\n-8 -24 0 -22 12\n",
"5 13756\n-2 -9 -10 0 10\n",
"7 3\n1 -3 0 3 -1 0 2\n",
"9 9\n-3 2 0 -2 -7 -1 0 5 3\n",
"2 3\n2 0\n",
"19 78701\n1 0 -1 0 -1 -1 0 1 0 -1 1 1 -1 1 0 0 -1 0 0\n",
"5 4\n-1 0 0 1 -1\n",
"6 4\n-1 0 2 -4 0 5\n",
"20 23036\n-1 1 -1 -1 -1 -1 1 -1 -1 0 0 1 1 0 0 1 0 0 -1 -1\n",
"5 4\n-1 0 -3 0 3\n",
"12 82016\n1 -2 -1 -1 -2 -1 0 -2 -1 1 -2 2\n",
"7 4\n-6 0 2 -3 0 4 0\n",
"4 4\n2 2 0 1\n",
"6 1\n-3 0 0 0 -2 3\n",
"8 26\n-4 9 -14 -11 0 7 23 -15\n",
"20 23079\n0 1 1 -1 1 0 -1 -1 0 0 1 -1 1 1 1 0 0 1 0 1\n",
"1 1\n1\n",
"7 8555\n-2 -3 -2 3 0 -2 0\n",
"4 100\n-100 0 -50 100\n",
"3 14\n12 12 -8\n",
"1 1\n2\n",
"10 23\n9 7 14 16 -13 -22 24 -3 -12 14\n",
"8 11\n12 -12 -9 3 -22 -21 1 3\n",
"19 49926\n-2 0 2 0 0 -2 2 -1 -1 0 0 0 1 0 1 1 -2 2 2\n",
"16 76798\n-1 11 -7 -4 0 -11 -12 3 0 -7 6 -4 8 6 5 -10\n",
"9 5\n-2 0 3 -4 0 4 -3 -2 0\n"
],
"output": [
"-1\n",
"-1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"-1\n",
"2\n",
"0\n",
"1\n",
"1\n",
"-1\n",
"1\n",
"1\n",
"1\n",
"1\n",
"-1\n",
"1\n",
"-1\n",
"0\n",
"0\n",
"1\n",
"1\n",
"-1\n",
"-1\n",
"-1\n",
"-1\n",
"1\n",
"1\n",
"1\n"
]
} | 1,900 | 0 |
2 | 7 | 915_A. Garden | Luba thinks about watering her garden. The garden can be represented as a segment of length k. Luba has got n buckets, the i-th bucket allows her to water some continuous subsegment of garden of length exactly ai each hour. Luba can't water any parts of the garden that were already watered, also she can't water the ground outside the garden.
Luba has to choose one of the buckets in order to water the garden as fast as possible (as mentioned above, each hour she will water some continuous subsegment of length ai if she chooses the i-th bucket). Help her to determine the minimum number of hours she has to spend watering the garden. It is guaranteed that Luba can always choose a bucket so it is possible water the garden.
See the examples for better understanding.
Input
The first line of input contains two integer numbers n and k (1 β€ n, k β€ 100) β the number of buckets and the length of the garden, respectively.
The second line of input contains n integer numbers ai (1 β€ ai β€ 100) β the length of the segment that can be watered by the i-th bucket in one hour.
It is guaranteed that there is at least one bucket such that it is possible to water the garden in integer number of hours using only this bucket.
Output
Print one integer number β the minimum number of hours required to water the garden.
Examples
Input
3 6
2 3 5
Output
2
Input
6 7
1 2 3 4 5 6
Output
7
Note
In the first test the best option is to choose the bucket that allows to water the segment of length 3. We can't choose the bucket that allows to water the segment of length 5 because then we can't water the whole garden.
In the second test we can choose only the bucket that allows us to water the segment of length 1. | {
"input": [
"3 6\n2 3 5\n",
"6 7\n1 2 3 4 5 6\n"
],
"output": [
"2\n",
"7\n"
]
} | {
"input": [
"3 7\n3 2 1\n",
"4 97\n97 1 50 10\n",
"5 25\n24 5 15 25 23\n",
"3 3\n3 2 1\n",
"4 18\n3 1 1 2\n",
"5 97\n1 10 50 97 2\n",
"1 88\n1\n",
"3 18\n1 9 3\n",
"8 8\n8 7 6 5 4 3 2 1\n",
"2 1\n2 1\n",
"5 16\n8 4 2 1 7\n",
"2 16\n8 4\n",
"1 25\n25\n",
"2 2\n2 1\n",
"4 21\n21 20 21 2\n",
"3 28\n7 14 1\n",
"2 6\n3 2\n",
"5 12\n12 4 3 4 4\n",
"5 10\n5 4 3 2 1\n",
"4 32\n1 1 1 1\n",
"5 12\n2 3 12 6 4\n",
"2 100\n99 1\n",
"3 6\n1 3 2\n",
"79 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79\n",
"3 6\n6 3 2\n",
"3 12\n3 12 2\n",
"5 97\n1 10 50 100 2\n",
"6 8\n6 5 4 3 2 1\n",
"7 24\n1 3 6 4 5 2 7\n",
"4 12\n1 2 12 3\n",
"5 12\n12 4 4 4 3\n",
"3 8\n4 3 2\n",
"2 4\n4 1\n",
"100 100\n2 46 24 18 86 90 31 38 84 49 58 28 15 80 14 24 87 56 62 87 41 87 55 71 87 32 41 56 91 32 24 75 43 42 35 30 72 53 31 26 54 61 87 85 36 75 44 31 7 38 77 57 61 54 70 77 45 96 39 57 11 8 91 42 52 15 42 30 92 41 27 26 34 27 3 80 32 86 26 97 63 91 30 75 14 7 19 23 45 11 8 43 44 73 11 56 3 55 63 16\n",
"3 9\n3 2 1\n",
"2 10\n5 2\n",
"2 4\n8 1\n",
"11 99\n1 2 3 6 5 4 7 8 99 33 66\n",
"4 12\n1 4 3 2\n",
"2 6\n5 3\n",
"4 6\n3 2 5 12\n",
"3 10\n2 10 5\n",
"2 12\n4 3\n",
"6 8\n2 4 1 3 5 7\n",
"6 15\n5 2 3 6 4 3\n",
"3 8\n3 4 2\n",
"99 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99\n",
"2 18\n6 3\n",
"4 12\n6 4 3 1\n",
"3 6\n3 2 1\n",
"4 6\n6 1 2 3\n",
"4 4\n1 2 2 4\n",
"3 8\n7 2 4\n",
"6 87\n1 2 8 4 5 7\n",
"3 6\n10 2 3\n",
"4 8\n2 8 4 1\n",
"5 6\n3 2 4 2 2\n",
"4 100\n2 50 4 1\n",
"100 91\n13 13 62 96 74 47 81 46 78 21 20 42 4 73 25 30 76 74 58 28 25 52 42 48 74 40 82 9 25 29 17 22 46 64 57 95 81 39 47 86 40 95 97 35 31 98 45 98 47 78 52 63 58 14 89 97 17 95 28 22 20 36 68 38 95 16 2 26 54 47 42 31 31 81 21 21 65 40 82 53 60 71 75 33 96 98 6 22 95 12 5 48 18 27 58 62 5 96 36 75\n",
"2 100\n7 1\n",
"4 12\n1 3 4 2\n",
"1 89\n1\n",
"3 18\n1 9 6\n",
"3 6\n2 3 1\n",
"3 6\n5 3 2\n",
"3 6\n2 3 2\n",
"5 6\n2 3 5 1 2\n",
"3 19\n7 1 1\n",
"3 12\n1 12 2\n",
"3 8\n4 2 1\n",
"4 12\n1 2 4 3\n",
"2 5\n5 1\n",
"6 7\n6 5 4 3 7 1\n",
"5 3\n2 4 5 3 6\n",
"3 8\n2 4 2\n",
"4 8\n2 4 8 1\n",
"98 12\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98\n",
"3 8\n8 4 2\n",
"3 6\n3 2 5\n",
"1 1\n1\n",
"1 100\n1\n"
],
"output": [
"7\n",
"1\n",
"1\n",
"1\n",
"6\n",
"1\n",
"88\n",
"2\n",
"1\n",
"1\n",
"2\n",
"2\n",
"1\n",
"1\n",
"1\n",
"2\n",
"2\n",
"1\n",
"2\n",
"32\n",
"1\n",
"100\n",
"2\n",
"1\n",
"1\n",
"1\n",
"97\n",
"2\n",
"4\n",
"1\n",
"1\n",
"2\n",
"1\n",
"50\n",
"3\n",
"2\n",
"4\n",
"1\n",
"3\n",
"2\n",
"2\n",
"1\n",
"3\n",
"2\n",
"3\n",
"2\n",
"1\n",
"3\n",
"2\n",
"2\n",
"1\n",
"1\n",
"2\n",
"87\n",
"2\n",
"1\n",
"2\n",
"2\n",
"7\n",
"100\n",
"3\n",
"89\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"19\n",
"1\n",
"2\n",
"3\n",
"1\n",
"1\n",
"1\n",
"2\n",
"1\n",
"1\n",
"1\n",
"2\n",
"1\n",
"100\n"
]
} | 900 | 0 |
2 | 8 | 938_B. Run For Your Prize | You and your friend are participating in a TV show "Run For Your Prize".
At the start of the show n prizes are located on a straight line. i-th prize is located at position ai. Positions of all prizes are distinct. You start at position 1, your friend β at position 106 (and there is no prize in any of these two positions). You have to work as a team and collect all prizes in minimum possible time, in any order.
You know that it takes exactly 1 second to move from position x to position x + 1 or x - 1, both for you and your friend. You also have trained enough to instantly pick up any prize, if its position is equal to your current position (and the same is true for your friend). Carrying prizes does not affect your speed (or your friend's speed) at all.
Now you may discuss your strategy with your friend and decide who will pick up each prize. Remember that every prize must be picked up, either by you or by your friend.
What is the minimum number of seconds it will take to pick up all the prizes?
Input
The first line contains one integer n (1 β€ n β€ 105) β the number of prizes.
The second line contains n integers a1, a2, ..., an (2 β€ ai β€ 106 - 1) β the positions of the prizes. No two prizes are located at the same position. Positions are given in ascending order.
Output
Print one integer β the minimum number of seconds it will take to collect all prizes.
Examples
Input
3
2 3 9
Output
8
Input
2
2 999995
Output
5
Note
In the first example you take all the prizes: take the first at 1, the second at 2 and the third at 8.
In the second example you take the first prize in 1 second and your friend takes the other in 5 seconds, you do this simultaneously, so the total time is 5. | {
"input": [
"2\n2 999995\n",
"3\n2 3 9\n"
],
"output": [
"5\n",
"8\n"
]
} | {
"input": [
"3\n500000 500001 500002\n",
"1\n505050\n",
"2\n999998 999999\n",
"2\n500000 500001\n",
"1\n999995\n",
"1\n753572\n",
"2\n2 999999\n",
"1\n999998\n",
"4\n2 3 4 5\n",
"1\n500002\n",
"2\n100 999900\n",
"1\n500001\n",
"2\n499999 500001\n",
"2\n2 500000\n",
"1\n900000\n",
"2\n500001 999999\n",
"1\n500000\n",
"1\n700000\n",
"1\n2\n",
"6\n2 3 500000 999997 999998 999999\n",
"2\n576696 760487\n",
"3\n2 5 27\n",
"10\n3 4 5 6 7 8 9 10 11 12\n",
"4\n999996 999997 999998 999999\n",
"1\n499999\n",
"2\n999997 999999\n",
"2\n499999 500000\n",
"1\n20\n",
"1\n510000\n",
"2\n600000 800000\n",
"2\n499999 999999\n",
"1\n800000\n",
"4\n2 3 4 999999\n",
"2\n2 999998\n",
"1\n999999\n",
"2\n100000 500001\n",
"5\n2 5 6 27 29\n",
"3\n999997 999998 999999\n",
"10\n3934 38497 42729 45023 51842 68393 77476 82414 91465 98055\n",
"2\n2 500001\n"
],
"output": [
"499999\n",
"494950\n",
"2\n",
"499999\n",
"5\n",
"246428\n",
"1\n",
"2\n",
"4\n",
"499998\n",
"100\n",
"499999\n",
"499999\n",
"499999\n",
"100000\n",
"499999\n",
"499999\n",
"300000\n",
"1\n",
"499999\n",
"423304\n",
"26\n",
"11\n",
"4\n",
"499998\n",
"3\n",
"499999\n",
"19\n",
"490000\n",
"400000\n",
"499998\n",
"200000\n",
"3\n",
"2\n",
"1\n",
"499999\n",
"28\n",
"3\n",
"98054\n",
"499999\n"
]
} | 1,100 | 0 |
2 | 8 | 963_B. Destruction of a Tree | You are given a tree (a graph with n vertices and n - 1 edges in which it's possible to reach any vertex from any other vertex using only its edges).
A vertex can be destroyed if this vertex has even degree. If you destroy a vertex, all edges connected to it are also deleted.
Destroy all vertices in the given tree or determine that it is impossible.
Input
The first line contains integer n (1 β€ n β€ 2Β·105) β number of vertices in a tree.
The second line contains n integers p1, p2, ..., pn (0 β€ pi β€ n). If pi β 0 there is an edge between vertices i and pi. It is guaranteed that the given graph is a tree.
Output
If it's possible to destroy all vertices, print "YES" (without quotes), otherwise print "NO" (without quotes).
If it's possible to destroy all vertices, in the next n lines print the indices of the vertices in order you destroy them. If there are multiple correct answers, print any.
Examples
Input
5
0 1 2 1 2
Output
YES
1
2
3
5
4
Input
4
0 1 2 3
Output
NO
Note
In the first example at first you have to remove the vertex with index 1 (after that, the edges (1, 2) and (1, 4) are removed), then the vertex with index 2 (and edges (2, 3) and (2, 5) are removed). After that there are no edges in the tree, so you can remove remaining vertices in any order.
<image> | {
"input": [
"5\n0 1 2 1 2\n",
"4\n0 1 2 3\n"
],
"output": [
"YES\n1\n2\n3\n5\n4\n",
"NO\n"
]
} | {
"input": [
"21\n11 19 4 19 6 0 13 7 6 2 5 3 16 10 1 9 15 21 9 21 2\n",
"100\n57 85 27 81 41 27 73 10 73 95 91 90 89 41 86 44 6 20 9 13 46 73 56 19 37 32 40 42 79 76 96 5 6 8 76 52 14 86 33 69 100 95 58 87 43 47 17 39 48 28 77 65 100 100 41 39 87 5 61 67 94 64 61 88 32 23 79 44 0 67 44 23 48 96 48 56 86 75 90 2 17 46 4 75 42 90 17 77 5 33 87 91 27 28 58 95 58 47 33 6\n",
"61\n5 61 20 5 50 59 56 29 44 1 48 13 20 35 61 33 38 52 30 8 43 17 35 43 24 59 22 23 11 26 38 37 48 36 13 37 44 23 30 19 26 1 15 19 8 18 42 0 50 33 52 36 17 11 29 18 48 15 24 22 42\n",
"8\n3 1 4 0 4 2 4 5\n",
"61\n58 39 45 57 31 43 11 24 8 18 56 54 47 37 50 40 19 16 29 10 1 23 36 28 21 48 52 55 27 42 2 33 46 25 53 6 15 26 14 17 9 44 56 34 5 61 38 12 30 7 49 32 20 41 51 0 3 4 60 35 13\n",
"21\n11 10 12 3 6 0 8 6 16 14 5 9 7 19 1 13 15 21 4 2 20\n",
"100\n81 96 65 28 4 40 5 49 5 89 48 70 94 70 17 58 58 1 61 19 45 33 46 19 22 83 56 67 62 82 57 16 29 36 84 71 42 66 78 54 73 45 82 80 67 88 79 69 61 66 5 36 24 60 96 21 77 67 68 29 87 37 91 34 78 43 0 69 49 62 16 2 68 79 57 1 60 12 39 99 14 37 30 92 47 18 14 75 73 39 94 12 43 87 90 22 91 59 54 71\n",
"21\n21 6 4 20 14 1 13 10 11 0 10 18 10 12 4 1 2 2 8 2 13\n",
"1\n0\n",
"21\n15 6 13 7 15 21 8 0 7 16 16 21 12 6 12 12 13 6 15 16 7\n",
"61\n47 61 20 5 10 59 46 55 44 1 57 13 3 35 21 48 31 7 9 45 43 53 14 6 42 39 22 23 54 40 45 37 16 36 12 44 34 28 25 19 26 33 25 39 33 36 42 0 50 4 52 46 17 11 29 7 48 15 41 27 58\n",
"61\n10 42 20 50 4 24 18 55 19 5 57 13 3 35 58 48 31 46 40 45 15 53 14 25 43 41 22 23 54 39 38 44 16 37 12 34 32 28 26 30 59 47 21 9 8 52 1 0 33 49 36 51 17 11 29 7 48 61 6 27 2\n",
"21\n5 20 9 19 8 0 13 6 13 19 5 3 8 10 1 9 1 20 3 10 18\n",
"79\n0 56 56 42 56 56 56 56 4 56 56 22 56 56 56 48 56 56 56 56 56 24 56 16 56 56 56 9 56 56 56 56 56 56 56 56 56 55 56 56 12 20 56 28 56 56 56 38 56 56 56 56 56 56 44 1 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56\n",
"21\n18 0 18 2 21 2 9 15 3 5 8 2 8 21 6 10 21 13 9 1 13\n",
"61\n45 48 30 23 15 47 8 3 35 56 54 35 17 47 35 56 32 42 14 37 36 44 6 44 1 44 41 46 43 0 33 3 44 54 43 3 47 57 7 32 29 60 36 36 43 61 36 47 3 48 18 8 17 29 3 54 3 6 43 43 56\n",
"61\n17 19 8 53 10 38 59 60 46 25 49 28 46 15 25 56 53 60 60 54 18 49 10 53 29 19 11 61 24 11 17 52 32 54 29 55 0 1 14 56 25 14 33 53 47 56 8 6 53 55 16 46 47 9 24 37 3 52 25 37 26\n",
"61\n56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 56 0 56 56 56 56 56 56 56 48 56 56 56 56 56\n",
"21\n18 18 18 18 18 0 18 18 18 18 18 18 18 18 18 18 18 6 18 18 18\n",
"121\n110 31 57 33 45 33 33 33 91 102 79 33 61 72 107 101 117 10 118 33 33 64 24 94 117 76 33 23 33 49 5 52 95 78 33 39 33 92 17 33 25 33 56 33 3 88 33 108 62 15 28 111 67 33 33 11 96 33 36 70 46 98 80 104 33 19 60 33 112 51 33 2 33 33 121 59 33 41 50 81 105 33 115 34 33 18 84 32 33 33 87 13 86 103 16 119 33 63 30 43 83 53 26 100 69 33 14 38 33 75 66 120 33 33 9 99 0 93 1 48 116\n"
],
"output": [
"YES\n11\n6\n16\n7\n8\n13\n10\n14\n2\n21\n18\n20\n19\n3\n12\n4\n9\n5\n15\n17\n1\n",
"NO\n",
"YES\n56\n7\n18\n46\n52\n51\n36\n34\n37\n32\n44\n9\n19\n40\n30\n39\n26\n41\n59\n6\n24\n25\n43\n21\n15\n58\n61\n2\n42\n47\n1\n10\n5\n4\n50\n49\n33\n16\n48\n11\n29\n8\n20\n3\n13\n12\n35\n14\n23\n28\n38\n17\n22\n27\n60\n53\n31\n45\n55\n54\n57\n",
"NO\n",
"YES\n1\n4\n3\n5\n2\n14\n15\n7\n56\n6\n23\n22\n36\n43\n11\n50\n37\n39\n31\n45\n57\n58\n25\n44\n30\n51\n28\n8\n41\n12\n26\n47\n61\n33\n52\n29\n17\n16\n10\n53\n60\n59\n35\n20\n18\n40\n19\n27\n32\n46\n13\n38\n48\n54\n9\n24\n55\n49\n42\n34\n21\n",
"YES\n11\n6\n7\n16\n12\n4\n14\n2\n21\n18\n20\n10\n19\n3\n9\n13\n8\n5\n15\n17\n1\n",
"NO\n",
"YES\n21\n13\n7\n8\n19\n11\n9\n10\n1\n18\n14\n5\n12\n20\n4\n3\n15\n2\n17\n6\n16\n",
"YES\n1\n",
"YES\n15\n5\n16\n10\n11\n20\n12\n6\n2\n14\n18\n7\n4\n8\n9\n21\n13\n3\n17\n19\n1\n",
"YES\n1\n43\n15\n61\n2\n58\n21\n25\n39\n41\n6\n24\n59\n26\n9\n40\n30\n19\n52\n51\n46\n7\n18\n56\n36\n37\n32\n34\n44\n42\n16\n57\n54\n55\n8\n29\n11\n48\n31\n53\n27\n60\n22\n17\n45\n3\n12\n14\n28\n38\n23\n35\n13\n20\n33\n47\n5\n50\n49\n4\n10\n",
"YES\n10\n4\n49\n16\n57\n54\n55\n45\n3\n12\n14\n28\n31\n53\n27\n60\n22\n17\n38\n23\n35\n13\n20\n8\n29\n11\n48\n33\n50\n5\n47\n2\n58\n21\n25\n6\n41\n39\n40\n9\n32\n34\n51\n46\n7\n56\n18\n52\n36\n37\n44\n19\n30\n26\n59\n24\n43\n15\n61\n42\n1\n",
"YES\n18\n21\n20\n2\n10\n14\n19\n4\n3\n12\n9\n16\n13\n7\n8\n5\n1\n15\n17\n11\n6\n",
"YES\n12\n41\n24\n22\n48\n16\n55\n38\n28\n44\n4\n9\n20\n42\n56\n2\n3\n5\n6\n7\n8\n10\n11\n13\n14\n15\n17\n18\n19\n21\n23\n25\n26\n27\n29\n30\n31\n32\n33\n34\n35\n36\n37\n39\n40\n43\n45\n46\n47\n49\n50\n51\n52\n53\n54\n57\n58\n59\n60\n61\n62\n63\n64\n65\n66\n67\n68\n69\n70\n71\n72\n73\n74\n75\n76\n77\n78\n79\n1\n",
"YES\n1\n3\n9\n7\n19\n21\n10\n16\n5\n14\n17\n13\n8\n6\n2\n4\n12\n15\n11\n18\n20\n",
"YES\n1\n41\n27\n29\n56\n10\n16\n46\n28\n61\n54\n11\n34\n60\n18\n51\n42\n43\n15\n5\n35\n9\n12\n33\n31\n44\n22\n24\n26\n23\n4\n6\n58\n14\n19\n37\n20\n47\n48\n2\n50\n36\n21\n7\n39\n8\n52\n57\n38\n3\n30\n32\n17\n13\n53\n40\n49\n55\n59\n45\n25\n",
"YES\n1\n17\n3\n57\n8\n18\n21\n26\n28\n12\n61\n19\n2\n37\n16\n51\n56\n40\n9\n54\n20\n34\n46\n13\n52\n33\n43\n32\n58\n60\n47\n45\n53\n4\n24\n29\n15\n14\n39\n42\n59\n7\n25\n10\n5\n23\n41\n35\n55\n36\n50\n44\n49\n11\n27\n30\n22\n31\n6\n48\n38\n",
"YES\n56\n1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n21\n22\n23\n24\n25\n26\n27\n28\n29\n30\n31\n32\n33\n34\n35\n36\n37\n38\n39\n40\n41\n42\n43\n44\n45\n46\n47\n49\n50\n51\n52\n53\n54\n55\n57\n58\n59\n60\n61\n48\n",
"YES\n18\n1\n2\n3\n4\n5\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n19\n20\n21\n6\n",
"YES\n1\n75\n116\n30\n62\n63\n81\n69\n120\n108\n92\n61\n88\n52\n66\n118\n86\n10\n53\n60\n51\n23\n94\n26\n59\n39\n117\n41\n34\n87\n9\n83\n16\n33\n4\n6\n7\n8\n12\n20\n21\n27\n29\n35\n37\n40\n42\n44\n47\n54\n55\n58\n65\n68\n71\n73\n74\n77\n82\n85\n89\n90\n97\n106\n109\n113\n114\n95\n101\n115\n91\n84\n78\n25\n17\n36\n76\n103\n24\n28\n70\n67\n102\n18\n93\n19\n111\n32\n46\n13\n38\n48\n112\n105\n80\n98\n49\n99\n121\n110\n96\n3\n5\n2\n14\n15\n79\n56\n100\n64\n22\n104\n43\n11\n50\n107\n72\n31\n45\n57\n119\n"
]
} | 2,000 | 1,000 |
2 | 11 | 990_E. Post Lamps | Adilbek's house is located on a street which can be represented as the OX axis. This street is really dark, so Adilbek wants to install some post lamps to illuminate it. Street has n positions to install lamps, they correspond to the integer numbers from 0 to n - 1 on the OX axis. However, some positions are blocked and no post lamp can be placed there.
There are post lamps of different types which differ only by their power. When placed in position x, post lamp of power l illuminates the segment [x; x + l]. The power of each post lamp is always a positive integer number.
The post lamp shop provides an infinite amount of lamps of each type from power 1 to power k. Though each customer is only allowed to order post lamps of exactly one type. Post lamps of power l cost a_l each.
What is the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street? If some lamps illuminate any other segment of the street, Adilbek does not care, so, for example, he may place a lamp of power 3 in position n - 1 (even though its illumination zone doesn't completely belong to segment [0; n]).
Input
The first line contains three integer numbers n, m and k (1 β€ k β€ n β€ 10^6, 0 β€ m β€ n) β the length of the segment of the street Adilbek wants to illuminate, the number of the blocked positions and the maximum power of the post lamp available.
The second line contains m integer numbers s_1, s_2, ..., s_m (0 β€ s_1 < s_2 < ... s_m < n) β the blocked positions.
The third line contains k integer numbers a_1, a_2, ..., a_k (1 β€ a_i β€ 10^6) β the costs of the post lamps.
Output
Print the minimal total cost of the post lamps of exactly one type Adilbek can buy to illuminate the entire segment [0; n] of the street.
If illumintaing the entire segment [0; n] is impossible, print -1.
Examples
Input
6 2 3
1 3
1 2 3
Output
6
Input
4 3 4
1 2 3
1 10 100 1000
Output
1000
Input
5 1 5
0
3 3 3 3 3
Output
-1
Input
7 4 3
2 4 5 6
3 14 15
Output
-1 | {
"input": [
"5 1 5\n0\n3 3 3 3 3\n",
"4 3 4\n1 2 3\n1 10 100 1000\n",
"7 4 3\n2 4 5 6\n3 14 15\n",
"6 2 3\n1 3\n1 2 3\n"
],
"output": [
"-1\n",
"1000\n",
"-1\n",
"6\n"
]
} | {
"input": [
"3 1 2\n2\n1 1\n",
"3 1 2\n1\n8 61\n",
"3 0 3\n\n334 500 1001\n",
"20 16 16\n1 2 3 4 5 6 8 9 10 11 13 14 15 16 18 19\n2 1 1 1 1 1 3 3 2 2 1 3 3 3 3 2\n",
"1 1 1\n0\n1000\n",
"4 1 3\n3\n838 185 210\n",
"3 1 1\n2\n1\n",
"3 0 3\n\n333 500 1001\n",
"6 2 3\n2 3\n1 1 3\n",
"20 2 10\n9 16\n109 58 165 715 341 620 574 732 653 675\n",
"11 4 6\n3 4 5 6\n1000000 1000000 1000000 1000000 1000000 1\n",
"1000000 0 1\n\n1000000\n",
"2 1 2\n1\n1 2\n",
"3 2 3\n1 2\n1 1 1000000\n",
"1000000 0 1\n\n999999\n",
"4 1 3\n3\n3 2 9\n",
"9 4 3\n3 4 7 8\n1 1 1\n",
"4 0 4\n\n1 4 4 3\n",
"10 3 2\n2 3 8\n2 4\n",
"2 1 1\n1\n1\n",
"1 0 1\n\n1000000\n"
],
"output": [
"2\n",
"122\n",
"1000\n",
"3\n",
"-1\n",
"370\n",
"-1\n",
"999\n",
"9\n",
"638\n",
"3\n",
"1000000000000\n",
"2\n",
"1000000\n",
"999999000000\n",
"4\n",
"4\n",
"3\n",
"-1\n",
"-1\n",
"1000000\n"
]
} | 2,100 | 0 |
2 | 9 | 101_C. Vectors | At a geometry lesson Gerald was given a task: to get vector B out of vector A. Besides, the teacher permitted him to perform the following operations with vector Π:
* Turn the vector by 90 degrees clockwise.
* Add to the vector a certain vector C.
Operations could be performed in any order any number of times.
Can Gerald cope with the task?
Input
The first line contains integers x1 ΠΈ y1 β the coordinates of the vector A ( - 108 β€ x1, y1 β€ 108). The second and the third line contain in the similar manner vectors B and C (their coordinates are integers; their absolute value does not exceed 108).
Output
Print "YES" (without the quotes) if it is possible to get vector B using the given operations. Otherwise print "NO" (without the quotes).
Examples
Input
0 0
1 1
0 1
Output
YES
Input
0 0
1 1
1 1
Output
YES
Input
0 0
1 1
2 2
Output
NO | {
"input": [
"0 0\n1 1\n1 1\n",
"0 0\n1 1\n0 1\n",
"0 0\n1 1\n2 2\n"
],
"output": [
"YES\n",
"YES\n",
"NO\n"
]
} | {
"input": [
"3 1\n-2 3\n-2 -2\n",
"-8916 9282\n2666 2344\n9109 -2730\n",
"0 45\n42 -47\n-51 -82\n",
"45 6\n65 5\n0 5\n",
"3 4\n-4 3\n1 7\n",
"-75629161 -68114618\n23285096 90997125\n84795646 72358903\n",
"2 3\n2 3\n0 0\n",
"-3 11\n6154942 80496611\n5 0\n",
"1 0\n0 1\n2 1\n",
"2630 8069\n-75372166 10085837\n-781 5563\n",
"69 -30\n-66 -100\n86 -38\n",
"69226391 60708120\n43106396 25795293\n80380957 88577789\n",
"-13 12\n826557 -90209918\n0 -5\n",
"0 0\n1 0\n100000000 0\n",
"9495309 -4445256\n66581093 -48831427\n5864682 -8016505\n",
"-100000000 -100000000\n100000000 100000000\n1 0\n",
"-34280877 -82070958\n66030914 -52671703\n0 -90987154\n",
"0 0\n-63411382 -42720436\n123456 543253\n",
"95 -13\n22 -36\n-25 -60\n",
"-2588 9699\n50743921 -45114432\n-5288 -7358\n",
"-59220368 0\n0 -75968891\n0 74081590\n",
"100000000 0\n1 0\n100000000 0\n",
"16 39\n95 18\n39 -64\n",
"-2413874 4166580\n83681508 25911924\n8615149 -6396049\n",
"-5922 -2466\n-46708374 -71085154\n-9882 298\n",
"-925 -1240\n25904140 -92743662\n-8028 -2933\n",
"-53 30\n-14 -19\n-61 11\n",
"-81 57\n-96 0\n-73 -58\n",
"100000000 0\n1 1\n100000000 100000000\n",
"0 4\n-1 -3\n4 1\n",
"0 0\n100000000 99999999\n100000000 100000000\n",
"-69415 74546\n37868 -89407\n19505 -59846\n",
"-48666683 22046293\n77649947 84819904\n-32803712 -99366118\n",
"2370720 9260730\n-31929898 43611588\n2817748 6788032\n",
"10 13\n-10 -13\n0 0\n",
"-17 -33\n56 -75\n-93 65\n",
"806224 -7075643\n94593948 -33094579\n-540130 -5612242\n",
"-2 -1\n0 1\n-2 -3\n",
"478 884\n418 -713\n-704 -961\n",
"100000000 1\n99999999 1\n100000000 1\n",
"-1 -7\n3 -2\n-4 -3\n",
"0 0\n100000000 0\n1 2\n",
"-9 4\n-2 -8\n9 4\n",
"57 43\n58 -54\n-43 0\n",
"8 2\n-10 1\n10 -2\n",
"6889 9158\n-843345 89332306\n7495 518\n",
"-52856 -58459\n-41878 81991\n-22821 59850\n",
"-50600641 25410541\n0 80575245\n0 62979800\n",
"-35 -90\n0 -42\n-8 -60\n",
"0 0\n100000000 99999997\n0 1\n",
"-6 9\n6 6\n9 6\n",
"80358706 0\n23898082 -87631921\n-48798084 88174414\n",
"-11 -10\n-1042937 89231497\n0 9\n",
"5491 -1888\n58611137 -17279700\n5629 -7705\n",
"74 -55\n0 50\n-68 26\n",
"-100000000 -100000000\n100000000 100000000\n0 1\n",
"1 1\n1 -1\n0 0\n",
"2 -1\n-2 -4\n1 -1\n",
"-127066 941778\n-654926 -838416\n809821 -229819\n",
"-4662151 6642823\n-620983 29911124\n6914655 -1204368\n",
"-1782346 -522853\n56023653 37655619\n7455445 -936314\n",
"0 0\n100000000 99999999\n1 0\n",
"-881780 8157586\n-83355045 -86221641\n-5080144 1016625\n",
"-52 0\n-60 -50\n-47 91\n",
"26164297 21666711\n-20848219 -49928045\n-36819763 26811563\n",
"-6389242 -2092524\n-18806778 85154882\n8457769 5141401\n",
"100000000 4444\n-4444 -100000000\n50000000 50000000\n",
"-8 1\n-10 -8\n1 -4\n",
"7 11\n13 13\n0 4\n",
"1778735 -1803902\n-92875004 -2966747\n-4125460 1149178\n",
"-95534030 -14392539\n-89751090 79655267\n-77491839 40745315\n",
"10327 -86117\n-51156 -26888\n-41007 27453\n",
"-4 3\n9 -2\n-3 -3\n",
"0 0\n4 2\n1 1\n",
"100000000 0\n99999999 1\n0 0\n",
"-8 -8\n66949614 -53875176\n-2 -4\n",
"-84 28\n33 -15\n-19 93\n",
"-65 -52\n31 -22\n0 -77\n",
"3 1\n1 -1\n-1 -4\n",
"1 1\n2 2\n-3 -3\n",
"-1 1\n2 1\n-2 -1\n",
"-7 9\n5 5\n-2 6\n",
"4 -3\n-3 1\n0 -2\n",
"92141071 -48275413\n-47968469 -13277723\n-15839680 51548907\n",
"-66738889 -24309585\n-39387414 -42921545\n-10462276 0\n",
"-5645 2118\n-23770935 62615171\n-2080 9473\n",
"4 0\n4 -3\n2 4\n",
"100000000 100000000\n0 0\n1 1\n",
"100000000 1\n99999999 1\n0 0\n",
"0 -4\n-1 -2\n0 1\n",
"60 55\n-88 -38\n0 59\n",
"836292 -1555463\n44451624 -63102407\n-7051275 -9619647\n",
"-38 -99\n76 43\n53 -84\n",
"0 0\n100000000 100000000\n1 0\n",
"1214 8046\n84729946 38445218\n3488 -5838\n",
"-43 41\n-99 92\n-20 51\n",
"-2797960 2819364\n59202462 71529306\n7799041 -4640234\n",
"-8725 -6466\n77278594 -3622341\n9344 -1256\n",
"-4 -4\n4 1\n-4 -2\n",
"-46921 46529\n87797 -73235\n18213 -86569\n",
"-8540887 -7511495\n-2659834 -6893955\n8115011 -3482324\n",
"100000000 0\n100000000 99999999\n100000000 100000000\n",
"45479363 56862079\n28029163 0\n-38736303 59867108\n",
"910801 387995\n-846325 167413\n-425681 -149086\n",
"6791 1587\n23543337 24784850\n3970 2327\n",
"-4 -4\n1 0\n-1 -3\n",
"0 0\n10 13\n10 13\n",
"10 13\n-13 10\n0 0\n",
"620 514\n-276 966\n578 106\n",
"2 0\n-2 1\n2 3\n",
"-95 -32\n-90 -43\n-40 16\n",
"-3 -2\n-3 3\n4 4\n",
"0 -4\n-3 -2\n3 -1\n",
"281 -914\n-217 113\n479 329\n",
"-66 -34\n59 -38\n13 0\n",
"59 0\n84 -28\n0 58\n",
"122542 -4826228\n-20855162 89301242\n8917870 2568139\n",
"0 0\n1 1\n100000000 100000000\n",
"-4 2\n4 -1\n-2 -1\n",
"-4 -3\n-3 -4\n1 4\n",
"-5493123 4007625\n-49191721 -31674255\n-9754636 6418706\n",
"27523869 0\n52900492 0\n33031150 -65488267\n",
"-2037 -1006\n-13301683 -83185771\n-3487 -4590\n",
"10150745 93724033\n-59625481 -18232739\n34384941 -28147896\n",
"-2 -2\n-2 3\n3 -1\n",
"98219518 -66590186\n14970849 -24409139\n82951915 43915349\n",
"100000000 100000000\n100000000 100000000\n0 1\n",
"0 14\n88 0\n88 0\n",
"2 2\n-2 1\n0 -3\n",
"0 100000000\n0 -100000000\n1 0\n",
"-23 36\n-72 0\n44 -60\n",
"-2911250 -3788914\n9975544 20015444\n7278331 4185016\n",
"72913933 0\n54300106 60510850\n32295823 -60694017\n",
"3411 2674\n-21536783 -33506984\n-8254 -3778\n",
"0 0\n12 12\n0 0\n",
"-2 4\n0 1\n-2 1\n",
"0 0\n0 0\n0 0\n",
"251893 526074\n593818 288991\n-120613 211128\n",
"-21570525 17439241\n-47857043 39456884\n-36121539 69473879\n",
"-28 0\n0 43\n0 -51\n",
"769260 131679\n-399548 -620680\n-439456 -164378\n",
"10 7\n91660376 -58581376\n0 -7\n",
"2 3\n3 -3\n3 -2\n",
"100000000 0\n99999999 1\n100000000 1\n",
"-6008 -6748\n-7106 -5319\n-1940 8048\n",
"0 0\n10000000 10000000\n1 1\n",
"5987456 -1627274\n-45083510 25782192\n-758074 971006\n",
"0 40072438\n-61016486 88561432\n28431496 60485628\n",
"-4 -2\n0 0\n-2 -1\n",
"-79956125 -88524398\n10949698 32312326\n-76024701 -77225990\n",
"-2919 -7389\n-4955 -1807\n2103 9400\n",
"24334185 -27189752\n0 -47230185\n0 -37588021\n",
"-2859 7599\n37114911 -75750711\n-9150 -7398\n",
"0 -14\n80 94\n-14 15\n",
"-48 -92\n59 -39\n-45 14\n",
"-380 -712\n-263 -104\n187 -329\n",
"3922510 4979687\n-83613487 73792320\n-2355010 7196240\n",
"4 1\n2 -1\n3 0\n",
"81 -91\n88 91\n-90 -77\n",
"6040 9662\n1903 7813\n5296 8638\n",
"82539131 17433579\n-56091046 68716401\n-73706000 41779060\n",
"2517677 8638224\n-75757217 -17117074\n-2847910 1342478\n",
"-4 1\n-4 2\n0 -2\n",
"-9234 9520\n58867682 17319702\n2273 -5831\n",
"51 77\n-9 81\n0 79\n",
"1 1\n1 2\n0 0\n",
"-573 5611\n-88934372 16274202\n-689 9294\n",
"89 55\n-13 27\n-13 -81\n",
"100000000 1\n99999999 1\n1 0\n",
"0 24078959\n75842668 -56466325\n-64025705 12045125\n",
"-12 9\n21015609 49124671\n3 2\n",
"4 2\n0 -1\n2 -2\n",
"-3 -9\n-72817057 -54284335\n-3 -1\n",
"6752575 4525855\n-2269760 5249721\n7718280 -5550799\n",
"0 0\n-30010581 33889813\n12862004 15575384\n",
"1 2\n-2 1\n0 0\n",
"0 0\n1 1\n0 0\n",
"-66381 86177\n24332 -47590\n-57592 80499\n",
"4931249 7448503\n8740191 1123509\n4410817 -3494433\n",
"0 0\n99999999 1\n100000000 1\n",
"9121753 -1624238\n1358642 -7305098\n9182854 -2204498\n",
"0 0\n100000000 99999997\n1 0\n",
"4 7\n2 9\n-7 -6\n",
"-7 0\n-51538008 -92285620\n-3 0\n",
"-9 4\n8 1\n-8 8\n",
"-1 -2\n3 -2\n-3 -1\n",
"-3 0\n2 1\n-2 0\n",
"0 -77922994\n47873382 0\n-48532375 -33729248\n",
"-12344578 -26470996\n0 -25186906\n-11572514 -38120367\n",
"-817674 316187\n-934134 660884\n-297136 -482732\n",
"1 3\n3 1\n3 3\n",
"32 34\n-50070000 21003000\n0 1\n",
"4560 -6056\n97943322 -20616116\n-1107 -5440\n",
"-33622572 -65473509\n-54144104 -59861983\n89814248 47623606\n",
"82237071 -62729681\n45778244 -73153917\n25235041 83636828\n",
"100000000 0\n99999999 1\n1 0\n",
"-78038627 -49761049\n0 22143739\n0 -60448485\n",
"94993760 -37786635\n-75326491 -21534927\n77949983 95218547\n",
"10 13\n0 0\n0 0\n",
"-253 -283\n-400 834\n718 -701\n",
"76 73\n82 -92\n-95 95\n",
"0 0\n48 0\n-62 68\n",
"67195377 58333196\n-60739152 -69557068\n-82003989 74825425\n",
"0 1\n2 3\n7 -11\n",
"0 4\n1 1\n-4 2\n",
"-2 2\n4 -2\n-2 -2\n",
"2 1\n1 -4\n-4 -2\n",
"10 13\n13 10\n0 0\n",
"-4664203 -2707147\n7039468 5543778\n5854600 -7808563\n",
"3 2\n1 0\n-4 -1\n",
"-2171 -9855\n4255 -3857\n6446 9559\n",
"10 -15\n23 0\n88 -36\n",
"-6223066 -5334825\n36109780 -5416931\n3246899 -4890875\n",
"6 2\n-97096230 19770854\n-5 4\n",
"-7355750 -5710643\n-48075697 25746997\n-3569463 3650928\n",
"100000000 1\n99999999 1\n0 1\n",
"-2 2\n3 3\n5 0\n",
"5 -12\n-47316040 -62956553\n-7 0\n",
"2 4\n-4 1\n3 3\n",
"-7 9\n-2 10\n-6 -4\n",
"-1334950 3309875\n-20438919 -45390492\n-722222 280804\n"
],
"output": [
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n"
]
} | 2,000 | 1,500 |
2 | 7 | 1043_A. Elections | Awruk is taking part in elections in his school. It is the final round. He has only one opponent β Elodreip. The are n students in the school. Each student has exactly k votes and is obligated to use all of them. So Awruk knows that if a person gives a_i votes for Elodreip, than he will get exactly k - a_i votes from this person. Of course 0 β€ k - a_i holds.
Awruk knows that if he loses his life is over. He has been speaking a lot with his friends and now he knows a_1, a_2, ..., a_n β how many votes for Elodreip each student wants to give. Now he wants to change the number k to win the elections. Of course he knows that bigger k means bigger chance that somebody may notice that he has changed something and then he will be disqualified.
So, Awruk knows a_1, a_2, ..., a_n β how many votes each student will give to his opponent. Help him select the smallest winning number k. In order to win, Awruk needs to get strictly more votes than Elodreip.
Input
The first line contains integer n (1 β€ n β€ 100) β the number of students in the school.
The second line contains n integers a_1, a_2, β¦, a_n (1 β€ a_i β€ 100) β the number of votes each student gives to Elodreip.
Output
Output the smallest integer k (k β₯ max a_i) which gives Awruk the victory. In order to win, Awruk needs to get strictly more votes than Elodreip.
Examples
Input
5
1 1 1 5 1
Output
5
Input
5
2 2 3 2 2
Output
5
Note
In the first example, Elodreip gets 1 + 1 + 1 + 5 + 1 = 9 votes. The smallest possible k is 5 (it surely can't be less due to the fourth person), and it leads to 4 + 4 + 4 + 0 + 4 = 16 votes for Awruk, which is enough to win.
In the second example, Elodreip gets 11 votes. If k = 4, Awruk gets 9 votes and loses to Elodreip. | {
"input": [
"5\n2 2 3 2 2\n",
"5\n1 1 1 5 1\n"
],
"output": [
"5\n",
"5\n"
]
} | {
"input": [
"3\n1 2 6\n",
"10\n7 7 7 7 7 7 7 7 7 7\n",
"76\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11 9\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"20\n3 3 5 2 10 1 2 1 2 2 2 3 2 1 2 1 3 5 2 4\n",
"5\n1 1 1 1 3\n",
"100\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91\n",
"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 3 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\n",
"10\n2 2 2 2 2 2 2 2 2 2\n",
"3\n1 1 2\n",
"4\n6 6 5 5\n",
"2\n1 1\n",
"2\n15 5\n",
"4\n1 2 3 4\n",
"4\n1 2 2 1\n",
"20\n2 2 2 2 4 2 2 2 2 2 1 1 2 2 2 1 1 2 1 1\n",
"7\n1 1 1 7 1 1 2\n",
"4\n1 1 1 3\n",
"100\n50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50 50\n",
"100\n75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75 75\n",
"77\n1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 1 2 3 4 5 6 7 8 9 10 7 7 7 7 7 7 7\n",
"5\n4 4 4 4 3\n",
"10\n5 5 5 5 5 5 5 5 5 5\n",
"25\n3 3 5 9 9 3 2 9 10 2 3 2 3 6 5 9 10 10 6 6 2 3 9 9 9\n",
"100\n26 32 47 42 13 36 42 9 16 37 9 49 42 46 47 49 26 20 37 29 38 2 3 1 22 37 13 10 9 45 28 2 41 21 36 3 4 41 13 14 39 41 7 22 21 15 21 17 17 21 34 35 4 12 49 5 12 31 37 28 37 3 24 14 42 22 50 20 27 32 10 12 19 27 8 16 29 8 40 15 42 23 49 46 31 14 9 30 100 8 48 9 44 39 25 43 50 47 31 3\n",
"75\n13 13 5 6 20 20 6 1 18 18 13 15 20 3 9 11 3 11 3 8 12 15 2 4 16 17 8 11 15 6 6 5 3 12 19 15 17 8 5 20 12 6 9 7 20 15 8 7 5 17 9 12 12 17 12 16 2 6 16 16 17 18 6 7 19 13 6 3 8 16 13 7 1 14 11\n",
"6\n4 5 5 5 5 5\n",
"50\n12 5 4 3 4 4 9 2 14 13 1 6 6 6 6 3 1 14 1 10 4 9 12 3 1 6 5 6 9 14 4 1 10 5 15 8 5 11 13 2 10 11 8 12 8 15 2 8 6 3\n",
"6\n4 4 4 4 4 9\n",
"3\n2 2 1\n",
"1\n1\n",
"2\n100 100\n",
"50\n2 2 2 2 2 1 1 1 2 2 1 1 2 2 1 1 2 2 2 1 2 2 2 2 2 2 2 1 1 5 1 2 1 2 1 1 1 2 1 1 1 2 2 1 1 2 1 1 1 1\n",
"1\n100\n",
"2\n1 4\n",
"20\n10 20 26 13 8 23 47 47 20 49 22 6 43 7 34 1 18 48 38 7\n",
"20\n10 7 1 9 9 3 10 9 9 2 9 8 5 10 9 20 4 9 9 9\n",
"10\n1 2 2 2 2 2 1 2 2 1\n",
"100\n25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25 25\n",
"10\n2 2 4 4 3 1 1 2 3 2\n",
"3\n1 4 1\n",
"3\n1 1 4\n",
"5\n1 1 1 3 4\n",
"5\n2 2 2 3 3\n",
"25\n2 2 3 3 2 3 1 2 1 3 3 2 3 3 2 1 1 3 1 2 3 3 1 1 3\n"
],
"output": [
"7\n",
"15\n",
"22\n",
"201\n",
"10\n",
"3\n",
"102\n",
"3\n",
"5\n",
"3\n",
"12\n",
"3\n",
"21\n",
"6\n",
"4\n",
"4\n",
"7\n",
"4\n",
"101\n",
"151\n",
"12\n",
"8\n",
"11\n",
"12\n",
"100\n",
"22\n",
"10\n",
"15\n",
"10\n",
"4\n",
"3\n",
"201\n",
"5\n",
"201\n",
"6\n",
"49\n",
"20\n",
"4\n",
"51\n",
"5\n",
"5\n",
"5\n",
"5\n",
"5\n",
"5\n"
]
} | 800 | 500 |
2 | 10 | 1107_D. Compression | You are given a binary matrix A of size n Γ n. Let's denote an x-compression of the given matrix as a matrix B of size n/x Γ n/x such that for every i β [1, n], j β [1, n] the condition A[i][j] = B[β i/x β][β j/x β] is met.
Obviously, x-compression is possible only if x divides n, but this condition is not enough. For example, the following matrix of size 2 Γ 2 does not have any 2-compression:
01 10
For the given matrix A, find maximum x such that an x-compression of this matrix is possible.
Note that the input is given in compressed form. But even though it is compressed, you'd better use fast input.
Input
The first line contains one number n (4 β€ n β€ 5200) β the number of rows and columns in the matrix A. It is guaranteed that n is divisible by 4.
Then the representation of matrix follows. Each of n next lines contains n/4 one-digit hexadecimal numbers (that is, these numbers can be represented either as digits from 0 to 9 or as uppercase Latin letters from A to F). Binary representation of each of these numbers denotes next 4 elements of the matrix in the corresponding row. For example, if the number B is given, then the corresponding elements are 1011, and if the number is 5, then the corresponding elements are 0101.
Elements are not separated by whitespaces.
Output
Print one number: maximum x such that an x-compression of the given matrix is possible.
Examples
Input
8
E7
E7
E7
00
00
E7
E7
E7
Output
1
Input
4
7
F
F
F
Output
1
Note
The first example corresponds to the matrix:
11100111 11100111 11100111 00000000 00000000 11100111 11100111 11100111
It is easy to see that the answer on this example is 1. | {
"input": [
"8\nE7\nE7\nE7\n00\n00\nE7\nE7\nE7\n",
"4\n7\nF\nF\nF\n"
],
"output": [
"1",
"1"
]
} | {
"input": [
"8\nFF\nFF\n00\n00\nFF\nFF\n00\n00\n",
"4\n0\n0\n0\n1\n",
"8\n33\n33\n33\n33\n33\n33\n11\n11\n",
"16\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\nFFC0\n",
"12\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\nE38\n",
"4\nA\nA\nA\nA\n",
"12\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\nFC0\n",
"12\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFC0\nFC0\nFC0\nF11\nF11\nF11\n",
"8\nCD\nCD\nCD\nCD\nCE\nCE\nCE\nCE\n",
"4\nE\nE\nE\nE\n",
"4\n3\n3\n3\n3\n",
"12\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFC0\nFC0\nFC3\nFC3\nFC1\nFC1\n",
"4\nF\n0\nF\n0\n",
"12\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n100\n",
"8\n0F\n0F\nF0\nF0\n0F\n0F\nF0\nF0\n",
"4\n3\nF\nF\nF\n",
"12\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFFF\nFC1\nFC1\n",
"4\n3\nC\n3\nC\n"
],
"output": [
"2",
"1",
"1",
"2",
"3",
"1",
"6",
"1",
"1",
"1",
"2",
"1",
"1",
"1",
"2",
"1",
"1",
"1"
]
} | 1,800 | 0 |
2 | 10 | 1136_D. Nastya Is Buying Lunch | At the big break Nastya came to the school dining room. There are n pupils in the school, numbered from 1 to n. Unfortunately, Nastya came pretty late, so that all pupils had already stood in the queue, i.e. Nastya took the last place in the queue. Of course, it's a little bit sad for Nastya, but she is not going to despond because some pupils in the queue can agree to change places with some other pupils.
Formally, there are some pairs u, v such that if the pupil with number u stands directly in front of the pupil with number v, Nastya can ask them and they will change places.
Nastya asks you to find the maximal number of places in queue she can move forward.
Input
The first line contains two integers n and m (1 β€ n β€ 3 β
10^{5}, 0 β€ m β€ 5 β
10^{5}) β the number of pupils in the queue and number of pairs of pupils such that the first one agrees to change places with the second one if the first is directly in front of the second.
The second line contains n integers p_1, p_2, ..., p_n β the initial arrangement of pupils in the queue, from the queue start to its end (1 β€ p_i β€ n, p is a permutation of integers from 1 to n). In other words, p_i is the number of the pupil who stands on the i-th position in the queue.
The i-th of the following m lines contains two integers u_i, v_i (1 β€ u_i, v_i β€ n, u_i β v_i), denoting that the pupil with number u_i agrees to change places with the pupil with number v_i if u_i is directly in front of v_i. It is guaranteed that if i β j, than v_i β v_j or u_i β u_j. Note that it is possible that in some pairs both pupils agree to change places with each other.
Nastya is the last person in the queue, i.e. the pupil with number p_n.
Output
Print a single integer β the number of places in queue she can move forward.
Examples
Input
2 1
1 2
1 2
Output
1
Input
3 3
3 1 2
1 2
3 1
3 2
Output
2
Input
5 2
3 1 5 4 2
5 2
5 4
Output
1
Note
In the first example Nastya can just change places with the first pupil in the queue.
Optimal sequence of changes in the second example is
* change places for pupils with numbers 1 and 3.
* change places for pupils with numbers 3 and 2.
* change places for pupils with numbers 1 and 2.
The queue looks like [3, 1, 2], then [1, 3, 2], then [1, 2, 3], and finally [2, 1, 3] after these operations. | {
"input": [
"5 2\n3 1 5 4 2\n5 2\n5 4\n",
"3 3\n3 1 2\n1 2\n3 1\n3 2\n",
"2 1\n1 2\n1 2\n"
],
"output": [
"1\n",
"2\n",
"1\n"
]
} | {
"input": [
"10 23\n6 9 8 10 4 3 7 1 5 2\n7 2\n3 2\n2 4\n2 3\n7 5\n6 4\n10 7\n7 1\n6 8\n6 2\n8 10\n3 5\n3 1\n6 1\n10 2\n8 2\n10 1\n7 4\n10 5\n6 9\n6 5\n9 1\n10 4\n",
"2 0\n1 2\n",
"3 2\n1 2 3\n1 2\n2 1\n",
"10 20\n2 1 3 9 5 4 7 8 6 10\n4 7\n6 4\n1 4\n2 8\n1 6\n7 9\n1 9\n5 4\n1 3\n10 6\n8 6\n5 6\n7 6\n8 10\n5 10\n7 10\n2 7\n1 10\n10 3\n6 9\n",
"5 4\n1 2 3 4 5\n4 5\n2 5\n1 3\n1 5\n",
"1 0\n1\n",
"20 47\n4 6 11 15 9 17 3 1 19 14 12 8 2 5 7 20 16 18 13 10\n18 10\n6 3\n15 17\n18 7\n6 5\n19 10\n6 7\n11 3\n1 10\n17 3\n6 14\n7 10\n19 5\n12 10\n1 8\n6 11\n18 5\n6 8\n12 8\n1 5\n20 10\n16 8\n6 10\n20 19\n17 8\n13 10\n2 5\n19 8\n6 9\n16 3\n16 10\n19 7\n17 16\n10 16\n8 9\n12 5\n17 10\n2 9\n6 15\n4 9\n10 1\n17 14\n19 14\n2 10\n17 5\n2 13\n1 14\n",
"5 11\n5 1 3 4 2\n5 1\n5 2\n1 5\n2 1\n1 2\n1 4\n2 5\n1 3\n5 4\n5 3\n3 1\n",
"2 1\n1 2\n2 1\n"
],
"output": [
"4\n",
"0\n",
"0\n",
"4\n",
"1\n",
"0\n",
"11\n",
"2\n",
"0\n"
]
} | 1,800 | 2,000 |
2 | 7 | 1155_A. Reverse a Substring | You are given a string s consisting of n lowercase Latin letters.
Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 3 and ends in position 6), but "aa" or "d" aren't substrings of this string. So the substring of the string s from position l to position r is s[l; r] = s_l s_{l + 1} ... s_r.
You have to choose exactly one of the substrings of the given string and reverse it (i. e. make s[l; r] = s_r s_{r - 1} ... s_l) to obtain a string that is less lexicographically. Note that it is not necessary to obtain the minimum possible string.
If it is impossible to reverse some substring of the given string to obtain a string that is less, print "NO". Otherwise print "YES" and any suitable substring.
String x is lexicographically less than string y, if either x is a prefix of y (and x β y), or there exists such i (1 β€ i β€ min(|x|, |y|)), that x_i < y_i, and for any j (1 β€ j < i) x_j = y_j. Here |a| denotes the length of the string a. The lexicographic comparison of strings is implemented by operator < in modern programming languagesββ.
Input
The first line of the input contains one integer n (2 β€ n β€ 3 β
10^5) β the length of s.
The second line of the input contains the string s of length n consisting only of lowercase Latin letters.
Output
If it is impossible to reverse some substring of the given string to obtain a string which is lexicographically less, print "NO". Otherwise print "YES" and two indices l and r (1 β€ l < r β€ n) denoting the substring you have to reverse. If there are multiple answers, you can print any.
Examples
Input
7
abacaba
Output
YES
2 5
Input
6
aabcfg
Output
NO
Note
In the first testcase the resulting string is "aacabba". | {
"input": [
"7\nabacaba\n",
"6\naabcfg\n"
],
"output": [
"YES\n2 3\n",
"NO\n"
]
} | {
"input": [
"6\nbabcdc\n",
"5\nbadec\n",
"3\naba\n",
"7\nbaaaccb\n",
"3\naaa\n",
"4\npara\n",
"3\nbac\n",
"7\nbdadccd\n",
"2\nba\n",
"7\nstoopid\n",
"7\nyxyzyyx\n",
"3\nacb\n",
"7\nbcbcbdc\n",
"7\nabacaba\n",
"2\naa\n",
"12\nparapapapaaa\n"
],
"output": [
"YES\n1 2\n",
"YES\n1 2\n",
"YES\n2 3\n",
"YES\n1 2\n",
"NO\n",
"YES\n1 2\n",
"YES\n1 2\n",
"YES\n2 3\n",
"YES\n1 2\n",
"YES\n2 3\n",
"YES\n1 2\n",
"YES\n2 3\n",
"YES\n2 3\n",
"YES\n2 3\n",
"NO\n",
"YES\n1 2\n"
]
} | 1,000 | 0 |
2 | 12 | 1176_F. Destroy it! | You are playing a computer card game called Splay the Sire. Currently you are struggling to defeat the final boss of the game.
The boss battle consists of n turns. During each turn, you will get several cards. Each card has two parameters: its cost c_i and damage d_i. You may play some of your cards during each turn in some sequence (you choose the cards and the exact order they are played), as long as the total cost of the cards you play during the turn does not exceed 3. After playing some (possibly zero) cards, you end your turn, and all cards you didn't play are discarded. Note that you can use each card at most once.
Your character has also found an artifact that boosts the damage of some of your actions: every 10-th card you play deals double damage.
What is the maximum possible damage you can deal during n turns?
Input
The first line contains one integer n (1 β€ n β€ 2 β
10^5) β the number of turns.
Then n blocks of input follow, the i-th block representing the cards you get during the i-th turn.
Each block begins with a line containing one integer k_i (1 β€ k_i β€ 2 β
10^5) β the number of cards you get during i-th turn. Then k_i lines follow, each containing two integers c_j and d_j (1 β€ c_j β€ 3, 1 β€ d_j β€ 10^9) β the parameters of the corresponding card.
It is guaranteed that β _{i = 1}^{n} k_i β€ 2 β
10^5.
Output
Print one integer β the maximum damage you may deal.
Example
Input
5
3
1 6
1 7
1 5
2
1 4
1 3
3
1 10
3 5
2 3
3
1 15
2 4
1 10
1
1 100
Output
263
Note
In the example test the best course of action is as follows:
During the first turn, play all three cards in any order and deal 18 damage.
During the second turn, play both cards and deal 7 damage.
During the third turn, play the first and the third card and deal 13 damage.
During the fourth turn, play the first and the third card and deal 25 damage.
During the fifth turn, play the only card, which will deal double damage (200). | {
"input": [
"5\n3\n1 6\n1 7\n1 5\n2\n1 4\n1 3\n3\n1 10\n3 5\n2 3\n3\n1 15\n2 4\n1 10\n1\n1 100\n"
],
"output": [
"263\n"
]
} | {
"input": [
"5\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 1\n1 1\n1 1\n3\n1 100\n1 1\n1 1\n",
"1\n4\n1 1\n1 1\n2 2\n3 4\n"
],
"output": [
"211\n",
"4\n"
]
} | 2,100 | 0 |
2 | 10 | 1195_D2. Submarine in the Rybinsk Sea (hard edition) | This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers a_1, a_2, ..., a_n.
A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem.
Let's denote a function that alternates digits of two numbers f(a_1 a_2 ... a_{p - 1} a_p, b_1 b_2 ... b_{q - 1} b_q), where a_1 ... a_p and b_1 ... b_q are digits of two integers written in the decimal notation without leading zeros.
In other words, the function f(x, y) alternately shuffles the digits of the numbers x and y by writing them from the lowest digits to the older ones, starting with the number y. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below.
For example: $$$f(1111, 2222) = 12121212 f(7777, 888) = 7787878 f(33, 44444) = 4443434 f(555, 6) = 5556 f(111, 2222) = 2121212$$$
Formally,
* if p β₯ q then f(a_1 ... a_p, b_1 ... b_q) = a_1 a_2 ... a_{p - q + 1} b_1 a_{p - q + 2} b_2 ... a_{p - 1} b_{q - 1} a_p b_q;
* if p < q then f(a_1 ... a_p, b_1 ... b_q) = b_1 b_2 ... b_{q - p} a_1 b_{q - p + 1} a_2 ... a_{p - 1} b_{q - 1} a_p b_q.
Mishanya gives you an array consisting of n integers a_i, your task is to help students to calculate β_{i = 1}^{n}β_{j = 1}^{n} f(a_i, a_j) modulo 998 244 353.
Input
The first line of the input contains a single integer n (1 β€ n β€ 100 000) β the number of elements in the array. The second line of the input contains n integers a_1, a_2, ..., a_n (1 β€ a_i β€ 10^9) β the elements of the array.
Output
Print the answer modulo 998 244 353.
Examples
Input
3
12 3 45
Output
12330
Input
2
123 456
Output
1115598 | {
"input": [
"3\n12 3 45\n",
"2\n123 456\n"
],
"output": [
"12330\n",
"1115598\n"
]
} | {
"input": [
"20\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\n",
"100\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7912 1245 9287 3059 8964 785 2614 4226 7093 5537 7285 1929 4499 9803 7277 212 2311 9198 9355 6422 577 9919 4656 1734 85 4102 3986 956 7000 4910 1897 6648 9208 3144 2850 6044 3842 232 256 653 90 3959 1606 550 9846 1567 8750 2804 7411 9986 7221 1163 9615 1284 7084 7631 1181 6220 505 9756 8692 7879 4916\n",
"100\n463 6421 2912 1546 3999 5175 4357 2259 7380 6081 1148 7857 3532 4168 5643 8819 2568 6681 975 9216 4590 5217 6215 7422 6631 1651 39 4268 8290 2022 3175 8281 1552 980 9314 234 934 5133 6712 1880 2766 5042 5004 5455 6038 6010 6022 1553 4015 4544 3985 4033 223 7682 6302 2121 4832 3956 9872 8340 5327 6763 2063 6708 4733 8339 2933 8477 7857 6074 1299 5768 3029 7138 8653 9121 6901 6803 5306 9098 6803 2902 9941 3926 3269 5739 3823 7278 3413 5796 4346 9968 3024 3416 7311 9307 4840 2545 2041 5300\n",
"100\n15 7214 8212 3205 5610 4217 5220 235 5691 7149 2027 7344 6416 139 481 4653 4909 8693 9715 6209 2087 6580 1234 6189 7049 580 8482 886 19 1763 5819 4630 9238 549 6236 7946 4585 5283 1187 2501 9159 4375 2374 7068 8223 8177 9645 8825 2547 5669 8725 6329 601 1131 9390 9293 8013 7198 5774 2460 3949 2190 3437 1264 2988 8366 5399 8021 1247 2342 3501 1149 9059 6354 9108 8686 9813 673 6804 7218 7400 8006 9002 3574 9635 3275 1958 9867 8912 9241 5518 1497 4943 1650 937 5895 8865 7544 6821 340\n",
"20\n28 98 66 48 1 74 39 86 11 68 57 82 71 78 96 21 51 35 3 11\n",
"100\n3615 1436 2205 5695 9684 7621 391 1579 557 420 1756 5265 247 5494 3509 6089 2931 7372 4939 8030 2901 1150 5389 7168 6213 2723 4301 7250 3857 9178 4723 1932 1161 1412 8200 5226 1474 3495 9533 8555 6372 1517 8034 6547 1148 9651 2399 3065 9675 3418 7758 3226 9844 4234 510 7652 162 8010 8162 2732 2112 4041 3392 6344 671 4120 4659 7718 8660 7102 9098 6195 6999 9411 6710 2261 4388 7125 3808 978 398 9286 1280 7382 1095 8203 5687 9281 3722 8159 470 5735 4210 3694 2197 5422 816 7546 9965 2963\n",
"1\n123767132\n",
"100\n7039 7577 5463 7876 8938 6398 2374 5567 521 1898 8004 5009 6146 7735 8024 4006 4845 9123 2957 2271 6649 7439 5602 1551 70 1443 8522 2111 8170 2152 3949 714 6557 7548 309 9826 3500 866 9474 1769 3961 6927 6519 1001 7849 8030 1914 7309 7589 6077 3576 4981 5642 8862 3406 4886 5945 4631 4017 536 5815 8850 2727 918 2702 6974 5148 3841 3259 2940 6750 8686 2718 1922 5586 3395 3549 6220 6653 782 9952 7446 2907 2206 7926 2579 4555 1928 5663 9273 7408 2851 5713 8355 1106 812 5732 6398 3099 2579\n",
"20\n80 9 55 1 98 29 81 10 96 100 70 87 86 12 58 82 10 22 59 13\n",
"20\n56 42 16 26 62 47 23 74 70 47 97 26 65 12 15 38 78 97 21 52\n",
"20\n4 53 9 79 47 2 64 98 51 82 14 30 77 41 69 4 37 85 81 62\n"
],
"output": [
"2178920\n",
"167137718\n",
"495837625\n",
"666837072\n",
"1899280\n",
"674832474\n",
"116407724\n",
"906817803\n",
"2248760\n",
"1934680\n",
"1675580\n"
]
} | 1,800 | 1,500 |
2 | 7 | 1236_A. Stones | Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains a stones, the second of them contains b stones and the third of them contains c stones.
Each time she can do one of two operations:
1. take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
2. take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 0 stones. Can you help her?
Input
The first line contains one integer t (1 β€ t β€ 100) β the number of test cases. Next t lines describe test cases in the following format:
Line contains three non-negative integers a, b and c, separated by spaces (0 β€ a,b,c β€ 100) β the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t = 1 should be satisfied.
Output
Print t lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer β the maximum possible number of stones that Alice can take after making some operations.
Example
Input
3
3 4 5
1 0 5
5 3 2
Output
9
0
6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 9. It is impossible to make some operations to take more than 9 stones, so the answer is 9. | {
"input": [
"3\n3 4 5\n1 0 5\n5 3 2\n"
],
"output": [
"9\n0\n6\n"
]
} | {
"input": [
"20\n9 4 8\n10 6 7\n4 6 0\n7 7 6\n3 3 10\n4 2 1\n4 4 0\n2 0 0\n8 8 7\n3 1 7\n3 10 7\n1 7 3\n7 9 1\n1 6 9\n0 9 5\n4 0 0\n2 10 0\n4 8 5\n10 0 1\n8 1 1\n",
"64\n0 0 0\n0 0 1\n0 0 2\n0 0 3\n0 1 0\n0 1 1\n0 1 2\n0 1 3\n0 2 0\n0 2 1\n0 2 2\n0 2 3\n0 3 0\n0 3 1\n0 3 2\n0 3 3\n1 0 0\n1 0 1\n1 0 2\n1 0 3\n1 1 0\n1 1 1\n1 1 2\n1 1 3\n1 2 0\n1 2 1\n1 2 2\n1 2 3\n1 3 0\n1 3 1\n1 3 2\n1 3 3\n2 0 0\n2 0 1\n2 0 2\n2 0 3\n2 1 0\n2 1 1\n2 1 2\n2 1 3\n2 2 0\n2 2 1\n2 2 2\n2 2 3\n2 3 0\n2 3 1\n2 3 2\n2 3 3\n3 0 0\n3 0 1\n3 0 2\n3 0 3\n3 1 0\n3 1 1\n3 1 2\n3 1 3\n3 2 0\n3 2 1\n3 2 2\n3 2 3\n3 3 0\n3 3 1\n3 3 2\n3 3 3\n",
"20\n2 0 8\n8 3 5\n8 10 3\n3 2 4\n4 2 1\n0 3 7\n0 7 5\n7 7 8\n3 3 9\n1 7 5\n2 8 4\n6 3 0\n4 1 10\n3 3 2\n0 0 0\n7 9 2\n10 6 1\n10 2 6\n8 9 1\n8 8 0\n",
"5\n100 100 100\n0 0 0\n0 50 100\n100 50 0\n100 30 100\n",
"20\n6 0 8\n0 6 5\n1 7 3\n6 5 2\n9 10 0\n2 8 8\n9 8 1\n1 9 8\n2 4 10\n9 5 0\n2 9 1\n5 5 10\n10 8 6\n3 6 0\n10 9 2\n6 9 1\n8 4 10\n10 3 4\n10 0 10\n6 1 9\n",
"20\n0 2 9\n2 9 7\n7 3 3\n9 0 10\n4 8 0\n2 3 9\n7 0 8\n5 8 10\n1 4 2\n6 4 7\n3 9 6\n3 5 7\n5 6 1\n2 9 1\n0 6 4\n5 9 1\n6 1 7\n0 6 10\n2 10 7\n4 5 10\n",
"20\n4 4 8\n5 3 7\n0 0 1\n2 3 8\n9 4 10\n4 8 10\n6 3 4\n10 10 0\n0 7 4\n6 2 2\n3 10 2\n2 7 6\n1 2 6\n2 3 0\n1 3 4\n5 0 10\n4 1 2\n3 7 7\n7 10 5\n0 9 0\n"
],
"output": [
"12\n12\n9\n15\n9\n3\n6\n0\n15\n3\n18\n6\n12\n15\n6\n0\n6\n15\n0\n0\n",
"0\n0\n0\n0\n0\n0\n3\n3\n0\n0\n3\n3\n0\n0\n3\n3\n0\n0\n0\n0\n0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n6\n6\n0\n0\n0\n0\n0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n6\n6\n0\n0\n0\n0\n0\n0\n3\n3\n3\n3\n3\n3\n3\n3\n6\n6\n",
"0\n6\n15\n6\n3\n9\n6\n15\n9\n9\n12\n3\n3\n6\n0\n15\n9\n6\n12\n12\n",
"225\n0\n150\n75\n90\n",
"0\n6\n6\n9\n15\n18\n12\n15\n12\n6\n6\n15\n15\n9\n15\n12\n12\n6\n0\n3\n",
"6\n15\n6\n0\n12\n9\n0\n18\n6\n9\n18\n12\n9\n6\n6\n12\n3\n15\n15\n15\n",
"12\n9\n0\n9\n12\n18\n6\n15\n6\n3\n12\n15\n6\n3\n6\n0\n3\n15\n18\n0\n"
]
} | 800 | 500 |
2 | 7 | 1382_A. Common Subsequence | You are given two arrays of integers a_1,β¦,a_n and b_1,β¦,b_m.
Your task is to find a non-empty array c_1,β¦,c_k that is a subsequence of a_1,β¦,a_n, and also a subsequence of b_1,β¦,b_m. If there are multiple answers, find one of the smallest possible length. If there are still multiple of the smallest possible length, find any. If there are no such arrays, you should report about it.
A sequence a is a subsequence of a sequence b if a can be obtained from b by deletion of several (possibly, zero) elements. For example, [3,1] is a subsequence of [3,2,1] and [4,3,1], but not a subsequence of [1,3,3,7] and [3,10,4].
Input
The first line contains a single integer t (1β€ tβ€ 1000) β the number of test cases. Next 3t lines contain descriptions of test cases.
The first line of each test case contains two integers n and m (1β€ n,mβ€ 1000) β the lengths of the two arrays.
The second line of each test case contains n integers a_1,β¦,a_n (1β€ a_iβ€ 1000) β the elements of the first array.
The third line of each test case contains m integers b_1,β¦,b_m (1β€ b_iβ€ 1000) β the elements of the second array.
It is guaranteed that the sum of n and the sum of m across all test cases does not exceed 1000 (β_{i=1}^t n_i, β_{i=1}^t m_iβ€ 1000).
Output
For each test case, output "YES" if a solution exists, or "NO" otherwise.
If the answer is "YES", on the next line output an integer k (1β€ kβ€ 1000) β the length of the array, followed by k integers c_1,β¦,c_k (1β€ c_iβ€ 1000) β the elements of the array.
If there are multiple solutions with the smallest possible k, output any.
Example
Input
5
4 5
10 8 6 4
1 2 3 4 5
1 1
3
3
1 1
3
2
5 3
1000 2 2 2 3
3 1 5
5 5
1 2 3 4 5
1 2 3 4 5
Output
YES
1 4
YES
1 3
NO
YES
1 3
YES
1 2
Note
In the first test case, [4] is a subsequence of [10, 8, 6, 4] and [1, 2, 3, 4, 5]. This array has length 1, it is the smallest possible length of a subsequence of both a and b.
In the third test case, no non-empty subsequences of both [3] and [2] exist, so the answer is "NO". | {
"input": [
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n"
],
"output": [
"YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 1\n"
]
} | {
"input": [
"1\n2 2\n1 1\n1 2\n",
"1\n1 3\n3\n1 2 3\n",
"1\n1 1\n1000\n1000\n",
"1\n2 2\n2 2\n2 2\n",
"5\n4 5\n10 8 6 4\n1 2 3 4 5\n1 1\n3\n3\n1 1\n3\n2\n5 3\n1000 2 2 2 3\n3 1 5\n5 5\n1 2 3 4 5\n1 2 3 4 5\n",
"1\n4 4\n1 1 1 1\n1 2 3 4\n",
"1\n2 3\n1 1\n1 2 3\n"
],
"output": [
"YES\n1 1\n",
"YES\n1 3\n",
"YES\n1 1000\n",
"YES\n1 2\n",
"YES\n1 4\nYES\n1 3\nNO\nYES\n1 3\nYES\n1 1\n",
"YES\n1 1\n",
"YES\n1 1\n"
]
} | 800 | 500 |
2 | 9 | 151_C. Win or Freeze | You can't possibly imagine how cold our friends are this winter in Nvodsk! Two of them play the following game to warm up: initially a piece of paper has an integer q. During a move a player should write any integer number that is a non-trivial divisor of the last written number. Then he should run this number of circles around the hotel. Let us remind you that a number's divisor is called non-trivial if it is different from one and from the divided number itself.
The first person who can't make a move wins as he continues to lie in his warm bed under three blankets while the other one keeps running. Determine which player wins considering that both players play optimally. If the first player wins, print any winning first move.
Input
The first line contains the only integer q (1 β€ q β€ 1013).
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.
Output
In the first line print the number of the winning player (1 or 2). If the first player wins then the second line should contain another integer β his first move (if the first player can't even make the first move, print 0). If there are multiple solutions, print any of them.
Examples
Input
6
Output
2
Input
30
Output
1
6
Input
1
Output
1
0
Note
Number 6 has only two non-trivial divisors: 2 and 3. It is impossible to make a move after the numbers 2 and 3 are written, so both of them are winning, thus, number 6 is the losing number. A player can make a move and write number 6 after number 30; 6, as we know, is a losing number. Thus, this move will bring us the victory. | {
"input": [
"1\n",
"6\n",
"30\n"
],
"output": [
"1\n0",
"2",
"1\n6"
]
} | {
"input": [
"8587340257\n",
"9\n",
"81\n",
"27\n",
"1408514752349\n",
"25\n",
"49380563\n",
"266418\n",
"319757451841\n",
"6599669076000\n",
"8\n",
"1000000000000\n",
"30971726\n",
"274875809788\n",
"64\n",
"34280152201\n",
"236\n",
"472670214391\n",
"7938986881993\n",
"44\n",
"4\n",
"388\n",
"2\n",
"802241960524\n",
"3047527844089\n",
"5\n",
"12\n",
"614125\n",
"1716443237161\n",
"48855707\n",
"99\n",
"9999925100701\n",
"5839252225\n",
"3\n",
"50\n",
"1307514188557\n",
"9999926826034\n",
"1468526771489\n",
"2975\n",
"8110708459517\n",
"401120980262\n",
"5138168457911\n",
"1245373417369\n",
"128\n",
"16\n",
"2000000014\n",
"445538663413\n",
"57461344602\n",
"324\n",
"7420738134810\n"
],
"output": [
"1\n9409",
"2",
"1\n9",
"1\n9",
"1\n72361",
"2",
"1\n289",
"1\n6",
"1\n289",
"1\n4",
"1\n4",
"1\n4",
"2",
"1\n4",
"1\n4",
"2",
"1\n4",
"1\n23020027",
"1\n378028993",
"1\n4",
"2",
"1\n4",
"1\n0",
"1\n4",
"2",
"1\n0",
"1\n4",
"1\n25",
"1\n5329",
"1\n2603",
"1\n9",
"1\n0",
"1\n25",
"1\n0",
"1\n10",
"1\n39283",
"2",
"1\n613783",
"1\n25",
"2",
"2",
"2",
"1\n908209",
"1\n4",
"1\n4",
"2",
"1\n0",
"1\n6",
"1\n4",
"1\n6"
]
} | 1,400 | 500 |
2 | 9 | 1547_C. Pair Programming | Monocarp and Polycarp are learning new programming techniques. Now they decided to try pair programming.
It's known that they have worked together on the same file for n + m minutes. Every minute exactly one of them made one change to the file. Before they started, there were already k lines written in the file.
Every minute exactly one of them does one of two actions: adds a new line to the end of the file or changes one of its lines.
Monocarp worked in total for n minutes and performed the sequence of actions [a_1, a_2, ..., a_n]. If a_i = 0, then he adds a new line to the end of the file. If a_i > 0, then he changes the line with the number a_i. Monocarp performed actions strictly in this order: a_1, then a_2, ..., a_n.
Polycarp worked in total for m minutes and performed the sequence of actions [b_1, b_2, ..., b_m]. If b_j = 0, then he adds a new line to the end of the file. If b_j > 0, then he changes the line with the number b_j. Polycarp performed actions strictly in this order: b_1, then b_2, ..., b_m.
Restore their common sequence of actions of length n + m such that all actions would be correct β there should be no changes to lines that do not yet exist. Keep in mind that in the common sequence Monocarp's actions should form the subsequence [a_1, a_2, ..., a_n] and Polycarp's β subsequence [b_1, b_2, ..., b_m]. They can replace each other at the computer any number of times.
Let's look at an example. Suppose k = 3. Monocarp first changed the line with the number 2 and then added a new line (thus, n = 2, \: a = [2, 0]). Polycarp first added a new line and then changed the line with the number 5 (thus, m = 2, \: b = [0, 5]).
Since the initial length of the file was 3, in order for Polycarp to change line number 5 two new lines must be added beforehand. Examples of correct sequences of changes, in this case, would be [0, 2, 0, 5] and [2, 0, 0, 5]. Changes [0, 0, 5, 2] (wrong order of actions) and [0, 5, 2, 0] (line 5 cannot be edited yet) are not correct.
Input
The first line contains an integer t (1 β€ t β€ 1000). Then t test cases follow. Before each test case, there is an empty line.
Each test case contains three lines. The first line contains three integers k, n, m (0 β€ k β€ 100, 1 β€ n, m β€ 100) β the initial number of lines in file and lengths of Monocarp's and Polycarp's sequences of changes respectively.
The second line contains n integers a_1, a_2, ..., a_n (0 β€ a_i β€ 300).
The third line contains m integers b_1, b_2, ..., b_m (0 β€ b_j β€ 300).
Output
For each test case print any correct common sequence of Monocarp's and Polycarp's actions of length n + m or -1 if such sequence doesn't exist.
Example
Input
5
3 2 2
2 0
0 5
4 3 2
2 0 5
0 6
0 2 2
1 0
2 3
5 4 4
6 0 8 0
0 7 0 9
5 4 1
8 7 8 0
0
Output
2 0 0 5
0 2 0 6 5
-1
0 6 0 7 0 8 0 9
-1 | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n"
],
"output": [
"0 2 0 5\n0 2 0 5 6\n-1\n0 6 0 7 0 8 0 9\n-1\n"
]
} | {
"input": [
"5\n\n3 2 2\n2 0\n0 5\n\n4 3 2\n2 0 5\n0 6\n\n0 2 2\n1 0\n2 3\n\n5 4 4\n6 0 8 0\n0 7 0 9\n\n5 4 1\n8 7 8 0\n0\n"
],
"output": [
"0 2 0 5\n0 2 0 5 6\n-1\n0 6 0 7 0 8 0 9\n-1\n"
]
} | 1,100 | 0 |
2 | 7 | 195_A. Let's Watch Football | Valeric and Valerko missed the last Euro football game, so they decided to watch the game's key moments on the Net. They want to start watching as soon as possible but the connection speed is too low. If they turn on the video right now, it will "hang up" as the size of data to watch per second will be more than the size of downloaded data per second.
The guys want to watch the whole video without any pauses, so they have to wait some integer number of seconds for a part of the video to download. After this number of seconds passes, they can start watching. Waiting for the whole video to download isn't necessary as the video can download after the guys started to watch.
Let's suppose that video's length is c seconds and Valeric and Valerko wait t seconds before the watching. Then for any moment of time t0, t β€ t0 β€ c + t, the following condition must fulfill: the size of data received in t0 seconds is not less than the size of data needed to watch t0 - t seconds of the video.
Of course, the guys want to wait as little as possible, so your task is to find the minimum integer number of seconds to wait before turning the video on. The guys must watch the video without pauses.
Input
The first line contains three space-separated integers a, b and c (1 β€ a, b, c β€ 1000, a > b). The first number (a) denotes the size of data needed to watch one second of the video. The second number (b) denotes the size of data Valeric and Valerko can download from the Net per second. The third number (c) denotes the video's length in seconds.
Output
Print a single number β the minimum integer number of seconds that Valeric and Valerko must wait to watch football without pauses.
Examples
Input
4 1 1
Output
3
Input
10 3 2
Output
5
Input
13 12 1
Output
1
Note
In the first sample video's length is 1 second and it is necessary 4 units of data for watching 1 second of video, so guys should download 4 Β· 1 = 4 units of data to watch the whole video. The most optimal way is to wait 3 seconds till 3 units of data will be downloaded and then start watching. While guys will be watching video 1 second, one unit of data will be downloaded and Valerik and Valerko will have 4 units of data by the end of watching. Also every moment till the end of video guys will have more data then necessary for watching.
In the second sample guys need 2 Β· 10 = 20 units of data, so they have to wait 5 seconds and after that they will have 20 units before the second second ends. However, if guys wait 4 seconds, they will be able to watch first second of video without pauses, but they will download 18 units of data by the end of second second and it is less then necessary. | {
"input": [
"10 3 2\n",
"13 12 1\n",
"4 1 1\n"
],
"output": [
"5\n",
"1\n",
"3\n"
]
} | {
"input": [
"993 992 991\n",
"100 1 10\n",
"960 935 994\n",
"99 8 99\n",
"60 16 1\n",
"759 10 258\n",
"24 19 9\n",
"196 169 144\n",
"1000 999 1\n",
"945 812 917\n",
"1000 100 10\n",
"500 300 300\n",
"888 777 1000\n",
"2 1 4\n",
"24 12 12\n",
"767 2 514\n",
"2 1 2\n",
"1000 1 1\n",
"5 2 1\n",
"70 32 1\n",
"765 123 899\n",
"17 7 10\n",
"5 4 10\n",
"888 777 888\n",
"66 38 4\n",
"1000 999 1000\n",
"9 3 300\n",
"244 87 4\n",
"765 123 45\n",
"1000 1 1000\n",
"305 203 421\n",
"100 10 1\n",
"64 12 8\n",
"894 1 999\n",
"2 1 1\n",
"18 14 10\n",
"6 2 4\n",
"888 777 1\n",
"27 26 1\n",
"2 1 3\n",
"5 1 5\n",
"7 3 200\n",
"561 31 917\n",
"17 10 7\n",
"93 74 831\n"
],
"output": [
"1\n",
"990\n",
"27\n",
"1127\n",
"3\n",
"19325\n",
"3\n",
"24\n",
"1\n",
"151\n",
"90\n",
"200\n",
"143\n",
"4\n",
"12\n",
"196605\n",
"2\n",
"999\n",
"2\n",
"2\n",
"4693\n",
"15\n",
"3\n",
"127\n",
"3\n",
"2\n",
"600\n",
"8\n",
"235\n",
"999000\n",
"212\n",
"9\n",
"35\n",
"892107\n",
"1\n",
"3\n",
"8\n",
"1\n",
"1\n",
"3\n",
"20\n",
"267\n",
"15678\n",
"5\n",
"214\n"
]
} | 1,000 | 500 |
2 | 7 | 219_A. k-String | A string is called a k-string if it can be represented as k concatenated copies of some string. For example, the string "aabaabaabaab" is at the same time a 1-string, a 2-string and a 4-string, but it is not a 3-string, a 5-string, or a 6-string and so on. Obviously any string is a 1-string.
You are given a string s, consisting of lowercase English letters and a positive integer k. Your task is to reorder the letters in the string s in such a way that the resulting string is a k-string.
Input
The first input line contains integer k (1 β€ k β€ 1000). The second line contains s, all characters in s are lowercase English letters. The string length s satisfies the inequality 1 β€ |s| β€ 1000, where |s| is the length of string s.
Output
Rearrange the letters in string s in such a way that the result is a k-string. Print the result on a single output line. If there are multiple solutions, print any of them.
If the solution doesn't exist, print "-1" (without quotes).
Examples
Input
2
aazz
Output
azaz
Input
3
abcabcabz
Output
-1 | {
"input": [
"2\naazz\n",
"3\nabcabcabz\n"
],
"output": [
"azaz",
"-1\n"
]
} | {
"input": [
"2\naaab\n",
"2\nbabac\n",
"2\naaaaaabbbb\n",
"1\naabaab\n",
"2\naabbbbccccccdddddddd\n",
"2\nabba\n",
"2\naaaazzzz\n",
"250\ncececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece\n",
"3\naaaaaaaaacccdddddd\n",
"2\naabaab\n",
"1\naaaaa\n",
"7\nabacaba\n",
"2\naaaabbbb\n",
"5\naaaaa\n",
"1\naaa\n",
"2\naaazz\n",
"3\naabaaaaabb\n",
"2\naaaa\n",
"2\naa\n",
"3\nbbbccc\n",
"15\nabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaaabaabbbcababaaa\n",
"1\na\n",
"2\nbbaaaa\n",
"2\naaaabb\n",
"2\naabbbb\n",
"2\naaaaaazz\n",
"3\naaaaaaaaacccbbbbbb\n",
"2\nbbbbaa\n",
"2\naaaazz\n",
"2\naazzzz\n",
"2\nacaccc\n"
],
"output": [
"-1\n",
"-1\n",
"aaabbaaabb",
"aaaabb\n",
"abbcccddddabbcccdddd",
"abab\n",
"aazzaazz",
"cececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececececece\n",
"aaacddaaacddaaacdd",
"aabaab\n",
"aaaaa\n",
"-1\n",
"aabbaabb\n",
"aaaaa\n",
"aaa\n",
"-1\n",
"-1\n",
"aaaa\n",
"aa\n",
"bcbcbc\n",
"aaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbcaaaaaaaabbbbbbc",
"a\n",
"aabaab\n",
"aabaab\n",
"abbabb\n",
"aaazaaaz",
"aaabbcaaabbcaaabbc\n",
"abbabb\n",
"aazaaz",
"azzazz\n",
"accacc\n"
]
} | 1,000 | 500 |
2 | 9 | 242_C. King's Path | The black king is standing on a chess field consisting of 109 rows and 109 columns. We will consider the rows of the field numbered with integers from 1 to 109 from top to bottom. The columns are similarly numbered with integers from 1 to 109 from left to right. We will denote a cell of the field that is located in the i-th row and j-th column as (i, j).
You know that some squares of the given chess field are allowed. All allowed cells of the chess field are given as n segments. Each segment is described by three integers ri, ai, bi (ai β€ bi), denoting that cells in columns from number ai to number bi inclusive in the ri-th row are allowed.
Your task is to find the minimum number of moves the king needs to get from square (x0, y0) to square (x1, y1), provided that he only moves along the allowed cells. In other words, the king can be located only on allowed cells on his way.
Let us remind you that a chess king can move to any of the neighboring cells in one move. Two cells of a chess field are considered neighboring if they share at least one point.
Input
The first line contains four space-separated integers x0, y0, x1, y1 (1 β€ x0, y0, x1, y1 β€ 109), denoting the initial and the final positions of the king.
The second line contains a single integer n (1 β€ n β€ 105), denoting the number of segments of allowed cells. Next n lines contain the descriptions of these segments. The i-th line contains three space-separated integers ri, ai, bi (1 β€ ri, ai, bi β€ 109, ai β€ bi), denoting that cells in columns from number ai to number bi inclusive in the ri-th row are allowed. Note that the segments of the allowed cells can intersect and embed arbitrarily.
It is guaranteed that the king's initial and final position are allowed cells. It is guaranteed that the king's initial and the final positions do not coincide. It is guaranteed that the total length of all given segments doesn't exceed 105.
Output
If there is no path between the initial and final position along allowed cells, print -1.
Otherwise print a single integer β the minimum number of moves the king needs to get from the initial position to the final one.
Examples
Input
5 7 6 11
3
5 3 8
6 7 11
5 2 5
Output
4
Input
3 4 3 10
3
3 1 4
4 5 9
3 10 10
Output
6
Input
1 1 2 10
2
1 1 3
2 6 10
Output
-1 | {
"input": [
"3 4 3 10\n3\n3 1 4\n4 5 9\n3 10 10\n",
"1 1 2 10\n2\n1 1 3\n2 6 10\n",
"5 7 6 11\n3\n5 3 8\n6 7 11\n5 2 5\n"
],
"output": [
"6\n",
"-1\n",
"4\n"
]
} | {
"input": [
"1 1 1 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"6 15 7 15\n9\n6 15 15\n7 14 14\n6 15 15\n9 14 14\n7 14 16\n6 15 15\n6 15 15\n7 14 14\n8 15 15\n",
"1 1 1000000000 2\n5\n1000000000 1 10000\n19920401 1188 5566\n1000000000 1 10000\n1 1 10000\n5 100 200\n",
"89 29 88 30\n16\n87 31 31\n14 95 95\n98 88 89\n96 88 88\n14 97 97\n13 97 98\n100 88 88\n88 32 32\n99 88 89\n90 29 29\n87 31 31\n15 94 96\n89 29 29\n88 32 32\n97 89 89\n88 29 30\n",
"30 14 39 19\n31\n35 7 11\n37 11 12\n32 13 13\n37 5 6\n46 13 13\n37 14 14\n31 13 13\n43 13 19\n45 15 19\n46 13 13\n32 17 17\n41 14 19\n30 14 14\n43 13 17\n34 16 18\n44 11 19\n38 13 13\n40 12 20\n37 16 18\n46 16 18\n34 10 14\n36 9 10\n36 15 19\n38 15 19\n42 13 19\n33 14 15\n35 15 19\n33 17 18\n39 12 20\n36 5 7\n45 12 12\n",
"9 8 7 8\n9\n10 6 6\n10 6 6\n7 7 8\n9 5 6\n8 9 9\n9 5 5\n9 8 8\n8 5 6\n9 10 10\n",
"2 1 1 1\n2\n1 1 2\n2 1 2\n",
"13 16 20 10\n18\n13 16 16\n20 10 10\n19 10 10\n12 15 15\n20 10 10\n18 11 11\n19 10 10\n19 10 10\n20 10 10\n19 10 10\n20 10 10\n20 10 10\n19 10 10\n18 11 11\n13 16 16\n12 15 15\n19 10 10\n19 10 10\n"
],
"output": [
"1\n",
"1\n",
"-1\n",
"1\n",
"9\n",
"2\n",
"1\n",
"-1\n"
]
} | 1,800 | 1,500 |
2 | 7 | 268_A. Games | Manao works on a sports TV. He's spent much time watching the football games of some country. After a while he began to notice different patterns. For example, each team has two sets of uniforms: home uniform and guest uniform. When a team plays a game at home, the players put on the home uniform. When a team plays as a guest on somebody else's stadium, the players put on the guest uniform. The only exception to that rule is: when the home uniform color of the host team matches the guests' uniform, the host team puts on its guest uniform as well. For each team the color of the home and guest uniform is different.
There are n teams taking part in the national championship. The championship consists of nΒ·(n - 1) games: each team invites each other team to its stadium. At this point Manao wondered: how many times during the championship is a host team going to put on the guest uniform? Note that the order of the games does not affect this number.
You know the colors of the home and guest uniform for each team. For simplicity, the colors are numbered by integers in such a way that no two distinct colors have the same number. Help Manao find the answer to his question.
Input
The first line contains an integer n (2 β€ n β€ 30). Each of the following n lines contains a pair of distinct space-separated integers hi, ai (1 β€ hi, ai β€ 100) β the colors of the i-th team's home and guest uniforms, respectively.
Output
In a single line print the number of games where the host team is going to play in the guest uniform.
Examples
Input
3
1 2
2 4
3 4
Output
1
Input
4
100 42
42 100
5 42
100 5
Output
5
Input
2
1 2
1 2
Output
0
Note
In the first test case the championship consists of 6 games. The only game with the event in question is the game between teams 2 and 1 on the stadium of team 2.
In the second test sample the host team will have to wear guest uniform in the games between teams: 1 and 2, 2 and 1, 2 and 3, 3 and 4, 4 and 2 (the host team is written first). | {
"input": [
"2\n1 2\n1 2\n",
"4\n100 42\n42 100\n5 42\n100 5\n",
"3\n1 2\n2 4\n3 4\n"
],
"output": [
"0\n",
"5\n",
"1\n"
]
} | {
"input": [
"24\n9 83\n90 31\n83 3\n83 3\n21 31\n83 3\n32 31\n12 21\n31 21\n90 32\n32 21\n12 9\n12 31\n9 83\n83 12\n32 3\n32 83\n90 31\n9 32\n31 21\n83 90\n32 21\n21 3\n32 9\n",
"25\n91 57\n2 73\n54 57\n2 57\n23 57\n2 6\n57 54\n57 23\n91 54\n91 23\n57 23\n91 57\n54 2\n6 91\n57 54\n2 57\n57 91\n73 91\n57 23\n91 57\n2 73\n91 2\n23 6\n2 73\n23 6\n",
"29\n8 18\n33 75\n69 22\n97 95\n1 97\n78 10\n88 18\n13 3\n19 64\n98 12\n79 92\n41 72\n69 15\n98 31\n57 74\n15 56\n36 37\n15 66\n63 100\n16 42\n47 56\n6 4\n73 15\n30 24\n27 71\n12 19\n88 69\n85 6\n50 11\n",
"30\n67 21\n85 39\n85 87\n21 39\n66 85\n10 95\n10 21\n87 85\n82 21\n67 21\n95 10\n21 39\n82 21\n21 66\n66 39\n95 30\n67 85\n66 82\n85 82\n21 66\n10 39\n67 10\n21 85\n10 82\n85 95\n10 85\n21 39\n85 39\n39 10\n95 67\n",
"22\n78 92\n15 92\n92 78\n78 80\n92 16\n24 80\n92 16\n16 92\n78 16\n24 78\n80 78\n92 80\n16 80\n80 78\n15 78\n92 16\n24 15\n24 80\n80 16\n16 80\n92 80\n24 80\n",
"29\n80 27\n69 80\n27 80\n69 80\n80 27\n80 27\n80 27\n80 69\n27 69\n80 69\n80 27\n27 69\n69 27\n80 69\n27 69\n69 80\n27 69\n80 69\n80 27\n69 27\n27 69\n27 80\n80 27\n69 80\n27 69\n80 69\n69 80\n69 80\n27 80\n",
"4\n8 7\n8 7\n7 8\n7 8\n",
"30\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n",
"29\n78 27\n50 68\n24 26\n68 43\n38 78\n26 38\n78 28\n28 26\n27 24\n23 38\n24 26\n24 43\n61 50\n38 78\n27 23\n61 26\n27 28\n43 23\n28 78\n43 27\n43 78\n27 61\n28 38\n61 78\n50 26\n43 27\n26 78\n28 50\n43 78\n",
"10\n68 42\n1 35\n25 70\n59 79\n65 63\n46 6\n28 82\n92 62\n43 96\n37 28\n",
"15\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n2 1\n1 2\n",
"30\n100 99\n58 59\n56 57\n54 55\n52 53\n50 51\n48 49\n46 47\n44 45\n42 43\n40 41\n38 39\n36 37\n34 35\n32 33\n30 31\n28 29\n26 27\n24 25\n22 23\n20 21\n18 19\n16 17\n14 15\n12 13\n10 11\n8 9\n6 7\n4 5\n2 3\n",
"13\n76 58\n32 85\n99 79\n23 58\n96 59\n72 35\n53 43\n96 55\n41 78\n75 10\n28 11\n72 7\n52 73\n",
"12\n1 2\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n2 1\n2 1\n2 1\n",
"6\n1 2\n1 2\n1 2\n1 2\n1 2\n2 1\n",
"30\n19 71\n7 89\n89 71\n21 7\n19 21\n7 89\n19 71\n89 8\n89 21\n19 8\n21 7\n8 89\n19 89\n7 21\n19 8\n19 7\n7 19\n8 21\n71 21\n71 89\n7 19\n7 19\n21 7\n21 19\n21 19\n71 8\n21 8\n71 19\n19 71\n8 21\n",
"15\n9 3\n2 6\n7 6\n5 10\n9 5\n8 1\n10 5\n2 8\n4 5\n9 8\n5 3\n3 8\n9 8\n4 10\n8 5\n",
"30\n10 39\n89 1\n78 58\n75 99\n36 13\n77 50\n6 97\n79 28\n27 52\n56 5\n93 96\n40 21\n33 74\n26 37\n53 59\n98 56\n61 65\n42 57\n9 7\n25 63\n74 34\n96 84\n95 47\n12 23\n34 21\n71 6\n27 13\n15 47\n64 14\n12 77\n",
"28\n31 66\n31 91\n91 31\n97 66\n31 66\n31 66\n66 91\n91 31\n97 31\n91 97\n97 31\n66 31\n66 97\n91 31\n31 66\n31 66\n66 31\n31 97\n66 97\n97 31\n31 91\n66 91\n91 66\n31 66\n91 66\n66 31\n66 31\n91 97\n",
"30\n46 100\n87 53\n34 84\n44 66\n23 20\n50 34\n90 66\n17 39\n13 22\n94 33\n92 46\n63 78\n26 48\n44 61\n3 19\n41 84\n62 31\n65 89\n23 28\n58 57\n19 85\n26 60\n75 66\n69 67\n76 15\n64 15\n36 72\n90 89\n42 69\n45 35\n",
"30\n44 17\n44 17\n44 17\n17 44\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n44 17\n44 17\n44 17\n17 44\n17 44\n17 44\n44 17\n44 17\n17 44\n44 17\n44 17\n44 17\n17 44\n17 44\n44 17\n17 44\n44 17\n44 17\n44 17\n",
"2\n46 6\n6 46\n",
"4\n1 2\n1 2\n2 1\n2 1\n",
"18\n6 90\n100 79\n26 100\n67 100\n29 100\n100 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 100\n",
"18\n6 90\n70 79\n26 52\n67 81\n29 95\n41 32\n94 88\n18 58\n59 65\n51 56\n64 68\n34 2\n6 98\n95 82\n34 2\n40 98\n83 78\n29 2\n",
"23\n43 78\n31 28\n58 80\n66 63\n20 4\n51 95\n40 20\n50 14\n5 34\n36 39\n77 42\n64 97\n62 89\n16 56\n8 34\n58 16\n37 35\n37 66\n8 54\n50 36\n24 8\n68 48\n85 33\n",
"25\n2 1\n1 2\n1 2\n1 2\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n1 2\n1 2\n2 1\n2 1\n2 1\n1 2\n2 1\n1 2\n2 1\n2 1\n2 1\n2 1\n1 2\n",
"7\n4 7\n52 55\n16 4\n55 4\n20 99\n3 4\n7 52\n"
],
"output": [
"59\n",
"96\n",
"10\n",
"100\n",
"74\n",
"277\n",
"8\n",
"450\n",
"73\n",
"1\n",
"108\n",
"0\n",
"0\n",
"72\n",
"10\n",
"154\n",
"20\n",
"6\n",
"210\n",
"4\n",
"418\n",
"2\n",
"8\n",
"8\n",
"1\n",
"6\n",
"312\n",
"6\n"
]
} | 800 | 500 |
2 | 10 | 290_D. Orange | <image>
Input
The first line of the input is a string (between 1 and 50 characters long, inclusive). Each character will be a letter of English alphabet, lowercase or uppercase.
The second line of the input is an integer between 0 and 26, inclusive.
Output
Output the required string.
Examples
Input
AprilFool
14
Output
AprILFooL | {
"input": [
"AprilFool\n14\n"
],
"output": [
"AprILFooL"
]
} | {
"input": [
"qH\n2\n",
"nifzlTLaeWxTD\n0\n",
"WlwbRjvrOZakKXqecEdlrCnmvXQtLKBsy\n5\n",
"LiqWMLEULRhW\n1\n",
"kGqopTbelcDUcoZgnnRYXgPCRQwSLoqeIByFWDI\n26\n",
"DuFhhnq\n4\n",
"aaaaAaaaaaaAAaaAaaAaAaaaAaaaaaAAaaAAAAAaaAaAAAAaAA\n4\n",
"VtQISIHREYaEGPustEkzJRN\n20\n",
"aaaaaaAAAaaaaAaaAaaAaaaaAAaAAAaaAAaaaAAaaaaaAaaAAa\n2\n",
"uehLuNwrjO\n0\n",
"MDJivQRiOIVRcCdkSuUlNbMEOkIVJRMTAnHbkVaOmOblLfignh\n25\n",
"isfvbcBEEPaXUDhbVhwddjEutVQqNdlimIKjUnajDQ\n2\n",
"BCABcbacbcbAAACCabbaccAabAAaaCCBcBAcCcbaABCCAcCb\n4\n",
"IOJRIQefPFxpUj\n18\n",
"RvpuYTxsbDiJDOLauRlfatcfwvtnDzKyaewGrZ\n22\n",
"fQHHXCdeaintxHWcFcaSGWFvqnYMEByMlSNKumiFgnJB\n0\n",
"cdccAAaBBAADdaCDBbDcaDDabdadAbBccCCCDDBADDcdAdC\n4\n",
"R\n26\n",
"sPWSFWWqZBPon\n3\n",
"abcdefabc\n3\n",
"SICNEaKsjCnvOEcVqFHLIC\n16\n",
"abczxy\n0\n",
"sm\n26\n",
"fBUycJpfGhsfIVnXAovyoDyndkhv\n9\n",
"TtQEIg\n24\n",
"vPuebwksPlxuevRLuWcACTBBgVnmcAUsQUficgEAhoEm\n9\n",
"GnlFOqPeZtPiBkvvLhaDvGPgFqBTnLgMT\n12\n",
"Ik\n3\n",
"VWOibsVSFkxPCmyZLWIOxFbfXdlsNzxVcUVf\n8\n",
"gfSAltDEjuPqEsOFuiTpcUpCOiENCLbHHnCgvCQtW\n13\n",
"fgWjSAlPOvcAbCdDEFjz\n7\n",
"pFgLGSkFnGpNKALeDPGlciUNTTlCtAPlFhaIRutCFaFo\n24\n",
"cefEDAbedffbaCcEDfEeCEaAcCeFCcEabEecdEdcaFFde\n4\n",
"WHbBHzhSNkCZOAOwiKdu\n17\n",
"RtsUOGkraqKyjTktAXloOEmQj\n18\n",
"LdsmfiNFkPfJgRxytsSJMQZnDTZZ\n11\n",
"xedzyPU\n13\n",
"bBbAbbbbaaAAAaabbBbaaabBaaaBaBbAaBabaAAAaaaaBabbb\n4\n",
"HXyXuYceFtVUMyLqi\n21\n",
"tAjlldiqGZUayJZHFQHFJVRukaIKepPVucrkyPtMrhIXoxZbw\n12\n",
"EcCEECdCEBaaeCBEBbAaCAeEdeCEedCAdDeEbcACdCcCCd\n4\n",
"hQfrRArEPuVAQGfcSuoVKBKvY\n22\n",
"jWBVk\n17\n"
],
"output": [
"qh",
"nifzltlaewxtd",
"wlwBrjvrozAkkxqECEDlrCnmvxqtlkBsy",
"liqwmleulrhw",
"KGQOPTBELCDUCOZGNNRYXGPCRQWSLOQEIBYFWDI",
"Dufhhnq",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"vTQISIHREyAEGPuSTEKzJRN",
"AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA",
"uehlunwrjo",
"MDJIVQRIOIVRCCDKSUULNBMEOKIVJRMTANHBKVAOMOBLLFIGNH",
"isfvBcBeepAxudhBvhwddjeutvqqndlimikjunAjdq",
"BCABCBACBCBAAACCABBACCAABAAAACCBCBACCCBAABCCACCB",
"IOJRIQEFPFxPuJ",
"RVPUyTxSBDIJDOLAURLFATCFwVTNDzKyAEwGRz",
"fqhhxcdeaintxhwcfcasgwfvqnymebymlsnkumifgnjb",
"CDCCAAABBAADDACDBBDCADDABDADABBCCCCCDDBADDCDADC",
"R",
"spwsfwwqzBpon",
"ABCdefABC",
"sICNEAKsJCNvOECvqFHLIC",
"abczxy",
"SM",
"FBuyCjpFGHsFIvnxAovyoDynDkHv",
"TTQEIG",
"vpuEBwksplxuEvrluwCACtBBGvnmCAusquFICGEAHoEm",
"GnLFoqpEztpIBKvvLHADvGpGFqBtnLGmt",
"ik",
"vwoiBsvsFkxpCmyzlwioxFBFxDlsnzxvCuvF",
"GFsALtDEJupqEsoFuItpCupCoIEnCLBHHnCGvCqtw",
"FGwjsAlpovCABCDDEFjz",
"PFGLGSKFNGPNKALEDPGLCIUNTTLCTAPLFHAIRUTCFAFO",
"CefeDABeDffBACCeDfeeCeAACCefCCeABeeCDeDCAffDe",
"wHBBHzHsNKCzOAOwIKDu",
"RtsuOGKRAQKyJtKtAxLOOEMQJ",
"lDsmFInFKpFJGrxytssJmqznDtzz",
"xEDzypu",
"BBBABBBBAAAAAAABBBBAAABBAAABABBAABABAAAAAAAABABBB",
"HxyxUyCEFTvUMyLQI",
"tAJLLDIqGzuAyJzHFqHFJvruKAIKEppvuCrKyptmrHIxoxzBw",
"eCCeeCDCeBAAeCBeBBAACAeeDeCeeDCADDeeBCACDCCCCD",
"HQFRRAREPUVAQGFCSUOVKBKVy",
"JwBvK"
]
} | 1,400 | 0 |
2 | 8 | 316_B2. EKG | In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.
(Cultural note: standing in huge and disorganized queues for hours is a native tradition in Russia, dating back to the Soviet period. Queues can resemble crowds rather than lines. Not to get lost in such a queue, a person should follow a strict survival technique: you approach the queue and ask who the last person is, somebody answers and you join the crowd. Now you're the last person in the queue till somebody else shows up. You keep an eye on the one who was last before you as he is your only chance to get to your destination) I'm sure many people have had the problem when a stranger asks who the last person in the queue is and even dares to hint that he will be the last in the queue and then bolts away to some unknown destination. These are the representatives of the modern world, in which the ratio of lack of time is so great that they do not even watch foreign top-rated TV series. Such people often create problems in queues, because the newcomer does not see the last person in the queue and takes a place after the "virtual" link in this chain, wondering where this legendary figure has left.
The Smart Beaver has been ill and he's made an appointment with a therapist. The doctor told the Beaver the sad news in a nutshell: it is necessary to do an electrocardiogram. The next day the Smart Beaver got up early, put on the famous TV series on download (three hours till the download's complete), clenched his teeth and bravely went to join a queue to the electrocardiogram room, which is notorious for the biggest queues at the clinic.
Having stood for about three hours in the queue, the Smart Beaver realized that many beavers had not seen who was supposed to stand in the queue before them and there was a huge mess. He came up to each beaver in the ECG room queue and asked who should be in front of him in the queue. If the beaver did not know his correct position in the queue, then it might be his turn to go get an ECG, or maybe he should wait for a long, long time...
As you've guessed, the Smart Beaver was in a hurry home, so he gave you all the necessary information for you to help him to determine what his number in the queue can be.
Input
The first line contains two integers n (1 β€ n β€ 103) and x (1 β€ x β€ n) β the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n.
The second line contains n integers a1, a2, ..., an (0 β€ ai β€ n) β the number of the beaver followed by the i-th beaver. If ai = 0, then the i-th beaver doesn't know who is should be in front of him. It is guaranteed that values ai are correct. That is there is no cycles in the dependencies. And any beaver is followed by at most one beaver in the queue.
The input limits for scoring 30 points are (subproblem B1):
* It is guaranteed that the number of zero elements ai doesn't exceed 20.
The input limits for scoring 100 points are (subproblems B1+B2):
* The number of zero elements ai is arbitrary.
Output
Print all possible positions of the Smart Beaver in the line in the increasing order.
Examples
Input
6 1
2 0 4 0 6 0
Output
2
4
6
Input
6 2
2 3 0 5 6 0
Output
2
5
Input
4 1
0 0 0 0
Output
1
2
3
4
Input
6 2
0 0 1 0 4 5
Output
1
3
4
6
Note
<image> Picture for the fourth test. | {
"input": [
"6 2\n2 3 0 5 6 0\n",
"6 2\n0 0 1 0 4 5\n",
"6 1\n2 0 4 0 6 0\n",
"4 1\n0 0 0 0\n"
],
"output": [
"2\n5\n",
"1\n3\n4\n6\n",
"2\n4\n6\n",
"1\n2\n3\n4\n"
]
} | {
"input": [
"20 20\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"10 4\n0 1 4 2 7 0 10 0 5 8\n",
"10 7\n10 8 6 5 0 0 0 4 3 9\n",
"10 1\n8 7 0 2 0 10 0 0 3 5\n",
"10 7\n7 9 2 10 0 0 0 3 5 1\n",
"10 2\n10 0 9 0 0 4 2 6 8 0\n",
"10 2\n0 7 0 10 8 0 4 2 3 0\n"
],
"output": [
"1\n2\n3\n4\n5\n6\n7\n8\n9\n10\n11\n12\n13\n14\n15\n16\n17\n18\n19\n20\n",
"3\n4\n8\n9\n",
"1\n5\n6\n10\n",
"2\n4\n5\n7\n8\n10\n",
"1\n2\n6\n7\n",
"1\n2\n3\n4\n6\n7\n8\n9\n",
"4\n5\n6\n7\n8\n"
]
} | 1,600 | 70 |
2 | 7 | 339_A. Helpful Maths | Xenia the beginner mathematician is a third year student at elementary school. She is now learning the addition operation.
The teacher has written down the sum of multiple numbers. Pupils should calculate the sum. To make the calculation easier, the sum only contains numbers 1, 2 and 3. Still, that isn't enough for Xenia. She is only beginning to count, so she can calculate a sum only if the summands follow in non-decreasing order. For example, she can't calculate sum 1+3+2+1 but she can calculate sums 1+1+2 and 3+3.
You've got the sum that was written on the board. Rearrange the summans and print the sum in such a way that Xenia can calculate the sum.
Input
The first line contains a non-empty string s β the sum Xenia needs to count. String s contains no spaces. It only contains digits and characters "+". Besides, string s is a correct sum of numbers 1, 2 and 3. String s is at most 100 characters long.
Output
Print the new sum that Xenia can count.
Examples
Input
3+2+1
Output
1+2+3
Input
1+1+3+1+3
Output
1+1+1+3+3
Input
2
Output
2 | {
"input": [
"2\n",
"3+2+1\n",
"1+1+3+1+3\n"
],
"output": [
"2\n",
"1+2+3\n",
"1+1+1+3+3\n"
]
} | {
"input": [
"2+2+1+1+3\n",
"3+1\n",
"1+3\n",
"2+2+1+1+1+3+1+1+3+3+2+3+1+3+1+1+3+1+1+2+2+2+2+1+2+1+2+1+1+1+3+1+3+2+3+2+3+3+1+1+1+2+3+2+1+3+1+3+2+2\n",
"2+2\n",
"1+1\n",
"2+3+3+1+2+2+2+1+1+2+1+3+2+2+3+3+2+2+3+3+3+1+1+1+3+3+3+2+1+3+2+3+2+1+1+3+3+3+1+2+2+1+2+2+1+2+1+3+1+1\n",
"1\n",
"1+2+1+2+2+2+2+1+3+3\n",
"2+3\n",
"1+2\n",
"3+2\n",
"3+3\n",
"2+1+2+2+1+3+2+3+1+1+2+1+2+2+3+1+1+3+3+3+2+2+3+2+2+2+1+2+1+2+3+2+2+2+1+3+1+3+3+3+1+2+1+2+2+2+2+3+1+1\n",
"2+1+2+2+2+3+1+3+1+2\n",
"2+1\n",
"3+2+3+3+2+2+1+2+1+2+3+1+2+3+2+3+2+1+2+2+1+1+2+2+3+2+1+3+1+1+3+2+2+2+2+3+3+2+2+3+3+1+1+2+3+3+2+3+3+3\n",
"3\n"
],
"output": [
"1+1+2+2+3\n",
"1+3\n",
"1+3\n",
"1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3\n",
"2+2\n",
"1+1\n",
"1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3\n",
"1\n",
"1+1+1+2+2+2+2+2+3+3\n",
"2+3\n",
"1+2\n",
"2+3\n",
"3+3\n",
"1+1+1+1+1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3\n",
"1+1+1+2+2+2+2+2+3+3\n",
"1+2\n",
"1+1+1+1+1+1+1+1+1+1+1+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+2+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3+3\n",
"3\n"
]
} | 800 | 500 |
2 | 9 | 361_C. Levko and Array Recovery | Levko loves array a1, a2, ... , an, consisting of integers, very much. That is why Levko is playing with array a, performing all sorts of operations with it. Each operation Levko performs is of one of two types:
1. Increase all elements from li to ri by di. In other words, perform assignments aj = aj + di for all j that meet the inequation li β€ j β€ ri.
2. Find the maximum of elements from li to ri. That is, calculate the value <image>.
Sadly, Levko has recently lost his array. Fortunately, Levko has records of all operations he has performed on array a. Help Levko, given the operation records, find at least one suitable array. The results of all operations for the given array must coincide with the record results. Levko clearly remembers that all numbers in his array didn't exceed 109 in their absolute value, so he asks you to find such an array.
Input
The first line contains two integers n and m (1 β€ n, m β€ 5000) β the size of the array and the number of operations in Levko's records, correspondingly.
Next m lines describe the operations, the i-th line describes the i-th operation. The first integer in the i-th line is integer ti (1 β€ ti β€ 2) that describes the operation type. If ti = 1, then it is followed by three integers li, ri and di (1 β€ li β€ ri β€ n, - 104 β€ di β€ 104) β the description of the operation of the first type. If ti = 2, then it is followed by three integers li, ri and mi (1 β€ li β€ ri β€ n, - 5Β·107 β€ mi β€ 5Β·107) β the description of the operation of the second type.
The operations are given in the order Levko performed them on his array.
Output
In the first line print "YES" (without the quotes), if the solution exists and "NO" (without the quotes) otherwise.
If the solution exists, then on the second line print n integers a1, a2, ... , an (|ai| β€ 109) β the recovered array.
Examples
Input
4 5
1 2 3 1
2 1 2 8
2 3 4 7
1 1 3 3
2 3 4 8
Output
YES
4 7 4 7
Input
4 5
1 2 3 1
2 1 2 8
2 3 4 7
1 1 3 3
2 3 4 13
Output
NO | {
"input": [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 13\n"
],
"output": [
"YES\n8 7 4 7 ",
"NO\n"
]
} | {
"input": [
"4 5\n1 2 3 1\n2 1 2 8\n2 3 4 7\n1 1 3 3\n2 3 4 8\n",
"1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 7\n",
"2 2\n2 1 2 8\n2 1 2 7\n",
"97 29\n2 78 82 356152\n2 14 29 430177\n1 59 84 3680\n1 49 89 -2247\n1 92 96 3701\n2 54 89 377271\n1 62 70 -507\n2 94 97 431563\n1 46 55 -9257\n1 51 83 1627\n1 10 20 6633\n1 17 34 -9263\n2 66 92 383251\n1 12 82 3884\n1 78 96 -5379\n2 13 35 424798\n1 68 91 2939\n2 80 84 214725\n1 61 85 -4390\n1 85 96 3106\n2 17 25 424798\n1 91 93 7298\n2 32 94 429290\n2 20 74 427777\n1 56 87 -4571\n2 71 91 351695\n1 45 64 2697\n2 20 40 427777\n1 60 96 -3025\n",
"1 2\n2 1 1 2\n2 1 1 1\n",
"3 2\n2 1 2 100\n2 1 3 50\n",
"1 2\n2 1 1 5\n2 1 1 1\n",
"1 2\n2 1 1 10\n2 1 1 5\n",
"2 2\n2 1 1 10\n2 1 2 5\n",
"1 4\n1 1 1 2\n2 1 1 6\n1 1 1 1\n2 1 1 8\n",
"1 1\n2 1 1 40000000\n",
"1 2\n2 1 1 8\n2 1 1 7\n",
"1 2\n2 1 1 1\n2 1 1 0\n"
],
"output": [
"YES\n8 7 4 7 ",
"YES\n4 ",
"NO\n",
"YES\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 414281 414281 414281 414281 423544 423544 423544 423544 430177 430177 430177 430177 430177 430177 430177 430177 430177 430177 430177 430177 430177 430177 420914 423893 423893 423893 423893 423893 423893 423893 423893 423893 423893 433150 433150 433150 435397 435397 433770 433770 433770 379518 379518 379518 379518 379518 375838 375838 375838 375838 375838 375838 375838 375838 375838 375838 375838 375838 350773 350773 350773 350773 350773 350773 350773 356152 356152 210221 210221 210221 214105 215732 362237 357847 357847 353276 353276 351029 343731 379550 420564 427862 427862 427862 431563 ",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n40000000 ",
"NO\n",
"NO\n"
]
} | 1,700 | 500 |
2 | 7 | 385_A. Bear and Raspberry | The bear decided to store some raspberry for the winter. He cunningly found out the price for a barrel of honey in kilos of raspberry for each of the following n days. According to the bear's data, on the i-th (1 β€ i β€ n) day, the price for one barrel of honey is going to is xi kilos of raspberry.
Unfortunately, the bear has neither a honey barrel, nor the raspberry. At the same time, the bear's got a friend who is ready to lend him a barrel of honey for exactly one day for c kilograms of raspberry. That's why the bear came up with a smart plan. He wants to choose some day d (1 β€ d < n), lent a barrel of honey and immediately (on day d) sell it according to a daily exchange rate. The next day (d + 1) the bear wants to buy a new barrel of honey according to a daily exchange rate (as he's got some raspberry left from selling the previous barrel) and immediately (on day d + 1) give his friend the borrowed barrel of honey as well as c kilograms of raspberry for renting the barrel.
The bear wants to execute his plan at most once and then hibernate. What maximum number of kilograms of raspberry can he earn? Note that if at some point of the plan the bear runs out of the raspberry, then he won't execute such a plan.
Input
The first line contains two space-separated integers, n and c (2 β€ n β€ 100, 0 β€ c β€ 100), β the number of days and the number of kilos of raspberry that the bear should give for borrowing the barrel.
The second line contains n space-separated integers x1, x2, ..., xn (0 β€ xi β€ 100), the price of a honey barrel on day i.
Output
Print a single integer β the answer to the problem.
Examples
Input
5 1
5 10 7 3 20
Output
3
Input
6 2
100 1 10 40 10 40
Output
97
Input
3 0
1 2 3
Output
0
Note
In the first sample the bear will lend a honey barrel at day 3 and then sell it for 7. Then the bear will buy a barrel for 3 and return it to the friend. So, the profit is (7 - 3 - 1) = 3.
In the second sample bear will lend a honey barrel at day 1 and then sell it for 100. Then the bear buy the barrel for 1 at the day 2. So, the profit is (100 - 1 - 2) = 97. | {
"input": [
"6 2\n100 1 10 40 10 40\n",
"5 1\n5 10 7 3 20\n",
"3 0\n1 2 3\n"
],
"output": [
"97\n",
"3\n",
"0\n"
]
} | {
"input": [
"89 1\n50 53 97 41 68 27 53 66 93 19 11 78 46 49 38 69 96 9 43 16 1 63 95 64 96 6 34 34 45 40 19 4 53 8 11 18 95 25 50 16 64 33 97 49 23 81 63 10 30 73 76 55 7 70 9 98 6 36 75 78 3 92 85 75 40 75 55 71 9 91 15 17 47 55 44 35 55 88 53 87 61 22 100 56 14 87 36 84 24\n",
"10 5\n10 1 11 2 12 3 13 4 14 5\n",
"6 100\n10 9 8 7 6 5\n",
"3 1\n19 20 1\n",
"59 27\n76 61 24 66 48 18 69 84 21 8 64 90 19 71 36 90 9 36 30 37 99 37 100 56 9 79 55 37 54 63 11 11 49 71 91 70 14 100 10 44 52 23 21 19 96 13 93 66 52 79 76 5 62 6 90 35 94 7 27\n",
"100 5\n15 91 86 53 18 52 26 89 8 4 5 100 11 64 88 91 35 57 67 72 71 71 69 73 97 23 11 1 59 86 37 82 6 67 71 11 7 31 11 68 21 43 89 54 27 10 3 33 8 57 79 26 90 81 6 28 24 7 33 50 24 13 27 85 4 93 14 62 37 67 33 40 7 48 41 4 14 9 95 10 64 62 7 93 23 6 28 27 97 64 26 83 70 0 97 74 11 82 70 93\n",
"3 3\n3 2 1\n",
"37 2\n65 36 92 92 92 76 63 56 15 95 75 26 15 4 73 50 41 92 26 20 19 100 63 55 25 75 61 96 35 0 14 6 96 3 28 41 83\n",
"2 0\n2 1\n",
"43 65\n32 58 59 75 85 18 57 100 69 0 36 38 79 95 82 47 7 55 28 88 27 88 63 71 80 86 67 53 69 37 99 54 81 19 55 12 2 17 84 77 25 26 62\n",
"96 0\n38 97 82 43 80 40 1 99 50 94 81 63 92 13 57 24 4 10 25 32 79 56 96 19 25 14 69 56 66 22 23 78 87 76 37 30 75 77 61 64 35 64 62 32 44 62 6 84 91 44 99 5 71 19 17 12 35 52 1 14 35 18 8 36 54 42 4 67 80 11 88 44 34 35 12 38 66 42 4 90 45 10 1 44 37 96 23 28 100 90 75 17 27 67 51 70\n",
"2 100\n0 0\n",
"100 100\n9 72 46 37 26 94 80 1 43 85 26 53 58 18 24 19 67 2 100 52 61 81 48 15 73 41 97 93 45 1 73 54 75 51 28 79 0 14 41 42 24 50 70 18 96 100 67 1 68 48 44 39 63 77 78 18 10 51 32 53 26 60 1 13 66 39 55 27 23 71 75 0 27 88 73 31 16 95 87 84 86 71 37 40 66 70 65 83 19 4 81 99 26 51 67 63 80 54 23 44\n",
"2 5\n5 4\n",
"12 64\n14 87 40 24 32 36 4 41 38 77 68 71\n",
"14 14\n87 63 62 31 59 47 40 89 92 43 80 30 99 42\n",
"86 54\n41 84 16 5 20 79 73 13 23 24 42 73 70 80 69 71 33 44 62 29 86 88 40 64 61 55 58 19 16 23 84 100 38 91 89 98 47 50 55 87 12 94 2 12 0 1 4 26 50 96 68 34 94 80 8 22 60 3 72 84 65 89 44 52 50 9 24 34 81 28 56 17 38 85 78 90 62 60 1 40 91 2 7 41 84 22\n",
"67 0\n40 48 15 46 90 7 65 52 24 15 42 81 2 6 71 94 32 18 97 67 83 98 48 51 10 47 8 68 36 46 65 75 90 30 62 9 5 35 80 60 69 58 62 68 58 73 80 9 22 46 56 64 44 11 93 73 62 54 15 20 17 69 16 33 85 62 49\n",
"3 100\n1 2 3\n",
"2 90\n10 5\n",
"5 1\n1 2 3 4 5\n",
"3 2\n3 3 3\n",
"3 1\n1 2 3\n",
"100 9\n66 71 37 41 23 38 77 11 74 13 51 26 93 56 81 17 12 70 85 37 54 100 14 99 12 83 44 16 99 65 13 48 92 32 69 33 100 57 58 88 25 45 44 85 5 41 82 15 37 18 21 45 3 68 33 9 52 64 8 73 32 41 87 99 26 26 47 24 79 93 9 44 11 34 85 26 14 61 49 38 25 65 49 81 29 82 28 23 2 64 38 13 77 68 67 23 58 57 83 46\n",
"75 94\n80 92 25 48 78 17 69 52 79 73 12 15 59 55 25 61 96 27 98 43 30 43 36 94 67 54 86 99 100 61 65 8 65 19 18 21 75 31 2 98 55 87 14 1 17 97 94 11 57 29 34 71 76 67 45 0 78 29 86 82 29 23 77 100 48 43 65 62 88 34 7 28 13 1 1\n",
"12 0\n100 1 100 2 100 3 100 4 100 5 100 0\n",
"19 4\n85 2 56 70 33 75 89 60 100 81 42 28 18 92 29 96 49 23 14\n",
"100 4\n2 57 70 8 44 10 88 67 50 44 93 79 72 50 69 19 21 9 71 47 95 13 46 10 68 72 54 40 15 83 57 92 58 25 4 22 84 9 8 55 87 0 16 46 86 58 5 21 32 28 10 46 11 29 13 33 37 34 78 33 33 21 46 70 77 51 45 97 6 21 68 61 87 54 8 91 37 12 76 61 57 9 100 45 44 88 5 71 98 98 26 45 37 87 34 50 33 60 64 77\n",
"5 1\n5 10 7 4 20\n"
],
"output": [
"91\n",
"4\n",
"0\n",
"18\n",
"63\n",
"84\n",
"0\n",
"91\n",
"1\n",
"4\n",
"94\n",
"0\n",
"0\n",
"0\n",
"0\n",
"43\n",
"38\n",
"83\n",
"0\n",
"0\n",
"0\n",
"0\n",
"0\n",
"78\n",
"0\n",
"100\n",
"79\n",
"87\n",
"2\n"
]
} | 1,000 | 500 |
2 | 11 | 405_E. Graph Cutting | Little Chris is participating in a graph cutting contest. He's a pro. The time has come to test his skills to the fullest.
Chris is given a simple undirected connected graph with n vertices (numbered from 1 to n) and m edges. The problem is to cut it into edge-distinct paths of length 2. Formally, Chris has to partition all edges of the graph into pairs in such a way that the edges in a single pair are adjacent and each edge must be contained in exactly one pair.
For example, the figure shows a way Chris can cut a graph. The first sample test contains the description of this graph.
<image>
You are given a chance to compete with Chris. Find a way to cut the given graph or determine that it is impossible!
Input
The first line of input contains two space-separated integers n and m (1 β€ n, m β€ 105), the number of vertices and the number of edges in the graph. The next m lines contain the description of the graph's edges. The i-th line contains two space-separated integers ai and bi (1 β€ ai, bi β€ n; ai β bi), the numbers of the vertices connected by the i-th edge. It is guaranteed that the given graph is simple (without self-loops and multi-edges) and connected.
Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++.
Output
If it is possible to cut the given graph into edge-distinct paths of length 2, output <image> lines. In the i-th line print three space-separated integers xi, yi and zi, the description of the i-th path. The graph should contain this path, i.e., the graph should contain edges (xi, yi) and (yi, zi). Each edge should appear in exactly one path of length 2. If there are multiple solutions, output any of them.
If it is impossible to cut the given graph, print "No solution" (without quotes).
Examples
Input
8 12
1 2
2 3
3 4
4 1
1 3
2 4
3 5
3 6
5 6
6 7
6 8
7 8
Output
1 2 4
1 3 2
1 4 3
5 3 6
5 6 8
6 7 8
Input
3 3
1 2
2 3
3 1
Output
No solution
Input
3 2
1 2
2 3
Output
1 2 3 | {
"input": [
"3 2\n1 2\n2 3\n",
"3 3\n1 2\n2 3\n3 1\n",
"8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n"
],
"output": [
"1 2 3\n",
"No solution\n",
"6 7 8 5 6 8 4 3 5 2 3 6 1 2 4 4 1 3 "
]
} | {
"input": [
"9 12\n1 2\n2 3\n4 5\n5 6\n6 7\n7 8\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"5 4\n2 1\n3 2\n4 3\n5 4\n",
"4 4\n1 2\n2 3\n3 1\n1 4\n",
"9 8\n1 9\n2 9\n3 9\n4 9\n5 9\n6 9\n7 9\n8 9\n",
"4 3\n3 2\n2 1\n1 4\n",
"8 12\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n3 5\n3 6\n5 6\n6 7\n6 8\n7 8\n",
"9 8\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n8 7\n9 8\n",
"10 30\n10 4\n3 8\n3 2\n10 1\n3 5\n3 4\n5 1\n8 2\n8 4\n3 10\n7 9\n3 6\n9 5\n5 10\n7 6\n7 5\n9 1\n2 7\n9 10\n1 4\n9 8\n6 2\n2 1\n7 1\n6 4\n4 5\n2 9\n10 8\n7 8\n5 2\n",
"7 6\n2 1\n3 2\n4 3\n5 4\n6 5\n7 6\n",
"4 5\n1 2\n2 3\n3 4\n4 1\n1 3\n",
"2 1\n1 2\n",
"7 10\n1 3\n2 3\n1 2\n3 4\n4 5\n4 6\n4 7\n5 6\n5 7\n6 7\n",
"4 6\n1 2\n2 3\n3 4\n4 1\n1 3\n2 4\n",
"10 9\n2 1\n3 1\n4 2\n5 4\n6 2\n7 4\n8 1\n9 8\n10 8\n"
],
"output": [
"5 8 7\n6 7 4\n1 4 5\n2 5 6\n9 6 3\n3 2 1\n",
"3 4 5\n1 2 3\n",
"1 3 2\n2 1 4\n",
"2 9 3 4 9 5 6 9 7 1 9 8 ",
"No solution\n",
"6 7 8 5 6 8 4 3 5 2 3 6 1 2 4 4 1 3 ",
"7 8 9\n5 6 7\n3 4 5\n1 2 3\n",
"7 9 5 6 7 5 7 2 6 9 2 5 2 8 9 3 8 7 2 3 5 4 3 6 8 4 6 10 4 5 3 10 5 9 10 8 10 1 5 9 1 4 2 1 7 ",
"5 6 7\n3 4 5\n1 2 3\n",
"No solution\n",
"No solution\n",
"1 2 3\n4 7 5\n4 6 7\n6 5 4\n4 3 1\n",
"1 4 2\n4 3 1\n3 2 1\n",
"No solution\n"
]
} | 2,300 | 3,000 |
2 | 7 | 433_A. Kitahara Haruki's Gift | Kitahara Haruki has bought n apples for Touma Kazusa and Ogiso Setsuna. Now he wants to divide all the apples between the friends.
Each apple weights 100 grams or 200 grams. Of course Kitahara Haruki doesn't want to offend any of his friend. Therefore the total weight of the apples given to Touma Kazusa must be equal to the total weight of the apples given to Ogiso Setsuna.
But unfortunately Kitahara Haruki doesn't have a knife right now, so he cannot split any apple into some parts. Please, tell him: is it possible to divide all the apples in a fair way between his friends?
Input
The first line contains an integer n (1 β€ n β€ 100) β the number of apples. The second line contains n integers w1, w2, ..., wn (wi = 100 or wi = 200), where wi is the weight of the i-th apple.
Output
In a single line print "YES" (without the quotes) if it is possible to divide all the apples between his friends. Otherwise print "NO" (without the quotes).
Examples
Input
3
100 200 100
Output
YES
Input
4
100 100 100 200
Output
NO
Note
In the first test sample Kitahara Haruki can give the first and the last apple to Ogiso Setsuna and the middle apple to Touma Kazusa. | {
"input": [
"4\n100 100 100 200\n",
"3\n100 200 100\n"
],
"output": [
"NO\n",
"YES\n"
]
} | {
"input": [
"9\n100 100 100 200 100 100 200 100 200\n",
"3\n100 100 100\n",
"7\n200 200 200 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"100\n100 100 200 200 100 200 100 100 100 100 100 100 200 100 200 200 200 100 100 200 200 200 200 200 100 200 100 200 100 100 100 200 100 100 200 100 200 100 100 100 200 200 100 100 100 200 200 200 200 200 100 200 200 100 100 100 100 200 100 100 200 100 100 100 100 200 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 200 100 200 200 100 200 100 200 200 200 200 200 200 100 100 100 200 200 100\n",
"56\n100 200 200 200 200 200 100 200 100 100 200 100 100 100 100 100 200 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 100 100 100 100 200 100 200 100 200 200 200 100 100 200 200 200 200 200 200 200 200 200 200 100\n",
"100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"6\n100 100 100 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 200 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"4\n200 100 100 200\n",
"60\n100 100 200 200 100 200 100 200 100 100 100 100 100 100 200 100 100 100 200 100 200 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100\n",
"72\n200 100 200 200 200 100 100 200 200 100 100 100 100 200 100 200 100 100 100 100 200 100 200 100 100 200 100 100 200 100 200 100 100 200 100 200 100 100 200 200 200 200 200 100 100 200 200 200 200 100 100 100 200 200 100 100 100 100 100 200 100 100 200 100 100 200 200 100 100 200 100 200\n",
"99\n100 200 100 100 100 100 200 200 100 200 100 100 200 100 100 100 100 100 100 200 100 100 100 100 100 100 100 200 100 200 100 100 100 100 100 100 100 200 200 200 200 200 200 200 100 200 100 200 100 200 100 200 100 100 200 200 200 100 200 200 200 200 100 200 100 200 200 200 200 100 200 100 200 200 100 200 200 200 200 200 100 100 200 100 100 100 100 200 200 200 100 100 200 200 200 200 200 200 200\n",
"100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"100\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"2\n200 200\n",
"5\n100 100 100 100 200\n",
"5\n200 200 200 200 200\n",
"100\n100 200 100 100 200 200 200 200 100 200 200 200 200 200 200 200 200 200 100 100 100 200 200 200 200 200 100 200 200 200 200 100 200 200 100 100 200 100 100 100 200 100 100 100 200 100 200 100 200 200 200 100 100 200 100 200 100 200 100 100 100 200 100 200 100 100 100 100 200 200 200 200 100 200 200 100 200 100 100 100 200 100 100 100 100 100 200 100 100 100 200 200 200 100 200 100 100 100 200 200\n",
"1\n100\n",
"40\n100 100 200 200 200 200 100 100 100 200 100 100 200 200 100 100 100 100 100 200 100 200 200 100 200 200 200 100 100 100 100 100 200 200 100 200 100 100 200 100\n",
"99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"1\n200\n",
"99\n200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"52\n200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 100 200 100 200 200 200 100 200 200\n",
"99\n100 200 200 200 100 200 100 200 200 100 100 100 100 200 100 100 200 100 200 100 100 200 100 100 200 200 100 100 100 100 200 200 200 200 200 100 100 200 200 100 100 100 100 200 200 100 100 100 100 100 200 200 200 100 100 100 200 200 200 100 200 100 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 100 200 100 200 200 200 200 100 200 100 100 100 100 100 100 100 100 100\n",
"4\n100 100 100 100\n",
"100\n100 100 200 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"3\n200 100 200\n",
"4\n200 200 200 200\n",
"100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"3\n200 200 200\n",
"99\n100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100 100\n",
"2\n100 100\n",
"99\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"2\n200 100\n",
"32\n200 200 200 100 100 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200\n",
"48\n200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 100 200 200 200 200 200 200\n",
"24\n200 200 100 100 200 100 200 200 100 200 200 200 200 200 100 200 200 200 200 200 200 200 200 100\n",
"100\n100 100 200 100 100 200 200 200 200 100 200 100 100 100 200 100 100 100 100 200 100 100 100 100 100 100 200 100 100 200 200 100 100 100 200 200 200 100 200 200 100 200 100 100 200 100 200 200 100 200 200 100 100 200 200 100 200 200 100 100 200 100 200 100 200 200 200 200 200 100 200 200 200 200 200 200 100 100 200 200 200 100 100 100 200 100 100 200 100 100 100 200 200 100 100 200 200 200 200 100\n",
"2\n100 200\n",
"4\n100 100 200 200\n",
"100\n200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 100 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200 200\n",
"99\n200 100 100 100 200 200 200 100 100 100 100 100 100 100 100 100 200 200 100 200 200 100 200 100 100 200 200 200 100 200 100 200 200 100 200 100 200 200 200 100 100 200 200 200 200 100 100 100 100 200 200 200 200 100 200 200 200 100 100 100 200 200 200 100 200 100 200 100 100 100 200 100 200 200 100 200 200 200 100 100 100 200 200 200 100 200 200 200 100 100 100 200 100 200 100 100 100 200 200\n"
],
"output": [
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"NO\n",
"YES\n",
"YES\n",
"YES\n"
]
} | 1,100 | 500 |
2 | 7 | 478_A. Initial Bet | There are five people playing a game called "Generosity". Each person gives some non-zero number of coins b as an initial bet. After all players make their bets of b coins, the following operation is repeated for several times: a coin is passed from one player to some other player.
Your task is to write a program that can, given the number of coins each player has at the end of the game, determine the size b of the initial bet or find out that such outcome of the game cannot be obtained for any positive number of coins b in the initial bet.
Input
The input consists of a single line containing five integers c1, c2, c3, c4 and c5 β the number of coins that the first, second, third, fourth and fifth players respectively have at the end of the game (0 β€ c1, c2, c3, c4, c5 β€ 100).
Output
Print the only line containing a single positive integer b β the number of coins in the initial bet of each player. If there is no such value of b, then print the only value "-1" (quotes for clarity).
Examples
Input
2 5 4 0 4
Output
3
Input
4 5 9 2 1
Output
-1
Note
In the first sample the following sequence of operations is possible:
1. One coin is passed from the fourth player to the second player;
2. One coin is passed from the fourth player to the fifth player;
3. One coin is passed from the first player to the third player;
4. One coin is passed from the fourth player to the second player. | {
"input": [
"2 5 4 0 4\n",
"4 5 9 2 1\n"
],
"output": [
"3\n",
"-1\n"
]
} | {
"input": [
"99 100 100 100 100\n",
"57 83 11 4 93\n",
"99 99 99 99 99\n",
"100 0 0 0 0\n",
"0 1 2 3 4\n",
"93 100 99 90 98\n",
"87 38 19 33 100\n",
"1 1 1 1 1\n",
"0 0 0 0 1\n",
"2 3 4 5 6\n",
"1 2 1 2 3\n",
"0 0 0 0 0\n",
"100 100 100 100 100\n",
"43 83 1 0 23\n",
"43 83 1 100 23\n",
"56 0 0 0 4\n",
"99 98 98 99 100\n"
],
"output": [
"-1\n",
"-1\n",
"99\n",
"20\n",
"2\n",
"96\n",
"-1\n",
"1\n",
"-1\n",
"4\n",
"-1\n",
"-1\n",
"100\n",
"30\n",
"50\n",
"12\n",
"-1\n"
]
} | 1,100 | 500 |
2 | 9 | 500_C. New Year Book Reading | New Year is coming, and Jaehyun decided to read many books during 2015, unlike this year. He has n books numbered by integers from 1 to n. The weight of the i-th (1 β€ i β€ n) book is wi.
As Jaehyun's house is not large enough to have a bookshelf, he keeps the n books by stacking them vertically. When he wants to read a certain book x, he follows the steps described below.
1. He lifts all the books above book x.
2. He pushes book x out of the stack.
3. He puts down the lifted books without changing their order.
4. After reading book x, he puts book x on the top of the stack.
<image>
He decided to read books for m days. In the j-th (1 β€ j β€ m) day, he will read the book that is numbered with integer bj (1 β€ bj β€ n). To read the book, he has to use the process described in the paragraph above. It is possible that he decides to re-read the same book several times.
After making this plan, he realized that the total weight of books he should lift during m days would be too heavy. So, he decided to change the order of the stacked books before the New Year comes, and minimize the total weight. You may assume that books can be stacked in any possible order. Note that book that he is going to read on certain step isn't considered as lifted on that step. Can you help him?
Input
The first line contains two space-separated integers n (2 β€ n β€ 500) and m (1 β€ m β€ 1000) β the number of books, and the number of days for which Jaehyun would read books.
The second line contains n space-separated integers w1, w2, ..., wn (1 β€ wi β€ 100) β the weight of each book.
The third line contains m space separated integers b1, b2, ..., bm (1 β€ bj β€ n) β the order of books that he would read. Note that he can read the same book more than once.
Output
Print the minimum total weight of books he should lift, which can be achieved by rearranging the order of stacked books.
Examples
Input
3 5
1 2 3
1 3 2 3 1
Output
12
Note
Here's a picture depicting the example. Each vertical column presents the stacked books.
<image> | {
"input": [
"3 5\n1 2 3\n1 3 2 3 1\n"
],
"output": [
"12\n"
]
} | {
"input": [
"50 50\n75 71 23 37 28 23 69 75 5 62 3 11 96 100 13 50 57 51 8 90 4 6 84 27 11 89 95 81 10 62 48 52 69 87 97 95 30 74 21 42 36 64 31 80 81 50 56 53 33 99\n26 30 5 33 35 29 6 15 36 17 32 16 14 1 29 34 22 40 12 42 38 48 39 50 13 47 18 43 10 8 49 45 11 31 21 37 46 28 20 41 2 7 9 24 27 23 3 44 15 14\n",
"10 10\n61 59 97 16 2 94 57 48 91 93\n2 8 6 5 3 1 3 4 9 10\n",
"2 1\n1 2\n1\n",
"3 3\n10 20 30\n1 2 3\n",
"50 60\n86 57 45 93 17 12 40 10 47 80 18 80 3 9 6 55 13 99 5 76 4 70 100 55 27 91 71 3 65 93 41 74 80 56 90 50 58 13 71 9 47 52 26 73 72 21 15 81 88 28\n40 32 5 16 49 23 3 17 14 10 1 15 1 21 28 22 13 45 12 25 44 48 46 32 36 43 11 8 49 7 7 35 10 14 39 4 42 10 30 27 1 17 31 15 8 41 44 33 25 26 19 18 29 37 50 6 36 38 47 9\n",
"2 7\n20 30\n1 1 1 2 2 2 2\n",
"2 2\n10 12\n2 1\n",
"5 1\n16 87 36 16 81\n3\n",
"2 3\n20 30\n1 1 1\n",
"2 10\n39 26\n1 1 2 2 2 2 2 2 1 2\n"
],
"output": [
"63929\n",
"2137\n",
"0\n",
"40\n",
"62514\n",
"20\n",
"12\n",
"0\n",
"0\n",
"104\n"
]
} | 1,600 | 1,000 |
2 | 7 | 526_A. King of Thieves | In this problem you will meet the simplified model of game King of Thieves.
In a new ZeptoLab game called "King of Thieves" your aim is to reach a chest with gold by controlling your character, avoiding traps and obstacles on your way.
<image>
An interesting feature of the game is that you can design your own levels that will be available to other players. Let's consider the following simple design of a level.
A dungeon consists of n segments located at a same vertical level, each segment is either a platform that character can stand on, or a pit with a trap that makes player lose if he falls into it. All segments have the same length, platforms on the scheme of the level are represented as '*' and pits are represented as '.'.
One of things that affects speedrun characteristics of the level is a possibility to perform a series of consecutive jumps of the same length. More formally, when the character is on the platform number i1, he can make a sequence of jumps through the platforms i1 < i2 < ... < ik, if i2 - i1 = i3 - i2 = ... = ik - ik - 1. Of course, all segments i1, i2, ... ik should be exactly the platforms, not pits.
Let's call a level to be good if you can perform a sequence of four jumps of the same length or in the other words there must be a sequence i1, i2, ..., i5, consisting of five platforms so that the intervals between consecutive platforms are of the same length. Given the scheme of the level, check if it is good.
Input
The first line contains integer n (1 β€ n β€ 100) β the number of segments on the level.
Next line contains the scheme of the level represented as a string of n characters '*' and '.'.
Output
If the level is good, print the word "yes" (without the quotes), otherwise print the word "no" (without the quotes).
Examples
Input
16
.**.*..*.***.**.
Output
yes
Input
11
.*.*...*.*.
Output
no
Note
In the first sample test you may perform a sequence of jumps through platforms 2, 5, 8, 11, 14. | {
"input": [
"16\n.**.*..*.***.**.\n",
"11\n.*.*...*.*.\n"
],
"output": [
"yes",
"no"
]
} | {
"input": [
"20\n.*..*...*....*.....*\n",
"97\n****.***.***.*..**.**.*.*.***.*............*..*......*.***.**.*.***.*.***.*..*.**.*.***.**.*****.\n",
"5\n*.***\n",
"4\n****\n",
"11\n.*.*.*.*...\n",
"72\n.***.**.*.*...*****.*.*.*.*.**....**.*.**..*.*...**..***.**.**..*.**..**\n",
"89\n..**..**..*.********....*.*****.**.****...*......*******..*.**.*****..*..****....*...**..\n",
"6\n***.**\n",
"54\n...***.*...****.*..****....*..**..**..***.*..**...**..\n",
"100\n****************************************************************************************************\n",
"53\n*.*.****.*.*......**....**.***.*.*.**.*.*.***...*..*.\n",
"87\n*..*..***.**.*...****...*....***....***......*..*.*.*****.**..*.***...*.****..**.*..***\n",
"90\n**....****.***..***.*.*****...*.*.***..***.******.**...***..*...*****..*.**.**...*..**...*\n",
"55\n...*..*.*.**..*.*....*.****..****....*..***.*****..*..*\n",
"21\n*.*...*.*...*.*...*.*\n",
"41\n*******....*..*.**..***.*...****.***.*...\n",
"31\n.******.**.**....*.*********...\n",
"64\n*.***...**...*..*...*....*..***.*.*.*.***.*.**...**.*.*.*..*....\n",
"10\n*****....*\n",
"99\n**...*.*.*..*....**.***..*...***..***.**.*.....*.*....*...*.**.**.****..**..*.*..*.***....**...**.*\n",
"69\n.***...*.***.**...*....*.***.*..*....**.*...**....*.*..**....**..*.**\n",
"99\n.*.......................*.......................*.......................*.......................*.\n",
"98\n.**..**.*****..***...*.**..*..*....*******..**....*.****.**.*.....*.**..***.**..***.*******..****.\n",
"57\n**...*....**.**.*.******.**..**.*.....**.***..***...**..*\n",
"64\n***.*...*...*.***.....*.....**.*****.*.*...*..*.*..***..*...***.\n",
"17\n*...*...*...*...*\n",
"100\n*...............................................................................................****\n",
"11\n*...**..*.*\n",
"1\n.\n",
"100\n*.....................*.....................*.....................*.....................*...........\n",
"56\n**.*..*...***.*.**.**..**.*.*.*.**...*.**.**....*...**..\n",
"99\n***....*.....****.*.**.*.*.**.*.*.*..*...*..*...***..*.*...*.*...***.*.*...**.**.*******....**....*\n",
"10\n.*.*.*.*.*\n",
"51\n....****....*........*.*..**........*....****....*.\n",
"17\n.*..*..*.....*..*\n",
"97\n...*..*...*******.*.**..**..******.*.*..*****.*...***.*.**.**.**..**.******.****.*.***.**..*...**\n",
"42\n***.*..*.*.***...**..*..**....**..*..*...*\n",
"5\n*****\n",
"42\n..*...*.*..**..*.*.*..**...**.***.*.******\n",
"71\n**.**..*****.*.*.*.********.....*****.****.*..***...*.*.*.**.****.**.**\n",
"5\n.****\n",
"99\n.*..**..*..*..**...***.****.*...*....*****.....**..****.*..*....****..**..*****..*....**.*.**..**..\n",
"42\n.*.*...*..**.****...****..*.*.***....**...\n",
"10\n.*.*.*.*..\n",
"1\n*\n",
"5\n***.*\n",
"16\n*.**.**.**.*..*.\n",
"100\n*.......................*.......................*.......................*.......................*...\n",
"7\n***.***\n",
"58\n**.*.*.**..******.**.*..*.**.*.*******.**.*.**.*..*****.*.\n",
"67\n..**.*...*.....****.***.**.*....***..***.*..***.....*******.....*.*\n",
"99\n.*.......................*...............................................*.......................*.\n",
"6\n......\n",
"11\n.**.*..*.**\n",
"15\n..........*****\n",
"75\n..*.**..*.*****.......*....*.*.*..**.*.***.*.***....******.****.*.....****.\n",
"45\n.***..******....***..**..*.*.*.**..**..*.**..\n",
"13\n*..*..*..*..*\n",
"5\n**.**\n",
"100\n*****...............................................................................................\n",
"99\n..*.*..**.*.*.******.*.*.**.**.**.*..**.*.*****..*.*.****.*....**....*****.....***..**....***.*.*.*\n",
"99\n***************************************************************************************************\n",
"5\n****.\n"
],
"output": [
"no",
"yes",
"no",
"no",
"no",
"yes",
"yes",
"no",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"no",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"yes",
"no",
"no",
"no",
"yes",
"yes",
"yes",
"yes",
"no",
"no",
"yes",
"yes",
"yes",
"yes",
"yes",
"no",
"yes",
"yes",
"no",
"no",
"no",
"yes",
"yes",
"no",
"yes",
"yes",
"no",
"no",
"no",
"yes",
"yes",
"yes",
"yes",
"no",
"yes",
"yes",
"yes",
"no"
]
} | 1,300 | 500 |
2 | 8 | 551_B. ZgukistringZ | Professor GukiZ doesn't accept string as they are. He likes to swap some letters in string to obtain a new one.
GukiZ has strings a, b, and c. He wants to obtain string k by swapping some letters in a, so that k should contain as many non-overlapping substrings equal either to b or c as possible. Substring of string x is a string formed by consecutive segment of characters from x. Two substrings of string x overlap if there is position i in string x occupied by both of them.
GukiZ was disappointed because none of his students managed to solve the problem. Can you help them and find one of possible strings k?
Input
The first line contains string a, the second line contains string b, and the third line contains string c (1 β€ |a|, |b|, |c| β€ 105, where |s| denotes the length of string s).
All three strings consist only of lowercase English letters.
It is possible that b and c coincide.
Output
Find one of possible strings k, as described in the problem statement. If there are multiple possible answers, print any of them.
Examples
Input
aaa
a
b
Output
aaa
Input
pozdravstaklenidodiri
niste
dobri
Output
nisteaadddiiklooprrvz
Input
abbbaaccca
ab
aca
Output
ababacabcc
Note
In the third sample, this optimal solutions has three non-overlaping substrings equal to either b or c on positions 1 β 2 (ab), 3 β 4 (ab), 5 β 7 (aca). In this sample, there exist many other optimal solutions, one of them would be acaababbcc. | {
"input": [
"pozdravstaklenidodiri\nniste\ndobri\n",
"aaa\na\nb\n",
"abbbaaccca\nab\naca\n"
],
"output": [
"nisteaadddiiklooprrvz\n",
"aaa\n",
"ababacabcc\n"
]
} | {
"input": [
"brtakoktrosttttttttttosafasfkalsfkodfdasiofhadfhasdsajfdsafoasodsafahaihfdisoadspapsapiosapdsajdipsahdhasuirhaeuifhhfkjgosooooooooodafdfioottttafdsafaddfuiasdjfjasdo\nokat\ntako\n",
"aleksandrehteosidatedodam\nevo\nsi\n",
"goodbyeihopecontestisntsohar\noh\ngod\n",
"duxidimkeetoivas\ndd\nodi\n",
"hellodeninobrdo\nod\nhel\n",
"ikbalturkeybelieveinyou\nbal\nkan\n",
"zdule\ndidins\nmeinkraft\n",
"cumurcumur\num\ncur\n",
"ikatanictisinajboljiuhrvatskojakoprictasovojaviseakotijedosadno\njavise\nsine\n",
"zlobobermyfriendandthanksforhelp\nde\nfor\n",
"navijamzaradnickiastabidrugo\ndruzina\ndjavola\n",
"saljivdzijasamjaneki\nneki\nja\n",
"bumbumdzejsikerol\nbumbum\nbum\n",
"svetislavgajicpoznatijikaosvetaxxx\nslavi\nslavu\n",
"princeofpersiayouhavegreatcontestbutinwrongtime\nop\npera\n",
"pozdravizamarkamatovicaaleksandracveticainenadaslagalicustanisica\nvas\nrad\n",
"dreamoonhasonedream\nno\nno\n",
"jankosustersicneceovoraditi\ncosovic\noce\n",
"milenicnikolaitisideotakmicenja\nelem\nnik\n",
"touristyouaregreatguy\ntourist\nguy\n",
"lukavpastaakojelukav\na\nu\n",
"xxxbbbcccoca\nca\ncb\n",
"aaaaaabababaaa\naa\na\n",
"petryouaregoodandyouhavegoodblogs\nblog\nrega\n",
"lebronnojameslebronprogrammers\nje\nbro\n",
"mztskopjetisisampiosrcenaterenostaviajdezanaspobedi\nmzt\noptee\n",
"gukimikazedauradimseminarskidodatnohumorhumor\ndp\nmrzime\n",
"razredninjegosgrebovicdobarcoveklosbasketas\nne\ngo\n",
"pozdravzamojeodeljenjeiprofesoreocudabudempetnula\nbojan\ncao\n",
"damandicnenapravicheckerzeznulibise\nman\nker\n",
"pozdravizazenskudecunecuvasodvajatidaseneprotumacipogresno\ncao\ndeco\n",
"egoryouaregoodbutcantsolveeverythinginonehour\neat\nyour\n",
"lemigazalemiolemilicomzalemljenje\nlemi\nzlo\n",
"randomusername\numno\numno\n",
"thisiscornercase\nyouhavetwolongerstrings\nibelivethatyoudontmissit\n",
"oduleodule\nxgrizx\nivanstosicprvi\n",
"molimprofesorkuengleskogdamidapetjasamdobarcovekitrudimseiztogaiakosamoperisan\nhvala\nunapred\n",
"djeneralmilomirstefanovic\nradi\nnesto\n",
"balsabratepozdravimajudevojku\noj\nzdrav\n",
"iwanttothanktomygrandmaheisveryimportantpersoninmylife\nthanks\nstanka\n"
],
"output": [
"takotakotakotakotakoaaaaaaaaaaaaaaaaaaaaaabddddddddddddddddddeffffffffffffffffffghhhhhhhhhiiiiiiiiijjjjjloooooooooooooooooppppprrrssssssssssssssssssssstttttttttttuuu\n",
"siaaaaddddeeeehklmnoorstt\n",
"ohohgodabceeeiinnooprsssttty\n",
"odiadeeiikmstuvx\n",
"ododhelbeilnnor\n",
"kanbbeeeeiiikllortuuvyy\n",
"deluz\n",
"umumcurcur\n",
"sinesineaaaaaaaaabccddhiiiiiijjjjjkkkklnooooooooprrssstttttuvvv\n",
"dedeforforaabbehhikllmnnnoprstyz\n",
"druzinaaaaaabcdgiiijkmnorstv\n",
"nekijajajaadiilmssvz\n",
"bumbumdeeijklorsz\n",
"slaviaaaaceegiiijjknoopsstttvvxxxz\n",
"peraperaabcceeeefgghiiiimnnnnoooorrsstttttuuvwy\n",
"vasvasvasradradradaaaaaaaaaaccccceeegiiiiiiikklllmmnnnnoopstttuzz\n",
"nonoaaaddeeehmmorrs\n",
"oceoceaadeiiijknnorrsssttuv\n",
"elemniknikaaaccdeiiiiijlmnoostt\n",
"touristguyguyaaeeorrt\n",
"aaaaauuejkkkllopstvv\n",
"cacbcbcboxxx\n",
"aaaaaaaaaaabbb\n",
"blogregaregaadddehnoooooopstuuvyy\n",
"jebrobroaaeeegllmmmnnnooprrrss\n",
"mztopteeopteeopteeaaaaaabcddiiiiijjkmnnnorrssssssvz\n",
"mrzimeaaaaaddddeghhiiiikkkmmmnnoooorrrsstuuuu\n",
"nenegogoaaaabbbccddeeeiijkklooorrrrsssstvvz\n",
"bojancaoaaddddeeeeeeeefijjllmmnooooppprrrstuuuvzz\n",
"mankeraaabcccddeeeehiiiilnnnprsuvzz\n",
"decodecodecoaaaaaaadeeegiiijkmnnnnooppprrrssssttuuuuvvvzzz\n",
"eateatyouryourbcdeeeeggghhiilnnnnooooorrstuvv\n",
"lemilemilemilemizlozloaaaceegjjmn\n",
"umnoaadeemnrrs\n",
"acceehiinorrssst\n",
"ddeelloouu\n",
"unapredunapredaaaaaaabcddeeeeefgggiiiiiiijkkkkllmmmmmmoooooooooprrrsssssstttvz\n",
"radinestoaceefiijllmmnorv\n",
"ojojzdravaaaabbdeeiklmprstuuv\n",
"stankaaaadeeeefghhiiiiilmmmmnnnnnoooopprrrrstttttvwyyy\n"
]
} | 1,800 | 1,250 |
2 | 9 | 578_C. Weakness and Poorness | You are given a sequence of n integers a1, a2, ..., an.
Determine a real number x such that the weakness of the sequence a1 - x, a2 - x, ..., an - x is as small as possible.
The weakness of a sequence is defined as the maximum value of the poorness over all segments (contiguous subsequences) of a sequence.
The poorness of a segment is defined as the absolute value of sum of the elements of segment.
Input
The first line contains one integer n (1 β€ n β€ 200 000), the length of a sequence.
The second line contains n integers a1, a2, ..., an (|ai| β€ 10 000).
Output
Output a real number denoting the minimum possible weakness of a1 - x, a2 - x, ..., an - x. Your answer will be considered correct if its relative or absolute error doesn't exceed 10 - 6.
Examples
Input
3
1 2 3
Output
1.000000000000000
Input
4
1 2 3 4
Output
2.000000000000000
Input
10
1 10 2 9 3 8 4 7 5 6
Output
4.500000000000000
Note
For the first case, the optimal value of x is 2 so the sequence becomes - 1, 0, 1 and the max poorness occurs at the segment "-1" or segment "1". The poorness value (answer) equals to 1 in this case.
For the second sample the optimal value of x is 2.5 so the sequence becomes - 1.5, - 0.5, 0.5, 1.5 and the max poorness occurs on segment "-1.5 -0.5" or "0.5 1.5". The poorness value (answer) equals to 2 in this case. | {
"input": [
"10\n1 10 2 9 3 8 4 7 5 6\n",
"4\n1 2 3 4\n",
"3\n1 2 3\n"
],
"output": [
"4.500000000000024\n",
"2.000000000000003\n",
"1.000000000000000\n"
]
} | {
"input": [
"10\n-405 -230 252 -393 -390 -259 97 163 81 -129\n",
"3\n10000 -10000 10000\n",
"1\n-10000\n",
"20\n-16 -23 29 44 -40 -50 -41 34 -38 30 -12 28 -44 -49 15 50 -28 38 -2 0\n"
],
"output": [
"702.333333333333712\n",
"10000.000000000016371\n",
"0.000000000000000\n",
"113.875000000000043\n"
]
} | 2,000 | 750 |
2 | 7 | 5_A. Chat Server's Outgoing Traffic | Polycarp is working on a new project called "Polychat". Following modern tendencies in IT, he decided, that this project should contain chat as well. To achieve this goal, Polycarp has spent several hours in front of his laptop and implemented a chat server that can process three types of commands:
* Include a person to the chat ('Add' command).
* Remove a person from the chat ('Remove' command).
* Send a message from a person to all people, who are currently in the chat, including the one, who sends the message ('Send' command).
Now Polycarp wants to find out the amount of outgoing traffic that the server will produce while processing a particular set of commands.
Polycarp knows that chat server sends no traffic for 'Add' and 'Remove' commands. When 'Send' command is processed, server sends l bytes to each participant of the chat, where l is the length of the message.
As Polycarp has no time, he is asking for your help in solving this problem.
Input
Input file will contain not more than 100 commands, each in its own line. No line will exceed 100 characters. Formats of the commands will be the following:
* +<name> for 'Add' command.
* -<name> for 'Remove' command.
* <sender_name>:<message_text> for 'Send' command.
<name> and <sender_name> is a non-empty sequence of Latin letters and digits. <message_text> can contain letters, digits and spaces, but can't start or end with a space. <message_text> can be an empty line.
It is guaranteed, that input data are correct, i.e. there will be no 'Add' command if person with such a name is already in the chat, there will be no 'Remove' command if there is no person with such a name in the chat etc.
All names are case-sensitive.
Output
Print a single number β answer to the problem.
Examples
Input
+Mike
Mike:hello
+Kate
+Dmitry
-Dmitry
Kate:hi
-Kate
Output
9
Input
+Mike
-Mike
+Mike
Mike:Hi I am here
-Mike
+Kate
-Kate
Output
14 | {
"input": [
"+Mike\nMike:hello\n+Kate\n+Dmitry\n-Dmitry\nKate:hi\n-Kate\n",
"+Mike\n-Mike\n+Mike\nMike:Hi I am here\n-Mike\n+Kate\n-Kate\n"
],
"output": [
"9\n",
"14\n"
]
} | {
"input": [
"+adabacaba\n-adabacaba\n+aca\naca:caba\n-aca\n+bacaba\n-bacaba\n+aba\n-aba\n+bad\n",
"+cab\n+abac\n-abac\n+baca\n",
"+8UjgAJ\n8UjgAJ:02hR7UBc1tqqfL\n-8UjgAJ\n+zdi\n-zdi\n",
"+acabadab\n+caba0aba\n",
"+Dmitry\n+Mike\nDmitry:All letters will be used\nDmitry:qwertyuiopasdfghjklzxcvbnm QWERTYUIOPASDFGHJKLZXCVBNM\nDmitry:And digits too\nDmitry:1234567890 0987654321\n-Dmitry\n",
"+Dmitry\n+Mike\n+Kate\nDmitry:\n",
"+badabac\nbadabac:abacabad\n-badabac\n+0ab\n-0ab\n+dabacab\n-dabacab\n+a0ab\n-a0ab\n+0abaca\n-0abaca\n+dabac\n-dabac\n+abaca\n-abaca\n+bacabada\n-bacabada\n+aca\n-aca\n+abadabaca\n-abadabaca\n+acaba\n-acaba\n+abacabadab\n-abacabadab\n",
"+qlHEc2AuYy\nqlHEc2AuYy:YYRwD0 edNZgpE nGfOguRWnMYpTpGUVM aXDKGXo1Gv1tHL9\nqlHEc2AuYy:yvh3GsPcImqrvoUcBNQcP6ezwpU0 xAVltaKZp94VKiNao\nqlHEc2AuYy:zuCO6Opey L eu7lTwysaSk00zjpv zrDfbt8l hpHfu\n+pErDMxgVgh\nqlHEc2AuYy:I1FLis mmQbZtd8Ui7y 1vcax6yZBMhVRdD6Ahlq7MNCw\nqlHEc2AuYy:lz MFUNJZhlqBYckHUDlNhLiEkmecRh1o0t7alXBvCRVEFVx\npErDMxgVgh:jCyMbu1dkuEj5TzbBOjyUhpfC50cL8R900Je3R KxRgAI dT\nqlHEc2AuYy:62b47eabo2hf vSUD7KioN ZHki6WB6gh3u GKv5rgwyfF\npErDMxgVgh:zD5 9 ympl4wR gy7a7eAGAn5xVdGP9FbL6hRCZAR6O4pT6zb\n",
"+6JPKkgXDrA\n+j6JHjv70An\n+QGtsceK0zJ\n6JPKkgXDrA:o4\n+CSmwi9zDra\nQGtsceK0zJ:Zl\nQGtsceK0zJ:0\nj6JHjv70An:7\nj6JHjv70An:B\nQGtsceK0zJ:OO\n",
"+Dmitry\nDmitry:No phrases with spaces at the beginning and at the end\n+Mike\nDmitry:spaces spaces\n-Dmitry\n",
"+1aLNq9S7uLV\n-1aLNq9S7uLV\n+O9ykq3xDJv\n-O9ykq3xDJv\n+54Yq1xJq14F\n+0zJ5Vo0RDZ\n-54Yq1xJq14F\n-0zJ5Vo0RDZ\n+lxlH7sdolyL\n-lxlH7sdolyL\n",
"+adabacaba0\n",
"+dabaca\n-dabaca\n+aba0ab\n",
"+XqD\n+aT537\nXqD:x6ZPjMR1DDKG2\nXqD:lLCriywPnB\n-XqD\n",
"+cabadabac\n-cabadabac\n+abacaba1ab\n-abacaba1ab\n+ba0abaca\n",
"+acabadab\n-acabadab\n+aba0abacab\n+baca\n+abacaba0ab\n-baca\n-abacaba0ab\n-aba0abacab\n+cab\n-cab\n+abacabada\n-abacabada\n+badabaca\n-badabaca\n+badaba\n"
],
"output": [
"4\n",
"0\n",
"14\n",
"0\n",
"224\n",
"0\n",
"8\n",
"615\n",
"34\n",
"86\n",
"0\n",
"0\n",
"0\n",
"46\n",
"0\n",
"0\n"
]
} | 1,000 | 0 |
2 | 10 | 621_D. Rat Kwesh and Cheese | Wet Shark asked Rat Kwesh to generate three positive real numbers x, y and z, from 0.1 to 200.0, inclusive. Wet Krash wants to impress Wet Shark, so all generated numbers will have exactly one digit after the decimal point.
Wet Shark knows Rat Kwesh will want a lot of cheese. So he will give the Rat an opportunity to earn a lot of cheese. He will hand the three numbers x, y and z to Rat Kwesh, and Rat Kwesh will pick one of the these twelve options:
1. a1 = xyz;
2. a2 = xzy;
3. a3 = (xy)z;
4. a4 = (xz)y;
5. a5 = yxz;
6. a6 = yzx;
7. a7 = (yx)z;
8. a8 = (yz)x;
9. a9 = zxy;
10. a10 = zyx;
11. a11 = (zx)y;
12. a12 = (zy)x.
Let m be the maximum of all the ai, and c be the smallest index (from 1 to 12) such that ac = m. Rat's goal is to find that c, and he asks you to help him. Rat Kwesh wants to see how much cheese he gets, so he you will have to print the expression corresponding to that ac.
Input
The only line of the input contains three space-separated real numbers x, y and z (0.1 β€ x, y, z β€ 200.0). Each of x, y and z is given with exactly one digit after the decimal point.
Output
Find the maximum value of expression among xyz, xzy, (xy)z, (xz)y, yxz, yzx, (yx)z, (yz)x, zxy, zyx, (zx)y, (zy)x and print the corresponding expression. If there are many maximums, print the one that comes first in the list.
xyz should be outputted as x^y^z (without brackets), and (xy)z should be outputted as (x^y)^z (quotes for clarity).
Examples
Input
1.1 3.4 2.5
Output
z^y^x
Input
2.0 2.0 2.0
Output
x^y^z
Input
1.9 1.8 1.7
Output
(x^y)^z | {
"input": [
"1.1 3.4 2.5\n",
"1.9 1.8 1.7\n",
"2.0 2.0 2.0\n"
],
"output": [
"z^y^x\n",
"(x^y)^z\n",
"x^y^z\n"
]
} | {
"input": [
"1.0 200.0 200.0\n",
"0.2 0.1 0.6\n",
"1.9 3.0 4.1\n",
"51.8 51.8 7.1\n",
"113.9 125.2 88.8\n",
"1.9 4.8 3.9\n",
"2.2 148.1 138.0\n",
"1.0 200.0 1.0\n",
"1.7 4.5 4.2\n",
"0.2 0.6 0.3\n",
"200.0 200.0 0.1\n",
"3.9 0.2 3.8\n",
"7.0 131.1 7.4\n",
"4.6 4.4 2.3\n",
"2.0 1.1 2.4\n",
"2.4 3.8 2.7\n",
"0.1 0.5 0.2\n",
"1.8 0.4 2.7\n",
"1.1 1.1 1.1\n",
"3.7 2.2 4.8\n",
"3.9 2.1 4.5\n",
"1.0 1.0 200.0\n",
"104.6 184.4 82.3\n",
"149.4 15.5 82.0\n",
"0.5 0.5 0.6\n",
"1.1 1.5 1.0\n",
"0.3 0.4 0.4\n",
"0.3 0.5 0.6\n",
"0.2 0.2 0.5\n",
"1.0 1.0 1.0\n",
"0.2 0.7 0.6\n",
"144.0 70.4 148.1\n",
"25.9 77.0 144.8\n",
"0.9 1.0 0.1\n",
"0.5 0.3 0.2\n",
"2.0 1.0 4.0\n",
"4.0 2.0 1.0\n",
"1.0 2.0 4.0\n",
"0.5 0.5 0.1\n",
"0.6 0.2 0.5\n",
"185.9 9.6 163.4\n",
"0.8 0.3 0.6\n",
"200.0 1.0 200.0\n",
"1.1 3.1 4.9\n",
"3.7 3.7 4.1\n",
"0.1 0.2 0.6\n",
"1.5 1.3 0.1\n",
"4.6 2.1 1.6\n",
"0.1 200.0 0.1\n",
"1.0 0.3 1.1\n",
"0.3 0.3 0.5\n",
"0.1 0.1 0.4\n",
"55.5 159.4 140.3\n",
"4.4 3.7 3.4\n",
"200.0 1.0 1.0\n",
"0.1 1.4 0.3\n",
"1.4 0.5 0.8\n",
"1.1 1.5 0.4\n",
"51.5 156.3 145.1\n",
"0.1 0.3 0.5\n",
"153.9 122.1 89.5\n",
"1.8 1.8 2.1\n",
"0.5 0.1 0.9\n",
"0.6 0.6 1.1\n",
"4.6 3.0 3.4\n",
"0.1 0.4 0.3\n",
"0.6 0.3 0.2\n",
"196.9 3.0 4.1\n",
"3.0 3.0 3.1\n",
"4.4 0.5 2.0\n",
"4.5 1.3 4.8\n",
"64.6 117.1 81.6\n",
"117.4 68.8 137.7\n",
"141.1 108.1 14.9\n",
"81.7 171.9 4.4\n",
"0.2 0.3 0.1\n",
"156.9 154.8 73.9\n",
"1.5 1.4 1.1\n",
"0.4 1.1 0.9\n",
"0.4 1.1 0.8\n",
"0.1 200.0 200.0\n",
"0.5 0.3 0.1\n",
"1.0 2.0 1.0\n",
"1.4 1.1 1.0\n",
"0.7 1.4 0.4\n",
"28.9 39.3 148.4\n",
"1.7 1.9 4.4\n",
"0.5 0.8 0.3\n",
"200.0 0.1 0.1\n",
"0.5 0.2 0.2\n",
"0.6 0.4 0.3\n",
"0.9 1.2 0.2\n",
"4.3 2.4 4.9\n",
"0.9 2.0 4.8\n",
"189.4 63.7 63.4\n",
"38.7 142.2 89.8\n",
"0.3 0.4 0.1\n",
"1.9 1.1 4.8\n",
"0.4 0.1 0.6\n",
"4.2 1.1 1.2\n",
"1.5 1.7 2.5\n",
"184.1 118.5 129.5\n",
"200.0 200.0 200.0\n",
"0.5 0.4 0.5\n",
"1.2 0.7 1.3\n",
"3.9 4.3 3.4\n",
"193.9 40.7 19.7\n",
"0.5 0.2 0.3\n",
"36.9 51.1 4.8\n",
"0.2 0.1 0.2\n",
"0.2 0.6 0.4\n",
"0.1 0.1 200.0\n",
"0.9 4.6 3.4\n",
"2.0 4.0 1.0\n",
"0.2 0.3 0.2\n",
"0.4 1.0 1.5\n",
"1.4 1.2 1.4\n",
"1.2 0.6 0.5\n",
"2.0 2.1 2.2\n",
"0.1 0.2 0.3\n",
"0.8 0.4 1.4\n",
"1.4 0.3 1.4\n",
"4.0 1.0 2.0\n",
"0.1 0.5 0.4\n",
"0.4 0.2 0.3\n",
"4.0 0.4 3.1\n",
"200.0 0.1 200.0\n",
"1.0 4.0 2.0\n",
"0.3 0.4 1.2\n",
"94.5 56.3 59.8\n",
"1.4 0.8 0.9\n",
"200.0 200.0 1.0\n",
"1.4 0.8 0.2\n",
"3.9 0.7 4.7\n",
"144.6 103.0 193.4\n",
"0.5 0.1 0.3\n",
"0.1 0.4 0.2\n",
"0.1 0.1 0.1\n",
"1.2 0.5 1.2\n",
"198.7 23.7 89.1\n",
"139.3 87.4 129.9\n",
"4.1 3.5 4.5\n",
"2.2 3.1 3.0\n",
"91.8 170.4 7.7\n",
"41.7 104.5 74.2\n"
],
"output": [
"y^z^x\n",
"(z^x)^y\n",
"x^y^z\n",
"z^x^y\n",
"z^x^y\n",
"x^z^y\n",
"x^z^y\n",
"y^x^z\n",
"x^z^y\n",
"(y^x)^z\n",
"(x^y)^z\n",
"x^z^y\n",
"x^z^y\n",
"z^y^x\n",
"(z^x)^y\n",
"x^z^y\n",
"(y^x)^z\n",
"z^x^y\n",
"(x^y)^z\n",
"y^x^z\n",
"y^x^z\n",
"z^x^y\n",
"z^x^y\n",
"y^z^x\n",
"(z^x)^y\n",
"y^x^z\n",
"(y^x)^z\n",
"(z^x)^y\n",
"(z^x)^y\n",
"x^y^z\n",
"(y^x)^z\n",
"y^x^z\n",
"x^y^z\n",
"y^x^z\n",
"(x^y)^z\n",
"x^z^y\n",
"x^y^z\n",
"y^z^x\n",
"(x^y)^z\n",
"(x^y)^z\n",
"y^z^x\n",
"(x^y)^z\n",
"x^z^y\n",
"x^y^z\n",
"x^y^z\n",
"(z^x)^y\n",
"x^y^z\n",
"z^y^x\n",
"y^x^z\n",
"z^x^y\n",
"(z^x)^y\n",
"(z^x)^y\n",
"x^z^y\n",
"z^y^x\n",
"x^y^z\n",
"y^z^x\n",
"x^z^y\n",
"y^x^z\n",
"x^z^y\n",
"(z^x)^y\n",
"z^y^x\n",
"(z^x)^y\n",
"(z^x)^y\n",
"z^x^y\n",
"y^z^x\n",
"(y^x)^z\n",
"(x^y)^z\n",
"y^z^x\n",
"x^y^z\n",
"x^z^y\n",
"y^x^z\n",
"x^z^y\n",
"y^x^z\n",
"z^y^x\n",
"z^x^y\n",
"(y^x)^z\n",
"z^y^x\n",
"(x^y)^z\n",
"y^z^x\n",
"y^z^x\n",
"(y^x)^z\n",
"(x^y)^z\n",
"y^x^z\n",
"x^y^z\n",
"y^x^z\n",
"x^y^z\n",
"x^y^z\n",
"(y^x)^z\n",
"x^y^z\n",
"(x^y)^z\n",
"(x^y)^z\n",
"y^x^z\n",
"y^x^z\n",
"(y^x)^z\n",
"z^y^x\n",
"x^z^y\n",
"(y^x)^z\n",
"x^z^y\n",
"(z^x)^y\n",
"(x^y)^z\n",
"(z^x)^y\n",
"y^z^x\n",
"x^y^z\n",
"(x^y)^z\n",
"z^x^y\n",
"z^x^y\n",
"z^y^x\n",
"(x^y)^z\n",
"z^x^y\n",
"(x^y)^z\n",
"(y^x)^z\n",
"z^x^y\n",
"(z^x)^y\n",
"x^y^z\n",
"(y^x)^z\n",
"z^y^x\n",
"(x^y)^z\n",
"x^y^z\n",
"x^z^y\n",
"(z^x)^y\n",
"z^x^y\n",
"x^z^y\n",
"x^z^y\n",
"(y^x)^z\n",
"(x^y)^z\n",
"x^z^y\n",
"(x^y)^z\n",
"y^z^x\n",
"z^y^x\n",
"y^z^x\n",
"x^z^y\n",
"x^y^z\n",
"x^y^z\n",
"(x^y)^z\n",
"y^x^z\n",
"(x^y)^z\n",
"(y^x)^z\n",
"(x^y)^z\n",
"x^z^y\n",
"y^z^x\n",
"y^z^x\n",
"y^x^z\n",
"x^z^y\n",
"z^x^y\n",
"x^z^y\n"
]
} | 2,400 | 2,000 |
2 | 8 | 643_B. Bear and Two Paths | Bearland has n cities, numbered 1 through n. Cities are connected via bidirectional roads. Each road connects two distinct cities. No two roads connect the same pair of cities.
Bear Limak was once in a city a and he wanted to go to a city b. There was no direct connection so he decided to take a long walk, visiting each city exactly once. Formally:
* There is no road between a and b.
* There exists a sequence (path) of n distinct cities v1, v2, ..., vn that v1 = a, vn = b and there is a road between vi and vi + 1 for <image>.
On the other day, the similar thing happened. Limak wanted to travel between a city c and a city d. There is no road between them but there exists a sequence of n distinct cities u1, u2, ..., un that u1 = c, un = d and there is a road between ui and ui + 1 for <image>.
Also, Limak thinks that there are at most k roads in Bearland. He wonders whether he remembers everything correctly.
Given n, k and four distinct cities a, b, c, d, can you find possible paths (v1, ..., vn) and (u1, ..., un) to satisfy all the given conditions? Find any solution or print -1 if it's impossible.
Input
The first line of the input contains two integers n and k (4 β€ n β€ 1000, n - 1 β€ k β€ 2n - 2) β the number of cities and the maximum allowed number of roads, respectively.
The second line contains four distinct integers a, b, c and d (1 β€ a, b, c, d β€ n).
Output
Print -1 if it's impossible to satisfy all the given conditions. Otherwise, print two lines with paths descriptions. The first of these two lines should contain n distinct integers v1, v2, ..., vn where v1 = a and vn = b. The second line should contain n distinct integers u1, u2, ..., un where u1 = c and un = d.
Two paths generate at most 2n - 2 roads: (v1, v2), (v2, v3), ..., (vn - 1, vn), (u1, u2), (u2, u3), ..., (un - 1, un). Your answer will be considered wrong if contains more than k distinct roads or any other condition breaks. Note that (x, y) and (y, x) are the same road.
Examples
Input
7 11
2 4 7 3
Output
2 7 1 3 6 5 4
7 1 5 4 6 2 3
Input
1000 999
10 20 30 40
Output
-1
Note
In the first sample test, there should be 7 cities and at most 11 roads. The provided sample solution generates 10 roads, as in the drawing. You can also see a simple path of length n between 2 and 4, and a path between 7 and 3.
<image> | {
"input": [
"1000 999\n10 20 30 40\n",
"7 11\n2 4 7 3\n"
],
"output": [
"-1",
"2 7 1 5 6 3 4 \n7 2 1 5 6 4 3 "
]
} | {
"input": [
"1000 1001\n217 636 713 516\n",
"1000 1998\n833 681 19 233\n",
"4 5\n1 3 4 2\n",
"6 7\n3 1 2 4\n",
"5 7\n4 3 2 1\n",
"55 56\n53 54 52 55\n",
"1000 1000\n89 983 751 38\n",
"1000 1002\n641 480 458 289\n",
"6 5\n3 2 5 4\n",
"999 999\n289 384 609 800\n",
"5 4\n2 3 5 4\n",
"6 10\n5 3 4 2\n",
"200 201\n7 100 8 9\n",
"5 6\n1 5 3 4\n",
"5 7\n1 2 3 4\n",
"5 8\n1 2 3 4\n",
"55 57\n54 55 52 53\n",
"57 88\n54 30 5 43\n",
"1000 1234\n330 433 967 641\n",
"4 6\n1 3 2 4\n",
"7 7\n6 2 5 7\n",
"200 201\n7 100 8 99\n",
"55 56\n52 53 54 55\n",
"1000 1577\n698 459 326 404\n",
"55 56\n1 2 3 4\n",
"5 8\n2 3 5 1\n",
"5 5\n1 2 3 4\n",
"55 75\n2 3 1 4\n",
"10 10\n2 5 3 8\n",
"999 1200\n753 805 280 778\n",
"10 10\n1 10 5 7\n",
"6 6\n1 2 3 4\n",
"5 6\n5 2 4 1\n",
"6 6\n1 3 4 5\n",
"700 699\n687 69 529 616\n",
"1000 999\n179 326 640 274\n",
"4 6\n1 2 3 4\n",
"4 4\n1 2 3 4\n",
"200 398\n60 61 7 100\n",
"200 210\n8 9 7 100\n",
"7 8\n2 7 6 5\n",
"765 766\n352 536 728 390\n",
"55 56\n4 1 2 3\n",
"5 5\n1 4 2 5\n",
"999 1000\n581 109 1 610\n",
"4 5\n1 2 3 4\n"
],
"output": [
"217 713 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 516 636 \n713 217 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 636 516 ",
"833 19 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 233 681 \n19 833 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 681 233 ",
"-1",
"3 2 5 6 4 1 \n2 3 5 6 1 4 ",
"4 2 5 1 3 \n2 4 5 3 1 ",
"53 52 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 55 54 \n52 53 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 54 55 ",
"-1",
"641 458 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 289 480 \n458 641 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 480 289 ",
"-1",
"-1",
"-1",
"5 4 1 6 2 3 \n4 5 1 6 3 2 ",
"7 8 1 2 3 4 5 6 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 9 100 \n8 7 1 2 3 4 5 6 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 100 9 ",
"1 3 2 4 5 \n3 1 2 5 4 ",
"1 3 5 4 2 \n3 1 5 2 4 ",
"1 3 5 4 2 \n3 1 5 2 4 ",
"54 52 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 53 55 \n52 54 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 55 53 ",
"54 5 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 52 53 55 56 57 43 30 \n5 54 1 2 3 4 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 31 32 33 34 35 36 37 38 39 40 41 42 44 45 46 47 48 49 50 51 52 53 55 56 57 30 43 ",
"330 967 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 641 433 \n967 330 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 433 641 ",
"-1",
"-1",
"7 8 1 2 3 4 5 6 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 99 100 \n8 7 1 2 3 4 5 6 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 100 99 ",
"52 54 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 55 53 \n54 52 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 53 55 ",
"698 326 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 404 459 \n326 698 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 459 404 ",
"1 3 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 4 2 \n3 1 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 2 4 ",
"2 5 4 1 3 \n5 2 4 3 1 ",
"-1",
"2 1 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 4 3 \n1 2 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 3 4 ",
"-1",
"753 280 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 778 805 \n280 753 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 805 778 ",
"-1",
"-1",
"5 4 3 1 2 \n4 5 3 2 1 ",
"-1",
"-1",
"-1",
"-1",
"-1",
"60 7 1 2 3 4 5 6 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 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 100 61 \n7 60 1 2 3 4 5 6 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 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 61 100 ",
"8 7 1 2 3 4 5 6 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 100 9 \n7 8 1 2 3 4 5 6 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 9 100 ",
"2 6 1 3 4 5 7 \n6 2 1 3 4 7 5 ",
"352 728 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 390 536 \n728 352 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 536 390 ",
"4 2 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 3 1 \n2 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 1 3 ",
"-1",
"581 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 610 109 \n1 581 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 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 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 109 610 ",
"-1"
]
} | 1,600 | 1,000 |
2 | 8 | 670_B. Game of Robots | In late autumn evening n robots gathered in the cheerful company of friends. Each robot has a unique identifier β an integer from 1 to 109.
At some moment, robots decided to play the game "Snowball". Below there are the rules of this game. First, all robots stand in a row. Then the first robot says his identifier. After that the second robot says the identifier of the first robot and then says his own identifier. Then the third robot says the identifier of the first robot, then says the identifier of the second robot and after that says his own. This process continues from left to right until the n-th robot says his identifier.
Your task is to determine the k-th identifier to be pronounced.
Input
The first line contains two positive integers n and k (1 β€ n β€ 100 000, 1 β€ k β€ min(2Β·109, nΒ·(n + 1) / 2).
The second line contains the sequence id1, id2, ..., idn (1 β€ idi β€ 109) β identifiers of roborts. It is guaranteed that all identifiers are different.
Output
Print the k-th pronounced identifier (assume that the numeration starts from 1).
Examples
Input
2 2
1 2
Output
1
Input
4 5
10 4 18 3
Output
4
Note
In the first sample identifiers of robots will be pronounced in the following order: 1, 1, 2. As k = 2, the answer equals to 1.
In the second test case identifiers of robots will be pronounced in the following order: 10, 10, 4, 10, 4, 18, 10, 4, 18, 3. As k = 5, the answer equals to 4. | {
"input": [
"4 5\n10 4 18 3\n",
"2 2\n1 2\n"
],
"output": [
"4",
"1"
]
} | {
"input": [
"4 9\n5 1000000000 999999999 12\n",
"4 6\n5 1000000000 999999999 12\n",
"1 1\n4\n",
"3 5\n4 5 6\n",
"3 4\n4 5 6\n",
"3 6\n4 5 6\n",
"4 2\n5 1000000000 999999999 12\n",
"2 3\n6 7\n",
"2 1\n5 1\n",
"4 1\n5 1000000000 999999999 12\n",
"4 3\n5 1000000000 999999999 12\n",
"3 1\n4 5 6\n",
"4 4\n5 1000000000 999999999 12\n",
"4 5\n5 1000000000 999999999 12\n",
"2 2\n1 4\n",
"4 8\n5 1000000000 999999999 12\n",
"3 3\n4 5 6\n",
"4 7\n5 1000000000 999999999 12\n",
"3 2\n4 5 6\n",
"4 10\n5 1000000000 999999999 12\n"
],
"output": [
"999999999",
"999999999",
"4",
"5",
"4",
"6",
"5",
"7",
"5",
"5",
"1000000000",
"4",
"5",
"1000000000",
"1",
"1000000000",
"5",
"5",
"4",
"12"
]
} | 1,000 | 750 |
2 | 10 | 691_D. Swaps in Permutation | You are given a permutation of the numbers 1, 2, ..., n and m pairs of positions (aj, bj).
At each step you can choose a pair from the given positions and swap the numbers in that positions. What is the lexicographically maximal permutation one can get?
Let p and q be two permutations of the numbers 1, 2, ..., n. p is lexicographically smaller than the q if a number 1 β€ i β€ n exists, so pk = qk for 1 β€ k < i and pi < qi.
Input
The first line contains two integers n and m (1 β€ n, m β€ 106) β the length of the permutation p and the number of pairs of positions.
The second line contains n distinct integers pi (1 β€ pi β€ n) β the elements of the permutation p.
Each of the last m lines contains two integers (aj, bj) (1 β€ aj, bj β€ n) β the pairs of positions to swap. Note that you are given a positions, not the values to swap.
Output
Print the only line with n distinct integers p'i (1 β€ p'i β€ n) β the lexicographically maximal permutation one can get.
Example
Input
9 6
1 2 3 4 5 6 7 8 9
1 4
4 7
2 5
5 8
3 6
6 9
Output
7 8 9 4 5 6 1 2 3 | {
"input": [
"9 6\n1 2 3 4 5 6 7 8 9\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n"
],
"output": [
"7 8 9 4 5 6 1 2 3 \n"
]
} | {
"input": [
"3 10\n2 3 1\n1 1\n3 3\n3 3\n3 2\n1 1\n2 2\n3 1\n1 3\n2 1\n3 3\n",
"7 20\n6 2 5 7 3 1 4\n7 7\n1 1\n2 2\n6 1\n4 4\n2 2\n2 2\n6 6\n3 5\n7 4\n1 6\n4 4\n6 1\n1 1\n3 3\n5 3\n3 5\n5 3\n2 2\n4 4\n",
"4 20\n4 2 3 1\n2 2\n1 4\n2 2\n1 1\n3 3\n3 3\n1 4\n3 3\n2 2\n3 3\n4 1\n2 2\n1 4\n3 3\n4 1\n1 1\n3 3\n2 2\n2 2\n4 4\n",
"9 6\n9 2 3 4 5 6 7 8 1\n1 4\n4 7\n2 5\n5 8\n3 6\n6 9\n",
"7 20\n5 6 2 1 7 4 3\n1 4\n5 4\n7 5\n7 4\n2 4\n6 5\n1 5\n3 3\n1 5\n6 2\n7 3\n4 1\n6 4\n7 5\n7 3\n1 5\n1 3\n6 6\n5 2\n5 7\n",
"3 1\n3 2 1\n1 2\n",
"8 20\n8 4 7 2 6 5 3 1\n6 6\n2 4\n7 3\n4 2\n3 3\n6 5\n6 5\n8 8\n3 7\n6 6\n7 3\n4 4\n1 8\n1 8\n3 7\n8 8\n6 6\n2 4\n8 8\n4 2\n",
"3 2\n1 3 2\n1 3\n3 1\n",
"20 20\n4 12 7 1 16 19 3 10 14 8 13 2 11 9 20 5 18 17 6 15\n9 14\n3 3\n8 10\n7 3\n20 20\n5 16\n13 11\n6 19\n6 6\n12 2\n12 2\n13 11\n18 18\n18 17\n9 14\n8 8\n20 15\n4 4\n16 16\n4 1\n",
"9 20\n6 7 9 1 3 4 8 2 5\n8 2\n2 7\n1 6\n6 1\n6 1\n3 3\n9 5\n8 2\n8 2\n9 5\n4 1\n5 5\n9 3\n9 3\n6 6\n7 8\n4 6\n7 8\n1 1\n8 2\n",
"5 20\n2 4 1 5 3\n1 4\n3 1\n4 5\n1 1\n4 2\n3 2\n4 4\n1 2\n4 5\n5 5\n5 5\n2 2\n2 5\n5 3\n5 5\n3 3\n5 1\n2 2\n4 5\n1 5\n",
"4 20\n3 4 1 2\n2 4\n4 4\n3 1\n3 1\n4 4\n3 3\n4 4\n1 1\n4 4\n4 2\n3 3\n1 3\n1 3\n2 2\n1 3\n1 1\n3 1\n2 4\n4 4\n2 4\n",
"6 20\n5 3 2 4 1 6\n3 2\n5 5\n3 2\n4 4\n4 4\n4 4\n5 1\n3 2\n3 2\n1 1\n6 6\n6 6\n6 6\n4 4\n6 6\n1 5\n1 1\n5 1\n2 2\n2 3\n",
"83 8\n54 3 52 12 61 36 65 62 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 16 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 1 42 13 44 72 22 4 9 25 19 57 10 70 18 68 32 34 20 80 23 79 24 63 64 51 59 41 74 48 40 33 46 83 55 56 78\n48 80\n1 8\n71 54\n15 59\n72 46\n36 9\n64 29\n55 58\n",
"1 1\n1\n1 1\n",
"5 20\n3 4 1 5 2\n2 4\n3 1\n2 2\n4 5\n4 5\n5 2\n1 1\n2 4\n3 3\n4 2\n3 1\n1 1\n5 2\n1 3\n3 1\n4 2\n1 3\n3 3\n4 2\n4 2\n",
"6 20\n4 6 1 3 2 5\n2 2\n6 5\n3 4\n3 4\n5 6\n3 3\n5 5\n6 6\n4 3\n2 2\n2 2\n5 2\n3 4\n1 4\n5 2\n4 3\n2 5\n1 4\n3 1\n4 3\n",
"2 10\n1 2\n1 1\n2 2\n2 2\n1 1\n1 1\n2 2\n2 2\n1 1\n2 2\n1 1\n",
"5 3\n5 2 3 4 1\n2 4\n1 4\n3 4\n",
"4 1\n4 3 1 2\n3 4\n",
"3 1\n1 3 2\n1 2\n",
"2 10\n2 1\n2 1\n1 2\n1 1\n2 1\n1 1\n2 1\n1 1\n1 1\n2 1\n2 1\n",
"3 1\n2 3 1\n1 1\n",
"8 1\n3 4 1 2 7 8 5 6\n3 4\n",
"3 10\n1 2 3\n2 2\n1 1\n2 2\n3 3\n1 1\n3 3\n3 3\n3 3\n2 2\n1 1\n"
],
"output": [
"3 2 1 \n",
"6 2 5 7 3 1 4 \n",
"4 2 3 1 \n",
"9 8 6 7 5 3 4 2 1 \n",
"7 6 5 4 3 2 1 \n",
"3 2 1 \n",
"8 4 7 2 6 5 3 1 \n",
"2 3 1 \n",
"4 12 7 1 16 19 3 10 14 8 13 2 11 9 20 5 18 17 6 15 \n",
"6 8 9 4 5 1 7 2 3 \n",
"5 4 3 2 1 \n",
"3 4 1 2 \n",
"5 3 2 4 1 6 \n",
"62 3 52 12 61 36 65 54 69 49 47 77 31 15 21 14 73 29 6 26 37 17 81 75 43 30 58 76 34 8 11 5 27 35 7 66 50 67 2 39 45 28 60 71 38 82 53 83 42 13 44 72 22 64 57 25 19 9 10 70 18 68 32 16 20 80 23 79 24 63 4 51 59 41 74 48 40 33 46 1 55 56 78 \n",
"1 \n",
"3 5 1 4 2 \n",
"4 6 3 1 5 2 \n",
"1 2 \n",
"5 4 3 2 1 \n",
"4 3 2 1 \n",
"3 1 2 \n",
"2 1 \n",
"2 3 1 \n",
"3 4 2 1 7 8 5 6 \n",
"1 2 3 \n"
]
} | 1,700 | 0 |
2 | 10 | 716_D. Complete The Graph | ZS the Coder has drawn an undirected graph of n vertices numbered from 0 to n - 1 and m edges between them. Each edge of the graph is weighted, each weight is a positive integer.
The next day, ZS the Coder realized that some of the weights were erased! So he wants to reassign positive integer weight to each of the edges which weights were erased, so that the length of the shortest path between vertices s and t in the resulting graph is exactly L. Can you help him?
Input
The first line contains five integers n, m, L, s, t (2 β€ n β€ 1000, 1 β€ m β€ 10 000, 1 β€ L β€ 109, 0 β€ s, t β€ n - 1, s β t) β the number of vertices, number of edges, the desired length of shortest path, starting vertex and ending vertex respectively.
Then, m lines describing the edges of the graph follow. i-th of them contains three integers, ui, vi, wi (0 β€ ui, vi β€ n - 1, ui β vi, 0 β€ wi β€ 109). ui and vi denote the endpoints of the edge and wi denotes its weight. If wi is equal to 0 then the weight of the corresponding edge was erased.
It is guaranteed that there is at most one edge between any pair of vertices.
Output
Print "NO" (without quotes) in the only line if it's not possible to assign the weights in a required way.
Otherwise, print "YES" in the first line. Next m lines should contain the edges of the resulting graph, with weights assigned to edges which weights were erased. i-th of them should contain three integers ui, vi and wi, denoting an edge between vertices ui and vi of weight wi. The edges of the new graph must coincide with the ones in the graph from the input. The weights that were not erased must remain unchanged whereas the new weights can be any positive integer not exceeding 1018.
The order of the edges in the output doesn't matter. The length of the shortest path between s and t must be equal to L.
If there are multiple solutions, print any of them.
Examples
Input
5 5 13 0 4
0 1 5
2 1 2
3 2 3
1 4 0
4 3 4
Output
YES
0 1 5
2 1 2
3 2 3
1 4 8
4 3 4
Input
2 1 123456789 0 1
0 1 0
Output
YES
0 1 123456789
Input
2 1 999999999 1 0
0 1 1000000000
Output
NO
Note
Here's how the graph in the first sample case looks like :
<image>
In the first sample case, there is only one missing edge weight. Placing the weight of 8 gives a shortest path from 0 to 4 of length 13.
In the second sample case, there is only a single edge. Clearly, the only way is to replace the missing weight with 123456789.
In the last sample case, there is no weights to assign but the length of the shortest path doesn't match the required value, so the answer is "NO". | {
"input": [
"5 5 13 0 4\n0 1 5\n2 1 2\n3 2 3\n1 4 0\n4 3 4\n",
"2 1 123456789 0 1\n0 1 0\n",
"2 1 999999999 1 0\n0 1 1000000000\n"
],
"output": [
"YES\n0 1 5\n2 1 2\n3 2 3\n1 4 8\n4 3 4\n",
"YES\n0 1 123456789\n",
"NO"
]
} | {
"input": [
"7 9 999999999 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n",
"7 9 320 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n",
"4 5 7 0 3\n0 1 0\n1 2 3\n2 3 0\n0 2 5\n1 3 5\n",
"8 9 10 1 0\n1 2 1\n2 4 1\n1 3 0\n3 4 0\n4 5 0\n5 6 1\n6 0 1\n5 7 0\n7 0 0\n",
"4 4 14 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12\n",
"5 6 1000000000 0 4\n0 1 1\n2 0 2\n3 0 3\n4 1 0\n4 2 0\n3 4 0\n",
"4 5 10 1 2\n0 1 3\n1 2 0\n1 3 4\n2 3 4\n2 0 6\n",
"4 4 2 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 0\n",
"5 5 2 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0\n",
"5 5 3 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0\n",
"4 4 8 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 6\n",
"1000 1 1000000000 998 0\n0 999 0\n",
"5 5 1 0 2\n0 1 1\n1 2 1\n0 4 0\n4 3 0\n3 2 0\n",
"100 1 123456 99 0\n0 99 123456\n",
"4 4 13 1 3\n1 3 13\n2 3 0\n2 0 0\n1 0 12\n",
"7 9 319 0 3\n0 1 0\n1 2 0\n2 3 0\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n",
"1000 1 5 999 0\n0 999 0\n"
],
"output": [
"YES\n0 1 1\n1 2 999999996\n2 3 999999997\n0 4 1\n4 1 1\n1 5 499999999\n5 2 499999999\n2 6 1\n6 3 1\n",
"YES\n0 1 1\n1 2 199\n2 3 318\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n",
"YES\n0 1 3\n1 2 3\n2 3 2\n0 2 5\n1 3 5\n",
"YES\n1 2 1\n2 4 1\n1 3 1\n3 4 1\n4 5 6\n5 6 1\n6 0 1\n5 7 1\n7 0 1\n",
"NO",
"YES\n0 1 1\n2 0 2\n3 0 3\n4 1 999999999\n4 2 999999998\n3 4 999999997\n",
"NO",
"NO",
"YES\n0 1 1\n1 2 1\n0 4 1\n4 3 1\n3 2 1\n",
"NO",
"YES\n1 3 13\n2 3 1\n2 0 1\n1 0 6\n",
"NO",
"NO",
"YES\n0 99 123456\n",
"YES\n1 3 13\n2 3 1\n2 0 1\n1 0 12\n",
"YES\n0 1 1\n1 2 198\n2 3 317\n0 4 1\n4 1 1\n1 5 100\n5 2 100\n2 6 59\n6 3 61\n",
"YES\n0 999 5\n"
]
} | 2,300 | 1,000 |
2 | 7 | 737_A. Road to Cinema | Vasya is currently at a car rental service, and he wants to reach cinema. The film he has bought a ticket for starts in t minutes. There is a straight road of length s from the service to the cinema. Let's introduce a coordinate system so that the car rental service is at the point 0, and the cinema is at the point s.
There are k gas stations along the road, and at each of them you can fill a car with any amount of fuel for free! Consider that this operation doesn't take any time, i.e. is carried out instantly.
There are n cars in the rental service, i-th of them is characterized with two integers ci and vi β the price of this car rent and the capacity of its fuel tank in liters. It's not allowed to fuel a car with more fuel than its tank capacity vi. All cars are completely fueled at the car rental service.
Each of the cars can be driven in one of two speed modes: normal or accelerated. In the normal mode a car covers 1 kilometer in 2 minutes, and consumes 1 liter of fuel. In the accelerated mode a car covers 1 kilometer in 1 minutes, but consumes 2 liters of fuel. The driving mode can be changed at any moment and any number of times.
Your task is to choose a car with minimum price such that Vasya can reach the cinema before the show starts, i.e. not later than in t minutes. Assume that all cars are completely fueled initially.
Input
The first line contains four positive integers n, k, s and t (1 β€ n β€ 2Β·105, 1 β€ k β€ 2Β·105, 2 β€ s β€ 109, 1 β€ t β€ 2Β·109) β the number of cars at the car rental service, the number of gas stations along the road, the length of the road and the time in which the film starts.
Each of the next n lines contains two positive integers ci and vi (1 β€ ci, vi β€ 109) β the price of the i-th car and its fuel tank capacity.
The next line contains k distinct integers g1, g2, ..., gk (1 β€ gi β€ s - 1) β the positions of the gas stations on the road in arbitrary order.
Output
Print the minimum rent price of an appropriate car, i.e. such car that Vasya will be able to reach the cinema before the film starts (not later than in t minutes). If there is no appropriate car, print -1.
Examples
Input
3 1 8 10
10 8
5 7
11 9
3
Output
10
Input
2 2 10 18
10 4
20 6
5 3
Output
20
Note
In the first sample, Vasya can reach the cinema in time using the first or the third cars, but it would be cheaper to choose the first one. Its price is equal to 10, and the capacity of its fuel tank is 8. Then Vasya can drive to the first gas station in the accelerated mode in 3 minutes, spending 6 liters of fuel. After that he can full the tank and cover 2 kilometers in the normal mode in 4 minutes, spending 2 liters of fuel. Finally, he drives in the accelerated mode covering the remaining 3 kilometers in 3 minutes and spending 6 liters of fuel. | {
"input": [
"3 1 8 10\n10 8\n5 7\n11 9\n3\n",
"2 2 10 18\n10 4\n20 6\n5 3\n"
],
"output": [
"10\n",
"20\n"
]
} | {
"input": [
"1 1 2 2\n1000000000 1000000000\n1\n",
"1 1 1000000000 1000000000\n100 1000000000\n1\n",
"1 1 10 18\n5 6\n5\n",
"2 1 1000000000 2000000000\n111 999999999\n101 999999998\n1\n",
"4 13 400 600\n13 30\n1 19\n1 160\n1 113\n58 73 15 319 194 362 128 157 336 162 77 90 96\n",
"1 15 100 200\n283 8\n30 58 16 45 80 82 55 95 24 23 86 28 51 47 20\n",
"3 2 300 400\n24 68\n13 65\n15 113\n127 177\n",
"1 1 2 1\n1 10\n1\n",
"4 2 7 15\n10 9\n4 4\n9 3\n4 10\n1 6\n",
"2 1 1000000000 2000000000\n111 1000000000\n101 1000000000\n5\n",
"2 1 1000000000 2000000000\n111 999999998\n101 999999998\n1\n",
"1 1 1000000000 1000000000\n1 1000000000\n1\n"
],
"output": [
"1000000000\n",
"-1\n",
"5\n",
"111\n",
"1\n",
"-1\n",
"-1\n",
"-1\n",
"4\n",
"101\n",
"-1\n",
"-1\n"
]
} | 1,700 | 1,750 |
2 | 8 | 784_B. Kids' Riddle | Programmers' kids solve this riddle in 5-10 minutes. How fast can you do it?
Input
The input contains a single integer n (0 β€ n β€ 2000000000).
Output
Output a single integer.
Examples
Input
11
Output
2
Input
14
Output
0
Input
61441
Output
2
Input
571576
Output
10
Input
2128506
Output
3 | {
"input": [
"14\n",
"2128506\n",
"11\n",
"571576\n",
"61441\n"
],
"output": [
"0",
"3",
"2",
"10",
"2"
]
} | {
"input": [
"143165576\n",
"1919020031\n",
"1204252996\n",
"210637432\n",
"724264821\n",
"1741\n",
"619489590\n",
"1199537418\n",
"1075765759\n",
"747976826\n",
"638486017\n",
"58438190\n",
"1285316221\n",
"186925426\n",
"1180540990\n",
"833393692\n",
"1818960378\n",
"2000000000\n",
"0\n",
"1309028227\n",
"514714359\n",
"624205168\n",
"1795248373\n",
"643201595\n",
"1304312649\n"
],
"output": [
"14",
"3",
"3",
"4",
"5",
"2",
"4",
"4",
"2",
"4",
"6",
"4",
"3",
"4",
"5",
"3",
"5",
"4",
"1",
"5",
"3",
"4",
"5",
"5",
"8"
]
} | 2,000 | 0 |
2 | 7 | 805_A. Fake NP | Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.
You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.
Solve the problem to show that it's not a NP problem.
Input
The first line contains two integers l and r (2 β€ l β€ r β€ 109).
Output
Print single integer, the integer that appears maximum number of times in the divisors.
If there are multiple answers, print any of them.
Examples
Input
19 29
Output
2
Input
3 6
Output
3
Note
Definition of a divisor: <https://www.mathsisfun.com/definitions/divisor-of-an-integer-.html>
The first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.
The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}. | {
"input": [
"19 29\n",
"3 6\n"
],
"output": [
"2\n",
"2\n"
]
} | {
"input": [
"252662256 252662260\n",
"141650963 141650963\n",
"4 12\n",
"1002523 1002523\n",
"93 95\n",
"331900277 331900277\n",
"56 92\n",
"10 100\n",
"3 1000000000\n",
"13 13\n",
"2 879190747\n",
"999900001 1000000000\n",
"820844234 892579936\n",
"419873015 419873018\n",
"568814539 568814539\n",
"999999937 999999937\n",
"519002744 519002744\n",
"80270976 80270977\n",
"5 10\n",
"3 6\n",
"392602363 392602367\n",
"6 12\n",
"634097178 634097179\n",
"6 15\n",
"3 10\n",
"305693653 305693653\n",
"2 3\n",
"1200007 1200007\n",
"5 100\n",
"10000019 10000019\n",
"720270740 720270743\n",
"94 95\n",
"908580370 968054552\n",
"760632746 850720703\n",
"900000011 900000011\n",
"37622224 162971117\n",
"5 5\n",
"76 134\n",
"3 12\n",
"39 91\n",
"999992977 999992977\n",
"17 17\n",
"29 29\n",
"770439256 770439256\n",
"347877978 913527175\n",
"3 8\n",
"5 15\n",
"349533413 349533413\n",
"100000007 100000007\n",
"104729 104729\n",
"900000000 1000000000\n",
"479001599 479001599\n",
"999727999 999727999\n",
"1717 1717\n",
"15 27\n",
"100003 100003\n",
"51 52\n",
"17 35\n",
"1000003 1000003\n",
"6 8\n",
"11 11\n",
"741254764 741254768\n",
"2 2\n",
"30 37\n",
"2 1000000000\n",
"4 8\n",
"620769961 988145114\n",
"951594860 953554446\n",
"450868287 450868290\n",
"575062045 575062049\n",
"28829775 28829776\n",
"999999797 999999797\n",
"990000023 990000023\n",
"871232720 871232722\n",
"242 244\n",
"273072892 273072894\n",
"2 999999999\n",
"7 7\n",
"38 98\n",
"39916801 39916801\n",
"998244353 998244353\n",
"3 111111\n",
"3 3\n",
"982451653 982451653\n",
"3 18\n",
"47 52\n",
"999999103 999999103\n",
"999999929 999999929\n",
"3 99\n",
"715827883 715827883\n",
"12 18\n",
"999999733 999999733\n"
],
"output": [
"2\n",
"141650963\n",
"2\n",
"1002523\n",
"2\n",
"331900277\n",
"2\n",
"2\n",
"2\n",
"13\n",
"2\n",
"2\n",
"2\n",
"2\n",
"568814539\n",
"999999937\n",
"519002744\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"305693653\n",
"2\n",
"1200007\n",
"2\n",
"10000019\n",
"2\n",
"2\n",
"2\n",
"2\n",
"900000011\n",
"2\n",
"5\n",
"2\n",
"2\n",
"2\n",
"999992977\n",
"17\n",
"29\n",
"770439256\n",
"2\n",
"2\n",
"2\n",
"349533413\n",
"100000007\n",
"104729\n",
"2\n",
"479001599\n",
"999727999\n",
"1717\n",
"2\n",
"100003\n",
"2\n",
"2\n",
"1000003\n",
"2\n",
"11\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"2\n",
"999999797\n",
"990000023\n",
"2\n",
"2\n",
"2\n",
"2\n",
"7\n",
"2\n",
"39916801\n",
"998244353\n",
"2\n",
"3\n",
"982451653\n",
"2\n",
"2\n",
"999999103\n",
"999999929\n",
"2\n",
"715827883\n",
"2\n",
"999999733\n"
]
} | 1,000 | 500 |
2 | 7 | 830_A. Office Keys | There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
Input
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 109) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a1, a2, ..., an (1 β€ ai β€ 109) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b1, b2, ..., bk (1 β€ bj β€ 109) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
Output
Print the minimum time (in seconds) needed for all n to reach the office with keys.
Examples
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
Note
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | {
"input": [
"1 2 10\n11\n15 7\n",
"2 4 50\n20 100\n60 10 40 80\n"
],
"output": [
"7",
"50"
]
} | {
"input": [
"1 1 10\n10\n10\n",
"2 2 10\n9 11\n11 8\n",
"1 1 1000000000\n1000000000\n1\n",
"1 1 50\n1\n1000000000\n",
"2 2 5\n2 3\n4 6\n",
"5 20 1\n314 316 328 323 321\n30 61 11 83 19 63 97 87 14 79 43 57 75 48 47 95 41 27 8 88\n",
"1 1 1\n2\n1000000000\n",
"2 2 10\n5 6\n4 6\n",
"2 4 1000\n1000 999\n1 1000 2 999\n",
"1 1 1\n1000000000\n1\n",
"3 4 10\n5 7 9\n6 8 14 4\n",
"1 1 2\n1\n1000000000\n",
"20 20 1000000000\n911196469 574676950 884047241 984218701 641693148 352743122 616364857 455260052 702604347 921615943 671695009 544819698 768892858 254148055 379968391 65297129 178692403 575557323 307174510 63022600\n1621 106 6866 6420 9307 6985 2741 9477 9837 5909 6757 3085 6139 1876 3726 9334 4321 1531 8534 560\n",
"40 45 1000\n6 55 34 32 20 76 2 84 47 68 31 60 14 70 99 72 21 61 81 79 26 51 96 86 10 1 43 69 87 78 13 11 80 67 50 52 9 29 94 12\n1974 1232 234 28 1456 626 408 1086 1525 1209 1096 940 795 1867 548 1774 1993 1199 1112 1087 1923 1156 876 1715 1815 1027 1658 955 398 910 620 1164 749 996 113 109 500 328 800 826 766 518 1474 1038 1029\n",
"1 1 1000000000\n1\n1000000000\n",
"3 3 4\n1 101 102\n2 3 100\n",
"2 2 1000\n10 1010\n1 1001\n",
"1 1 42\n666\n1337\n",
"2 2 4\n3 4\n5 6\n",
"2 2 7122\n123 456\n1 4444\n",
"1 1 1\n1\n1\n",
"1 1 10\n5\n15\n",
"2 2 3\n1 5\n5 1\n",
"2 2 1\n2 3\n4 100\n",
"2 5 15\n10 4\n29 23 21 22 26\n",
"2 2 100\n99 150\n1 150\n",
"50 55 2000\n9518 9743 9338 9956 9827 9772 9094 9644 9242 9292 9148 9205 9907 9860 9530 9814 9662 9482 9725 9227 9105 9424 9268 9427 9470 9578 9808 9976 9143 9070 9079 9896 9367 9235 9925 9009 9619 9012 9669 9077 9870 9766 9479 9598 9055 9988 9792 9197 9377 9610\n828 656 345 412 69 506 274 994 384 766 587 126 720 227 66 839 997 602 646 955 256 262 243 676 459 83 507 88 559 595 71 154 867 276 487 895 857 888 368 179 813 407 973 780 588 112 815 290 554 230 768 804 974 3 745\n",
"1 1 1\n1\n1000000000\n",
"3 10 1500\n106 160 129\n1333 1532 1181 1091 1656 1698 1291 1741 1242 1163\n",
"2 2 10\n3 12\n1 9\n",
"2 2 5\n1 2\n3 1000000000\n",
"3 3 1\n1 2 3\n999 1000000000 1\n",
"3 10 5\n1 2 3\n10000 9999 9998 9997 9996 9995 9994 7 6 5\n",
"1 1 1000000000\n1000000000\n10\n"
],
"output": [
"0",
"3",
"1999999998",
"1999999949",
"4",
"327",
"1999999997",
"7",
"1",
"999999999",
"7",
"1999999997",
"1984199027",
"2449",
"999999999",
"99",
"1008",
"1966",
"4",
"7243",
"0",
"15",
"2",
"196",
"23",
"197",
"10833",
"1999999998",
"1394",
"11",
"1999999993",
"1999999996",
"6",
"1999999980"
]
} | 1,800 | 500 |
2 | 8 | 851_B. Arpa and an exam about geometry | Arpa is taking a geometry exam. Here is the last problem of the exam.
You are given three points a, b, c.
Find a point and an angle such that if we rotate the page around the point by the angle, the new position of a is the same as the old position of b, and the new position of b is the same as the old position of c.
Arpa is doubting if the problem has a solution or not (i.e. if there exists a point and an angle satisfying the condition). Help Arpa determine if the question has a solution or not.
Input
The only line contains six integers ax, ay, bx, by, cx, cy (|ax|, |ay|, |bx|, |by|, |cx|, |cy| β€ 109). It's guaranteed that the points are distinct.
Output
Print "Yes" if the problem has a solution, "No" otherwise.
You can print each letter in any case (upper or lower).
Examples
Input
0 1 1 1 1 0
Output
Yes
Input
1 1 0 0 1000 1000
Output
No
Note
In the first sample test, rotate the page around (0.5, 0.5) by <image>.
In the second sample test, you can't find any solution. | {
"input": [
"0 1 1 1 1 0\n",
"1 1 0 0 1000 1000\n"
],
"output": [
"Yes\n",
"No\n"
]
} | {
"input": [
"264193194 -448876521 736684426 -633906160 -328597212 -47935734\n",
"-357531221 381512519 -761132895 -224448284 328888775 -237692564\n",
"-1000000000 -1000000000 0 0 1000000000 999999999\n",
"0 2 4 5 4 0\n",
"0 0 2 45 0 90\n",
"-1000000000 -1000000000 0 1000000000 1000000000 -1000000000\n",
"0 1000000000 1 0 0 -1000000000\n",
"1 0 2 0 3 0\n",
"299948862 -648908808 338174789 841279400 -850322448 350263551\n",
"-1 -1000000000 0 1000000000 1 -1000000000\n",
"-607353321 -620687860 248029390 477864359 728255275 -264646027\n",
"5 0 4 -2 0 1\n",
"0 0 1000000000 1 1000000000 -999999999\n",
"589824 196608 262144 196608 0 0\n",
"3 4 0 0 4 3\n",
"0 0 2 0 4 0\n",
"1 1 3 3 5 5\n",
"-947393823 -495674431 211535284 -877153626 -522763219 -778236665\n",
"419578772 -125025887 169314071 89851312 961404059 21419450\n",
"48517753 416240699 7672672 272460100 -917845051 199790781\n",
"1000000000 1000000000 0 -1000000000 -1000000000 1000000000\n",
"-326038504 547872194 49630307 713863100 303770000 -556852524\n",
"-3 -3 5 2 3 -1\n",
"-1000000000 -1000000000 0 0 1000000000 1000000000\n",
"-1000000000 1 0 0 1000000000 1\n",
"0 1000000000 0 0 0 -1000000000\n",
"-685673792 -488079395 909733355 385950193 -705890324 256550506\n",
"-999999999 -1000000000 0 0 1000000000 999999999\n",
"0 2 0 3 0 4\n",
"999999999 1000000000 0 0 -1000000000 -999999999\n",
"0 0 1 1 2 0\n",
"-4 -3 2 -1 -3 4\n",
"1 1 2 2 3 1\n",
"0 0 0 2 0 1\n",
"49152 0 0 0 0 81920\n",
"0 0 1 1 2 2\n",
"0 1 1 2 2 3\n",
"0 0 3 4 3 9\n",
"-2 -2 1 4 -2 0\n",
"1 -1 4 4 2 -3\n",
"1 1 2 2 3 3\n",
"-1000000000 -999999999 0 0 1000000000 999999999\n",
"1 1 1 2 1 3\n",
"-706921242 -758563024 -588592101 -443440080 858751713 238854303\n"
],
"output": [
"No\n",
"No\n",
"No\n",
"Yes\n",
"Yes\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"Yes\n",
"Yes\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"Yes\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n",
"No\n"
]
} | 1,400 | 1,000 |
2 | 11 | 920_E. Connected Components? | You are given an undirected graph consisting of n vertices and <image> edges. Instead of giving you the edges that exist in the graph, we give you m unordered pairs (x, y) such that there is no edge between x and y, and if some pair of vertices is not listed in the input, then there is an edge between these vertices.
You have to find the number of connected components in the graph and the size of each component. A connected component is a set of vertices X such that for every two vertices from this set there exists at least one path in the graph connecting these vertices, but adding any other vertex to X violates this rule.
Input
The first line contains two integers n and m (1 β€ n β€ 200000, <image>).
Then m lines follow, each containing a pair of integers x and y (1 β€ x, y β€ n, x β y) denoting that there is no edge between x and y. Each pair is listed at most once; (x, y) and (y, x) are considered the same (so they are never listed in the same test). If some pair of vertices is not listed in the input, then there exists an edge between those vertices.
Output
Firstly print k β the number of connected components in this graph.
Then print k integers β the sizes of components. You should output these integers in non-descending order.
Example
Input
5 5
1 2
3 4
3 2
4 2
2 5
Output
2
1 4 | {
"input": [
"5 5\n1 2\n3 4\n3 2\n4 2\n2 5\n"
],
"output": [
"2\n1 4 \n"
]
} | {
"input": [
"7 20\n4 6\n6 7\n4 5\n1 2\n2 4\n1 7\n3 5\n2 1\n6 2\n6 1\n7 3\n3 2\n3 6\n3 1\n3 4\n2 5\n1 6\n7 4\n6 3\n7 5\n",
"8 23\n1 2\n1 4\n1 6\n1 8\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 5\n3 6\n3 7\n3 8\n4 5\n4 6\n4 7\n5 6\n5 7\n5 8\n6 8\n7 8\n",
"4 4\n2 1\n3 1\n1 4\n3 2\n",
"8 18\n1 4\n1 6\n1 7\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n3 4\n3 8\n4 7\n5 6\n5 7\n5 8\n6 7\n6 8\n7 8\n",
"10 34\n7 10\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 10\n4 5\n4 6\n4 7\n4 8\n4 9\n6 7\n6 8\n6 9\n6 10\n1 2\n1 3\n1 5\n8 9\n1 6\n1 7\n1 8\n1 9\n1 10\n3 4\n3 5\n3 6\n3 8\n3 10\n5 6\n5 9\n5 10\n",
"5 7\n1 2\n2 3\n3 4\n1 5\n2 5\n3 5\n4 5\n",
"2 0\n",
"8 23\n2 7\n7 5\n8 6\n8 2\n6 3\n3 5\n8 1\n8 4\n8 3\n3 4\n1 2\n2 6\n5 2\n6 4\n7 6\n6 5\n7 8\n7 1\n5 4\n3 7\n1 4\n3 1\n3 2\n",
"2 1\n1 2\n",
"6 9\n1 2\n1 4\n1 5\n2 3\n2 5\n2 6\n3 5\n4 6\n5 6\n",
"12 56\n9 5\n2 6\n9 8\n5 4\n1 11\n1 6\n4 1\n1 10\n10 3\n8 4\n5 1\n9 1\n5 10\n2 7\n11 5\n6 11\n5 8\n7 6\n3 2\n12 7\n8 6\n12 3\n1 2\n8 1\n2 11\n10 12\n4 6\n5 12\n2 4\n10 2\n7 3\n12 11\n7 10\n7 1\n9 2\n11 9\n9 10\n8 7\n11 3\n7 9\n5 7\n4 12\n3 5\n12 2\n4 10\n9 12\n5 2\n9 4\n11 8\n8 2\n3 6\n4 11\n8 10\n6 10\n3 9\n3 4\n",
"12 58\n1 2\n1 3\n1 4\n1 5\n1 6\n1 7\n1 8\n1 10\n1 11\n1 12\n2 3\n2 4\n2 5\n2 6\n2 7\n2 8\n2 9\n2 10\n2 11\n2 12\n3 4\n3 5\n3 6\n3 7\n3 8\n3 9\n3 10\n3 11\n3 12\n4 5\n4 6\n4 8\n4 11\n4 12\n5 6\n5 7\n5 8\n5 9\n5 10\n5 11\n6 7\n6 8\n6 9\n6 10\n6 11\n6 12\n7 8\n7 9\n7 10\n7 11\n7 12\n8 9\n8 10\n8 11\n9 10\n9 11\n9 12\n10 12\n",
"4 3\n2 1\n3 1\n4 2\n",
"3 1\n2 3\n",
"6 10\n1 2\n1 3\n1 4\n1 6\n2 3\n2 4\n2 5\n3 5\n3 6\n4 6\n",
"11 49\n10 3\n6 4\n11 3\n7 6\n10 6\n6 1\n4 3\n10 2\n4 5\n9 2\n10 1\n5 7\n1 5\n9 7\n2 11\n8 6\n3 9\n2 5\n9 5\n6 5\n1 4\n11 9\n1 7\n8 10\n3 6\n3 7\n11 5\n6 9\n4 10\n8 7\n4 9\n8 2\n4 2\n8 11\n7 4\n9 10\n8 1\n10 7\n3 2\n5 8\n8 9\n1 3\n2 7\n10 11\n5 3\n10 5\n4 11\n1 11\n8 3\n",
"5 4\n1 4\n2 3\n4 3\n4 2\n",
"4 3\n1 2\n3 1\n4 3\n",
"4 3\n1 3\n1 4\n2 3\n",
"10 36\n7 8\n7 9\n2 3\n2 4\n2 5\n9 10\n2 7\n2 8\n2 9\n2 10\n4 5\n4 6\n4 7\n4 8\n4 10\n6 7\n6 9\n6 10\n1 2\n1 3\n1 4\n8 9\n1 5\n8 10\n1 7\n1 8\n1 9\n1 10\n3 4\n3 6\n3 7\n3 9\n5 6\n5 7\n5 9\n5 10\n",
"8 15\n2 1\n4 5\n2 4\n3 4\n2 5\n3 5\n2 6\n3 6\n5 6\n4 6\n2 7\n3 8\n2 8\n3 7\n6 7\n"
],
"output": [
"3\n1 2 4 \n",
"3\n1 2 5 \n",
"2\n1 3 \n",
"1\n8 \n",
"1\n10 \n",
"2\n1 4 \n",
"1\n2 \n",
"3\n1 3 4 \n",
"2\n1 1 \n",
"1\n6 \n",
"3\n1 4 7 \n",
"4\n1 1 1 9 \n",
"1\n4 \n",
"1\n3 \n",
"1\n6 \n",
"5\n1 1 1 2 6 \n",
"1\n5 \n",
"1\n4 \n",
"1\n4 \n",
"2\n2 8 \n",
"1\n8 \n"
]
} | 2,100 | 0 |
2 | 9 | 949_C. Data Center Maintenance | BigData Inc. is a corporation that has n data centers indexed from 1 to n that are located all over the world. These data centers provide storage for client data (you can figure out that client data is really big!).
Main feature of services offered by BigData Inc. is the access availability guarantee even under the circumstances of any data center having an outage. Such a guarantee is ensured by using the two-way replication. Two-way replication is such an approach for data storage that any piece of data is represented by two identical copies that are stored in two different data centers.
For each of m company clients, let us denote indices of two different data centers storing this client data as ci, 1 and ci, 2.
In order to keep data centers operational and safe, the software running on data center computers is being updated regularly. Release cycle of BigData Inc. is one day meaning that the new version of software is being deployed to the data center computers each day.
Data center software update is a non-trivial long process, that is why there is a special hour-long time frame that is dedicated for data center maintenance. During the maintenance period, data center computers are installing software updates, and thus they may be unavailable. Consider the day to be exactly h hours long. For each data center there is an integer uj (0 β€ uj β€ h - 1) defining the index of an hour of day, such that during this hour data center j is unavailable due to maintenance.
Summing up everything above, the condition uci, 1 β uci, 2 should hold for each client, or otherwise his data may be unaccessible while data centers that store it are under maintenance.
Due to occasional timezone change in different cities all over the world, the maintenance time in some of the data centers may change by one hour sometimes. Company should be prepared for such situation, that is why they decided to conduct an experiment, choosing some non-empty subset of data centers, and shifting the maintenance time for them by an hour later (i.e. if uj = h - 1, then the new maintenance hour would become 0, otherwise it would become uj + 1). Nonetheless, such an experiment should not break the accessibility guarantees, meaning that data of any client should be still available during any hour of a day after the data center maintenance times are changed.
Such an experiment would provide useful insights, but changing update time is quite an expensive procedure, that is why the company asked you to find out the minimum number of data centers that have to be included in an experiment in order to keep the data accessibility guarantees.
Input
The first line of input contains three integers n, m and h (2 β€ n β€ 100 000, 1 β€ m β€ 100 000, 2 β€ h β€ 100 000), the number of company data centers, number of clients and the day length of day measured in hours.
The second line of input contains n integers u1, u2, ..., un (0 β€ uj < h), j-th of these numbers is an index of a maintenance hour for data center j.
Each of the next m lines contains two integers ci, 1 and ci, 2 (1 β€ ci, 1, ci, 2 β€ n, ci, 1 β ci, 2), defining the data center indices containing the data of client i.
It is guaranteed that the given maintenance schedule allows each client to access at least one copy of his data at any moment of day.
Output
In the first line print the minimum possible number of data centers k (1 β€ k β€ n) that have to be included in an experiment in order to keep the data available for any client.
In the second line print k distinct integers x1, x2, ..., xk (1 β€ xi β€ n), the indices of data centers whose maintenance time will be shifted by one hour later. Data center indices may be printed in any order.
If there are several possible answers, it is allowed to print any of them. It is guaranteed that at there is at least one valid choice of data centers.
Examples
Input
3 3 5
4 4 0
1 3
3 2
3 1
Output
1
3
Input
4 5 4
2 1 0 3
4 3
3 2
1 2
1 4
1 3
Output
4
1 2 3 4
Note
Consider the first sample test. The given answer is the only way to conduct an experiment involving the only data center. In such a scenario the third data center has a maintenance during the hour 1, and no two data centers storing the information of the same client have maintenance at the same hour.
On the other hand, for example, if we shift the maintenance time on hour later for the first data center, then the data of clients 1 and 3 will be unavailable during the hour 0. | {
"input": [
"3 3 5\n4 4 0\n1 3\n3 2\n3 1\n",
"4 5 4\n2 1 0 3\n4 3\n3 2\n1 2\n1 4\n1 3\n"
],
"output": [
"1\n3 \n",
"4\n1 2 3 4 \n"
]
} | {
"input": [
"10 9 5\n0 0 0 0 0 0 0 0 0 4\n10 3\n10 7\n10 5\n10 8\n10 9\n10 1\n10 4\n10 6\n10 2\n",
"10 20 5\n2 2 1 4 0 3 0 4 1 3\n6 1\n8 5\n2 10\n3 5\n1 9\n4 6\n9 7\n2 3\n7 4\n10 8\n4 9\n2 5\n4 10\n2 8\n10 3\n1 8\n8 10\n6 7\n5 1\n10 3\n",
"10 9 2\n1 1 0 1 1 1 1 1 1 1\n3 10\n3 8\n3 6\n3 7\n3 5\n3 4\n3 1\n3 9\n3 2\n",
"10 10 5\n3 4 2 0 3 0 1 1 2 4\n8 9\n7 3\n5 2\n4 8\n3 5\n6 8\n3 5\n1 10\n10 6\n9 1\n",
"10 30 10\n7 9 1 5 4 6 0 3 8 2\n10 8\n8 5\n6 1\n8 5\n3 10\n10 8\n9 2\n8 5\n7 3\n3 10\n1 9\n10 8\n6 1\n1 9\n8 5\n7 3\n1 9\n7 3\n7 3\n4 6\n10 8\n7 3\n3 10\n10 8\n1 9\n8 5\n6 1\n4 6\n3 10\n6 1\n",
"6 7 3\n0 1 2 0 1 2\n1 2\n2 3\n3 1\n3 4\n4 5\n5 6\n6 4\n",
"10 9 2\n0 1 0 0 1 0 1 1 1 1\n3 7\n3 2\n8 6\n1 7\n3 9\n5 4\n10 1\n4 9\n6 2\n",
"10 10 10\n2 3 5 7 0 8 6 9 4 1\n1 2\n10 1\n5 10\n5 10\n4 6\n8 5\n1 2\n1 2\n7 4\n1 2\n",
"10 9 5\n1 1 1 1 1 2 1 1 1 1\n6 7\n6 3\n6 5\n6 4\n6 9\n6 8\n6 1\n6 10\n6 2\n",
"10 9 2\n0 0 0 0 1 1 0 1 1 1\n4 10\n8 2\n10 3\n3 9\n1 5\n6 2\n6 1\n7 9\n8 7\n",
"5 5 3\n2 2 0 1 0\n5 4\n5 2\n1 4\n5 1\n4 3\n",
"10 9 5\n0 4 1 0 1 2 1 0 4 4\n8 7\n4 3\n1 5\n2 4\n6 5\n10 8\n9 1\n6 7\n6 3\n",
"7 8 3\n0 0 1 2 2 0 1\n1 5\n4 3\n7 5\n1 7\n3 2\n2 4\n6 7\n6 5\n",
"10 30 7\n5 4 2 3 3 2 5 0 1 6\n7 2\n2 4\n9 3\n3 5\n5 2\n7 10\n6 5\n10 1\n9 8\n10 8\n3 4\n10 4\n4 2\n7 6\n2 8\n1 10\n5 10\n5 6\n5 6\n6 2\n6 5\n9 10\n8 6\n2 4\n9 7\n1 9\n10 4\n6 10\n9 3\n2 7\n",
"5 5 3\n1 1 2 0 0\n1 3\n1 5\n2 3\n3 4\n2 4\n",
"10 10 2\n1 1 1 0 1 0 0 0 0 1\n4 10\n10 7\n7 1\n5 6\n6 3\n1 8\n2 9\n5 4\n3 8\n2 9\n",
"9 13 3\n0 2 1 2 2 0 1 0 1\n4 7\n9 5\n7 5\n7 6\n9 6\n8 2\n3 2\n8 3\n4 3\n4 9\n1 2\n1 3\n5 6\n",
"6 3 3\n0 1 2 0 1 2\n4 5\n5 6\n4 6\n",
"10 10 5\n3 3 3 4 4 1 3 0 2 4\n7 5\n10 8\n10 8\n5 8\n2 10\n9 2\n7 4\n3 4\n7 5\n4 8\n",
"10 15 2\n1 0 1 1 0 0 1 0 0 1\n5 1\n7 8\n2 10\n3 5\n1 9\n6 4\n7 9\n2 3\n6 4\n8 10\n9 4\n8 4\n8 1\n10 8\n6 7\n",
"2 1 2\n1 0\n1 2\n",
"5 5 4\n0 1 2 3 3\n1 2\n2 3\n3 4\n4 1\n3 5\n",
"10 9 5\n2 1 2 0 1 0 1 2 0 4\n10 9\n3 7\n1 5\n10 6\n7 9\n10 4\n5 4\n2 6\n8 2\n",
"9 10 3\n0 2 2 1 0 0 1 2 1\n4 6\n2 6\n5 7\n4 8\n9 2\n9 1\n3 5\n8 1\n3 7\n6 2\n",
"10 20 3\n2 2 1 1 2 0 0 1 2 2\n7 5\n7 10\n2 7\n10 4\n10 8\n1 7\n3 7\n9 7\n3 10\n6 3\n4 1\n4 1\n8 6\n3 7\n10 3\n2 7\n8 5\n2 7\n1 4\n2 6\n",
"10 9 8\n3 2 1 1 5 6 7 0 4 0\n10 7\n5 9\n10 4\n7 6\n6 5\n3 2\n2 1\n9 1\n3 8\n"
],
"output": [
"1\n1 \n",
"5\n1 4 6 7 9 \n",
"10\n1 2 3 4 5 6 7 8 9 10 \n",
"1\n2 \n",
"1\n2 \n",
"3\n4 5 6 \n",
"10\n1 2 3 4 5 6 7 8 9 10 \n",
"1\n2 \n",
"1\n6 \n",
"10\n1 2 3 4 5 6 7 8 9 10 \n",
"3\n1 4 5 \n",
"1\n6 \n",
"3\n2 3 4 \n",
"8\n2 3 4 5 7 8 9 10 \n",
"3\n2 3 4 \n",
"2\n2 9 \n",
"1\n4 \n",
"1\n1 \n",
"1\n1 \n",
"10\n1 2 3 4 5 6 7 8 9 10 \n",
"2\n1 2 \n",
"1\n5 \n",
"1\n1 \n",
"3\n3 5 7 \n",
"3\n3 7 10 \n",
"1\n4 \n"
]
} | 1,900 | 1,250 |
2 | 8 | 977_B. Two-gram | Two-gram is an ordered pair (i.e. string of length two) of capital Latin letters. For example, "AZ", "AA", "ZA" β three distinct two-grams.
You are given a string s consisting of n capital Latin letters. Your task is to find any two-gram contained in the given string as a substring (i.e. two consecutive characters of the string) maximal number of times. For example, for string s = "BBAABBBA" the answer is two-gram "BB", which contained in s three times. In other words, find any most frequent two-gram.
Note that occurrences of the two-gram can overlap with each other.
Input
The first line of the input contains integer number n (2 β€ n β€ 100) β the length of string s. The second line of the input contains the string s consisting of n capital Latin letters.
Output
Print the only line containing exactly two capital Latin letters β any two-gram contained in the given string s as a substring (i.e. two consecutive characters of the string) maximal number of times.
Examples
Input
7
ABACABA
Output
AB
Input
5
ZZZAA
Output
ZZ
Note
In the first example "BA" is also valid answer.
In the second example the only two-gram "ZZ" can be printed because it contained in the string "ZZZAA" two times. | {
"input": [
"5\nZZZAA\n",
"7\nABACABA\n"
],
"output": [
"ZZ\n",
"AB\n"
]
} | {
"input": [
"15\nMIRZOYANOVECLOX\n",
"23\nAABBBAAACCCCCAAADDDDDDD\n",
"2\nQA\n",
"11\nGGRRAATTZZZ\n",
"6\nAZAZAZ\n",
"10\nSQSQSQSQTG\n",
"3\nKEK\n",
"100\nURXCAIZFIBNJTPCZHBQIBCILLPXZCFGMKKZMNPLCYGAVJVIBMCZEBSJWPSCPQDYCTTKPOKIJRSKIZPDGCHVOUTMPNECYORSFZFNC\n",
"3\nLOL\n",
"2\nWW\n",
"8\nPUTINVOR\n",
"26\nQWERTYUIOPASDFGHJKLZXCVBNM\n",
"5\nAZAZA\n",
"9\nEGORLETOV\n",
"7\nKADUROV\n",
"9\nMIKEPIDOR\n",
"9\nAAAAAAAAA\n",
"100\nAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA\n",
"5\nFUFEL\n",
"50\nNYQAHBYYOXLTRYQDMVENEMAQNBAKGLGQOLXNAIFNQTOCLNNQIA\n"
],
"output": [
"MI\n",
"DD\n",
"QA\n",
"ZZ\n",
"AZ\n",
"SQ\n",
"KE\n",
"IB\n",
"LO\n",
"WW\n",
"PU\n",
"QW\n",
"AZ\n",
"EG\n",
"KA\n",
"MI\n",
"AA\n",
"AA\n",
"FU\n",
"YQ\n"
]
} | 900 | 0 |
2 | 8 | 1012_B. Chemical table | Innopolis University scientists continue to investigate the periodic table. There are nΒ·m known elements and they form a periodic table: a rectangle with n rows and m columns. Each element can be described by its coordinates (r, c) (1 β€ r β€ n, 1 β€ c β€ m) in the table.
Recently scientists discovered that for every four different elements in this table that form a rectangle with sides parallel to the sides of the table, if they have samples of three of the four elements, they can produce a sample of the fourth element using nuclear fusion. So if we have elements in positions (r1, c1), (r1, c2), (r2, c1), where r1 β r2 and c1 β c2, then we can produce element (r2, c2).
<image>
Samples used in fusion are not wasted and can be used again in future fusions. Newly crafted elements also can be used in future fusions.
Innopolis University scientists already have samples of q elements. They want to obtain samples of all nΒ·m elements. To achieve that, they will purchase some samples from other laboratories and then produce all remaining elements using an arbitrary number of nuclear fusions in some order. Help them to find the minimal number of elements they need to purchase.
Input
The first line contains three integers n, m, q (1 β€ n, m β€ 200 000; 0 β€ q β€ min(nΒ·m, 200 000)), the chemical table dimensions and the number of elements scientists already have.
The following q lines contain two integers ri, ci (1 β€ ri β€ n, 1 β€ ci β€ m), each describes an element that scientists already have. All elements in the input are different.
Output
Print the minimal number of elements to be purchased.
Examples
Input
2 2 3
1 2
2 2
2 1
Output
0
Input
1 5 3
1 3
1 1
1 5
Output
2
Input
4 3 6
1 2
1 3
2 2
2 3
3 1
3 3
Output
1
Note
For each example you have a picture which illustrates it.
The first picture for each example describes the initial set of element samples available. Black crosses represent elements available in the lab initially.
The second picture describes how remaining samples can be obtained. Red dashed circles denote elements that should be purchased from other labs (the optimal solution should minimize the number of red circles). Blue dashed circles are elements that can be produced with nuclear fusion. They are numbered in order in which they can be produced.
Test 1
We can use nuclear fusion and get the element from three other samples, so we don't need to purchase anything.
<image>
Test 2
We cannot use any nuclear fusion at all as there is only one row, so we have to purchase all missing elements.
<image>
Test 3
There are several possible solutions. One of them is illustrated below.
Note that after purchasing one element marked as red it's still not possible to immidiately produce the middle element in the bottom row (marked as 4). So we produce the element in the left-top corner first (marked as 1), and then use it in future fusions.
<image> | {
"input": [
"1 5 3\n1 3\n1 1\n1 5\n",
"2 2 3\n1 2\n2 2\n2 1\n",
"4 3 6\n1 2\n1 3\n2 2\n2 3\n3 1\n3 3\n"
],
"output": [
"2\n",
"0\n",
"1\n"
]
} | {
"input": [
"20 20 20\n18 16\n4 20\n2 5\n7 4\n11 13\n6 10\n20 8\n14 6\n3 12\n5 1\n16 7\n10 9\n1 11\n12 18\n19 15\n13 19\n17 3\n9 17\n15 2\n8 14\n",
"20 20 1\n17 13\n",
"1 1 0\n",
"10000 9999 1\n5717 9264\n",
"20 10 5\n18 10\n19 10\n19 9\n20 9\n20 8\n",
"1 20 3\n1 18\n1 12\n1 10\n",
"20 10 20\n9 5\n15 6\n17 10\n14 1\n18 7\n7 4\n2 3\n19 6\n6 6\n16 10\n5 2\n3 5\n12 6\n10 6\n11 1\n4 1\n20 5\n13 8\n1 9\n8 7\n",
"98 100 25\n96 100\n97 100\n97 99\n98 99\n98 98\n95 98\n96 97\n94 97\n95 96\n93 96\n94 95\n92 95\n93 94\n91 94\n92 93\n90 93\n91 92\n89 92\n90 91\n88 91\n89 90\n87 90\n88 89\n86 89\n87 88\n",
"5 5 5\n2 4\n3 3\n5 1\n4 1\n2 1\n",
"200000 200000 0\n",
"2 2 2\n1 1\n2 2\n",
"20 20 2\n9 14\n4 1\n",
"2 2 3\n1 2\n2 1\n2 2\n",
"1 2 1\n1 1\n",
"2 2 4\n1 1\n1 2\n2 1\n2 2\n",
"10000 10000 0\n",
"1 200000 0\n",
"20 20 80\n5 3\n13 13\n8 5\n2 9\n12 16\n1 11\n15 11\n3 20\n10 7\n5 4\n11 2\n5 20\n14 8\n5 1\n8 13\n11 5\n19 2\n15 12\n12 7\n16 5\n17 3\n12 2\n17 16\n12 3\n12 6\n18 20\n2 20\n9 1\n5 10\n9 18\n17 1\n17 10\n20 1\n12 12\n19 14\n7 8\n2 19\n6 14\n5 6\n15 2\n18 14\n5 7\n14 14\n17 2\n20 20\n11 6\n18 15\n10 5\n20 3\n1 8\n18 8\n6 3\n9 7\n14 20\n15 1\n7 14\n13 17\n3 18\n18 9\n14 13\n6 10\n19 13\n11 11\n17 8\n3 5\n9 12\n12 17\n19 1\n19 15\n11 12\n5 9\n1 9\n3 13\n5 14\n9 15\n18 11\n20 12\n4 20\n3 9\n8 2\n",
"10 10 20\n7 9\n2 3\n3 5\n4 6\n2 4\n10 1\n4 8\n6 6\n3 8\n3 9\n8 3\n5 1\n10 7\n1 1\n5 4\n2 1\n7 5\n6 7\n9 1\n1 2\n",
"20 20 39\n3 16\n4 8\n2 11\n3 8\n14 13\n10 1\n20 10\n4 13\n13 15\n11 18\n14 6\n9 17\n5 4\n18 15\n18 9\n20 20\n7 5\n5 17\n13 7\n15 16\n6 12\n7 18\n8 6\n16 12\n16 14\n19 2\n12 3\n15 10\n17 19\n19 4\n6 11\n1 5\n12 14\n9 9\n1 19\n10 7\n11 20\n2 1\n17 3\n",
"20 1 10\n18 1\n17 1\n12 1\n15 1\n6 1\n5 1\n14 1\n9 1\n19 1\n10 1\n",
"20 20 39\n13 7\n12 3\n16 1\n11 1\n11 4\n10 14\n9 20\n5 12\n5 18\n14 17\n6 3\n17 13\n19 14\n2 14\n6 4\n15 13\n15 5\n5 10\n16 16\n9 7\n15 8\n9 15\n3 7\n1 14\n18 1\n12 7\n14 2\n7 16\n8 14\n9 5\n6 19\n7 14\n4 14\n14 11\n14 9\n9 6\n14 12\n14 13\n20 14\n",
"2 2 3\n1 1\n1 2\n2 1\n",
"200000 200000 1\n113398 188829\n",
"2 1 0\n",
"100 100 0\n",
"20 100 2\n5 5\n7 44\n",
"20 20 39\n18 20\n19 20\n19 19\n20 19\n20 18\n17 18\n18 17\n16 17\n17 16\n15 16\n16 15\n14 15\n15 14\n13 14\n14 13\n12 13\n13 12\n11 12\n12 11\n10 11\n11 10\n9 10\n10 9\n8 9\n9 8\n7 8\n8 7\n6 7\n7 6\n5 6\n6 5\n4 5\n5 4\n3 4\n4 3\n2 3\n3 2\n1 2\n2 1\n",
"100 94 20\n14 61\n67 24\n98 32\n43 41\n87 59\n17 52\n44 54\n74 86\n36 77\n8 13\n84 30\n4 87\n59 27\n33 30\n100 56\n56 43\n19 46\n86 38\n76 47\n25 94\n",
"200000 1 0\n",
"2 2 3\n1 1\n2 1\n2 2\n",
"20 20 0\n",
"240 100 25\n238 100\n239 100\n239 99\n240 99\n240 98\n237 98\n238 97\n236 97\n237 96\n235 96\n236 95\n234 95\n235 94\n233 94\n234 93\n232 93\n233 92\n231 92\n232 91\n230 91\n231 90\n229 90\n230 89\n228 89\n229 88\n",
"20 20 20\n1 8\n1 9\n1 17\n1 18\n1 6\n1 12\n1 19\n1 2\n1 13\n1 15\n1 20\n1 16\n1 11\n1 7\n1 5\n1 14\n1 1\n1 3\n1 4\n1 10\n",
"20 20 20\n17 19\n13 18\n5 11\n19 1\n17 16\n1 19\n3 16\n17 10\n13 19\n5 10\n2 7\n18 17\n16 20\n8 8\n8 13\n4 4\n1 17\n17 18\n17 7\n16 11\n",
"2 2 3\n1 1\n1 2\n2 2\n",
"2 2 1\n1 2\n",
"250 1 0\n",
"20 20 30\n6 15\n2 6\n16 14\n13 7\n6 8\n13 17\n12 3\n7 13\n5 20\n10 10\n2 20\n1 12\n12 11\n15 4\n7 18\n10 12\n4 19\n18 19\n4 1\n9 13\n17 2\n11 5\n4 9\n20 8\n3 1\n14 14\n8 4\n19 4\n11 2\n16 16\n",
"1 10000 0\n",
"2 2 2\n1 2\n2 2\n",
"2 2 2\n1 2\n2 1\n",
"2 2 1\n2 1\n",
"10 20 0\n",
"1 1 1\n1 1\n",
"250 250 0\n",
"2 2 2\n1 1\n1 2\n",
"20 1 0\n",
"3 3 5\n1 3\n2 3\n2 2\n3 2\n3 1\n",
"1 2 0\n",
"1 20 20\n1 19\n1 5\n1 8\n1 12\n1 3\n1 9\n1 2\n1 10\n1 11\n1 18\n1 6\n1 7\n1 20\n1 4\n1 17\n1 16\n1 15\n1 14\n1 1\n1 13\n",
"20 20 37\n16 11\n14 20\n10 1\n14 4\n20 19\n20 15\n5 15\n19 20\n13 19\n11 19\n18 18\n4 13\n12 12\n1 12\n6 8\n18 6\n7 9\n3 16\n4 7\n9 11\n7 1\n12 5\n18 16\n20 14\n9 16\n15 15\n19 3\n6 15\n18 10\n14 9\n2 11\n18 2\n8 11\n17 9\n4 5\n20 17\n19 7\n",
"13 17 20\n6 14\n5 16\n2 1\n11 6\n4 10\n4 15\n8 14\n2 11\n10 6\n5 11\n2 4\n4 8\n2 10\n1 13\n11 13\n2 5\n7 13\n9 7\n2 15\n8 11\n",
"20 1 20\n13 1\n10 1\n5 1\n17 1\n12 1\n18 1\n1 1\n9 1\n6 1\n14 1\n20 1\n11 1\n2 1\n3 1\n8 1\n16 1\n4 1\n7 1\n15 1\n19 1\n",
"2 2 1\n2 2\n",
"100 20 1\n13 9\n",
"15 15 29\n5 3\n2 14\n3 9\n11 12\n5 5\n4 2\n6 10\n13 12\n12 5\n1 11\n3 4\n4 6\n11 3\n10 13\n15 11\n1 15\n7 15\n2 9\n13 14\n12 6\n9 7\n10 1\n8 1\n6 7\n7 10\n9 4\n8 8\n15 13\n14 8\n",
"2 2 2\n1 1\n2 1\n",
"1 20 0\n",
"250 250 1\n217 197\n",
"8 3 7\n8 3\n1 2\n8 1\n3 2\n5 1\n5 3\n6 1\n",
"2 2 0\n",
"10000 1 0\n",
"2 1 1\n1 1\n",
"20 20 20\n6 5\n13 8\n9 20\n5 15\n10 2\n12 12\n15 4\n7 18\n18 10\n17 13\n11 11\n20 7\n16 19\n8 6\n3 3\n2 16\n4 1\n1 17\n19 14\n14 9\n",
"17 13 20\n16 4\n17 10\n16 1\n15 7\n10 1\n14 6\n6 13\n2 2\n7 10\n12 12\n14 1\n10 4\n12 5\n14 2\n3 1\n12 13\n9 1\n4 1\n5 9\n10 6\n",
"2 20 0\n",
"2 20 40\n1 19\n2 19\n1 7\n2 20\n1 8\n1 14\n2 10\n1 10\n1 9\n2 12\n1 12\n2 17\n1 3\n2 13\n1 20\n1 18\n2 5\n2 6\n2 4\n1 6\n2 9\n2 11\n1 1\n2 8\n2 7\n2 16\n2 2\n1 16\n1 15\n1 11\n1 4\n2 1\n2 15\n2 14\n2 3\n1 17\n1 2\n1 5\n2 18\n1 13\n",
"1 250 0\n",
"2 2 1\n1 1\n",
"2 20 10\n1 7\n2 9\n2 16\n1 4\n1 8\n1 19\n1 20\n1 9\n2 5\n2 6\n",
"20 10 0\n",
"20 20 20\n10 13\n12 13\n14 13\n20 13\n18 13\n3 13\n19 13\n2 13\n13 13\n5 13\n9 13\n6 13\n16 13\n1 13\n17 13\n11 13\n15 13\n7 13\n4 13\n8 13\n",
"10 20 19\n8 20\n9 20\n9 19\n10 19\n10 18\n7 18\n8 17\n6 17\n7 16\n5 16\n6 15\n4 15\n5 14\n3 14\n4 13\n2 13\n3 12\n1 12\n2 11\n",
"2 2 2\n2 1\n2 2\n"
],
"output": [
"19\n",
"38\n",
"1\n",
"19997\n",
"24\n",
"17\n",
"9\n",
"172\n",
"4\n",
"399999\n",
"1\n",
"37\n",
"0\n",
"1\n",
"0\n",
"19999\n",
"200000\n",
"0\n",
"1\n",
"0\n",
"10\n",
"0\n",
"0\n",
"399998\n",
"2\n",
"199\n",
"117\n",
"0\n",
"173\n",
"200000\n",
"0\n",
"39\n",
"314\n",
"19\n",
"20\n",
"0\n",
"2\n",
"250\n",
"9\n",
"10000\n",
"1\n",
"1\n",
"2\n",
"29\n",
"0\n",
"499\n",
"1\n",
"20\n",
"0\n",
"2\n",
"0\n",
"2\n",
"10\n",
"0\n",
"2\n",
"118\n",
"0\n",
"1\n",
"20\n",
"498\n",
"4\n",
"3\n",
"10000\n",
"1\n",
"19\n",
"11\n",
"21\n",
"0\n",
"250\n",
"2\n",
"11\n",
"29\n",
"19\n",
"10\n",
"1\n"
]
} | 1,900 | 1,250 |
2 | 8 | 1037_B. Reach Median | You are given an array a of n integers and an integer s. It is guaranteed that n is odd.
In one operation you can either increase or decrease any single element by one. Calculate the minimum number of operations required to make the median of the array being equal to s.
The median of the array with odd length is the value of the element which is located on the middle position after the array is sorted. For example, the median of the array 6, 5, 8 is equal to 6, since if we sort this array we will get 5, 6, 8, and 6 is located on the middle position.
Input
The first line contains two integers n and s (1β€ nβ€ 2β
10^5-1, 1β€ sβ€ 10^9) β the length of the array and the required value of median.
The second line contains n integers a_1, a_2, β¦, a_n (1β€ a_i β€ 10^9) β the elements of the array a.
It is guaranteed that n is odd.
Output
In a single line output the minimum number of operations to make the median being equal to s.
Examples
Input
3 8
6 5 8
Output
2
Input
7 20
21 15 12 11 20 19 12
Output
6
Note
In the first sample, 6 can be increased twice. The array will transform to 8, 5, 8, which becomes 5, 8, 8 after sorting, hence the median is equal to 8.
In the second sample, 19 can be increased once and 15 can be increased five times. The array will become equal to 21, 20, 12, 11, 20, 20, 12. If we sort this array we get 11, 12, 12, 20, 20, 20, 21, this way the median is 20. | {
"input": [
"3 8\n6 5 8\n",
"7 20\n21 15 12 11 20 19 12\n"
],
"output": [
"2\n",
"6\n"
]
} | {
"input": [
"3 1\n1 2 5\n",
"1 1\n100000\n",
"5 1\n2 2 4 6 1\n",
"3 10\n5 5 10\n",
"1 1\n1\n",
"3 4\n1 2 5\n",
"1 100\n88\n",
"1 100\n105\n"
],
"output": [
"1\n",
"99999\n",
"2\n",
"5\n",
"0\n",
"2\n",
"12\n",
"5\n"
]
} | 1,300 | 750 |
2 | 9 | 105_C. Item World | Each item in the game has a level. The higher the level is, the higher basic parameters the item has. We shall consider only the following basic parameters: attack (atk), defense (def) and resistance to different types of impact (res).
Each item belongs to one class. In this problem we will only consider three of such classes: weapon, armor, orb.
Besides, there's a whole new world hidden inside each item. We can increase an item's level travelling to its world. We can also capture the so-called residents in the Item World
Residents are the creatures that live inside items. Each resident gives some bonus to the item in which it is currently located. We will only consider residents of types: gladiator (who improves the item's atk), sentry (who improves def) and physician (who improves res).
Each item has the size parameter. The parameter limits the maximum number of residents that can live inside an item. We can move residents between items. Within one moment of time we can take some resident from an item and move it to some other item if it has a free place for a new resident. We cannot remove a resident from the items and leave outside β any of them should be inside of some item at any moment of time.
Laharl has a certain number of items. He wants to move the residents between items so as to equip himself with weapon, armor and a defensive orb. The weapon's atk should be largest possible in the end. Among all equipping patterns containing weapon's maximum atk parameter we should choose the ones where the armorβs def parameter is the largest possible. Among all such equipment patterns we should choose the one where the defensive orb would have the largest possible res parameter. Values of the parameters def and res of weapon, atk and res of armor and atk and def of orb are indifferent for Laharl.
Find the optimal equipment pattern Laharl can get.
Input
The first line contains number n (3 β€ n β€ 100) β representing how many items Laharl has.
Then follow n lines. Each line contains description of an item. The description has the following form: "name class atk def res size" β the item's name, class, basic attack, defense and resistance parameters and its size correspondingly.
* name and class are strings and atk, def, res and size are integers.
* name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive.
* class can be "weapon", "armor" or "orb".
* 0 β€ atk, def, res β€ 1000.
* 1 β€ size β€ 10.
It is guaranteed that Laharl has at least one item of each class.
The next line contains an integer k (1 β€ k β€ 1000) β the number of residents.
Then k lines follow. Each of them describes a resident. A resident description looks like: "name type bonus home" β the resident's name, his type, the number of points the resident adds to the item's corresponding parameter and the name of the item which currently contains the resident.
* name, type and home are strings and bonus is an integer.
* name consists of lowercase Latin letters and its length can range from 1 to 10, inclusive.
* type may be "gladiator", "sentry" or "physician".
* 1 β€ bonus β€ 100.
It is guaranteed that the number of residents in each item does not exceed the item's size.
The names of all items and residents are pairwise different.
All words and numbers in the input are separated by single spaces.
Output
Print on the first line the name of the weapon in the optimal equipping pattern; then print the number of residents the weapon contains; then print the residents' names.
Print on the second and third lines in the same form the names of the armor and defensive orb as well as the residents they contain.
Use single spaces for separation.
If there are several possible solutions, print any of them.
Examples
Input
4
sword weapon 10 2 3 2
pagstarmor armor 0 15 3 1
iceorb orb 3 2 13 2
longbow weapon 9 1 2 1
5
mike gladiator 5 longbow
bobby sentry 6 pagstarmor
petr gladiator 7 iceorb
teddy physician 6 sword
blackjack sentry 8 sword
Output
sword 2 petr mike
pagstarmor 1 blackjack
iceorb 2 teddy bobby
Input
4
sword weapon 10 2 3 2
pagstarmor armor 0 15 3 1
iceorb orb 3 2 13 2
longbow weapon 9 1 2 1
6
mike gladiator 5 longbow
bobby sentry 6 pagstarmor
petr gladiator 7 iceorb
teddy physician 6 sword
blackjack sentry 8 sword
joe physician 6 iceorb
Output
longbow 1 mike
pagstarmor 1 bobby
iceorb 2 petr joe
Note
In the second sample we have no free space inside the items, therefore we cannot move the residents between them. | {
"input": [
"4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n6\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\njoe physician 6 iceorb\n",
"4\nsword weapon 10 2 3 2\npagstarmor armor 0 15 3 1\niceorb orb 3 2 13 2\nlongbow weapon 9 1 2 1\n5\nmike gladiator 5 longbow\nbobby sentry 6 pagstarmor\npetr gladiator 7 iceorb\nteddy physician 6 sword\nblackjack sentry 8 sword\n"
],
"output": [
"longbow 1 mike\npagstarmor 1 bobby\niceorb 2 petr joe\n",
"sword 2 petr mike \npagstarmor 1 blackjack \niceorb 2 teddy bobby \n"
]
} | {
"input": [
"6\nc armor 0 13 0 3\na weapon 23 0 0 3\nb weapon 20 0 0 4\ne orb 0 0 13 3\nd armor 0 15 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 a\nh gladiator 3 f\ng gladiator 4 e\ni gladiator 7 a\nk gladiator 1 b\n",
"6\nc armor 0 13 0 3\na weapon 23 0 0 3\nb weapon 10 0 0 4\ne orb 0 0 19 3\nd armor 0 15 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 e\nh gladiator 5 f\ng gladiator 4 c\ni gladiator 7 b\nk gladiator 1 d\n",
"4\nsword weapon 0 0 0 2\npagstarmor armor 0 0 0 1\niceorb orb 0 0 0 2\nlongbow weapon 0 0 0 1\n1\nteddy physician 1 iceorb\n",
"5\npixiebow weapon 10 0 7 2\nlance weapon 12 4 2 1\nbushido armor 0 14 1 4\nstarorb orb 2 3 16 3\nmoonorb orb 3 4 8 1\n11\nste gladiator 10 moonorb\nphi gladiator 8 starorb\nhjk gladiator 5 starorb\npoi gladiator 7 starorb\njor gladiator 4 lance\npui gladiator 6 bushido\nzea gladiator 1 bushido\nqwe gladiator 2 pixiebow\nkkk physician 20 bushido\nlkh sentry 4 pixiebow\noop sentry 8 bushido\n",
"5\naxgovq orb 75 830 793 3\nzeckskde weapon 316 351 917 2\nnrtbk armor 540 178 332 2\nnhjodogdd armor 880 453 186 2\ndxrgvjhvhg weapon 961 616 561 3\n7\nzvi gladiator 16 axgovq\nrq gladiator 52 axgovq\njlr physician 69 zeckskde\njackbeadx sentry 90 zeckskde\nvuhpq gladiator 23 nrtbk\nvfhyjtps physician 88 nhjodogdd\nrb gladiator 90 nhjodogdd\n",
"3\nhcyc weapon 646 755 45 5\nhfh armor 556 875 434 6\njkob orb 654 0 65 7\n1\njhcytccc sentry 76 jkob\n",
"5\npixiebow weapon 10 0 7 2\nlance weapon 12 4 2 1\nbushido armor 0 14 1 4\nstarorb orb 2 3 16 3\nmoonorb orb 3 4 8 1\n8\nste gladiator 10 moonorb\nphi gladiator 8 starorb\nhjk gladiator 5 starorb\npoi gladiator 7 starorb\njor gladiator 4 lance\npui gladiator 6 bushido\nzea gladiator 1 bushido\nqwe gladiator 2 pixiebow\n",
"5\nhs orb 830 875 879 3\nfudflb weapon 13 854 317 1\nwwvhixixe armor 500 285 382 2\nh orb 58 57 409 2\ny weapon 734 408 297 4\n12\nwvxwgjoera physician 55 hs\nusukedr sentry 41 hs\niu physician 100 hs\ngixlx gladiator 42 fudflb\nrd sentry 95 wwvhixixe\nbaff sentry 6 wwvhixixe\nwkhxoubhy sentry 73 h\niat physician 3 h\nc sentry 24 y\noveuaziss gladiator 54 y\nbyfhpjezzv sentry 18 y\njxnpuofle gladiator 65 y\n",
"3\nweapon weapon 10 5 2 4\narmor armor 0 20 0 6\norb orb 3 4 25 3\n3\nx gladiator 12 armor\ny sentry 13 orb\nz physician 5 weapon\n",
"5\nxx weapon 15 0 0 2\nyy armor 0 14 0 2\nzz orb 0 0 16 2\npp weapon 1 0 0 5\nqq armor 0 1 0 4\n9\na gladiator 2 pp\nb gladiator 3 pp\nc gladiator 4 pp\nd sentry 1 pp\ne sentry 2 pp\nf sentry 3 qq\ng physician 2 qq\nh physician 3 qq\ni physician 3 qq\n",
"6\nc armor 0 14 0 3\na weapon 23 0 0 3\nb weapon 21 0 0 4\ne orb 0 0 13 3\nd armor 0 5 0 4\nf orb 0 0 17 5\n5\nj gladiator 7 f\nh gladiator 5 a\ng gladiator 6 c\ni gladiator 7 d\nk gladiator 1 d\n"
],
"output": [
"a 3 j i g \nd 2 h k \nf 0 \n",
"a 3 j i h \nd 2 g k \ne 0 \n",
"sword 0 \npagstarmor 0 \niceorb 1 teddy \n",
"lance 1 jor\nbushido 4 pui zea kkk oop\nstarorb 3 phi hjk poi\n",
"dxrgvjhvhg 3 rb rq vuhpq \nnhjodogdd 2 jackbeadx zvi \naxgovq 2 vfhyjtps jlr \n",
"hcyc 0\nhfh 1 jhcytccc\njkob 0\n",
"pixiebow 2 ste phi\nbushido 4 poi pui hjk jor\nstarorb 2 qwe zea\n",
"y 4 c oveuaziss byfhpjezzv jxnpuofle\nwwvhixixe 2 rd baff\nhs 3 wvxwgjoera usukedr iu\n",
"weapon 1 x\narmor 1 y\norb 1 z\n",
"xx 2 c b\nyy 2 f e\nzz 2 h i\n",
"b 4 j i g h \nc 1 k \nf 0 \n"
]
} | 2,200 | 1,500 |
2 | 10 | 1081_D. Maximum Distance | Chouti was tired of the tedious homework, so he opened up an old programming problem he created years ago.
You are given a connected undirected graph with n vertices and m weighted edges. There are k special vertices: x_1, x_2, β¦, x_k.
Let's define the cost of the path as the maximum weight of the edges in it. And the distance between two vertexes as the minimum cost of the paths connecting them.
For each special vertex, find another special vertex which is farthest from it (in terms of the previous paragraph, i.e. the corresponding distance is maximum possible) and output the distance between them.
The original constraints are really small so he thought the problem was boring. Now, he raises the constraints and hopes you can solve it for him.
Input
The first line contains three integers n, m and k (2 β€ k β€ n β€ 10^5, n-1 β€ m β€ 10^5) β the number of vertices, the number of edges and the number of special vertices.
The second line contains k distinct integers x_1, x_2, β¦, x_k (1 β€ x_i β€ n).
Each of the following m lines contains three integers u, v and w (1 β€ u,v β€ n, 1 β€ w β€ 10^9), denoting there is an edge between u and v of weight w. The given graph is undirected, so an edge (u, v) can be used in the both directions.
The graph may have multiple edges and self-loops.
It is guaranteed, that the graph is connected.
Output
The first and only line should contain k integers. The i-th integer is the distance between x_i and the farthest special vertex from it.
Examples
Input
2 3 2
2 1
1 2 3
1 2 2
2 2 1
Output
2 2
Input
4 5 3
1 2 3
1 2 5
4 2 1
2 3 2
1 4 4
1 3 3
Output
3 3 3
Note
In the first example, the distance between vertex 1 and 2 equals to 2 because one can walk through the edge of weight 2 connecting them. So the distance to the farthest node for both 1 and 2 equals to 2.
In the second example, one can find that distance between 1 and 2, distance between 1 and 3 are both 3 and the distance between 2 and 3 is 2.
The graph may have multiple edges between and self-loops, as in the first example. | {
"input": [
"4 5 3\n1 2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"2 3 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n"
],
"output": [
"3 3 3 ",
"2 2 "
]
} | {
"input": [
"4 4 3\n1 2 3\n1 2 1\n2 3 2\n1 3 3\n1 4 4\n",
"4 3 2\n1 4\n1 2 1\n2 3 5\n3 4 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 47\n",
"3 2 2\n1 2\n1 2 1\n2 3 1000\n",
"3 2 2\n1 2\n1 2 10\n2 3 100\n",
"3 3 2\n2 3\n1 2 100\n1 3 100\n2 3 1\n",
"3 2 2\n1 2\n1 2 2\n2 3 3\n",
"6 5 3\n1 2 4\n1 3 3\n3 2 2\n2 4 1\n3 5 4\n5 6 10\n",
"3 2 2\n2 3\n1 2 10\n2 3 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 4\n",
"6 5 2\n1 6\n1 2 1\n2 3 2\n3 4 3\n4 5 2\n5 6 1\n",
"5 4 2\n4 5\n1 2 100\n2 3 100\n3 4 10\n3 5 20\n",
"4 3 3\n1 2 3\n1 2 5\n1 3 4\n1 4 5\n",
"4 4 3\n1 2 3\n1 2 1\n1 3 2\n2 3 3\n3 4 5\n",
"2 2 2\n1 2\n1 2 3\n1 2 5\n",
"3 2 2\n1 2\n1 2 1\n2 3 100\n",
"3 3 2\n1 2\n1 2 1\n2 3 4\n1 3 5\n",
"3 2 2\n2 3\n1 2 3\n2 3 1\n",
"5 4 2\n4 5\n1 2 10\n2 3 10\n3 4 1\n4 5 1\n",
"4 3 2\n1 4\n1 2 4\n2 3 6\n3 4 4\n",
"4 3 2\n1 2\n1 2 1\n2 3 23\n3 4 1231\n",
"3 2 2\n1 2\n1 2 3\n2 3 5\n",
"5 4 2\n1 5\n1 2 1\n1 3 2\n2 4 5\n3 5 3\n",
"3 4 2\n2 1\n1 2 3\n1 2 2\n2 2 1\n1 3 99\n",
"4 3 2\n1 2\n1 2 1\n2 3 123\n3 4 12321\n",
"4 3 3\n1 2 3\n1 2 6\n1 3 7\n1 4 10\n",
"4 5 2\n2 3\n1 2 5\n4 2 1\n2 3 2\n1 4 4\n1 3 3\n",
"3 2 2\n1 2\n1 2 1\n2 3 5\n",
"3 2 2\n1 2\n1 2 1\n2 3 2\n",
"3 2 2\n1 2\n3 2 10\n2 1 1\n",
"4 3 2\n3 4\n1 2 2\n1 3 4\n3 4 1\n",
"3 2 2\n1 3\n1 2 1\n2 3 1\n",
"5 5 2\n1 2\n1 2 1\n2 3 2\n3 4 2\n4 5 2\n5 1 2\n",
"5 4 3\n1 2 4\n1 2 10\n2 3 100\n2 4 20\n5 3 1000\n",
"4 3 2\n3 4\n1 2 9\n2 3 6\n3 4 1\n",
"3 2 2\n1 2\n1 2 10\n3 2 20\n",
"5 4 2\n4 5\n1 2 100\n2 3 100\n3 4 100\n4 5 1\n",
"3 2 2\n3 2\n1 2 233\n2 3 3\n",
"4 3 2\n1 4\n1 2 1\n2 3 3\n3 4 1\n",
"2 1 2\n1 2\n1 2 1000000000\n",
"5 7 4\n1 2 3 4\n1 2 3\n5 1 4\n3 1 1\n4 2 5\n2 5 6\n2 3 3\n3 4 6\n",
"4 3 2\n1 2\n1 2 1\n2 3 2\n3 4 1\n",
"3 2 2\n2 3\n1 2 1000\n2 3 1\n",
"4 3 2\n3 4\n1 2 10000\n2 3 10000\n3 4 1\n",
"7 6 2\n6 7\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n5 6 1\n6 7 1\n",
"3 2 2\n2 3\n1 2 100\n2 3 1\n",
"4 3 2\n1 2\n1 2 1\n2 3 12\n3 4 123123\n",
"3 2 2\n2 1\n1 2 1\n2 3 100\n",
"3 2 2\n2 3\n1 2 2\n2 3 1\n",
"3 2 2\n2 3\n1 2 7\n2 3 1\n",
"3 2 2\n1 2\n1 2 1\n2 3 3\n",
"3 2 2\n1 2\n1 2 10\n2 3 15\n",
"4 3 2\n1 4\n1 2 3\n2 3 4\n3 4 3\n",
"6 5 4\n1 2 3 4\n1 2 1\n2 3 1\n3 4 1\n4 5 1\n5 6 10\n",
"4 3 2\n2 3\n1 2 1000\n2 3 1\n3 4 1000\n",
"4 3 2\n1 2\n1 2 1\n2 3 1000\n3 4 1000\n",
"3 3 2\n1 2\n1 2 1\n1 3 1000\n2 3 1000\n",
"3 2 2\n1 2\n1 2 3\n1 3 5\n",
"4 4 2\n3 4\n1 2 1000000000\n2 3 1000000000\n3 1 1000000000\n3 4 1\n",
"4 3 2\n3 4\n1 2 5\n2 3 3\n2 4 4\n",
"3 2 2\n1 2\n1 2 3\n2 3 100\n",
"3 2 2\n2 3\n1 2 5\n2 3 1\n",
"5 4 2\n4 5\n1 2 10\n2 3 10\n3 4 1\n3 5 1\n",
"4 3 2\n2 3\n1 2 100\n2 3 1\n3 4 100\n",
"4 3 3\n1 2 3\n1 2 1\n3 1 2\n4 3 3\n",
"4 3 2\n3 4\n1 2 100\n2 3 2\n2 4 2\n"
],
"output": [
"2 2 2 ",
"5 5 ",
"1 1 ",
"1 1 ",
"10 10 ",
"1 1 ",
"2 2 ",
"3 3 3 ",
"1 1 ",
"1 1 ",
"3 3 ",
"20 20 ",
"5 5 5 ",
"2 2 2 ",
"3 3 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"6 6 ",
"1 1 ",
"3 3 ",
"3 3 ",
"2 2 ",
"1 1 ",
"7 7 7 ",
"2 2 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"20 20 20 ",
"1 1 ",
"10 10 ",
"1 1 ",
"3 3 ",
"3 3 ",
"1000000000 1000000000 ",
"5 5 5 5 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"10 10 ",
"4 4 ",
"1 1 1 1 ",
"1 1 ",
"1 1 ",
"1 1 ",
"3 3 ",
"1 1 ",
"4 4 ",
"3 3 ",
"1 1 ",
"1 1 ",
"1 1 ",
"2 2 2 ",
"2 2 "
]
} | 1,800 | 2,000 |
2 | 7 | 1129_A2. Toy Train | Alice received a set of Toy Trainβ’ from Bob. It consists of one train and a connected railway network of n stations, enumerated from 1 through n. The train occupies one station at a time and travels around the network of stations in a circular manner. More precisely, the immediate station that the train will visit after station i is station i+1 if 1 β€ i < n or station 1 if i = n. It takes the train 1 second to travel to its next station as described.
Bob gave Alice a fun task before he left: to deliver m candies that are initially at some stations to their independent destinations using the train. The candies are enumerated from 1 through m. Candy i (1 β€ i β€ m), now at station a_i, should be delivered to station b_i (a_i β b_i).
<image> The blue numbers on the candies correspond to b_i values. The image corresponds to the 1-st example.
The train has infinite capacity, and it is possible to load off any number of candies at a station. However, only at most one candy can be loaded from a station onto the train before it leaves the station. You can choose any candy at this station. The time it takes to move the candies is negligible.
Now, Alice wonders how much time is needed for the train to deliver all candies. Your task is to find, for each station, the minimum time the train would need to deliver all the candies were it to start from there.
Input
The first line contains two space-separated integers n and m (2 β€ n β€ 5 000; 1 β€ m β€ 20 000) β the number of stations and the number of candies, respectively.
The i-th of the following m lines contains two space-separated integers a_i and b_i (1 β€ a_i, b_i β€ n; a_i β b_i) β the station that initially contains candy i and the destination station of the candy, respectively.
Output
In the first and only line, print n space-separated integers, the i-th of which is the minimum time, in seconds, the train would need to deliver all the candies were it to start from station i.
Examples
Input
5 7
2 4
5 1
2 3
3 4
4 1
5 3
3 5
Output
10 9 10 10 9
Input
2 3
1 2
1 2
1 2
Output
5 6
Note
Consider the second sample.
If the train started at station 1, the optimal strategy is as follows.
1. Load the first candy onto the train.
2. Proceed to station 2. This step takes 1 second.
3. Deliver the first candy.
4. Proceed to station 1. This step takes 1 second.
5. Load the second candy onto the train.
6. Proceed to station 2. This step takes 1 second.
7. Deliver the second candy.
8. Proceed to station 1. This step takes 1 second.
9. Load the third candy onto the train.
10. Proceed to station 2. This step takes 1 second.
11. Deliver the third candy.
Hence, the train needs 5 seconds to complete the tasks.
If the train were to start at station 2, however, it would need to move to station 1 before it could load the first candy, which would take one additional second. Thus, the answer in this scenario is 5+1 = 6 seconds. | {
"input": [
"2 3\n1 2\n1 2\n1 2\n",
"5 7\n2 4\n5 1\n2 3\n3 4\n4 1\n5 3\n3 5\n"
],
"output": [
"5 6 ",
"10 9 10 10 9 "
]
} | {
"input": [
"5 1\n3 2\n",
"3 3\n1 2\n1 2\n1 2\n",
"5 3\n2 4\n5 4\n3 2\n",
"20 5\n3 12\n5 20\n16 4\n13 3\n9 14\n",
"3 2\n3 1\n1 3\n",
"3 1\n3 1\n",
"3 2\n1 3\n2 1\n",
"50 20\n4 18\n39 33\n49 32\n7 32\n38 1\n46 11\n8 1\n3 31\n30 47\n24 16\n33 5\n5 21\n3 48\n13 23\n49 50\n18 47\n40 32\n9 23\n19 39\n25 12\n",
"100 50\n29 35\n10 75\n29 34\n10 87\n29 13\n29 38\n41 21\n10 6\n29 94\n10 47\n31 27\n41 24\n41 8\n10 93\n41 52\n41 36\n31 32\n85 81\n31 32\n41 79\n41 99\n85 88\n41 25\n31 68\n41 93\n10 87\n85 97\n41 85\n10 64\n10 68\n85 22\n10 45\n85 15\n10 16\n10 21\n41 66\n29 68\n41 96\n29 34\n10 22\n41 72\n85 54\n29 48\n10 100\n29 91\n41 43\n85 59\n85 10\n31 90\n41 64\n",
"10 8\n5 2\n6 5\n3 8\n9 10\n4 3\n9 5\n2 6\n9 10\n",
"5000 1\n4008 1126\n",
"3 1\n1 2\n",
"50 20\n45 33\n44 7\n31 41\n45 12\n3 13\n18 17\n3 39\n31 11\n31 1\n44 7\n44 23\n18 46\n44 1\n45 6\n31 22\n18 13\n31 22\n45 8\n45 17\n18 43\n",
"10 13\n9 5\n10 4\n9 5\n8 7\n10 2\n9 1\n9 1\n10 8\n9 1\n5 7\n9 3\n3 7\n6 5\n",
"10 4\n8 6\n1 7\n6 1\n5 1\n",
"10 3\n3 4\n1 3\n5 2\n",
"10 20\n6 10\n2 3\n10 7\n8 10\n4 7\n6 2\n7 10\n7 4\n10 3\n9 3\n4 8\n1 7\n2 10\n6 9\n3 6\n6 3\n10 2\n10 7\n10 5\n4 5\n",
"10 2\n9 2\n10 8\n",
"3 2\n2 1\n2 3\n",
"10 3\n7 9\n3 2\n7 1\n",
"100 1\n7 75\n",
"3 3\n1 2\n3 2\n2 3\n",
"10 6\n6 8\n4 5\n1 9\n1 6\n7 5\n8 3\n",
"100 50\n55 68\n94 68\n39 6\n45 32\n59 20\n72 53\n41 25\n63 32\n78 18\n79 97\n17 1\n72 64\n85 89\n26 25\n82 29\n15 1\n8 18\n28 3\n33 61\n87 25\n90 62\n86 60\n90 66\n55 10\n16 21\n23 97\n38 100\n64 66\n63 83\n99 97\n97 43\n88 21\n79 32\n47 36\n83 26\n71 52\n76 75\n80 1\n48 26\n65 87\n73 12\n73 21\n46 15\n5 32\n77 8\n91 90\n39 29\n41 70\n36 52\n80 88\n",
"3 2\n3 2\n1 2\n",
"10 10\n6 5\n1 10\n6 5\n10 9\n5 4\n7 6\n5 4\n6 5\n1 10\n1 10\n",
"10 11\n10 1\n7 6\n6 5\n2 9\n1 8\n10 8\n8 10\n7 2\n1 6\n1 5\n4 5\n",
"3 1\n3 2\n",
"10 10\n6 1\n6 10\n5 7\n5 6\n9 3\n2 1\n4 10\n6 7\n4 1\n1 5\n",
"5 3\n1 2\n4 3\n1 5\n",
"3 3\n2 1\n1 2\n1 3\n"
],
"output": [
"6 5 4 8 7 ",
"7 9 8 ",
"8 7 6 8 7 ",
"23 22 21 28 27 34 33 32 31 30 29 28 27 29 28 27 27 26 25 24 ",
"3 4 3 ",
"3 2 1 ",
"3 4 4 ",
"99 98 97 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 93 92 91 90 89 88 87 86 85 84 100 ",
"1442 1441 1440 1439 1438 1437 1436 1435 1434 1433 1432 1431 1430 1429 1428 1427 1426 1425 1424 1423 1422 1421 1420 1419 1418 1417 1416 1415 1414 1413 1412 1411 1410 1409 1408 1407 1406 1405 1404 1403 1402 1501 1500 1499 1498 1497 1496 1495 1494 1493 1492 1491 1490 1489 1488 1487 1486 1485 1484 1483 1482 1481 1480 1479 1478 1477 1476 1475 1474 1473 1472 1471 1470 1469 1468 1467 1466 1465 1464 1463 1462 1461 1460 1459 1458 1457 1456 1455 1454 1453 1452 1451 1450 1449 1448 1447 1446 1445 1444 1443 ",
"29 28 27 26 25 24 23 22 21 30 ",
"6125 6124 6123 6122 6121 6120 6119 6118 6117 6116 6115 6114 6113 6112 6111 6110 6109 6108 6107 6106 6105 6104 6103 6102 6101 6100 6099 6098 6097 6096 6095 6094 6093 6092 6091 6090 6089 6088 6087 6086 6085 6084 6083 6082 6081 6080 6079 6078 6077 6076 6075 6074 6073 6072 6071 6070 6069 6068 6067 6066 6065 6064 6063 6062 6061 6060 6059 6058 6057 6056 6055 6054 6053 6052 6051 6050 6049 6048 6047 6046 6045 6044 6043 6042 6041 6040 6039 6038 6037 6036 6035 6034 6033 6032 6031 6030 6029 6028 6027 6026 6025 6024 6023 6022 6021 6020 6019 6018 6017 6016 6015 6014 6013 6012 6011 6010 6009 6008 6007 6006 6005 6004 6003 6002 6001 6000 5999 5998 5997 5996 5995 5994 5993 5992 5991 5990 5989 5988 5987 5986 5985 5984 5983 5982 5981 5980 5979 5978 5977 5976 5975 5974 5973 5972 5971 5970 5969 5968 5967 5966 5965 5964 5963 5962 5961 5960 5959 5958 5957 5956 5955 5954 5953 5952 5951 5950 5949 5948 5947 5946 5945 5944 5943 5942 5941 5940 5939 5938 5937 5936 5935 5934 5933 5932 5931 5930 5929 5928 5927 5926 5925 5924 5923 5922 5921 5920 5919 5918 5917 5916 5915 5914 5913 5912 5911 5910 5909 5908 5907 5906 5905 5904 5903 5902 5901 5900 5899 5898 5897 5896 5895 5894 5893 5892 5891 5890 5889 5888 5887 5886 5885 5884 5883 5882 5881 5880 5879 5878 5877 5876 5875 5874 5873 5872 5871 5870 5869 5868 5867 5866 5865 5864 5863 5862 5861 5860 5859 5858 5857 5856 5855 5854 5853 5852 5851 5850 5849 5848 5847 5846 5845 5844 5843 5842 5841 5840 5839 5838 5837 5836 5835 5834 5833 5832 5831 5830 5829 5828 5827 5826 5825 5824 5823 5822 5821 5820 5819 5818 5817 5816 5815 5814 5813 5812 5811 5810 5809 5808 5807 5806 5805 5804 5803 5802 5801 5800 5799 5798 5797 5796 5795 5794 5793 5792 5791 5790 5789 5788 5787 5786 5785 5784 5783 5782 5781 5780 5779 5778 5777 5776 5775 5774 5773 5772 5771 5770 5769 5768 5767 5766 5765 5764 5763 5762 5761 5760 5759 5758 5757 5756 5755 5754 5753 5752 5751 5750 5749 5748 5747 5746 5745 5744 5743 5742 5741 5740 5739 5738 5737 5736 5735 5734 5733 5732 5731 5730 5729 5728 5727 5726 5725 5724 5723 5722 5721 5720 5719 5718 5717 5716 5715 5714 5713 5712 5711 5710 5709 5708 5707 5706 5705 5704 5703 5702 5701 5700 5699 5698 5697 5696 5695 5694 5693 5692 5691 5690 5689 5688 5687 5686 5685 5684 5683 5682 5681 5680 5679 5678 5677 5676 5675 5674 5673 5672 5671 5670 5669 5668 5667 5666 5665 5664 5663 5662 5661 5660 5659 5658 5657 5656 5655 5654 5653 5652 5651 5650 5649 5648 5647 5646 5645 5644 5643 5642 5641 5640 5639 5638 5637 5636 5635 5634 5633 5632 5631 5630 5629 5628 5627 5626 5625 5624 5623 5622 5621 5620 5619 5618 5617 5616 5615 5614 5613 5612 5611 5610 5609 5608 5607 5606 5605 5604 5603 5602 5601 5600 5599 5598 5597 5596 5595 5594 5593 5592 5591 5590 5589 5588 5587 5586 5585 5584 5583 5582 5581 5580 5579 5578 5577 5576 5575 5574 5573 5572 5571 5570 5569 5568 5567 5566 5565 5564 5563 5562 5561 5560 5559 5558 5557 5556 5555 5554 5553 5552 5551 5550 5549 5548 5547 5546 5545 5544 5543 5542 5541 5540 5539 5538 5537 5536 5535 5534 5533 5532 5531 5530 5529 5528 5527 5526 5525 5524 5523 5522 5521 5520 5519 5518 5517 5516 5515 5514 5513 5512 5511 5510 5509 5508 5507 5506 5505 5504 5503 5502 5501 5500 5499 5498 5497 5496 5495 5494 5493 5492 5491 5490 5489 5488 5487 5486 5485 5484 5483 5482 5481 5480 5479 5478 5477 5476 5475 5474 5473 5472 5471 5470 5469 5468 5467 5466 5465 5464 5463 5462 5461 5460 5459 5458 5457 5456 5455 5454 5453 5452 5451 5450 5449 5448 5447 5446 5445 5444 5443 5442 5441 5440 5439 5438 5437 5436 5435 5434 5433 5432 5431 5430 5429 5428 5427 5426 5425 5424 5423 5422 5421 5420 5419 5418 5417 5416 5415 5414 5413 5412 5411 5410 5409 5408 5407 5406 5405 5404 5403 5402 5401 5400 5399 5398 5397 5396 5395 5394 5393 5392 5391 5390 5389 5388 5387 5386 5385 5384 5383 5382 5381 5380 5379 5378 5377 5376 5375 5374 5373 5372 5371 5370 5369 5368 5367 5366 5365 5364 5363 5362 5361 5360 5359 5358 5357 5356 5355 5354 5353 5352 5351 5350 5349 5348 5347 5346 5345 5344 5343 5342 5341 5340 5339 5338 5337 5336 5335 5334 5333 5332 5331 5330 5329 5328 5327 5326 5325 5324 5323 5322 5321 5320 5319 5318 5317 5316 5315 5314 5313 5312 5311 5310 5309 5308 5307 5306 5305 5304 5303 5302 5301 5300 5299 5298 5297 5296 5295 5294 5293 5292 5291 5290 5289 5288 5287 5286 5285 5284 5283 5282 5281 5280 5279 5278 5277 5276 5275 5274 5273 5272 5271 5270 5269 5268 5267 5266 5265 5264 5263 5262 5261 5260 5259 5258 5257 5256 5255 5254 5253 5252 5251 5250 5249 5248 5247 5246 5245 5244 5243 5242 5241 5240 5239 5238 5237 5236 5235 5234 5233 5232 5231 5230 5229 5228 5227 5226 5225 5224 5223 5222 5221 5220 5219 5218 5217 5216 5215 5214 5213 5212 5211 5210 5209 5208 5207 5206 5205 5204 5203 5202 5201 5200 5199 5198 5197 5196 5195 5194 5193 5192 5191 5190 5189 5188 5187 5186 5185 5184 5183 5182 5181 5180 5179 5178 5177 5176 5175 5174 5173 5172 5171 5170 5169 5168 5167 5166 5165 5164 5163 5162 5161 5160 5159 5158 5157 5156 5155 5154 5153 5152 5151 5150 5149 5148 5147 5146 5145 5144 5143 5142 5141 5140 5139 5138 5137 5136 5135 5134 5133 5132 5131 5130 5129 5128 5127 5126 5125 5124 5123 5122 5121 5120 5119 5118 5117 5116 5115 5114 5113 5112 5111 5110 5109 5108 5107 5106 5105 5104 5103 5102 5101 5100 5099 5098 5097 5096 5095 5094 5093 5092 5091 5090 5089 5088 5087 5086 5085 5084 5083 5082 5081 5080 5079 5078 5077 5076 5075 5074 5073 5072 5071 5070 5069 5068 5067 5066 5065 5064 5063 5062 5061 5060 5059 5058 5057 5056 5055 5054 5053 5052 5051 5050 5049 5048 5047 5046 5045 5044 5043 5042 5041 5040 5039 5038 5037 5036 5035 5034 5033 5032 5031 5030 5029 5028 5027 5026 5025 5024 5023 5022 5021 5020 5019 5018 5017 5016 5015 5014 5013 5012 5011 5010 5009 5008 5007 5006 5005 5004 5003 5002 5001 5000 4999 4998 4997 4996 4995 4994 4993 4992 4991 4990 4989 4988 4987 4986 4985 4984 4983 4982 4981 4980 4979 4978 4977 4976 4975 4974 4973 4972 4971 4970 4969 4968 4967 4966 4965 4964 4963 4962 4961 4960 4959 4958 4957 4956 4955 4954 4953 4952 4951 4950 4949 4948 4947 4946 4945 4944 4943 4942 4941 4940 4939 4938 4937 4936 4935 4934 4933 4932 4931 4930 4929 4928 4927 4926 4925 4924 4923 4922 4921 4920 4919 4918 4917 4916 4915 4914 4913 4912 4911 4910 4909 4908 4907 4906 4905 4904 4903 4902 4901 4900 4899 4898 4897 4896 4895 4894 4893 4892 4891 4890 4889 4888 4887 4886 4885 4884 4883 4882 4881 4880 4879 4878 4877 4876 4875 4874 4873 4872 4871 4870 4869 4868 4867 4866 4865 4864 4863 4862 4861 4860 4859 4858 4857 4856 4855 4854 4853 4852 4851 4850 4849 4848 4847 4846 4845 4844 4843 4842 4841 4840 4839 4838 4837 4836 4835 4834 4833 4832 4831 4830 4829 4828 4827 4826 4825 4824 4823 4822 4821 4820 4819 4818 4817 4816 4815 4814 4813 4812 4811 4810 4809 4808 4807 4806 4805 4804 4803 4802 4801 4800 4799 4798 4797 4796 4795 4794 4793 4792 4791 4790 4789 4788 4787 4786 4785 4784 4783 4782 4781 4780 4779 4778 4777 4776 4775 4774 4773 4772 4771 4770 4769 4768 4767 4766 4765 4764 4763 4762 4761 4760 4759 4758 4757 4756 4755 4754 4753 4752 4751 4750 4749 4748 4747 4746 4745 4744 4743 4742 4741 4740 4739 4738 4737 4736 4735 4734 4733 4732 4731 4730 4729 4728 4727 4726 4725 4724 4723 4722 4721 4720 4719 4718 4717 4716 4715 4714 4713 4712 4711 4710 4709 4708 4707 4706 4705 4704 4703 4702 4701 4700 4699 4698 4697 4696 4695 4694 4693 4692 4691 4690 4689 4688 4687 4686 4685 4684 4683 4682 4681 4680 4679 4678 4677 4676 4675 4674 4673 4672 4671 4670 4669 4668 4667 4666 4665 4664 4663 4662 4661 4660 4659 4658 4657 4656 4655 4654 4653 4652 4651 4650 4649 4648 4647 4646 4645 4644 4643 4642 4641 4640 4639 4638 4637 4636 4635 4634 4633 4632 4631 4630 4629 4628 4627 4626 4625 4624 4623 4622 4621 4620 4619 4618 4617 4616 4615 4614 4613 4612 4611 4610 4609 4608 4607 4606 4605 4604 4603 4602 4601 4600 4599 4598 4597 4596 4595 4594 4593 4592 4591 4590 4589 4588 4587 4586 4585 4584 4583 4582 4581 4580 4579 4578 4577 4576 4575 4574 4573 4572 4571 4570 4569 4568 4567 4566 4565 4564 4563 4562 4561 4560 4559 4558 4557 4556 4555 4554 4553 4552 4551 4550 4549 4548 4547 4546 4545 4544 4543 4542 4541 4540 4539 4538 4537 4536 4535 4534 4533 4532 4531 4530 4529 4528 4527 4526 4525 4524 4523 4522 4521 4520 4519 4518 4517 4516 4515 4514 4513 4512 4511 4510 4509 4508 4507 4506 4505 4504 4503 4502 4501 4500 4499 4498 4497 4496 4495 4494 4493 4492 4491 4490 4489 4488 4487 4486 4485 4484 4483 4482 4481 4480 4479 4478 4477 4476 4475 4474 4473 4472 4471 4470 4469 4468 4467 4466 4465 4464 4463 4462 4461 4460 4459 4458 4457 4456 4455 4454 4453 4452 4451 4450 4449 4448 4447 4446 4445 4444 4443 4442 4441 4440 4439 4438 4437 4436 4435 4434 4433 4432 4431 4430 4429 4428 4427 4426 4425 4424 4423 4422 4421 4420 4419 4418 4417 4416 4415 4414 4413 4412 4411 4410 4409 4408 4407 4406 4405 4404 4403 4402 4401 4400 4399 4398 4397 4396 4395 4394 4393 4392 4391 4390 4389 4388 4387 4386 4385 4384 4383 4382 4381 4380 4379 4378 4377 4376 4375 4374 4373 4372 4371 4370 4369 4368 4367 4366 4365 4364 4363 4362 4361 4360 4359 4358 4357 4356 4355 4354 4353 4352 4351 4350 4349 4348 4347 4346 4345 4344 4343 4342 4341 4340 4339 4338 4337 4336 4335 4334 4333 4332 4331 4330 4329 4328 4327 4326 4325 4324 4323 4322 4321 4320 4319 4318 4317 4316 4315 4314 4313 4312 4311 4310 4309 4308 4307 4306 4305 4304 4303 4302 4301 4300 4299 4298 4297 4296 4295 4294 4293 4292 4291 4290 4289 4288 4287 4286 4285 4284 4283 4282 4281 4280 4279 4278 4277 4276 4275 4274 4273 4272 4271 4270 4269 4268 4267 4266 4265 4264 4263 4262 4261 4260 4259 4258 4257 4256 4255 4254 4253 4252 4251 4250 4249 4248 4247 4246 4245 4244 4243 4242 4241 4240 4239 4238 4237 4236 4235 4234 4233 4232 4231 4230 4229 4228 4227 4226 4225 4224 4223 4222 4221 4220 4219 4218 4217 4216 4215 4214 4213 4212 4211 4210 4209 4208 4207 4206 4205 4204 4203 4202 4201 4200 4199 4198 4197 4196 4195 4194 4193 4192 4191 4190 4189 4188 4187 4186 4185 4184 4183 4182 4181 4180 4179 4178 4177 4176 4175 4174 4173 4172 4171 4170 4169 4168 4167 4166 4165 4164 4163 4162 4161 4160 4159 4158 4157 4156 4155 4154 4153 4152 4151 4150 4149 4148 4147 4146 4145 4144 4143 4142 4141 4140 4139 4138 4137 4136 4135 4134 4133 4132 4131 4130 4129 4128 4127 4126 4125 4124 4123 4122 4121 4120 4119 4118 4117 4116 4115 4114 4113 4112 4111 4110 4109 4108 4107 4106 4105 4104 4103 4102 4101 4100 4099 4098 4097 4096 4095 4094 4093 4092 4091 4090 4089 4088 4087 4086 4085 4084 4083 4082 4081 4080 4079 4078 4077 4076 4075 4074 4073 4072 4071 4070 4069 4068 4067 4066 4065 4064 4063 4062 4061 4060 4059 4058 4057 4056 4055 4054 4053 4052 4051 4050 4049 4048 4047 4046 4045 4044 4043 4042 4041 4040 4039 4038 4037 4036 4035 4034 4033 4032 4031 4030 4029 4028 4027 4026 4025 4024 4023 4022 4021 4020 4019 4018 4017 4016 4015 4014 4013 4012 4011 4010 4009 4008 4007 4006 4005 4004 4003 4002 4001 4000 3999 3998 3997 3996 3995 3994 3993 3992 3991 3990 3989 3988 3987 3986 3985 3984 3983 3982 3981 3980 3979 3978 3977 3976 3975 3974 3973 3972 3971 3970 3969 3968 3967 3966 3965 3964 3963 3962 3961 3960 3959 3958 3957 3956 3955 3954 3953 3952 3951 3950 3949 3948 3947 3946 3945 3944 3943 3942 3941 3940 3939 3938 3937 3936 3935 3934 3933 3932 3931 3930 3929 3928 3927 3926 3925 3924 3923 3922 3921 3920 3919 3918 3917 3916 3915 3914 3913 3912 3911 3910 3909 3908 3907 3906 3905 3904 3903 3902 3901 3900 3899 3898 3897 3896 3895 3894 3893 3892 3891 3890 3889 3888 3887 3886 3885 3884 3883 3882 3881 3880 3879 3878 3877 3876 3875 3874 3873 3872 3871 3870 3869 3868 3867 3866 3865 3864 3863 3862 3861 3860 3859 3858 3857 3856 3855 3854 3853 3852 3851 3850 3849 3848 3847 3846 3845 3844 3843 3842 3841 3840 3839 3838 3837 3836 3835 3834 3833 3832 3831 3830 3829 3828 3827 3826 3825 3824 3823 3822 3821 3820 3819 3818 3817 3816 3815 3814 3813 3812 3811 3810 3809 3808 3807 3806 3805 3804 3803 3802 3801 3800 3799 3798 3797 3796 3795 3794 3793 3792 3791 3790 3789 3788 3787 3786 3785 3784 3783 3782 3781 3780 3779 3778 3777 3776 3775 3774 3773 3772 3771 3770 3769 3768 3767 3766 3765 3764 3763 3762 3761 3760 3759 3758 3757 3756 3755 3754 3753 3752 3751 3750 3749 3748 3747 3746 3745 3744 3743 3742 3741 3740 3739 3738 3737 3736 3735 3734 3733 3732 3731 3730 3729 3728 3727 3726 3725 3724 3723 3722 3721 3720 3719 3718 3717 3716 3715 3714 3713 3712 3711 3710 3709 3708 3707 3706 3705 3704 3703 3702 3701 3700 3699 3698 3697 3696 3695 3694 3693 3692 3691 3690 3689 3688 3687 3686 3685 3684 3683 3682 3681 3680 3679 3678 3677 3676 3675 3674 3673 3672 3671 3670 3669 3668 3667 3666 3665 3664 3663 3662 3661 3660 3659 3658 3657 3656 3655 3654 3653 3652 3651 3650 3649 3648 3647 3646 3645 3644 3643 3642 3641 3640 3639 3638 3637 3636 3635 3634 3633 3632 3631 3630 3629 3628 3627 3626 3625 3624 3623 3622 3621 3620 3619 3618 3617 3616 3615 3614 3613 3612 3611 3610 3609 3608 3607 3606 3605 3604 3603 3602 3601 3600 3599 3598 3597 3596 3595 3594 3593 3592 3591 3590 3589 3588 3587 3586 3585 3584 3583 3582 3581 3580 3579 3578 3577 3576 3575 3574 3573 3572 3571 3570 3569 3568 3567 3566 3565 3564 3563 3562 3561 3560 3559 3558 3557 3556 3555 3554 3553 3552 3551 3550 3549 3548 3547 3546 3545 3544 3543 3542 3541 3540 3539 3538 3537 3536 3535 3534 3533 3532 3531 3530 3529 3528 3527 3526 3525 3524 3523 3522 3521 3520 3519 3518 3517 3516 3515 3514 3513 3512 3511 3510 3509 3508 3507 3506 3505 3504 3503 3502 3501 3500 3499 3498 3497 3496 3495 3494 3493 3492 3491 3490 3489 3488 3487 3486 3485 3484 3483 3482 3481 3480 3479 3478 3477 3476 3475 3474 3473 3472 3471 3470 3469 3468 3467 3466 3465 3464 3463 3462 3461 3460 3459 3458 3457 3456 3455 3454 3453 3452 3451 3450 3449 3448 3447 3446 3445 3444 3443 3442 3441 3440 3439 3438 3437 3436 3435 3434 3433 3432 3431 3430 3429 3428 3427 3426 3425 3424 3423 3422 3421 3420 3419 3418 3417 3416 3415 3414 3413 3412 3411 3410 3409 3408 3407 3406 3405 3404 3403 3402 3401 3400 3399 3398 3397 3396 3395 3394 3393 3392 3391 3390 3389 3388 3387 3386 3385 3384 3383 3382 3381 3380 3379 3378 3377 3376 3375 3374 3373 3372 3371 3370 3369 3368 3367 3366 3365 3364 3363 3362 3361 3360 3359 3358 3357 3356 3355 3354 3353 3352 3351 3350 3349 3348 3347 3346 3345 3344 3343 3342 3341 3340 3339 3338 3337 3336 3335 3334 3333 3332 3331 3330 3329 3328 3327 3326 3325 3324 3323 3322 3321 3320 3319 3318 3317 3316 3315 3314 3313 3312 3311 3310 3309 3308 3307 3306 3305 3304 3303 3302 3301 3300 3299 3298 3297 3296 3295 3294 3293 3292 3291 3290 3289 3288 3287 3286 3285 3284 3283 3282 3281 3280 3279 3278 3277 3276 3275 3274 3273 3272 3271 3270 3269 3268 3267 3266 3265 3264 3263 3262 3261 3260 3259 3258 3257 3256 3255 3254 3253 3252 3251 3250 3249 3248 3247 3246 3245 3244 3243 3242 3241 3240 3239 3238 3237 3236 3235 3234 3233 3232 3231 3230 3229 3228 3227 3226 3225 3224 3223 3222 3221 3220 3219 3218 3217 3216 3215 3214 3213 3212 3211 3210 3209 3208 3207 3206 3205 3204 3203 3202 3201 3200 3199 3198 3197 3196 3195 3194 3193 3192 3191 3190 3189 3188 3187 3186 3185 3184 3183 3182 3181 3180 3179 3178 3177 3176 3175 3174 3173 3172 3171 3170 3169 3168 3167 3166 3165 3164 3163 3162 3161 3160 3159 3158 3157 3156 3155 3154 3153 3152 3151 3150 3149 3148 3147 3146 3145 3144 3143 3142 3141 3140 3139 3138 3137 3136 3135 3134 3133 3132 3131 3130 3129 3128 3127 3126 3125 3124 3123 3122 3121 3120 3119 3118 3117 3116 3115 3114 3113 3112 3111 3110 3109 3108 3107 3106 3105 3104 3103 3102 3101 3100 3099 3098 3097 3096 3095 3094 3093 3092 3091 3090 3089 3088 3087 3086 3085 3084 3083 3082 3081 3080 3079 3078 3077 3076 3075 3074 3073 3072 3071 3070 3069 3068 3067 3066 3065 3064 3063 3062 3061 3060 3059 3058 3057 3056 3055 3054 3053 3052 3051 3050 3049 3048 3047 3046 3045 3044 3043 3042 3041 3040 3039 3038 3037 3036 3035 3034 3033 3032 3031 3030 3029 3028 3027 3026 3025 3024 3023 3022 3021 3020 3019 3018 3017 3016 3015 3014 3013 3012 3011 3010 3009 3008 3007 3006 3005 3004 3003 3002 3001 3000 2999 2998 2997 2996 2995 2994 2993 2992 2991 2990 2989 2988 2987 2986 2985 2984 2983 2982 2981 2980 2979 2978 2977 2976 2975 2974 2973 2972 2971 2970 2969 2968 2967 2966 2965 2964 2963 2962 2961 2960 2959 2958 2957 2956 2955 2954 2953 2952 2951 2950 2949 2948 2947 2946 2945 2944 2943 2942 2941 2940 2939 2938 2937 2936 2935 2934 2933 2932 2931 2930 2929 2928 2927 2926 2925 2924 2923 2922 2921 2920 2919 2918 2917 2916 2915 2914 2913 2912 2911 2910 2909 2908 2907 2906 2905 2904 2903 2902 2901 2900 2899 2898 2897 2896 2895 2894 2893 2892 2891 2890 2889 2888 2887 2886 2885 2884 2883 2882 2881 2880 2879 2878 2877 2876 2875 2874 2873 2872 2871 2870 2869 2868 2867 2866 2865 2864 2863 2862 2861 2860 2859 2858 2857 2856 2855 2854 2853 2852 2851 2850 2849 2848 2847 2846 2845 2844 2843 2842 2841 2840 2839 2838 2837 2836 2835 2834 2833 2832 2831 2830 2829 2828 2827 2826 2825 2824 2823 2822 2821 2820 2819 2818 2817 2816 2815 2814 2813 2812 2811 2810 2809 2808 2807 2806 2805 2804 2803 2802 2801 2800 2799 2798 2797 2796 2795 2794 2793 2792 2791 2790 2789 2788 2787 2786 2785 2784 2783 2782 2781 2780 2779 2778 2777 2776 2775 2774 2773 2772 2771 2770 2769 2768 2767 2766 2765 2764 2763 2762 2761 2760 2759 2758 2757 2756 2755 2754 2753 2752 2751 2750 2749 2748 2747 2746 2745 2744 2743 2742 2741 2740 2739 2738 2737 2736 2735 2734 2733 2732 2731 2730 2729 2728 2727 2726 2725 2724 2723 2722 2721 2720 2719 2718 2717 2716 2715 2714 2713 2712 2711 2710 2709 2708 2707 2706 2705 2704 2703 2702 2701 2700 2699 2698 2697 2696 2695 2694 2693 2692 2691 2690 2689 2688 2687 2686 2685 2684 2683 2682 2681 2680 2679 2678 2677 2676 2675 2674 2673 2672 2671 2670 2669 2668 2667 2666 2665 2664 2663 2662 2661 2660 2659 2658 2657 2656 2655 2654 2653 2652 2651 2650 2649 2648 2647 2646 2645 2644 2643 2642 2641 2640 2639 2638 2637 2636 2635 2634 2633 2632 2631 2630 2629 2628 2627 2626 2625 2624 2623 2622 2621 2620 2619 2618 2617 2616 2615 2614 2613 2612 2611 2610 2609 2608 2607 2606 2605 2604 2603 2602 2601 2600 2599 2598 2597 2596 2595 2594 2593 2592 2591 2590 2589 2588 2587 2586 2585 2584 2583 2582 2581 2580 2579 2578 2577 2576 2575 2574 2573 2572 2571 2570 2569 2568 2567 2566 2565 2564 2563 2562 2561 2560 2559 2558 2557 2556 2555 2554 2553 2552 2551 2550 2549 2548 2547 2546 2545 2544 2543 2542 2541 2540 2539 2538 2537 2536 2535 2534 2533 2532 2531 2530 2529 2528 2527 2526 2525 2524 2523 2522 2521 2520 2519 2518 2517 2516 2515 2514 2513 2512 2511 2510 2509 2508 2507 2506 2505 2504 2503 2502 2501 2500 2499 2498 2497 2496 2495 2494 2493 2492 2491 2490 2489 2488 2487 2486 2485 2484 2483 2482 2481 2480 2479 2478 2477 2476 2475 2474 2473 2472 2471 2470 2469 2468 2467 2466 2465 2464 2463 2462 2461 2460 2459 2458 2457 2456 2455 2454 2453 2452 2451 2450 2449 2448 2447 2446 2445 2444 2443 2442 2441 2440 2439 2438 2437 2436 2435 2434 2433 2432 2431 2430 2429 2428 2427 2426 2425 2424 2423 2422 2421 2420 2419 2418 2417 2416 2415 2414 2413 2412 2411 2410 2409 2408 2407 2406 2405 2404 2403 2402 2401 2400 2399 2398 2397 2396 2395 2394 2393 2392 2391 2390 2389 2388 2387 2386 2385 2384 2383 2382 2381 2380 2379 2378 2377 2376 2375 2374 2373 2372 2371 2370 2369 2368 2367 2366 2365 2364 2363 2362 2361 2360 2359 2358 2357 2356 2355 2354 2353 2352 2351 2350 2349 2348 2347 2346 2345 2344 2343 2342 2341 2340 2339 2338 2337 2336 2335 2334 2333 2332 2331 2330 2329 2328 2327 2326 2325 2324 2323 2322 2321 2320 2319 2318 2317 2316 2315 2314 2313 2312 2311 2310 2309 2308 2307 2306 2305 2304 2303 2302 2301 2300 2299 2298 2297 2296 2295 2294 2293 2292 2291 2290 2289 2288 2287 2286 2285 2284 2283 2282 2281 2280 2279 2278 2277 2276 2275 2274 2273 2272 2271 2270 2269 2268 2267 2266 2265 2264 2263 2262 2261 2260 2259 2258 2257 2256 2255 2254 2253 2252 2251 2250 2249 2248 2247 2246 2245 2244 2243 2242 2241 2240 2239 2238 2237 2236 2235 2234 2233 2232 2231 2230 2229 2228 2227 2226 2225 2224 2223 2222 2221 2220 2219 2218 2217 2216 2215 2214 2213 2212 2211 2210 2209 2208 2207 2206 2205 2204 2203 2202 2201 2200 2199 2198 2197 2196 2195 2194 2193 2192 2191 2190 2189 2188 2187 2186 2185 2184 2183 2182 2181 2180 2179 2178 2177 2176 2175 2174 2173 2172 2171 2170 2169 2168 2167 2166 2165 2164 2163 2162 2161 2160 2159 2158 2157 2156 2155 2154 2153 2152 2151 2150 2149 2148 2147 2146 2145 2144 2143 2142 2141 2140 2139 2138 2137 2136 2135 2134 2133 2132 2131 2130 2129 2128 2127 2126 2125 2124 2123 2122 2121 2120 2119 2118 7117 7116 7115 7114 7113 7112 7111 7110 7109 7108 7107 7106 7105 7104 7103 7102 7101 7100 7099 7098 7097 7096 7095 7094 7093 7092 7091 7090 7089 7088 7087 7086 7085 7084 7083 7082 7081 7080 7079 7078 7077 7076 7075 7074 7073 7072 7071 7070 7069 7068 7067 7066 7065 7064 7063 7062 7061 7060 7059 7058 7057 7056 7055 7054 7053 7052 7051 7050 7049 7048 7047 7046 7045 7044 7043 7042 7041 7040 7039 7038 7037 7036 7035 7034 7033 7032 7031 7030 7029 7028 7027 7026 7025 7024 7023 7022 7021 7020 7019 7018 7017 7016 7015 7014 7013 7012 7011 7010 7009 7008 7007 7006 7005 7004 7003 7002 7001 7000 6999 6998 6997 6996 6995 6994 6993 6992 6991 6990 6989 6988 6987 6986 6985 6984 6983 6982 6981 6980 6979 6978 6977 6976 6975 6974 6973 6972 6971 6970 6969 6968 6967 6966 6965 6964 6963 6962 6961 6960 6959 6958 6957 6956 6955 6954 6953 6952 6951 6950 6949 6948 6947 6946 6945 6944 6943 6942 6941 6940 6939 6938 6937 6936 6935 6934 6933 6932 6931 6930 6929 6928 6927 6926 6925 6924 6923 6922 6921 6920 6919 6918 6917 6916 6915 6914 6913 6912 6911 6910 6909 6908 6907 6906 6905 6904 6903 6902 6901 6900 6899 6898 6897 6896 6895 6894 6893 6892 6891 6890 6889 6888 6887 6886 6885 6884 6883 6882 6881 6880 6879 6878 6877 6876 6875 6874 6873 6872 6871 6870 6869 6868 6867 6866 6865 6864 6863 6862 6861 6860 6859 6858 6857 6856 6855 6854 6853 6852 6851 6850 6849 6848 6847 6846 6845 6844 6843 6842 6841 6840 6839 6838 6837 6836 6835 6834 6833 6832 6831 6830 6829 6828 6827 6826 6825 6824 6823 6822 6821 6820 6819 6818 6817 6816 6815 6814 6813 6812 6811 6810 6809 6808 6807 6806 6805 6804 6803 6802 6801 6800 6799 6798 6797 6796 6795 6794 6793 6792 6791 6790 6789 6788 6787 6786 6785 6784 6783 6782 6781 6780 6779 6778 6777 6776 6775 6774 6773 6772 6771 6770 6769 6768 6767 6766 6765 6764 6763 6762 6761 6760 6759 6758 6757 6756 6755 6754 6753 6752 6751 6750 6749 6748 6747 6746 6745 6744 6743 6742 6741 6740 6739 6738 6737 6736 6735 6734 6733 6732 6731 6730 6729 6728 6727 6726 6725 6724 6723 6722 6721 6720 6719 6718 6717 6716 6715 6714 6713 6712 6711 6710 6709 6708 6707 6706 6705 6704 6703 6702 6701 6700 6699 6698 6697 6696 6695 6694 6693 6692 6691 6690 6689 6688 6687 6686 6685 6684 6683 6682 6681 6680 6679 6678 6677 6676 6675 6674 6673 6672 6671 6670 6669 6668 6667 6666 6665 6664 6663 6662 6661 6660 6659 6658 6657 6656 6655 6654 6653 6652 6651 6650 6649 6648 6647 6646 6645 6644 6643 6642 6641 6640 6639 6638 6637 6636 6635 6634 6633 6632 6631 6630 6629 6628 6627 6626 6625 6624 6623 6622 6621 6620 6619 6618 6617 6616 6615 6614 6613 6612 6611 6610 6609 6608 6607 6606 6605 6604 6603 6602 6601 6600 6599 6598 6597 6596 6595 6594 6593 6592 6591 6590 6589 6588 6587 6586 6585 6584 6583 6582 6581 6580 6579 6578 6577 6576 6575 6574 6573 6572 6571 6570 6569 6568 6567 6566 6565 6564 6563 6562 6561 6560 6559 6558 6557 6556 6555 6554 6553 6552 6551 6550 6549 6548 6547 6546 6545 6544 6543 6542 6541 6540 6539 6538 6537 6536 6535 6534 6533 6532 6531 6530 6529 6528 6527 6526 6525 6524 6523 6522 6521 6520 6519 6518 6517 6516 6515 6514 6513 6512 6511 6510 6509 6508 6507 6506 6505 6504 6503 6502 6501 6500 6499 6498 6497 6496 6495 6494 6493 6492 6491 6490 6489 6488 6487 6486 6485 6484 6483 6482 6481 6480 6479 6478 6477 6476 6475 6474 6473 6472 6471 6470 6469 6468 6467 6466 6465 6464 6463 6462 6461 6460 6459 6458 6457 6456 6455 6454 6453 6452 6451 6450 6449 6448 6447 6446 6445 6444 6443 6442 6441 6440 6439 6438 6437 6436 6435 6434 6433 6432 6431 6430 6429 6428 6427 6426 6425 6424 6423 6422 6421 6420 6419 6418 6417 6416 6415 6414 6413 6412 6411 6410 6409 6408 6407 6406 6405 6404 6403 6402 6401 6400 6399 6398 6397 6396 6395 6394 6393 6392 6391 6390 6389 6388 6387 6386 6385 6384 6383 6382 6381 6380 6379 6378 6377 6376 6375 6374 6373 6372 6371 6370 6369 6368 6367 6366 6365 6364 6363 6362 6361 6360 6359 6358 6357 6356 6355 6354 6353 6352 6351 6350 6349 6348 6347 6346 6345 6344 6343 6342 6341 6340 6339 6338 6337 6336 6335 6334 6333 6332 6331 6330 6329 6328 6327 6326 6325 6324 6323 6322 6321 6320 6319 6318 6317 6316 6315 6314 6313 6312 6311 6310 6309 6308 6307 6306 6305 6304 6303 6302 6301 6300 6299 6298 6297 6296 6295 6294 6293 6292 6291 6290 6289 6288 6287 6286 6285 6284 6283 6282 6281 6280 6279 6278 6277 6276 6275 6274 6273 6272 6271 6270 6269 6268 6267 6266 6265 6264 6263 6262 6261 6260 6259 6258 6257 6256 6255 6254 6253 6252 6251 6250 6249 6248 6247 6246 6245 6244 6243 6242 6241 6240 6239 6238 6237 6236 6235 6234 6233 6232 6231 6230 6229 6228 6227 6226 6225 6224 6223 6222 6221 6220 6219 6218 6217 6216 6215 6214 6213 6212 6211 6210 6209 6208 6207 6206 6205 6204 6203 6202 6201 6200 6199 6198 6197 6196 6195 6194 6193 6192 6191 6190 6189 6188 6187 6186 6185 6184 6183 6182 6181 6180 6179 6178 6177 6176 6175 6174 6173 6172 6171 6170 6169 6168 6167 6166 6165 6164 6163 6162 6161 6160 6159 6158 6157 6156 6155 6154 6153 6152 6151 6150 6149 6148 6147 6146 6145 6144 6143 6142 6141 6140 6139 6138 6137 6136 6135 6134 6133 6132 6131 6130 6129 6128 6127 6126 ",
"1 3 2 ",
"255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 259 258 257 256 255 254 253 252 251 250 249 248 247 246 260 259 258 257 256 ",
"60 59 58 57 56 55 54 53 52 61 ",
"15 15 14 13 12 15 14 13 17 16 ",
"11 11 10 10 9 16 15 14 13 12 ",
"51 50 49 48 47 46 45 44 43 42 ",
"17 16 15 14 13 12 11 10 9 12 ",
"5 4 6 ",
"18 17 16 18 17 16 15 21 20 19 ",
"74 73 72 71 70 69 68 167 166 165 164 163 162 161 160 159 158 157 156 155 154 153 152 151 150 149 148 147 146 145 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 ",
"4 3 3 ",
"15 24 23 22 21 20 19 18 17 16 ",
"261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225 224 223 266 265 264 263 262 261 260 259 258 257 256 255 254 253 252 251 250 249 248 247 246 245 244 243 242 241 240 239 238 237 236 235 234 280 279 278 277 276 275 274 273 272 271 270 269 268 267 266 265 264 263 271 270 269 268 267 266 265 264 263 262 ",
"4 3 2 ",
"34 38 37 36 35 34 38 37 36 35 ",
"24 33 32 31 30 29 28 27 26 25 ",
"4 3 2 ",
"26 25 24 23 25 24 30 29 28 27 ",
"7 10 9 8 8 ",
"4 6 5 "
]
} | 1,800 | 250 |
2 | 8 | 1149_B. Three Religions | During the archaeological research in the Middle East you found the traces of three ancient religions: First religion, Second religion and Third religion. You compiled the information on the evolution of each of these beliefs, and you now wonder if the followers of each religion could coexist in peace.
The Word of Universe is a long word containing the lowercase English characters only. At each moment of time, each of the religion beliefs could be described by a word consisting of lowercase English characters.
The three religions can coexist in peace if their descriptions form disjoint subsequences of the Word of Universe. More formally, one can paint some of the characters of the Word of Universe in three colors: 1, 2, 3, so that each character is painted in at most one color, and the description of the i-th religion can be constructed from the Word of Universe by removing all characters that aren't painted in color i.
The religions however evolve. In the beginning, each religion description is empty. Every once in a while, either a character is appended to the end of the description of a single religion, or the last character is dropped from the description. After each change, determine if the religions could coexist in peace.
Input
The first line of the input contains two integers n, q (1 β€ n β€ 100 000, 1 β€ q β€ 1000) β the length of the Word of Universe and the number of religion evolutions, respectively. The following line contains the Word of Universe β a string of length n consisting of lowercase English characters.
Each of the following line describes a single evolution and is in one of the following formats:
* + i c (i β \{1, 2, 3\}, c β \{a, b, ..., z\}: append the character c to the end of i-th religion description.
* - i (i β \{1, 2, 3\}) β remove the last character from the i-th religion description. You can assume that the pattern is non-empty.
You can assume that no religion will have description longer than 250 characters.
Output
Write q lines. The i-th of them should be YES if the religions could coexist in peace after the i-th evolution, or NO otherwise.
You can print each character in any case (either upper or lower).
Examples
Input
6 8
abdabc
+ 1 a
+ 1 d
+ 2 b
+ 2 c
+ 3 a
+ 3 b
+ 1 c
- 2
Output
YES
YES
YES
YES
YES
YES
NO
YES
Input
6 8
abbaab
+ 1 a
+ 2 a
+ 3 a
+ 1 b
+ 2 b
+ 3 b
- 1
+ 2 z
Output
YES
YES
YES
YES
YES
NO
YES
NO
Note
In the first example, after the 6th evolution the religion descriptions are: ad, bc, and ab. The following figure shows how these descriptions form three disjoint subsequences of the Word of Universe:
<image> | {
"input": [
"6 8\nabdabc\n+ 1 a\n+ 1 d\n+ 2 b\n+ 2 c\n+ 3 a\n+ 3 b\n+ 1 c\n- 2\n",
"6 8\nabbaab\n+ 1 a\n+ 2 a\n+ 3 a\n+ 1 b\n+ 2 b\n+ 3 b\n- 1\n+ 2 z\n"
],
"output": [
"YES\nYES\nYES\nYES\nYES\nYES\nNO\nYES\n",
"YES\nYES\nYES\nYES\nYES\nNO\nYES\nNO\n"
]
} | {
"input": [
"1 1\nt\n+ 2 p\n",
"2 12\naa\n+ 1 a\n+ 2 a\n+ 3 a\n- 1\n+ 1 a\n- 2\n+ 2 a\n- 3\n+ 3 a\n+ 2 a\n- 1\n- 3\n",
"2 10\nuh\n+ 1 h\n+ 2 u\n+ 3 h\n- 1\n- 2\n+ 2 h\n+ 3 u\n- 2\n+ 1 u\n- 3\n",
"1 1\nz\n+ 3 z\n"
],
"output": [
"NO\n",
"YES\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nNO\nNO\nYES\n",
"YES\nYES\nNO\nYES\nYES\nNO\nNO\nNO\nNO\nYES\n",
"YES\n"
]
} | 2,200 | 1,250 |
2 | 7 | 1189_A. Keanu Reeves | After playing Neo in the legendary "Matrix" trilogy, Keanu Reeves started doubting himself: maybe we really live in virtual reality? To find if this is true, he needs to solve the following problem.
Let's call a string consisting of only zeroes and ones good if it contains different numbers of zeroes and ones. For example, 1, 101, 0000 are good, while 01, 1001, and 111000 are not good.
We are given a string s of length n consisting of only zeroes and ones. We need to cut s into minimal possible number of substrings s_1, s_2, β¦, s_k such that all of them are good. More formally, we have to find minimal by number of strings sequence of good strings s_1, s_2, β¦, s_k such that their concatenation (joining) equals s, i.e. s_1 + s_2 + ... + s_k = s.
For example, cuttings 110010 into 110 and 010 or into 11 and 0010 are valid, as 110, 010, 11, 0010 are all good, and we can't cut 110010 to the smaller number of substrings as 110010 isn't good itself. At the same time, cutting of 110010 into 1100 and 10 isn't valid as both strings aren't good. Also, cutting of 110010 into 1, 1, 0010 isn't valid, as it isn't minimal, even though all 3 strings are good.
Can you help Keanu? We can show that the solution always exists. If there are multiple optimal answers, print any.
Input
The first line of the input contains a single integer n (1β€ n β€ 100) β the length of the string s.
The second line contains the string s of length n consisting only from zeros and ones.
Output
In the first line, output a single integer k (1β€ k) β a minimal number of strings you have cut s into.
In the second line, output k strings s_1, s_2, β¦, s_k separated with spaces. The length of each string has to be positive. Their concatenation has to be equal to s and all of them have to be good.
If there are multiple answers, print any.
Examples
Input
1
1
Output
1
1
Input
2
10
Output
2
1 0
Input
6
100011
Output
2
100 011
Note
In the first example, the string 1 wasn't cut at all. As it is good, the condition is satisfied.
In the second example, 1 and 0 both are good. As 10 isn't good, the answer is indeed minimal.
In the third example, 100 and 011 both are good. As 100011 isn't good, the answer is indeed minimal. | {
"input": [
"1\n1\n",
"6\n100011\n",
"2\n10\n"
],
"output": [
"1\n1\n",
"2\n1 00011\n",
"2\n1 0\n"
]
} | {
"input": [
"72\n111101100111001110000000100010100000011011100110001010111010101011111100\n",
"3\n101\n",
"18\n101111001111000110\n",
"7\n1111000\n",
"3\n010\n",
"12\n101010100101\n",
"1\n0\n",
"4\n1010\n",
"6\n101100\n",
"100\n0010110000001111110111101011100111101000110011011100100011110001101110000001000010100001011011110001\n",
"2\n01\n",
"8\n11000011\n",
"15\n110001101000101\n",
"36\n111100110011010001010010100011001101\n",
"8\n10100011\n",
"3\n111\n",
"4\n0101\n",
"4\n1100\n",
"6\n010011\n",
"3\n100\n",
"3\n000\n",
"8\n10010101\n",
"100\n0110110011011111001110000110010010000111111001100001011101101000001011001101100111011111100111101110\n",
"80\n01110111110010110111011110101000110110000111000100111000000101001011111000110011\n",
"10\n1100010011\n",
"20\n10010000010111010111\n",
"44\n10010000111011010000111011111010010100001101\n",
"4\n1000\n",
"8\n11001100\n",
"6\n100011\n",
"2\n00\n",
"45\n101001101111010010111100000111111010111001001\n",
"10\n1101001100\n",
"2\n11\n"
],
"output": [
"2\n1 11101100111001110000000100010100000011011100110001010111010101011111100\n",
"1\n101\n",
"1\n101111001111000110\n",
"1\n1111000\n",
"1\n010\n",
"2\n1 01010100101\n",
"1\n0\n",
"2\n1 010\n",
"2\n1 01100\n",
"2\n0 010110000001111110111101011100111101000110011011100100011110001101110000001000010100001011011110001\n",
"2\n0 1\n",
"2\n1 1000011\n",
"1\n110001101000101\n",
"2\n1 11100110011010001010010100011001101\n",
"2\n1 0100011\n",
"1\n111\n",
"2\n0 101\n",
"2\n1 100\n",
"2\n0 10011\n",
"1\n100\n",
"1\n000\n",
"2\n1 0010101\n",
"1\n0110110011011111001110000110010010000111111001100001011101101000001011001101100111011111100111101110\n",
"1\n01110111110010110111011110101000110110000111000100111000000101001011111000110011\n",
"2\n1 100010011\n",
"2\n1 0010000010111010111\n",
"2\n1 0010000111011010000111011111010010100001101\n",
"1\n1000\n",
"2\n1 1001100\n",
"2\n1 00011\n",
"1\n00\n",
"1\n101001101111010010111100000111111010111001001\n",
"2\n1 101001100\n",
"1\n11\n"
]
} | 800 | 500 |
2 | 7 | 1208_A. XORinacci | Cengiz recently learned Fibonacci numbers and now he is studying different algorithms to find them. After getting bored of reading them, he came with his own new type of numbers that he named XORinacci numbers. He defined them as follows:
* f(0) = a;
* f(1) = b;
* f(n) = f(n-1) β f(n-2) when n > 1, where β denotes the [bitwise XOR operation](https://en.wikipedia.org/wiki/Bitwise_operation#XOR).
You are given three integers a, b, and n, calculate f(n).
You have to answer for T independent test cases.
Input
The input contains one or more independent test cases.
The first line of input contains a single integer T (1 β€ T β€ 10^3), the number of test cases.
Each of the T following lines contains three space-separated integers a, b, and n (0 β€ a, b, n β€ 10^9) respectively.
Output
For each test case, output f(n).
Example
Input
3
3 4 2
4 5 0
325 265 1231232
Output
7
4
76
Note
In the first example, f(2) = f(0) β f(1) = 3 β 4 = 7. | {
"input": [
"3\n3 4 2\n4 5 0\n325 265 1231232\n"
],
"output": [
"7\n4\n76\n"
]
} | {
"input": [
"10\n669924290 408119795 804030560\n663737793 250734602 29671646\n431160679 146708815 289491233\n189259304 606497663 379372476\n707829111 49504411 81710658\n54555019 65618101 626948607\n578351356 288589794 974275296\n400531973 205638174 323247740\n219131617 178762989 799964854\n825160173 502080627 608216046\n",
"10\n0 0 1000000000\n1002 2003 36523\n233 5656 898989\n0 2352 0\n21132 23256 2323256\n12313 454878 11000\n1213 0 21\n11 1 1\n1 1 98532\n1000000000 1000000000 1000000000\n",
"2\n168342 440469 517112\n841620 806560 140538\n",
"1\n25369 85223 58963241\n",
"1\n1 2 3\n"
],
"output": [
"1069371953\n696139211\n286024744\n189259304\n707829111\n54555019\n578351356\n463366171\n178762989\n825160173\n",
"0\n2003\n233\n0\n2132\n442567\n1213\n1\n1\n1000000000\n",
"272643\n841620\n",
"77822\n",
"1\n"
]
} | 900 | 500 |
2 | 7 | 1227_A. Math Problem | Your math teacher gave you the following problem:
There are n segments on the x-axis, [l_1; r_1], [l_2; r_2], β¦, [l_n; r_n]. The segment [l; r] includes the bounds, i.e. it is a set of such x that l β€ x β€ r. The length of the segment [l; r] is equal to r - l.
Two segments [a; b] and [c; d] have a common point (intersect) if there exists x that a β€ x β€ b and c β€ x β€ d. For example, [2; 5] and [3; 10] have a common point, but [5; 6] and [1; 4] don't have.
You should add one segment, which has at least one common point with each of the given segments and as short as possible (i.e. has minimal length). The required segment can degenerate to be a point (i.e a segment with length zero). The added segment may or may not be among the given n segments.
In other words, you need to find a segment [a; b], such that [a; b] and every [l_i; r_i] have a common point for each i, and b-a is minimal.
Input
The first line contains integer number t (1 β€ t β€ 100) β the number of test cases in the input. Then t test cases follow.
The first line of each test case contains one integer n (1 β€ n β€ 10^{5}) β the number of segments. The following n lines contain segment descriptions: the i-th of them contains two integers l_i,r_i (1 β€ l_i β€ r_i β€ 10^{9}).
The sum of all values n over all the test cases in the input doesn't exceed 10^5.
Output
For each test case, output one integer β the smallest possible length of the segment which has at least one common point with all given segments.
Example
Input
4
3
4 5
5 9
7 7
5
11 19
4 17
16 16
3 12
14 17
1
1 10
1
1 1
Output
2
4
0
0
Note
In the first test case of the example, we can choose the segment [5;7] as the answer. It is the shortest segment that has at least one common point with all given segments. | {
"input": [
"4\n3\n4 5\n5 9\n7 7\n5\n11 19\n4 17\n16 16\n3 12\n14 17\n1\n1 10\n1\n1 1\n"
],
"output": [
"2\n4\n0\n0\n"
]
} | {
"input": [
"1\n2\n999999997 999999998\n999999999 1000000000\n",
"4\n1\n1 1000000000\n5\n1 1\n12 18\n1000000000 1000000000\n1 1\n8888888 88888888\n5\n2 5\n3 6\n4 7\n5 8\n6 9\n3\n1 1000000000\n1 1\n1000000000 1000000000\n",
"1\n10\n132182352 630066892\n323711215 923129673\n259700817 882571434\n226161845 398771294\n243750814 771888758\n322757488 771114163\n241900265 761492222\n197067927 815099563\n33872533 895781009\n271628366 729808874\n",
"1\n2\n1000000000 1000000000\n1000000000 1000000000\n"
],
"output": [
"1\n",
"0\n999999999\n1\n999999999\n",
"0\n",
"0\n"
]
} | 1,100 | 500 |
2 | 10 | 124_D. Squares | You are given an infinite checkered field. You should get from a square (x1; y1) to a square (x2; y2). Using the shortest path is not necessary. You can move on the field squares in four directions. That is, when you are positioned in any square, you can move to any other side-neighboring one.
A square (x; y) is considered bad, if at least one of the two conditions is fulfilled:
* |x + y| β‘ 0 (mod 2a),
* |x - y| β‘ 0 (mod 2b).
Your task is to find the minimum number of bad cells one will have to visit on the way from (x1; y1) to (x2; y2).
Input
The only line contains integers a, b, x1, y1, x2 and y2 β the parameters of the bad squares, the coordinates of the initial and the final squares correspondingly (2 β€ a, b β€ 109 and |x1|,|y1|,|x2|,|y2| β€ 109). It is guaranteed that the initial and the final square aren't bad.
Output
Print a single number β the minimum number of bad cells that one will have to visit in order to travel from square (x1; y1) to square (x2; y2).
Examples
Input
2 2 1 0 0 1
Output
1
Input
2 2 10 11 0 1
Output
5
Input
2 4 3 -1 3 7
Output
2
Note
In the third sample one of the possible paths in (3;-1)->(3;0)->(3;1)->(3;2)->(4;2)->(4;3)->(4;4)->(4;5)->(4;6)->(4;7)->(3;7). Squares (3;1) and (4;4) are bad. | {
"input": [
"2 2 1 0 0 1\n",
"2 2 10 11 0 1\n",
"2 4 3 -1 3 7\n"
],
"output": [
"1",
"5",
"2"
]
} | {
"input": [
"605 297 -251700323 -366763764 -445828791 325081312\n",
"14 9 44 45 -50 -9\n",
"18 17 -26078453 -12853708 26705417 -4593122\n",
"472555248 417950652 -897989583 -805741694 915661619 800897620\n",
"1005 557 -451917708 -32771965 501646713 -357583032\n",
"465 469 376765675 358805048 -390193085 -375070460\n",
"3 2 -11 -10 10 11\n",
"840853 1638188 -425749679 502946202 -953467908 557484181\n",
"7 7 23 28 -20 -27\n",
"10311 10242 764996339 626041956 -740573838 -97126465\n",
"3 4 -8 5 6 -3\n",
"5 3 6 3 3 12\n",
"207 226 -194940280 130461973 246251465 260969752\n",
"3 2 -8 -9 -14 -1\n",
"134699726 208640218 514309071 801051734 276512437 -803859310\n",
"1576 15 -503228573 -531048974 531411118 557082183\n",
"2 2 9 10 -10 -11\n",
"127 88 66407013 205897916 133496817 264883406\n",
"11 10 9 -40 37 -56\n",
"2033 1908 -480144210 482795119 496763189 -594064604\n",
"10005 10008 -234169778 -592210597 -126329886 -812018105\n",
"5989 6249 -605686335 -602992500 586207791 624769222\n",
"21 24 31005425 54491054 -24732944 -61529693\n",
"12 63 100712190 36906101 87205943 82885374\n",
"509 565 14560229 -77153392 -340426524 82224911\n",
"781751245 1000000000 -848188940 813653557 978830633 -825182414\n",
"4 4 3 2 10 -1\n",
"8 12 -14763515 -11730382 -1343471 -4020758\n",
"146 157 261464154 113810381 214579048 -202712885\n",
"4209 7951 232804958 -326325341 -138865076 516216059\n",
"2455 2436 -335351804 -50788097 286734045 222304974\n",
"2959011 3049607 253816894 -342369389 610124947 440828496\n",
"14 16 1967781 241814 1873488 -829353\n",
"8 9 8 -23 31 -46\n",
"10067 8186 -736794579 -820525762 -407728461 839527984\n",
"551 8823 -644698584 720097649 -746775493 -719362914\n",
"24 27 -57405669 -65437426 56079726 56139299\n",
"267 263 -291849914 -111930623 344642355 250706518\n",
"3 5 -20 19 21 16\n",
"29 54 16062290 129524399 -84381788 132177911\n",
"4237214 4640696 -612169083 -326390834 887479529 304518522\n",
"1123 1126 438419485 487688122 -477080698 -185247601\n",
"10000 10002 96487781 -692179874 182133670 357089051\n",
"216 218 15106122 259371253 296596165 -45704666\n",
"31288011 27242802 -934902606 343371553 926119543 -195542560\n",
"77 101 -241379320 -196400933 220541904 214436435\n",
"999999 100000 12345 54321 6789 9876\n",
"26 34 -107153659 6976200 34136365 -95904822\n",
"664 408 -151206136 -299481355 -385233545 310492602\n",
"3 5 -4 -7 5 0\n",
"899 549 -249681750 38465319 105189786 -64009701\n",
"1811 1038 526157767 549399960 -479125660 -508887739\n",
"5 8 35 -36 -34 33\n",
"55 22 189761193 -192020216 -153412991 188486816\n",
"43649 46022 -793221994 750708255 871188328 -901390875\n",
"2 3 -12 13 13 -12\n",
"86 1341 -197343715 13981506 -529124963 208152056\n",
"1558 2911 -239080974 -489789417 369291826 -67795521\n",
"15 11 -140506021 21571904 -148280972 64286933\n",
"6 13 -37 12 3 60\n",
"6929 8303 -718092932 630511765 717136401 -678221530\n",
"20967 19929 821529452 892087465 -867106029 -836044344\n",
"3 2 8 -25 0 25\n",
"3341 3479 481143880 -383576301 -584637231 166949262\n",
"86 84 -65173069 221707138 155388823 -224274366\n",
"17 22 72042304 -75756269 -70969649 64115614\n",
"2795 3024 418200485 -575735266 101404272 -10209857\n",
"999999999 1000000000 1000000000 -999999999 -1000000000 999999999\n",
"53 50 -120558789 -138770904 4229051 102239338\n",
"10 8 -44 41 43 -38\n",
"288 40 338359015 273791206 -341021431 56950660\n",
"66 39 -170201625 -169447104 166170410 181151513\n",
"222075 201776 -663198106 -381459887 -29690718 -65372649\n",
"10058 9799 -25054219 -611037250 172201377 486371190\n",
"1147 1627 473801348 -494462579 -514604760 486124951\n",
"72 75 182000846 -19533501 -166922752 -142084479\n",
"7368 7243 646513016 723552175 -631585348 -678824351\n",
"356 10 97627462 341324361 -132835544 -334849729\n",
"526654 264582 -19827600 -757880279 -903623062 -934193021\n",
"101304499 148554333 -590787464 -890180401 -117457421 997140710\n",
"34 19 -95432112 102651275 96089919 -106537520\n",
"388 113 366011910 -387447751 -403158698 353327235\n",
"2 3 2 -1 -10 -1\n",
"321 30 46954660 -343679003 -37851471 373573736\n",
"2036 9146 46737913 478540414 -603176411 -34978692\n",
"34483 1001201 -483230679 -24466088 827887504 293189155\n",
"7 7 -30 -29 32 31\n",
"4238 464 631928630 -699088687 -665579317 658247096\n",
"70 110 221139524 -236077945 -236283510 205078897\n",
"13225 984 -760662977 -854994174 786299019 825465374\n",
"5099 3763 239091250 -689089763 -331708609 690647436\n",
"7 179 -249546082 207791883 267735483 49881404\n",
"5431 5421 218916782 582895951 714645533 -634539842\n",
"1174 901 522498777 -499217148 77740787 519316970\n",
"2 9 37 34 -38 -37\n",
"7 20 10771554 -46099323 39192337 54007626\n",
"4260 4286 -559966975 430515446 630949753 -403746792\n",
"1425 1444 516172942 520776621 -319341286 -488388923\n",
"125 204 91089644 83192699 -300075653 54365352\n",
"38 5 -13548447 534376 64966608 -29272371\n",
"3868 1251 -639544998 21536679 -480078735 -457166436\n",
"14699 14675 792934253 -867739654 -737526630 840318203\n",
"11 5 -71 44 -18 -21\n",
"783 827 -98613981 316213558 -275430891 455234090\n",
"18 116 231579605 226020224 -214399491 -217631436\n",
"6152051 53675778 964821583 85960172 -939564894 755134693\n",
"148 163 -62225702 -294347345 -98578232 214557359\n",
"31 29 73305636 76203147 -85238444 -86730133\n",
"1000000000 1000000000 871940474 991768763 -914352281 -886310260\n",
"4 4 0 -3 11 -4\n",
"2571 2243 474188235 -306739018 48936920 -83297677\n",
"25706 3236 867426580 143799455 254112907 -287546356\n",
"380 397 -340890121 -349529418 396652406 353599055\n",
"504 116 -408147784 387006943 367365902 -415105789\n",
"3 2 11 -12 -12 11\n",
"8387 10012 -275798799 489020846 127010938 154401541\n",
"10088 6166 -735339950 -111273129 787180186 -439981865\n",
"5 18 41299309 8851928 -40049166 -35564497\n",
"299386785 573704302 956852511 -973861202 -816995136 989470727\n",
"4685 84 597126772 174658367 -667031403 657366658\n",
"42 45 13921918 62207801 80023961 -85820354\n",
"868 969 245648369 212586392 258298826 -389155385\n",
"3 3 12 11 -12 -11\n",
"133 122 -258888058 250173335 258738451 -242389122\n",
"689 635 344525358 -321493413 12979458 -353392841\n",
"10721 11225 -767745746 709747051 443545879 -717667636\n",
"5 6 23 -10 -20 -17\n"
],
"output": [
"1491538",
"6",
"1695679",
"3",
"1147554",
"1613801",
"7",
"281",
"7",
"108076",
"3",
"2",
"1380917",
"4",
"6",
"1783049",
"10",
"496360",
"2",
"538199",
"16370",
"202009",
"4089503",
"1353043",
"455190",
"1",
"1",
"1320604",
"1244549",
"76356",
"182317",
"192",
"41624",
"3",
"98794",
"1398855",
"4897128",
"1871029",
"7",
"1686044",
"251",
"707229",
"56746",
"1345335",
"44",
"5667263",
"0",
"3590751",
"1034315",
"2",
"416527",
"569733",
"9",
"16447301",
"36031",
"9",
"800062",
"330670",
"2294999",
"8",
"165239",
"81480",
"15",
"232295",
"3967520",
"6429178",
"145887",
"1",
"3450925",
"11",
"5781749",
"5204323",
"2138",
"64360",
"605100",
"3274129",
"181900",
"22285554",
"1337",
"12",
"10545022",
"6681175",
"3",
"13367648",
"285715",
"23617",
"9",
"2860823",
"4084454",
"122020",
"259173",
"25669363",
"158012",
"812037",
"36",
"9180553",
"236255",
"647256",
"1679971",
"10832180",
"255064",
"110341",
"12",
"190954",
"24711966",
"100",
"1672568",
"5185118",
"1",
"1",
"144603",
"28116",
"1895619",
"6800114",
"11",
"36828",
"150116",
"12576490",
"3",
"10398014",
"2379224",
"339339",
"7",
"4140119",
"263749",
"117537",
"5"
]
} | 1,800 | 1,000 |
2 | 8 | 1269_B. Modulo Equality | You are given a positive integer m and two integer sequence: a=[a_1, a_2, β¦, a_n] and b=[b_1, b_2, β¦, b_n]. Both of these sequence have a length n.
Permutation is a sequence of n different positive integers from 1 to n. For example, these sequences are permutations: [1], [1,2], [2,1], [6,7,3,4,1,2,5]. These are not: [0], [1,1], [2,3].
You need to find the non-negative integer x, and increase all elements of a_i by x, modulo m (i.e. you want to change a_i to (a_i + x) mod m), so it would be possible to rearrange elements of a to make it equal b, among them you need to find the smallest possible x.
In other words, you need to find the smallest non-negative integer x, for which it is possible to find some permutation p=[p_1, p_2, β¦, p_n], such that for all 1 β€ i β€ n, (a_i + x) mod m = b_{p_i}, where y mod m β remainder of division of y by m.
For example, if m=3, a = [0, 0, 2, 1], b = [2, 0, 1, 1], you can choose x=1, and a will be equal to [1, 1, 0, 2] and you can rearrange it to make it equal [2, 0, 1, 1], which is equal to b.
Input
The first line contains two integers n,m (1 β€ n β€ 2000, 1 β€ m β€ 10^9): number of elemens in arrays and m.
The second line contains n integers a_1, a_2, β¦, a_n (0 β€ a_i < m).
The third line contains n integers b_1, b_2, β¦, b_n (0 β€ b_i < m).
It is guaranteed that there exists some non-negative integer x, such that it would be possible to find some permutation p_1, p_2, β¦, p_n such that (a_i + x) mod m = b_{p_i}.
Output
Print one integer, the smallest non-negative integer x, such that it would be possible to find some permutation p_1, p_2, β¦, p_n such that (a_i + x) mod m = b_{p_i} for all 1 β€ i β€ n.
Examples
Input
4 3
0 0 2 1
2 0 1 1
Output
1
Input
3 2
0 0 0
1 1 1
Output
1
Input
5 10
0 0 0 1 2
2 1 0 0 0
Output
0 | {
"input": [
"3 2\n0 0 0\n1 1 1\n",
"4 3\n0 0 2 1\n2 0 1 1\n",
"5 10\n0 0 0 1 2\n2 1 0 0 0\n"
],
"output": [
"1",
"1",
"0"
]
} | {
"input": [
"20 10000000\n8861863 2169292 3484361 511558 5975675 1413584 774309 5847326 6668965 2531461 3337531 9484932 2648359 3710600 2232337 5474539 2785576 4119997 5005708 1717831\n247095 4003803 2013625 1177623 7391127 1314840 5198229 2239864 9942848 1060725 1866795 3534972 698556 9303573 761601 9040822 4504939 4376590 8014196 2649261\n",
"20 10\n6 2 4 4 0 1 1 2 8 1 1 6 0 6 2 1 2 5 5 6\n4 3 4 8 4 3 0 3 7 8 6 3 7 8 8 4 2 2 6 3\n",
"5 5\n4 4 4 4 4\n0 0 0 0 0\n",
"20 1\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n",
"4 4\n1 1 3 3\n0 0 2 2\n",
"20 1000\n244 890 362 5 192 703 419 446 236 946 663 893 511 193 512 615 670 622 685 377\n209 722 251 343 778 278 454 535 502 25 495 68 24 725 344 447 837 76 517 194\n",
"20 2000\n1325 300 1826 397 1185 1473 1962 480 354 757 627 696 612 1403 426 1572 1822 427 1871 1877\n1793 919 1451 1523 1059 1724 1577 1854 974 500 570 282 422 669 923 968 1494 1709 1524 1397\n",
"20 1000000\n721052 846307 513012 215644 114498 53365 421630 415546 265423 770423 479097 734598 593043 302633 254846 832345 238162 590175 857497 602081\n924969 675701 468643 343388 736834 887759 479833 224417 212511 37882 877182 837980 454681 43966 135348 101433 392759 215379 356934 860498\n",
"1 1\n0\n0\n",
"2 10\n4 9\n1 6\n",
"1 15\n12\n1\n",
"20 100\n52 31 63 19 40 96 49 19 65 67 21 59 73 60 96 53 79 29 71 58\n48 57 76 36 88 84 69 80 77 75 38 13 70 36 46 66 96 90 82 13\n",
"20 1000000000\n667066860 170421783 139902912 635488786 31946329 289281524 541340760 264115900 680775010 102068388 128171043 636359373 477042326 879154458 716982402 654668379 256334407 874949294 737194458 663371809\n688973261 813186249 677241392 581016678 216137209 424019643 428224807 184559135 203738728 185429722 26112675 229845359 838351873 266052751 651138737 719492132 212442158 286264807 90411109 805404756\n",
"20 100000000\n8743874 50450434 97350102 56627608 58810302 44896142 94908981 7712357 92270868 74466850 67644901 82528249 75634359 52176967 68307504 92929477 51061480 65025274 79111412 28464881\n86157462 63274210 67918772 83716341 53832634 81078228 96519717 57114864 47617662 81736837 33703502 56452261 39868840 17272241 97551234 71335609 39257794 45434968 40984327 64441719\n",
"20 100000\n34457 88488 23358 60303 22639 75635 39073 80874 67687 68520 43708 94524 73919 16634 21183 24473 91736 14270 43708 96378\n42447 4368 76510 30629 51698 31348 81909 96478 68293 47063 2514 51698 88864 29173 75677 22260 32463 83625 24624 99726\n",
"20 10000\n894 8893 6181 5851 9829 7561 8853 4003 5908 4978 6862 2986 3585 1318 512 5495 9542 9560 6589 5062\n2522 6398 430 48 9096 6125 854 3121 7097 5717 4514 9365 5387 8389 5031 5444 9078 3539 4598 8429\n",
"20 2\n0 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 0 0 1 1\n0 1 0 0 1 1 0 0 1 1 0 0 0 0 0 0 1 1 0 0\n"
],
"output": [
"8529264",
"2",
"1",
"0",
"1",
"832",
"1097",
"622336",
"0",
"2",
"4",
"17",
"549070349",
"88807360",
"7990",
"9536",
"0\n"
]
} | 1,500 | 1,000 |
2 | 9 | 1311_C. Perform the Combo | You want to perform the combo on your opponent in one popular fighting game. The combo is the string s consisting of n lowercase Latin letters. To perform the combo, you have to press all buttons in the order they appear in s. I.e. if s="abca" then you have to press 'a', then 'b', 'c' and 'a' again.
You know that you will spend m wrong tries to perform the combo and during the i-th try you will make a mistake right after p_i-th button (1 β€ p_i < n) (i.e. you will press first p_i buttons right and start performing the combo from the beginning). It is guaranteed that during the m+1-th try you press all buttons right and finally perform the combo.
I.e. if s="abca", m=2 and p = [1, 3] then the sequence of pressed buttons will be 'a' (here you're making a mistake and start performing the combo from the beginning), 'a', 'b', 'c', (here you're making a mistake and start performing the combo from the beginning), 'a' (note that at this point you will not perform the combo because of the mistake), 'b', 'c', 'a'.
Your task is to calculate for each button (letter) the number of times you'll press it.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 10^4) β the number of test cases.
Then t test cases follow.
The first line of each test case contains two integers n and m (2 β€ n β€ 2 β
10^5, 1 β€ m β€ 2 β
10^5) β the length of s and the number of tries correspondingly.
The second line of each test case contains the string s consisting of n lowercase Latin letters.
The third line of each test case contains m integers p_1, p_2, ..., p_m (1 β€ p_i < n) β the number of characters pressed right during the i-th try.
It is guaranteed that the sum of n and the sum of m both does not exceed 2 β
10^5 (β n β€ 2 β
10^5, β m β€ 2 β
10^5).
It is guaranteed that the answer for each letter does not exceed 2 β
10^9.
Output
For each test case, print the answer β 26 integers: the number of times you press the button 'a', the number of times you press the button 'b', ..., the number of times you press the button 'z'.
Example
Input
3
4 2
abca
1 3
10 5
codeforces
2 8 3 2 9
26 10
qwertyuioplkjhgfdsazxcvbnm
20 10 1 2 3 5 10 5 9 4
Output
4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0
2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2
Note
The first test case is described in the problem statement. Wrong tries are "a", "abc" and the final try is "abca". The number of times you press 'a' is 4, 'b' is 2 and 'c' is 2.
In the second test case, there are five wrong tries: "co", "codeforc", "cod", "co", "codeforce" and the final try is "codeforces". The number of times you press 'c' is 9, 'd' is 4, 'e' is 5, 'f' is 3, 'o' is 9, 'r' is 3 and 's' is 1. | {
"input": [
"3\n4 2\nabca\n1 3\n10 5\ncodeforces\n2 8 3 2 9\n26 10\nqwertyuioplkjhgfdsazxcvbnm\n20 10 1 2 3 5 10 5 9 4\n"
],
"output": [
"4 2 2 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 \n\n0 0 9 4 5 3 0 0 0 0 0 0 0 0 9 0 0 3 1 0 0 0 0 0 0 0 \n\n2 1 1 2 9 2 2 2 5 2 2 2 1 1 5 4 11 8 2 7 5 1 10 1 5 2 \n\n"
]
} | {
"input": [
"2\n2 2\nyz\n1 1\n2 2\nyz\n1 1\n",
"1\n11 2\nthisisatest\n3 5\n"
],
"output": [
"0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 \n\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 1 \n\n",
"1 0 0 0 1 0 0 3 5 0 0 0 0 0 0 0 0 0 4 5 0 0 0 0 0 0 \n\n"
]
} | 1,300 | 0 |
2 | 7 | 1334_A. Level Statistics | Polycarp has recently created a new level in this cool new game Berlio Maker 85 and uploaded it online. Now players from all over the world can try his level.
All levels in this game have two stats to them: the number of plays and the number of clears. So when a player attempts the level, the number of plays increases by 1. If he manages to finish the level successfully then the number of clears increases by 1 as well. Note that both of the statistics update at the same time (so if the player finishes the level successfully then the number of plays will increase at the same time as the number of clears).
Polycarp is very excited about his level, so he keeps peeking at the stats to know how hard his level turns out to be.
So he peeked at the stats n times and wrote down n pairs of integers β (p_1, c_1), (p_2, c_2), ..., (p_n, c_n), where p_i is the number of plays at the i-th moment of time and c_i is the number of clears at the same moment of time. The stats are given in chronological order (i.e. the order of given pairs is exactly the same as Polycarp has written down).
Between two consecutive moments of time Polycarp peeked at the stats many players (but possibly zero) could attempt the level.
Finally, Polycarp wonders if he hasn't messed up any records and all the pairs are correct. If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then he considers his records correct.
Help him to check the correctness of his records.
For your convenience you have to answer multiple independent test cases.
Input
The first line contains a single integer T (1 β€ T β€ 500) β the number of test cases.
The first line of each test case contains a single integer n (1 β€ n β€ 100) β the number of moments of time Polycarp peeked at the stats.
Each of the next n lines contains two integers p_i and c_i (0 β€ p_i, c_i β€ 1000) β the number of plays and the number of clears of the level at the i-th moment of time.
Note that the stats are given in chronological order.
Output
For each test case print a single line.
If there could exist such a sequence of plays (and clears, respectively) that the stats were exactly as Polycarp has written down, then print "YES".
Otherwise, print "NO".
You can print each letter in any case (upper or lower).
Example
Input
6
3
0 0
1 1
1 2
2
1 0
1000 3
4
10 1
15 2
10 2
15 2
1
765 432
2
4 4
4 3
5
0 0
1 0
1 0
1 0
1 0
Output
NO
YES
NO
YES
NO
YES
Note
In the first test case at the third moment of time the number of clears increased but the number of plays did not, that couldn't have happened.
The second test case is a nice example of a Super Expert level.
In the third test case the number of plays decreased, which is impossible.
The fourth test case is probably an auto level with a single jump over the spike.
In the fifth test case the number of clears decreased, which is also impossible.
Nobody wanted to play the sixth test case; Polycarp's mom attempted it to make him feel better, however, she couldn't clear it. | {
"input": [
"6\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n"
],
"output": [
"NO\nYES\nNO\nYES\nNO\nYES\n"
]
} | {
"input": [
"1\n2\n110 2\n115 112\n",
"10\n5\n88 60\n10 3\n48 21\n90 70\n40 88\n5\n20 81\n39 98\n34 87\n100 82\n21 21\n2\n46 91\n89 71\n2\n81 98\n25 36\n3\n84 97\n40 32\n17 29\n2\n56 16\n96 75\n5\n35 24\n82 73\n23 15\n45 95\n79 90\n2\n68 13\n70 100\n3\n94 35\n95 77\n31 86\n5\n99 14\n12 54\n81 60\n80 29\n46 55\n",
"4\n1\n1 2\n3\n1 1\n2 2\n3 2\n3\n1 1\n1 1\n1 1\n5\n0 0\n0 0\n1 0\n1 0\n2 2\n",
"1\n2\n100 1\n101 3\n",
"1\n3\n5 4\n8 8\n9 8\n",
"1\n2\n4 1\n5 3\n",
"1\n2\n3 1\n4 3\n",
"1\n2\n10 2\n12 5\n",
"1\n2\n5 0\n6 3\n",
"1\n3\n2 2\n10 3\n11 5\n",
"1\n2\n500 0\n501 400\n",
"1\n2\n2 0\n7 6\n",
"1\n5\n5 1\n6 3\n7 4\n8 5\n9 5\n",
"1\n2\n5 3\n10 9\n",
"1\n4\n4 2\n7 6\n8 8\n9 9\n",
"19\n1\n1 1\n1\n2 2\n1\n3 3\n1\n4 4\n1\n5 5\n1\n6 6\n1\n7 7\n1\n8 8\n1\n9 9\n1\n10 10\n1\n11 11\n1\n12 12\n1\n13 13\n1\n14 14\n1\n15 15\n1\n16 16\n1\n17 17\n1\n18 18\n1\n19 19\n",
"1\n2\n5 1\n7 4\n",
"1\n3\n1 1\n2 1\n3 3\n",
"1\n2\n10 1\n11 4\n",
"1\n2\n2 0\n3 2\n",
"2\n3\n4 2\n5 5\n6 6\n3\n1 1\n3 3\n4 4\n",
"1\n2\n6 3\n7 5\n",
"1\n2\n4 3\n8 8\n",
"1\n2\n10 8\n20 19\n",
"1\n2\n10 1\n11 7\n",
"1\n2\n5 2\n6 5\n",
"1\n5\n1 1\n2 1\n3 1\n4 1\n5 3\n",
"1\n2\n3 2\n5 5\n",
"1\n3\n1 0\n4 0\n6 4\n",
"1\n3\n0 0\n2 1\n3 3\n",
"1\n2\n4 3\n6 6\n",
"1\n3\n0 0\n10 1\n15 7\n",
"3\n3\n2 1\n3 2\n4 4\n2\n5 3\n5 6\n2\n2 2\n3 2\n",
"1\n3\n10 2\n12 7\n13 8\n",
"1\n3\n5 2\n6 5\n7 6\n",
"1\n3\n10 9\n11 11\n11 11\n",
"1\n3\n1 1\n10 1\n11 7\n",
"1\n2\n5 1\n6 3\n",
"1\n3\n5 0\n7 4\n10 10\n",
"20\n2\n1 0\n1000 3\n3\n4 2\n4 2\n4 2\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n3\n0 0\n1 1\n1 2\n2\n1 0\n1000 3\n4\n10 1\n15 2\n10 2\n15 2\n1\n765 432\n2\n4 4\n4 3\n5\n0 0\n1 0\n1 0\n1 0\n1 0\n",
"1\n3\n99 49\n100 50\n101 99\n",
"2\n4\n1 1\n10 10\n100 10\n1000 920\n4\n1 5\n1000 100\n1000 100\n1000 100\n",
"11\n5\n85 49\n90 49\n92 50\n95 50\n99 50\n5\n85 49\n90 49\n92 50\n95 50\n99 50\n1\n3 4\n5\n42 18\n70 25\n82 28\n96 43\n99 48\n5\n37 50\n95 50\n100 50\n100 50\n100 50\n5\n59 34\n100 38\n100 38\n100 39\n100 41\n5\n40 39\n97 47\n97 50\n99 50\n100 50\n5\n42 18\n70 25\n82 28\n96 43\n99 48\n5\n37 50\n95 50\n100 50\n100 50\n100 50\n5\n59 34\n100 38\n100 38\n100 39\n100 41\n5\n40 39\n97 47\n97 50\n99 50\n100 50\n",
"1\n2\n10 3\n13 8\n",
"1\n3\n1 1\n2 1\n5 5\n",
"1\n2\n1 0\n10 10\n",
"1\n3\n1 1\n5 1\n6 6\n",
"1\n3\n1 1\n3 2\n4 4\n",
"1\n3\n0 0\n100 0\n101 2\n",
"1\n2\n5 3\n6 5\n",
"1\n2\n765 432\n767 436\n",
"1\n2\n10 0\n11 2\n",
"1\n2\n10 1\n12 7\n",
"1\n3\n1 1\n3 2\n7 7\n",
"10\n2\n1 2\n3 3\n1\n5 3\n2\n3 0\n4 5\n1\n3 5\n1\n0 5\n2\n5 4\n0 4\n2\n0 1\n0 5\n1\n4 3\n2\n5 3\n2 5\n2\n5 4\n5 1\n",
"1\n3\n7 3\n8 4\n9 6\n",
"2\n2\n1 0\n2 2\n1\n0 1\n",
"1\n4\n1 0\n3 2\n13 13\n15 15\n",
"1\n2\n4 3\n7 7\n",
"1\n3\n1 1\n10 3\n13 7\n",
"1\n3\n401 1\n402 2\n403 4\n",
"1\n2\n5 1\n6 6\n",
"1\n2\n4 3\n5 5\n",
"2\n3\n0 0\n100 0\n104 5\n3\n0 0\n100 0\n104 4\n",
"1\n2\n10 2\n11 4\n",
"1\n3\n0 0\n11 5\n21 20\n",
"1\n2\n12 10\n15 15\n",
"1\n2\n3 2\n4 4\n",
"1\n3\n1 1\n30 10\n31 20\n",
"1\n3\n0 0\n5 1\n7 4\n",
"1\n2\n10 8\n12 11\n",
"1\n2\n11 0\n13 4\n",
"1\n2\n10 5\n11 7\n",
"1\n2\n5 2\n6 4\n",
"1\n2\n5 2\n7 6\n",
"1\n2\n2 1\n5 5\n",
"1\n2\n6 2\n8 5\n",
"1\n2\n5 0\n7 3\n",
"1\n3\n0 0\n50 20\n55 30\n",
"1\n3\n5 2\n6 4\n7 6\n",
"1\n3\n1 1\n30 20\n40 40\n",
"1\n4\n0 0\n1 0\n2 0\n3 3\n",
"1\n2\n1 0\n3 3\n",
"1\n3\n3 2\n4 2\n5 5\n",
"1\n2\n18 10\n22 15\n",
"1\n2\n1 0\n2 2\n",
"1\n2\n4 1\n10 9\n",
"1\n2\n100 51\n101 99\n",
"1\n2\n10 8\n11 10\n",
"1\n3\n0 0\n4 3\n5 5\n",
"1\n2\n100 10\n101 101\n",
"1\n2\n43 34\n44 35\n",
"1\n2\n10 5\n16 12\n",
"1\n2\n10 1\n101 101\n",
"1\n2\n4 3\n9 9\n",
"1\n2\n10 7\n12 10\n",
"1\n3\n1 1\n10 1\n11 5\n",
"1\n2\n4 2\n5 4\n",
"1\n3\n1 0\n5 1\n6 3\n",
"1\n4\n1 1\n2 1\n5 1\n6 3\n",
"1\n4\n1 0\n2 1\n4 4\n6 5\n",
"1\n2\n100 50\n101 99\n",
"1\n2\n7 6\n8 8\n",
"1\n2\n100 3\n105 50\n",
"1\n2\n5 0\n10 6\n",
"1\n2\n5 4\n6 6\n",
"1\n2\n4 2\n6 5\n",
"1\n4\n0 0\n1 1\n10 1\n11 3\n",
"1\n3\n1 1\n500 1\n501 99\n",
"1\n5\n1 0\n1 0\n5 1\n6 3\n7 4\n",
"2\n2\n2 0\n3 2\n3\n0 0\n3 1\n4 3\n",
"1\n2\n30 10\n31 21\n",
"1\n4\n1 0\n5 4\n10 5\n11 7\n",
"1\n4\n3 2\n5 4\n8 8\n9 9\n",
"1\n2\n10 1\n11 10\n",
"1\n3\n0 0\n10 5\n11 8\n",
"1\n3\n1 1\n100 1\n101 10\n",
"1\n3\n4 2\n5 4\n6 5\n",
"1\n2\n11 1\n12 3\n",
"1\n11\n1 1\n1 1\n3 1\n20 18\n21 19\n43 41\n43 41\n44 42\n46 44\n47 45\n48 47\n",
"1\n2\n8 1\n9 5\n",
"1\n2\n5 2\n9 8\n",
"1\n5\n25 10\n26 12\n27 13\n28 14\n29 15\n",
"1\n2\n2 1\n3 3\n",
"1\n2\n5 0\n7 4\n",
"1\n2\n13 10\n16 15\n",
"1\n2\n10 3\n11 5\n",
"1\n5\n1 0\n1 0\n5 5\n6 6\n7 7\n",
"1\n2\n5 1\n6 4\n",
"1\n2\n6 1\n8 4\n",
"1\n2\n5 2\n15 14\n",
"1\n3\n0 0\n5 3\n6 6\n",
"1\n3\n0 0\n3 1\n4 3\n",
"1\n2\n3 1\n5 4\n",
"1\n2\n2 1\n4 4\n",
"1\n2\n3 0\n5 5\n",
"1\n99\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n1 1\n",
"3\n2\n1 0\n4 4\n1\n1 2\n2\n4 0\n6 3\n",
"1\n4\n4 1\n5 1\n6 4\n6 4\n",
"4\n3\n2 1\n3 2\n4 4\n2\n5 3\n5 6\n2\n2 2\n3 2\n3\n1 1\n2 2\n145 1\n",
"5\n5\n42 18\n70 25\n82 28\n96 43\n99 48\n5\n85 49\n90 49\n92 50\n95 50\n99 50\n5\n37 50\n95 50\n100 50\n100 50\n100 50\n5\n59 34\n100 38\n100 38\n100 39\n100 41\n5\n40 39\n97 47\n97 50\n99 50\n100 50\n",
"1\n2\n3 1\n6 6\n",
"1\n2\n5 1\n8 5\n",
"1\n2\n108 1\n110 22\n",
"1\n2\n10 1\n11 3\n",
"1\n3\n5 1\n6 3\n7 4\n",
"2\n2\n4 1\n5 3\n2\n100 50\n101 99\n",
"1\n3\n1 1\n4 1\n5 3\n",
"1\n3\n1 1\n4 2\n5 4\n",
"1\n4\n0 0\n0 0\n2 1\n3 3\n",
"1\n3\n2 1\n4 1\n5 3\n",
"1\n2\n3 0\n5 3\n",
"1\n3\n10 5\n12 8\n13 9\n",
"1\n3\n5 0\n7 5\n8 8\n",
"1\n2\n5 2\n8 6\n",
"1\n3\n0 0\n5 3\n6 5\n",
"1\n3\n4 2\n6 5\n6 5\n",
"1\n2\n10 6\n15 12\n",
"1\n2\n10 1\n12 4\n",
"1\n2\n100 5\n101 10\n",
"1\n2\n100 3\n105 9\n",
"1\n2\n2 0\n3 3\n",
"1\n2\n100 0\n101 2\n"
],
"output": [
"NO\n",
"NO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"NO\nYES\nYES\nNO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\nYES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\nYES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\nNO\nYES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\nNO\nYES\n",
"NO\n",
"NO\nNO\n",
"YES\nYES\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\nNO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\nYES\nNO\nNO\nNO\nNO\nNO\nYES\nNO\nNO\n",
"NO\n",
"NO\nNO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\nYES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\nNO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"YES\n",
"NO\nNO\nNO\n",
"NO\n",
"NO\nNO\nYES\nNO\n",
"NO\nYES\nNO\nNO\nNO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\nNO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n",
"NO\n"
]
} | 1,200 | 0 |
2 | 9 | 1354_C2. Not So Simple Polygon Embedding | The statement of this problem is the same as the statement of problem C1. The only difference is that, in problem C1, n is always even, and in C2, n is always odd.
You are given a regular polygon with 2 β
n vertices (it's convex and has equal sides and equal angles) and all its sides have length 1. Let's name it as 2n-gon.
Your task is to find the square of the minimum size such that you can embed 2n-gon in the square. Embedding 2n-gon in the square means that you need to place 2n-gon in the square in such way that each point which lies inside or on a border of 2n-gon should also lie inside or on a border of the square.
You can rotate 2n-gon and/or the square.
Input
The first line contains a single integer T (1 β€ T β€ 200) β the number of test cases.
Next T lines contain descriptions of test cases β one per line. Each line contains single odd integer n (3 β€ n β€ 199). Don't forget you need to embed 2n-gon, not an n-gon.
Output
Print T real numbers β one per test case. For each test case, print the minimum length of a side of the square 2n-gon can be embedded in. Your answer will be considered correct if its absolute or relative error doesn't exceed 10^{-6}.
Example
Input
3
3
5
199
Output
1.931851653
3.196226611
126.687663595 | {
"input": [
"3\n3\n5\n199\n"
],
"output": [
"1.931851653\n3.196226611\n126.687663797\n"
]
} | {
"input": [
"99\n3\n5\n7\n9\n11\n13\n15\n17\n19\n21\n23\n25\n27\n29\n31\n33\n35\n37\n39\n41\n43\n45\n47\n49\n51\n53\n55\n57\n59\n61\n63\n65\n67\n69\n71\n73\n75\n77\n79\n81\n83\n85\n87\n89\n91\n93\n95\n97\n99\n101\n103\n105\n107\n109\n111\n113\n115\n117\n119\n121\n123\n125\n127\n129\n131\n133\n135\n137\n139\n141\n143\n145\n147\n149\n151\n153\n155\n157\n159\n161\n163\n165\n167\n169\n171\n173\n175\n177\n179\n181\n183\n185\n187\n189\n191\n193\n195\n197\n199\n",
"99\n29\n161\n177\n95\n195\n183\n83\n153\n63\n181\n111\n149\n23\n103\n17\n167\n135\n171\n147\n71\n115\n51\n169\n125\n49\n141\n193\n3\n21\n13\n139\n159\n101\n25\n5\n163\n113\n119\n73\n7\n67\n53\n151\n145\n107\n85\n89\n189\n191\n157\n81\n197\n79\n127\n59\n133\n87\n179\n137\n57\n165\n35\n55\n61\n121\n91\n117\n43\n143\n65\n37\n187\n33\n131\n175\n123\n109\n93\n11\n19\n199\n69\n45\n39\n75\n129\n173\n41\n105\n15\n9\n99\n155\n31\n97\n47\n185\n77\n27\n"
],
"output": [
"1.931851653\n3.196226611\n4.465702219\n5.736856623\n7.008771102\n8.281093968\n9.553661305\n10.826387200\n12.099221274\n13.372132512\n14.645100987\n15.918112605\n17.191158259\n18.464230694\n19.737324500\n21.010436133\n22.283562263\n23.556700727\n24.829849560\n26.103007187\n27.376172462\n28.649344249\n29.922522051\n31.195704692\n32.468891893\n33.742082996\n35.015277559\n36.288475370\n37.561676016\n38.834879126\n40.108084606\n41.381292209\n42.654501797\n43.927712932\n45.200925705\n46.474140148\n47.747355603\n49.020572617\n50.293790682\n51.567009723\n52.840229758\n54.113450760\n55.386672671\n56.659895296\n57.933118569\n59.206342682\n60.479567372\n61.752792818\n63.026018737\n64.299245193\n65.572472013\n66.845699518\n68.118927442\n69.392155812\n70.665384422\n71.938613686\n73.211842992\n74.485072905\n75.758303055\n77.031533374\n78.304764251\n79.577995147\n80.851226648\n82.124458183\n83.397689899\n84.670921988\n85.944154279\n87.217386648\n88.490619395\n89.763852237\n91.037085184\n92.310318534\n93.583551972\n94.856785462\n96.130019187\n97.403253104\n98.676487172\n99.949721352\n101.222955607\n102.496189900\n103.769424507\n105.042659319\n106.315894015\n107.589128889\n108.862363946\n110.135599080\n111.408834331\n112.682069666\n113.955304906\n115.228540565\n116.501776008\n117.775011837\n119.048247602\n120.321483288\n121.594719211\n122.867955301\n124.141191342\n125.414427604\n126.687663797\n",
"18.464230694\n102.496189900\n112.682069666\n60.479567372\n124.141191342\n116.501776008\n52.840229758\n97.403253104\n40.108084606\n115.228540565\n70.665384422\n94.856785462\n14.645100987\n65.572472013\n10.826387200\n106.315894015\n85.944154279\n108.862363946\n93.583551972\n45.200925705\n73.211842992\n32.468891893\n107.589128889\n79.577995147\n31.195704692\n89.763852237\n122.867955301\n1.931851653\n13.372132512\n8.281093968\n88.490619395\n101.222955607\n64.299245193\n15.918112605\n3.196226611\n103.769424507\n71.938613686\n75.758303055\n46.474140148\n4.465702219\n42.654501797\n33.742082996\n96.130019187\n92.310318534\n68.118927442\n54.113450760\n56.659895296\n120.321483288\n121.594719211\n99.949721352\n51.567009723\n125.414427604\n50.293790682\n80.851226648\n37.561676016\n84.670921988\n55.386672671\n113.955304906\n87.217386648\n36.288475370\n105.042659319\n22.283562263\n35.015277559\n38.834879126\n77.031533374\n57.933118569\n74.485072905\n27.376172462\n91.037085184\n41.381292209\n23.556700727\n119.048247602\n21.010436133\n83.397689899\n111.408834331\n78.304764251\n69.392155812\n59.206342682\n7.008771102\n12.099221274\n126.687663797\n43.927712932\n28.649344249\n24.829849560\n47.747355603\n82.124458183\n110.135599080\n26.103007187\n66.845699518\n9.553661305\n5.736856623\n63.026018737\n98.676487172\n19.737324500\n61.752792818\n29.922522051\n117.775011837\n49.020572617\n17.191158259\n"
]
} | 2,000 | 0 |
2 | 8 | 1374_B. Multiply by 2, divide by 6 | You are given an integer n. In one move, you can either multiply n by two or divide n by 6 (if it is divisible by 6 without the remainder).
Your task is to find the minimum number of moves needed to obtain 1 from n or determine if it's impossible to do that.
You have to answer t independent test cases.
Input
The first line of the input contains one integer t (1 β€ t β€ 2 β
10^4) β the number of test cases. Then t test cases follow.
The only line of the test case contains one integer n (1 β€ n β€ 10^9).
Output
For each test case, print the answer β the minimum number of moves needed to obtain 1 from n if it's possible to do that or -1 if it's impossible to obtain 1 from n.
Example
Input
7
1
2
3
12
12345
15116544
387420489
Output
0
-1
2
-1
-1
12
36
Note
Consider the sixth test case of the example. The answer can be obtained by the following sequence of moves from the given integer 15116544:
1. Divide by 6 and get 2519424;
2. divide by 6 and get 419904;
3. divide by 6 and get 69984;
4. divide by 6 and get 11664;
5. multiply by 2 and get 23328;
6. divide by 6 and get 3888;
7. divide by 6 and get 648;
8. divide by 6 and get 108;
9. multiply by 2 and get 216;
10. divide by 6 and get 36;
11. divide by 6 and get 6;
12. divide by 6 and get 1. | {
"input": [
"7\n1\n2\n3\n12\n12345\n15116544\n387420489\n"
],
"output": [
"0\n-1\n2\n-1\n-1\n12\n36\n"
]
} | {
"input": [
"1\n999838675\n"
],
"output": [
"-1\n"
]
} | 900 | 0 |
2 | 9 | 1397_C. Multiples of Length | You are given an array a of n integers.
You want to make all elements of a equal to zero by doing the following operation exactly three times:
* Select a segment, for each number in this segment we can add a multiple of len to it, where len is the length of this segment (added integers can be different).
It can be proven that it is always possible to make all elements of a equal to zero.
Input
The first line contains one integer n (1 β€ n β€ 100 000): the number of elements of the array.
The second line contains n elements of an array a separated by spaces: a_1, a_2, ..., a_n (-10^9 β€ a_i β€ 10^9).
Output
The output should contain six lines representing three operations.
For each operation, print two lines:
* The first line contains two integers l, r (1 β€ l β€ r β€ n): the bounds of the selected segment.
* The second line contains r-l+1 integers b_l, b_{l+1}, ..., b_r (-10^{18} β€ b_i β€ 10^{18}): the numbers to add to a_l, a_{l+1}, β¦, a_r, respectively; b_i should be divisible by r - l + 1.
Example
Input
4
1 3 2 4
Output
1 1
-1
3 4
4 2
2 4
-3 -6 -6 | {
"input": [
"4\n1 3 2 4\n"
],
"output": [
"1 1\n-1\n2 4\n9 6 12 \n1 4\n0 -12 -8 -16 \n"
]
} | {
"input": [
"2\n-492673762 -496405053\n",
"13\n-958184557 -577042357 -616514099 -553646903 -719490759 -761325526 -210773060 -44979753 864458686 -387054074 546903944 638449520 299190036\n",
"5\n450402558 -840167367 -231820501 586187125 -627664644\n",
"32\n474784688 671671886 -592758087 -662585781 997003198 333008394 111507813 985930436 -352098852 400811080 770280786 168025633 -258151427 726678951 914413742 -544810046 496546254 -749255284 -332401894 346164819 -207260314 68209011 940966817 -284672239 -655684691 845249877 -632338846 -531116897 486034507 609523579 721218400 848881449\n",
"1\n-1\n",
"3\n390029247 153996608 -918017777\n",
"17\n-542470641 -617247806 998970243 699622219 565143960 -860452587 447120886 203125491 707835273 960261677 908578885 550556483 718584588 -844249102 -360207707 702669908 297223934\n",
"7\n805743163 -181176136 454376774 681211377 988713965 -599336611 -823748404\n",
"8\n-311553829 469225525 -933496047 -592182543 -29674334 -268378634 -985852520 -225395842\n",
"6\n-76959846 -779700294 380306679 -340361999 58979764 -392237502\n",
"19\n-482097330 -201346367 -19865188 742768969 -113444726 -736593719 -223932141 474661760 -517960081 -808531390 -667493854 90097774 -45779385 200613819 -132533405 -931316230 -69997546 -623661790 -4421275\n",
"4\n-432300451 509430974 -600857890 -140418957\n",
"1\n-2\n",
"4\n1 3 2 4\n",
"16\n-15108237 489260742 681810357 -78861365 -416467743 -896443270 904192296 -932642644 173249302 402207268 -329323498 537696045 -899233426 902347982 -595589754 -480337024\n",
"1\n34688642\n",
"11\n686474839 417121618 697288626 -353703861 -630836661 -885184394 755247261 -611483316 -204713255 -618261009 -223868114\n"
],
"output": [
"1 2\n985347524 992810106 \n1 1\n-492673762 \n2 2\n-496405053 \n",
"1 1\n958184557\n2 13\n-6924508284 -7398169188 -6643762836 -8633889108 -9135906312 -2529276720 -539757036 10373504232 -4644648888 6562847328 7661394240 3590280432 \n1 13\n0 \n7501550641 \n8014683287 \n7197409739 \n9353379867 \n9897231838 \n2740049780 \n584736789 \n-11237962918 \n5031702962 \n-7109751272 \n-8299843760 \n-3889470468 \n",
"1 1\n-450402558\n2 5\n-3360669468 -927282004 2344748500 -2510658576 \n1 5\n0 \n4200836835 \n1159102505 \n-2930935625 \n3138323220 \n",
"1 1\n-474784688\n2 32\n20821828466 -18375500697 -20540159211 30907099138 10323260214 3456742203 30563843516 -10915064412 12425143480 23878704366 5208794623 -8002694237 22527047481 28346826002 -16889111426 15392933874 -23226913804 -10304458714 10731109389 -6425069734 2114479341 29169971327 -8824839409 -20326225421 26202746187 -19602504226 -16464623807 15067069717 18895230949 22357770400 26315324919 \n1 32\n0 -21493500352 18968258784 21202744992 -31904102336 -10656268608 -3568250016 -31549773952 11267163264 -12825954560 -24648985152 -5376820256 8260845664 -23253726432 -29261239744 17433921472 -15889480128 23976169088 10636860608 -11077274208 6632330048 -2182688352 -30110938144 9109511648 20981910112 -27047996064 20234843072 16995740704 -15553104224 -19504754528 -23078988800 -27164206368 \n",
"1 1\n1\n1 1\n0\n1 1\n0\n",
"1 1\n-390029247\n2 3\n307993216 -1836035554 \n1 3\n0 \n-461989824 \n2754053331 \n",
"1 1\n542470641\n2 17\n-9875964896 15983523888 11193955504 9042303360 -13767241392 7153934176 3250007856 11325364368 15364186832 14537262160 8808903728 11497353408 -13507985632 -5763323312 11242718528 4755582944 \n1 17\n0 \n10493212702 \n-16982494131 \n-11893577723 \n-9607447320 \n14627693979 \n-7601055062 \n-3453133347 \n-12033199641 \n-16324448509 \n-15445841045 \n-9359460211 \n-12215937996 \n14352234734 \n6123531019 \n-11945388436 \n-5052806878 \n",
"1 1\n-805743163\n2 7\n-1087056816 2726260644 4087268262 5932283790 -3596019666 -4942490424 \n1 7\n0 \n1268232952 \n-3180637418 \n-4768479639 \n-6920997755 \n4195356277 \n5766238828 \n",
"1 1\n311553829\n2 8\n3284578675 -6534472329 -4145277801 -207720338 -1878650438 -6900967640 -1577770894 \n1 8\n0 -3753804200 7467968376 4737460344 237394672 2147029072 7886820160 1803166736 \n",
"1 1\n76959846\n2 6\n-3898501470 1901533395 -1701809995 294898820 -1961187510 \n1 6\n0 4678201764 -2281840074 2042171994 -353878584 2353425012 \n",
"1 1\n482097330\n2 19\n-3624234606 -357573384 13369841442 -2042005068 -13258686942 -4030778538 8543911680 -9323281458 -14553565020 -12014889372 1621759932 -824028930 3611048742 -2385601290 -16763692140 -1259955828 -11225912220 -79582950 \n1 19\n0 \n3825580973 \n377438572 \n-14112610411 \n2155449794 \n13995280661 \n4254710679 \n-9018573440 \n9841241539 \n15362096410 \n12682383226 \n-1711857706 \n869808315 \n-3811662561 \n2518134695 \n17695008370 \n1329953374 \n11849574010 \n84004225 \n",
"1 1\n432300451\n2 4\n1528292922 -1802573670 -421256871 \n1 4\n0 -2037723896 2403431560 561675828 \n",
"1 1\n2\n1 1\n0\n1 1\n0\n",
"1 1\n-1\n2 4\n9 6 12 \n1 4\n0 -12 -8 -16 \n",
"1 1\n15108237\n2 16\n7338911130 10227155355 -1182920475 -6247016145 -13446649050 13562884440 -13989639660 2598739530 6033109020 -4939852470 8065440675 -13488501390 13535219730 -8933846310 -7205055360 \n1 16\n0 -7828171872 -10908965712 1261781840 6663483888 14343092320 -14467076736 14922282304 -2771988832 -6435316288 5269175968 -8603136720 14387734816 -14437567712 9529436064 7685392384 \n",
"1 1\n-34688642\n1 1\n0\n1 1\n0\n",
"1 1\n-686474839\n2 11\n4171216180 6972886260 -3537038610 -6308366610 -8851843940 7552472610 -6114833160 -2047132550 -6182610090 -2238681140 \n1 11\n0 \n-4588337798 \n-7670174886 \n3890742471 \n6939203271 \n9737028334 \n-8307719871 \n6726316476 \n2251845805 \n6800871099 \n2462549254 \n"
]
} | 1,600 | 500 |
2 | 10 | 1420_D. Rescue Nibel! | Ori and Sein have overcome many difficult challenges. They finally lit the Shrouded Lantern and found Gumon Seal, the key to the Forlorn Ruins. When they tried to open the door to the ruins... nothing happened.
Ori was very surprised, but Sein gave the explanation quickly: clever Gumon decided to make an additional defence for the door.
There are n lamps with Spirit Tree's light. Sein knows the time of turning on and off for the i-th lamp β l_i and r_i respectively. To open the door you have to choose k lamps in such a way that there will be a moment of time when they all will be turned on.
While Sein decides which of the k lamps to pick, Ori is interested: how many ways there are to pick such k lamps that the door will open? It may happen that Sein may be wrong and there are no such k lamps. The answer might be large, so print it modulo 998 244 353.
Input
First line contains two integers n and k (1 β€ n β€ 3 β
10^5, 1 β€ k β€ n) β total number of lamps and the number of lamps that must be turned on simultaneously.
Next n lines contain two integers l_i ans r_i (1 β€ l_i β€ r_i β€ 10^9) β period of time when i-th lamp is turned on.
Output
Print one integer β the answer to the task modulo 998 244 353.
Examples
Input
7 3
1 7
3 8
4 5
6 7
1 3
5 10
8 9
Output
9
Input
3 1
1 1
2 2
3 3
Output
3
Input
3 2
1 1
2 2
3 3
Output
0
Input
3 3
1 3
2 3
3 3
Output
1
Input
5 2
1 3
2 4
3 5
4 6
5 7
Output
7
Note
In first test case there are nine sets of k lamps: (1, 2, 3), (1, 2, 4), (1, 2, 5), (1, 2, 6), (1, 3, 6), (1, 4, 6), (2, 3, 6), (2, 4, 6), (2, 6, 7).
In second test case k=1, so the answer is 3.
In third test case there are no such pairs of lamps.
In forth test case all lamps are turned on in a time 3, so the answer is 1.
In fifth test case there are seven sets of k lamps: (1, 2), (1, 3), (2, 3), (2, 4), (3, 4), (3, 5), (4, 5). | {
"input": [
"3 3\n1 3\n2 3\n3 3\n",
"3 1\n1 1\n2 2\n3 3\n",
"7 3\n1 7\n3 8\n4 5\n6 7\n1 3\n5 10\n8 9\n",
"3 2\n1 1\n2 2\n3 3\n",
"5 2\n1 3\n2 4\n3 5\n4 6\n5 7\n"
],
"output": [
"1\n",
"3\n",
"9\n",
"0\n",
"7\n"
]
} | {
"input": [
"10 7\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"2 2\n1 1\n1 1\n",
"20 12\n18525 35038\n15816 31586\n18641 46864\n35863 38632\n13563 35915\n41614 98684\n13573 35863\n25851 35985\n41687 55831\n31583 80871\n18525 35038\n15816 31586\n18641 46864\n35863 38632\n13563 35915\n41614 98684\n13573 35863\n25851 35985\n41687 55831\n31583 80871\n",
"20 7\n18525 35038\n15816 31586\n18641 46864\n35863 38632\n13563 35915\n41614 98684\n13573 35863\n25851 35985\n41687 55831\n31583 80871\n18525 35038\n15816 31586\n18641 46864\n35863 38632\n13563 35915\n41614 98684\n13573 35863\n25851 35985\n41687 55831\n31583 80871\n",
"10 5\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"1 1\n13371337 42424242\n",
"10 3\n1 10\n2 10\n3 10\n4 10\n5 10\n1 2\n1 3\n1 4\n1 5\n1 6\n",
"1 1\n1 1\n",
"2 1\n1 1\n1 1\n"
],
"output": [
"4\n",
"1\n",
"92\n",
"4112\n",
"66\n",
"1\n",
"80\n",
"1\n",
"2\n"
]
} | 1,800 | 2,000 |
2 | 9 | 167_C. Wizards and Numbers | In some country live wizards. They love playing with numbers.
The blackboard has two numbers written on it β a and b. The order of the numbers is not important. Let's consider a β€ b for the sake of definiteness. The players can cast one of the two spells in turns:
* Replace b with b - ak. Number k can be chosen by the player, considering the limitations that k > 0 and b - ak β₯ 0. Number k is chosen independently each time an active player casts a spell.
* Replace b with b mod a.
If a > b, similar moves are possible.
If at least one of the numbers equals zero, a player can't make a move, because taking a remainder modulo zero is considered somewhat uncivilized, and it is far too boring to subtract a zero. The player who cannot make a move, loses.
To perform well in the magic totalizator, you need to learn to quickly determine which player wins, if both wizards play optimally: the one that moves first or the one that moves second.
Input
The first line contains a single integer t β the number of input data sets (1 β€ t β€ 104). Each of the next t lines contains two integers a, b (0 β€ a, b β€ 1018). The numbers are separated by a space.
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.
Output
For any of the t input sets print "First" (without the quotes) if the player who moves first wins. Print "Second" (without the quotes) if the player who moves second wins. Print the answers to different data sets on different lines in the order in which they are given in the input.
Examples
Input
4
10 21
31 10
0 1
10 30
Output
First
Second
Second
First
Note
In the first sample, the first player should go to (11,10). Then, after a single move of the second player to (1,10), he will take 10 modulo 1 and win.
In the second sample the first player has two moves to (1,10) and (21,10). After both moves the second player can win.
In the third sample, the first player has no moves.
In the fourth sample, the first player wins in one move, taking 30 modulo 10. | {
"input": [
"4\n10 21\n31 10\n0 1\n10 30\n"
],
"output": [
"First\nSecond\nSecond\nFirst\n"
]
} | {
"input": [
"7\n576460752303423487 2\n82 9\n101 104\n10 21\n31 10\n0 1\n10 30\n",
"1\n128817972817282999 327672410994637530\n",
"66\n7 0\n5 7\n1 3\n3 2\n3 5\n0 6\n1 2\n0 7\n4 5\n4 7\n5 1\n2 0\n4 0\n0 5\n3 6\n7 3\n6 0\n5 2\n6 6\n1 7\n5 6\n2 2\n3 4\n2 1\n5 3\n4 6\n6 2\n3 3\n100000000000 1000000000000000000\n0 1\n4 1\n2 6\n5 5\n4 3\n0 3\n3 7\n3 1\n1 0\n4 4\n1000000000000000000 100000000000\n7 6\n4 2\n7 5\n1 6\n6 1\n2 7\n7 7\n6 7\n2 4\n0 2\n2 5\n7 2\n0 0\n5 0\n5 4\n7 4\n6 4\n0 4\n1 1\n6 5\n1 4\n2 3\n1 5\n7 1\n6 3\n3 0\n",
"1\n100000000000 100000000001\n",
"1\n23917 1000000000000000000\n"
],
"output": [
"First\nSecond\nSecond\nFirst\nSecond\nSecond\nFirst\n",
"First\n",
"Second\nSecond\nFirst\nSecond\nFirst\nSecond\nFirst\nSecond\nSecond\nFirst\nFirst\nSecond\nSecond\nSecond\nFirst\nFirst\nSecond\nFirst\nFirst\nFirst\nSecond\nFirst\nSecond\nFirst\nFirst\nSecond\nFirst\nFirst\nFirst\nSecond\nFirst\nFirst\nFirst\nSecond\nSecond\nFirst\nFirst\nSecond\nFirst\nFirst\nSecond\nFirst\nSecond\nFirst\nFirst\nFirst\nFirst\nSecond\nFirst\nSecond\nFirst\nFirst\nSecond\nSecond\nSecond\nFirst\nSecond\nSecond\nFirst\nSecond\nFirst\nSecond\nFirst\nFirst\nFirst\nSecond\n",
"Second\n",
"Second\n"
]
} | 2,300 | 1,500 |