info
large_stringlengths 120
50k
| question
large_stringlengths 504
10.4k
| avg@8_qwen3_4b_instruct_2507
float64 0
0.88
|
|---|---|---|
{"tests": "{\"inputs\": [\"6\\nADD 1\\nACCEPT 1\\nADD 2\\nACCEPT 2\\nADD 3\\nACCEPT 3\\n\", \"4\\nADD 1\\nADD 2\\nADD 3\\nACCEPT 2\\n\", \"7\\nADD 1\\nADD 2\\nADD 3\\nADD 4\\nADD 5\\nACCEPT 3\\nACCEPT 5\\n\", \"6\\nADD 10\\nADD 7\\nADD 13\\nADD 15\\nADD 12\\nACCEPT 10\\n\", \"8\\nADD 10\\nADD 7\\nADD 13\\nADD 15\\nADD 12\\nACCEPT 10\\nADD 11\\nADD 8\\n\", \"15\\nADD 14944938\\nADD 40032655\\nACCEPT 14944938\\nACCEPT 40032655\\nADD 79373162\\nACCEPT 79373162\\nADD 55424250\\nACCEPT 55424250\\nADD 67468892\\nACCEPT 67468892\\nADD 51815959\\nADD 13976252\\nADD 2040654\\nADD 74300637\\nACCEPT 51815959\\n\", \"12\\nADD 85752704\\nACCEPT 85752704\\nADD 82888551\\nADD 31364670\\nACCEPT 82888551\\nADD 95416363\\nADD 27575237\\nADD 47306380\\nACCEPT 31364670\\nACCEPT 47306380\\nADD 22352020\\nADD 32836602\\n\", \"5\\nADD 187264133\\nACCEPT 187264133\\nADD 182071021\\nACCEPT 182071021\\nADD 291739970\\n\", \"1\\nADD 308983066\\n\"], \"outputs\": [\"8\\n\", \"2\\n\", \"0\\n\", \"2\\n\", \"6\\n\", \"32\\n\", \"8\\n\", \"8\\n\", \"2\\n\"]}", "source": "primeintellect"}
|
Let's consider a simplified version of order book of some stock. The order book is a list of orders (offers) from people that want to buy or sell one unit of the stock, each order is described by direction (BUY or SELL) and price.
At every moment of time, every SELL offer has higher price than every BUY offer.
In this problem no two ever existed orders will have the same price.
The lowest-price SELL order and the highest-price BUY order are called the best offers, marked with black frames on the picture below. [Image] The presented order book says that someone wants to sell the product at price $12$ and it's the best SELL offer because the other two have higher prices. The best BUY offer has price $10$.
There are two possible actions in this orderbook: Somebody adds a new order of some direction with some price. Somebody accepts the best possible SELL or BUY offer (makes a deal). It's impossible to accept not the best SELL or BUY offer (to make a deal at worse price). After someone accepts the offer, it is removed from the orderbook forever.
It is allowed to add new BUY order only with prices less than the best SELL offer (if you want to buy stock for higher price, then instead of adding an order you should accept the best SELL offer). Similarly, one couldn't add a new SELL order with price less or equal to the best BUY offer. For example, you can't add a new offer "SELL $20$" if there is already an offer "BUY $20$" or "BUY $25$" — in this case you just accept the best BUY offer.
You have a damaged order book log (in the beginning the are no orders in book). Every action has one of the two types: "ADD $p$" denotes adding a new order with price $p$ and unknown direction. The order must not contradict with orders still not removed from the order book. "ACCEPT $p$" denotes accepting an existing best offer with price $p$ and unknown direction.
The directions of all actions are lost. Information from the log isn't always enough to determine these directions. Count the number of ways to correctly restore all ADD action directions so that all the described conditions are satisfied at any moment. Since the answer could be large, output it modulo $10^9 + 7$. If it is impossible to correctly restore directions, then output $0$.
-----Input-----
The first line contains an integer $n$ ($1 \le n \le 363\,304$) — the number of actions in the log.
Each of the next $n$ lines contains a string "ACCEPT" or "ADD" and an integer $p$ ($1 \le p \le 308\,983\,066$), describing an action type and price.
All ADD actions have different prices. For ACCEPT action it is guaranteed that the order with the same price has already been added but has not been accepted yet.
-----Output-----
Output the number of ways to restore directions of ADD actions modulo $10^9 + 7$.
-----Examples-----
Input
6
ADD 1
ACCEPT 1
ADD 2
ACCEPT 2
ADD 3
ACCEPT 3
Output
8
Input
4
ADD 1
ADD 2
ADD 3
ACCEPT 2
Output
2
Input
7
ADD 1
ADD 2
ADD 3
ADD 4
ADD 5
ACCEPT 3
ACCEPT 5
Output
0
-----Note-----
In the first example each of orders may be BUY or SELL.
In the second example the order with price $1$ has to be BUY order, the order with the price $3$ has to be SELL order.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 1\\n1 2\\n1 2\\n\", \"4 3\\n1 3 2 4\\n1 2\\n2 3\\n1 4\\n\", \"7 4\\n7 6 4 2 1 5 3\\n1 3\\n2 1\\n7 2\\n3 5\\n\", \"10 1\\n1 2 3 4 5 6 7 8 9 10\\n1 10\\n\", \"9 20\\n9 8 7 6 5 4 3 2 1\\n4 6\\n9 4\\n5 9\\n6 8\\n1 9\\n5 8\\n6 9\\n7 3\\n1 9\\n8 3\\n4 5\\n9 6\\n3 8\\n4 1\\n1 2\\n3 2\\n4 9\\n6 7\\n7 5\\n9 6\\n\", \"20 7\\n3 17 7 14 11 4 1 18 20 19 13 12 5 6 15 16 9 2 8 10\\n19 13\\n20 6\\n19 11\\n12 3\\n10 19\\n14 10\\n3 16\\n\", \"100 1\\n78 52 95 76 96 49 53 59 77 100 64 11 9 48 15 17 44 46 21 54 39 68 43 4 32 28 73 6 16 62 72 84 65 86 98 75 33 45 25 3 91 82 2 92 63 88 7 50 97 93 14 22 20 42 60 55 80 85 29 34 56 71 83 38 26 47 90 70 51 41 40 31 37 12 35 99 67 94 1 87 57 8 61 19 23 79 36 18 66 74 5 27 81 69 24 58 13 10 89 30\\n17 41\\n\", \"125 8\\n111 69 3 82 24 38 4 39 42 22 92 6 16 10 8 45 17 91 84 53 5 46 124 47 18 57 43 73 114 102 121 105 118 95 104 98 72 20 56 60 123 80 103 70 65 107 67 112 101 108 99 49 12 94 2 68 119 109 59 40 86 116 88 63 110 14 13 120 41 64 89 71 15 35 81 51 113 90 55 122 1 75 54 33 28 7 125 9 100 115 19 58 61 83 117 52 106 87 11 50 93 32 21 96 26 78 48 79 23 36 66 27 31 62 25 77 30 74 76 44 97 85 29 34 37\\n33 17\\n84 103\\n71 33\\n5 43\\n23 15\\n65 34\\n125 58\\n51 69\\n\", \"100 2\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\\n88 90\\n62 77\\n\"], \"outputs\": [\"0.500000000\\n\", \"3.000000000\\n\", \"11.250000000\\n\", \"8.500000000\\n\", \"20.105407715\\n\", \"102.250000000\\n\", \"2659.500000000\\n\", \"3919.000000000\\n\", \"16.000000000\\n\"]}", "source": "primeintellect"}
|
The Little Elephant loves permutations of integers from 1 to n very much. But most of all he loves sorting them. To sort a permutation, the Little Elephant repeatedly swaps some elements. As a result, he must receive a permutation 1, 2, 3, ..., n.
This time the Little Elephant has permutation p_1, p_2, ..., p_{n}. Its sorting program needs to make exactly m moves, during the i-th move it swaps elements that are at that moment located at the a_{i}-th and the b_{i}-th positions. But the Little Elephant's sorting program happened to break down and now on every step it can equiprobably either do nothing or swap the required elements.
Now the Little Elephant doesn't even hope that the program will sort the permutation, but he still wonders: if he runs the program and gets some permutation, how much will the result of sorting resemble the sorted one? For that help the Little Elephant find the mathematical expectation of the number of permutation inversions after all moves of the program are completed.
We'll call a pair of integers i, j (1 ≤ i < j ≤ n) an inversion in permutatuon p_1, p_2, ..., p_{n}, if the following inequality holds: p_{i} > p_{j}.
-----Input-----
The first line contains two integers n and m (1 ≤ n, m ≤ 1000, n > 1) — the permutation size and the number of moves. The second line contains n distinct integers, not exceeding n — the initial permutation. Next m lines each contain two integers: the i-th line contains integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the positions of elements that were changed during the i-th move.
-----Output-----
In the only line print a single real number — the answer to the problem. The answer will be considered correct if its relative or absolute error does not exceed 10^{ - 6}.
-----Examples-----
Input
2 1
1 2
1 2
Output
0.500000000
Input
4 3
1 3 2 4
1 2
2 3
1 4
Output
3.000000000
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1 1 3 4\\n7\\n\", \"4 3 4 2\\n7 9 11\\n\", \"10 10 51 69\\n154 170 170 183 251 337 412 426 445 452\\n\", \"70 10 26 17\\n361 371 579 585 629 872 944 1017 1048 1541\\n\", \"100 20 49 52\\n224 380 690 1585 1830 1973 2490 2592 3240 3341 3406 3429 3549 3560 3895 3944 4344 4390 4649 4800\\n\", \"100 30 36 47\\n44 155 275 390 464 532 1186 1205 1345 1349 1432 1469 1482 1775 1832 1856 1869 2049 2079 2095 2374 2427 2577 2655 2792 2976 3020 3317 3482 3582\\n\", \"97 60 1 1\\n5 6 6 7 9 10 10 11 11 11 12 13 13 13 13 14 14 15 16 18 20 23 23 24 25 26 29 31 32 35 38 41 43 43 46 47 48 48 49 52 53 54 55 56 58 59 68 70 72 74 78 81 81 82 91 92 96 96 97 98\\n\", \"1000000000 1 157 468\\n57575875712\\n\", \"1000000000 1 1000000000 1000000000000000000\\n1000000000000000000\\n\"], \"outputs\": [\"1\\n\", \"4\\n\", \"6\\n\", \"70\\n\", \"55\\n\", \"51\\n\", \"49\\n\", \"333333334\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
There is an automatic door at the entrance of a factory. The door works in the following way: when one or several people come to the door and it is closed, the door immediately opens automatically and all people immediately come inside, when one or several people come to the door and it is open, all people immediately come inside, opened door immediately closes in d seconds after its opening, if the door is closing and one or several people are coming to the door at the same moment, then all of them will have enough time to enter and only after that the door will close.
For example, if d = 3 and four people are coming at four different moments of time t_1 = 4, t_2 = 7, t_3 = 9 and t_4 = 13 then the door will open three times: at moments 4, 9 and 13. It will close at moments 7 and 12.
It is known that n employees will enter at moments a, 2·a, 3·a, ..., n·a (the value a is positive integer). Also m clients will enter at moments t_1, t_2, ..., t_{m}.
Write program to find the number of times the automatic door will open. Assume that the door is initially closed.
-----Input-----
The first line contains four integers n, m, a and d (1 ≤ n, a ≤ 10^9, 1 ≤ m ≤ 10^5, 1 ≤ d ≤ 10^18) — the number of the employees, the number of the clients, the moment of time when the first employee will come and the period of time in which the door closes.
The second line contains integer sequence t_1, t_2, ..., t_{m} (1 ≤ t_{i} ≤ 10^18) — moments of time when clients will come. The values t_{i} are given in non-decreasing order.
-----Output-----
Print the number of times the door will open.
-----Examples-----
Input
1 1 3 4
7
Output
1
Input
4 3 4 2
7 9 11
Output
4
-----Note-----
In the first example the only employee will come at moment 3. At this moment the door will open and will stay open until the moment 7. At the same moment of time the client will come, so at first he will enter and only after it the door will close. Thus the door will open one time.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\n1 4 3 2 5\\n\", \"5\\n1 2 2 2 1\\n\", \"7\\n10 20 40 50 70 90 30\\n\", \"1\\n1\\n\", \"2\\n1 15\\n\", \"4\\n36 54 55 9\\n\", \"5\\n984181411 215198610 969039668 60631313 85746445\\n\", \"10\\n12528139 986722043 1595702 997595062 997565216 997677838 999394520 999593240 772077 998195916\\n\", \"100\\n9997 9615 4045 2846 7656 2941 2233 9214 837 2369 5832 578 6146 8773 164 7303 3260 8684 2511 6608 9061 9224 7263 7279 1361 1823 8075 5946 2236 6529 6783 7494 510 1217 1135 8745 6517 182 8180 2675 6827 6091 2730 897 1254 471 1990 1806 1706 2571 8355 5542 5536 1527 886 2093 1532 4868 2348 7387 5218 3181 3140 3237 4084 9026 504 6460 9256 6305 8827 840 2315 5763 8263 5068 7316 9033 7552 9939 8659 6394 4566 3595 2947 2434 1790 2673 6291 6736 8549 4102 953 8396 8985 1053 5906 6579 5854 6805\\n\"], \"outputs\": [\"6\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"778956192\\n\", \"1982580029\\n\", \"478217\\n\"]}", "source": "primeintellect"}
|
Polycarp plans to conduct a load testing of its new project Fakebook. He already agreed with his friends that at certain points in time they will send requests to Fakebook. The load testing will last n minutes and in the i-th minute friends will send a_{i} requests.
Polycarp plans to test Fakebook under a special kind of load. In case the information about Fakebook gets into the mass media, Polycarp hopes for a monotone increase of the load, followed by a monotone decrease of the interest to the service. Polycarp wants to test this form of load.
Your task is to determine how many requests Polycarp must add so that before some moment the load on the server strictly increases and after that moment strictly decreases. Both the increasing part and the decreasing part can be empty (i. e. absent). The decrease should immediately follow the increase. In particular, the load with two equal neigbouring values is unacceptable.
For example, if the load is described with one of the arrays [1, 2, 8, 4, 3], [1, 3, 5] or [10], then such load satisfies Polycarp (in each of the cases there is an increasing part, immediately followed with a decreasing part). If the load is described with one of the arrays [1, 2, 2, 1], [2, 1, 2] or [10, 10], then such load does not satisfy Polycarp.
Help Polycarp to make the minimum number of additional requests, so that the resulting load satisfies Polycarp. He can make any number of additional requests at any minute from 1 to n.
-----Input-----
The first line contains a single integer n (1 ≤ n ≤ 100 000) — the duration of the load testing.
The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9), where a_{i} is the number of requests from friends in the i-th minute of the load testing.
-----Output-----
Print the minimum number of additional requests from Polycarp that would make the load strictly increasing in the beginning and then strictly decreasing afterwards.
-----Examples-----
Input
5
1 4 3 2 5
Output
6
Input
5
1 2 2 2 1
Output
1
Input
7
10 20 40 50 70 90 30
Output
0
-----Note-----
In the first example Polycarp must make two additional requests in the third minute and four additional requests in the fourth minute. So the resulting load will look like: [1, 4, 5, 6, 5]. In total, Polycarp will make 6 additional requests.
In the second example it is enough to make one additional request in the third minute, so the answer is 1.
In the third example the load already satisfies all conditions described in the statement, so the answer is 0.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"tinkoff\\nzscoder\\n\", \"xxxxxx\\nxxxxxx\\n\", \"ioi\\nimo\\n\", \"abc\\naaa\\n\", \"reddit\\nabcdef\\n\", \"cbxz\\naaaa\\n\", \"bcdef\\nabbbc\\n\", \"z\\ny\\n\", \"y\\nz\\n\"], \"outputs\": [\"fzfsirk\\n\", \"xxxxxx\\n\", \"ioi\\n\", \"aab\\n\", \"dfdeed\\n\", \"abac\\n\", \"bccdb\\n\", \"z\\n\", \"y\\n\"]}", "source": "primeintellect"}
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s ≠ t) if s_{i} < t_{i} where i is the smallest index such that s_{i} ≠ t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 ≤ n ≤ 3·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n5\\n231\\n7\\n2323\\n6\\n333\\n24\\n133321333\\n\", \"9\\n1500\\n1212\\n1500\\n1221\\n1500\\n122\\n1500\\n12121\\n1500\\n22\\n1500\\n1111112111111112\\n1500\\n1111111111221111111\\n1500\\n111111122\\n1500\\n11111121111121111111\\n\", \"1\\n1000000\\n22\\n\", \"1\\n1000000\\n221\\n\", \"1\\n1000000\\n1221\\n\", \"1\\n1000000\\n2121\\n\", \"1\\n1000000\\n2211\\n\", \"1\\n1000000\\n1212\\n\", \"1\\n1000000\\n2112\\n\"], \"outputs\": [\"25\\n1438\\n1101\\n686531475\\n\", \"1504\\n1599\\n1502\\n1598\\n1502\\n1510\\n1657\\n1502\\n1763\\n\", \"1000002\\n\", \"1001822\\n\", \"1001823\\n\", \"1001821\\n\", \"1002004\\n\", \"1000004\\n\", \"1000006\\n\"]}", "source": "primeintellect"}
|
We start with a string $s$ consisting only of the digits $1$, $2$, or $3$. The length of $s$ is denoted by $|s|$. For each $i$ from $1$ to $|s|$, the $i$-th character of $s$ is denoted by $s_i$.
There is one cursor. The cursor's location $\ell$ is denoted by an integer in $\{0, \ldots, |s|\}$, with the following meaning: If $\ell = 0$, then the cursor is located before the first character of $s$. If $\ell = |s|$, then the cursor is located right after the last character of $s$. If $0 < \ell < |s|$, then the cursor is located between $s_\ell$ and $s_{\ell+1}$.
We denote by $s_\text{left}$ the string to the left of the cursor and $s_\text{right}$ the string to the right of the cursor.
We also have a string $c$, which we call our clipboard, which starts out as empty. There are three types of actions: The Move action. Move the cursor one step to the right. This increments $\ell$ once. The Cut action. Set $c \leftarrow s_\text{right}$, then set $s \leftarrow s_\text{left}$. The Paste action. Append the value of $c$ to the end of the string $s$. Note that this doesn't modify $c$.
The cursor initially starts at $\ell = 0$. Then, we perform the following procedure: Perform the Move action once. Perform the Cut action once. Perform the Paste action $s_\ell$ times. If $\ell = x$, stop. Otherwise, return to step 1.
You're given the initial string $s$ and the integer $x$. What is the length of $s$ when the procedure stops? Since this value may be very large, only find it modulo $10^9 + 7$.
It is guaranteed that $\ell \le |s|$ at any time.
-----Input-----
The first line of input contains a single integer $t$ ($1 \le t \le 1000$) denoting the number of test cases. The next lines contain descriptions of the test cases.
The first line of each test case contains a single integer $x$ ($1 \le x \le 10^6$). The second line of each test case consists of the initial string $s$ ($1 \le |s| \le 500$). It is guaranteed, that $s$ consists of the characters "1", "2", "3".
It is guaranteed that the sum of $x$ in a single file is at most $10^6$. It is guaranteed that in each test case before the procedure will stop it will be true that $\ell \le |s|$ at any time.
-----Output-----
For each test case, output a single line containing a single integer denoting the answer for that test case modulo $10^9 + 7$.
-----Example-----
Input
4
5
231
7
2323
6
333
24
133321333
Output
25
1438
1101
686531475
-----Note-----
Let's illustrate what happens with the first test case. Initially, we have $s = $ 231. Initially, $\ell = 0$ and $c = \varepsilon$ (the empty string). The following things happen if we follow the procedure above:
Step 1, Move once: we get $\ell = 1$. Step 2, Cut once: we get $s = $ 2 and $c = $ 31. Step 3, Paste $s_\ell = $ 2 times: we get $s = $ 23131. Step 4: $\ell = 1 \not= x = 5$, so we return to step 1.
Step 1, Move once: we get $\ell = 2$. Step 2, Cut once: we get $s = $ 23 and $c = $ 131. Step 3, Paste $s_\ell = $ 3 times: we get $s = $ 23131131131. Step 4: $\ell = 2 \not= x = 5$, so we return to step 1.
Step 1, Move once: we get $\ell = 3$. Step 2, Cut once: we get $s = $ 231 and $c = $ 31131131. Step 3, Paste $s_\ell = $ 1 time: we get $s = $ 23131131131. Step 4: $\ell = 3 \not= x = 5$, so we return to step 1.
Step 1, Move once: we get $\ell = 4$. Step 2, Cut once: we get $s = $ 2313 and $c = $ 1131131. Step 3, Paste $s_\ell = $ 3 times: we get $s = $ 2313113113111311311131131. Step 4: $\ell = 4 \not= x = 5$, so we return to step 1.
Step 1, Move once: we get $\ell = 5$. Step 2, Cut once: we get $s = $ 23131 and $c = $ 13113111311311131131. Step 3, Paste $s_\ell = $ 1 times: we get $s = $ 2313113113111311311131131. Step 4: $\ell = 5 = x$, so we stop.
At the end of the procedure, $s$ has length $25$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 0\\n3 7 3 7 3\\n\", \"10 0\\n1 2 1 2 3 1 1 1 50 1\\n\", \"6 0\\n6 6 3 3 4 4\\n\", \"7 0\\n3 3 1 3 2 1 2\\n\", \"5 0\\n1 2 1 2 1\\n\", \"5 0\\n2 3 2 3 3\\n\", \"100 0\\n6 7 100 8 5 61 5 75 59 65 51 47 83 37 34 54 87 46 4 26 21 87 12 97 86 68 60 11 62 76 14 83 29 31 91 62 57 80 47 75 85 97 62 77 91 86 14 25 48 77 83 65 39 61 78 77 45 46 90 74 100 91 86 98 55 5 84 42 91 69 100 4 74 98 60 37 75 44 41 12 15 34 36 1 99 16 7 87 36 26 79 42 41 84 17 98 72 16 38 55\\n\", \"100 0\\n91 32 10 38 92 14 100 7 48 72 47 10 76 99 56 53 41 46 68 18 37 47 61 99 16 60 12 51 17 50 69 8 82 78 34 95 3 15 79 4 51 45 83 91 81 68 79 91 16 30 6 86 72 97 63 75 67 14 50 60 1 13 77 37 57 14 65 79 41 62 15 11 74 56 76 62 54 52 9 96 8 27 44 21 59 57 17 53 15 66 49 94 62 58 71 53 88 97 65 37\\n\", \"100 0\\n44 8 97 30 48 96 35 54 42 9 66 27 99 57 74 97 90 24 78 97 98 55 74 56 25 30 34 26 12 87 77 12 7 49 79 2 95 33 72 50 47 28 95 31 99 27 96 43 9 62 6 21 55 22 10 79 71 27 85 37 32 66 54 61 48 48 10 61 57 78 91 41 30 43 29 70 96 4 36 19 50 99 16 68 8 80 55 74 18 35 54 84 70 9 17 77 69 71 67 24\\n\"], \"outputs\": [\"2\\n\", \"4\\n\", \"0\\n\", \"4\\n\", \"2\\n\", \"2\\n\", \"95\\n\", \"97\\n\", \"96\\n\"]}", "source": "primeintellect"}
|
This is an easier version of the next problem. In this version, $q = 0$.
A sequence of integers is called nice if its elements are arranged in blocks like in $[3, 3, 3, 4, 1, 1]$. Formally, if two elements are equal, everything in between must also be equal.
Let's define difficulty of a sequence as a minimum possible number of elements to change to get a nice sequence. However, if you change at least one element of value $x$ to value $y$, you must also change all other elements of value $x$ into $y$ as well. For example, for $[3, 3, 1, 3, 2, 1, 2]$ it isn't allowed to change first $1$ to $3$ and second $1$ to $2$. You need to leave $1$'s untouched or change them to the same value.
You are given a sequence of integers $a_1, a_2, \ldots, a_n$ and $q$ updates.
Each update is of form "$i$ $x$" — change $a_i$ to $x$. Updates are not independent (the change stays for the future).
Print the difficulty of the initial sequence and of the sequence after every update.
-----Input-----
The first line contains integers $n$ and $q$ ($1 \le n \le 200\,000$, $q = 0$), the length of the sequence and the number of the updates.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 200\,000$), the initial sequence.
Each of the following $q$ lines contains integers $i_t$ and $x_t$ ($1 \le i_t \le n$, $1 \le x_t \le 200\,000$), the position and the new value for this position.
-----Output-----
Print $q+1$ integers, the answer for the initial sequence and the answer after every update.
-----Examples-----
Input
5 0
3 7 3 7 3
Output
2
Input
10 0
1 2 1 2 3 1 1 1 50 1
Output
4
Input
6 0
6 6 3 3 4 4
Output
0
Input
7 0
3 3 1 3 2 1 2
Output
4
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n2 3\\n3 4\\n3 5\\n\", \"4 6\\n1 2\\n2 3\\n1 3\\n3 4\\n2 4\\n1 4\\n\", \"4 2\\n1 3\\n2 4\\n\", \"1 0\\n\", \"1000 0\\n\", \"1000 4\\n100 200\\n200 300\\n300 400\\n400 100\\n\", \"14 30\\n12 10\\n1 7\\n12 13\\n7 3\\n14 10\\n3 12\\n11 1\\n2 12\\n2 5\\n14 3\\n14 1\\n14 4\\n6 7\\n12 6\\n9 5\\n7 10\\n8 5\\n6 14\\n13 7\\n4 12\\n9 10\\n1 9\\n14 5\\n1 8\\n2 13\\n5 11\\n8 6\\n4 9\\n9 13\\n2 4\\n\", \"59 24\\n40 3\\n14 10\\n17 5\\n40 15\\n22 40\\n9 40\\n46 41\\n17 24\\n20 15\\n49 46\\n17 50\\n14 25\\n8 14\\n11 36\\n59 40\\n7 36\\n16 46\\n20 35\\n20 49\\n58 20\\n17 49\\n26 46\\n59 14\\n38 40\\n\"], \"outputs\": [\"3\\n\", \"-1\\n\", \"2\\n\", \"0\\n\", \"0\\n\", \"2\\n\", \"-1\\n\", \"10\\n\"]}", "source": "primeintellect"}
|
Vova and Marina love offering puzzles to each other. Today Marina offered Vova to cope with the following task.
Vova has a non-directed graph consisting of n vertices and m edges without loops and multiple edges. Let's define the operation of contraction two vertices a and b that are not connected by an edge. As a result of this operation vertices a and b are deleted and instead of them a new vertex x is added into the graph, and also edges are drawn from it to all vertices that were connected with a or with b (specifically, if the vertex was connected with both a and b, then also exactly one edge is added from x to it). Thus, as a result of contraction again a non-directed graph is formed, it contains no loops nor multiple edges, and it contains (n - 1) vertices.
Vova must perform the contraction an arbitrary number of times to transform the given graph into a chain of the maximum length. A chain of length k (k ≥ 0) is a connected graph whose vertices can be numbered with integers from 1 to k + 1 so that the edges of the graph connect all pairs of vertices (i, i + 1) (1 ≤ i ≤ k) and only them. Specifically, the graph that consists of one vertex is a chain of length 0. The vertices that are formed as a result of the contraction are allowed to be used in the following operations of contraction.
[Image] The picture illustrates the contraction of two vertices marked by red.
Help Vova cope with his girlfriend's task. Find the maximum length of the chain that can be obtained from the resulting graph or else determine that it is impossible to obtain the chain.
-----Input-----
The first line contains two integers n, m (1 ≤ n ≤ 1000, 0 ≤ m ≤ 100 000) — the number of vertices and the number of edges in the original graph.
Next m lines contain the descriptions of edges in the format a_{i}, b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}), which means that there is an edge between vertices a_{i} and b_{i}. It is guaranteed that there is at most one edge between each pair of vertexes.
-----Output-----
If it is impossible to obtain a chain from the given graph, print - 1. Otherwise, print the maximum possible number of edges in the resulting chain.
-----Examples-----
Input
5 4
1 2
2 3
3 4
3 5
Output
3
Input
4 6
1 2
2 3
1 3
3 4
2 4
1 4
Output
-1
Input
4 2
1 3
2 4
Output
2
-----Note-----
In the first sample test you can contract vertices 4 and 5 and obtain a chain of length 3.
In the second sample test it is initially impossible to contract any pair of vertexes, so it is impossible to achieve the desired result.
In the third sample test you can contract vertices 1 and 2 and obtain a chain of length 2.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6\\n\", \"9\\n\", \"2\\n\", \"10\\n\", \"100\\n\", \"1\\n\", \"3\\n\", \"5\\n\"], \"outputs\": [\"2\\n6 3\\n2 4\\n\", \"3\\n9 3\\n2 4\\n6 8\\n\", \"0\\n\", \"4\\n2 4\\n6 8\\n10 5\\n9 3\\n\", \"44\\n33 27\\n22 11\\n25 5\\n64 66\\n42 44\\n31 62\\n58 29\\n43 86\\n15 21\\n6 99\\n8 12\\n85 65\\n7 49\\n23 46\\n16 14\\n20 18\\n90 92\\n48 50\\n40 36\\n74 37\\n35 55\\n10 95\\n56 60\\n47 94\\n45 39\\n93 87\\n88 84\\n72 76\\n28 24\\n75 81\\n78 80\\n54 52\\n38 19\\n3 9\\n32 30\\n91 77\\n70 68\\n63 69\\n2 4\\n57 51\\n82 41\\n17 34\\n13 26\\n96 98\\n\", \"0\\n\", \"0\\n\", \"1\\n2 4\\n\"]}", "source": "primeintellect"}
|
Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.
Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.
Jzzhu wonders how to get the maximum possible number of groups. Can you help him?
-----Input-----
A single integer n (1 ≤ n ≤ 10^5), the number of the apples.
-----Output-----
The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.
If there are several optimal answers you can print any of them.
-----Examples-----
Input
6
Output
2
6 3
2 4
Input
9
Output
3
9 3
2 4
6 8
Input
2
Output
0
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n3 4 5\\n\", \"3\\n1 2 4\\n\", \"1\\n1\\n\", \"1\\n1000000\\n\", \"2\\n1000000 999999\\n\", \"12\\n4 4 10 13 28 30 41 43 58 61 70 88\\n\", \"7\\n2 13 22 32 72 91 96\\n\", \"5\\n5 11 12 109 110\\n\"], \"outputs\": [\"2\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"30\\n\", \"27\\n\", \"10\\n\"]}", "source": "primeintellect"}
|
You are given a sequence a consisting of n integers. Find the maximum possible value of $a_{i} \operatorname{mod} a_{j}$ (integer remainder of a_{i} divided by a_{j}), where 1 ≤ i, j ≤ n and a_{i} ≥ a_{j}.
-----Input-----
The first line contains integer n — the length of the sequence (1 ≤ n ≤ 2·10^5).
The second line contains n space-separated integers a_{i} (1 ≤ a_{i} ≤ 10^6).
-----Output-----
Print the answer to the problem.
-----Examples-----
Input
3
3 4 5
Output
2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.875
|
{"tests": "{\"inputs\": [\"3 3\\naaa\\n\", \"3 3\\naab\\n\", \"1 2\\na\\n\", \"10 9\\nabacadefgh\\n\", \"15 3\\nabababababababa\\n\", \"100 26\\njysrixyptvsesnapfljeqkytlpeepjopspmkviqdqbdkylvfiawhdjjdvqqvcjmmsgfdmpjwahuwhgsyfcgnefzmqlvtvqqfbfsf\\n\", \"1 26\\nz\\n\"], \"outputs\": [\"6\\n\", \"11\\n\", \"1\\n\", \"789\\n\", \"345\\n\", \"237400\\n\", \"25\\n\"]}", "source": "primeintellect"}
|
You are given a string S of length n with each character being one of the first m lowercase English letters.
Calculate how many different strings T of length n composed from the first m lowercase English letters exist such that the length of LCS (longest common subsequence) between S and T is n - 1.
Recall that LCS of two strings S and T is the longest string C such that C both in S and T as a subsequence.
-----Input-----
The first line contains two numbers n and m denoting the length of string S and number of first English lowercase characters forming the character set for strings (1 ≤ n ≤ 100 000, 2 ≤ m ≤ 26).
The second line contains string S.
-----Output-----
Print the only line containing the answer.
-----Examples-----
Input
3 3
aaa
Output
6
Input
3 3
aab
Output
11
Input
1 2
a
Output
1
Input
10 9
abacadefgh
Output
789
-----Note-----
For the first sample, the 6 possible strings T are: aab, aac, aba, aca, baa, caa.
For the second sample, the 11 possible strings T are: aaa, aac, aba, abb, abc, aca, acb, baa, bab, caa, cab.
For the third sample, the only possible string T is b.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"10\\nmihail\\noolyana\\nkooooper\\nhoon\\nulyana\\nkoouper\\nmikhail\\nkhun\\nkuooper\\nkkkhoon\\n\", \"9\\nhariton\\nhkariton\\nbuoi\\nkkkhariton\\nboooi\\nbui\\nkhariton\\nboui\\nboi\\n\", \"2\\nalex\\nalex\\n\", \"40\\nuok\\nkuu\\nku\\no\\nkku\\nuh\\nu\\nu\\nhh\\nk\\nkh\\nh\\nh\\nou\\nokh\\nukk\\nou\\nuhk\\nuo\\nuko\\nu\\nuu\\nh\\nh\\nhk\\nuhu\\nuoh\\nooo\\nk\\nh\\nuk\\nk\\nkku\\nh\\nku\\nok\\nk\\nkuu\\nou\\nhh\\n\", \"40\\noooo\\nhu\\no\\nhoh\\nkhk\\nuuh\\nhu\\nou\\nuuoh\\no\\nkouk\\nuouo\\nu\\nok\\nuu\\nuuuo\\nhoh\\nuu\\nkuu\\nh\\nu\\nkkoh\\nkhh\\nuoh\\nouuk\\nkuo\\nk\\nu\\nuku\\nh\\nu\\nk\\nhuho\\nku\\nh\\noo\\nuh\\nk\\nuo\\nou\\n\", \"100\\nuh\\nu\\nou\\nhk\\nokh\\nuou\\nk\\no\\nuhh\\nk\\noku\\nk\\nou\\nhuh\\nkoo\\nuo\\nkk\\nkok\\nhhu\\nuu\\noou\\nk\\nk\\noh\\nhk\\nk\\nu\\no\\nuo\\no\\no\\no\\nhoh\\nkuo\\nhuh\\nkhu\\nuu\\nk\\noku\\nk\\nh\\nuu\\nuo\\nhuo\\noo\\nhu\\nukk\\nok\\no\\noh\\nuo\\nkko\\nok\\nouh\\nkoh\\nhhu\\nku\\nko\\nhho\\nkho\\nkho\\nkhk\\nho\\nhk\\nuko\\nukh\\nh\\nkh\\nkk\\nuku\\nkkk\\no\\nuo\\no\\nouh\\nou\\nuhk\\nou\\nk\\nh\\nkko\\nuko\\no\\nu\\nho\\nu\\nooo\\nuo\\no\\nko\\noh\\nkh\\nuk\\nohk\\noko\\nuko\\nh\\nh\\noo\\no\\n\", \"2\\nkkkhkkh\\nhh\\n\"], \"outputs\": [\"4\\n\", \"5\\n\", \"1\\n\", \"21\\n\", \"25\\n\", \"36\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
There are some ambiguities when one writes Berland names with the letters of the Latin alphabet.
For example, the Berland sound u can be written in the Latin alphabet as "u", and can be written as "oo". For this reason, two words "ulyana" and "oolyana" denote the same name.
The second ambiguity is about the Berland sound h: one can use both "h" and "kh" to write it. For example, the words "mihail" and "mikhail" denote the same name.
There are n users registered on the Polycarp's website. Each of them indicated a name represented by the Latin letters. How many distinct names are there among them, if two ambiguities described above are taken into account?
Formally, we assume that two words denote the same name, if using the replacements "u" [Image] "oo" and "h" [Image] "kh", you can make the words equal. One can make replacements in both directions, in any of the two words an arbitrary number of times. A letter that resulted from the previous replacement can participate in the next replacements.
For example, the following pairs of words denote the same name: "koouper" and "kuooper". Making the replacements described above, you can make both words to be equal: "koouper" $\rightarrow$ "kuuper" and "kuooper" $\rightarrow$ "kuuper". "khun" and "kkkhoon". With the replacements described above you can make both words to be equal: "khun" $\rightarrow$ "khoon" and "kkkhoon" $\rightarrow$ "kkhoon" $\rightarrow$ "khoon".
For a given list of words, find the minimal number of groups where the words in each group denote the same name.
-----Input-----
The first line contains integer number n (2 ≤ n ≤ 400) — number of the words in the list.
The following n lines contain words, one word per line. Each word consists of only lowercase Latin letters. The length of each word is between 1 and 20 letters inclusive.
-----Output-----
Print the minimal number of groups where the words in each group denote the same name.
-----Examples-----
Input
10
mihail
oolyana
kooooper
hoon
ulyana
koouper
mikhail
khun
kuooper
kkkhoon
Output
4
Input
9
hariton
hkariton
buoi
kkkhariton
boooi
bui
khariton
boui
boi
Output
5
Input
2
alex
alex
Output
1
-----Note-----
There are four groups of words in the first example. Words in each group denote same name: "mihail", "mikhail" "oolyana", "ulyana" "kooooper", "koouper" "hoon", "khun", "kkkhoon"
There are five groups of words in the second example. Words in each group denote same name: "hariton", "kkkhariton", "khariton" "hkariton" "buoi", "boooi", "boui" "bui" "boi"
In the third example the words are equal, so they denote the same name.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7 4\\n1 2\\n1 3\\n1 4\\n3 5\\n3 6\\n4 7\\n\", \"4 1\\n1 2\\n1 3\\n2 4\\n\", \"8 5\\n7 5\\n1 7\\n6 1\\n3 7\\n8 3\\n2 1\\n4 5\\n\", \"2 1\\n1 2\\n\", \"20 7\\n9 7\\n3 7\\n15 9\\n1 3\\n11 9\\n18 7\\n17 18\\n20 1\\n4 11\\n2 11\\n12 18\\n8 18\\n13 2\\n19 2\\n10 9\\n6 13\\n5 8\\n14 1\\n16 13\\n\", \"3 2\\n1 2\\n1 3\\n\", \"3 1\\n1 2\\n2 3\\n\"], \"outputs\": [\"7\", \"2\", \"9\", \"1\", \"38\", \"2\", \"2\"]}", "source": "primeintellect"}
|
Writing light novels is the most important thing in Linova's life. Last night, Linova dreamed about a fantastic kingdom. She began to write a light novel for the kingdom as soon as she woke up, and of course, she is the queen of it.
[Image]
There are $n$ cities and $n-1$ two-way roads connecting pairs of cities in the kingdom. From any city, you can reach any other city by walking through some roads. The cities are numbered from $1$ to $n$, and the city $1$ is the capital of the kingdom. So, the kingdom has a tree structure.
As the queen, Linova plans to choose exactly $k$ cities developing industry, while the other cities will develop tourism. The capital also can be either industrial or tourism city.
A meeting is held in the capital once a year. To attend the meeting, each industry city sends an envoy. All envoys will follow the shortest path from the departure city to the capital (which is unique).
Traveling in tourism cities is pleasant. For each envoy, his happiness is equal to the number of tourism cities on his path.
In order to be a queen loved by people, Linova wants to choose $k$ cities which can maximize the sum of happinesses of all envoys. Can you calculate the maximum sum for her?
-----Input-----
The first line contains two integers $n$ and $k$ ($2\le n\le 2 \cdot 10^5$, $1\le k< n$) — the number of cities and industry cities respectively.
Each of the next $n-1$ lines contains two integers $u$ and $v$ ($1\le u,v\le n$), denoting there is a road connecting city $u$ and city $v$.
It is guaranteed that from any city, you can reach any other city by the roads.
-----Output-----
Print the only line containing a single integer — the maximum possible sum of happinesses of all envoys.
-----Examples-----
Input
7 4
1 2
1 3
1 4
3 5
3 6
4 7
Output
7
Input
4 1
1 2
1 3
2 4
Output
2
Input
8 5
7 5
1 7
6 1
3 7
8 3
2 1
4 5
Output
9
-----Note-----
[Image]
In the first example, Linova can choose cities $2$, $5$, $6$, $7$ to develop industry, then the happiness of the envoy from city $2$ is $1$, the happiness of envoys from cities $5$, $6$, $7$ is $2$. The sum of happinesses is $7$, and it can be proved to be the maximum one.
[Image]
In the second example, choosing cities $3$, $4$ developing industry can reach a sum of $3$, but remember that Linova plans to choose exactly $k$ cities developing industry, then the maximum sum is $2$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n0 0 0\\n\", \"2\\n0 1\\n\", \"5\\n0 1 1 1 10\\n\", \"1\\n0\\n\", \"15\\n0 0 3 3 13 3 6 34 47 12 20 6 6 21 55\\n\", \"20\\n0 1 7 15 30 15 59 42 1 4 1 36 116 36 16 136 10 36 46 36\\n\", \"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\"], \"outputs\": [\"3 2 1\\n\", \"1 2\\n\", \"1 4 3 2 5\\n\", \"1\\n\", \"2 1 15 10 12 3 6 13 14 8 9 5 4 7 11\\n\", \"1 6 8 15 17 12 18 16 3 4 2 14 20 13 7 19 5 10 11 9\\n\", \"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\\n\"]}", "source": "primeintellect"}
|
An array of integers $p_{1},p_{2}, \ldots,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 \le n \le 2 \cdot 10^{5}$) — the size of the permutation.
The second line contains $n$ integers $s_{1}, s_{2}, \ldots, s_{n}$ ($0 \le s_{i} \le \frac{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}, \ldots, 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$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n0 1\\n1 0\\n\", \"5\\n0 2 2 1 2\\n2 0 4 1 3\\n2 4 0 1 3\\n1 1 1 0 1\\n2 3 3 1 0\\n\", \"10\\n0 1 5 2 5 3 4 5 5 5\\n1 0 1 1 1 1 1 1 1 1\\n5 1 0 2 6 3 4 6 6 6\\n2 1 2 0 2 2 2 2 2 2\\n5 1 6 2 0 3 4 8 8 7\\n3 1 3 2 3 0 3 3 3 3\\n4 1 4 2 4 3 0 4 4 4\\n5 1 6 2 8 3 4 0 9 7\\n5 1 6 2 8 3 4 9 0 7\\n5 1 6 2 7 3 4 7 7 0\\n\", \"4\\n0 1 3 2\\n1 0 1 1\\n3 1 0 2\\n2 1 2 0\\n\", \"7\\n0 3 2 4 1 4 4\\n3 0 2 3 1 3 3\\n2 2 0 2 1 2 2\\n4 3 2 0 1 5 5\\n1 1 1 1 0 1 1\\n4 3 2 5 1 0 6\\n4 3 2 5 1 6 0\\n\", \"10\\n0 4 4 1 4 4 4 2 3 4\\n4 0 5 1 6 8 9 2 3 7\\n4 5 0 1 5 5 5 2 3 5\\n1 1 1 0 1 1 1 1 1 1\\n4 6 5 1 0 6 6 2 3 6\\n4 8 5 1 6 0 8 2 3 7\\n4 9 5 1 6 8 0 2 3 7\\n2 2 2 1 2 2 2 0 2 2\\n3 3 3 1 3 3 3 2 0 3\\n4 7 5 1 6 7 7 2 3 0\\n\", \"13\\n0 5 5 2 5 4 5 5 3 5 5 5 1\\n5 0 6 2 6 4 6 6 3 6 6 6 1\\n5 6 0 2 10 4 7 10 3 8 10 9 1\\n2 2 2 0 2 2 2 2 2 2 2 2 1\\n5 6 10 2 0 4 7 12 3 8 11 9 1\\n4 4 4 2 4 0 4 4 3 4 4 4 1\\n5 6 7 2 7 4 0 7 3 7 7 7 1\\n5 6 10 2 12 4 7 0 3 8 11 9 1\\n3 3 3 2 3 3 3 3 0 3 3 3 1\\n5 6 8 2 8 4 7 8 3 0 8 8 1\\n5 6 10 2 11 4 7 11 3 8 0 9 1\\n5 6 9 2 9 4 7 9 3 8 9 0 1\\n1 1 1 1 1 1 1 1 1 1 1 1 0\\n\"], \"outputs\": [\"2 1\\n\", \"2 5 4 1 3\\n\", \"5 1 6 2 8 3 4 10 9 7\\n\", \"4 1 3 2\\n\", \"4 3 2 5 1 7 6\\n\", \"4 10 5 1 6 8 9 2 3 7\\n\", \"5 6 10 2 13 4 7 12 3 8 11 9 1\\n\"]}", "source": "primeintellect"}
|
Bob has a permutation of integers from 1 to n. Denote this permutation as p. The i-th element of p will be denoted as p_{i}. For all pairs of distinct integers i, j between 1 and n, he wrote the number a_{i}, j = min(p_{i}, p_{j}). He writes a_{i}, i = 0 for all integer i from 1 to n.
Bob gave you all the values of a_{i}, j that he wrote down. Your job is to reconstruct any permutation that could have generated these values. The input will be formed so that it is guaranteed that there is at least one solution that is consistent with the information given.
-----Input-----
The first line of the input will contain a single integer n (2 ≤ n ≤ 50).
The next n lines will contain the values of a_{i}, j. The j-th number on the i-th line will represent a_{i}, j. The i-th number on the i-th line will be 0. It's guaranteed that a_{i}, j = a_{j}, i and there is at least one solution consistent with the information given.
-----Output-----
Print n space separated integers, which represents a permutation that could have generated these values. If there are multiple possible solutions, print any of them.
-----Examples-----
Input
2
0 1
1 0
Output
2 1
Input
5
0 2 2 1 2
2 0 4 1 3
2 4 0 1 3
1 1 1 0 1
2 3 3 1 0
Output
2 5 4 1 3
-----Note-----
In the first case, the answer can be {1, 2} or {2, 1}.
In the second case, another possible answer is {2, 4, 5, 1, 3}.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n1 3 4 2\\n\", \"8\\n6 8 3 4 7 2 1 5\\n\", \"1\\n1\\n\", \"11\\n10 8 9 4 6 3 5 1 11 7 2\\n\", \"11\\n10 8 9 4 3 5 1 11 7 2 6\\n\", \"100\\n1 72 43 50 58 87 10 94 29 51 99 86 92 80 36 31 9 100 85 59 66 30 3 78 17 73 93 37 57 71 45 15 24 2 64 44 65 22 38 79 23 8 16 52 98 97 96 95 91 90 89 88 84 83 82 81 77 76 75 74 70 69 68 67 63 62 61 60 56 55 54 53 49 48 47 46 42 41 40 39 35 34 33 32 28 27 26 25 21 20 19 18 14 13 12 11 7 6 5 4\\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\"], \"outputs\": [\"1 2 3 2 1\\n\", \"1 2 2 3 4 3 4 5 1\\n\", \"1 1\\n\", \"1 2 3 4 5 6 7 8 9 6 2 1\\n\", \"1 2 3 4 5 6 7 8 5 5 6 1\\n\", \"1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 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 43 43 43 40 40 40 40 37 37 37 37 34 34 34 34 31 31 31 31 28 28 28 28 25 25 25 25 22 22 22 22 19 19 19 19 16 16 16 16 13 13 13 13 10 10 10 10 7 7 7 7 4 4 4 4 1\\n\", \"1 2 3 4 5 6 7 8 9 10 11 12 13 14 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 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 70 71 72 73 74 75 76 77 78 71 39 1\\n\"]}", "source": "primeintellect"}
|
Recently, Dima met with Sasha in a philatelic store, and since then they are collecting coins together. Their favorite occupation is to sort collections of coins. Sasha likes having things in order, that is why he wants his coins to be arranged in a row in such a way that firstly come coins out of circulation, and then come coins still in circulation.
For arranging coins Dima uses the following algorithm. One step of his algorithm looks like the following:
He looks through all the coins from left to right; If he sees that the i-th coin is still in circulation, and (i + 1)-th coin is already out of circulation, he exchanges these two coins and continues watching coins from (i + 1)-th.
Dima repeats the procedure above until it happens that no two coins were exchanged during this procedure. Dima calls hardness of ordering the number of steps required for him according to the algorithm above to sort the sequence, e.g. the number of times he looks through the coins from the very beginning. For example, for the ordered sequence hardness of ordering equals one.
Today Sasha invited Dima and proposed him a game. First he puts n coins in a row, all of them are out of circulation. Then Sasha chooses one of the coins out of circulation and replaces it with a coin in circulation for n times. During this process Sasha constantly asks Dima what is the hardness of ordering of the sequence.
The task is more complicated because Dima should not touch the coins and he should determine hardness of ordering in his mind. Help Dima with this task.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 300 000) — number of coins that Sasha puts behind Dima.
Second line contains n distinct integers p_1, p_2, ..., p_{n} (1 ≤ p_{i} ≤ n) — positions that Sasha puts coins in circulation to. At first Sasha replaces coin located at position p_1, then coin located at position p_2 and so on. Coins are numbered from left to right.
-----Output-----
Print n + 1 numbers a_0, a_1, ..., a_{n}, where a_0 is a hardness of ordering at the beginning, a_1 is a hardness of ordering after the first replacement and so on.
-----Examples-----
Input
4
1 3 4 2
Output
1 2 3 2 1
Input
8
6 8 3 4 7 2 1 5
Output
1 2 2 3 4 3 4 5 1
-----Note-----
Let's denote as O coin out of circulation, and as X — coin is circulation.
At the first sample, initially in row there are coins that are not in circulation, so Dima will look through them from left to right and won't make any exchanges.
After replacement of the first coin with a coin in circulation, Dima will exchange this coin with next three times and after that he will finally look through the coins and finish the process.
XOOO → OOOX
After replacement of the third coin, Dima's actions look this way:
XOXO → OXOX → OOXX
After replacement of the fourth coin, Dima's actions look this way:
XOXX → OXXX
Finally, after replacement of the second coin, row becomes consisting of coins that are in circulation and Dima will look through coins from left to right without any exchanges.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 4\\n1 2\\n4 3\\n1 4\\n3 4\\n\", \"6 5\\n2 3\\n2 1\\n3 4\\n6 5\\n4 5\\n\", \"2 1\\n1 2\\n\", \"100000 12\\n8 7\\n1 9\\n5 4\\n11 12\\n7 8\\n3 4\\n3 5\\n12 15\\n15 13\\n13 14\\n7 8\\n11 14\\n\", \"10 15\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n1 6\\n2 7\\n3 8\\n4 9\\n5 10\\n6 8\\n7 9\\n8 10\\n9 6\\n10 7\\n\", \"4 2\\n1 2\\n2 3\\n\", \"4 2\\n1 3\\n2 4\\n\"], \"outputs\": [\"1\\n\", \"0\\n\", \"0\\n\", \"4\\n\", \"6\\n\", \"0\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
The legendary Farmer John is throwing a huge party, and animals from all over the world are hanging out at his house. His guests are hungry, so he instructs his cow Bessie to bring out the snacks! Moo!
There are $n$ snacks flavors, numbered with integers $1, 2, \ldots, n$. Bessie has $n$ snacks, one snack of each flavor. Every guest has exactly two favorite flavors. The procedure for eating snacks will go as follows: First, Bessie will line up the guests in some way. Then in this order, guests will approach the snacks one by one. Each guest in their turn will eat all remaining snacks of their favorite flavor. In case no favorite flavors are present when a guest goes up, they become very sad.
Help Bessie to minimize the number of sad guests by lining the guests in an optimal way.
-----Input-----
The first line contains integers $n$ and $k$ ($2 \le n \le 10^5$, $1 \le k \le 10^5$), the number of snacks and the number of guests.
The $i$-th of the following $k$ lines contains two integers $x_i$ and $y_i$ ($1 \le x_i, y_i \le n$, $x_i \ne y_i$), favorite snack flavors of the $i$-th guest.
-----Output-----
Output one integer, the smallest possible number of sad guests.
-----Examples-----
Input
5 4
1 2
4 3
1 4
3 4
Output
1
Input
6 5
2 3
2 1
3 4
6 5
4 5
Output
0
-----Note-----
In the first example, Bessie can order the guests like this: $3, 1, 2, 4$. Guest $3$ goes first and eats snacks $1$ and $4$. Then the guest $1$ goes and eats the snack $2$ only, because the snack $1$ has already been eaten. Similarly, the guest $2$ goes up and eats the snack $3$ only. All the snacks are gone, so the guest $4$ will be sad.
In the second example, one optimal ordering is $2, 1, 3, 5, 4$. All the guests will be satisfied.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n1 0 1\\n1\\n1 3\\n\", \"3\\n1 0 1\\n2\\n1 1\\n3 3\\n\", \"3\\n1 0 1\\n2\\n1 1\\n2 3\\n\", \"5\\n0 1 0 1 0\\n1\\n1 5\\n\", \"9\\n0 1 0 1 1 1 0 1 0\\n3\\n1 4\\n5 8\\n6 7\\n\", \"15\\n1 1 0 0 0 0 0 0 1 0 1 1 1 0 0\\n9\\n4 10\\n13 14\\n1 7\\n4 14\\n9 11\\n2 6\\n7 8\\n3 12\\n7 13\\n\", \"10\\n0 0 0 1 0 0 1 1 1 0\\n7\\n1 4\\n2 5\\n1 3\\n6 7\\n9 9\\n1 5\\n7 9\\n\"], \"outputs\": [\"1\\n\", \"0\\n\", \"1\\n\", \"2\\n\", \"3\\n\", \"5\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
You are given a sequence a = \{a_1, ..., a_N\} with all zeros, and a sequence b = \{b_1, ..., b_N\} consisting of 0 and 1. The length of both is N.
You can perform Q kinds of operations. The i-th operation is as follows:
- Replace each of a_{l_i}, a_{l_i + 1}, ..., a_{r_i} with 1.
Minimize the hamming distance between a and b, that is, the number of i such that a_i \neq b_i, by performing some of the Q operations.
-----Constraints-----
- 1 \leq N \leq 200,000
- b consists of 0 and 1.
- 1 \leq Q \leq 200,000
- 1 \leq l_i \leq r_i \leq N
- If i \neq j, either l_i \neq l_j or r_i \neq r_j.
-----Input-----
Input is given from Standard Input in the following format:
N
b_1 b_2 ... b_N
Q
l_1 r_1
l_2 r_2
:
l_Q r_Q
-----Output-----
Print the minimum possible hamming distance.
-----Sample Input-----
3
1 0 1
1
1 3
-----Sample Output-----
1
If you choose to perform the operation, a will become \{1, 1, 1\}, for a hamming distance of 1.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 3\\n2\\n3\\n4\\n\", \"13 4\\n10\\n5\\n4\\n8\\n\", \"2 2\\n1\\n2\\n\", \"1 1\\n1\\n\", \"3 3\\n3\\n2\\n1\\n\", \"12 12\\n9\\n11\\n5\\n3\\n7\\n2\\n8\\n6\\n4\\n10\\n12\\n1\\n\"], \"outputs\": [\"3\\n2\\n4\\n\", \"13\\n3\\n8\\n9\\n\", \"1\\n2\\n\", \"1\\n\", \"2\\n3\\n1\\n\", \"5\\n6\\n3\\n2\\n4\\n7\\n12\\n8\\n10\\n9\\n11\\n1\\n\"]}", "source": "primeintellect"}
|
Dima is a beginner programmer. During his working process, he regularly has to repeat the following operation again and again: to remove every second element from the array. One day he has been bored with easy solutions of this problem, and he has come up with the following extravagant algorithm.
Let's consider that initially array contains n numbers from 1 to n and the number i is located in the cell with the index 2i - 1 (Indices are numbered starting from one) and other cells of the array are empty. Each step Dima selects a non-empty array cell with the maximum index and moves the number written in it to the nearest empty cell to the left of the selected one. The process continues until all n numbers will appear in the first n cells of the array. For example if n = 4, the array is changing as follows: [Image]
You have to write a program that allows you to determine what number will be in the cell with index x (1 ≤ x ≤ n) after Dima's algorithm finishes.
-----Input-----
The first line contains two integers n and q (1 ≤ n ≤ 10^18, 1 ≤ q ≤ 200 000), the number of elements in the array and the number of queries for which it is needed to find the answer.
Next q lines contain integers x_{i} (1 ≤ x_{i} ≤ n), the indices of cells for which it is necessary to output their content after Dima's algorithm finishes.
-----Output-----
For each of q queries output one integer number, the value that will appear in the corresponding array cell after Dima's algorithm finishes.
-----Examples-----
Input
4 3
2
3
4
Output
3
2
4
Input
13 4
10
5
4
8
Output
13
3
8
9
-----Note-----
The first example is shown in the picture.
In the second example the final array is [1, 12, 2, 8, 3, 11, 4, 9, 5, 13, 6, 10, 7].
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n1 1\\n\", \"5\\n1 2 3 4\\n\", \"31\\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\\n\", \"29\\n1 2 2 4 4 6 6 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28\\n\", \"2\\n1\\n\", \"3\\n1 2\\n\"], \"outputs\": [\"4 3 3\", \"5 8 9 8 5\", \"73741817 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913 536870913\", \"191 380 191 470 236 506 254 506 504 500 494 486 476 464 450 434 416 396 374 350 324 296 266 234 200 164 126 86 44\", \"2 2\", \"3 4 3\"]}", "source": "primeintellect"}
|
The country has n cities and n - 1 bidirectional roads, it is possible to get from every city to any other one if you move only along the roads. The cities are numbered with integers from 1 to n inclusive.
All the roads are initially bad, but the government wants to improve the state of some roads. We will assume that the citizens are happy about road improvement if the path from the capital located in city x to any other city contains at most one bad road.
Your task is — for every possible x determine the number of ways of improving the quality of some roads in order to meet the citizens' condition. As those values can be rather large, you need to print each value modulo 1 000 000 007 (10^9 + 7).
-----Input-----
The first line of the input contains a single integer n (2 ≤ n ≤ 2·10^5) — the number of cities in the country. Next line contains n - 1 positive integers p_2, p_3, p_4, ..., p_{n} (1 ≤ p_{i} ≤ i - 1) — the description of the roads in the country. Number p_{i} means that the country has a road connecting city p_{i} and city i.
-----Output-----
Print n integers a_1, a_2, ..., a_{n}, where a_{i} is the sought number of ways to improve the quality of the roads modulo 1 000 000 007 (10^9 + 7), if the capital of the country is at city number i.
-----Examples-----
Input
3
1 1
Output
4 3 3
Input
5
1 2 3 4
Output
5 8 9 8 5
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 5 3\\n1 2 1\\n2 3 2\\n1 3 3\\n3 4 4\\n1 5 5\\n3 5\\n4 5\\n5 5\\n\", \"2 2 3\\n1 2 2\\n2 1 3\\n2 1\\n2 2\\n2 3\\n\", \"5 4 3\\n1 2 999999999\\n2 3 1000000000\\n3 4 529529529\\n5 1 524524524\\n5 524444444\\n5 529999999\\n2 1000000000\\n\", \"3 2 5\\n1 2 2\\n2 3 4\\n3 5\\n3 5\\n3 5\\n3 6\\n3 7\\n\", \"5 5 3\\n1 2 999999999\\n2 3 1000000000\\n3 4 529529529\\n5 1 524524524\\n5 3 1000000000\\n5 524444444\\n5 529999999\\n2 1000000000\\n\", \"2 1 5\\n1 2 4\\n2 3\\n2 5\\n2 4\\n2 4\\n2 5\\n\", \"3 3 6\\n1 2 499999999\\n2 3 500000000\\n1 3 999999999\\n2 499999999\\n2 500000000\\n2 499999999\\n3 999999999\\n3 1000000000\\n3 1000000000\\n\", \"2 1 1\\n1 2 1\\n2 1000000000\\n\", \"3 2 2\\n1 2 4\\n2 3 4\\n2 2\\n3 6\\n\", \"5 5 2\\n1 2 100\\n2 3 100\\n3 4 100\\n4 5 20\\n2 5 5\\n5 50\\n4 1\\n\", \"3 2 2\\n1 2 100\\n2 3 1\\n2 1\\n3 3\\n\"], \"outputs\": [\"2\\n\", \"2\\n\", \"2\\n\", \"4\\n\", \"2\\n\", \"4\\n\", \"6\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
Jzzhu is the president of country A. There are n cities numbered from 1 to n in his country. City 1 is the capital of A. Also there are m roads connecting the cities. One can go from city u_{i} to v_{i} (and vise versa) using the i-th road, the length of this road is x_{i}. Finally, there are k train routes in the country. One can use the i-th train route to go from capital of the country to city s_{i} (and vise versa), the length of this route is y_{i}.
Jzzhu doesn't want to waste the money of the country, so he is going to close some of the train routes. Please tell Jzzhu the maximum number of the train routes which can be closed under the following condition: the length of the shortest path from every city to the capital mustn't change.
-----Input-----
The first line contains three integers n, m, k (2 ≤ n ≤ 10^5; 1 ≤ m ≤ 3·10^5; 1 ≤ k ≤ 10^5).
Each of the next m lines contains three integers u_{i}, v_{i}, x_{i} (1 ≤ u_{i}, v_{i} ≤ n; u_{i} ≠ v_{i}; 1 ≤ x_{i} ≤ 10^9).
Each of the next k lines contains two integers s_{i} and y_{i} (2 ≤ s_{i} ≤ n; 1 ≤ y_{i} ≤ 10^9).
It is guaranteed that there is at least one way from every city to the capital. Note, that there can be multiple roads between two cities. Also, there can be multiple routes going to the same city from the capital.
-----Output-----
Output a single integer representing the maximum number of the train routes which can be closed.
-----Examples-----
Input
5 5 3
1 2 1
2 3 2
1 3 3
3 4 4
1 5 5
3 5
4 5
5 5
Output
2
Input
2 2 3
1 2 2
2 1 3
2 1
2 2
2 3
Output
2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"zyxxxxxxyyz\\n5\\n5 5\\n1 3\\n1 11\\n1 4\\n3 6\\n\", \"yxzyzxzzxyyzzxxxzyyzzyzxxzxyzyyzxyzxyxxyzxyxzyzxyzxyyxzzzyzxyyxyzxxy\\n10\\n17 67\\n6 35\\n12 45\\n56 56\\n14 30\\n25 54\\n1 1\\n46 54\\n3 33\\n19 40\\n\", \"xxxxyyxyyzzyxyxzxyzyxzyyyzyzzxxxxzyyzzzzyxxxxzzyzzyzx\\n5\\n4 4\\n3 3\\n1 24\\n3 28\\n18 39\\n\", \"yzxyzxyzxzxzyzxyzyzzzyxzyz\\n9\\n4 6\\n2 7\\n3 5\\n14 24\\n3 13\\n2 24\\n2 5\\n2 14\\n3 15\\n\", \"zxyzxyzyyzxzzxyzxyzx\\n15\\n7 10\\n17 17\\n6 7\\n8 14\\n4 7\\n11 18\\n12 13\\n1 1\\n3 8\\n1 1\\n9 17\\n4 4\\n5 11\\n3 15\\n1 1\\n\", \"x\\n1\\n1 1\\n\"], \"outputs\": [\"YES\\nYES\\nNO\\nYES\\nNO\\n\", \"NO\\nNO\\nNO\\nYES\\nYES\\nNO\\nYES\\nNO\\nNO\\nYES\\n\", \"YES\\nYES\\nNO\\nNO\\nNO\\n\", \"YES\\nYES\\nYES\\nNO\\nYES\\nNO\\nYES\\nNO\\nNO\\n\", \"NO\\nYES\\nYES\\nYES\\nYES\\nYES\\nYES\\nYES\\nNO\\nYES\\nNO\\nYES\\nYES\\nNO\\nYES\\n\", \"YES\\n\"]}", "source": "primeintellect"}
|
Sereja loves all sorts of algorithms. He has recently come up with a new algorithm, which receives a string as an input. Let's represent the input string of the algorithm as q = q_1q_2... q_{k}. The algorithm consists of two steps:
Find any continuous subsequence (substring) of three characters of string q, which doesn't equal to either string "zyx", "xzy", "yxz". If q doesn't contain any such subsequence, terminate the algorithm, otherwise go to step 2. Rearrange the letters of the found subsequence randomly and go to step 1.
Sereja thinks that the algorithm works correctly on string q if there is a non-zero probability that the algorithm will be terminated. But if the algorithm anyway will work for infinitely long on a string, then we consider the algorithm to work incorrectly on this string.
Sereja wants to test his algorithm. For that, he has string s = s_1s_2... s_{n}, consisting of n characters. The boy conducts a series of m tests. As the i-th test, he sends substring s_{l}_{i}s_{l}_{i} + 1... s_{r}_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n) to the algorithm input. Unfortunately, the implementation of his algorithm works too long, so Sereja asked you to help. For each test (l_{i}, r_{i}) determine if the algorithm works correctly on this test or not.
-----Input-----
The first line contains non-empty string s, its length (n) doesn't exceed 10^5. It is guaranteed that string s only contains characters: 'x', 'y', 'z'.
The second line contains integer m (1 ≤ m ≤ 10^5) — the number of tests. Next m lines contain the tests. The i-th line contains a pair of integers l_{i}, r_{i} (1 ≤ l_{i} ≤ r_{i} ≤ n).
-----Output-----
For each test, print "YES" (without the quotes) if the algorithm works correctly on the corresponding test and "NO" (without the quotes) otherwise.
-----Examples-----
Input
zyxxxxxxyyz
5
5 5
1 3
1 11
1 4
3 6
Output
YES
YES
NO
YES
NO
-----Note-----
In the first example, in test one and two the algorithm will always be terminated in one step. In the fourth test you can get string "xzyx" on which the algorithm will terminate. In all other tests the algorithm doesn't work correctly.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n16 4\\n...AAAAA........\\ns.BBB......CCCCC\\n........DDDDD...\\n16 4\\n...AAAAA........\\ns.BBB....CCCCC..\\n.......DDDDD....\\n\", \"2\\n10 4\\ns.ZZ......\\n.....AAABB\\n.YYYYYY...\\n10 4\\ns.ZZ......\\n....AAAABB\\n.YYYYYY...\\n\", \"1\\n100 26\\ns................PPPP.CCCCC..UUUUUU.........YYYQQQQQQQ...GGGGG............MMM.....JJJJ..............\\n.OOOOOO....EEE....................................................SSSSSS........LLLLLL......NNNIIII.\\n......FFFFFF...VVVV..ZZZBBB...KKKKK..WWWWWWWXXX..RRRRRRR......AAAAADDDDDDD.HHH............TTTTTTT...\\n\", \"2\\n16 4\\n...AAAAA........\\ns.BBB......CCCCC\\n........DDDDD...\\n16 4\\n...AAAAA........\\ns.BBB....CCCCC..\\n.......DDDDD....\\n\", \"2\\n10 4\\ns.ZZ......\\n.....AAABB\\n.YYYYYY...\\n10 4\\ns.ZZ......\\n....AAAABB\\n.YYYYYY...\\n\", \"1\\n100 26\\ns................PPPP.CCCCC..UUUUUU.........YYYQQQQQQQ...GGGGG............MMM.....JJJJ..............\\n.OOOOOO....EEE....................................................SSSSSS........LLLLLL......NNNIIII.\\n......FFFFFF...VVVV..ZZZBBB...KKKKK..WWWWWWWXXX..RRRRRRR......AAAAADDDDDDD.HHH............TTTTTTT...\\n\"], \"outputs\": [\"YES\\nNO\\n\", \"YES\\nNO\\n\", \"YES\\n\", \"YES\\nNO\\n\", \"YES\\nNO\\n\", \"YES\\n\"]}", "source": "primeintellect"}
|
The mobile application store has a new game called "Subway Roller".
The protagonist of the game Philip is located in one end of the tunnel and wants to get out of the other one. The tunnel is a rectangular field consisting of three rows and n columns. At the beginning of the game the hero is in some cell of the leftmost column. Some number of trains rides towards the hero. Each train consists of two or more neighbouring cells in some row of the field.
All trains are moving from right to left at a speed of two cells per second, and the hero runs from left to right at the speed of one cell per second. For simplicity, the game is implemented so that the hero and the trains move in turns. First, the hero moves one cell to the right, then one square up or down, or stays idle. Then all the trains move twice simultaneously one cell to the left. Thus, in one move, Philip definitely makes a move to the right and can move up or down. If at any point, Philip is in the same cell with a train, he loses. If the train reaches the left column, it continues to move as before, leaving the tunnel.
Your task is to answer the question whether there is a sequence of movements of Philip, such that he would be able to get to the rightmost column.
[Image]
-----Input-----
Each test contains from one to ten sets of the input data. The first line of the test contains a single integer t (1 ≤ t ≤ 10 for pretests and tests or t = 1 for hacks; see the Notes section for details) — the number of sets.
Then follows the description of t sets of the input data.
The first line of the description of each set contains two integers n, k (2 ≤ n ≤ 100, 1 ≤ k ≤ 26) — the number of columns on the field and the number of trains. Each of the following three lines contains the sequence of n character, representing the row of the field where the game is on. Philip's initial position is marked as 's', he is in the leftmost column. Each of the k trains is marked by some sequence of identical uppercase letters of the English alphabet, located in one line. Distinct trains are represented by distinct letters. Character '.' represents an empty cell, that is, the cell that doesn't contain either Philip or the trains.
-----Output-----
For each set of the input data print on a single line word YES, if it is possible to win the game and word NO otherwise.
-----Examples-----
Input
2
16 4
...AAAAA........
s.BBB......CCCCC
........DDDDD...
16 4
...AAAAA........
s.BBB....CCCCC..
.......DDDDD....
Output
YES
NO
Input
2
10 4
s.ZZ......
.....AAABB
.YYYYYY...
10 4
s.ZZ......
....AAAABB
.YYYYYY...
Output
YES
NO
-----Note-----
In the first set of the input of the first sample Philip must first go forward and go down to the third row of the field, then go only forward, then go forward and climb to the second row, go forward again and go up to the first row. After that way no train blocks Philip's path, so he can go straight to the end of the tunnel.
Note that in this problem the challenges are restricted to tests that contain only one testset.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"60 3\\n2012-03-16 16:15:25: Disk size is\\n2012-03-16 16:15:25: Network failute\\n2012-03-16 16:16:29: Cant write varlog\\n2012-03-16 16:16:42: Unable to start process\\n2012-03-16 16:16:43: Disk size is too small\\n2012-03-16 16:16:53: Timeout detected\\n\", \"1 2\\n2012-03-16 23:59:59:Disk size\\n2012-03-17 00:00:00: Network\\n2012-03-17 00:00:01:Cant write varlog\\n\", \"2 2\\n2012-03-16 23:59:59:Disk size is too sm\\n2012-03-17 00:00:00:Network failute dete\\n2012-03-17 00:00:01:Cant write varlogmysq\\n\", \"10 30\\n2012-02-03 10:01:10: qQsNeHR.BLmZVMsESEKKDvqcQHHzBeddbKiIb,aDQnBKNtdcvitwtpUDGVFSh.Lx,FPBZXdSrsSDZtIJDgx!mSovndGiqHlCwCFAHy\\n\", \"2 3\\n2012-02-20 16:15:00: Dis\\n2012-03-16 16:15:01: Net\\n2012-03-16 16:15:02: Cant write varlog\\n2012-03-16 16:15:02: Unable to start process\\n2012-03-16 16:16:43: Dis\\n2012-03-16 16:16:53: Timeout detected\\n\", \"2 4\\n2012-02-20 16:15:00: Dis\\n2012-03-16 16:15:01: Net\\n2012-03-16 16:15:02: Cant write varlog\\n2012-03-16 16:15:02: Unable to start process\\n2012-03-16 16:16:43: Dis\\n2012-03-16 16:16:53: Timeout detected\\n\"], \"outputs\": [\"2012-03-16 16:16:43\\n\", \"-1\\n\", \"2012-03-17 00:00:00\\n\", \"-1\\n\", \"2012-03-16 16:15:02\\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
You've got a list of program warning logs. Each record of a log stream is a string in this format: "2012-MM-DD HH:MM:SS:MESSAGE" (without the quotes).
String "MESSAGE" consists of spaces, uppercase and lowercase English letters and characters "!", ".", ",", "?". String "2012-MM-DD" determines a correct date in the year of 2012. String "HH:MM:SS" determines a correct time in the 24 hour format.
The described record of a log stream means that at a certain time the record has got some program warning (string "MESSAGE" contains the warning's description).
Your task is to print the first moment of time, when the number of warnings for the last n seconds was not less than m.
-----Input-----
The first line of the input contains two space-separated integers n and m (1 ≤ n, m ≤ 10000).
The second and the remaining lines of the input represent the log stream. The second line of the input contains the first record of the log stream, the third line contains the second record and so on. Each record of the log stream has the above described format. All records are given in the chronological order, that is, the warning records are given in the order, in which the warnings appeared in the program.
It is guaranteed that the log has at least one record. It is guaranteed that the total length of all lines of the log stream doesn't exceed 5·10^6 (in particular, this means that the length of some line does not exceed 5·10^6 characters). It is guaranteed that all given dates and times are correct, and the string 'MESSAGE" in all records is non-empty.
-----Output-----
If there is no sought moment of time, print -1. Otherwise print a string in the format "2012-MM-DD HH:MM:SS" (without the quotes) — the first moment of time when the number of warnings for the last n seconds got no less than m.
-----Examples-----
Input
60 3
2012-03-16 16:15:25: Disk size is
2012-03-16 16:15:25: Network failute
2012-03-16 16:16:29: Cant write varlog
2012-03-16 16:16:42: Unable to start process
2012-03-16 16:16:43: Disk size is too small
2012-03-16 16:16:53: Timeout detected
Output
2012-03-16 16:16:43
Input
1 2
2012-03-16 23:59:59:Disk size
2012-03-17 00:00:00: Network
2012-03-17 00:00:01:Cant write varlog
Output
-1
Input
2 2
2012-03-16 23:59:59:Disk size is too sm
2012-03-17 00:00:00:Network failute dete
2012-03-17 00:00:01:Cant write varlogmysq
Output
2012-03-17 00:00:00
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 2\\n00\\n01\\n\", \"2 2\\n00\\n11\\n\", \"3 3\\n0\\n10\\n110\\n\", \"2 1\\n0\\n1\\n\", \"1 2\\n11\\n\", \"2 3\\n101\\n11\\n\"], \"outputs\": [\"Alice\\n\", \"Bob\\n\", \"Alice\\n\", \"Bob\\n\", \"Alice\\n\", \"Bob\\n\"]}", "source": "primeintellect"}
|
For strings s and t, we will say that s and t are prefix-free when neither is a prefix of the other.
Let L be a positive integer. A set of strings S is a good string set when the following conditions hold true:
- Each string in S has a length between 1 and L (inclusive) and consists of the characters 0 and 1.
- Any two distinct strings in S are prefix-free.
We have a good string set S = \{ s_1, s_2, ..., s_N \}. Alice and Bob will play a game against each other. They will alternately perform the following operation, starting from Alice:
- Add a new string to S. After addition, S must still be a good string set.
The first player who becomes unable to perform the operation loses the game. Determine the winner of the game when both players play optimally.
-----Constraints-----
- 1 \leq N \leq 10^5
- 1 \leq L \leq 10^{18}
- s_1, s_2, ..., s_N are all distinct.
- { s_1, s_2, ..., s_N } is a good string set.
- |s_1| + |s_2| + ... + |s_N| \leq 10^5
-----Input-----
Input is given from Standard Input in the following format:
N L
s_1
s_2
:
s_N
-----Output-----
If Alice will win, print Alice; if Bob will win, print Bob.
-----Sample Input-----
2 2
00
01
-----Sample Output-----
Alice
If Alice adds 1, Bob will be unable to add a new string.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n0110\\n\", \"7\\n1101001\\n\", \"12\\n011100011100\\n\", \"100\\n0110110011011111001110000110010010000111111001100001011101101000001011001101100111011111100111101110\\n\", \"1\\n0\\n\"], \"outputs\": [\"12\\n\", \"30\\n\", \"156\\n\", \"23254\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
Zookeeper is buying a carton of fruit to feed his pet wabbit. The fruits are a sequence of apples and oranges, which is represented by a binary string $s_1s_2\ldots s_n$ of length $n$. $1$ represents an apple and $0$ represents an orange.
Since wabbit is allergic to eating oranges, Zookeeper would like to find the longest contiguous sequence of apples. Let $f(l,r)$ be the longest contiguous sequence of apples in the substring $s_{l}s_{l+1}\ldots s_{r}$.
Help Zookeeper find $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l,r)$, or the sum of $f$ across all substrings.
-----Input-----
The first line contains a single integer $n$ $(1 \leq n \leq 5 \cdot 10^5)$.
The next line contains a binary string $s$ of length $n$ $(s_i \in \{0,1\})$
-----Output-----
Print a single integer: $\sum_{l=1}^{n} \sum_{r=l}^{n} f(l,r)$.
-----Examples-----
Input
4
0110
Output
12
Input
7
1101001
Output
30
Input
12
011100011100
Output
156
-----Note-----
In the first test, there are ten substrings. The list of them (we let $[l,r]$ be the substring $s_l s_{l+1} \ldots s_r$): $[1,1]$: 0 $[1,2]$: 01 $[1,3]$: 011 $[1,4]$: 0110 $[2,2]$: 1 $[2,3]$: 11 $[2,4]$: 110 $[3,3]$: 1 $[3,4]$: 10 $[4,4]$: 0
The lengths of the longest contiguous sequence of ones in each of these ten substrings are $0,1,2,2,1,2,2,1,1,0$ respectively. Hence, the answer is $0+1+2+2+1+2+2+1+1+0 = 12$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6 4\\n()(())\\n\", \"8 8\\n(()(()))\\n\", \"20 10\\n((()))()((()()(())))\\n\", \"40 30\\n((((((((()()()))))))))((())((()())))(())\\n\", \"2 2\\n()\\n\"], \"outputs\": [\"()()\\n\", \"(()(()))\\n\", \"((()))()()\\n\", \"((((((((()()()))))))))(())()()\\n\", \"()\\n\"]}", "source": "primeintellect"}
|
A bracket sequence is a string containing only characters "(" and ")". A regular bracket sequence is a bracket sequence that can be transformed into a correct arithmetic expression by inserting characters "1" and "+" between the original characters of the sequence. For example, bracket sequences "()()" and "(())" are regular (the resulting expressions are: "(1)+(1)" and "((1+1)+1)"), and ")(", "(" and ")" are not.
Subsequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements.
You are given a regular bracket sequence $s$ and an integer number $k$. Your task is to find a regular bracket sequence of length exactly $k$ such that it is also a subsequence of $s$.
It is guaranteed that such sequence always exists.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \le k \le n \le 2 \cdot 10^5$, both $n$ and $k$ are even) — the length of $s$ and the length of the sequence you are asked to find.
The second line is a string $s$ — regular bracket sequence of length $n$.
-----Output-----
Print a single string — a regular bracket sequence of length exactly $k$ such that it is also a subsequence of $s$.
It is guaranteed that such sequence always exists.
-----Examples-----
Input
6 4
()(())
Output
()()
Input
8 8
(()(()))
Output
(()(()))
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"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\", \"2 1 1\\n2 1\\n\", \"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\"], \"outputs\": [\"0\\n0\\n3\\n3\\n\", \"0\\n0\\n0\\n3\\n3\\n4\\n4\\n5\\n\", \"0\\n0\\n0\\n0\\n3\\n4\\n4\\n\", \"2\\n\", \"0\\n0\\n3\\n3\\n3\\n3\\n7\\n7\\n7\\n7\\n7\\n11\\n11\\n11\\n11\\n15\\n15\\n15\\n15\\n16\\n\"]}", "source": "primeintellect"}
|
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 \leq n \leq 2 \cdot 10^5, 1 \leq m \leq 2 \cdot 10^5$, $1 \le 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 \leq i \leq m$) of the next $m$ lines contains two integers $x$ and $y$ ($1\leq x, y\leq n$, $x\ne 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\leq i\leq 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$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.375
|
{"tests": "{\"inputs\": [\"4\\n7 8\\nAAPAAAAA\\nPPPPAAAA\\nPPPPAAAA\\nAPAAPPPP\\nAPAPPAPP\\nAAAAPPAP\\nAAAAPPAA\\n6 5\\nAAAAA\\nAAAAA\\nAAPAA\\nAAPAP\\nAAAPP\\nAAAPP\\n4 4\\nPPPP\\nPPPP\\nPPPP\\nPPPP\\n3 4\\nPPPP\\nPAAP\\nPPPP\\n\", \"1\\n1 1\\nA\\n\", \"1\\n3 3\\nAAA\\nAAA\\nAAA\\n\", \"1\\n4 4\\nAAAA\\nAAAA\\nAAAA\\nAAAA\\n\", \"1\\n2 2\\nAA\\nAA\\n\"], \"outputs\": [\"2\\n1\\nMORTAL\\n4\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
You are an all-powerful being and you have created a rectangular world. In fact, your world is so bland that it could be represented by a $r \times c$ grid. Each cell on the grid represents a country. Each country has a dominant religion. There are only two religions in your world. One of the religions is called Beingawesomeism, who do good for the sake of being good. The other religion is called Pushingittoofarism, who do murders for the sake of being bad.
Oh, and you are actually not really all-powerful. You just have one power, which you can use infinitely many times! Your power involves missionary groups. When a missionary group of a certain country, say $a$, passes by another country $b$, they change the dominant religion of country $b$ to the dominant religion of country $a$.
In particular, a single use of your power is this: You choose a horizontal $1 \times x$ subgrid or a vertical $x \times 1$ subgrid. That value of $x$ is up to you; You choose a direction $d$. If you chose a horizontal subgrid, your choices will either be NORTH or SOUTH. If you choose a vertical subgrid, your choices will either be EAST or WEST; You choose the number $s$ of steps; You command each country in the subgrid to send a missionary group that will travel $s$ steps towards direction $d$. In each step, they will visit (and in effect convert the dominant religion of) all $s$ countries they pass through, as detailed above. The parameters $x$, $d$, $s$ must be chosen in such a way that any of the missionary groups won't leave the grid.
The following image illustrates one possible single usage of your power. Here, A represents a country with dominant religion Beingawesomeism and P represents a country with dominant religion Pushingittoofarism. Here, we've chosen a $1 \times 4$ subgrid, the direction NORTH, and $s = 2$ steps. [Image]
You are a being which believes in free will, for the most part. However, you just really want to stop receiving murders that are attributed to your name. Hence, you decide to use your powers and try to make Beingawesomeism the dominant religion in every country.
What is the minimum number of usages of your power needed to convert everyone to Beingawesomeism?
With god, nothing is impossible. But maybe you're not god? If it is impossible to make Beingawesomeism the dominant religion in all countries, you must also admit your mortality and say so.
-----Input-----
The first line of input contains a single integer $t$ ($1 \le t \le 2\cdot 10^4$) denoting the number of test cases.
The first line of each test case contains two space-separated integers $r$ and $c$ denoting the dimensions of the grid ($1 \le r, c \le 60$). The next $r$ lines each contains $c$ characters describing the dominant religions in the countries. In particular, the $j$-th character in the $i$-th line describes the dominant religion in the country at the cell with row $i$ and column $j$, where: "A" means that the dominant religion is Beingawesomeism; "P" means that the dominant religion is Pushingittoofarism.
It is guaranteed that the grid will only contain "A" or "P" characters. It is guaranteed that the sum of the $r \cdot c$ in a single file is at most $3 \cdot 10^6$.
-----Output-----
For each test case, output a single line containing the minimum number of usages of your power needed to convert everyone to Beingawesomeism, or the string "MORTAL" (without quotes) if it is impossible to do so.
-----Example-----
Input
4
7 8
AAPAAAAA
PPPPAAAA
PPPPAAAA
APAAPPPP
APAPPAPP
AAAAPPAP
AAAAPPAA
6 5
AAAAA
AAAAA
AAPAA
AAPAP
AAAPP
AAAPP
4 4
PPPP
PPPP
PPPP
PPPP
3 4
PPPP
PAAP
PPPP
Output
2
1
MORTAL
4
-----Note-----
In the first test case, it can be done in two usages, as follows:
Usage 1: [Image]
Usage 2: [Image]
In the second test case, it can be done with just one usage of the power.
In the third test case, it is impossible to convert everyone to Beingawesomeism, so the answer is "MORTAL".
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n1 3\\n2 3\\n4 3\\n4\\n2 1 2\\n3 2 3 4\\n3 1 2 4\\n4 1 2 3 4\\n\", \"7\\n1 2\\n2 3\\n3 4\\n1 5\\n5 6\\n5 7\\n1\\n4 2 4 6 7\\n\", \"7\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n5\\n4 1 3 5 7\\n3 2 4 6\\n2 1 7\\n2 3 4\\n3 1 6 7\\n\", \"30\\n1 2\\n1 3\\n1 4\\n2 5\\n2 6\\n2 7\\n4 8\\n4 9\\n6 10\\n6 11\\n11 30\\n11 23\\n30 24\\n30 25\\n25 26\\n25 27\\n27 29\\n27 28\\n23 20\\n23 22\\n20 21\\n20 19\\n3 12\\n3 13\\n13 14\\n13 15\\n15 16\\n15 17\\n15 18\\n2\\n6 17 25 20 5 9 13\\n10 2 4 3 14 16 18 22 29 30 19\\n\", \"4\\n1 2\\n2 3\\n1 4\\n1\\n3 1 3 4\\n\"], \"outputs\": [\"1\\n-1\\n1\\n-1\\n\", \"2\\n\", \"3\\n2\\n1\\n-1\\n-1\\n\", \"3\\n6\\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
Meanwhile, the kingdom of K is getting ready for the marriage of the King's daughter. However, in order not to lose face in front of the relatives, the King should first finish reforms in his kingdom. As the King can not wait for his daughter's marriage, reforms must be finished as soon as possible.
The kingdom currently consists of n cities. Cities are connected by n - 1 bidirectional road, such that one can get from any city to any other city. As the King had to save a lot, there is only one path between any two cities.
What is the point of the reform? The key ministries of the state should be relocated to distinct cities (we call such cities important). However, due to the fact that there is a high risk of an attack by barbarians it must be done carefully. The King has made several plans, each of which is described by a set of important cities, and now wonders what is the best plan.
Barbarians can capture some of the cities that are not important (the important ones will have enough protection for sure), after that the captured city becomes impassable. In particular, an interesting feature of the plan is the minimum number of cities that the barbarians need to capture in order to make all the important cities isolated, that is, from all important cities it would be impossible to reach any other important city.
Help the King to calculate this characteristic for each of his plan.
-----Input-----
The first line of the input contains integer n (1 ≤ n ≤ 100 000) — the number of cities in the kingdom.
Each of the next n - 1 lines contains two distinct integers u_{i}, v_{i} (1 ≤ u_{i}, v_{i} ≤ n) — the indices of the cities connected by the i-th road. It is guaranteed that you can get from any city to any other one moving only along the existing roads.
The next line contains a single integer q (1 ≤ q ≤ 100 000) — the number of King's plans.
Each of the next q lines looks as follows: first goes number k_{i} — the number of important cities in the King's plan, (1 ≤ k_{i} ≤ n), then follow exactly k_{i} space-separated pairwise distinct numbers from 1 to n — the numbers of important cities in this plan.
The sum of all k_{i}'s does't exceed 100 000.
-----Output-----
For each plan print a single integer — the minimum number of cities that the barbarians need to capture, or print - 1 if all the barbarians' attempts to isolate important cities will not be effective.
-----Examples-----
Input
4
1 3
2 3
4 3
4
2 1 2
3 2 3 4
3 1 2 4
4 1 2 3 4
Output
1
-1
1
-1
Input
7
1 2
2 3
3 4
1 5
5 6
5 7
1
4 2 4 6 7
Output
2
-----Note-----
In the first sample, in the first and the third King's plan barbarians can capture the city 3, and that will be enough. In the second and the fourth plans all their attempts will not be effective.
In the second sample the cities to capture are 3 and 5.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n1 2\\n2 4\\n1 10\\n\", \"55\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n2 2\\n2 3\\n2 4\\n2 5\\n2 6\\n2 7\\n2 8\\n2 9\\n2 10\\n3 3\\n3 4\\n3 5\\n3 6\\n3 7\\n3 8\\n3 9\\n3 10\\n4 4\\n4 5\\n4 6\\n4 7\\n4 8\\n4 9\\n4 10\\n5 5\\n5 6\\n5 7\\n5 8\\n5 9\\n5 10\\n6 6\\n6 7\\n6 8\\n6 9\\n6 10\\n7 7\\n7 8\\n7 9\\n7 10\\n8 8\\n8 9\\n8 10\\n9 9\\n9 10\\n10 10\\n\", \"18\\n1 10\\n1 100\\n1 1000\\n1 10000\\n1 100000\\n1 1000000\\n1 10000000\\n1 100000000\\n1 1000000000\\n1 10000000000\\n1 100000000000\\n1 1000000000000\\n1 10000000000000\\n1 100000000000000\\n1 1000000000000000\\n1 10000000000000000\\n1 100000000000000000\\n1 1000000000000000000\\n\", \"3\\n0 0\\n1 3\\n2 4\\n\", \"17\\n0 0\\n0 8\\n1 8\\n36 39\\n3 4\\n3 7\\n2 17\\n8 12\\n9 12\\n10 12\\n10 15\\n6 14\\n8 15\\n9 15\\n15 15\\n100000000000000000 1000000000000000000\\n99999999999999999 1000000000000000000\\n\"], \"outputs\": [\"1\\n3\\n7\\n\", \"1\\n1\\n3\\n3\\n3\\n3\\n7\\n7\\n7\\n7\\n2\\n3\\n3\\n3\\n3\\n7\\n7\\n7\\n7\\n3\\n3\\n3\\n3\\n7\\n7\\n7\\n7\\n4\\n5\\n5\\n7\\n7\\n7\\n7\\n5\\n5\\n7\\n7\\n7\\n7\\n6\\n7\\n7\\n7\\n7\\n7\\n7\\n7\\n7\\n8\\n9\\n9\\n9\\n9\\n10\\n\", \"7\\n63\\n511\\n8191\\n65535\\n524287\\n8388607\\n67108863\\n536870911\\n8589934591\\n68719476735\\n549755813887\\n8796093022207\\n70368744177663\\n562949953421311\\n9007199254740991\\n72057594037927935\\n576460752303423487\\n\", \"0\\n3\\n3\\n\", \"0\\n7\\n7\\n39\\n3\\n7\\n15\\n11\\n11\\n11\\n15\\n7\\n15\\n15\\n15\\n576460752303423487\\n576460752303423487\\n\"]}", "source": "primeintellect"}
|
Let's denote as $\text{popcount}(x)$ the number of bits set ('1' bits) in the binary representation of the non-negative integer x.
You are given multiple queries consisting of pairs of integers l and r. For each query, find the x, such that l ≤ x ≤ r, and $\text{popcount}(x)$ is maximum possible. If there are multiple such numbers find the smallest of them.
-----Input-----
The first line contains integer n — the number of queries (1 ≤ n ≤ 10000).
Each of the following n lines contain two integers l_{i}, r_{i} — the arguments for the corresponding query (0 ≤ l_{i} ≤ r_{i} ≤ 10^18).
-----Output-----
For each query print the answer in a separate line.
-----Examples-----
Input
3
1 2
2 4
1 10
Output
1
3
7
-----Note-----
The binary representations of numbers from 1 to 10 are listed below:
1_10 = 1_2
2_10 = 10_2
3_10 = 11_2
4_10 = 100_2
5_10 = 101_2
6_10 = 110_2
7_10 = 111_2
8_10 = 1000_2
9_10 = 1001_2
10_10 = 1010_2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n1 1\\n1 2\\n2 1\\n2 2\\n\", \"4\\n3 2\\n1 2\\n4 1\\n4 2\\n2 2\\n4 4\\n2 1\\n1 3\\n\", \"4\\n1 1\\n2 2\\n3 3\\n4 4\\n1 2\\n2 1\\n3 4\\n4 3\\n\", \"8\\n6 2\\n5 1\\n6 8\\n7 8\\n6 5\\n5 7\\n4 3\\n1 4\\n7 6\\n8 3\\n2 8\\n3 6\\n3 2\\n8 5\\n1 5\\n5 8\\n\", \"3\\n1 1\\n1 2\\n1 3\\n2 1\\n2 2\\n2 3\\n\"], \"outputs\": [\"8\\n\", \"7392\\n\", \"4480\\n\", \"82060779\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
There are 2N balls in the xy-plane. The coordinates of the i-th of them is (x_i, y_i).
Here, x_i and y_i are integers between 1 and N (inclusive) for all i, and no two balls occupy the same coordinates.
In order to collect these balls, Snuke prepared 2N robots, N of type A and N of type B.
Then, he placed the type-A robots at coordinates (1, 0), (2, 0), ..., (N, 0), and the type-B robots at coordinates (0, 1), (0, 2), ..., (0, N), one at each position.
When activated, each type of robot will operate as follows.
- When a type-A robot is activated at coordinates (a, 0), it will move to the position of the ball with the lowest y-coordinate among the balls on the line x = a, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
- When a type-B robot is activated at coordinates (0, b), it will move to the position of the ball with the lowest x-coordinate among the balls on the line y = b, collect the ball and deactivate itself. If there is no such ball, it will just deactivate itself without doing anything.
Once deactivated, a robot cannot be activated again. Also, while a robot is operating, no new robot can be activated until the operating robot is deactivated.
When Snuke was about to activate a robot, he noticed that he may fail to collect all the balls, depending on the order of activating the robots.
Among the (2N)! possible orders of activating the robots, find the number of the ones such that all the balls can be collected, modulo 1 000 000 007.
-----Constraints-----
- 2 \leq N \leq 10^5
- 1 \leq x_i \leq N
- 1 \leq y_i \leq N
- If i ≠ j, either x_i ≠ x_j or y_i ≠ y_j.
-----Inputs-----
Input is given from Standard Input in the following format:
N
x_1 y_1
...
x_{2N} y_{2N}
-----Outputs-----
Print the number of the orders of activating the robots such that all the balls can be collected, modulo 1 000 000 007.
-----Sample Input-----
2
1 1
1 2
2 1
2 2
-----Sample Output-----
8
We will refer to the robots placed at (1, 0) and (2, 0) as A1 and A2, respectively, and the robots placed at (0, 1) and (0, 2) as B1 and B2, respectively.
There are eight orders of activation that satisfy the condition, as follows:
- A1, B1, A2, B2
- A1, B1, B2, A2
- A1, B2, B1, A2
- A2, B1, A1, B2
- B1, A1, B2, A2
- B1, A1, A2, B2
- B1, A2, A1, B2
- B2, A1, B1, A2
Thus, the output should be 8.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 2\\n2 3\\n1 4\\n\", \"3 4\\n2 5 10\\n1 3 7 13\\n\", \"4 1\\n1 2 4 5\\n3\\n\", \"4 5\\n2 5 7 11\\n1 3 6 9 13\\n\", \"10 10\\n4 13 15 18 19 20 21 22 25 27\\n1 5 11 12 14 16 23 26 29 30\\n\"], \"outputs\": [\"3\\n\", \"8\\n\", \"1\\n\", \"6\\n\", \"22\\n\"]}", "source": "primeintellect"}
|
There are N robots and M exits on a number line.
The N + M coordinates of these are all integers and all distinct.
For each i (1 \leq i \leq N), the coordinate of the i-th robot from the left is x_i.
Also, for each j (1 \leq j \leq M), the coordinate of the j-th exit from the left is y_j.
Snuke can repeatedly perform the following two kinds of operations in any order to move all the robots simultaneously:
- Increment the coordinates of all the robots on the number line by 1.
- Decrement the coordinates of all the robots on the number line by 1.
Each robot will disappear from the number line when its position coincides with that of an exit, going through that exit.
Snuke will continue performing operations until all the robots disappear.
When all the robots disappear, how many combinations of exits can be used by the robots?
Find the count modulo 10^9 + 7.
Here, two combinations of exits are considered different when there is a robot that used different exits in those two combinations.
-----Constraints-----
- 1 \leq N, M \leq 10^5
- 1 \leq x_1 < x_2 < ... < x_N \leq 10^9
- 1 \leq y_1 < y_2 < ... < y_M \leq 10^9
- All given coordinates are integers.
- All given coordinates are distinct.
-----Input-----
Input is given from Standard Input in the following format:
N M
x_1 x_2 ... x_N
y_1 y_2 ... y_M
-----Output-----
Print the number of the combinations of exits that can be used by the robots when all the robots disappear, modulo 10^9 + 7.
-----Sample Input-----
2 2
2 3
1 4
-----Sample Output-----
3
The i-th robot from the left will be called Robot i, and the j-th exit from the left will be called Exit j.
There are three possible combinations of exits (the exit used by Robot 1, the exit used by Robot 2) as follows:
- (Exit 1, Exit 1)
- (Exit 1, Exit 2)
- (Exit 2, Exit 2)
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n1 3\\n5 7\\n1 3\\n\", \"3\\n2 5\\n4 6\\n1 4\\n\", \"5\\n999999999 1000000000\\n1 2\\n314 315\\n500000 500001\\n999999999 1000000000\\n\", \"5\\n123456 789012\\n123 456\\n12 345678901\\n123456 789012\\n1 23\\n\", \"1\\n1 400\\n\"], \"outputs\": [\"2\\n\", \"0\\n\", \"1999999680\\n\", \"246433\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
AtCoDeer the deer found N rectangle lying on the table, each with height 1.
If we consider the surface of the desk as a two-dimensional plane, the i-th rectangle i(1≤i≤N) covers the vertical range of [i-1,i] and the horizontal range of [l_i,r_i], as shown in the following figure:
AtCoDeer will move these rectangles horizontally so that all the rectangles are connected.
For each rectangle, the cost to move it horizontally by a distance of x, is x.
Find the minimum cost to achieve connectivity.
It can be proved that this value is always an integer under the constraints of the problem.
-----Constraints-----
- All input values are integers.
- 1≤N≤10^5
- 1≤l_i<r_i≤10^9
-----Partial Score-----
- 300 points will be awarded for passing the test set satisfying 1≤N≤400 and 1≤l_i<r_i≤400.
-----Input-----
The input is given from Standard Input in the following format:
N
l_1 r_1
l_2 r_2
:
l_N r_N
-----Output-----
Print the minimum cost to achieve connectivity.
-----Sample Input-----
3
1 3
5 7
1 3
-----Sample Output-----
2
The second rectangle should be moved to the left by a distance of 2.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n1 2\\n\", \"4\\n1000 100 10 1\\n\", \"5\\n1 3 4 5 2\\n\", \"1\\n10000000\\n\", \"4\\n1 5 8 4\\n\", \"3\\n1 3 2\\n\", \"4\\n3 1 2 4\\n\", \"12\\n7 1 62 12 3 5 8 9 10 22 23 0\\n\", \"17\\n1 3 2 5 4 6 7 8 10 9 13 11 12 14 15 16 18\\n\", \"22\\n1 3 5 7 22 2 4 6 8 9 10 11 12 13 15 14 17 18 16 20 19 23\\n\", \"22\\n17 6 1 22 9 23 38 40 10 20 29 11 12 39 3 32 26 4 13 36 14 35\\n\", \"22\\n27 21 12 14 8 40 47 45 24 49 36 37 17 32 42 13 35 10 18 2 5 30\\n\", \"22\\n33 2 19 26 18 13 27 9 25 35 6 24 20 22 11 5 1 30 17 15 7 29\\n\", \"22\\n18 37 15 33 35 5 14 1 0 27 22 11 40 20 13 2 30 21 8 25 32 16\\n\", \"22\\n4 24 22 18 28 3 17 8 29 20 11 15 13 2 19 26 5 36 33 14 30 25\\n\", \"22\\n28 40 5 38 29 12 21 24 2 33 35 17 30 11 16 0 8 27 34 14 19 36\\n\", \"22\\n25 12 38 5 6 20 30 27 4 19 8 18 10 17 26 32 43 14 40 35 1 22\\n\", \"22\\n2 22 21 19 3 25 28 11 10 9 14 37 18 38 15 23 20 34 7 30 31 4\\n\", \"22\\n7 0 23 37 20 18 46 26 2 24 44 13 47 15 32 5 35 30 39 41 27 10\\n\", \"22\\n36 5 7 22 33 30 14 8 25 24 28 12 19 29 37 2 20 15 10 17 13 21\\n\", \"22\\n23 32 13 39 29 41 40 6 21 10 38 42 4 8 20 35 31 26 15 2 17 5\\n\", \"22\\n41 12 14 36 16 21 0 2 18 22 39 29 40 31 37 25 28 9 4 34 6 43\\n\", \"22\\n32 43 3 37 29 42 40 12 28 1 14 25 34 46 8 35 5 17 2 23 20 9\\n\", \"22\\n17 10 24 44 41 33 48 6 30 27 38 19 16 46 22 8 35 13 5 9 4 1\\n\", \"22\\n16 11 29 30 12 5 3 2 13 6 17 15 9 24 25 35 1 27 0 23 20 33\\n\", \"22\\n12 38 6 37 14 26 2 0 9 17 28 33 3 11 15 8 31 21 29 34 18 24\\n\", \"22\\n20 38 26 32 36 8 44 0 40 41 35 21 11 17 29 33 1 42 24 14 5 3\\n\", \"22\\n7 10 1 25 42 8 39 35 6 19 31 24 16 0 21 32 11 28 13 4 37 22\\n\", \"22\\n9 13 7 20 38 40 27 12 31 25 1 23 46 35 45 29 19 16 33 4 42 39\\n\", \"22\\n13 2 10 25 5 34 19 18 16 9 7 22 28 20 31 38 36 35 1 26 6 23\\n\", \"22\\n106855341 41953605 16663229 140358177 145011760 49391214 42672526 1000000000 173686818 18529133 155326121 177597841 65855243 125680752 111261017 47020618 35558283 100881772 149421816 84207033 181739589 185082482\\n\", \"22\\n177663922 168256855 139197944 78700101 93490895 127229611 46317725 84284513 48674853 66142856 29224095 1000000000 138390832 117500569 98525700 100418194 44827621 151960474 43225995 16918107 53307514 48861499\\n\", \"22\\n83255567 39959119 124812899 157774437 12694468 89732189 102545715 67019496 110206980 98186415 63181429 141617294 177406424 195504716 158928060 64956133 67949891 31436243 155002729 1000000000 128745406 52504492\\n\", \"22\\n138499935 195582510 159774498 12295611 37071371 91641202 167958938 119995178 19438466 182405139 207729895 56797798 79876605 152841775 1000000000 149079380 158867321 154637978 72179187 75460169 145092927 103227705\\n\", \"22\\n133295371 188010892 71730560 209842234 193069109 184556873 87395258 234247052 230809052 211444018 148989732 17810977 158722706 11753932 100093528 1000000000 43672080 61357581 171830832 13873487 34865589 114340079\\n\", \"22\\n94506085 195061283 78884975 27418524 41348358 185397891 151515774 66605535 170723638 212843258 218566729 7450050 21809921 1000000000 146101141 132453297 228865386 240705035 57636433 114219677 158240908 228428432\\n\", \"22\\n116213533 171312666 76695399 60099180 30779320 43431323 146620629 15321904 71245898 94843310 56549974 104020167 84091716 134384095 24383373 83975332 1000000000 101710173 188076412 199811222 153566780 115893674\\n\", \"22\\n79749952 42551386 1000000000 60427603 50702468 16899307 85913428 116634789 151569595 100251788 152378664 96284924 60769416 136345503 59995727 88224321 29257228 64921932 77805288 126026727 103477637 115959196\\n\", \"22\\n32119698 129510003 107370317 182795872 160438101 17245069 117836566 141016185 196664039 215252245 170450315 18866624 68629021 47385728 77249092 89835593 132769095 95649030 48749357 126701972 40219294 1000000000\\n\", \"22\\n148671024 180468173 99388811 78666746 187172484 157360521 112604605 2988530 60271244 163263697 27469084 166381131 1000000000 125847469 137766458 198740424 88387613 15152912 200315776 149201551 45997250 36252057\\n\"], \"outputs\": [\"2 1 \\n\", \"100 1 1000 10\\n\", \"5 2 3 4 1 \\n\", \"10000000 \\n\", \"8 4 5 1 \\n\", \"3 2 1 \\n\", \"2 4 1 3 \\n\", \"5 0 23 10 1 3 7 8 9 12 22 62 \\n\", \"18 2 1 4 3 5 6 7 9 8 12 10 11 13 14 15 16 \\n\", \"23 2 4 6 20 1 3 5 7 8 9 10 11 12 14 13 16 17 15 19 18 22 \\n\", \"14 4 40 20 6 22 36 39 9 17 26 10 11 38 1 29 23 3 12 35 13 32 \\n\", \"24 18 10 13 5 37 45 42 21 47 35 36 14 30 40 12 32 8 17 49 2 27 \\n\", \"30 1 18 25 17 11 26 7 24 33 5 22 19 20 9 2 35 29 15 13 6 27 \\n\", \"16 35 14 32 33 2 13 0 40 25 21 8 37 18 11 1 27 20 5 22 30 15 \\n\", \"3 22 20 17 26 2 15 5 28 19 8 14 11 36 18 25 4 33 30 13 29 24 \\n\", \"27 38 2 36 28 11 19 21 0 30 34 16 29 8 14 40 5 24 33 12 17 35 \\n\", \"22 10 35 4 5 19 27 26 1 18 6 17 8 14 25 30 40 12 38 32 43 20 \\n\", \"38 21 20 18 2 23 25 10 9 7 11 34 15 37 14 22 19 31 4 28 30 3 \\n\", \"5 47 20 35 18 15 44 24 0 23 41 10 46 13 30 2 32 27 37 39 26 7 \\n\", \"33 2 5 21 30 29 13 7 24 22 25 10 17 28 36 37 19 14 8 15 12 20 \\n\", \"21 31 10 38 26 40 39 5 20 8 35 41 2 6 17 32 29 23 13 42 15 4 \\n\", \"40 9 12 34 14 18 43 0 16 21 37 28 39 29 36 22 25 6 2 31 4 41 \\n\", \"29 42 2 35 28 40 37 9 25 46 12 23 32 43 5 34 3 14 1 20 17 8 \\n\", \"16 9 22 41 38 30 46 5 27 24 35 17 13 44 19 6 33 10 4 8 1 48 \\n\", \"15 9 27 29 11 3 2 1 12 5 16 13 6 23 24 33 0 25 35 20 17 30 \\n\", \"11 37 3 34 12 24 0 38 8 15 26 31 2 9 14 6 29 18 28 33 17 21 \\n\", \"17 36 24 29 35 5 42 44 38 40 33 20 8 14 26 32 0 41 21 11 3 1 \\n\", \"6 8 0 24 39 7 37 32 4 16 28 22 13 42 19 31 10 25 11 1 35 21 \\n\", \"7 12 4 19 35 39 25 9 29 23 46 20 45 33 42 27 16 13 31 1 40 38 \\n\", \"10 1 9 23 2 31 18 16 13 7 6 20 26 19 28 36 35 34 38 25 5 22 \\n\", \"100881772 35558283 1000000000 125680752 140358177 47020618 41953605 185082482 155326121 16663229 149421816 173686818 49391214 111261017 106855341 42672526 18529133 84207033 145011760 65855243 177597841 181739589 \\n\", \"168256855 151960474 138390832 66142856 84284513 117500569 44827621 78700101 46317725 53307514 16918107 177663922 127229611 100418194 93490895 98525700 43225995 139197944 29224095 1000000000 48861499 48674853 \\n\", \"67949891 31436243 110206980 155002729 1000000000 83255567 98186415 64956133 102545715 89732189 52504492 128745406 158928060 177406424 157774437 63181429 67019496 12694468 141617294 195504716 124812899 39959119 \\n\", \"119995178 182405139 158867321 1000000000 19438466 79876605 159774498 103227705 12295611 167958938 195582510 37071371 75460169 149079380 207729895 145092927 154637978 152841775 56797798 72179187 138499935 91641202 \\n\", \"114340079 184556873 61357581 193069109 188010892 171830832 71730560 230809052 211444018 209842234 133295371 13873487 148989732 1000000000 87395258 234247052 34865589 43672080 158722706 11753932 17810977 100093528 \\n\", \"78884975 185397891 66605535 21809921 27418524 170723638 146101141 57636433 158240908 195061283 212843258 1000000000 7450050 240705035 132453297 114219677 228428432 228865386 41348358 94506085 151515774 218566729 \\n\", \"115893674 153566780 71245898 56549974 24383373 30779320 134384095 1000000000 60099180 84091716 43431323 101710173 83975332 116213533 15321904 76695399 199811222 94843310 171312666 188076412 146620629 104020167 \\n\", \"77805288 29257228 152378664 59995727 42551386 1000000000 79749952 115959196 136345503 96284924 151569595 88224321 60427603 126026727 50702468 85913428 16899307 60769416 64921932 116634789 100251788 103477637 \\n\", \"18866624 126701972 95649030 170450315 141016185 1000000000 107370317 132769095 182795872 196664039 160438101 17245069 48749357 40219294 68629021 77249092 129510003 89835593 47385728 117836566 32119698 215252245 \\n\", \"137766458 166381131 88387613 60271244 180468173 149201551 99388811 1000000000 45997250 157360521 15152912 163263697 200315776 112604605 125847469 187172484 78666746 2988530 198740424 148671024 36252057 27469084 \\n\"]}", "source": "primeintellect"}
|
You are given an array a with n distinct integers. Construct an array b by permuting a such that for every non-empty subset of indices S = {x_1, x_2, ..., x_{k}} (1 ≤ x_{i} ≤ n, 0 < k < n) the sums of elements on that positions in a and b are different, i. e. $\sum_{i = 1}^{k} a_{x_{i}} \neq \sum_{i = 1}^{k} b_{x_{i}}$
-----Input-----
The first line contains one integer n (1 ≤ n ≤ 22) — the size of the array.
The second line contains n space-separated distinct integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} ≤ 10^9) — the elements of the array.
-----Output-----
If there is no such array b, print -1.
Otherwise in the only line print n space-separated integers b_1, b_2, ..., b_{n}. Note that b must be a permutation of a.
If there are multiple answers, print any of them.
-----Examples-----
Input
2
1 2
Output
2 1
Input
4
1000 100 10 1
Output
100 1 1000 10
-----Note-----
An array x is a permutation of y, if we can shuffle elements of y such that it will coincide with x.
Note that the empty subset and the subset containing all indices are not counted.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 1 998244353\\n\", \"1 2 1000000007\\n\", \"10 8 861271909\\n\", \"2 1 905589253\\n\", \"14 19 964292983\\n\", \"24 26 804695321\\n\", \"39 36 991399517\\n\", \"46 46 961455263\\n\", \"60 55 931711961\\n\", \"64 64 879068783\\n\", \"75 77 988580261\\n\", \"89 89 942910693\\n\", \"94 94 826395733\\n\", \"96 90 819042001\\n\", \"99 96 867494357\\n\", \"93 90 952438633\\n\", \"99 97 849572149\\n\", \"100 100 996766481\\n\", \"1 1 1000000009\\n\", \"77 47 984380351\\n\", \"69 15 857601697\\n\", \"42 94 907502863\\n\", \"25 38 900878039\\n\"], \"outputs\": [\"1\\n3\\n1\\n\", \"2\\n\", \"8\\n602\\n81827\\n4054238\\n41331779\\n41331779\\n4054238\\n81827\\n602\\n8\\n\", \"1\\n1\\n\", \"19\\n40239\\n116285439\\n44188045\\n615501833\\n534054421\\n694441861\\n694441861\\n534054421\\n615501833\\n44188045\\n116285439\\n40239\\n19\\n\", \"26\\n316385\\n587325446\\n562348028\\n259395159\\n735586658\\n540711096\\n448382968\\n646169129\\n665286086\\n740680401\\n638151860\\n638151860\\n740680401\\n665286086\\n646169129\\n448382968\\n540711096\\n735586658\\n259395159\\n562348028\\n587325446\\n316385\\n26\\n\", \"36\\n3667920\\n990929167\\n858401463\\n60493630\\n785191252\\n714265038\\n453588092\\n382455915\\n582064241\\n401317628\\n441250455\\n403968890\\n230277786\\n432651121\\n410095141\\n951960058\\n916461902\\n641905774\\n948722200\\n641905774\\n916461902\\n951960058\\n410095141\\n432651121\\n230277786\\n403968890\\n441250455\\n401317628\\n582064241\\n382455915\\n453588092\\n714265038\\n785191252\\n60493630\\n858401463\\n990929167\\n3667920\\n36\\n\", \"46\\n30370929\\n166679864\\n575290604\\n194798504\\n252130064\\n445139667\\n765778720\\n850511791\\n84674874\\n116060159\\n145552585\\n387190100\\n700612085\\n942254961\\n156013598\\n731283537\\n729273362\\n945901131\\n779104366\\n172673174\\n208486221\\n861159317\\n861159317\\n208486221\\n172673174\\n779104366\\n945901131\\n729273362\\n731283537\\n156013598\\n942254961\\n700612085\\n387190100\\n145552585\\n116060159\\n84674874\\n850511791\\n765778720\\n445139667\\n252130064\\n194798504\\n575290604\\n166679864\\n30370929\\n46\\n\", \"55\\n167152439\\n128555668\\n452169460\\n643905949\\n564166013\\n107864137\\n829142158\\n441763502\\n504605298\\n881084581\\n745369157\\n165726026\\n347696005\\n335989092\\n224952495\\n581117185\\n108036073\\n23523713\\n890135712\\n292644259\\n89593977\\n548089517\\n38923823\\n577648100\\n401357148\\n249060686\\n489717600\\n558942321\\n63131721\\n63131721\\n558942321\\n489717600\\n249060686\\n401357148\\n577648100\\n38923823\\n548089517\\n89593977\\n292644259\\n890135712\\n23523713\\n108036073\\n581117185\\n224952495\\n335989092\\n347696005\\n165726026\\n745369157\\n881084581\\n504605298\\n441763502\\n829142158\\n107864137\\n564166013\\n643905949\\n452169460\\n128555668\\n167152439\\n55\\n\", \"64\\n800028839\\n273410689\\n196010624\\n312953380\\n227966059\\n861538616\\n217255633\\n551899524\\n272244211\\n529845574\\n363735259\\n82493642\\n864217314\\n260504844\\n624735861\\n777035883\\n168402978\\n60765332\\n70545429\\n703637526\\n112727240\\n298194780\\n873071920\\n613410636\\n624439078\\n129940147\\n656653400\\n554594139\\n519526204\\n586168365\\n613826896\\n613826896\\n586168365\\n519526204\\n554594139\\n656653400\\n129940147\\n624439078\\n613410636\\n873071920\\n298194780\\n112727240\\n703637526\\n70545429\\n60765332\\n168402978\\n777035883\\n624735861\\n260504844\\n864217314\\n82493642\\n363735259\\n529845574\\n272244211\\n551899524\\n217255633\\n861538616\\n227966059\\n312953380\\n196010624\\n273410689\\n800028839\\n64\\n\", \"77\\n421332563\\n185730875\\n360429166\\n675372404\\n881609639\\n484733434\\n634909079\\n103284953\\n925194231\\n264709881\\n123064656\\n502896411\\n644256875\\n967090113\\n333204169\\n966807529\\n626419932\\n488814458\\n208653026\\n689831686\\n979969185\\n837738878\\n843170164\\n390592437\\n274900757\\n230073000\\n23105152\\n399821886\\n853236996\\n535025854\\n628541071\\n444492493\\n947338316\\n422517124\\n190711625\\n699376661\\n435761061\\n699376661\\n190711625\\n422517124\\n947338316\\n444492493\\n628541071\\n535025854\\n853236996\\n399821886\\n23105152\\n230073000\\n274900757\\n390592437\\n843170164\\n837738878\\n979969185\\n689831686\\n208653026\\n488814458\\n626419932\\n966807529\\n333204169\\n967090113\\n644256875\\n502896411\\n123064656\\n264709881\\n925194231\\n103284953\\n634909079\\n484733434\\n881609639\\n675372404\\n360429166\\n185730875\\n421332563\\n77\\n\", \"89\\n39936542\\n195454156\\n656721203\\n631357927\\n217894594\\n154160725\\n638317552\\n840343374\\n174218327\\n425232179\\n1907817\\n221399060\\n55623559\\n449859916\\n461977473\\n524410836\\n443896072\\n234283060\\n570186728\\n299135533\\n47682698\\n540920573\\n561289612\\n25067383\\n813997840\\n918322355\\n877125510\\n438792625\\n646455342\\n644567581\\n890924735\\n81674404\\n355946581\\n926266101\\n254402052\\n641374921\\n393575974\\n399528713\\n92571866\\n589016560\\n708936745\\n420527488\\n549659078\\n273155421\\n549659078\\n420527488\\n708936745\\n589016560\\n92571866\\n399528713\\n393575974\\n641374921\\n254402052\\n926266101\\n355946581\\n81674404\\n890924735\\n644567581\\n646455342\\n438792625\\n877125510\\n918322355\\n813997840\\n25067383\\n561289612\\n540920573\\n47682698\\n299135533\\n570186728\\n234283060\\n443896072\\n524410836\\n461977473\\n449859916\\n55623559\\n221399060\\n1907817\\n425232179\\n174218327\\n840343374\\n638317552\\n154160725\\n217894594\\n631357927\\n656721203\\n195454156\\n39936542\\n89\\n\", \"94\\n265647617\\n387893472\\n738066733\\n86520619\\n656163016\\n405429313\\n815078307\\n443616344\\n512145331\\n542638582\\n288885865\\n666773848\\n709611994\\n646076824\\n247485371\\n446663954\\n246800688\\n649240945\\n265806909\\n152772875\\n515165398\\n187931766\\n759636807\\n199845139\\n428693396\\n67862667\\n647890913\\n760379559\\n752677492\\n667415202\\n812228423\\n510963606\\n794915058\\n17109908\\n628664401\\n485963811\\n625518961\\n92045152\\n802943188\\n746052666\\n507545653\\n517587489\\n427928558\\n470452524\\n321506149\\n131834334\\n131834334\\n321506149\\n470452524\\n427928558\\n517587489\\n507545653\\n746052666\\n802943188\\n92045152\\n625518961\\n485963811\\n628664401\\n17109908\\n794915058\\n510963606\\n812228423\\n667415202\\n752677492\\n760379559\\n647890913\\n67862667\\n428693396\\n199845139\\n759636807\\n187931766\\n515165398\\n152772875\\n265806909\\n649240945\\n246800688\\n446663954\\n247485371\\n646076824\\n709611994\\n666773848\\n288885865\\n542638582\\n512145331\\n443616344\\n815078307\\n405429313\\n656163016\\n86520619\\n738066733\\n387893472\\n265647617\\n94\\n\", \"90\\n605059907\\n198354410\\n673849386\\n154926763\\n134866344\\n8143772\\n133537054\\n538291720\\n521277234\\n592295168\\n203941089\\n238588787\\n452945189\\n814482829\\n494205724\\n669134365\\n22231530\\n282834938\\n124550795\\n786873606\\n198947801\\n518473614\\n62028843\\n365088103\\n243952808\\n548001686\\n441376661\\n175994898\\n531078863\\n753716927\\n736722144\\n192384599\\n400227229\\n385944721\\n612335759\\n497648657\\n294111241\\n395772069\\n583481712\\n258116318\\n352563916\\n301818365\\n39031126\\n154208355\\n530213436\\n621647514\\n172670134\\n172670134\\n621647514\\n530213436\\n154208355\\n39031126\\n301818365\\n352563916\\n258116318\\n583481712\\n395772069\\n294111241\\n497648657\\n612335759\\n385944721\\n400227229\\n192384599\\n736722144\\n753716927\\n531078863\\n175994898\\n441376661\\n548001686\\n243952808\\n365088103\\n62028843\\n518473614\\n198947801\\n786873606\\n124550795\\n282834938\\n22231530\\n669134365\\n494205724\\n814482829\\n452945189\\n238588787\\n203941089\\n592295168\\n521277234\\n538291720\\n133537054\\n8143772\\n134866344\\n154926763\\n673849386\\n198354410\\n605059907\\n90\\n\", \"96\\n685266867\\n527860958\\n789289317\\n713564179\\n257781899\\n508052569\\n104685750\\n389322717\\n501801759\\n772987295\\n796745275\\n698454400\\n43415064\\n202285109\\n352495965\\n125867619\\n204240242\\n413335850\\n850872935\\n550672387\\n79471915\\n64271624\\n200594784\\n716610756\\n5761613\\n715198701\\n353401623\\n61922631\\n226677476\\n272502365\\n379041771\\n551125092\\n118531346\\n62521874\\n235953669\\n814328146\\n540492797\\n331642406\\n174779148\\n268311874\\n571246065\\n768120496\\n508250596\\n216464438\\n6807407\\n279555138\\n563007377\\n226571514\\n276909105\\n226571514\\n563007377\\n279555138\\n6807407\\n216464438\\n508250596\\n768120496\\n571246065\\n268311874\\n174779148\\n331642406\\n540492797\\n814328146\\n235953669\\n62521874\\n118531346\\n551125092\\n379041771\\n272502365\\n226677476\\n61922631\\n353401623\\n715198701\\n5761613\\n716610756\\n200594784\\n64271624\\n79471915\\n550672387\\n850872935\\n413335850\\n204240242\\n125867619\\n352495965\\n202285109\\n43415064\\n698454400\\n796745275\\n772987295\\n501801759\\n389322717\\n104685750\\n508052569\\n257781899\\n713564179\\n789289317\\n527860958\\n685266867\\n96\\n\", \"90\\n468902106\\n485522357\\n689600349\\n346418139\\n519338271\\n810724072\\n897803765\\n64130697\\n596372297\\n465126204\\n153828222\\n573899326\\n163922387\\n258187325\\n478590158\\n867882463\\n407682638\\n304803105\\n731744538\\n344115139\\n650567430\\n5381611\\n357554030\\n327622805\\n31048393\\n127295835\\n609753679\\n115362652\\n812800874\\n779982579\\n756428708\\n445446657\\n735981697\\n125553883\\n512144322\\n896302026\\n828192680\\n670960735\\n269693996\\n516441322\\n707196425\\n441384939\\n660859365\\n597885806\\n66815060\\n115095319\\n66815060\\n597885806\\n660859365\\n441384939\\n707196425\\n516441322\\n269693996\\n670960735\\n828192680\\n896302026\\n512144322\\n125553883\\n735981697\\n445446657\\n756428708\\n779982579\\n812800874\\n115362652\\n609753679\\n127295835\\n31048393\\n327622805\\n357554030\\n5381611\\n650567430\\n344115139\\n731744538\\n304803105\\n407682638\\n867882463\\n478590158\\n258187325\\n163922387\\n573899326\\n153828222\\n465126204\\n596372297\\n64130697\\n897803765\\n810724072\\n519338271\\n346418139\\n689600349\\n485522357\\n468902106\\n90\\n\", \"97\\n589156599\\n413310414\\n399392037\\n735443568\\n656304478\\n685373311\\n56971929\\n368708146\\n820048313\\n769297270\\n545603290\\n654387200\\n637238807\\n275596041\\n638866195\\n628642797\\n230183692\\n623776482\\n765354019\\n410591775\\n457328422\\n77533099\\n729425767\\n278214124\\n658483227\\n674143923\\n504019775\\n824605928\\n644153286\\n271263992\\n391336921\\n206818896\\n755033913\\n623313116\\n599798791\\n355088061\\n459910242\\n791189018\\n637243903\\n183102384\\n232445783\\n216439644\\n460942725\\n437526552\\n231405479\\n300621429\\n841239066\\n166285887\\n635742144\\n166285887\\n841239066\\n300621429\\n231405479\\n437526552\\n460942725\\n216439644\\n232445783\\n183102384\\n637243903\\n791189018\\n459910242\\n355088061\\n599798791\\n623313116\\n755033913\\n206818896\\n391336921\\n271263992\\n644153286\\n824605928\\n504019775\\n674143923\\n658483227\\n278214124\\n729425767\\n77533099\\n457328422\\n410591775\\n765354019\\n623776482\\n230183692\\n628642797\\n638866195\\n275596041\\n637238807\\n654387200\\n545603290\\n769297270\\n820048313\\n368708146\\n56971929\\n685373311\\n656304478\\n735443568\\n399392037\\n413310414\\n589156599\\n97\\n\", \"100\\n479013218\\n301906461\\n76865454\\n197164919\\n185261994\\n562146154\\n218533225\\n703919664\\n761757943\\n421733444\\n150668448\\n939625796\\n441056419\\n399708797\\n265484256\\n872130614\\n530113978\\n956321625\\n942851863\\n391142590\\n196625433\\n784864879\\n819183001\\n159683454\\n296917015\\n221161941\\n731209317\\n448421227\\n627343466\\n96812703\\n658830978\\n929743853\\n634638996\\n987997473\\n521196870\\n640660350\\n267753320\\n902541346\\n262706763\\n514447345\\n954420281\\n621769349\\n892390620\\n720449512\\n837536064\\n273041385\\n337735532\\n151628949\\n784376865\\n784376865\\n151628949\\n337735532\\n273041385\\n837536064\\n720449512\\n892390620\\n621769349\\n954420281\\n514447345\\n262706763\\n902541346\\n267753320\\n640660350\\n521196870\\n987997473\\n634638996\\n929743853\\n658830978\\n96812703\\n627343466\\n448421227\\n731209317\\n221161941\\n296917015\\n159683454\\n819183001\\n784864879\\n196625433\\n391142590\\n942851863\\n956321625\\n530113978\\n872130614\\n265484256\\n399708797\\n441056419\\n939625796\\n150668448\\n421733444\\n761757943\\n703919664\\n218533225\\n562146154\\n185261994\\n197164919\\n76865454\\n301906461\\n479013218\\n100\\n\", \"1\\n\", \"47\\n37005455\\n655827090\\n841853556\\n611622803\\n578616110\\n121504566\\n284904675\\n891634360\\n377336782\\n74305742\\n400674303\\n40726716\\n231832902\\n540371916\\n61720624\\n426204166\\n713024598\\n887235048\\n629982900\\n18435119\\n586810591\\n459813654\\n240930967\\n281061283\\n475993101\\n885733307\\n398851052\\n327924289\\n346318481\\n367661460\\n612707707\\n708292758\\n809657216\\n892969100\\n73795181\\n88286917\\n935190393\\n945731063\\n935190393\\n88286917\\n73795181\\n892969100\\n809657216\\n708292758\\n612707707\\n367661460\\n346318481\\n327924289\\n398851052\\n885733307\\n475993101\\n281061283\\n240930967\\n459813654\\n586810591\\n18435119\\n629982900\\n887235048\\n713024598\\n426204166\\n61720624\\n540371916\\n231832902\\n40726716\\n400674303\\n74305742\\n377336782\\n891634360\\n284904675\\n121504566\\n578616110\\n611622803\\n841853556\\n655827090\\n37005455\\n47\\n\", \"15\\n10943\\n25350255\\n528980058\\n565392555\\n490875203\\n751016925\\n116301690\\n327562015\\n256781058\\n831969974\\n397081586\\n605439049\\n625311459\\n64045373\\n376722122\\n591803433\\n356268338\\n542636205\\n625267543\\n578345629\\n297436059\\n65991694\\n796883879\\n221304789\\n513275577\\n520270726\\n261893767\\n634531775\\n192703632\\n186961710\\n552544729\\n70149983\\n832033597\\n483172204\\n832033597\\n70149983\\n552544729\\n186961710\\n192703632\\n634531775\\n261893767\\n520270726\\n513275577\\n221304789\\n796883879\\n65991694\\n297436059\\n578345629\\n625267543\\n542636205\\n356268338\\n591803433\\n376722122\\n64045373\\n625311459\\n605439049\\n397081586\\n831969974\\n256781058\\n327562015\\n116301690\\n751016925\\n490875203\\n565392555\\n528980058\\n25350255\\n10943\\n15\\n\", \"94\\n854567507\\n188138242\\n470085043\\n455355673\\n700530208\\n656215169\\n812522729\\n463091752\\n311387076\\n205298231\\n578306483\\n182314350\\n607901635\\n163659300\\n720202715\\n792949911\\n252979813\\n528672464\\n198746271\\n30368013\\n30368013\\n198746271\\n528672464\\n252979813\\n792949911\\n720202715\\n163659300\\n607901635\\n182314350\\n578306483\\n205298231\\n311387076\\n463091752\\n812522729\\n656215169\\n700530208\\n455355673\\n470085043\\n188138242\\n854567507\\n94\\n\", \"38\\n5655545\\n464939347\\n500668393\\n269881226\\n392721252\\n665197363\\n554583516\\n778381832\\n863024566\\n587384571\\n782714127\\n393342842\\n782714127\\n587384571\\n863024566\\n778381832\\n554583516\\n665197363\\n392721252\\n269881226\\n500668393\\n464939347\\n5655545\\n38\\n\"]}", "source": "primeintellect"}
|
Given positive integers N, K and M, solve the following problem for every integer x between 1 and N (inclusive):
- Find the number, modulo M, of non-empty multisets containing between 0 and K (inclusive) instances of each of the integers 1, 2, 3 \cdots, N such that the average of the elements is x.
-----Constraints-----
- 1 \leq N, K \leq 100
- 10^8 \leq M \leq 10^9 + 9
- M is prime.
- All values in input are integers.
-----Input-----
Input is given from Standard Input in the following format:
N K M
-----Output-----
Use the following format:
c_1
c_2
:
c_N
Here, c_x should be the number, modulo M, of multisets such that the average of the elements is x.
-----Sample Input-----
3 1 998244353
-----Sample Output-----
1
3
1
Consider non-empty multisets containing between 0 and 1 instance(s) of each of the integers between 1 and 3. Among them, there are:
- one multiset such that the average of the elements is k = 1: \{1\};
- three multisets such that the average of the elements is k = 2: \{2\}, \{1, 3\}, \{1, 2, 3\};
- one multiset such that the average of the elements is k = 3: \{3\}.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n3 10\\n6 3\\n8 2\\n1 4\\n4 10\\n4 1\\n3 2\\n2 6\\n1 100\\n2 15\\n10 11\\n14 100\\n\", \"7\\n5 1000000000\\n2 1\\n1 10\\n1 1\\n4 1000000000\\n3 3\\n1 1000000000\\n5 1\\n2 999999999\\n3 1\\n2 10000000\\n4 10000000\\n10000000 999999999\\n9999900 12\\n9999999 55\\n9999999 1\\n2 1000000\\n1000000 1000000\\n999999 1\\n3 999999911\\n3 1\\n11 1000000000\\n10 9\\n3 1000000000\\n1231 1200\\n1000 800\\n1 100\\n\", \"1\\n1 1\\n3 1\\n\", \"1\\n2 10\\n8 10\\n11 14\\n\", \"1\\n1 1\\n1 100\\n\", \"1\\n1 1\\n10 10\\n\", \"1\\n1 10\\n11 100\\n\", \"1\\n1 5\\n6 7\\n\", \"1\\n1 8\\n10 100\\n\", \"1\\n1 10\\n10 11\\n\", \"1\\n5 10\\n1 2\\n2 3\\n3 4\\n4 5\\n999 9999\\n\", \"1\\n2 100\\n100 101\\n1 101\\n\", \"1\\n1 10\\n20 25\\n\", \"1\\n1 10\\n11 12\\n\", \"1\\n1 5\\n5 5\\n\", \"1\\n1 10\\n20 10000\\n\", \"1\\n2 10\\n10 120\\n8 10\\n\", \"1\\n2 5\\n10 100\\n2 1\\n\", \"1\\n5 5\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n\", \"1\\n2 1\\n1 1\\n1 1\\n\", \"1\\n1 5\\n5 7\\n\", \"1\\n1 10\\n10 10\\n\", \"1\\n3 10\\n11 11\\n12 12\\n13 13\\n\", \"1\\n1 100\\n100 1000\\n\", \"1\\n1 1\\n2 2\\n\", \"1\\n1 100\\n101 110\\n\", \"1\\n5 10\\n2 1\\n3 2\\n4 3\\n5 4\\n999 999\\n\", \"1\\n1 100\\n101 102\\n\", \"1\\n3 3\\n1 2\\n2 3\\n3 4\\n\", \"1\\n1 1\\n5 6\\n\", \"1\\n1 10\\n11 9\\n\", \"1\\n3 6\\n7 8\\n10 11\\n2 10\\n\", \"1\\n2 10\\n15 100\\n50 100\\n\", \"1\\n1 5\\n6 10\\n\", \"1\\n1 5\\n5 10\\n\", \"1\\n1 100\\n100 100\\n\", \"1\\n1 1\\n100 1000\\n\", \"1\\n1 100\\n100 500\\n\", \"1\\n1 2\\n2 2\\n\", \"1\\n1 5\\n5 6\\n\", \"1\\n1 17\\n17 17\\n\", \"1\\n2 287724084\\n410622275 558519327\\n460165364 773440538\\n\", \"1\\n2 10\\n15 100\\n20 100\\n\", \"1\\n1 10\\n15 2\\n\", \"1\\n1 10\\n10000 10000\\n\", \"1\\n2 100\\n1 2\\n100 100\\n\", \"1\\n1 1\\n1 1\\n\", \"1\\n1 5\\n7 7\\n\", \"1\\n1 5\\n10 20\\n\", \"1\\n2 5\\n6 10\\n7 8\\n\", \"1\\n1 1\\n3 2\\n\", \"1\\n3 10\\n51 52\\n53 54\\n55 56\\n\", \"1\\n1 3\\n4 5\\n\", \"1\\n1 3\\n7 9\\n\", \"1\\n2 3\\n7 9\\n7 9\\n\", \"1\\n2 10\\n15 20\\n2 5\\n\", \"1\\n2 5\\n3 3\\n6 6\\n\", \"1\\n1 1\\n1 2\\n\", \"1\\n1 1\\n1000 2000\\n\", \"1\\n1 3\\n3 4\\n\", \"1\\n2 10\\n11 20\\n10 20\\n\", \"1\\n2 10\\n2 5\\n11 15\\n\", \"1\\n2 1\\n13 13\\n5 4\\n\", \"1\\n3 7\\n1 2\\n2 3\\n7 8\\n\", \"1\\n1 10000\\n10002 20000\\n\", \"1\\n1 10\\n15 100\\n\", \"1\\n3 1\\n1 1\\n1 1\\n4 1\\n\", \"1\\n1 10\\n100 200\\n\", \"1\\n2 10\\n3 5\\n11 15\\n\", \"7\\n2 10\\n5 3\\n5 4\\n2 10\\n2 2\\n2 5\\n2 2\\n2 2\\n2 5\\n3 3\\n1 1\\n2 2\\n3 3\\n3 3\\n3 1\\n3 2\\n3 3\\n3 5\\n3 1\\n3 2\\n3 3\\n4 40\\n39 40\\n5 2\\n11 1\\n18 8\\n\", \"1\\n1 10\\n11 123\\n\", \"1\\n3 4\\n1 3\\n2 2\\n9 9\\n\", \"1\\n2 9\\n9 10\\n1 9\\n\", \"1\\n1 491766614\\n580887809 696119733\\n\", \"1\\n1 10\\n99 654\\n\", \"1\\n2 1000\\n9 8\\n1002 1001\\n\", \"1\\n1 10\\n100 100\\n\", \"1\\n2 10\\n10 15\\n10 15\\n\", \"1\\n1 5\\n10 10\\n\", \"1\\n1 1\\n1000000000 999999999\\n\", \"1\\n3 2\\n1 2\\n2 3\\n3 4\\n\", \"1\\n2 1\\n555 777\\n7 1\\n\", \"1\\n1 10\\n10 100\\n\", \"1\\n3 10\\n8 10\\n11 1\\n5 6\\n\", \"1\\n3 4\\n1 3\\n2 6\\n5 10\\n\", \"1\\n3 10\\n100 1022\\n2 3\\n4 5\\n\", \"1\\n3 10\\n12 13\\n14 15\\n16 17\\n\", \"1\\n1 9\\n10 11\\n\", \"1\\n2 1\\n2 2\\n1 1\\n\", \"1\\n1 2\\n10 1\\n\", \"1\\n2 10\\n2 3\\n10 100\\n\", \"1\\n1 2\\n2 3\\n\", \"1\\n1 100\\n100 101\\n\", \"1\\n1 11\\n11 11\\n\", \"1\\n1 5\\n9 9\\n\", \"1\\n1 10\\n10 15\\n\", \"1\\n1 1\\n10 20\\n\", \"2\\n2 10\\n11 12\\n1 1\\n1 10\\n3 2\\n\", \"1\\n5 5\\n3 2\\n4 3\\n5 4\\n6 5\\n7 6\\n\", \"1\\n1 1\\n100 99\\n\", \"1\\n1 10\\n10 13\\n\", \"1\\n1 4\\n4 5\\n\", \"1\\n1 10\\n10 19\\n\", \"1\\n2 10\\n12 15\\n15 17\\n\", \"1\\n1 10\\n11 1\\n\", \"1\\n2 209810534\\n506067088 741292314\\n137757052 779663018\\n\", \"1\\n1 20\\n20 25\\n\", \"1\\n1 4\\n5 8\\n\", \"1\\n3 1\\n1 1\\n1 1\\n1 1\\n\", \"1\\n1 10\\n10 20\\n\", \"1\\n2 100\\n100 101\\n6 7\\n\", \"1\\n1 100\\n101 100\\n\", \"1\\n1 2\\n3 2\\n\", \"1\\n1 10\\n11 80\\n\", \"1\\n2 2\\n23 54\\n69 69\\n\", \"1\\n1 10\\n12 15\\n\", \"1\\n1 89811704\\n189906434 633748930\\n\", \"1\\n2 10\\n12 14\\n2 4\\n\", \"1\\n2 1000\\n9 8\\n1002 1000\\n\", \"1\\n2 5\\n100 1\\n4 1\\n\", \"1\\n1 10\\n100 99\\n\", \"1\\n2 5\\n10 10\\n2 1\\n\", \"1\\n1 10\\n11 20\\n\", \"1\\n1 2\\n4 1\\n\", \"1\\n1 5\\n5 10000\\n\", \"1\\n2 5\\n10 10\\n10 10\\n\", \"1\\n4 10\\n500 502\\n7 6\\n4 5\\n6 8\\n\", \"1\\n1 1\\n5 5\\n\", \"1\\n2 5\\n5 5\\n2 2\\n\", \"1\\n3 4\\n1 3\\n2 2\\n4 4\\n\", \"1\\n1 1\\n1 1000\\n\", \"1\\n2 5\\n6 7\\n4 8\\n\", \"1\\n3 10\\n1 2\\n2 3\\n11 15\\n\", \"1\\n1 6\\n7 10\\n\", \"1\\n5 1\\n1 2\\n1 6\\n13 15\\n3 7\\n5 5\\n\", \"1\\n1 1\\n1 10\\n\", \"1\\n2 1\\n2 2\\n2 2\\n\", \"1\\n1 2\\n3 3\\n\", \"1\\n2 10\\n1 10000\\n10 10000\\n\", \"1\\n3 6\\n4 8\\n5 9\\n6 99\\n\", \"1\\n1 20\\n21 23\\n\", \"1\\n1 6\\n10 6\\n\", \"1\\n3 5\\n3 4\\n4 5\\n5 6\\n\", \"2\\n1 10\\n10 15\\n1 10\\n10 10\\n\", \"1\\n1 9\\n10 9\\n\", \"1\\n1 3\\n4 4\\n\", \"1\\n1 1\\n10 11\\n\", \"1\\n1 100\\n101 3000\\n\", \"1\\n3 1\\n20 10\\n100 101\\n1 5\\n\", \"2\\n1 1\\n2 1\\n1 1\\n2 1\\n\", \"1\\n2 9\\n100 100\\n1 9\\n\", \"1\\n1 10\\n20 30\\n\", \"1\\n1 3\\n3 3\\n\", \"1\\n1 1\\n2 3\\n\", \"1\\n5 5\\n2 1\\n3 2\\n4 3\\n5 4\\n6 5\\n\", \"1\\n2 30\\n100 99\\n10 2\\n\", \"1\\n2 9\\n9 100\\n1 9\\n\", \"1\\n1 10\\n11 13\\n\", \"1\\n5 10\\n10 1\\n10 1\\n10 1\\n10 1\\n10 1\\n\", \"1\\n2 5\\n30 1\\n5 2\\n\", \"1\\n2 100806436\\n842674389 898363387\\n210544824 952928428\\n\", \"3\\n3 10\\n6000 300000\\n8 2\\n1 4\\n4 10\\n4 1\\n3 2\\n2 6\\n1 100\\n2 15\\n10 11\\n14 100\\n\", \"2\\n3 10\\n6 3\\n8 2\\n1 4\\n3 10\\n12 13\\n14 15\\n16 17\\n\", \"1\\n1 4\\n5 6\\n\", \"1\\n1 1\\n10000 9999\\n\", \"1\\n1 10\\n20 100\\n\", \"1\\n3 10\\n11 20\\n12 20\\n13 20\\n\", \"1\\n1 2\\n4 100\\n\", \"2\\n1 1\\n1 1\\n1 5\\n4 3\\n\", \"1\\n2 10\\n10 11\\n11 9\\n\", \"1\\n1 1\\n5 666\\n\", \"1\\n2 1000\\n500 8\\n1002 1000\\n\", \"1\\n1 1\\n3 4567\\n\", \"1\\n1 10\\n100 1000\\n\", \"1\\n2 10\\n10 12\\n6 6\\n\", \"1\\n1 100\\n101 3455\\n\", \"1\\n1 2\\n2 100\\n\", \"1\\n2 8\\n9 3\\n2 5\\n\", \"1\\n3 12\\n1 1\\n12 13\\n2 2\\n\", \"1\\n1 4\\n5 4\\n\", \"1\\n3 10\\n1 2\\n2 3\\n10 15\\n\", \"1\\n1 4\\n5 5\\n\", \"1\\n2 6\\n8 9\\n4 5\\n\", \"2\\n1 1\\n5 3\\n1 1\\n5 7\\n\", \"1\\n2 10\\n8 10\\n11 15\\n\", \"3\\n2 3\\n9 7\\n9 7\\n2 20\\n8 5\\n3 1\\n2 21\\n8 5\\n3 1\\n\", \"1\\n1 1000\\n9999 9998\\n\", \"1\\n1 10\\n11 15\\n\", \"2\\n11 236954583\\n902012977 320763974\\n795972796 981875810\\n849039459 256297310\\n782811205 953973488\\n262492899 708681326\\n833903408 988437142\\n830999367 921787976\\n909531471 330119840\\n672682916 669593112\\n307978155 979351913\\n758319968 46137816\\n5 875387866\\n950231414 197254148\\n854504122 480138329\\n319447758 525876673\\n777901059 142050710\\n67202045 969307738\\n\", \"1\\n2 15\\n15 16\\n3 5\\n\", \"1\\n1 10\\n10 12\\n\", \"1\\n1 5\\n7 6\\n\", \"1\\n2 10\\n100 95\\n10 1\\n\", \"1\\n12 790047110\\n714642478 7205470\\n381215384 839029596\\n191781258 384578253\\n167922554 359020009\\n12430721 23222566\\n45051351 597654656\\n128899497 204770156\\n514457749 198042762\\n967258595 333421841\\n503721720 888792850\\n662475029 195770292\\n316890699 632578367\\n\", \"1\\n1 1\\n1000 999\\n\", \"1\\n2 5\\n5 6\\n4 6\\n\", \"1\\n1 1\\n3 4\\n\", \"1\\n2 1\\n2 1\\n9 1\\n\", \"1\\n1 1\\n21 20\\n\", \"1\\n2 2\\n100 1\\n3 2\\n\", \"1\\n1 5\\n6 9\\n\", \"2\\n1 6\\n6 6\\n2 6\\n8 9\\n4 5\\n\", \"1\\n4 2\\n2 5\\n3 5\\n4 5\\n5 5\\n\", \"3\\n2 398083007\\n686447318 668381376\\n422715566 612018694\\n5 648145615\\n229660856 653591442\\n12444108 167654072\\n639943528 197810896\\n964979355 258904556\\n874646832 700273338\\n4 731014817\\n214843599 471451702\\n602930121 250804331\\n567630290 666424069\\n888754797 421013037\\n\", \"1\\n2 10\\n1000 1000\\n9 1\\n\", \"3\\n6 11456887\\n997675914 458860071\\n264651355 659381898\\n539251720 829968843\\n463998465 202892606\\n170824635 110122375\\n354836349 313752791\\n3 566100868\\n125389553 456048140\\n43407260 34704081\\n682940726 758773192\\n11 483018644\\n924702809 255692722\\n312155389 379172890\\n530348500 666383977\\n664288622 460695848\\n149388464 374322915\\n183579194 1485347\\n90522297 239403951\\n686084898 544011746\\n319167381 235062727\\n490344138 599696655\\n103868854 345455072\\n\", \"3\\n5 334943905\\n691877845 590800271\\n852210365 891315257\\n695598357 697313782\\n123985514 104901799\\n887775079 636754439\\n1 69138927\\n789294172 133464854\\n13 122804187\\n221740911 622365596\\n327188939 257834630\\n595296972 991905886\\n257013641 634041041\\n315692825 153629258\\n578226816 391573613\\n314822377 156131049\\n737573444 178961145\\n38293225 662681012\\n382876028 755818411\\n233026832 609858818\\n957378758 491249603\\n523943413 881360575\\n\", \"2\\n1 5\\n999 999\\n1 3\\n7 7\\n\", \"1\\n2 10\\n2 1\\n100 100\\n\", \"1\\n7 745132167\\n928769069 893298383\\n653090177 337257634\\n815624998 996403895\\n224663197 845554094\\n663417903 312894963\\n27048664 603602031\\n292571325 286821960\\n\", \"1\\n2 40\\n1000 1000\\n9 1\\n\", \"1\\n2 10\\n1000 1000\\n4 1\\n\", \"1\\n14 53717421\\n865217515 137858932\\n466658902 21520184\\n145652745 913062876\\n641765012 966392701\\n71291526 265158769\\n76450464 956645142\\n883239294 975007070\\n691295831 225929568\\n577001921 532543299\\n572467945 507218178\\n48561331 764461747\\n254137352 63844123\\n81777574 607109424\\n940294572 422353762\\n\", \"1\\n2 10\\n11 11\\n2 2\\n\", \"1\\n1 9\\n10 20\\n\", \"1\\n12 51427082\\n313775771 974893234\\n486055065 680686555\\n891079673 827082888\\n392061048 844818093\\n587844063 506386243\\n259101840 755677625\\n583100762 11654427\\n933805977 303701130\\n417576054 848789361\\n863727087 16520322\\n157119826 312307878\\n889171810 218188458\\n\", \"3\\n6 940859392\\n532160257 888437166\\n254656628 301382706\\n720470406 114473575\\n257681807 169501880\\n454443505 726025264\\n441443506 832262185\\n1 294652649\\n424623279 556935750\\n14 937457215\\n497461770 437660432\\n842140049 954111728\\n303451744 161202041\\n140140704 680926056\\n662206981 584859677\\n55811681 989390067\\n914639886 36410416\\n753079752 341478459\\n959054519 419745532\\n692812350 765020627\\n888209199 650682241\\n831705070 194177867\\n599440034 113913651\\n851642438 445728719\\n\", \"1\\n5 27\\n8 44\\n44 65\\n17 74\\n12 96\\n9 92\\n\", \"5\\n4 807989196\\n770312657 78181451\\n624192034 690910298\\n754831733 354913874\\n519577171 400120478\\n4 491297333\\n546432637 76258441\\n312107971 75446008\\n767483254 958677299\\n84044330 577526244\\n2 177840791\\n197738084 143071228\\n23274563 597315796\\n7 610054060\\n858529462 646280969\\n644068190 462783596\\n820658202 845877177\\n192491527 719512716\\n21905484 960718976\\n548261425 971882256\\n284893133 42507015\\n3 358535210\\n56376506 490101521\\n465816877 732253365\\n339502648 781257233\\n\", \"3\\n11 104209236\\n949583781 458761573\\n780497863 492414882\\n838499633 565322864\\n817039132 348022228\\n723527488 152186300\\n467396274 271801504\\n91422826 344258169\\n268689377 248424263\\n179726899 346924948\\n785270416 609191471\\n941418243 609381696\\n1 209888207\\n719297361 955556943\\n9 15177110\\n841587884 597751827\\n390527478 254837828\\n846003355 65835769\\n78243798 718907088\\n34621371 919537262\\n519930567 569304342\\n973078604 63126305\\n209417213 366621677\\n642152661 965392467\\n\", \"2\\n2 5\\n10 100\\n2 1\\n1 100\\n100 500\\n\", \"1\\n2 4\\n5 5\\n3 2\\n\", \"1\\n1 2\\n2 1000\\n\", \"1\\n2 100\\n3 2\\n105 10000\\n\"], \"outputs\": [\"2\\n3\\n-1\\n\", \"999999997\\n250000000\\n499999999\\n1\\n1\\n499999951\\n4999995\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"4\\n-1\\n1\\n1\\n1\\n2\\n2\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n8\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n3\\n-1\\n\", \"2\\n1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n2\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n5\\n6\\n\", \"1\\n\", \"1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n1\\n1\\n\", \"1\\n\", \"1\\n1\\n1\\n\", \"1\\n1\\n1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"2\\n1\\n1\\n\", \"1\\n\", \"2\\n1\\n1\\n1\\n1\\n\", \"1\\n1\\n1\\n\", \"1\\n1\\n\", \"1\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
You are fighting with Zmei Gorynich — a ferocious monster from Slavic myths, a huge dragon-like reptile with multiple heads!
$m$
Initially Zmei Gorynich has $x$ heads. You can deal $n$ types of blows. If you deal a blow of the $i$-th type, you decrease the number of Gorynich's heads by $min(d_i, curX)$, there $curX$ is the current number of heads. But if after this blow Zmei Gorynich has at least one head, he grows $h_i$ new heads. If $curX = 0$ then Gorynich is defeated.
You can deal each blow any number of times, in any order.
For example, if $curX = 10$, $d = 7$, $h = 10$ then the number of heads changes to $13$ (you cut $7$ heads off, but then Zmei grows $10$ new ones), but if $curX = 10$, $d = 11$, $h = 100$ then number of heads changes to $0$ and Zmei Gorynich is considered defeated.
Calculate the minimum number of blows to defeat Zmei Gorynich!
You have to answer $t$ independent queries.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) – the number of queries.
The first line of each query contains two integers $n$ and $x$ ($1 \le n \le 100$, $1 \le x \le 10^9$) — the number of possible types of blows and the number of heads Zmei initially has, respectively.
The following $n$ lines of each query contain the descriptions of types of blows you can deal. The $i$-th line contains two integers $d_i$ and $h_i$ ($1 \le d_i, h_i \le 10^9$) — the description of the $i$-th blow.
-----Output-----
For each query print the minimum number of blows you have to deal to defeat Zmei Gorynich.
If Zmei Gorynuch cannot be defeated print $-1$.
-----Example-----
Input
3
3 10
6 3
8 2
1 4
4 10
4 1
3 2
2 6
1 100
2 15
10 11
14 100
Output
2
3
-1
-----Note-----
In the first query you can deal the first blow (after that the number of heads changes to $10 - 6 + 3 = 7$), and then deal the second blow.
In the second query you just deal the first blow three times, and Zmei is defeated.
In third query you can not defeat Zmei Gorynich. Maybe it's better to convince it to stop fighting?
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.875
|
{"tests": "{\"inputs\": [\"6 2\\n5 3\\n0\\n0\\n0\\n2 2 1\\n1 4\\n1 5\\n\", \"9 3\\n3 9 5\\n0\\n0\\n3 9 4 5\\n0\\n0\\n1 8\\n1 6\\n1 2\\n2 1 2\\n\", \"3 3\\n1 2 3\\n1 2\\n1 3\\n1 1\\n\", \"5 3\\n2 1 4\\n0\\n0\\n1 5\\n0\\n0\\n\", \"5 2\\n4 1\\n0\\n1 4\\n1 5\\n0\\n2 1 2\\n\", \"5 2\\n4 5\\n2 3 4\\n1 4\\n1 4\\n0\\n0\\n\", \"6 6\\n5 4 3 2 6 1\\n1 4\\n0\\n2 2 6\\n2 3 6\\n3 3 4 6\\n0\\n\", \"6 6\\n4 1 6 3 2 5\\n2 3 5\\n4 1 3 4 5\\n1 5\\n2 3 5\\n0\\n2 1 5\\n\", \"6 5\\n2 4 1 3 5\\n0\\n0\\n0\\n1 1\\n0\\n1 3\\n\", \"7 6\\n4 3 2 1 6 5\\n0\\n2 4 5\\n1 6\\n1 7\\n1 6\\n0\\n1 4\\n\", \"7 2\\n1 5\\n5 2 3 4 5 6\\n2 1 7\\n0\\n3 1 2 7\\n0\\n2 5 7\\n0\\n\", \"7 6\\n2 5 3 1 7 6\\n1 7\\n2 3 7\\n0\\n0\\n0\\n1 3\\n1 2\\n\", \"3 3\\n1 3 2\\n0\\n1 3\\n1 1\\n\", \"10 1\\n1\\n1 5\\n1 3\\n0\\n1 10\\n0\\n1 8\\n1 1\\n2 7 4\\n2 6 2\\n0\\n\", \"1 1\\n1\\n0\\n\", \"2 2\\n1 2\\n0\\n0\\n\", \"2 2\\n2 1\\n0\\n0\\n\", \"2 1\\n1\\n1 2\\n0\\n\", \"2 1\\n1\\n0\\n0\\n\", \"2 1\\n2\\n0\\n1 1\\n\", \"2 1\\n2\\n0\\n0\\n\", \"3 1\\n1\\n2 2 3\\n0\\n1 2\\n\", \"3 3\\n2 1 3\\n0\\n2 1 3\\n1 2\\n\", \"10 3\\n8 4 1\\n1 3\\n0\\n0\\n0\\n1 1\\n2 10 9\\n1 4\\n3 5 1 2\\n2 2 7\\n2 8 4\\n\", \"6 6\\n1 2 3 4 5 6\\n2 2 6\\n1 3\\n2 4 5\\n0\\n1 4\\n1 2\\n\", \"3 2\\n1 3\\n0\\n0\\n1 1\\n\", \"3 1\\n1\\n2 2 3\\n0\\n0\\n\", \"3 3\\n3 1 2\\n0\\n0\\n0\\n\", \"3 3\\n1 2 3\\n0\\n0\\n0\\n\", \"3 2\\n2 1\\n0\\n0\\n0\\n\", \"3 3\\n3 2 1\\n0\\n0\\n0\\n\", \"3 3\\n3 2 1\\n0\\n0\\n0\\n\", \"3 3\\n3 1 2\\n0\\n0\\n0\\n\", \"3 2\\n3 2\\n0\\n1 3\\n1 1\\n\", \"3 3\\n2 1 3\\n0\\n1 1\\n0\\n\", \"3 2\\n3 1\\n1 3\\n0\\n0\\n\", \"3 1\\n3\\n0\\n0\\n1 2\\n\", \"3 1\\n1\\n0\\n1 1\\n0\\n\", \"3 2\\n3 2\\n0\\n1 1\\n1 2\\n\", \"3 3\\n1 2 3\\n0\\n1 1\\n2 1 2\\n\", \"4 2\\n2 3\\n2 3 4\\n1 1\\n0\\n0\\n\", \"4 4\\n3 2 1 4\\n2 2 3\\n1 1\\n1 2\\n1 3\\n\", \"4 2\\n4 3\\n0\\n0\\n0\\n0\\n\", \"4 1\\n1\\n2 2 3\\n0\\n2 2 4\\n0\\n\", \"4 1\\n2\\n0\\n0\\n2 1 4\\n2 1 2\\n\", \"4 4\\n3 1 4 2\\n1 2\\n1 3\\n1 2\\n0\\n\", \"4 4\\n1 3 2 4\\n1 3\\n1 3\\n0\\n1 2\\n\", \"4 1\\n4\\n2 2 4\\n0\\n1 2\\n0\\n\", \"4 2\\n3 1\\n0\\n0\\n0\\n0\\n\", \"4 4\\n3 1 4 2\\n1 4\\n0\\n0\\n0\\n\", \"4 1\\n1\\n1 4\\n2 1 3\\n1 4\\n1 3\\n\", \"4 2\\n3 2\\n0\\n1 4\\n1 1\\n0\\n\", \"4 4\\n2 3 1 4\\n0\\n2 1 3\\n2 1 4\\n0\\n\", \"4 4\\n4 1 2 3\\n2 2 4\\n0\\n0\\n0\\n\", \"4 1\\n1\\n0\\n1 1\\n0\\n0\\n\", \"5 1\\n5\\n0\\n1 1\\n2 2 5\\n0\\n0\\n\", \"5 5\\n1 2 4 3 5\\n0\\n0\\n2 1 2\\n1 5\\n0\\n\", \"5 5\\n2 1 5 4 3\\n1 4\\n0\\n0\\n0\\n1 2\\n\", \"5 2\\n2 4\\n1 2\\n0\\n1 2\\n1 2\\n0\\n\", \"5 2\\n2 1\\n1 3\\n1 3\\n1 1\\n3 1 2 3\\n1 3\\n\", \"5 4\\n5 2 1 3\\n2 3 5\\n1 3\\n0\\n0\\n2 2 4\\n\", \"5 4\\n5 1 4 2\\n0\\n0\\n1 5\\n1 1\\n0\\n\", \"5 2\\n1 3\\n0\\n2 4 5\\n0\\n1 2\\n2 1 2\\n\", \"5 1\\n5\\n1 4\\n2 1 4\\n2 4 5\\n2 2 5\\n1 1\\n\", \"5 4\\n3 2 1 4\\n1 2\\n0\\n0\\n0\\n0\\n\", \"5 1\\n2\\n3 2 3 4\\n0\\n2 2 4\\n0\\n4 1 2 3 4\\n\", \"5 3\\n5 2 4\\n1 4\\n0\\n0\\n0\\n0\\n\", \"5 1\\n3\\n2 4 5\\n0\\n0\\n0\\n1 3\\n\", \"5 3\\n2 5 1\\n1 2\\n0\\n0\\n1 5\\n0\\n\", \"5 3\\n4 2 3\\n0\\n0\\n1 2\\n0\\n1 4\\n\", \"6 4\\n2 1 4 3\\n3 3 4 5\\n1 4\\n0\\n1 3\\n4 2 3 4 6\\n1 3\\n\", \"6 2\\n3 6\\n2 2 3\\n0\\n1 1\\n1 6\\n0\\n0\\n\", \"6 1\\n2\\n0\\n0\\n1 6\\n0\\n1 2\\n0\\n\", \"6 3\\n6 5 1\\n0\\n1 1\\n0\\n1 3\\n0\\n1 5\\n\", \"6 6\\n1 3 6 5 4 2\\n0\\n0\\n0\\n0\\n0\\n0\\n\", \"6 5\\n3 4 1 6 5\\n2 2 6\\n2 4 5\\n1 1\\n0\\n1 4\\n0\\n\", \"6 2\\n5 2\\n1 4\\n0\\n1 2\\n0\\n0\\n1 5\\n\", \"6 6\\n4 5 1 6 3 2\\n0\\n1 6\\n1 1\\n2 1 3\\n1 1\\n2 1 3\\n\", \"6 6\\n3 2 4 1 5 6\\n1 6\\n1 1\\n0\\n1 5\\n0\\n0\\n\", \"6 1\\n3\\n2 4 6\\n2 4 6\\n2 1 2\\n1 2\\n1 2\\n1 5\\n\", \"6 6\\n5 1 2 3 6 4\\n0\\n0\\n0\\n0\\n1 4\\n1 1\\n\", \"6 5\\n3 6 2 4 1\\n1 4\\n1 3\\n0\\n0\\n0\\n2 1 5\\n\", \"6 4\\n4 3 6 5\\n0\\n0\\n3 1 4 5\\n1 6\\n1 6\\n0\\n\", \"6 1\\n1\\n0\\n0\\n1 5\\n0\\n0\\n1 5\\n\", \"6 6\\n4 2 5 6 1 3\\n1 3\\n0\\n2 5 6\\n2 2 6\\n1 2\\n1 4\\n\", \"7 7\\n1 7 6 2 5 4 3\\n0\\n2 5 6\\n1 5\\n1 2\\n0\\n1 1\\n1 1\\n\", \"7 6\\n6 3 5 1 4 7\\n0\\n0\\n0\\n0\\n1 1\\n1 2\\n1 1\\n\", \"7 2\\n2 3\\n0\\n0\\n0\\n0\\n0\\n1 4\\n0\\n\", \"7 4\\n7 5 4 2\\n0\\n2 6 7\\n0\\n1 3\\n2 2 6\\n0\\n2 3 4\\n\", \"7 6\\n5 4 2 1 6 7\\n2 2 7\\n1 5\\n0\\n0\\n1 3\\n1 2\\n0\\n\", \"7 4\\n2 1 6 7\\n0\\n2 3 6\\n1 6\\n0\\n2 1 3\\n1 7\\n0\\n\", \"7 2\\n5 1\\n4 2 5 6 7\\n1 5\\n5 1 2 5 6 7\\n1 2\\n0\\n0\\n4 2 4 5 6\\n\", \"7 1\\n5\\n2 2 5\\n0\\n2 5 7\\n0\\n1 6\\n0\\n0\\n\", \"7 6\\n5 7 2 4 3 6\\n2 5 7\\n0\\n3 2 5 7\\n2 2 6\\n0\\n0\\n2 2 5\\n\", \"7 4\\n6 4 7 3\\n0\\n0\\n2 2 5\\n1 6\\n2 1 7\\n2 1 2\\n0\\n\", \"7 5\\n1 5 4 7 2\\n1 4\\n4 1 4 6 7\\n2 1 4\\n1 6\\n3 3 4 7\\n0\\n0\\n\", \"2 1\\n1\\n0\\n1 1\\n\", \"2 1\\n1\\n1 2\\n1 1\\n\", \"2 1\\n2\\n1 2\\n0\\n\", \"2 1\\n2\\n1 2\\n1 1\\n\", \"2 2\\n1 2\\n1 2\\n0\\n\", \"2 2\\n2 1\\n0\\n1 1\\n\", \"2 2\\n2 1\\n1 2\\n1 1\\n\", \"7 1\\n4\\n0\\n6 1 3 4 5 6 7\\n4 1 4 6 7\\n2 1 7\\n4 1 3 6 7\\n2 3 4\\n0\\n\", \"7 2\\n1 2\\n0\\n0\\n3 2 4 6\\n1 3\\n1 6\\n1 5\\n0\\n\", \"7 4\\n1 7 6 2\\n1 7\\n0\\n0\\n0\\n1 1\\n0\\n0\\n\", \"7 6\\n3 7 4 1 6 2\\n2 4 6\\n0\\n0\\n3 2 3 5\\n1 3\\n1 2\\n3 1 5 6\\n\", \"8 5\\n7 1 2 8 3\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n\", \"8 3\\n4 8 7\\n0\\n1 3\\n0\\n1 2\\n0\\n0\\n1 1\\n0\\n\", \"8 2\\n2 6\\n0\\n0\\n0\\n2 5 7\\n0\\n2 1 2\\n0\\n3 1 2 3\\n\", \"8 6\\n8 3 6 4 7 5\\n0\\n1 4\\n1 4\\n1 8\\n1 7\\n1 4\\n0\\n0\\n\", \"8 7\\n2 5 3 6 4 8 1\\n3 3 5 6\\n1 3\\n2 4 5\\n4 1 2 5 6\\n2 1 2\\n2 2 8\\n1 2\\n2 6 7\\n\", \"8 5\\n2 5 8 3 1\\n3 2 5 6\\n1 5\\n1 4\\n5 1 5 6 7 8\\n0\\n2 2 8\\n4 1 3 5 6\\n1 2\\n\", \"8 5\\n6 4 7 5 1\\n1 7\\n1 6\\n1 1\\n0\\n0\\n0\\n1 5\\n1 7\\n\", \"8 3\\n3 1 8\\n0\\n3 4 6 7\\n2 6 7\\n2 3 6\\n2 4 6\\n1 1\\n1 1\\n1 3\\n\", \"8 8\\n6 3 1 2 4 8 5 7\\n0\\n0\\n0\\n2 5 7\\n0\\n1 5\\n0\\n1 1\\n\", \"8 5\\n2 1 5 7 6\\n1 8\\n3 3 4 6\\n0\\n0\\n1 6\\n0\\n0\\n0\\n\", \"8 8\\n3 1 2 7 8 4 5 6\\n2 4 8\\n2 3 8\\n1 6\\n0\\n2 4 6\\n0\\n5 2 3 4 5 8\\n2 3 4\\n\", \"8 3\\n4 3 1\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n\", \"8 1\\n3\\n0\\n3 1 3 6\\n0\\n0\\n1 1\\n0\\n1 6\\n1 7\\n\", \"8 8\\n5 8 7 2 1 3 4 6\\n1 3\\n3 1 3 4\\n0\\n0\\n1 1\\n1 5\\n0\\n2 4 6\\n\", \"8 7\\n6 3 7 8 1 5 4\\n0\\n2 1 5\\n0\\n2 7 8\\n1 4\\n0\\n0\\n0\\n\", \"9 9\\n6 3 1 4 2 9 5 7 8\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n0\\n\", \"9 3\\n5 7 3\\n3 3 4 5\\n4 4 6 7 9\\n2 1 2\\n2 3 5\\n1 3\\n4 4 5 7 8\\n3 1 4 5\\n3 1 3 4\\n7 1 2 4 5 6 7 8\\n\", \"9 6\\n1 6 7 4 5 3\\n2 2 6\\n3 5 6 8\\n5 2 4 5 6 9\\n3 5 6 8\\n0\\n0\\n5 2 3 5 6 9\\n4 1 3 5 6\\n5 1 2 4 6 8\\n\", \"9 8\\n4 2 9 1 8 3 7 6\\n0\\n2 1 8\\n0\\n0\\n1 1\\n2 1 8\\n2 6 8\\n3 4 5 9\\n5 1 2 5 7 8\\n\", \"9 2\\n6 9\\n2 3 9\\n0\\n1 8\\n1 6\\n3 3 6 7\\n1 2\\n1 9\\n0\\n0\\n\", \"9 6\\n5 4 3 2 6 7\\n3 4 5 9\\n1 6\\n4 1 5 8 9\\n3 3 5 6\\n0\\n0\\n2 3 8\\n1 3\\n0\\n\", \"9 8\\n2 8 4 7 3 6 9 5\\n0\\n1 4\\n0\\n0\\n0\\n1 8\\n0\\n3 2 3 7\\n0\\n\", \"9 6\\n6 7 1 5 9 2\\n0\\n0\\n0\\n0\\n1 4\\n0\\n0\\n2 1 3\\n1 6\\n\", \"9 4\\n5 1 2 3\\n1 7\\n0\\n1 8\\n0\\n0\\n3 1 5 8\\n1 6\\n2 5 7\\n2 1 4\\n\", \"9 8\\n4 8 6 9 5 7 2 3\\n0\\n1 4\\n0\\n3 2 6 8\\n1 6\\n1 7\\n0\\n0\\n2 3 6\\n\", \"9 3\\n8 5 3\\n3 3 6 9\\n1 5\\n1 5\\n1 8\\n1 2\\n1 3\\n1 9\\n1 5\\n0\\n\", \"9 6\\n7 3 1 6 4 2\\n1 3\\n0\\n1 7\\n1 8\\n1 4\\n1 7\\n1 8\\n0\\n2 1 7\\n\", \"9 2\\n7 4\\n1 2\\n0\\n1 7\\n0\\n1 1\\n0\\n0\\n2 2 6\\n1 5\\n\", \"9 5\\n3 8 2 5 1\\n1 5\\n3 1 6 7\\n3 4 6 8\\n3 2 6 9\\n2 7 9\\n2 5 7\\n1 2\\n2 4 5\\n2 1 6\\n\", \"9 4\\n6 9 7 8\\n3 5 8 9\\n1 3\\n1 4\\n0\\n2 4 9\\n2 4 9\\n5 2 3 4 8 9\\n0\\n1 7\\n\", \"10 1\\n7\\n2 4 10\\n1 8\\n2 4 8\\n0\\n1 3\\n1 2\\n2 3 5\\n1 7\\n0\\n1 1\\n\", \"10 2\\n9 4\\n0\\n0\\n0\\n0\\n1 7\\n0\\n0\\n1 9\\n0\\n0\\n\", \"10 3\\n7 5 3\\n3 3 4 5\\n1 10\\n1 7\\n3 2 6 7\\n1 7\\n0\\n0\\n3 1 4 6\\n3 2 3 5\\n1 6\\n\", \"10 1\\n1\\n1 5\\n1 1\\n3 4 6 10\\n1 1\\n0\\n4 1 2 5 9\\n4 1 6 9 10\\n6 1 2 3 6 9 10\\n2 2 5\\n4 1 2 5 9\\n\", \"10 1\\n4\\n0\\n0\\n0\\n0\\n1 10\\n0\\n0\\n0\\n0\\n0\\n\", \"10 10\\n6 2 4 5 8 1 9 3 10 7\\n4 2 7 8 9\\n2 7 9\\n5 1 6 8 9 10\\n2 7 9\\n6 1 4 6 7 8 9\\n1 8\\n0\\n2 4 9\\n0\\n4 2 4 7 9\\n\", \"10 5\\n2 1 10 4 9\\n2 3 6\\n5 1 6 7 8 10\\n3 4 6 7\\n2 1 6\\n2 6 7\\n1 3\\n1 4\\n3 5 6 10\\n4 1 2 8 10\\n4 1 5 6 7\\n\", \"10 5\\n4 8 3 1 6\\n0\\n1 10\\n0\\n0\\n1 3\\n2 3 5\\n1 3\\n1 10\\n2 1 6\\n0\\n\", \"10 8\\n1 5 4 10 6 2 3 9\\n7 3 4 5 6 7 8 10\\n1 5\\n4 2 5 7 10\\n3 2 5 6\\n0\\n3 2 5 7\\n1 2\\n8 1 2 3 5 6 7 9 10\\n4 2 4 6 7\\n3 4 6 7\\n\", \"10 5\\n6 9 8 5 2\\n2 7 9\\n4 4 5 6 7\\n2 6 7\\n2 5 8\\n2 6 9\\n1 9\\n2 2 6\\n3 1 2 7\\n3 3 5 6\\n6 1 2 5 6 8 9\\n\", \"10 7\\n7 10 5 1 9 4 3\\n4 2 4 9 10\\n5 1 4 6 8 9\\n7 2 4 5 6 7 8 10\\n3 3 5 10\\n2 7 10\\n3 4 5 9\\n6 1 2 3 4 6 8\\n4 1 3 4 10\\n1 5\\n1 1\\n\", \"10 9\\n5 1 3 6 10 8 2 9 7\\n0\\n0\\n2 1 6\\n1 3\\n1 4\\n2 5 7\\n1 6\\n0\\n1 8\\n0\\n\", \"10 4\\n2 5 10 9\\n2 2 4\\n5 3 4 6 7 10\\n2 7 10\\n4 1 3 8 10\\n2 6 10\\n2 7 10\\n1 1\\n3 6 7 10\\n1 7\\n3 1 7 8\\n\", \"10 8\\n6 8 2 1 7 10 3 4\\n0\\n2 1 4\\n2 6 7\\n0\\n3 1 8 9\\n3 1 8 9\\n0\\n0\\n1 6\\n1 8\\n\", \"10 3\\n1 6 3\\n1 4\\n1 4\\n0\\n0\\n2 3 10\\n1 2\\n0\\n1 4\\n0\\n1 2\\n\", \"11 2\\n10 7\\n5 2 3 6 10 11\\n0\\n1 8\\n5 1 3 6 9 10\\n4 1 2 3 6\\n1 5\\n5 2 6 9 10 11\\n5 2 3 4 7 11\\n3 3 6 8\\n6 2 4 5 6 8 9\\n3 2 3 5\\n\", \"11 11\\n3 2 1 7 8 4 10 11 9 6 5\\n3 2 7 11\\n0\\n0\\n1 11\\n1 1\\n1 8\\n2 4 5\\n0\\n1 4\\n0\\n0\\n\", \"11 7\\n11 2 1 7 9 8 6\\n0\\n7 3 4 5 6 8 10 11\\n3 1 5 8\\n1 11\\n3 1 7 8\\n7 1 3 4 5 7 8 10\\n3 4 6 8\\n1 5\\n2 8 10\\n4 1 4 5 7\\n5 1 4 6 8 10\\n\", \"11 6\\n7 1 10 3 2 11\\n0\\n1 11\\n0\\n0\\n1 9\\n1 5\\n0\\n0\\n0\\n0\\n0\\n\", \"11 7\\n6 9 7 3 4 10 11\\n4 3 6 8 11\\n3 3 5 9\\n2 6 7\\n1 6\\n1 4\\n0\\n0\\n2 7 9\\n0\\n2 4 11\\n3 6 7 9\\n\", \"11 5\\n10 11 8 2 7\\n1 9\\n1 3\\n0\\n1 6\\n1 1\\n0\\n0\\n1 2\\n2 4 8\\n0\\n0\\n\", \"11 6\\n6 3 11 1 9 4\\n6 2 3 6 7 8 9\\n4 5 6 8 10\\n4 1 2 6 8\\n7 1 3 5 6 7 9 11\\n4 3 6 7 8\\n1 8\\n2 3 9\\n0\\n0\\n5 1 5 7 8 9\\n5 1 2 3 7 8\\n\", \"11 6\\n4 2 9 7 3 1\\n1 11\\n0\\n1 10\\n1 11\\n3 7 8 10\\n1 11\\n1 11\\n1 11\\n0\\n1 2\\n1 2\\n\", \"11 5\\n3 2 5 7 6\\n4 3 5 7 9\\n2 7 9\\n3 7 9 11\\n5 5 6 7 9 10\\n3 7 9 11\\n6 2 3 5 7 10 11\\n0\\n2 7 10\\n0\\n2 2 11\\n2 7 9\\n\", \"11 11\\n11 6 4 7 8 5 1 3 2 9 10\\n5 3 4 7 9 11\\n0\\n1 2\\n1 3\\n2 3 4\\n6 1 3 4 8 10 11\\n1 3\\n2 2 4\\n3 2 4 11\\n5 4 5 7 9 11\\n4 2 3 4 7\\n\", \"11 6\\n7 1 6 4 3 8\\n0\\n0\\n1 2\\n1 1\\n0\\n0\\n1 8\\n0\\n0\\n1 1\\n0\\n\", \"11 3\\n9 11 5\\n0\\n0\\n0\\n0\\n1 8\\n0\\n2 1 11\\n0\\n1 2\\n0\\n0\\n\", \"11 11\\n5 4 2 1 6 10 3 7 11 8 9\\n0\\n1 3\\n0\\n0\\n0\\n2 9 11\\n1 9\\n0\\n0\\n0\\n0\\n\", \"11 10\\n9 6 10 3 2 8 4 7 11 5\\n1 2\\n0\\n5 1 8 9 10 11\\n4 1 7 8 11\\n3 2 7 11\\n3 1 7 10\\n0\\n2 6 11\\n6 1 2 6 7 10 11\\n2 1 11\\n2 1 7\\n\", \"11 10\\n5 8 7 6 1 4 9 3 2 11\\n3 3 8 10\\n2 4 8\\n1 5\\n2 1 11\\n1 4\\n3 4 8 9\\n2 3 11\\n1 5\\n3 1 5 8\\n2 3 5\\n0\\n\", \"12 9\\n9 2 5 7 6 1 10 12 11\\n0\\n3 6 7 12\\n1 4\\n1 7\\n1 3\\n1 1\\n0\\n0\\n2 1 4\\n1 3\\n0\\n2 2 10\\n\", \"12 10\\n2 6 1 5 7 9 10 8 12 3\\n1 10\\n1 9\\n1 11\\n0\\n1 10\\n0\\n1 3\\n1 7\\n1 6\\n1 11\\n0\\n0\\n\", \"12 10\\n9 11 3 6 4 12 2 7 10 8\\n1 7\\n3 7 8 9\\n3 1 8 11\\n4 1 7 9 10\\n1 4\\n1 12\\n1 2\\n1 2\\n0\\n2 1 9\\n1 7\\n1 7\\n\", \"12 3\\n8 10 11\\n4 2 5 6 7\\n5 4 7 8 10 11\\n6 2 4 5 6 8 10\\n2 6 8\\n0\\n3 5 7 8\\n0\\n2 3 7\\n8 2 4 5 6 8 10 11 12\\n2 4 7\\n6 2 3 5 6 7 12\\n5 1 3 6 7 8\\n\", \"12 1\\n8\\n2 2 4\\n1 9\\n1 10\\n1 12\\n4 6 10 11 12\\n0\\n0\\n1 9\\n0\\n1 8\\n0\\n0\\n\", \"12 10\\n4 10 9 6 7 2 1 11 3 8\\n1 4\\n0\\n7 2 4 5 6 7 8 11\\n3 1 10 11\\n3 4 8 12\\n6 4 7 8 10 11 12\\n2 2 11\\n1 11\\n6 3 4 8 10 11 12\\n1 12\\n1 1\\n0\\n\", \"12 3\\n4 7 8\\n2 11 12\\n0\\n0\\n2 3 9\\n3 7 11 12\\n5 1 3 7 8 10\\n1 3\\n0\\n2 2 8\\n1 11\\n0\\n2 8 11\\n\", \"12 9\\n2 10 6 3 4 12 7 1 5\\n0\\n0\\n0\\n1 8\\n0\\n1 8\\n0\\n1 3\\n0\\n0\\n0\\n1 8\\n\", \"12 1\\n10\\n0\\n1 12\\n2 2 9\\n0\\n2 1 2\\n3 1 7 8\\n3 8 9 10\\n0\\n0\\n3 5 11 12\\n0\\n0\\n\", \"12 4\\n5 1 7 3\\n0\\n3 4 5 12\\n0\\n1 10\\n1 12\\n1 9\\n3 3 4 9\\n1 1\\n1 11\\n1 5\\n2 1 4\\n0\\n\", \"12 2\\n11 4\\n0\\n0\\n0\\n1 5\\n0\\n0\\n0\\n0\\n1 2\\n0\\n0\\n0\\n\", \"12 2\\n6 8\\n6 2 4 5 7 9 11\\n4 8 9 11 12\\n0\\n2 8 9\\n2 8 12\\n4 2 3 5 9\\n2 9 12\\n0\\n0\\n4 3 4 7 9\\n2 7 8\\n0\\n\", \"12 10\\n8 7 9 5 10 6 4 12 3 11\\n1 5\\n1 10\\n1 1\\n1 5\\n1 7\\n1 11\\n1 10\\n2 1 3\\n0\\n1 1\\n1 8\\n0\\n\", \"12 1\\n4\\n2 4 11\\n1 8\\n2 2 5\\n0\\n0\\n1 3\\n0\\n0\\n1 2\\n1 9\\n2 2 6\\n0\\n\", \"12 2\\n10 5\\n0\\n0\\n3 1 5 11\\n1 3\\n0\\n1 1\\n2 5 9\\n2 5 7\\n1 8\\n2 6 9\\n0\\n1 1\\n\"], \"outputs\": [\"5\\n1 2 3 4 5 \\n\", \"6\\n1 2 9 4 5 3 \\n\", \"-1\\n\", \"3\\n1 2 4 \\n\", \"2\\n1 4 \\n\", \"2\\n4 5 \\n\", \"6\\n2 6 3 4 1 5 \\n\", \"6\\n5 3 1 4 2 6 \\n\", \"5\\n1 2 3 4 5 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"3\\n1 3 2 \\n\", \"2\\n5 1 \\n\", \"1\\n1 \\n\", \"2\\n1 2 \\n\", \"2\\n1 2 \\n\", \"2\\n2 1 \\n\", \"1\\n1 \\n\", \"2\\n1 2 \\n\", \"1\\n2 \\n\", \"3\\n2 3 1 \\n\", \"-1\\n\", \"6\\n3 1 2 4 5 8 \\n\", \"6\\n4 5 3 2 6 1 \\n\", \"2\\n1 3 \\n\", \"3\\n2 3 1 \\n\", \"3\\n1 2 3 \\n\", \"3\\n1 2 3 \\n\", \"2\\n1 2 \\n\", \"3\\n1 2 3 \\n\", \"3\\n1 2 3 \\n\", \"3\\n1 2 3 \\n\", \"3\\n1 3 2 \\n\", \"3\\n1 2 3 \\n\", \"2\\n3 1 \\n\", \"2\\n2 3 \\n\", \"1\\n1 \\n\", \"3\\n1 2 3 \\n\", \"3\\n1 2 3 \\n\", \"4\\n3 4 1 2 \\n\", \"-1\\n\", \"2\\n3 4 \\n\", \"4\\n2 4 3 1 \\n\", \"1\\n2 \\n\", \"-1\\n\", \"4\\n3 1 2 4 \\n\", \"1\\n4 \\n\", \"2\\n1 3 \\n\", \"4\\n4 1 2 3 \\n\", \"-1\\n\", \"4\\n1 4 2 3 \\n\", \"4\\n1 4 3 2 \\n\", \"4\\n2 4 1 3 \\n\", \"1\\n1 \\n\", \"1\\n5 \\n\", \"5\\n1 2 3 5 4 \\n\", \"5\\n4 1 2 3 5 \\n\", \"2\\n2 4 \\n\", \"-1\\n\", \"5\\n3 2 4 5 1 \\n\", \"4\\n1 2 4 5 \\n\", \"2\\n1 3 \\n\", \"-1\\n\", \"4\\n2 1 3 4 \\n\", \"1\\n2 \\n\", \"3\\n2 4 5 \\n\", \"1\\n3 \\n\", \"3\\n2 1 5 \\n\", \"3\\n2 3 4 \\n\", \"6\\n3 4 2 6 5 1 \\n\", \"-1\\n\", \"1\\n2 \\n\", \"3\\n1 5 6 \\n\", \"6\\n1 2 3 4 5 6 \\n\", \"6\\n4 5 2 6 1 3 \\n\", \"2\\n2 5 \\n\", \"6\\n1 3 6 2 4 5 \\n\", \"6\\n6 1 2 3 5 4 \\n\", \"-1\\n\", \"6\\n1 2 3 4 5 6 \\n\", \"6\\n4 1 3 2 5 6 \\n\", \"5\\n1 6 4 5 3 \\n\", \"1\\n1 \\n\", \"-1\\n\", \"7\\n1 5 6 2 3 4 7 \\n\", \"7\\n1 2 3 4 5 6 7 \\n\", \"2\\n2 3 \\n\", \"6\\n6 3 4 7 2 5 \\n\", \"7\\n3 5 2 7 1 4 6 \\n\", \"5\\n1 7 6 3 2 \\n\", \"6\\n5 2 6 4 7 1 \\n\", \"2\\n6 5 \\n\", \"6\\n2 5 7 3 6 4 \\n\", \"7\\n1 2 7 5 3 6 4 \\n\", \"7\\n6 4 1 7 2 3 5 \\n\", \"1\\n1 \\n\", \"-1\\n\", \"1\\n2 \\n\", \"-1\\n\", \"2\\n2 1 \\n\", \"2\\n1 2 \\n\", \"-1\\n\", \"3\\n1 7 4 \\n\", \"2\\n1 2 \\n\", \"4\\n7 1 2 6 \\n\", \"7\\n2 3 5 4 6 1 7 \\n\", \"5\\n1 2 3 7 8 \\n\", \"6\\n1 3 2 4 7 8 \\n\", \"3\\n1 2 6 \\n\", \"6\\n8 4 3 7 5 6 \\n\", \"-1\\n\", \"-1\\n\", \"5\\n5 7 1 4 6 \\n\", \"5\\n1 6 7 3 8 \\n\", \"8\\n1 2 3 5 7 4 6 8 \\n\", \"8\\n8 1 3 4 6 2 5 7 \\n\", \"8\\n4 6 3 8 1 2 5 7 \\n\", \"3\\n1 3 4 \\n\", \"1\\n3 \\n\", \"8\\n3 1 4 2 5 6 7 8 \\n\", \"7\\n1 3 7 8 4 5 6 \\n\", \"9\\n1 2 3 4 5 6 7 8 9 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"3\\n2 6 9 \\n\", \"-1\\n\", \"8\\n4 2 3 5 7 8 6 9 \\n\", \"7\\n1 2 4 5 6 7 9 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"7\\n8 7 3 1 2 4 6 \\n\", \"2\\n4 7 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"2\\n4 9 \\n\", \"3\\n7 3 5 \\n\", \"2\\n5 1 \\n\", \"1\\n4 \\n\", \"10\\n7 9 2 4 8 1 6 10 3 5 \\n\", \"-1\\n\", \"7\\n1 3 4 5 6 10 8 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"5\\n4 1 2 3 6 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"6\\n1 11 2 3 7 10 \\n\", \"7\\n6 7 3 4 9 11 10 \\n\", \"6\\n3 2 7 8 10 11 \\n\", \"-1\\n\", \"8\\n2 11 1 10 3 4 7 9 \\n\", \"8\\n7 9 2 11 3 5 10 6 \\n\", \"11\\n2 3 4 7 11 9 1 5 8 10 6 \\n\", \"7\\n1 2 3 4 6 8 7 \\n\", \"5\\n2 8 5 9 11 \\n\", \"11\\n1 3 2 4 5 9 11 6 7 8 10 \\n\", \"11\\n2 1 7 11 10 6 8 9 3 4 5 \\n\", \"-1\\n\", \"-1\\n\", \"11\\n11 10 1 6 9 2 3 5 7 8 12 \\n\", \"-1\\n\", \"-1\\n\", \"2\\n9 8 \\n\", \"-1\\n\", \"6\\n2 3 8 9 4 7 \\n\", \"10\\n1 2 3 8 4 5 6 7 10 12 \\n\", \"6\\n1 12 2 5 11 10 \\n\", \"9\\n1 3 12 5 10 4 11 9 7 \\n\", \"3\\n5 4 11 \\n\", \"9\\n8 9 12 7 11 2 3 5 6 \\n\", \"-1\\n\", \"1\\n4 \\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
Now you can take online courses in the Berland State University! Polycarp needs to pass k main online courses of his specialty to get a diploma. In total n courses are availiable for the passage.
The situation is complicated by the dependence of online courses, for each course there is a list of those that must be passed before starting this online course (the list can be empty, it means that there is no limitation).
Help Polycarp to pass the least number of courses in total to get the specialty (it means to pass all main and necessary courses). Write a program which prints the order of courses.
Polycarp passes courses consistently, he starts the next course when he finishes the previous one. Each course can't be passed more than once.
-----Input-----
The first line contains n and k (1 ≤ k ≤ n ≤ 10^5) — the number of online-courses and the number of main courses of Polycarp's specialty.
The second line contains k distinct integers from 1 to n — numbers of main online-courses of Polycarp's specialty.
Then n lines follow, each of them describes the next course: the i-th of them corresponds to the course i. Each line starts from the integer t_{i} (0 ≤ t_{i} ≤ n - 1) — the number of courses on which the i-th depends. Then there follows the sequence of t_{i} distinct integers from 1 to n — numbers of courses in random order, on which the i-th depends. It is guaranteed that no course can depend on itself.
It is guaranteed that the sum of all values t_{i} doesn't exceed 10^5.
-----Output-----
Print -1, if there is no the way to get a specialty.
Otherwise, in the first line print the integer m — the minimum number of online-courses which it is necessary to pass to get a specialty. In the second line print m distinct integers — numbers of courses which it is necessary to pass in the chronological order of their passage. If there are several answers it is allowed to print any of them.
-----Examples-----
Input
6 2
5 3
0
0
0
2 2 1
1 4
1 5
Output
5
1 2 3 4 5
Input
9 3
3 9 5
0
0
3 9 4 5
0
0
1 8
1 6
1 2
2 1 2
Output
6
1 2 9 4 5 3
Input
3 3
1 2 3
1 2
1 3
1 1
Output
-1
-----Note-----
In the first test firstly you can take courses number 1 and 2, after that you can take the course number 4, then you can take the course number 5, which is the main. After that you have to take only the course number 3, which is the last not passed main course.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 3\\n3 2 1\\n\", \"5 3\\n2 3 1\\n\", \"5 1\\n3\\n\", \"5 2\\n3 4\\n\", \"20 19\\n2 18 19 11 9 20 15 1 8 14 4 6 5 12 17 16 7 13 3\\n\", \"10 1\\n6\\n\", \"20 18\\n8 14 18 10 1 3 7 15 2 12 17 19 5 4 11 13 20 16\\n\", \"10 2\\n3 7\\n\", \"100000 3\\n43791 91790 34124\\n\", \"20 17\\n9 11 19 4 8 16 13 3 1 6 18 2 20 10 17 7 5\\n\", \"10 3\\n2 10 3\\n\", \"100000 4\\n8269 53984 47865 42245\\n\", \"20 16\\n8 1 5 11 15 14 7 20 16 9 12 13 18 4 6 10\\n\", \"10 4\\n2 4 1 10\\n\", \"100000 5\\n82211 48488 99853 11566 42120\\n\", \"20 15\\n6 7 14 13 8 4 15 2 11 9 12 16 5 1 20\\n\", \"10 5\\n2 10 5 8 4\\n\", \"100000 6\\n98217 55264 24242 71840 2627 67839\\n\", \"20 14\\n10 15 4 3 1 5 11 12 13 14 6 2 19 20\\n\", \"10 6\\n4 5 2 1 6 3\\n\", \"100000 7\\n44943 51099 61988 40497 85738 74092 2771\\n\", \"20 13\\n6 16 5 19 8 1 4 18 2 20 10 11 13\\n\", \"10 7\\n10 4 3 8 2 5 6\\n\", \"100000 8\\n88153 88461 80211 24770 13872 57414 32941 63030\\n\", \"20 12\\n20 11 14 7 16 13 9 1 4 18 6 12\\n\", \"10 8\\n7 9 3 6 2 4 1 8\\n\", \"40 39\\n25 4 26 34 35 11 22 23 21 2 1 28 20 8 36 5 27 15 39 7 24 14 17 19 33 6 38 16 18 3 32 10 30 13 37 31 29 9 12\\n\", \"20 1\\n20\\n\", \"40 38\\n32 35 36 4 22 6 15 21 40 13 33 17 5 24 28 9 1 23 25 14 26 3 8 11 37 30 18 16 19 20 27 12 39 2 10 38 29 31\\n\", \"20 2\\n1 13\\n\", \"200000 3\\n60323 163214 48453\\n\", \"40 37\\n26 16 40 10 9 30 8 33 39 19 4 11 2 3 38 21 22 12 1 27 20 37 24 17 23 14 13 29 7 28 34 31 25 35 6 32 5\\n\", \"20 3\\n16 6 14\\n\", \"200000 4\\n194118 175603 110154 129526\\n\", \"40 36\\n27 33 34 40 16 39 1 10 9 12 8 37 17 7 24 30 2 31 13 23 20 18 29 21 4 28 25 35 6 22 36 15 3 11 5 26\\n\", \"20 4\\n2 10 4 9\\n\", \"200000 5\\n53765 19781 63409 69811 120021\\n\", \"40 35\\n2 1 5 3 11 32 13 16 37 26 6 10 8 35 25 24 7 38 21 17 40 14 9 34 33 20 29 12 22 28 36 31 30 19 27\\n\", \"20 5\\n11 19 6 2 12\\n\", \"200000 6\\n33936 11771 42964 153325 684 8678\\n\", \"40 34\\n35 31 38 25 29 9 32 23 24 16 3 26 39 2 17 28 14 1 30 34 5 36 33 7 22 13 21 12 27 19 40 10 18 15\\n\", \"20 6\\n3 6 9 13 20 14\\n\", \"200000 7\\n175932 99083 128533 75304 164663 7578 174396\\n\", \"40 33\\n11 15 22 26 21 6 8 5 32 39 28 29 30 13 2 40 33 27 17 31 7 36 9 19 3 38 37 12 10 16 1 23 35\\n\", \"20 7\\n7 5 6 13 16 3 17\\n\", \"200000 8\\n197281 11492 67218 100058 179300 182264 17781 192818\\n\", \"40 32\\n22 7 35 31 14 28 9 20 10 3 38 6 15 36 33 16 37 2 11 13 26 23 30 12 40 5 21 1 34 19 27 24\\n\", \"20 8\\n1 16 14 11 7 9 2 12\\n\", \"30 3\\n17 5 3\\n\", \"30 3\\n29 25 21\\n\", \"10 6\\n2 1 4 3 6 5\\n\", \"4 3\\n2 1 3\\n\", \"6 4\\n5 4 3 1\\n\", \"4 3\\n1 2 3\\n\", \"6 4\\n1 3 2 6\\n\", \"5 4\\n3 2 1 5\\n\", \"10 4\\n6 4 1 3\\n\", \"4 3\\n3 4 2\\n\", \"4 3\\n3 1 4\\n\", \"3 2\\n2 3\\n\", \"4 3\\n1 4 2\\n\", \"4 3\\n3 1 2\\n\", \"2 1\\n1\\n\", \"3 2\\n3 2\\n\", \"4 3\\n4 1 2\\n\", \"3 2\\n3 1\\n\", \"4 3\\n2 1 4\\n\", \"8 5\\n3 1 4 2 7\\n\", \"6 4\\n2 5 1 4\\n\", \"10 5\\n10 1 8 5 6\\n\", \"10 3\\n6 4 3\\n\", \"10 3\\n2 1 6\\n\", \"10 3\\n8 1 7\\n\", \"10 2\\n5 4\\n\", \"10 3\\n1 2 10\\n\", \"10 4\\n4 1 6 3\\n\", \"10 3\\n8 1 5\\n\", \"10 4\\n1 4 9 8\\n\", \"10 3\\n3 1 6\\n\", \"10 6\\n1 2 5 4 3 6\\n\", \"10 9\\n9 8 7 5 4 3 2 1 6\\n\", \"10 4\\n4 7 5 10\\n\", \"10 5\\n8 6 2 1 5\\n\", \"10 7\\n7 5 2 1 4 3 6\\n\", \"10 4\\n1 2 10 6\\n\", \"10 6\\n1 10 9 5 4 3\\n\", \"10 8\\n6 10 4 7 9 8 5 3\\n\", \"10 4\\n6 1 10 3\\n\", \"10 9\\n9 6 1 4 2 3 5 10 7\\n\", \"10 9\\n10 1 9 3 2 4 5 8 6\\n\", \"10 4\\n10 8 1 7\\n\", \"10 4\\n2 1 3 6\\n\", \"10 3\\n2 1 4\\n\", \"10 3\\n4 1 5\\n\", \"10 5\\n9 8 1 2 10\\n\", \"10 3\\n9 8 3\\n\", \"10 4\\n8 2 1 5\\n\", \"10 6\\n6 5 3 1 2 4\\n\", \"10 2\\n1 2\\n\", \"10 6\\n9 6 5 2 1 4\\n\", \"10 4\\n2 1 7 3\\n\", \"10 2\\n6 5\\n\", \"10 3\\n2 1 5\\n\", \"10 4\\n3 1 2 4\\n\", \"10 3\\n8 5 4\\n\", \"10 4\\n2 1 8 4\\n\", \"10 3\\n8 3 2\\n\", \"10 3\\n5 4 2\\n\", \"10 9\\n10 8 7 5 6 2 1 9 4\\n\", \"10 4\\n2 1 6 4\\n\", \"10 4\\n2 1 3 9\\n\", \"10 3\\n1 4 3\\n\", \"10 7\\n3 2 1 9 8 6 5\\n\", \"10 4\\n10 7 1 5\\n\", \"10 4\\n8 7 1 2\\n\", \"10 4\\n1 5 4 2\\n\", \"10 5\\n2 1 9 3 7\\n\", \"10 4\\n2 1 5 3\\n\", \"10 5\\n9 6 1 8 2\\n\", \"20 13\\n3 2 1 7 4 5 6 11 10 9 8 13 12\\n\", \"20 14\\n3 2 1 7 4 5 6 14 11 10 9 8 13 12\\n\", \"10 5\\n9 4 2 1 5\\n\", \"10 5\\n1 5 2 10 3\\n\", \"10 8\\n6 5 3 1 2 4 9 8\\n\", \"10 4\\n10 9 3 7\\n\", \"10 7\\n10 8 5 1 2 7 3\\n\", \"10 3\\n3 1 5\\n\", \"10 5\\n1 9 8 4 3\\n\", \"10 3\\n1 8 4\\n\", \"10 4\\n6 2 1 4\\n\", \"10 3\\n1 6 4\\n\", \"10 3\\n10 9 3\\n\", \"10 9\\n8 10 4 1 3 2 9 7 5\\n\", \"10 3\\n7 10 6\\n\", \"10 3\\n9 10 8\\n\", \"10 6\\n10 8 1 6 2 7\\n\", \"10 6\\n6 5 1 2 9 3\\n\", \"10 3\\n10 1 8\\n\", \"10 9\\n1 9 7 10 5 8 4 6 3\\n\", \"10 5\\n1 9 3 2 5\\n\", \"10 4\\n10 1 9 7\\n\", \"10 8\\n1 10 3 2 9 4 8 5\\n\", \"10 1\\n1\\n\", \"10 7\\n9 7 1 6 5 4 2\\n\", \"10 9\\n10 2 1 7 8 3 5 6 9\\n\", \"10 4\\n2 1 3 10\\n\", \"10 9\\n5 1 4 6 3 9 8 10 7\\n\", \"10 6\\n8 2 1 7 6 5\\n\", \"10 5\\n2 9 8 6 1\\n\", \"10 4\\n9 2 1 6\\n\", \"10 3\\n2 1 7\\n\", \"10 7\\n4 1 2 10 9 6 3\\n\", \"10 6\\n10 2 1 3 9 4\\n\", \"10 4\\n9 2 1 4\\n\", \"10 3\\n5 1 4\\n\", \"10 4\\n4 1 2 10\\n\", \"8 6\\n5 4 3 2 1 8\\n\", \"10 4\\n1 6 5 4\\n\", \"10 2\\n10 2\\n\", \"10 5\\n1 6 2 10 5\\n\", \"10 9\\n6 1 2 10 9 5 3 4 8\\n\", \"10 5\\n4 1 7 2 3\\n\", \"10 4\\n2 1 3 4\\n\", \"11 2\\n3 2\\n\", \"6 5\\n3 2 1 4 5\\n\", \"5 4\\n2 1 3 5\\n\", \"10 6\\n3 2 1 5 4 6\\n\", \"11 5\\n1 8 7 6 5\\n\", \"10 3\\n2 1 3\\n\", \"10 4\\n2 1 7 6\\n\", \"10 4\\n5 4 1 8\\n\", \"10 4\\n9 1 5 4\\n\", \"10 3\\n6 1 4\\n\", \"10 6\\n1 9 3 2 4 6\\n\", \"10 3\\n10 1 9\\n\", \"10 3\\n1 9 7\\n\", \"10 2\\n2 10\\n\", \"10 5\\n9 2 1 4 3\\n\", \"10 6\\n1 2 3 6 5 4\\n\", \"10 5\\n7 6 5 1 4\\n\", \"10 9\\n8 1 3 4 10 5 9 7 2\\n\"], \"outputs\": [\"3 2 1 5 4 \", \"-1\\n\", \"3 2 1 5 4 \", \"-1\\n\", \"-1\\n\", \"6 5 4 3 2 1 10 9 8 7 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 \", \"-1\\n\", \"1 13 12 11 10 9 8 7 6 5 4 3 2 20 19 18 17 16 15 14 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"17 5 3 2 1 4 16 15 14 13 12 11 10 9 8 7 6 30 29 28 27 26 25 24 23 22 21 20 19 18 \", \"29 25 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 24 23 22 28 27 26 30 \", \"2 1 4 3 6 5 10 9 8 7 \", \"2 1 3 4 \", \"5 4 3 1 2 6 \", \"1 2 3 4 \", \"1 3 2 6 5 4 \", \"3 2 1 5 4 \", \"6 4 1 3 2 5 10 9 8 7 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"1 4 2 3 \", \"3 1 2 4 \", \"1 2 \", \"3 2 1 \", \"4 1 2 3 \", \"3 1 2 \", \"2 1 4 3 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"6 4 3 2 1 5 10 9 8 7 \", \"2 1 6 5 4 3 10 9 8 7 \", \"8 1 7 6 5 4 3 2 10 9 \", \"5 4 3 2 1 10 9 8 7 6 \", \"1 2 10 9 8 7 6 5 4 3 \", \"-1\\n\", \"8 1 5 4 3 2 7 6 10 9 \", \"-1\\n\", \"-1\\n\", \"1 2 5 4 3 6 10 9 8 7 \", \"9 8 7 5 4 3 2 1 6 10 \", \"-1\\n\", \"8 6 2 1 5 4 3 7 10 9 \", \"7 5 2 1 4 3 6 10 9 8 \", \"1 2 10 6 5 4 3 9 8 7 \", \"1 10 9 5 4 3 2 8 7 6 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"10 1 9 3 2 4 5 8 6 7 \", \"10 8 1 7 6 5 4 3 2 9 \", \"2 1 3 6 5 4 10 9 8 7 \", \"2 1 4 3 10 9 8 7 6 5 \", \"-1\\n\", \"-1\\n\", \"9 8 3 2 1 7 6 5 4 10 \", \"8 2 1 5 4 3 7 6 10 9 \", \"6 5 3 1 2 4 10 9 8 7 \", \"1 2 10 9 8 7 6 5 4 3 \", \"9 6 5 2 1 4 3 8 7 10 \", \"2 1 7 3 6 5 4 10 9 8 \", \"6 5 4 3 2 1 10 9 8 7 \", \"2 1 5 4 3 10 9 8 7 6 \", \"3 1 2 4 10 9 8 7 6 5 \", \"8 5 4 3 2 1 7 6 10 9 \", \"2 1 8 4 3 7 6 5 10 9 \", \"8 3 2 1 7 6 5 4 10 9 \", \"5 4 2 1 3 10 9 8 7 6 \", \"-1\\n\", \"2 1 6 4 3 5 10 9 8 7 \", \"2 1 3 9 8 7 6 5 4 10 \", \"1 4 3 2 10 9 8 7 6 5 \", \"3 2 1 9 8 6 5 4 7 10 \", \"10 7 1 5 4 3 2 6 9 8 \", \"8 7 1 2 6 5 4 3 10 9 \", \"1 5 4 2 3 10 9 8 7 6 \", \"2 1 9 3 7 6 5 4 8 10 \", \"2 1 5 3 4 10 9 8 7 6 \", \"-1\\n\", \"3 2 1 7 4 5 6 11 10 9 8 13 12 20 19 18 17 16 15 14 \", \"3 2 1 7 4 5 6 14 11 10 9 8 13 12 20 19 18 17 16 15 \", \"-1\\n\", \"-1\\n\", \"6 5 3 1 2 4 9 8 7 10 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"1 9 8 4 3 2 7 6 5 10 \", \"1 8 4 3 2 7 6 5 10 9 \", \"6 2 1 4 3 5 10 9 8 7 \", \"1 6 4 3 2 5 10 9 8 7 \", \"10 9 3 2 1 8 7 6 5 4 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"10 1 8 7 6 5 4 3 2 9 \", \"-1\\n\", \"1 9 3 2 5 4 8 7 6 10 \", \"10 1 9 7 6 5 4 3 2 8 \", \"1 10 3 2 9 4 8 5 7 6 \", \"1 10 9 8 7 6 5 4 3 2 \", \"9 7 1 6 5 4 2 3 8 10 \", \"-1\\n\", \"2 1 3 10 9 8 7 6 5 4 \", \"-1\\n\", \"8 2 1 7 6 5 4 3 10 9 \", \"-1\\n\", \"9 2 1 6 5 4 3 8 7 10 \", \"2 1 7 6 5 4 3 10 9 8 \", \"-1\\n\", \"10 2 1 3 9 4 8 7 6 5 \", \"9 2 1 4 3 8 7 6 5 10 \", \"5 1 4 3 2 10 9 8 7 6 \", \"-1\\n\", \"5 4 3 2 1 8 7 6 \", \"1 6 5 4 3 2 10 9 8 7 \", \"10 2 1 9 8 7 6 5 4 3 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"2 1 3 4 10 9 8 7 6 5 \", \"3 2 1 11 10 9 8 7 6 5 4 \", \"3 2 1 4 5 6 \", \"2 1 3 5 4 \", \"3 2 1 5 4 6 10 9 8 7 \", \"1 8 7 6 5 4 3 2 11 10 9 \", \"2 1 3 10 9 8 7 6 5 4 \", \"2 1 7 6 5 4 3 10 9 8 \", \"-1\\n\", \"9 1 5 4 3 2 8 7 6 10 \", \"6 1 4 3 2 5 10 9 8 7 \", \"1 9 3 2 4 6 5 8 7 10 \", \"10 1 9 8 7 6 5 4 3 2 \", \"1 9 7 6 5 4 3 2 8 10 \", \"-1\\n\", \"9 2 1 4 3 8 7 6 5 10 \", \"1 2 3 6 5 4 10 9 8 7 \", \"7 6 5 1 4 3 2 10 9 8 \", \"-1\\n\"]}", "source": "primeintellect"}
|
Let's suppose you have an array a, a stack s (initially empty) and an array b (also initially empty).
You may perform the following operations until both a and s are empty:
Take the first element of a, push it into s and remove it from a (if a is not empty); Take the top element from s, append it to the end of array b and remove it from s (if s is not empty).
You can perform these operations in arbitrary order.
If there exists a way to perform the operations such that array b is sorted in non-descending order in the end, then array a is called stack-sortable.
For example, [3, 1, 2] is stack-sortable, because b will be sorted if we perform the following operations:
Remove 3 from a and push it into s; Remove 1 from a and push it into s; Remove 1 from s and append it to the end of b; Remove 2 from a and push it into s; Remove 2 from s and append it to the end of b; Remove 3 from s and append it to the end of b.
After all these operations b = [1, 2, 3], so [3, 1, 2] is stack-sortable. [2, 3, 1] is not stack-sortable.
You are given k first elements of some permutation p of size n (recall that a permutation of size n is an array of size n where each integer from 1 to n occurs exactly once). You have to restore the remaining n - k elements of this permutation so it is stack-sortable. If there are multiple answers, choose the answer such that p is lexicographically maximal (an array q is lexicographically greater than an array p iff there exists some integer k such that for every i < k q_{i} = p_{i}, and q_{k} > p_{k}). You may not swap or change any of first k elements of the permutation.
Print the lexicographically maximal permutation p you can obtain.
If there exists no answer then output -1.
-----Input-----
The first line contains two integers n and k (2 ≤ n ≤ 200000, 1 ≤ k < n) — the size of a desired permutation, and the number of elements you are given, respectively.
The second line contains k integers p_1, p_2, ..., p_{k} (1 ≤ p_{i} ≤ n) — the first k elements of p. These integers are pairwise distinct.
-----Output-----
If it is possible to restore a stack-sortable permutation p of size n such that the first k elements of p are equal to elements given in the input, print lexicographically maximal such permutation.
Otherwise print -1.
-----Examples-----
Input
5 3
3 2 1
Output
3 2 1 5 4
Input
5 3
2 3 1
Output
-1
Input
5 1
3
Output
3 2 1 5 4
Input
5 2
3 4
Output
-1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"oXoxoXo\\n\", \"bod\\n\", \"ER\\n\", \"o\\n\", \"a\\n\", \"opo\\n\", \"HCMoxkgbNb\\n\", \"vMhhXCMWDe\\n\", \"iIcamjTRFH\\n\", \"WvoWvvWovW\\n\", \"WXxAdbAxXW\\n\", \"vqMTUUTMpv\\n\", \"iii\\n\", \"AAWW\\n\", \"ss\\n\", \"i\\n\", \"ii\\n\", \"mm\\n\", \"LJ\\n\", \"m\\n\", \"ioi\\n\", \"OA\\n\", \"aaaiaaa\\n\", \"SS\\n\", \"iiii\\n\", \"ssops\\n\", \"ssss\\n\", \"ll\\n\", \"s\\n\", \"bb\\n\", \"uu\\n\", \"ZoZ\\n\", \"mom\\n\", \"uou\\n\", \"u\\n\", \"JL\\n\", \"mOm\\n\", \"llll\\n\", \"ouo\\n\", \"aa\\n\", \"olo\\n\", \"S\\n\", \"lAl\\n\", \"nnnn\\n\", \"ZzZ\\n\", \"bNd\\n\", \"ZZ\\n\", \"oNoNo\\n\", \"l\\n\", \"zz\\n\", \"NON\\n\", \"nn\\n\", \"NoN\\n\", \"sos\\n\", \"lol\\n\", \"mmm\\n\", \"YAiAY\\n\", \"ipIqi\\n\", \"AAA\\n\", \"uoOou\\n\", \"SOS\\n\", \"NN\\n\", \"n\\n\", \"h\\n\", \"blld\\n\", \"ipOqi\\n\", \"pop\\n\", \"BB\\n\", \"OuO\\n\", \"lxl\\n\", \"Z\\n\", \"vvivv\\n\", \"nnnnnnnnnnnnn\\n\", \"AA\\n\", \"t\\n\", \"z\\n\", \"mmmAmmm\\n\", \"qlililp\\n\", \"mpOqm\\n\", \"iiiiiiiiii\\n\", \"BAAAB\\n\", \"UA\\n\", \"mmmmmmm\\n\", \"NpOqN\\n\", \"uOu\\n\", \"uuu\\n\", \"NAMAN\\n\", \"lllll\\n\", \"T\\n\", \"mmmmmmmmmmmmmmmm\\n\", \"AiiA\\n\", \"iOi\\n\", \"lll\\n\", \"N\\n\", \"viv\\n\", \"oiio\\n\", \"AiiiA\\n\", \"NNNN\\n\", \"ixi\\n\", \"AuuA\\n\", \"AAAANANAAAA\\n\", \"mmmmm\\n\", \"oYo\\n\", \"dd\\n\", \"A\\n\", \"ioh\\n\", \"mmmm\\n\", \"uuuu\\n\", \"puq\\n\", \"rrrrrr\\n\", \"c\\n\", \"AbpA\\n\", \"qAq\\n\", \"tt\\n\", \"mnmnm\\n\", \"sss\\n\", \"yy\\n\", \"bob\\n\", \"NAN\\n\", \"mAm\\n\", \"tAt\\n\", \"yAy\\n\", \"zAz\\n\", \"aZ\\n\", \"hh\\n\", \"bbbb\\n\", \"ZAZ\\n\", \"Y\\n\", \"AAMM\\n\", \"lml\\n\", \"AZA\\n\", \"mXm\\n\", \"bd\\n\", \"H\\n\", \"uvu\\n\", \"dxxd\\n\", \"dp\\n\", \"vV\\n\", \"vMo\\n\", \"O\\n\", \"vYv\\n\", \"fv\\n\", \"U\\n\", \"iAi\\n\", \"I\\n\", \"VxrV\\n\", \"POP\\n\", \"bid\\n\", \"bmd\\n\", \"AiA\\n\", \"mmmmmm\\n\", \"XHX\\n\", \"llllll\\n\", \"aAa\\n\", \"Db\\n\", \"lOl\\n\", \"bzd\\n\"], \"outputs\": [\"TAK\\n\", \"TAK\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"TAK\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"TAK\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"TAK\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\", \"NIE\\n\"]}", "source": "primeintellect"}
|
Let's call a string "s-palindrome" if it is symmetric about the middle of the string. For example, the string "oHo" is "s-palindrome", but the string "aa" is not. The string "aa" is not "s-palindrome", because the second half of it is not a mirror reflection of the first half.
[Image] English alphabet
You are given a string s. Check if the string is "s-palindrome".
-----Input-----
The only line contains the string s (1 ≤ |s| ≤ 1000) which consists of only English letters.
-----Output-----
Print "TAK" if the string s is "s-palindrome" and "NIE" otherwise.
-----Examples-----
Input
oXoxoXo
Output
TAK
Input
bod
Output
TAK
Input
ER
Output
NIE
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"123\\n222\\n\", \"3921\\n10000\\n\", \"4940\\n5000\\n\", \"23923472834\\n23589234723\\n\", \"102391019\\n491010301\\n\", \"123456789123456789\\n276193619183618162\\n\", \"1000000000000000000\\n1000000000000000000\\n\", \"1\\n1000000000000000000\\n\", \"999999999999999999\\n1000000000000000000\\n\", \"2475345634895\\n3455834583479\\n\", \"15778899\\n98715689\\n\", \"4555\\n5454\\n\", \"122112\\n221112\\n\", \"199999999999991\\n191000000000000\\n\", \"13\\n31\\n\", \"212\\n211\\n\", \"222234\\n322223\\n\", \"123456789\\n987654311\\n\", \"20123\\n21022\\n\", \"10101\\n11000\\n\", \"592\\n924\\n\", \"5654456\\n5634565\\n\", \"655432\\n421631\\n\", \"200\\n200\\n\", \"123456789987654321\\n121111111111111111\\n\", \"12345\\n21344\\n\", \"120\\n200\\n\", \"123\\n212\\n\", \"2184645\\n5213118\\n\", \"9912346\\n9912345\\n\", \"5003\\n5000\\n\", \"12345\\n31234\\n\", \"5001\\n5000\\n\", \"53436\\n53425\\n\", \"9329\\n3268\\n\", \"1234567890\\n9000000001\\n\", \"321\\n212\\n\", \"109823464\\n901234467\\n\", \"6543\\n6542\\n\", \"555441\\n555100\\n\", \"472389479\\n327489423\\n\", \"45645643756464352\\n53465475637456247\\n\", \"254\\n599\\n\", \"5232222345652321\\n5000000000000000\\n\", \"201\\n200\\n\", \"14362799391220361\\n45160821596433661\\n\", \"3453\\n5304\\n\", \"989\\n998\\n\", \"5200000000234\\n5200000000311\\n\", \"5555132\\n1325442\\n\", \"123\\n211\\n\", \"65689\\n66123\\n\", \"123451234567890\\n123456789012345\\n\", \"22115\\n22015\\n\", \"123\\n311\\n\", \"12222\\n21111\\n\", \"765\\n567\\n\", \"9087645\\n9087640\\n\", \"1111111122222333\\n2220000000000000\\n\", \"7901\\n7108\\n\", \"215489\\n215488\\n\", \"102\\n200\\n\", \"19260817\\n20011213\\n\", \"12345\\n53200\\n\", \"1040003001\\n1040003000\\n\", \"295\\n924\\n\", \"20000000000000001\\n20000000000000000\\n\", \"99988877\\n99887766\\n\", \"12\\n12\\n\", \"199999999999999999\\n900000000000000000\\n\", \"1234\\n4310\\n\", \"100011\\n100100\\n\", \"328899\\n328811\\n\", \"646722972346\\n397619201220\\n\", \"1203\\n1200\\n\", \"1\\n2\\n\", \"1112\\n2110\\n\", \"4545\\n5540\\n\", \"3053\\n5004\\n\", \"3503\\n5004\\n\", \"351731653766064847\\n501550303749042658\\n\", \"10123456789013451\\n26666666666666666\\n\", \"1110111\\n1100000\\n\", \"30478\\n32265\\n\", \"456546546549874615\\n441554543131214545\\n\", \"214\\n213\\n\", \"415335582799619283\\n133117803602859310\\n\", \"787\\n887\\n\", \"3333222288889999\\n3333222288881111\\n\", \"495779862481416791\\n836241745208800994\\n\", \"139\\n193\\n\", \"9568\\n6500\\n\", \"3208899\\n3228811\\n\", \"27778\\n28710\\n\", \"62345\\n46415\\n\", \"405739873179209\\n596793907108871\\n\", \"365\\n690\\n\", \"8388731334391\\n4710766672578\\n\", \"1230\\n1200\\n\", \"1025\\n5000\\n\", \"4207799\\n4027711\\n\", \"4444222277779999\\n4444222277771111\\n\", \"7430\\n3047\\n\", \"649675735\\n540577056\\n\", \"26\\n82\\n\", \"241285\\n207420\\n\", \"3\\n3\\n\", \"12\\n21\\n\", \"481287\\n826607\\n\", \"40572351\\n59676984\\n\", \"268135787269\\n561193454469\\n\", \"4\\n9\\n\", \"5\\n6\\n\", \"60579839\\n33370073\\n\", \"49939\\n39200\\n\", \"2224\\n4220\\n\", \"427799\\n427711\\n\", \"49\\n90\\n\", \"93875\\n82210\\n\", \"78831\\n7319682\\n\", \"937177\\n7143444\\n\", \"499380628\\n391990337\\n\", \"2090909\\n2900000\\n\", \"112233445566778890\\n987654321987654320\\n\", \"48257086\\n80903384\\n\", \"112233445566778890\\n900654321987654320\\n\", \"112233445566778890\\n123456789123456788\\n\", \"5207799\\n5027711\\n\", \"200000000000000001\\n200000000000000000\\n\", \"597402457\\n797455420\\n\", \"90\\n94\\n\", \"86888\\n88683\\n\", \"419155888\\n588151913\\n\", \"408919130\\n191830070\\n\", \"524975\\n554924\\n\", \"53029\\n30524\\n\", \"5549\\n5542\\n\", \"6\\n9\\n\", \"87\\n810\\n\", \"920491855\\n281495062\\n\", \"6691\\n6910\\n\", \"533\\n335\\n\", \"999999999999999998\\n999999999999999997\\n\", \"21111111111111111\\n21111111111111110\\n\", \"2\\n12\\n\", \"76544\\n45744\\n\", \"2000000000000001\\n2000000000000000\\n\", \"740867\\n467701\\n\", \"2\\n6\\n\", \"103\\n130\\n\", \"2423712\\n8466235\\n\", \"84\\n48\\n\", \"1210\\n12113\\n\", \"2430\\n20786\\n\", \"100\\n999\\n\", \"19325\\n21903\\n\", \"1969\\n23251\\n\"], \"outputs\": [\"213\\n\", \"9321\\n\", \"4940\\n\", \"23498743322\\n\", \"399211100\\n\", \"276193618987554432\\n\", \"1000000000000000000\\n\", \"1\\n\", \"999999999999999999\\n\", \"3455834579642\\n\", \"98598771\\n\", \"4555\\n\", \"221112\\n\", \"119999999999999\\n\", \"31\\n\", \"122\\n\", \"243222\\n\", \"987654231\\n\", \"20321\\n\", \"10110\\n\", \"592\\n\", \"5566544\\n\", \"365542\\n\", \"200\\n\", \"119988776655443322\\n\", \"15432\\n\", \"120\\n\", \"132\\n\", \"5186442\\n\", \"9694321\\n\", \"3500\\n\", \"25431\\n\", \"1500\\n\", \"53364\\n\", \"2993\\n\", \"8976543210\\n\", \"132\\n\", \"896443210\\n\", \"6534\\n\", \"554541\\n\", \"327487994\\n\", \"53465475636654442\\n\", \"542\\n\", \"4655533322222221\\n\", \"120\\n\", \"43999766332221110\\n\", \"4533\\n\", \"998\\n\", \"5200000000243\\n\", \"1255553\\n\", \"132\\n\", \"65986\\n\", \"123456789012345\\n\", \"21521\\n\", \"231\\n\", \"12222\\n\", \"567\\n\", \"9087564\\n\", \"2213332221111111\\n\", \"7091\\n\", \"214985\\n\", \"120\\n\", \"19876210\\n\", \"53142\\n\", \"1040001300\\n\", \"592\\n\", \"12000000000000000\\n\", \"99879887\\n\", \"12\\n\", \"199999999999999999\\n\", \"4231\\n\", \"100011\\n\", \"299883\\n\", \"397476664222\\n\", \"1032\\n\", \"1\\n\", \"1211\\n\", \"5454\\n\", \"3530\\n\", \"3530\\n\", \"501548777666643331\\n\", \"26598754433111100\\n\", \"1011111\\n\", \"30874\\n\", \"441554498766665554\\n\", \"142\\n\", \"132999887655543321\\n\", \"877\\n\", \"3332999988883222\\n\", \"829998777665444111\\n\", \"193\\n\", \"5986\\n\", \"3209988\\n\", \"27877\\n\", \"46352\\n\", \"594998777332100\\n\", \"653\\n\", \"4398887333311\\n\", \"1032\\n\", \"2510\\n\", \"2997740\\n\", \"4442999977774222\\n\", \"3047\\n\", \"539776654\\n\", \"62\\n\", \"185422\\n\", \"3\\n\", \"21\\n\", \"824871\\n\", \"57543210\\n\", \"539887766221\\n\", \"4\\n\", \"5\\n\", \"30998765\\n\", \"34999\\n\", \"2422\\n\", \"299774\\n\", \"49\\n\", \"79853\\n\", \"88731\\n\", \"977731\\n\", \"390988642\\n\", \"2099900\\n\", \"987654321876543210\\n\", \"80876542\\n\", \"898776655443322110\\n\", \"123456789123456780\\n\", \"2997750\\n\", \"120000000000000000\\n\", \"797455420\\n\", \"90\\n\", \"86888\\n\", \"588151894\\n\", \"191830049\\n\", \"554792\\n\", \"30295\\n\", \"5495\\n\", \"6\\n\", \"87\\n\", \"281495059\\n\", \"6691\\n\", \"335\\n\", \"999999999999999989\\n\", \"12111111111111111\\n\", \"2\\n\", \"45674\\n\", \"1200000000000000\\n\", \"467087\\n\", \"2\\n\", \"130\\n\", \"7432221\\n\", \"48\\n\", \"2110\\n\", \"4320\\n\", \"100\\n\", \"21593\\n\", \"9961\\n\"]}", "source": "primeintellect"}
|
You are given two positive integer numbers a and b. Permute (change order) of the digits of a to construct maximal number not exceeding b. No number in input and/or output can start with the digit 0.
It is allowed to leave a as it is.
-----Input-----
The first line contains integer a (1 ≤ a ≤ 10^18). The second line contains integer b (1 ≤ b ≤ 10^18). Numbers don't have leading zeroes. It is guaranteed that answer exists.
-----Output-----
Print the maximum possible number that is a permutation of digits of a and is not greater than b. The answer can't have any leading zeroes. It is guaranteed that the answer exists.
The number in the output should have exactly the same length as number a. It should be a permutation of digits of a.
-----Examples-----
Input
123
222
Output
213
Input
3921
10000
Output
9321
Input
4940
5000
Output
4940
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1.1 3.4 2.5\\n\", \"2.0 2.0 2.0\\n\", \"1.9 1.8 1.7\\n\", \"2.0 2.1 2.2\\n\", \"1.5 1.7 2.5\\n\", \"1.1 1.1 1.1\\n\", \"4.2 1.1 1.2\\n\", \"113.9 125.2 88.8\\n\", \"185.9 9.6 163.4\\n\", \"198.7 23.7 89.1\\n\", \"141.1 108.1 14.9\\n\", \"153.9 122.1 89.5\\n\", \"25.9 77.0 144.8\\n\", \"38.7 142.2 89.8\\n\", \"51.5 156.3 145.1\\n\", \"193.9 40.7 19.7\\n\", \"51.8 51.8 7.1\\n\", \"64.6 117.1 81.6\\n\", \"7.0 131.1 7.4\\n\", \"149.4 15.5 82.0\\n\", \"91.8 170.4 7.7\\n\", \"104.6 184.4 82.3\\n\", \"117.4 68.8 137.7\\n\", \"189.4 63.7 63.4\\n\", \"2.2 148.1 138.0\\n\", \"144.6 103.0 193.4\\n\", \"144.0 70.4 148.1\\n\", \"156.9 154.8 73.9\\n\", \"28.9 39.3 148.4\\n\", \"41.7 104.5 74.2\\n\", \"184.1 118.5 129.5\\n\", \"196.9 3.0 4.1\\n\", \"139.3 87.4 129.9\\n\", \"81.7 171.9 4.4\\n\", \"94.5 56.3 59.8\\n\", \"36.9 51.1 4.8\\n\", \"55.5 159.4 140.3\\n\", \"3.9 0.2 3.8\\n\", \"0.9 4.6 3.4\\n\", \"3.7 3.7 4.1\\n\", \"1.1 3.1 4.9\\n\", \"3.9 2.1 4.5\\n\", \"0.9 2.0 4.8\\n\", \"3.7 2.2 4.8\\n\", \"1.5 1.3 0.1\\n\", \"3.9 0.7 4.7\\n\", \"1.8 1.8 2.1\\n\", \"4.6 2.1 1.6\\n\", \"2.0 1.1 2.4\\n\", \"4.4 0.5 2.0\\n\", \"1.8 0.4 2.7\\n\", \"4.6 4.4 2.3\\n\", \"2.4 3.8 2.7\\n\", \"4.4 3.7 3.4\\n\", \"2.2 3.1 3.0\\n\", \"4.6 3.0 3.4\\n\", \"4.0 0.4 3.1\\n\", \"1.9 4.8 3.9\\n\", \"3.9 4.3 3.4\\n\", \"1.7 4.5 4.2\\n\", \"4.1 3.5 4.5\\n\", \"1.9 3.0 4.1\\n\", \"4.3 2.4 4.9\\n\", \"1.7 1.9 4.4\\n\", \"4.5 1.3 4.8\\n\", \"1.9 1.1 4.8\\n\", \"0.4 0.2 0.3\\n\", \"0.4 1.1 0.9\\n\", \"0.2 0.7 0.6\\n\", \"0.1 0.1 0.4\\n\", \"1.4 1.1 1.0\\n\", \"1.4 0.5 0.8\\n\", \"1.2 0.7 1.3\\n\", \"1.0 0.3 1.1\\n\", \"0.9 1.2 0.2\\n\", \"0.8 0.3 0.6\\n\", \"0.6 0.6 1.1\\n\", \"0.5 0.1 0.9\\n\", \"0.4 1.0 1.5\\n\", \"0.3 0.4 1.2\\n\", \"0.1 1.4 0.3\\n\", \"1.4 0.8 0.2\\n\", \"1.4 1.2 1.4\\n\", \"1.2 0.6 0.5\\n\", \"1.1 1.5 0.4\\n\", \"1.5 1.4 1.1\\n\", \"1.4 0.8 0.9\\n\", \"1.4 0.3 1.4\\n\", \"1.2 0.5 1.2\\n\", \"1.1 1.5 1.0\\n\", \"0.9 1.0 0.1\\n\", \"0.8 0.4 1.4\\n\", \"0.7 1.4 0.4\\n\", \"0.5 0.8 0.3\\n\", \"0.4 1.1 0.8\\n\", \"0.2 0.1 0.2\\n\", \"0.1 0.2 0.6\\n\", \"0.1 0.2 0.6\\n\", \"0.5 0.1 0.3\\n\", \"0.1 0.1 0.1\\n\", \"0.5 0.5 0.1\\n\", \"0.5 0.2 0.2\\n\", \"0.3 0.4 0.4\\n\", \"0.1 0.3 0.5\\n\", \"0.3 0.3 0.5\\n\", \"0.2 0.6 0.3\\n\", \"0.6 0.3 0.2\\n\", \"0.2 0.1 0.6\\n\", \"0.4 0.1 0.6\\n\", \"0.6 0.4 0.3\\n\", \"0.4 0.2 0.3\\n\", \"0.2 0.2 0.5\\n\", \"0.2 0.3 0.2\\n\", \"0.6 0.3 0.2\\n\", \"0.2 0.6 0.4\\n\", \"0.6 0.2 0.5\\n\", \"0.5 0.2 0.3\\n\", \"0.5 0.3 0.2\\n\", \"0.3 0.5 0.6\\n\", \"0.5 0.3 0.1\\n\", \"0.3 0.4 0.1\\n\", \"0.5 0.4 0.5\\n\", \"0.1 0.5 0.4\\n\", \"0.5 0.5 0.6\\n\", \"0.1 0.5 0.2\\n\", \"1.0 2.0 4.0\\n\", \"1.0 4.0 2.0\\n\", \"2.0 1.0 4.0\\n\", \"2.0 4.0 1.0\\n\", \"4.0 1.0 2.0\\n\", \"4.0 2.0 1.0\\n\", \"3.0 3.0 3.1\\n\", \"0.1 0.2 0.3\\n\", \"200.0 200.0 200.0\\n\", \"1.0 1.0 200.0\\n\", \"1.0 200.0 1.0\\n\", \"200.0 1.0 1.0\\n\", \"200.0 200.0 1.0\\n\", \"200.0 1.0 200.0\\n\", \"1.0 200.0 200.0\\n\", \"1.0 1.0 1.0\\n\", \"200.0 0.1 0.1\\n\", \"200.0 0.1 200.0\\n\", \"0.1 200.0 200.0\\n\", \"200.0 200.0 0.1\\n\", \"0.1 200.0 0.1\\n\", \"0.1 0.1 200.0\\n\", \"0.1 0.1 0.1\\n\", \"0.1 0.4 0.2\\n\", \"0.2 0.3 0.1\\n\", \"0.1 0.4 0.3\\n\", \"1.0 2.0 1.0\\n\"], \"outputs\": [\"z^y^x\\n\", \"x^y^z\\n\", \"(x^y)^z\\n\", \"x^z^y\\n\", \"(z^x)^y\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"z^x^y\\n\", \"y^z^x\\n\", \"y^z^x\\n\", \"z^y^x\\n\", \"z^y^x\\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\", \"x^z^y\\n\", \"y^z^x\\n\", \"z^x^y\\n\", \"z^x^y\\n\", \"y^x^z\\n\", \"z^y^x\\n\", \"x^z^y\\n\", \"y^x^z\\n\", \"y^x^z\\n\", \"z^y^x\\n\", \"x^y^z\\n\", \"x^z^y\\n\", \"y^z^x\\n\", \"y^z^x\\n\", \"y^z^x\\n\", \"z^x^y\\n\", \"y^z^x\\n\", \"z^x^y\\n\", \"x^z^y\\n\", \"x^z^y\\n\", \"(z^x)^y\\n\", \"x^y^z\\n\", \"x^y^z\\n\", \"y^x^z\\n\", \"(y^x)^z\\n\", \"y^x^z\\n\", \"x^y^z\\n\", \"(x^y)^z\\n\", \"(z^x)^y\\n\", \"z^y^x\\n\", \"(z^x)^y\\n\", \"x^z^y\\n\", \"z^x^y\\n\", \"z^y^x\\n\", \"x^z^y\\n\", \"z^y^x\\n\", \"x^z^y\\n\", \"y^z^x\\n\", \"x^z^y\\n\", \"x^z^y\\n\", \"z^x^y\\n\", \"x^z^y\\n\", \"y^x^z\\n\", \"x^y^z\\n\", \"y^x^z\\n\", \"x^y^z\\n\", \"y^x^z\\n\", \"x^z^y\\n\", \"(x^y)^z\\n\", \"y^z^x\\n\", \"(y^x)^z\\n\", \"(z^x)^y\\n\", \"x^y^z\\n\", \"x^z^y\\n\", \"z^x^y\\n\", \"z^x^y\\n\", \"y^x^z\\n\", \"(x^y)^z\\n\", \"z^x^y\\n\", \"(z^x)^y\\n\", \"z^y^x\\n\", \"z^y^x\\n\", \"y^z^x\\n\", \"x^y^z\\n\", \"(x^y)^z\\n\", \"x^y^z\\n\", \"y^x^z\\n\", \"(x^y)^z\\n\", \"x^z^y\\n\", \"x^z^y\\n\", \"x^z^y\\n\", \"y^x^z\\n\", \"y^x^z\\n\", \"z^x^y\\n\", \"y^x^z\\n\", \"(y^x)^z\\n\", \"y^z^x\\n\", \"(x^y)^z\\n\", \"(z^x)^y\\n\", \"(z^x)^y\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"(y^x)^z\\n\", \"(z^x)^y\\n\", \"(z^x)^y\\n\", \"(y^x)^z\\n\", \"(x^y)^z\\n\", \"(z^x)^y\\n\", \"(z^x)^y\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"(z^x)^y\\n\", \"(y^x)^z\\n\", \"(x^y)^z\\n\", \"(y^x)^z\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"(x^y)^z\\n\", \"(z^x)^y\\n\", \"(x^y)^z\\n\", \"(y^x)^z\\n\", \"(x^y)^z\\n\", \"(y^x)^z\\n\", \"(z^x)^y\\n\", \"(y^x)^z\\n\", \"y^z^x\\n\", \"y^z^x\\n\", \"x^z^y\\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^x^y\\n\", \"y^x^z\\n\", \"x^y^z\\n\", \"x^y^z\\n\", \"x^z^y\\n\", \"y^z^x\\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\", \"z^x^y\\n\", \"(x^y)^z\\n\", \"(y^x)^z\\n\", \"(y^x)^z\\n\", \"(y^x)^z\\n\", \"y^x^z\\n\"]}", "source": "primeintellect"}
|
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: a_1 = x^{y}^{z}; a_2 = x^{z}^{y}; a_3 = (x^{y})^{z}; a_4 = (x^{z})^{y}; a_5 = y^{x}^{z}; a_6 = y^{z}^{x}; a_7 = (y^{x})^{z}; a_8 = (y^{z})^{x}; a_9 = z^{x}^{y}; a_10 = z^{y}^{x}; a_11 = (z^{x})^{y}; a_12 = (z^{y})^{x}.
Let m be the maximum of all the a_{i}, and c be the smallest index (from 1 to 12) such that a_{c} = 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 a_{c}.
-----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 x^{y}^{z}, x^{z}^{y}, (x^{y})^{z}, (x^{z})^{y}, y^{x}^{z}, y^{z}^{x}, (y^{x})^{z}, (y^{z})^{x}, z^{x}^{y}, z^{y}^{x}, (z^{x})^{y}, (z^{y})^{x} and print the corresponding expression. If there are many maximums, print the one that comes first in the list.
x^{y}^{z} should be outputted as x^y^z (without brackets), and (x^{y})^{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
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"5\\n01 0\\n2 1\\n2extra 0\\n3 1\\n99 0\\n\", \"2\\n1 0\\n2 1\\n\", \"5\\n1 0\\n11 1\\n111 0\\n1111 1\\n11111 0\\n\", \"4\\nir7oz8 1\\nvj4v5t 1\\nkwkahb 1\\nj5s8o1 0\\n\", \"4\\n3 1\\n1o0bp2 0\\n9tn379 0\\nv04v6j 1\\n\", \"4\\n1 0\\nsc7czx 0\\nfr4033 1\\n3 0\\n\", \"4\\n4 0\\n1 0\\n2 0\\nizfotg 1\\n\", \"4\\n2 0\\n3 0\\n1 1\\n4 1\\n\", \"5\\npuusew 1\\npvoy4h 0\\nwdzx4r 0\\n1z84cx 0\\nozsuvd 0\\n\", \"5\\n949pnr 1\\n9sxhcr 0\\n5 1\\nx8srx3 1\\ncl7ppd 1\\n\", \"5\\n2 0\\n1 0\\np2gcxf 1\\nwfyoiq 1\\nzjw3vg 1\\n\", \"5\\nogvgi7 0\\n3 1\\n4 1\\n1 1\\nm5nhux 0\\n\", \"5\\nt6kdte 1\\n2 1\\n4 1\\n5 1\\n3 1\\n\", \"5\\n2 0\\n3 1\\n4 0\\n1 1\\n5 1\\n\", \"1\\nsd84r7 1\\n\", \"1\\n1 0\\n\", \"2\\n5xzjm4 0\\njoa6mr 1\\n\", \"2\\n1 0\\nxdkh5a 1\\n\", \"2\\n1 0\\n2 0\\n\", \"3\\nz1nwrd 1\\nt0xrja 0\\n106qy1 0\\n\", \"3\\nt4hdos 0\\ndhje0g 0\\n3 0\\n\", \"3\\n3 0\\n26mp5s 0\\n1 1\\n\", \"3\\n2 1\\n1 0\\n3 0\\n\", \"1\\nprzvln 0\\n\", \"2\\nkfsipl 0\\n1jj1ol 0\\n\", \"3\\n2x7a4g 0\\n27lqe6 0\\nzfo3sp 0\\n\", \"1\\nxzp9ni 1\\n\", \"1\\nabbdf7 1\\n\", \"2\\ndbif39 1\\ne8dkf8 0\\n\", \"2\\n2 0\\njkwekx 1\\n\", \"3\\nn3pmj8 0\\n2alui6 0\\ne7lf4u 1\\n\", \"3\\ndr1lp8 0\\n1 0\\n6a2egk 1\\n\", \"4\\nyi9ta0 1\\nmeljgm 0\\nf7bqon 0\\n5bbvun 0\\n\", \"4\\n0la3gu 0\\nzhrmyb 1\\n3iprc0 0\\n3 0\\n\", \"1\\n1 1\\n\", \"1\\n1 1\\n\", \"2\\n17dgbb 0\\n2 1\\n\", \"2\\n1 0\\n2 1\\n\", \"3\\nscrn8k 0\\n3 1\\nycvm9s 0\\n\", \"3\\nt0dfz3 0\\n3 0\\n1 1\\n\", \"4\\nkgw83p 0\\np3p3ch 0\\n4 1\\n0te9lv 0\\n\", \"4\\n3 1\\nnj94jx 0\\n3a5ad1 0\\n1 0\\n\", \"2\\no9z069 1\\n5hools 1\\n\", \"2\\nyzzyab 1\\n728oq0 1\\n\", \"2\\nqy2kmc 1\\nqb4crj 1\\n\", \"3\\nunw560 1\\n0iswxk 0\\ndonjp9 1\\n\", \"3\\n2 0\\nuv8c54 1\\n508bb0 1\\n\", \"3\\n9afh0z 1\\n0qcaht 1\\n3 0\\n\", \"4\\n2kk04q 0\\nkdktvk 1\\nc4i5k8 1\\nawaock 0\\n\", \"4\\n2 0\\nmqbjos 0\\n6mhijg 1\\n6wum8y 1\\n\", \"4\\n4 0\\npa613p 1\\nuuizq7 1\\n2 0\\n\", \"5\\nw0g96a 1\\nv99tdi 0\\nmywrle 0\\nweh22w 1\\n9hywt4 0\\n\", \"5\\n5 0\\n12qcjd 1\\nuthzbz 0\\nb3670z 0\\nl2u93o 1\\n\", \"5\\n0jc7xb 1\\n2 0\\n1m7l9s 0\\n9xzkau 1\\n1 0\\n\", \"2\\n1 1\\nvinxur 1\\n\", \"2\\n1qe46n 1\\n1 1\\n\", \"2\\n1 1\\ng5jlzp 1\\n\", \"3\\nc8p28p 1\\n2 1\\nvk4gdf 0\\n\", \"3\\n2 1\\n3 0\\nhs9j9t 1\\n\", \"3\\n2 1\\n1 0\\nomitxh 1\\n\", \"4\\n4 1\\nu9do88 1\\n787at9 0\\nfcud6k 0\\n\", \"4\\n3 0\\nqvw4ow 1\\nne0ng9 0\\n1 1\\n\", \"4\\ng6ugrm 1\\n1 1\\n3 0\\n2 0\\n\", \"5\\n5 1\\nz9zr7d 0\\ne8rwo4 1\\nrfpjp6 0\\ngz6dhj 0\\n\", \"5\\n5sn77g 0\\nsetddt 1\\nbz16cb 0\\n4 1\\n2 0\\n\", \"5\\n1 1\\nx2miqh 1\\n3 0\\n2 0\\n1rq643 0\\n\", \"2\\n1 1\\n2 1\\n\", \"2\\n1 1\\n2 1\\n\", \"2\\n2 1\\n1 1\\n\", \"3\\n3 1\\nav5vex 0\\n1 1\\n\", \"3\\n3 1\\n1 0\\n2 1\\n\", \"3\\n3 1\\n1 0\\n2 1\\n\", \"4\\ny9144q 0\\n3 1\\n2 1\\ns0bdnf 0\\n\", \"4\\n4 1\\n1 0\\n3 1\\nmod9zl 0\\n\", \"4\\n4 1\\n3 1\\n1 0\\n2 0\\n\", \"5\\n1 1\\nnoidnv 0\\n3 1\\nx3xiiz 0\\n1lfa9v 0\\n\", \"5\\n1 1\\nvsyajx 0\\n783b38 0\\n4 0\\n2 1\\n\", \"5\\n3 1\\n5 0\\ncvfl8i 0\\n4 1\\n2 0\\n\", \"3\\nbxo0pe 1\\nbt50pa 1\\n2tx68t 1\\n\", \"3\\nj9rnac 1\\noetwfz 1\\nd6n3ww 1\\n\", \"3\\naf2f6j 1\\nmjni5l 1\\njvyxgc 1\\n\", \"3\\nr2qlj2 1\\nt8wf1y 1\\nigids8 1\\n\", \"4\\nuilh9a 0\\n4lxxh9 1\\nkqdpzy 1\\nn1d7hd 1\\n\", \"4\\n3 0\\niipymv 1\\nvakd5b 1\\n2ktczv 1\\n\", \"4\\nq4b449 1\\n3 0\\ncjg1x2 1\\ne878er 1\\n\", \"4\\n9f4aoa 1\\n4 0\\nf4m1ec 1\\nqyr2h6 1\\n\", \"5\\n73s1nt 1\\nsbngv2 0\\n4n3qri 1\\nbyhzp8 1\\nadpjs4 0\\n\", \"5\\n7ajg8o 1\\np7cqxy 1\\n3qrp34 0\\nh93m07 1\\n2 0\\n\", \"5\\ny0wnwz 1\\n5 0\\n0totai 1\\n1 0\\nym8xwz 1\\n\", \"5\\n5 0\\n4 0\\n5nvzu4 1\\nvkpzzk 1\\nzamzcz 1\\n\", \"6\\np1wjw9 1\\nueksby 0\\nu1ixfc 1\\nj3lk2e 1\\n36iskv 0\\n9imqi1 0\\n\", \"6\\n6slonw 1\\nptk9mc 1\\n57a4nq 0\\nhiq2f7 1\\n2 0\\nc0gtv3 0\\n\", \"6\\n5 0\\n2 0\\ncbhvyf 1\\nl1z5mg 0\\nwkwhby 1\\nx7fdh9 1\\n\", \"6\\n1t68ks 1\\npkbj1g 1\\n5 0\\n5pw8wm 1\\n1 0\\n4 0\\n\", \"3\\n1 1\\n7ph5fw 1\\ntfxz1j 1\\n\", \"3\\norwsz0 1\\nmbt097 1\\n3 1\\n\", \"3\\n1 1\\nzwfnx2 1\\n7g8t6z 1\\n\", \"3\\nqmf7iz 1\\ndjwdce 1\\n1 1\\n\", \"4\\n4i2i2a 0\\n4 1\\npf618n 1\\nlx6nmh 1\\n\", \"4\\nxpteku 1\\n1 0\\n4 1\\n73xpqz 1\\n\", \"4\\n1wp56i 1\\n2 1\\n1 0\\n6m76jb 1\\n\", \"4\\n3 1\\nyumiqt 1\\n1 0\\nt19jus 1\\n\", \"5\\nynagvf 1\\n3 1\\nojz4mm 1\\ndovec3 0\\nnc1jye 0\\n\", \"5\\n5 1\\nwje9ts 1\\nkytn5q 1\\n7frk8z 0\\n3 0\\n\", \"5\\n1 0\\n4 1\\n3 0\\nlog9cm 1\\nu5m0ls 1\\n\", \"5\\nh015vv 1\\n3 1\\n1 0\\n9w2keb 1\\n2 0\\n\", \"6\\n0zluka 0\\nqp7q8l 1\\nwglqu8 1\\n9i7kta 0\\nnwf8m3 0\\n3 1\\n\", \"6\\n3 1\\n1h3t85 1\\n5 0\\nrf2ikt 0\\n3vhl6e 1\\n5l3oka 0\\n\", \"6\\n2 0\\n3 0\\nw9h0pv 1\\n5 1\\nq92z4i 0\\n6qb4ia 1\\n\", \"6\\n4 1\\n410jiy 1\\n1 0\\n6 0\\nxc98l2 1\\n5 0\\n\", \"3\\n1 1\\nc9qyld 1\\n3 1\\n\", \"3\\ngdm5ri 1\\n1 1\\n2 1\\n\", \"3\\n3 1\\n2 1\\ni19lnk 1\\n\", \"3\\ncxbbpd 1\\n3 1\\n1 1\\n\", \"4\\nwy6i6o 0\\n1 1\\n3 1\\niy1dq6 1\\n\", \"4\\n4 1\\nwgh8s0 1\\n1 0\\n2 1\\n\", \"4\\nhex0ur 1\\n4 1\\n3 0\\n2 1\\n\", \"4\\n4 1\\n1 1\\n3 0\\n4soxj3 1\\n\", \"5\\n5sbtul 1\\n2 1\\n8i2duz 0\\n5 1\\n4b85z6 0\\n\", \"5\\n3 1\\n4 0\\nejo0a4 1\\ngqzdbk 0\\n1 1\\n\", \"5\\n2y4agr 1\\n5 0\\n3 0\\n1 1\\n4 1\\n\", \"5\\n2 0\\n1 1\\nq4hyeg 1\\n5 0\\n4 1\\n\", \"6\\n5 1\\nrdm6fu 0\\n4 1\\noclx1h 0\\n7l3kg1 1\\nq25te0 0\\n\", \"6\\n1 0\\np4tuyt 0\\n5 1\\n2 1\\nwrrcmu 1\\n3r4wqz 0\\n\", \"6\\n5 1\\n6 0\\nxhfzge 0\\n3 1\\n1 0\\n1n9mqv 1\\n\", \"6\\nhmpfsz 1\\n6 0\\n5 1\\n4 0\\n1 0\\n3 1\\n\", \"3\\n1 1\\n3 1\\n2 1\\n\", \"3\\n2 1\\n3 1\\n1 1\\n\", \"3\\n2 1\\n1 1\\n3 1\\n\", \"3\\n1 1\\n2 1\\n3 1\\n\", \"4\\n3 1\\n1 1\\n4 1\\nd1cks2 0\\n\", \"4\\n4 0\\n3 1\\n1 1\\n2 1\\n\", \"4\\n2 1\\n4 1\\n1 0\\n3 1\\n\", \"4\\n4 1\\n1 1\\n3 1\\n2 0\\n\", \"5\\n4 1\\nhvshea 0\\naio11n 0\\n2 1\\n3 1\\n\", \"5\\n5 0\\nts7a1c 0\\n4 1\\n1 1\\n2 1\\n\", \"5\\n4 0\\n3 1\\n5 0\\n2 1\\n1 1\\n\", \"5\\n3 1\\n5 0\\n4 1\\n1 1\\n2 0\\n\", \"6\\neik3kw 0\\n5 1\\nzoonoj 0\\n2 1\\n1 1\\nivzfie 0\\n\", \"6\\n7igwk9 0\\n6 1\\n5 1\\ndx2yu0 0\\n2 0\\n1 1\\n\", \"6\\nc3py3h 0\\n2 1\\n4 0\\n3 0\\n1 1\\n5 1\\n\", \"6\\n1 1\\n3 0\\n2 1\\n6 1\\n4 0\\n5 0\\n\", \"20\\nphp8vy 1\\nkeeona 0\\n8 0\\nwzf4eb 0\\n16 1\\n9 0\\nf2548d 0\\n11 0\\nyszsig 0\\nyyf4q2 0\\n1pon1p 1\\njvpwuo 0\\nd9stsx 0\\ne14bkx 1\\n5 0\\n17 0\\nsbklx4 0\\nsfms2u 1\\n6 0\\n18 1\\n\", \"4\\n3 1\\n4 1\\n1 0\\n2 0\\n\", \"1\\n01 1\\n\", \"2\\n01 0\\n02 1\\n\"], \"outputs\": [\"4\\nmove 3 1\\nmove 01 5\\nmove 2extra 4\\nmove 99 3\\n\", \"3\\nmove 1 07x45l\\nmove 2 1\\nmove 07x45l 2\\n\", \"5\\nmove 1 5\\nmove 11 1\\nmove 1111 2\\nmove 111 4\\nmove 11111 3\\n\", \"4\\nmove ir7oz8 1\\nmove vj4v5t 2\\nmove kwkahb 3\\nmove j5s8o1 4\\n\", \"4\\nmove 3 1\\nmove v04v6j 2\\nmove 1o0bp2 4\\nmove 9tn379 3\\n\", \"3\\nmove 1 4\\nmove fr4033 1\\nmove sc7czx 2\\n\", \"2\\nmove 1 3\\nmove izfotg 1\\n\", \"3\\nmove 2 3b4gxa\\nmove 4 2\\nmove 3b4gxa 4\\n\", \"5\\nmove puusew 1\\nmove pvoy4h 5\\nmove wdzx4r 4\\nmove 1z84cx 3\\nmove ozsuvd 2\\n\", \"5\\nmove 5 1\\nmove 949pnr 2\\nmove x8srx3 3\\nmove cl7ppd 4\\nmove 9sxhcr 5\\n\", \"5\\nmove 2 5\\nmove 1 4\\nmove p2gcxf 1\\nmove wfyoiq 2\\nmove zjw3vg 3\\n\", \"3\\nmove 4 2\\nmove ogvgi7 5\\nmove m5nhux 4\\n\", \"1\\nmove t6kdte 1\\n\", \"3\\nmove 2 8z9k33\\nmove 5 2\\nmove 8z9k33 5\\n\", \"1\\nmove sd84r7 1\\n\", \"0\\n\", \"2\\nmove joa6mr 1\\nmove 5xzjm4 2\\n\", \"2\\nmove 1 2\\nmove xdkh5a 1\\n\", \"0\\n\", \"3\\nmove z1nwrd 1\\nmove t0xrja 3\\nmove 106qy1 2\\n\", \"2\\nmove t4hdos 2\\nmove dhje0g 1\\n\", \"1\\nmove 26mp5s 2\\n\", \"3\\nmove 2 adavev\\nmove 1 2\\nmove adavev 1\\n\", \"1\\nmove przvln 1\\n\", \"2\\nmove kfsipl 2\\nmove 1jj1ol 1\\n\", \"3\\nmove 2x7a4g 3\\nmove 27lqe6 2\\nmove zfo3sp 1\\n\", \"1\\nmove xzp9ni 1\\n\", \"1\\nmove abbdf7 1\\n\", \"2\\nmove dbif39 1\\nmove e8dkf8 2\\n\", \"1\\nmove jkwekx 1\\n\", \"3\\nmove e7lf4u 1\\nmove n3pmj8 3\\nmove 2alui6 2\\n\", \"3\\nmove 1 3\\nmove 6a2egk 1\\nmove dr1lp8 2\\n\", \"4\\nmove yi9ta0 1\\nmove meljgm 4\\nmove f7bqon 3\\nmove 5bbvun 2\\n\", \"3\\nmove zhrmyb 1\\nmove 0la3gu 4\\nmove 3iprc0 2\\n\", \"0\\n\", \"0\\n\", \"2\\nmove 2 1\\nmove 17dgbb 2\\n\", \"3\\nmove 1 94gxxb\\nmove 2 1\\nmove 94gxxb 2\\n\", \"3\\nmove 3 1\\nmove scrn8k 3\\nmove ycvm9s 2\\n\", \"1\\nmove t0dfz3 2\\n\", \"4\\nmove 4 1\\nmove kgw83p 4\\nmove p3p3ch 3\\nmove 0te9lv 2\\n\", \"4\\nmove 1 4\\nmove 3 1\\nmove nj94jx 3\\nmove 3a5ad1 2\\n\", \"2\\nmove o9z069 1\\nmove 5hools 2\\n\", \"2\\nmove yzzyab 1\\nmove 728oq0 2\\n\", \"2\\nmove qy2kmc 1\\nmove qb4crj 2\\n\", \"3\\nmove unw560 1\\nmove donjp9 2\\nmove 0iswxk 3\\n\", \"3\\nmove 2 3\\nmove uv8c54 1\\nmove 508bb0 2\\n\", \"2\\nmove 9afh0z 1\\nmove 0qcaht 2\\n\", \"4\\nmove kdktvk 1\\nmove c4i5k8 2\\nmove 2kk04q 4\\nmove awaock 3\\n\", \"4\\nmove 2 4\\nmove 6mhijg 1\\nmove 6wum8y 2\\nmove mqbjos 3\\n\", \"3\\nmove 2 3\\nmove pa613p 1\\nmove uuizq7 2\\n\", \"5\\nmove w0g96a 1\\nmove weh22w 2\\nmove v99tdi 5\\nmove mywrle 4\\nmove 9hywt4 3\\n\", \"4\\nmove 12qcjd 1\\nmove l2u93o 2\\nmove uthzbz 4\\nmove b3670z 3\\n\", \"5\\nmove 2 5\\nmove 1 4\\nmove 0jc7xb 1\\nmove 9xzkau 2\\nmove 1m7l9s 3\\n\", \"1\\nmove vinxur 2\\n\", \"1\\nmove 1qe46n 2\\n\", \"1\\nmove g5jlzp 2\\n\", \"2\\nmove c8p28p 1\\nmove vk4gdf 3\\n\", \"1\\nmove hs9j9t 1\\n\", \"2\\nmove 1 3\\nmove omitxh 1\\n\", \"4\\nmove 4 1\\nmove u9do88 2\\nmove 787at9 4\\nmove fcud6k 3\\n\", \"2\\nmove qvw4ow 2\\nmove ne0ng9 4\\n\", \"2\\nmove 2 4\\nmove g6ugrm 2\\n\", \"5\\nmove 5 1\\nmove e8rwo4 2\\nmove z9zr7d 5\\nmove rfpjp6 4\\nmove gz6dhj 3\\n\", \"5\\nmove 4 1\\nmove 2 5\\nmove setddt 2\\nmove 5sn77g 4\\nmove bz16cb 3\\n\", \"3\\nmove 2 5\\nmove x2miqh 2\\nmove 1rq643 4\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"2\\nmove 3 2\\nmove av5vex 3\\n\", \"3\\nmove 3 ger8ob\\nmove 1 3\\nmove ger8ob 1\\n\", \"3\\nmove 3 7d2teb\\nmove 1 3\\nmove 7d2teb 1\\n\", \"3\\nmove 3 1\\nmove y9144q 4\\nmove s0bdnf 3\\n\", \"4\\nmove 4 2\\nmove 1 4\\nmove 3 1\\nmove mod9zl 3\\n\", \"5\\nmove 4 ger8ob\\nmove 1 4\\nmove 3 1\\nmove 2 3\\nmove ger8ob 2\\n\", \"4\\nmove 3 2\\nmove noidnv 5\\nmove x3xiiz 4\\nmove 1lfa9v 3\\n\", \"2\\nmove vsyajx 5\\nmove 783b38 3\\n\", \"4\\nmove 3 1\\nmove 2 3\\nmove 4 2\\nmove cvfl8i 4\\n\", \"3\\nmove bxo0pe 1\\nmove bt50pa 2\\nmove 2tx68t 3\\n\", \"3\\nmove j9rnac 1\\nmove oetwfz 2\\nmove d6n3ww 3\\n\", \"3\\nmove af2f6j 1\\nmove mjni5l 2\\nmove jvyxgc 3\\n\", \"3\\nmove r2qlj2 1\\nmove t8wf1y 2\\nmove igids8 3\\n\", \"4\\nmove 4lxxh9 1\\nmove kqdpzy 2\\nmove n1d7hd 3\\nmove uilh9a 4\\n\", \"4\\nmove 3 4\\nmove iipymv 1\\nmove vakd5b 2\\nmove 2ktczv 3\\n\", \"4\\nmove 3 4\\nmove q4b449 1\\nmove cjg1x2 2\\nmove e878er 3\\n\", \"3\\nmove 9f4aoa 1\\nmove f4m1ec 2\\nmove qyr2h6 3\\n\", \"5\\nmove 73s1nt 1\\nmove 4n3qri 2\\nmove byhzp8 3\\nmove sbngv2 5\\nmove adpjs4 4\\n\", \"5\\nmove 2 5\\nmove 7ajg8o 1\\nmove p7cqxy 2\\nmove h93m07 3\\nmove 3qrp34 4\\n\", \"4\\nmove 1 4\\nmove y0wnwz 1\\nmove 0totai 2\\nmove ym8xwz 3\\n\", \"3\\nmove 5nvzu4 1\\nmove vkpzzk 2\\nmove zamzcz 3\\n\", \"6\\nmove p1wjw9 1\\nmove u1ixfc 2\\nmove j3lk2e 3\\nmove ueksby 6\\nmove 36iskv 5\\nmove 9imqi1 4\\n\", \"6\\nmove 2 6\\nmove 6slonw 1\\nmove ptk9mc 2\\nmove hiq2f7 3\\nmove 57a4nq 5\\nmove c0gtv3 4\\n\", \"5\\nmove 2 6\\nmove cbhvyf 1\\nmove wkwhby 2\\nmove x7fdh9 3\\nmove l1z5mg 4\\n\", \"4\\nmove 1 6\\nmove 1t68ks 1\\nmove pkbj1g 2\\nmove 5pw8wm 3\\n\", \"2\\nmove 7ph5fw 2\\nmove tfxz1j 3\\n\", \"2\\nmove orwsz0 1\\nmove mbt097 2\\n\", \"2\\nmove zwfnx2 2\\nmove 7g8t6z 3\\n\", \"2\\nmove qmf7iz 2\\nmove djwdce 3\\n\", \"4\\nmove 4 1\\nmove pf618n 2\\nmove lx6nmh 3\\nmove 4i2i2a 4\\n\", \"4\\nmove 4 2\\nmove 1 4\\nmove xpteku 1\\nmove 73xpqz 3\\n\", \"3\\nmove 1 4\\nmove 1wp56i 1\\nmove 6m76jb 3\\n\", \"3\\nmove 1 4\\nmove yumiqt 1\\nmove t19jus 2\\n\", \"4\\nmove ynagvf 1\\nmove ojz4mm 2\\nmove dovec3 5\\nmove nc1jye 4\\n\", \"5\\nmove 5 1\\nmove 3 5\\nmove wje9ts 2\\nmove kytn5q 3\\nmove 7frk8z 4\\n\", \"5\\nmove 4 2\\nmove 1 5\\nmove 3 4\\nmove log9cm 1\\nmove u5m0ls 3\\n\", \"4\\nmove 1 5\\nmove 2 4\\nmove h015vv 1\\nmove 9w2keb 2\\n\", \"5\\nmove qp7q8l 1\\nmove wglqu8 2\\nmove 0zluka 6\\nmove 9i7kta 5\\nmove nwf8m3 4\\n\", \"4\\nmove 1h3t85 1\\nmove 3vhl6e 2\\nmove rf2ikt 6\\nmove 5l3oka 4\\n\", \"6\\nmove 5 1\\nmove 2 6\\nmove 3 5\\nmove w9h0pv 2\\nmove 6qb4ia 3\\nmove q92z4i 4\\n\", \"4\\nmove 4 2\\nmove 1 4\\nmove 410jiy 1\\nmove xc98l2 3\\n\", \"1\\nmove c9qyld 2\\n\", \"1\\nmove gdm5ri 3\\n\", \"1\\nmove i19lnk 1\\n\", \"1\\nmove cxbbpd 2\\n\", \"2\\nmove iy1dq6 2\\nmove wy6i6o 4\\n\", \"3\\nmove 4 3\\nmove 1 4\\nmove wgh8s0 1\\n\", \"3\\nmove 4 1\\nmove 3 4\\nmove hex0ur 3\\n\", \"3\\nmove 4 2\\nmove 3 4\\nmove 4soxj3 3\\n\", \"4\\nmove 5 1\\nmove 5sbtul 3\\nmove 8i2duz 5\\nmove 4b85z6 4\\n\", \"2\\nmove ejo0a4 2\\nmove gqzdbk 5\\n\", \"3\\nmove 4 2\\nmove 3 4\\nmove 2y4agr 3\\n\", \"3\\nmove 4 3\\nmove 2 4\\nmove q4hyeg 2\\n\", \"6\\nmove 5 1\\nmove 4 2\\nmove 7l3kg1 3\\nmove rdm6fu 6\\nmove oclx1h 5\\nmove q25te0 4\\n\", \"5\\nmove 5 3\\nmove 1 6\\nmove wrrcmu 1\\nmove p4tuyt 5\\nmove 3r4wqz 4\\n\", \"4\\nmove 5 2\\nmove 1 5\\nmove 1n9mqv 1\\nmove xhfzge 4\\n\", \"3\\nmove 5 2\\nmove 1 5\\nmove hmpfsz 1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"2\\nmove 4 2\\nmove d1cks2 4\\n\", \"0\\n\", \"3\\nmove 4 sm2dpo\\nmove 1 4\\nmove sm2dpo 1\\n\", \"3\\nmove 4 2kxv8f\\nmove 2 4\\nmove 2kxv8f 2\\n\", \"3\\nmove 4 1\\nmove hvshea 5\\nmove aio11n 4\\n\", \"2\\nmove 4 3\\nmove ts7a1c 4\\n\", \"0\\n\", \"3\\nmove 4 9nzu21\\nmove 2 4\\nmove 9nzu21 2\\n\", \"4\\nmove 5 3\\nmove eik3kw 6\\nmove zoonoj 5\\nmove ivzfie 4\\n\", \"5\\nmove 6 3\\nmove 2 6\\nmove 5 2\\nmove 7igwk9 5\\nmove dx2yu0 4\\n\", \"3\\nmove 3 6\\nmove 5 3\\nmove c3py3h 5\\n\", \"3\\nmove 3 2kxv8f\\nmove 6 3\\nmove 2kxv8f 6\\n\", \"16\\nmove 16 1\\nmove 18 2\\nmove 5 20\\nmove 6 19\\nmove php8vy 3\\nmove 1pon1p 4\\nmove e14bkx 5\\nmove sfms2u 6\\nmove keeona 18\\nmove wzf4eb 16\\nmove f2548d 15\\nmove yszsig 14\\nmove yyf4q2 13\\nmove jvpwuo 12\\nmove d9stsx 10\\nmove sbklx4 7\\n\", \"5\\nmove 3 7dcv6s\\nmove 1 3\\nmove 4 1\\nmove 2 4\\nmove 7dcv6s 2\\n\", \"1\\nmove 01 1\\n\", \"2\\nmove 02 1\\nmove 01 2\\n\"]}", "source": "primeintellect"}
|
The All-Berland National Olympiad in Informatics has just ended! Now Vladimir wants to upload the contest from the Olympiad as a gym to a popular Codehorses website.
Unfortunately, the archive with Olympiad's data is a mess. For example, the files with tests are named arbitrary without any logic.
Vladimir wants to rename the files with tests so that their names are distinct integers starting from 1 without any gaps, namely, "1", "2", ..., "n', where n is the total number of tests.
Some of the files contain tests from statements (examples), while others contain regular tests. It is possible that there are no examples, and it is possible that all tests are examples. Vladimir wants to rename the files so that the examples are the first several tests, all all the next files contain regular tests only.
The only operation Vladimir can perform is the "move" command. Vladimir wants to write a script file, each of the lines in which is "move file_1 file_2", that means that the file "file_1" is to be renamed to "file_2". If there is a file "file_2" at the moment of this line being run, then this file is to be rewritten. After the line "move file_1 file_2" the file "file_1" doesn't exist, but there is a file "file_2" with content equal to the content of "file_1" before the "move" command.
Help Vladimir to write the script file with the minimum possible number of lines so that after this script is run: all examples are the first several tests having filenames "1", "2", ..., "e", where e is the total number of examples; all other files contain regular tests with filenames "e + 1", "e + 2", ..., "n", where n is the total number of all tests.
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 10^5) — the number of files with tests.
n lines follow, each describing a file with test. Each line has a form of "name_i type_i", where "name_i" is the filename, and "type_i" equals "1", if the i-th file contains an example test, and "0" if it contains a regular test. Filenames of each file are strings of digits and small English letters with length from 1 to 6 characters. The filenames are guaranteed to be distinct.
-----Output-----
In the first line print the minimum number of lines in Vladimir's script file.
After that print the script file, each line should be "move file_1 file_2", where "file_1" is an existing at the moment of this line being run filename, and "file_2" — is a string of digits and small English letters with length from 1 to 6.
-----Examples-----
Input
5
01 0
2 1
2extra 0
3 1
99 0
Output
4
move 3 1
move 01 5
move 2extra 4
move 99 3
Input
2
1 0
2 1
Output
3
move 1 3
move 2 1
move 3 2
Input
5
1 0
11 1
111 0
1111 1
11111 0
Output
5
move 1 5
move 11 1
move 1111 2
move 111 4
move 11111 3
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n\", \"7\\n\", \"39\\n\", \"14\\n\", \"94\\n\", \"60\\n\", \"60\\n\", \"59\\n\", \"181994\\n\", \"486639\\n\", \"34514\\n\", \"826594\\n\", \"1000000000000000000\\n\", \"854460\\n\", \"164960\\n\", \"618459\\n\", \"496181994\\n\", \"1000000000\\n\", \"228939226\\n\", \"973034514\\n\", \"984826594\\n\", \"19164960\\n\", \"249781780\\n\", \"851838979\\n\", \"978618459\\n\", \"871854460\\n\", \"302486639\\n\", \"0\\n\", \"1\\n\", \"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\", \"13\\n\", \"14\\n\", \"15\\n\", \"16\\n\", \"17\\n\", \"18\\n\", \"19\\n\", \"20\\n\", \"21\\n\", \"22\\n\", \"23\\n\", \"24\\n\", \"25\\n\", \"26\\n\", \"27\\n\", \"28\\n\", \"29\\n\", \"30\\n\", \"257947185131120683\\n\", \"258773432604171403\\n\", \"259599671487287531\\n\", \"260425914665370955\\n\", \"261252157843454379\\n\", \"262078401021537803\\n\", \"262904639904653932\\n\", \"263730878787770060\\n\", \"264557126260820780\\n\", \"775736713043603670\\n\", \"776562956221687094\\n\", \"777389199399770518\\n\", \"778215438282886646\\n\", \"779041681460970070\\n\", \"779867924639053494\\n\", \"780694167817136918\\n\", \"781520406700253046\\n\", \"782346645583369174\\n\", \"783172893056419894\\n\", \"294352484134170081\\n\", \"34761473798667069\\n\", \"247761054921329978\\n\", \"88904985049714519\\n\", \"64695994584418558\\n\", \"2999472947040002\\n\", \"134013960807648841\\n\", \"27719767248080188\\n\", \"228296921967681448\\n\", \"622704061396296670\\n\", \"382830415035226081\\n\", \"175683606088259879\\n\", \"533568904697339792\\n\", \"281824423976299408\\n\", \"237223610332609448\\n\", \"82638676376847406\\n\", \"358538881902627465\\n\", \"1941943667672759\\n\", \"504819148029580024\\n\", \"24271330411219667\\n\", \"108364135632524999\\n\", \"16796277375911920\\n\", \"194403552286884865\\n\", \"565840809656836956\\n\", \"39010293491965817\\n\", \"746407891412272132\\n\", \"95626493228268863\\n\", \"385078658398478614\\n\", \"177207687885798058\\n\", \"536222521732590352\\n\", \"1571429132955632\\n\", \"498549006180463098\\n\", \"438594547809157461\\n\", \"214071008058709620\\n\", \"599060227806517999\\n\", \"329939015655396840\\n\", \"281523482448806534\\n\", \"109561818187625921\\n\", \"412565943716413781\\n\", \"196006607922989510\\n\", \"379604878823574823\\n\", \"173500741457825598\\n\", \"138919367769131398\\n\", \"29974778103430162\\n\", \"234685974076220810\\n\", \"633227154929081648\\n\", \"58101264340386100\\n\", \"1718550904886625\\n\", \"124444652733481603\\n\", \"441000740540275741\\n\", \"545168342596476149\\n\", \"138919367769131403\\n\", \"138919367984320752\\n\", \"1\\n\", \"2\\n\", \"4\\n\", \"5\\n\", \"6\\n\"], \"outputs\": [\"-2 0\\n\", \"3 2\\n\", \"5 6\\n\", \"-2 -4\\n\", \"8 8\\n\", \"8 0\\n\", \"8 0\\n\", \"7 -2\\n\", \"154 -492\\n\", \"-33 806\\n\", \"13 -214\\n\", \"-769 562\\n\", \"-418284973 -1154700538\\n\", \"414 1068\\n\", \"458 -20\\n\", \"-797 -222\\n\", \"21108 9228\\n\", \"27596 -17836\\n\", \"1516 17472\\n\", \"27776 16488\\n\", \"22704 -27064\\n\", \"4864 384\\n\", \"2815 18250\\n\", \"8695 33702\\n\", \"-15591 -36122\\n\", \"31404 5384\\n\", \"11555 -17054\\n\", \"0 0\\n\", \"1 2\\n\", \"-1 2\\n\", \"-2 0\\n\", \"-1 -2\\n\", \"1 -2\\n\", \"2 0\\n\", \"3 2\\n\", \"2 4\\n\", \"0 4\\n\", \"-2 4\\n\", \"-3 2\\n\", \"-4 0\\n\", \"-3 -2\\n\", \"-2 -4\\n\", \"0 -4\\n\", \"2 -4\\n\", \"3 -2\\n\", \"4 0\\n\", \"5 2\\n\", \"4 4\\n\", \"3 6\\n\", \"1 6\\n\", \"-1 6\\n\", \"-3 6\\n\", \"-4 4\\n\", \"-5 2\\n\", \"-6 0\\n\", \"-5 -2\\n\", \"-4 -4\\n\", \"-3 -6\\n\", \"-53995102 -586455096\\n\", \"-438664202 297458800\\n\", \"-252460838 -588330600\\n\", \"-423141322 332249584\\n\", \"-164822562 -590200144\\n\", \"439863347 302538706\\n\", \"-378326148 -427475264\\n\", \"200309780 592993400\\n\", \"489196540 209450068\\n\", \"-794841963 -444342246\\n\", \"-623135314 -788838484\\n\", \"-328249537 -1018095738\\n\", \"-719067659 -599137942\\n\", \"-637165825 764022826\\n\", \"559082192 -921270732\\n\", \"7343027 1020257594\\n\", \"-707743686 626107308\\n\", \"797020774 -448632052\\n\", \"604133660 -835484644\\n\", \"-264428508 -626474244\\n\", \"-107643660 215287324\\n\", \"-287379568 574759144\\n\", \"344296355 2\\n\", \"146851396 293702780\\n\", \"31620002 63239992\\n\", \"-422711816 4\\n\", \"-96124517 -192249026\\n\", \"-275860421 551720850\\n\", \"-911192665 10\\n\", \"357225613 714451226\\n\", \"-483988434 8\\n\", \"-421730125 843460258\\n\", \"-306498737 -612997466\\n\", \"-281201952 -562403896\\n\", \"-331941110 4\\n\", \"-691412929 6\\n\", \"-25442382 -50884744\\n\", \"820421960 -4\\n\", \"179893783 -2\\n\", \"-380112498 8\\n\", \"74824856 -149649712\\n\", \"-509121532 4\\n\", \"868593352 0\\n\", \"-114032591 -228065170\\n\", \"498801191 -997602386\\n\", \"178537107 357074206\\n\", \"358273010 -716546028\\n\", \"486083238 -4\\n\", \"-422777531 845555062\\n\", \"45773778 4\\n\", \"407655496 -815310984\\n\", \"382358709 -764717418\\n\", \"534254630 0\\n\", \"-446863220 893726452\\n\", \"-331631832 663263664\\n\", \"306335045 612670094\\n\", \"191103653 382207306\\n\", \"370839563 741679126\\n\", \"-255608161 511216338\\n\", \"-355717526 711435056\\n\", \"240486136 480972264\\n\", \"-430378693 10\\n\", \"99957958 199915904\\n\", \"-279693865 559387730\\n\", \"-459429777 -918859546\\n\", \"-139165682 278331372\\n\", \"23934291 -47868582\\n\", \"203670197 -407340402\\n\", \"-383406115 -766812218\\n\", \"852579099 -2\\n\", \"-430378698 0\\n\", \"-215189349 -430378698\\n\", \"1 2\\n\", \"-1 2\\n\", \"-1 -2\\n\", \"1 -2\\n\", \"2 0\\n\"]}", "source": "primeintellect"}
|
Ayrat is looking for the perfect code. He decided to start his search from an infinite field tiled by hexagons. For convenience the coordinate system is introduced, take a look at the picture to see how the coordinates of hexagon are defined:
[Image] [Image] Ayrat is searching through the field. He started at point (0, 0) and is moving along the spiral (see second picture). Sometimes he forgets where he is now. Help Ayrat determine his location after n moves.
-----Input-----
The only line of the input contains integer n (0 ≤ n ≤ 10^18) — the number of Ayrat's moves.
-----Output-----
Print two integers x and y — current coordinates of Ayrat coordinates.
-----Examples-----
Input
3
Output
-2 0
Input
7
Output
3 2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n0\\n\", \"4\\n1010\\n\", \"20\\n10101010101010\\n\", \"2\\n11\\n\", \"5\\n00101\\n\", \"10\\n100101\\n\", \"4\\n0011\\n\", \"7\\n1100\\n\", \"8\\n01010001\\n\", \"6\\n10\\n\", \"17\\n011100101100110\\n\", \"22\\n1110011010100111\\n\", \"17\\n1110110111010101\\n\", \"11\\n10100000100\\n\", \"20\\n10100001011\\n\", \"16\\n101011\\n\", \"33\\n0001100010001100110000\\n\", \"30\\n111001000100\\n\", \"40\\n1001\\n\", \"31\\n101\\n\", \"18\\n001000011010000\\n\", \"36\\n110110010000\\n\", \"40\\n00000111111100110111000010000010101001\\n\", \"39\\n000000000000000000000000000000000000001\\n\", \"37\\n0101010101010101010101010101010101010\\n\", \"31\\n11011101110000011100\\n\", \"34\\n110000100\\n\", \"35\\n111111100100100\\n\", \"20\\n100010000\\n\", \"21\\n01011101001010001\\n\", \"11\\n00010\\n\", \"16\\n10011000100001\\n\", \"39\\n11101001101111001011110111010010111001\\n\", \"32\\n10101100\\n\", \"13\\n111\\n\", \"4\\n01\\n\", \"8\\n100\\n\", \"9\\n1110\\n\", \"1\\n1\\n\", \"20\\n01100111000\\n\", \"5\\n1\\n\", \"38\\n11111010100111100011\\n\", \"24\\n1101110111000111011\\n\", \"6\\n101111\\n\", \"39\\n1010001010100100001\\n\", \"34\\n1111001001101011101101101\\n\", \"35\\n11100110100\\n\", \"7\\n1111\\n\", \"35\\n010100010101011110110101000\\n\", \"18\\n110101110001\\n\", \"10\\n0110101\\n\", \"38\\n0111110111100000000000100\\n\", \"32\\n101011001\\n\", \"39\\n111011011000100\\n\", \"31\\n00101010000\\n\", \"35\\n100011111010001011100001\\n\", \"39\\n1010000110\\n\", \"34\\n1011010111111001100011110111\\n\", \"37\\n100110110011100100100010110000011\\n\", \"40\\n1010100001001010110011000110001\\n\", \"30\\n11110010111010001010111\\n\", \"36\\n100101110110110111100110010011001\\n\", \"40\\n01011011110\\n\", \"36\\n00001010001000010101111010\\n\", \"40\\n111101001000110000111001110111111110111\\n\", \"37\\n1000101000000000011101011111010011\\n\", \"31\\n0111111101001100\\n\", \"35\\n00010000111011\\n\", \"38\\n11111111111111111111111111111111100000\\n\", \"39\\n000000000000000111111111111111111111111\\n\", \"36\\n000000000011111111111111111111111111\\n\", \"37\\n1111110000000000000000000000000000000\\n\", \"37\\n0000000000000000011111111111111111111\\n\", \"39\\n101010101010101010101010101010101010101\\n\", \"38\\n10101010101010101010101010101010101010\\n\", \"37\\n1010101010101010101010101010101010101\\n\", \"40\\n0101010101010101010101010101010101010101\\n\", \"38\\n00000000000000000000000000000000000000\\n\", \"37\\n0011111111111011011111110111011111111\\n\", \"35\\n00001000110100100101101111110101111\\n\", \"40\\n0000000000100000100000000000000000000000\\n\", \"37\\n0000110000100100011101000100000001010\\n\", \"40\\n1111111111111011111111101111111111111111\\n\", \"38\\n10100000011100111001100101000100001000\\n\", \"40\\n1111110111111111111111011111111111111110\\n\", \"40\\n0000010010000000000001000110000001010100\\n\", \"39\\n100110001010001000000001010000000110100\\n\", \"38\\n01011110100111011\\n\", \"37\\n100110111000011010011010110011101\\n\", \"30\\n000000000110001011111011000\\n\", \"33\\n101110110010101\\n\", \"34\\n1101010100001111111\\n\", \"32\\n01100010110111100111110010\\n\", \"40\\n000010101101010011111101011110010011\\n\", \"32\\n0111010100\\n\", \"31\\n0101100101100000111001\\n\", \"39\\n00111\\n\", \"33\\n00111101\\n\", \"37\\n1010001011111100110101110\\n\", \"37\\n111000011\\n\", \"37\\n011111001111100010001011000001100111\\n\", \"40\\n0000\\n\", \"40\\n1000\\n\", \"40\\n0100\\n\", \"40\\n1100\\n\", \"40\\n0010\\n\", \"40\\n1010\\n\", \"40\\n0110\\n\", \"40\\n1110\\n\", \"40\\n0001\\n\", \"40\\n0101\\n\", \"40\\n1101\\n\", \"40\\n0011\\n\", \"40\\n1011\\n\", \"40\\n0111\\n\", \"40\\n1111\\n\", \"40\\n000\\n\", \"40\\n100\\n\", \"40\\n010\\n\", \"40\\n110\\n\", \"40\\n001\\n\", \"40\\n101\\n\", \"40\\n011\\n\", \"40\\n111\\n\", \"40\\n00\\n\", \"40\\n01\\n\", \"40\\n10\\n\", \"40\\n11\\n\", \"40\\n0\\n\", \"40\\n1\\n\", \"1\\n0\\n\"], \"outputs\": [\"3\", \"2\", \"962\", \"1\", \"5\", \"155\", \"4\", \"56\", \"8\", \"62\", \"68\", \"1408\", \"34\", \"11\", \"10230\", \"15248\", \"67584\", \"7857600\", \"1029761794578\", \"2110188507\", \"144\", \"603021324\", \"160\", \"39\", \"37\", \"63488\", \"1121963008\", \"36696800\", \"40840\", \"336\", \"638\", \"64\", \"78\", \"519167992\", \"5435\", \"14\", \"208\", \"270\", \"1\", \"10230\", \"31\", \"9961415\", \"768\", \"6\", \"40894230\", \"17408\", \"585195800\", \"29\", \"8960\", \"1152\", \"75\", \"311296\", \"263480312\", \"654211584\", \"32331574\", \"71680\", \"20653344998\", \"2176\", \"592\", \"20480\", \"3840\", \"288\", \"21354424310\", \"36864\", \"80\", \"296\", \"1015777\", \"73382400\", \"38\", \"39\", \"36\", \"37\", \"37\", \"39\", \"2\", \"37\", \"2\", \"1\", \"37\", \"35\", \"40\", \"37\", \"40\", \"38\", \"40\", \"40\", \"39\", \"79690256\", \"592\", \"240\", \"8647584\", \"1114095\", \"2048\", \"640\", \"133105408\", \"15872\", \"419341377312\", \"1068677566\", \"151552\", \"9626769261\", \"74\", \"848129718780\", \"1060965767804\", \"1029761794578\", \"1060965767804\", \"1029761794578\", \"1000453489698\", \"1029761794578\", \"1060965767804\", \"1060965767804\", \"1000453489698\", \"1029761794578\", \"1060965767804\", \"1029761794578\", \"1060965767804\", \"848129718780\", \"1060965767805\", \"1099282801648\", \"1093624901051\", \"1099282801648\", \"1099282801648\", \"1093624901051\", \"1099282801648\", \"1060965767805\", \"1099282801649\", \"1099511627774\", \"1099511627774\", \"1099282801649\", \"1099511627775\", \"1099511627775\", \"1\"]}", "source": "primeintellect"}
|
You are given a binary string $s$.
Find the number of distinct cyclical binary strings of length $n$ which contain $s$ as a substring.
The cyclical string $t$ contains $s$ as a substring if there is some cyclical shift of string $t$, such that $s$ is a substring of this cyclical shift of $t$.
For example, the cyclical string "000111" contains substrings "001", "01110" and "10", but doesn't contain "0110" and "10110".
Two cyclical strings are called different if they differ from each other as strings. For example, two different strings, which differ from each other by a cyclical shift, are still considered different cyclical strings.
-----Input-----
The first line contains a single integer $n$ ($1 \le n \le 40$) — the length of the target string $t$.
The next line contains the string $s$ ($1 \le |s| \le n$) — the string which must be a substring of cyclical string $t$. String $s$ contains only characters '0' and '1'.
-----Output-----
Print the only integer — the number of distinct cyclical binary strings $t$, which contain $s$ as a substring.
-----Examples-----
Input
2
0
Output
3
Input
4
1010
Output
2
Input
20
10101010101010
Output
962
-----Note-----
In the first example, there are three cyclical strings, which contain "0" — "00", "01" and "10".
In the second example, there are only two such strings — "1010", "0101".
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n-1 0\\n0 -1\\n1 0\\n1 1\\n\", \"6\\n-1 0\\n0 -1\\n1 0\\n1 1\\n-4 -5\\n-4 -6\\n\", \"10\\n8 6\\n-7 -3\\n9 8\\n7 10\\n-3 -8\\n3 7\\n6 -8\\n-9 8\\n9 2\\n6 7\\n\", \"20\\n-9 8\\n-7 3\\n0 10\\n3 7\\n6 -9\\n6 8\\n7 -6\\n-6 10\\n-10 3\\n-8 -10\\n10 -2\\n1 -8\\n-8 10\\n10 10\\n10 6\\n-5 6\\n5 -8\\n5 -9\\n-9 -1\\n9 2\\n\", \"2\\n351 -4175\\n-328 -657\\n\", \"3\\n620 -1189\\n8101 -2770\\n3347 3473\\n\", \"4\\n-7061 -5800\\n-3471 -9470\\n-7639 2529\\n5657 -6522\\n\", \"5\\n-7519 -3395\\n-32 -257\\n-4827 -1889\\n9545 -7037\\n2767 583\\n\", \"6\\n-5120 -3251\\n8269 -7984\\n841 3396\\n3136 -7551\\n-1280 -3013\\n-3263 -3278\\n\", \"7\\n-2722 6597\\n-3303 200\\n6508 -1021\\n-1107 -1042\\n6875 7616\\n-3047 6749\\n662 -1979\\n\", \"8\\n-36 749\\n5126 943\\n1165 533\\n-1647 -5725\\n5031 6532\\n5956 8447\\n2297 -2284\\n1986 6937\\n\", \"9\\n-391 -1706\\n995 -5756\\n-5013 -154\\n1121 3160\\n-7111 8303\\n-7303 -2414\\n-7791 -935\\n7576 -9361\\n1072 203\\n\", \"10\\n-9920 -5477\\n9691 -3200\\n754 885\\n-1895 1768\\n-941 1588\\n6293 -2631\\n-2288 9129\\n4067 696\\n-6754 9869\\n-5747 701\\n\", \"2\\n1 0\\n-1 0\\n\", \"2\\n0 1\\n0 -1\\n\", \"2\\n2131 -3249\\n-2131 3249\\n\", \"3\\n-5 1\\n-5 -1\\n5 0\\n\", \"3\\n-100 1\\n-100 -1\\n0 100\\n\", \"3\\n1 10\\n10 1\\n10 -1\\n\", \"3\\n3 0\\n0 3\\n1 -3\\n\", \"3\\n1 1\\n-1 0\\n1 -1\\n\", \"3\\n-1 0\\n10 -1\\n1 0\\n\", \"4\\n1 10\\n10 1\\n-2 -2\\n10 -1\\n\", \"3\\n-6 0\\n6 1\\n6 -1\\n\", \"3\\n114 1\\n-514 0\\n114 -1\\n\", \"4\\n-1 0\\n0 -1\\n-1 1\\n1 0\\n\", \"4\\n2 1\\n2 -1\\n-1 1\\n-1 -1\\n\", \"3\\n3 1\\n3 -1\\n0 3\\n\", \"3\\n1 1\\n9000 1\\n9000 -1\\n\", \"3\\n1 0\\n-1 1\\n-1 -1\\n\", \"6\\n1 1\\n-1 -1\\n0 20\\n100 1\\n-100 0\\n100 -1\\n\", \"4\\n1 0\\n0 1\\n-1 0\\n-13 -1\\n\", \"3\\n1 0\\n-1 0\\n1 -1\\n\", \"3\\n100 1\\n-100 0\\n100 -1\\n\", \"3\\n-100 1\\n100 0\\n-100 -1\\n\", \"3\\n1 100\\n0 -100\\n-1 100\\n\", \"11\\n-7945 386\\n7504 -576\\n-6020 -8277\\n930 9737\\n1682 474\\n-8279 1197\\n2790 2607\\n-5514 -9601\\n-3159 5939\\n-1806 4207\\n-9073 -2138\\n\", \"3\\n1 0\\n10000 -1\\n1 1\\n\", \"4\\n-7125 -1643\\n-1235 4071\\n-75 -8717\\n2553 9278\\n\", \"5\\n-6 0\\n6 1\\n6 -1\\n0 6\\n0 -6\\n\", \"4\\n5 5\\n5 -5\\n-555 1\\n-555 -1\\n\", \"4\\n1 1\\n-1 1\\n-1 -1\\n2 -1\\n\", \"4\\n-1 -100\\n1 -100\\n-100 -100\\n100 -100\\n\", \"3\\n1 0\\n1 -1\\n-4 -6\\n\", \"4\\n-1 -100\\n1 -100\\n100 -100\\n-100 -100\\n\", \"4\\n-1 0\\n0 -2\\n-3 3\\n4 0\\n\", \"4\\n-2 0\\n0 -3\\n-5 5\\n4 0\\n\", \"3\\n1 -100\\n0 100\\n-1 -100\\n\", \"5\\n10000 2\\n10000 -1\\n10000 -5\\n10000 -9\\n10000 -13\\n\", \"8\\n-9580 8545\\n-9379 -1139\\n5824 -391\\n-8722 2765\\n-1357 -5547\\n-7700 217\\n9323 -7008\\n957 -8356\\n\", \"4\\n5 5\\n5 -5\\n-500 1\\n-500 -1\\n\", \"3\\n30 1\\n30 -1\\n0 30\\n\", \"4\\n3966 -1107\\n8007 -5457\\n-7753 4945\\n-2209 -4221\\n\", \"4\\n1 9999\\n0 1\\n10000 0\\n10000 -1\\n\", \"3\\n10000 1\\n10000 -1\\n-10000 0\\n\", \"13\\n1 2\\n2 3\\n3 4\\n4 5\\n5 6\\n6 7\\n7 8\\n8 9\\n9 10\\n10 11\\n11 12\\n13 14\\n12 13\\n\", \"4\\n2 1\\n2 -1\\n0 1\\n-1 0\\n\", \"4\\n10 3\\n10 -3\\n-500 1\\n-500 -1\\n\", \"4\\n1 10000\\n-1 1\\n10000 0\\n10000 -1\\n\", \"3\\n0 1\\n1 0\\n1 -1\\n\", \"3\\n1 0\\n0 1\\n1 -1\\n\", \"4\\n1 1\\n-1 1\\n1 -2\\n-1 -2\\n\", \"4\\n0 -1\\n-1 0\\n-1 1\\n1 0\\n\", \"3\\n-100 1\\n-100 -1\\n1 1\\n\", \"3\\n-3 1\\n-3 -1\\n2 -3\\n\", \"3\\n1 -1\\n1 0\\n0 1\\n\", \"5\\n-5 1\\n0 5\\n4 1\\n0 -4\\n-5 -1\\n\", \"4\\n1 10000\\n0 1\\n10000 0\\n9999 -1\\n\", \"4\\n2 3\\n2 -3\\n-3 2\\n-3 -2\\n\", \"3\\n1 -3\\n1 0\\n0 1\\n\", \"3\\n1 0\\n-1 0\\n-1 -1\\n\", \"4\\n-2 1\\n-2 -1\\n1 1\\n1 -1\\n\", \"3\\n1 -1\\n-1 1\\n-1 -2\\n\", \"3\\n1 0\\n-1 -1\\n1 -1\\n\", \"3\\n5 5\\n-5 0\\n5 -5\\n\", \"4\\n1 -2\\n1 0\\n-1 0\\n10 -1\\n\", \"3\\n-1000 1\\n-1000 -1\\n1000 0\\n\", \"6\\n1 1\\n1 -1\\n-1 1\\n-1 -1\\n1 -10000\\n-1 -10000\\n\", \"3\\n1 1\\n-1 0\\n0 -1\\n\", \"4\\n5000 1\\n5000 -1\\n-2 -1\\n2 -1\\n\", \"3\\n1 0\\n-1 1\\n-1 -5\\n\", \"3\\n-5374 1323\\n-4463 -8462\\n6118 -7918\\n\", \"4\\n-6427 -6285\\n-5386 -5267\\n-3898 7239\\n-3905 7252\\n\", \"10\\n-7 -3\\n-2 8\\n9 -9\\n0 1\\n4 5\\n5 3\\n-3 0\\n10 2\\n4 -1\\n2 -10\\n\", \"4\\n9999 1\\n9999 -1\\n-9998 1\\n-10000 -1\\n\", \"4\\n10000 9999\\n9999 9998\\n9998 9997\\n9997 9996\\n\", \"4\\n-6285 -6427\\n-5267 -5386\\n7239 -3898\\n7252 -3905\\n\", \"4\\n-6427 6285\\n-5386 5267\\n3898 -7239\\n3905 -7252\\n\", \"4\\n-6427 -6285\\n-5386 -5267\\n-3898 -7239\\n-3905 -7252\\n\", \"3\\n0 1\\n-1 -1\\n1 -1\\n\", \"4\\n10000 1\\n9998 -1\\n-9999 1\\n-9999 -1\\n\", \"3\\n100 0\\n100 2\\n100 -1\\n\", \"3\\n-1 1\\n-1 -1\\n1 0\\n\", \"4\\n9844 9986\\n181 9967\\n-9812 -9925\\n-194 -9900\\n\", \"4\\n9800 9981\\n61 9899\\n-9926 -9932\\n-149 -9926\\n\", \"4\\n-9901 9900\\n-10000 9899\\n9899 9801\\n9899 9900\\n\", \"4\\n9934 9989\\n199 9949\\n-9917 -9974\\n-197 -9901\\n\", \"3\\n-1 1\\n1 0\\n-1 -1\\n\", \"3\\n1 1\\n-10 -10\\n-10 -9\\n\", \"3\\n1 0\\n10000 -1\\n-1 0\\n\", \"4\\n9999 1\\n9999 -1\\n-10000 1\\n-10000 -1\\n\", \"3\\n-5 1\\n-5 -1\\n1 0\\n\", \"3\\n1 0\\n10000 1\\n-1 0\\n\", \"4\\n-9990 9995\\n9994 -9991\\n-9999 -9992\\n9993 9992\\n\", \"8\\n1 0\\n1 1\\n0 1\\n-1 1\\n-1 0\\n-1 -1\\n0 -1\\n1 -2\\n\", \"3\\n-9930 9932\\n9909 -9909\\n-9932 -9931\\n\", \"4\\n9876 9977\\n127 9938\\n-9820 -9934\\n-120 -9921\\n\", \"3\\n10000 -1\\n-1 0\\n0 -1\\n\", \"4\\n6427 -6285\\n5386 -5267\\n3898 7239\\n3905 7252\\n\", \"4\\n9811 9970\\n155 9994\\n-9826 -9977\\n-159 -9986\\n\", \"4\\n9851 9917\\n74 9921\\n-9855 -9916\\n-77 -9984\\n\", \"4\\n9826 9977\\n159 9986\\n-9811 -9970\\n-155 -9994\\n\", \"4\\n9849 9986\\n148 9980\\n-9800 -9999\\n-116 -9927\\n\", \"4\\n9822 9967\\n111 9905\\n-9943 -9986\\n-163 -9953\\n\", \"4\\n9959 9995\\n113 9940\\n-9965 -9931\\n-148 -9945\\n\", \"4\\n9851 9972\\n153 9983\\n-9866 -9926\\n-183 -9946\\n\", \"4\\n9816 -9979\\n127 -9940\\n-9876 9915\\n-190 9978\\n\", \"4\\n9887 -9917\\n138 -9977\\n-9826 9995\\n-68 9971\\n\", \"4\\n9936 -9965\\n135 -9949\\n-9928 9980\\n-123 9908\\n\", \"4\\n9981 -9985\\n191 -9956\\n-9893 9937\\n-171 9962\\n\", \"4\\n-9811 9970\\n-155 9994\\n9826 -9977\\n159 -9986\\n\", \"4\\n9808 9899\\n179 9966\\n-9870 -9961\\n-179 -9950\\n\", \"4\\n9815 -9936\\n168 -9937\\n-9896 9995\\n-180 9969\\n\", \"4\\n1 1\\n1 -1\\n-100 1\\n-100 -1\\n\", \"4\\n9965 114\\n87 9916\\n-9957 -106\\n-95 -9929\\n\", \"4\\n9895 -9949\\n188 -9978\\n-9810 9935\\n-151 9914\\n\", \"4\\n-9957 106\\n-95 9929\\n9965 -114\\n87 -9916\\n\", \"4\\n-9862 9980\\n-174 9917\\n9845 -9967\\n173 -9980\\n\", \"4\\n9944 9926\\n9927 9935\\n-9961 -9929\\n-9997 -9991\\n\", \"4\\n9917 9909\\n196 9925\\n-9971 -9991\\n-183 -9977\\n\"], \"outputs\": [\"3 4\\n\", \"5 6\\n\", \"1 3\\n\", \"13 16\\n\", \"2 1\\n\", \"1 2\\n\", \"1 2\\n\", \"3 1\\n\", \"1 6\\n\", \"1 6\\n\", \"5 6\\n\", \"3 7\\n\", \"5 9\\n\", \"1 2\\n\", \"1 2\\n\", \"2 1\\n\", \"1 2\\n\", \"1 2\\n\", \"3 2\\n\", \"3 1\\n\", \"3 1\\n\", \"2 3\\n\", \"4 2\\n\", \"3 2\\n\", \"3 1\\n\", \"3 1\\n\", \"2 1\\n\", \"2 1\\n\", \"3 2\\n\", \"2 3\\n\", \"6 4\\n\", \"3 4\\n\", \"3 1\\n\", \"3 1\\n\", \"1 3\\n\", \"1 3\\n\", \"10 9\\n\", \"2 1\\n\", \"4 2\\n\", \"3 2\\n\", \"3 4\\n\", \"4 1\\n\", \"1 2\\n\", \"2 1\\n\", \"1 2\\n\", \"3 1\\n\", \"3 1\\n\", \"3 1\\n\", \"2 1\\n\", \"6 2\\n\", \"3 4\\n\", \"2 1\\n\", \"2 1\\n\", \"4 3\\n\", \"2 1\\n\", \"12 13\\n\", \"2 1\\n\", \"3 4\\n\", \"4 3\\n\", \"3 2\\n\", \"3 1\\n\", \"4 3\\n\", \"3 2\\n\", \"1 2\\n\", \"1 2\\n\", \"1 2\\n\", \"1 5\\n\", \"1 2\\n\", \"3 4\\n\", \"1 2\\n\", \"2 3\\n\", \"1 2\\n\", \"3 1\\n\", \"3 1\\n\", \"3 1\\n\", \"4 2\\n\", \"1 2\\n\", \"6 5\\n\", \"2 3\\n\", \"2 1\\n\", \"3 1\\n\", \"2 3\\n\", \"4 3\\n\", \"4 2\\n\", \"2 1\\n\", \"2 1\\n\", \"3 4\\n\", \"4 3\\n\", \"3 4\\n\", \"2 3\\n\", \"3 4\\n\", \"3 1\\n\", \"1 2\\n\", \"1 2\\n\", \"3 4\\n\", \"3 4\\n\", \"3 4\\n\", \"1 3\\n\", \"3 2\\n\", \"2 1\\n\", \"3 4\\n\", \"1 2\\n\", \"1 2\\n\", \"2 4\\n\", \"7 8\\n\", \"3 2\\n\", \"3 4\\n\", \"3 1\\n\", \"3 4\\n\", \"1 2\\n\", \"1 2\\n\", \"3 4\\n\", \"3 4\\n\", \"1 2\\n\", \"1 2\\n\", \"1 2\\n\", \"2 1\\n\", \"2 1\\n\", \"2 1\\n\", \"2 1\\n\", \"2 1\\n\", \"3 4\\n\", \"2 1\\n\", \"3 4\\n\", \"3 4\\n\", \"2 1\\n\", \"2 1\\n\", \"2 1\\n\", \"3 4\\n\", \"3 4\\n\"]}", "source": "primeintellect"}
|
You are given the set of vectors on the plane, each of them starting at the origin. Your task is to find a pair of vectors with the minimal non-oriented angle between them.
Non-oriented angle is non-negative value, minimal between clockwise and counterclockwise direction angles. Non-oriented angle is always between 0 and π. For example, opposite directions vectors have angle equals to π.
-----Input-----
First line of the input contains a single integer n (2 ≤ n ≤ 100 000) — the number of vectors.
The i-th of the following n lines contains two integers x_{i} and y_{i} (|x|, |y| ≤ 10 000, x^2 + y^2 > 0) — the coordinates of the i-th vector. Vectors are numbered from 1 to n in order of appearing in the input. It is guaranteed that no two vectors in the input share the same direction (but they still can have opposite directions).
-----Output-----
Print two integer numbers a and b (a ≠ b) — a pair of indices of vectors with the minimal non-oriented angle. You can print the numbers in any order. If there are many possible answers, print any.
-----Examples-----
Input
4
-1 0
0 -1
1 0
1 1
Output
3 4
Input
6
-1 0
0 -1
1 0
1 1
-4 -5
-4 -6
Output
6 5
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5 2 1 4 10\\n\", \"5 2 1 4 5\\n\", \"1 1 1 2 1\\n\", \"1000000000000 1000000 999999 1000000 1000000\\n\", \"997167959139 199252 232602 952690 802746\\n\", \"244641009859 748096 689016 889744 927808\\n\", \"483524125987 264237 209883 668942 244358\\n\", \"726702209411 813081 730750 893907 593611\\n\", \"965585325539 329221 187165 817564 718673\\n\", \"213058376259 910770 679622 814124 67926\\n\", \"451941492387 235422 164446 207726 192988\\n\", \"690824608515 751563 656903 733131 509537\\n\", \"934002691939 300407 113318 885765 858791\\n\", \"375802030518 196518 567765 737596 550121\\n\", \"614685146646 521171 24179 943227 899375\\n\", \"857863230070 37311 545046 657309 991732\\n\", \"101041313494 586155 1461 22992 340986\\n\", \"344219396918 167704 522327 941101 690239\\n\", \"583102513046 683844 978741 986255 815301\\n\", \"821985629174 232688 471200 927237 164554\\n\", \"1000000000000 1 1 2 1000000\\n\", \"1049 593 10 36 7\\n\", \"1 100 1 5 10\\n\", \"2 3 1 4 10\\n\", \"10 20 5 15 50\\n\", \"404319 964146 262266 311113 586991\\n\", \"1000000000000 1 1 4 1\\n\", \"1000000000000 1 1 10 1\\n\", \"100 123 1 2 1000\\n\", \"100 111 1 2 123456\\n\", \"100 110 1 2 100000\\n\", \"100 122 1 2 70505\\n\", \"100 120 1 2 300\\n\", \"100 125 1 2 300\\n\", \"100 120 1 2 305\\n\", \"10 12 3 4 5\\n\", \"100 1000 1 10 1000\\n\", \"5 10 1 2 5\\n\", \"11 3 4 5 1\\n\", \"100 121 1 2 666\\n\", \"1 10 1 10 10\\n\", \"100 120 1 2 567\\n\", \"1 2 1 2 1\\n\", \"100 120 1 2 306\\n\", \"1 2 1 2 2\\n\", \"100 120 1 2 307\\n\", \"3 100 1 2 5\\n\", \"11 12 3 4 5\\n\", \"100 120 1 2 399\\n\", \"1 9 54 722 945\\n\", \"100 10 1 10 100\\n\", \"100 120 1 2 98765\\n\", \"100 101 1 2 3\\n\", \"1000000000000 1 1 1000000 1\\n\", \"1 100 2 200 900\\n\", \"100 120 1 2 505\\n\", \"100 120 1 2 3\\n\", \"2 100 1 2 10\\n\", \"5 10 1 2 10\\n\", \"10 100 5 6 1000\\n\", \"100 120 1 2 506\\n\", \"5 10 1 2 500\\n\", \"100 120 1 2 507\\n\", \"100 123 1 2 1006\\n\", \"100 120 1 2 509\\n\", \"100 120 1 2 510\\n\", \"100 120 1 2 512\\n\", \"4 5 3 4 199\\n\", \"100 120 1 2 513\\n\", \"100 123 1 2 1007\\n\", \"5 6 1 2 10000\\n\", \"1 10 10 11 12\\n\", \"100 120 1 2 515\\n\", \"100 120 1 2 516\\n\", \"5 10 1 2000 100000\\n\", \"1000000000000 3 4 5 1\\n\", \"100 5 20 21 50\\n\", \"3 10 3 6 100\\n\", \"41 18467 6334 26500 19169\\n\", \"10 20 1 2 100\\n\", \"4 6 1 2 100\\n\", \"270 66 76 82 27\\n\", \"4492 4 3 13 28\\n\", \"28 32 37 38 180\\n\", \"100 120 1 2 520\\n\", \"5 10 2 3 10\\n\", \"66 21 11 21 97\\n\", \"549 88 81471 83555 35615\\n\", \"100 120 1 2 1\\n\", \"1 999999 1 2 1000000\\n\", \"100 20 1 100 999999\\n\", \"3 9 8 9 4\\n\", \"100 120 1 2 600\\n\", \"6 3 4 9 4\\n\", \"9 1 1 2 1\\n\", \"100 120 1 2 522\\n\", \"501 47 789 798 250\\n\", \"3 6 1 6 9\\n\", \"2 5 8 9 4\\n\", \"9 1 3 8 2\\n\", \"17 42 22 64 14\\n\", \"20 5 82 93 50\\n\", \"5 6 2 3 50\\n\", \"100 120 1 2 525\\n\", \"6 3 7 9 1\\n\", \"1686604166 451776 534914 885584 885904\\n\", \"1 4 4 6 7\\n\", \"5 67 61 68 83\\n\", \"15 5 11 20 15\\n\", \"15 2 9 15 13\\n\", \"17 15 9 17 19\\n\", \"1 17 9 10 6\\n\", \"2 10 10 16 8\\n\", \"18419 54 591 791 797\\n\", \"10 2 1 2 18\\n\", \"100 120 1 2 528\\n\", \"5 17 2 3 8\\n\", \"63793 358 368 369 367\\n\", \"7 2 4 16 19\\n\", \"3 8 3 5 19\\n\", \"17 7 6 9 13\\n\", \"14 3 14 16 5\\n\", \"2000002 1000000 1 3 1000000\\n\", \"2 1 3 8 14\\n\", \"18 6 8 9 7\\n\", \"10 20 10 20 7\\n\", \"12 7 8 18 1\\n\", \"16 1 3 20 2\\n\", \"5 1000 1 4 10\\n\"], \"outputs\": [\"14\\n\", \"13\\n\", \"1\\n\", \"999999999999000000\\n\", \"231947279018960454\\n\", \"168561873458925288\\n\", \"101483941282301425\\n\", \"531038170074636443\\n\", \"180725885278576882\\n\", \"144799175679959130\\n\", \"74320341137487118\\n\", \"453805226165077316\\n\", \"105841987132852686\\n\", \"213368291855090933\\n\", \"14863532910609884\\n\", \"467597724229950776\\n\", \"147680137840428\\n\", \"179796501677835485\\n\", \"570707031914457669\\n\", \"387320209764489810\\n\", \"1999999999999\\n\", \"10497\\n\", \"1\\n\", \"2\\n\", \"50\\n\", \"106039126854\\n\", \"1999999999999\\n\", \"1999999999999\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"30\\n\", \"100\\n\", \"5\\n\", \"47\\n\", \"100\\n\", \"1\\n\", \"100\\n\", \"1\\n\", \"100\\n\", \"1\\n\", \"100\\n\", \"3\\n\", \"33\\n\", \"100\\n\", \"54\\n\", \"910\\n\", \"100\\n\", \"100\\n\", \"1999999999999\\n\", \"2\\n\", \"100\\n\", \"100\\n\", \"2\\n\", \"5\\n\", \"50\\n\", \"100\\n\", \"5\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"100\\n\", \"12\\n\", \"100\\n\", \"100\\n\", \"5\\n\", \"10\\n\", \"100\\n\", \"100\\n\", \"5\\n\", \"4333333333333\\n\", \"2095\\n\", \"9\\n\", \"259694\\n\", \"10\\n\", \"4\\n\", \"20628\\n\", \"44892\\n\", \"1036\\n\", \"100\\n\", \"10\\n\", \"950\\n\", \"44941269\\n\", \"100\\n\", \"1\\n\", \"8020\\n\", \"24\\n\", \"100\\n\", \"28\\n\", \"17\\n\", \"100\\n\", \"397789\\n\", \"3\\n\", \"16\\n\", \"43\\n\", \"374\\n\", \"1790\\n\", \"10\\n\", \"100\\n\", \"43\\n\", \"902191487931356\\n\", \"4\\n\", \"305\\n\", \"195\\n\", \"213\\n\", \"169\\n\", \"9\\n\", \"20\\n\", \"11157406\\n\", \"18\\n\", \"100\\n\", \"10\\n\", \"23539259\\n\", \"78\\n\", \"9\\n\", \"124\\n\", \"215\\n\", \"3000006\\n\", \"11\\n\", \"156\\n\", \"100\\n\", \"97\\n\", \"78\\n\", \"5\\n\"]}", "source": "primeintellect"}
|
Vasiliy has a car and he wants to get from home to the post office. The distance which he needs to pass equals to d kilometers.
Vasiliy's car is not new — it breaks after driven every k kilometers and Vasiliy needs t seconds to repair it. After repairing his car Vasiliy can drive again (but after k kilometers it will break again, and so on). In the beginning of the trip the car is just from repair station.
To drive one kilometer on car Vasiliy spends a seconds, to walk one kilometer on foot he needs b seconds (a < b).
Your task is to find minimal time after which Vasiliy will be able to reach the post office. Consider that in every moment of time Vasiliy can left his car and start to go on foot.
-----Input-----
The first line contains 5 positive integers d, k, a, b, t (1 ≤ d ≤ 10^12; 1 ≤ k, a, b, t ≤ 10^6; a < b), where: d — the distance from home to the post office; k — the distance, which car is able to drive before breaking; a — the time, which Vasiliy spends to drive 1 kilometer on his car; b — the time, which Vasiliy spends to walk 1 kilometer on foot; t — the time, which Vasiliy spends to repair his car.
-----Output-----
Print the minimal time after which Vasiliy will be able to reach the post office.
-----Examples-----
Input
5 2 1 4 10
Output
14
Input
5 2 1 4 5
Output
13
-----Note-----
In the first example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds) and then to walk on foot 3 kilometers (in 12 seconds). So the answer equals to 14 seconds.
In the second example Vasiliy needs to drive the first 2 kilometers on the car (in 2 seconds), then repair his car (in 5 seconds) and drive 2 kilometers more on the car (in 2 seconds). After that he needs to walk on foot 1 kilometer (in 4 seconds). So the answer equals to 13 seconds.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"abrakadabrabrakadabra\\n\", \"acacacaca\\n\", \"abcabc\\n\", \"abababab\\n\", \"tatbt\\n\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\n\", \"r\\n\", \"zaz\\n\", \"zaza\\n\", \"gg\\n\", \"gagaga\\n\", \"hhhh\\n\", \"sssss\\n\", \"nxnxnx\\n\", \"vygvygv\\n\", \"rlrlrlrl\\n\", \"zyzyzyzyz\\n\", \"jjjjjjjjjj\\n\", \"kkhuskkhusk\\n\", \"gzgzgzgzgzgz\\n\", \"vkyxvkyxvkyxv\\n\", \"uuuuuuuuuuuuuu\\n\", \"esxwpesxwpesxwp\\n\", \"qltrajqltrajqltr\\n\", \"alxalxalxalxalxal\\n\", \"ijtojrijtojrijtojr\\n\", \"yhbhamyhbhamyhbhamy\\n\", \"cdrcuccdrcuccdrcuccd\\n\", \"ddoaxeaddoaxeaddoaxea\\n\", \"ejfrayejfrayejfrayejfr\\n\", \"oxciazoxciazoxciazoxcia\\n\", \"zfusxizfusxizfusxizfusxi\\n\", \"kqkqkqkqkqkqkqkqkqkqkqkqk\\n\", \"mrmrmrmrmrmrmrmrmrmrmrmrmr\\n\", \"wnwnwnwnwnwnwnwnwnwnwnwnwnw\\n\", \"zchvhrmcrzchvhrmcrzchvhrmcrz\\n\", \"hngryskhngryskhngryskhngryskh\\n\", \"papapapapapapapapapapapapapapa\\n\", \"qqgedqkewrelydzqqgedqkewrelydzq\\n\", \"mtphoncwmtphoncwmtphoncwmtphoncw\\n\", \"sypfetgsuhifxzsypfetgsuhifxzsypfe\\n\", \"avhiggygrtudeavhiggygrtudeavhiggyg\\n\", \"hphhiattwnahphhiattwnahphhiattwnahp\\n\", \"lpuilpuilpuilpuilpuilpuilpuilpuilpui\\n\", \"bbztwlxbocpbbztwlxbocpbbztwlxbocpbbzt\\n\", \"dvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdvdv\\n\", \"mnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnvkmnv\\n\", \"ugugugugugugugugugugugugugugugugugugugug\\n\", \"nyilpgayabfzpqifnyilpgayabfzpqifnyilpgaya\\n\", \"awxmegcmrkzawxmegcmrkzawxmegcmrkzawxmegcmr\\n\", \"ugduygugduygugduygugduygugduygugduygugduygu\\n\", \"dkwelorlspdltsdkwelorlspdltsdkwelorlspdltsdk\\n\", \"xwyxssvcedrwtpgxwyxssvcedrwtpgxwyxssvcedrwtpg\\n\", \"pwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpwjkpw\\n\", \"vxumrzwwzrzzfuvxumrzwwzrzzfuvxumrzwwzrzzfuvxumr\\n\", \"kkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrhhkkkkrh\\n\", \"lfbpinxnjsfvjsfbshblyvlfbpinxnjsfvjsfbshblyvlfbpi\\n\", \"sqdrmjqbfbmjmqfbcemrjtsqdrmjqbfbmjmqfbcemrjtsqdrmj\\n\", \"eeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiaeeaiae\\n\", \"fhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfhfh\\n\", \"ouygsznbnotbouygsznbnotbouygsznbnotbouygsznbnotbouygs\\n\", \"wtqqagwaguqgaffuqgqtwtwawtqqagwaguqgaffuqgqtwtwawtqqag\\n\", \"sogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpw\\n\", \"vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\\n\", \"hlyjflfbvbtvtqtsjklkfsbqthvshlyjflfbvbtvtqtsjklkfsbqthvsh\\n\", \"mlymfzfkmkfjomlymfzfkmkfjomlymfzfkmkfjomlymfzfkmkfjomlymfz\\n\", \"swylxswylxswylxswylxswylxswylxswylxswylxswylxswylxswylxswyl\\n\", \"cifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcifcif\\n\", \"lvifmwwfkvewsezsufghillvifmwwfkvewsezsufghillvifmwwfkvewsezsu\\n\", \"mhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtg\\n\", \"szfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofck\\n\", \"ceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdq\\n\", \"ojmtpzmojamdjydojmtpzmojamdjydojmtpzmojamdjydojmtpzmojamdjydojmtp\\n\", \"uuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\\n\", \"uhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsv\\n\", \"xcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrv\\n\", \"vuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdj\\n\", \"yukcccrccccyukcccrccccyukcccrccccyukcccrccccyukcccrccccyukcccrccccyukc\\n\", \"rrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainni\\n\", \"xmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdf\\n\", \"xovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtc\\n\", \"howwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfz\\n\", \"ickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifj\\n\", \"zgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzww\\n\", \"ppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyh\\n\", \"itlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmm\\n\", \"yqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqy\\n\", \"ijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfb\\n\", \"jozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjoz\\n\", \"tvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebw\\n\", \"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\\n\", \"zyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpav\\n\", \"irlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlg\\n\", \"hththththththththththththththththththththththththththththththththththththththththththt\\n\", \"wlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladfl\\n\", \"frxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxa\\n\", \"uzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbif\\n\", \"dzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpo\\n\", \"avqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaavqriqniaa\\n\", \"qqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqq\\n\", \"mnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmn\\n\", \"qzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzo\\n\", \"pymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujk\\n\", \"yguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhot\\n\", \"kowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovf\\n\", \"mrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdreps\\n\", \"hgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiy\\n\", \"foxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfo\\n\", \"bkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwd\\n\", \"cftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtgl\\n\", \"twfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmcon\\n\", \"wajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk\\n\", \"pppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppppp\\n\", \"axquczgfdshcpqjcqaxquczgfdshcpqjcqaxquczgfdshcpqjcqaxquczxfdshcpqjcqaxquczgfdshcpqjcqaxquc\\n\", \"vyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvyhsqvvshsqvvyhsqvv\\n\", \"bpqxbraxrcxwdoftbpqxbraxryxwdoftbpqxbraxrcxwdoftbpqxbraxrcxwdoftbpqxbraxrcxwdoftbpqxbraxrcxw\\n\", \"renpsuotrenpsuotrenpsuotrenpsuotrenpsuotrenpsuoprenpsuotrenpsuotrenpsuotrenpsuotrenpsuotrenps\\n\", \"qqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqq\\n\", \"gfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpis\\n\", \"nnsssnnngsbnngnsnnbgbgnbnbnnsssnnngsbnngnsnnbgbgnbnbnnsssnnngsbnngnbnnbgbgnbnbnnsssnnngsbnngnsnn\\n\", \"qimxxxojmmjqmxqfxfqiximjxqimxxxojqmjqmxqfxfqiximjxqimxxxojmmjqmxqfxfqiximjxqimxxxojmmjqmxqfxfqixi\\n\", \"otjwmbgahamrbbhnttmoqahohbhbjxwkbtotjwmbgahamrbbhnttmoqahohbhyjxwkbtotjwmbgahamrbbhnttmoqahohbhbjx\\n\", \"hligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzyjejeskxapshligdsxyzljejeskxap\\n\", \"ooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhabbckrnovooogesrsajsnzroyhadbck\\n\"], \"outputs\": [\"YES\\nabrakadabra\\n\", \"YES\\nacaca\\n\", \"NO\\n\", \"YES\\nababab\\n\", \"NO\\n\", \"YES\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\ngaga\\n\", \"YES\\nhhh\\n\", \"YES\\nsss\\n\", \"YES\\nnxnx\\n\", \"YES\\nvygv\\n\", \"YES\\nrlrlrl\\n\", \"YES\\nzyzyz\\n\", \"YES\\njjjjjj\\n\", \"YES\\nkkhusk\\n\", \"YES\\ngzgzgzgz\\n\", \"YES\\nvkyxvkyxv\\n\", \"YES\\nuuuuuuuu\\n\", \"YES\\nesxwpesxwp\\n\", \"YES\\nqltrajqltr\\n\", \"YES\\nalxalxalxal\\n\", \"YES\\nijtojrijtojr\\n\", \"YES\\nyhbhamyhbhamy\\n\", \"YES\\ncdrcuccdrcuccd\\n\", \"YES\\nddoaxeaddoaxea\\n\", \"YES\\nejfrayejfrayejfr\\n\", \"YES\\noxciazoxciazoxcia\\n\", \"YES\\nzfusxizfusxizfusxi\\n\", \"YES\\nkqkqkqkqkqkqk\\n\", \"YES\\nmrmrmrmrmrmrmr\\n\", \"YES\\nwnwnwnwnwnwnwnw\\n\", \"YES\\nzchvhrmcrzchvhrmcrz\\n\", \"YES\\nhngryskhngryskh\\n\", \"YES\\npapapapapapapapa\\n\", \"YES\\nqqgedqkewrelydzq\\n\", \"YES\\nmtphoncwmtphoncwmtphoncw\\n\", \"YES\\nsypfetgsuhifxzsypfe\\n\", \"YES\\navhiggygrtudeavhiggyg\\n\", \"YES\\nhphhiattwnahphhiattwnahp\\n\", \"YES\\nlpuilpuilpuilpuilpui\\n\", \"YES\\nbbztwlxbocpbbztwlxbocpbbzt\\n\", \"YES\\ndvdvdvdvdvdvdvdvdvdv\\n\", \"YES\\nmnvkmnvkmnvkmnvkmnvkmnv\\n\", \"YES\\nugugugugugugugugugugug\\n\", \"YES\\nnyilpgayabfzpqifnyilpgaya\\n\", \"YES\\nawxmegcmrkzawxmegcmrkzawxmegcmr\\n\", \"YES\\nugduygugduygugduygugduygu\\n\", \"YES\\ndkwelorlspdltsdkwelorlspdltsdk\\n\", \"YES\\nxwyxssvcedrwtpgxwyxssvcedrwtpg\\n\", \"YES\\npwjkpwjkpwjkpwjkpwjkpwjkpw\\n\", \"YES\\nvxumrzwwzrzzfuvxumrzwwzrzzfuvxumr\\n\", \"YES\\nkkkkrhhkkkkrhhkkkkrhhkkkkrh\\n\", \"YES\\nlfbpinxnjsfvjsfbshblyvlfbpi\\n\", \"YES\\nsqdrmjqbfbmjmqfbcemrjtsqdrmj\\n\", \"YES\\neeaiaeeaiaeeaiaeeaiaeeaiae\\n\", \"YES\\nfhfhfhfhfhfhfhfhfhfhfhfhfhfh\\n\", \"YES\\nouygsznbnotbouygsznbnotbouygs\\n\", \"YES\\nwtqqagwaguqgaffuqgqtwtwawtqqag\\n\", \"YES\\nsogoiyexpwmpaixsogoiyexpwmpaixsogoiyexpw\\n\", \"YES\\nvvvvvvvvvvvvvvvvvvvvvvvvvvvvv\\n\", \"YES\\nhlyjflfbvbtvtqtsjklkfsbqthvsh\\n\", \"YES\\nmlymfzfkmkfjomlymfzfkmkfjomlymfz\\n\", \"YES\\nswylxswylxswylxswylxswylxswylxswyl\\n\", \"YES\\ncifcifcifcifcifcifcifcifcifcifcif\\n\", \"YES\\nlvifmwwfkvewsezsufghillvifmwwfkvewsezsu\\n\", \"YES\\nmhgbtgdmhgbtgdmhgbtgdmhgbtgdmhgbtg\\n\", \"YES\\nszfsdufuduiofckbszfsdufuduiofckbszfsdufuduiofck\\n\", \"YES\\nceypvrszdqljkzezlcceypvrszdqljkzezlcceypvrszdq\\n\", \"YES\\nojmtpzmojamdjydojmtpzmojamdjydojmtp\\n\", \"YES\\nuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuuu\\n\", \"YES\\nuhkuqbhrhlqjhgbshsvtqouquhkuqbhrhlqjhgbshsv\\n\", \"YES\\nxcgtgdpomjvngwdtrvrttldigxcgtgdpomjvngwdtrv\\n\", \"YES\\nvuuovdvktdjvuaafiguzdrrtratjyvuuovdvktdj\\n\", \"YES\\nyukcccrccccyukcccrccccyukcccrccccyukc\\n\", \"YES\\nrrriiiiaaainnrrrainniiarirrriiiiaaainnrrrainni\\n\", \"YES\\nxmxxumdfubrcsbccxmxxumdfubrcsbccxmxxumdf\\n\", \"YES\\nxovouvxuxtcvvovpxnhruswcphrstctxovouvxuxtc\\n\", \"YES\\nhowwwscoebckiatfzarhowwwscoebckiatfzarhowwwscoebckiatfz\\n\", \"YES\\nickpakvkbaljifqdifjfcdxpashuickpakvkbaljifqdifj\\n\", \"YES\\nzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzwwwhzgzgzwgwggzggwzzww\\n\", \"YES\\nppdbpyheotppdbpyheotppdbpyheotppdbpyheotppdbpyh\\n\", \"YES\\nitlmmmqfkflfamdaqekrjlocitlmmmqfkflfamdaqekrjlocitlmmm\\n\", \"YES\\nyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqyqy\\n\", \"YES\\nijdghvidfbqqpajplojvtlppdiftzvhuqatijdghvidfb\\n\", \"YES\\njozbicochmmtmmhogkgrfutknpjozbicochmmtmmhogkgrfutknpjoz\\n\", \"YES\\ntvsyxhopzmbebwoimyxhjbjuyszplhhggftvsyxhopzmbebw\\n\", \"YES\\nkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\\n\", \"YES\\nzyqxlypnlpavjxuydvxcnnzszyqxlypnlpavjxuydvxcnnzszyqxlypnlpav\\n\", \"YES\\nirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlgpgsejirlg\\n\", \"YES\\nhthththththththththththththththththththththt\\n\", \"YES\\nwlladflfanfmlljbbldamdjabtfbnftawbfnllfjwlladfl\\n\", \"YES\\nfrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxafrxa\\n\", \"YES\\nuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbifcuzdcgbif\\n\", \"YES\\ndzpttoozpoqsjywqnzokdzpttoozpoqsjywqnzokdzpttoozpo\\n\", \"YES\\navqriqniaavqriqniaavqriqniaavqriqniaavqriqniaa\\n\", \"YES\\nqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqqpppqqpqqqqqpqqpqpqqqpqpqqqqqqq\\n\", \"YES\\nmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmnmxvxqrfnjxnmn\\n\", \"YES\\nqzcgreoroxoxqzwvvoeiggriwrzotcxizqzcgreoroxoxqzwvvoeiggriwrzo\\n\", \"YES\\npymvkuoucpujkekgnjrvnkrvodtszsbkmoabtlgdbpymvkuoucpujk\\n\", \"YES\\nyguclskcmiuobsgckhotgkzqykebvttqaqmtzsyguclskcmiuobsgckhot\\n\", \"YES\\nkowiovfyffitkipvmccesjhatgyqaekowiovfyffitkipvmccesjhatgyqaekowiovf\\n\", \"YES\\nmrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdrepsprwlwwjewemrjdreps\\n\", \"YES\\nhgxenqnawiyiirinhraywlhgxenqnawiyiirinhraywlhgxenqnawiy\\n\", \"YES\\nfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfoxywhckxuiipgfo\\n\", \"YES\\nbkwdegdnxtnvtczozttjitzmfienbtxhoipldptluxbtvhmybkwd\\n\", \"YES\\ncftorbxtglokyoxsemzlysptutvldtlzqbhawyecivljlcftorbxtgl\\n\", \"YES\\ntwfflboprkkjobbgoubmybfkbmmconrjhsktwfflboprkkjobbgoubmybfkbmmcon\\n\", \"YES\\nwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmkwajaubjjlsvvatkrwphykszmk\\n\", \"YES\\nppppppppppppppppppppppppppppppppppppppppppppppppppp\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\nqqeemdmddqddkmudbmaabaedquqmqqdqqqeemdmddqddkmudbmaabaedquqmqq\\n\", \"YES\\ngfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpiskgfpis\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\"]}", "source": "primeintellect"}
|
В Берляндском государственном университете локальная сеть между серверами не всегда работает без ошибок. При передаче двух одинаковых сообщений подряд возможна ошибка, в результате которой эти два сообщения сливаются в одно. При таком слиянии конец первого сообщения совмещается с началом второго. Конечно, совмещение может происходить только по одинаковым символам. Длина совмещения должна быть положительным числом, меньшим длины текста сообщения.
Например, при передаче двух сообщений «abrakadabra» подряд возможно, что оно будет передано с ошибкой описанного вида, и тогда будет получено сообщение вида «abrakadabrabrakadabra» или «abrakadabrakadabra» (в первом случае совмещение произошло по одному символу, а во втором — по четырем).
По полученному сообщению t определите, возможно ли, что это результат ошибки описанного вида работы локальной сети, и если возможно, определите возможное значение s.
Не следует считать ошибкой ситуацию полного наложения друга на друга двух сообщений. К примеру, если получено сообщение «abcd», следует считать, что в нём ошибки нет. Аналогично, простое дописывание одного сообщения вслед за другим не является признаком ошибки. Например, если получено сообщение «abcabc», следует считать, что в нём ошибки нет.
-----Входные данные-----
В единственной строке выходных данных следует непустая строка t, состоящая из строчных букв латинского алфавита. Длина строки t не превосходит 100 символов.
-----Выходные данные-----
Если сообщение t не может содержать ошибки, выведите «NO» (без кавычек) в единственную строку выходных данных.
В противном случае в первой строке выведите «YES» (без кавычек), а в следующей строке выведите строку s — возможное сообщение, которое могло привести к ошибке. Если возможных ответов несколько, разрешается вывести любой из них.
-----Примеры-----
Входные данные
abrakadabrabrakadabra
Выходные данные
YES
abrakadabra
Входные данные
acacacaca
Выходные данные
YES
acaca
Входные данные
abcabc
Выходные данные
NO
Входные данные
abababab
Выходные данные
YES
ababab
Входные данные
tatbt
Выходные данные
NO
-----Примечание-----
Во втором примере подходящим ответом также является строка acacaca.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"8\\nabacabac\\n1 1 1 1 1 1 1 1\\n\", \"8\\nabaccaba\\n1 2 3 4 5 6 7 8\\n\", \"8\\nabacabca\\n1 2 3 4 4 3 2 1\\n\", \"100\\nbaaacbccbccaccaccaaabcabcabccacaabcbccbccabbabcbcbbaacacbacacacaacccbcbbbbacccababcbacacbacababcacbc\\n28 28 36 36 9 53 7 54 66 73 63 30 55 53 54 74 60 2 34 36 72 56 13 63 99 4 44 54 29 75 9 68 80 49 74 94 42 22 43 4 41 88 87 44 85 76 20 5 5 36 50 90 78 63 84 93 47 33 64 60 11 67 70 7 14 45 48 88 12 95 65 53 37 15 49 50 47 57 15 84 96 18 63 23 93 14 85 26 55 58 8 49 54 94 3 10 61 24 68 1\\n\", \"100\\ncccccaacccbaaababacbbacbbbcbccaccaccbcccbbaabababcacbccaacacaababacbcbcccabcacbccccbccaaabcabcaaabcc\\n95 91 11 97 2 16 42 33 22 1 26 52 47 45 96 96 53 99 38 61 27 53 6 13 12 77 76 19 69 60 88 85 61 29 81 65 52 47 23 12 93 76 46 30 71 11 96 3 80 79 71 93 17 57 57 20 71 75 58 41 34 99 54 27 88 12 37 37 3 73 72 25 28 35 35 55 37 56 61 1 11 59 89 52 81 13 13 53 7 83 90 61 36 58 77 4 41 33 13 84\\n\", \"100\\ncabaabbacacabbbababcbcbccaccbcaabcbbcabbacccbacbaabbaccabcaccbaacacaaabbaababbcababcbcbacbcacbbccbaa\\n68 65 4 76 17 74 33 92 47 72 10 17 20 4 20 57 99 47 7 17 32 46 8 47 89 75 33 27 64 74 36 90 62 77 23 62 35 68 82 80 55 29 53 41 26 81 75 90 65 97 90 15 43 55 31 48 69 86 43 15 23 21 1 23 93 53 93 88 47 22 13 61 69 98 54 69 87 7 23 70 29 40 50 41 85 79 14 44 44 46 27 59 65 89 81 52 39 53 45 7\\n\", \"100\\nbaaabbccbadabbaccdbbdacacaacbcccbbbacbabbaacabbbbaddaacbbdcdccaaddddbbadcddbbbabdccbcadbbdcaccabdbad\\n76 26 64 3 47 52 77 89 81 23 38 18 27 57 17 96 72 29 84 39 89 80 54 90 66 28 19 45 35 16 44 96 55 39 73 3 5 8 57 44 38 27 5 22 9 67 37 14 91 6 94 13 82 48 87 3 30 17 32 99 40 38 65 45 58 48 44 86 69 45 63 68 46 24 43 75 73 1 8 85 56 87 34 74 38 73 38 25 65 38 6 6 75 96 25 98 30 21 97 74\\n\", \"100\\nbaccccbcbdcddcddbbdcacaddabdbaaaacbadabdbcbbababddadbacddabdcddbcaadadbcbdcdbabbbcbbbadadcaacdbaaacd\\n49 100 65 90 73 14 68 48 5 94 21 91 99 7 45 57 13 82 48 95 91 66 56 28 46 22 87 56 29 34 88 2 60 74 23 7 92 25 16 13 4 76 16 29 67 33 16 13 76 24 8 35 13 45 61 35 28 24 16 69 29 48 13 33 58 89 88 37 14 90 3 3 86 83 62 80 11 48 66 63 78 68 83 67 42 51 34 12 6 100 44 7 100 36 32 45 28 37 29 85\\n\", \"10\\ncaabacddad\\n86 47 85 37 79 63 55 19 62 27\\n\", \"100\\nadebebcdacabaadcbcdebcccdaadaeeedecdbcbdeddcbcaeedbecaeeabaabbdccaebdebabbabdcebbbdaabdbddcadaddadad\\n52 62 28 18 100 84 16 53 43 52 49 92 10 64 50 95 90 52 21 14 60 3 94 63 31 70 74 62 93 75 100 96 58 36 76 40 62 74 91 77 92 78 65 11 50 18 79 29 10 25 4 24 44 39 4 91 81 63 97 65 50 65 77 51 19 87 43 31 40 8 57 14 67 17 47 94 96 46 59 69 96 11 75 100 87 36 70 1 22 92 31 50 2 35 68 95 19 96 89 52\\n\", \"100\\nebccbbebeeedaedeeaaeebcaabbebaceaaaccbddcbbaecddaadacbedbbbeeeddeaabbedecdaceaeeddeebdcdbdaeeacddabd\\n21 36 34 1 18 50 15 12 68 24 37 57 83 18 78 60 36 13 90 69 53 85 4 96 7 72 34 86 91 90 45 2 58 83 26 36 53 95 46 42 50 26 72 21 9 89 53 20 87 51 23 58 70 32 83 19 83 70 85 35 39 83 32 43 27 25 99 90 84 58 98 45 8 80 59 100 39 93 9 47 14 92 32 85 95 14 71 84 60 54 64 51 31 75 80 43 25 13 13 67\\n\", \"10\\nbbddcaabcb\\n26 91 79 74 6 80 78 77 80 72\\n\", \"100\\nbcddacdbcffebdbfbadbfbabfcfddddffbdfbdddcfecadafdeabfbcfbbfeeaecaaafefeeffaadbbbcfbebdabeefbeffaeadc\\n24 97 93 28 45 24 55 9 5 70 65 55 98 67 83 95 13 83 67 88 22 18 46 39 84 21 21 92 62 39 57 8 60 41 79 81 20 47 29 5 41 25 16 7 91 70 16 45 21 48 27 44 1 26 30 75 36 9 62 32 56 92 84 61 84 27 54 84 7 72 44 48 89 5 47 6 20 92 6 53 41 31 20 14 45 8 99 69 80 46 48 94 41 78 16 92 8 76 73 38\\n\", \"100\\ndaebebaffffcbbacbccabeadaeeecffacdeffceafbdcdffbfbeabdafceaeaddcbeddbffcabaabacbdbfecfefcffadccabefa\\n97 63 94 11 71 90 50 68 22 45 52 19 62 26 7 56 55 36 27 55 28 4 44 73 60 15 85 4 49 54 9 14 60 84 30 78 10 64 80 70 7 77 27 10 46 40 95 32 6 78 41 78 28 23 13 7 30 16 50 2 45 14 40 57 84 69 6 36 51 21 88 92 29 76 67 20 71 34 64 31 63 20 77 3 53 78 3 60 17 17 85 91 63 17 19 40 17 96 100 53\\n\", \"10\\nafbabeffdb\\n77 35 69 7 17 1 92 32 98 20\\n\", \"100\\ndddfagdfaabgfebfccgfddbdfdfbcabbdbffeadbgefffcgadgffddefecacbacgaddeacebgagageefdfefebgbfbgeggdggaae\\n97 25 58 38 97 60 94 65 68 4 80 25 81 74 8 94 32 18 8 66 85 37 94 8 50 64 71 22 20 99 13 16 54 42 79 18 73 4 64 38 87 75 75 96 36 22 61 52 32 75 42 63 63 17 56 63 91 55 35 94 66 18 4 79 49 67 61 33 78 43 38 90 7 2 56 26 48 29 53 33 81 63 68 40 94 72 27 40 49 9 68 46 72 21 64 90 97 59 52 16\\n\", \"100\\ngccacggcaecdebedbfeadceadaddagedeefdaecaggcdabacfegbdbacfefgbedebddbedgdcaadagagccgdgbfgabedbggdfcba\\n78 99 63 21 16 22 85 32 84 75 60 86 42 37 40 59 73 66 69 29 90 23 91 38 26 61 32 29 14 13 66 21 62 94 29 19 68 25 19 7 53 24 82 98 95 92 40 55 17 1 64 89 89 14 30 91 81 58 23 60 55 41 51 63 49 4 10 85 22 89 79 34 47 65 71 39 95 75 7 15 3 44 26 25 2 46 28 28 87 71 6 36 98 64 71 38 6 80 88 35\\n\", \"10\\nccgccbdged\\n17 78 59 44 44 10 15 90 20 65\\n\", \"100\\nadbgaebehfhffghahfgbgbghedgecaaafachecfgegbcebhbbffgdggbgghfdbebecaadfaaddbhgbgbfadddheedehgfhfcfagb\\n85 61 23 48 50 100 33 29 26 22 87 95 61 81 40 94 46 37 54 44 47 61 42 85 7 10 18 40 86 59 70 27 52 52 82 63 30 74 2 67 36 34 27 92 77 74 99 71 43 2 56 87 32 8 86 46 46 93 1 53 76 53 7 85 18 99 60 83 45 7 29 28 28 98 64 41 76 74 3 17 29 87 5 62 56 31 52 12 7 63 89 82 8 68 3 87 90 43 36 98\\n\", \"100\\nahddfeaacehehhcfcdaccddgfddbdgchabhhgfdfbagabfdfdhhcbcgefdgbcddhdhbdcdfddcffgadfabgdchacbhbdeecacdeb\\n54 39 24 35 65 66 32 88 43 97 71 64 33 44 64 54 88 97 10 3 48 42 39 14 79 4 78 59 76 73 22 33 61 91 33 60 21 95 53 35 98 75 38 91 36 44 81 62 24 28 75 9 50 1 56 78 36 4 89 27 73 68 63 73 18 44 13 38 93 52 69 76 65 57 84 51 23 21 54 99 47 68 62 51 60 9 60 100 44 26 26 84 29 7 18 35 95 63 72 21\\n\", \"10\\ncbhhcbehge\\n56 18 50 82 55 27 33 44 38 10\\n\", \"100\\necffafibcdedacabcidegiecgfdabcbeedidebighfciafcebfddecdeigcbebhcdabdhadcbciadhhgigcgegabbhagcaeadgca\\n57 96 87 63 95 37 72 81 85 51 7 61 40 93 73 93 65 67 87 18 17 80 90 53 68 53 65 69 40 23 26 39 55 53 86 96 88 35 28 91 89 81 86 81 15 25 44 82 58 29 75 98 90 99 7 34 93 39 74 19 82 80 23 95 87 35 71 36 7 75 23 74 46 83 68 53 8 19 50 1 66 7 54 88 5 3 88 88 65 22 10 26 43 7 55 84 79 22 28 84\\n\", \"100\\ndbbhgbhgicfdhcehfffhaiebcdicdggbecidcbecdihbdbeiaidiggihbfffecgddadgdgheadachaigccbdbbdbfeichehfihci\\n31 74 93 49 18 3 71 44 5 23 82 26 12 43 97 66 7 24 56 82 15 65 87 83 44 51 33 81 42 37 78 41 63 96 28 1 78 52 87 60 56 25 93 79 73 95 23 73 39 55 97 28 16 92 82 62 95 50 62 89 79 2 78 91 87 84 24 87 60 24 64 6 86 46 80 67 51 66 9 75 88 96 11 73 9 81 85 68 2 80 47 28 68 50 58 28 84 39 56 3\\n\", \"10\\ndgfcifihdc\\n100 70 48 19 78 45 56 98 64 63\\n\", \"100\\ncaeebfcicgjdfaagafcbbegghaigchaddifajfaadgedcgfdijajchhebbgccgiegaheeccejdhedajfadfaieegbigbajfejibj\\n8 6 57 3 53 18 83 23 87 53 67 32 93 27 67 49 91 47 52 89 9 71 37 15 52 40 45 2 23 31 92 41 55 94 41 71 67 25 47 92 65 74 83 19 35 17 12 98 11 44 36 69 8 8 4 68 19 67 84 96 30 68 68 42 92 22 60 64 11 13 49 25 41 10 33 25 80 16 92 27 30 30 90 54 57 42 45 13 56 33 9 71 44 85 51 83 20 62 77 65\\n\", \"100\\ngeacehcgiidjfbdddeecbggfijfdehcbceiajghhehjiiefdcechfijccebhfchcbhgedgfgehcidhcbejbhbgicbdadbeejhfhd\\n81 81 58 98 80 79 74 86 12 28 51 1 61 85 91 22 32 99 17 57 7 56 35 45 24 34 5 21 17 54 44 46 67 37 88 72 62 46 6 61 27 14 90 22 94 87 95 89 96 66 54 87 30 2 79 4 9 82 72 66 20 86 23 30 5 67 12 23 59 62 97 69 81 69 53 31 22 54 50 5 52 19 47 47 61 20 46 4 93 96 54 76 66 24 62 35 21 82 1 80\\n\", \"10\\naigfbdghac\\n30 50 75 93 67 6 61 60 56 56\\n\", \"100\\nkjgfjaiegkcheceibggeffagekkjgfbhgegbdchidacfhjkihakciejkgheihbfiiigkfcdedjkdafagbgfiebbkeajeejeijhec\\n84 42 18 17 10 58 22 83 46 75 83 99 72 30 100 61 10 77 90 75 76 90 85 91 5 83 91 31 85 95 56 48 53 99 45 12 25 86 81 21 10 24 43 7 85 69 58 9 30 71 54 89 62 95 34 59 73 17 57 63 40 3 76 48 61 62 67 13 78 80 43 71 58 99 42 33 4 61 39 15 78 58 38 80 15 14 82 81 17 88 26 23 79 24 2 80 9 37 60 47\\n\", \"100\\nbdbjgdgabbbkcebhjeikhdjbckabejahidcckjjeakbcfkedifddjeigddfhdjdkdjjkckhehbbiahejfickdedebkegjkkkjiga\\n53 16 19 4 25 16 21 38 70 46 58 63 41 92 24 26 51 30 62 31 81 71 83 21 81 80 56 43 79 17 100 54 61 42 91 13 15 4 44 90 76 65 50 18 39 39 36 100 7 93 77 11 92 96 5 88 68 28 45 29 26 13 31 48 62 11 20 72 26 30 92 11 99 58 61 47 54 100 93 89 96 39 95 69 23 92 78 72 54 50 71 20 1 71 2 32 10 57 92 62\\n\", \"10\\nfabkafeicj\\n70 98 70 22 86 23 88 15 74 100\\n\", \"100\\nacaliggfdidgfcdjdlglklgiigddbblcdhcagclfjlbfacgfalajccdaaeaigaghkdacjiecljchhiglbhfbhabdabkgabbcgfbi\\n56 78 86 23 63 90 61 35 8 5 90 65 60 41 29 60 20 100 35 49 38 9 25 60 70 29 42 57 46 55 13 64 55 100 48 46 78 56 20 53 56 71 94 100 22 20 99 17 41 90 77 1 23 94 56 39 32 63 22 29 46 30 95 66 30 1 74 62 41 48 34 10 76 92 50 53 36 98 77 92 14 82 83 2 64 77 6 61 83 42 50 67 15 71 50 78 2 21 44 25\\n\", \"100\\nagcaklffhchjdiggfjeigjadbkeibibacadiebihgccljkgbkgffdhlhhfhijjjbjfikikjfdjcfldlhelefjiekkeidlglfcbia\\n29 44 87 18 78 56 52 6 32 76 78 30 24 100 57 21 74 61 96 5 43 98 31 90 46 23 2 69 41 77 57 66 63 44 86 42 73 77 79 22 22 20 1 2 81 91 81 16 26 20 95 30 53 83 30 75 22 74 10 95 36 52 42 58 31 47 19 25 97 93 82 53 16 55 62 66 78 45 40 74 36 63 40 91 72 55 11 44 8 5 95 69 32 2 53 30 99 37 76 48\\n\", \"10\\nihhcegchje\\n9 45 68 63 14 32 14 73 92 41\\n\", \"100\\nealhkjmlhihghiahefljahkihjkfckfccblijhddimjmciebmeecbfdjalmbicddfkmmhmljgkgjamilmadkgckkcidlgmkllcam\\n33 5 47 38 8 26 100 3 70 35 10 39 39 48 53 60 43 31 81 27 100 28 73 37 24 72 89 75 4 15 69 72 57 10 44 87 35 25 54 82 9 22 53 88 63 68 44 40 52 17 88 20 92 77 73 31 79 1 87 87 52 56 99 76 91 37 81 15 8 12 25 52 98 80 46 68 60 40 32 76 63 6 28 28 22 41 35 28 40 1 67 11 42 13 89 79 91 4 28 15\\n\", \"100\\nkeccabkciaeigflgffeaefmicmhkihdkklhldmcijmjjkjfiibdmdeekgjfcgmalekaglhedlfbihgbagegbbmkmhcbmfhdkhacf\\n10 79 48 29 30 88 91 58 95 6 85 100 12 11 81 24 93 84 37 79 2 21 71 67 100 74 57 98 98 41 13 74 58 49 90 87 30 42 17 51 79 70 60 99 22 42 15 27 38 43 6 50 19 70 60 55 77 12 75 53 42 79 54 60 96 75 30 75 56 61 77 87 46 51 70 78 2 94 87 58 85 95 89 17 30 15 39 20 77 59 12 5 71 45 1 27 88 25 60 26\\n\", \"10\\njljdgdlklc\\n53 89 58 93 25 49 29 27 14 94\\n\", \"100\\njhjmkfbgehjcfldijgijlckjdkickikjlfmdaflbbblhcecjcmjggdhmjenbeikigfehaemnmlahmehbbemafjfalgffdfimjbme\\n17 41 12 56 61 66 39 55 29 52 25 5 23 59 86 59 62 62 22 1 71 55 21 5 85 22 44 4 70 79 26 84 56 7 43 28 93 82 92 15 55 72 1 81 4 20 78 47 71 44 10 40 50 64 3 11 34 47 60 54 62 83 14 86 60 77 84 64 79 79 19 94 19 77 55 80 84 89 79 60 3 38 65 50 71 9 63 96 98 51 91 55 81 56 41 85 79 88 12 93\\n\", \"100\\nfbfjleaghhnibkgfagaaecfgegndidgliffdfbdkajcflajfalhmnmadgdkflbbdimnengldfcbaggahbkgcefdfhicmacbdjkgh\\n90 15 17 39 71 32 30 18 53 28 1 70 91 10 10 20 11 18 79 57 68 41 19 35 65 12 4 16 68 1 70 89 56 46 93 29 83 4 43 75 25 21 20 87 55 94 56 42 49 62 25 61 76 61 82 47 32 62 49 20 52 6 69 78 61 18 37 28 27 29 68 30 68 36 74 94 34 35 37 34 21 15 26 39 79 87 68 88 35 26 33 53 99 92 40 32 77 8 44 4\\n\", \"10\\nkhkenaljlf\\n88 29 49 34 52 70 51 85 28 39\\n\", \"100\\nbfhbfaokkkildhjgliejmbkokladgdleddhbmbaifooanfbflcikgmjjlkdieifbelhihdblfakhkaidnhdekfdblbelhcnlobcg\\n89 76 77 66 2 2 74 15 91 86 33 68 2 70 19 58 76 97 56 75 33 74 73 82 42 69 90 34 28 38 82 91 58 16 46 69 54 52 26 47 4 19 64 69 49 72 23 59 78 71 25 59 11 55 25 95 89 93 26 16 72 10 26 100 22 17 87 13 45 47 10 36 41 73 63 4 16 34 22 44 40 62 14 68 32 72 96 76 59 13 8 100 12 95 88 78 68 63 100 83\\n\", \"100\\noogjlibiflmemkgkbnlhohemmfmdkiifofnihgndadjececkamlmlcfcmagccdjiolbmgcilkmngmhgakdahoekhkehnahhkadlc\\n63 51 78 49 24 64 73 78 16 57 16 36 74 21 43 23 26 45 24 35 39 60 67 12 18 63 47 42 26 61 34 97 58 59 97 66 41 73 81 12 70 72 71 80 96 46 1 49 68 89 39 81 38 56 4 27 87 8 14 86 62 32 73 88 30 54 36 77 93 92 58 72 89 32 79 13 58 73 80 18 62 47 75 57 37 50 97 60 96 76 53 97 42 34 92 26 66 84 35 94\\n\", \"10\\noggdlibbii\\n32 72 39 67 63 88 66 48 50 83\\n\", \"100\\nlnfilfbkmbpdfpkpanpdmbocnbnjllfepodgjpigngkmaobiaikmkiinchogopgelcnlheepfmbmmhmaifclikggooljcolcpjdf\\n66 12 41 76 54 42 13 75 53 4 44 34 82 70 44 62 95 15 97 49 96 97 21 55 7 12 33 52 97 2 34 95 56 13 50 2 11 21 64 76 58 70 20 66 91 23 64 78 93 98 40 71 73 46 55 82 44 39 95 75 78 45 41 10 91 57 98 63 16 15 4 82 54 58 71 19 40 79 77 28 88 95 58 90 82 36 33 48 17 68 33 44 39 34 28 75 57 47 87 61\\n\", \"100\\nljpobnapiihcpannkdbdbcdcobkgdjpdchapdkoebipdnkmmkleipnipiencginckiggocjkmmmleojllfndhckmejffcdibembg\\n39 86 46 63 69 8 8 38 78 79 28 7 54 32 76 19 45 68 66 9 1 83 15 85 84 5 97 72 84 24 91 1 60 65 96 7 94 42 16 45 20 18 31 68 45 97 43 69 79 16 62 1 99 43 29 10 46 46 83 41 68 59 92 98 91 94 43 22 64 64 53 14 3 21 83 29 90 22 27 2 6 67 15 79 86 14 29 27 50 30 74 45 69 81 35 23 55 67 19 72\\n\", \"10\\nmmojgklhgb\\n72 16 29 8 82 5 88 98 68 32\\n\", \"100\\nqchhfaocnbignfamnmlgkgifcimjoloqjfebfkdcacjhchmmladcihiiaibfpbqegjlbnakbahqnbejbpgmjdpbqkgioiehdcqdf\\n38 48 6 86 7 78 56 35 12 34 63 12 73 77 76 57 14 46 42 32 58 16 61 31 61 62 88 82 51 58 91 3 58 23 53 39 69 83 99 100 3 29 75 54 28 75 6 89 12 25 62 90 42 36 80 66 99 77 60 41 84 72 53 20 52 93 2 12 83 78 91 17 76 55 68 31 76 16 24 12 28 15 7 16 39 8 53 16 74 22 49 88 79 81 75 73 46 30 71 43\\n\", \"100\\ncccjqikgocbhqqabapmjbidalibmbpcbiqejqnickjokmqfkegafpjfgolplnlahpqjicfjhkhkchnfilcgfdmjbkniichojlooe\\n19 14 7 69 26 40 47 90 40 5 43 73 33 40 100 22 59 3 7 91 60 98 55 61 41 56 44 93 53 84 43 9 59 66 99 44 51 4 50 69 73 69 82 65 83 49 84 80 86 43 81 16 56 30 55 98 93 92 48 7 74 94 100 16 52 34 54 75 31 28 43 60 24 18 87 45 14 63 78 86 46 91 64 1 43 86 50 3 11 89 95 89 4 20 83 21 48 47 3 54\\n\", \"10\\nlpfilflalm\\n19 68 23 38 1 14 10 56 86 77\\n\", \"100\\noeqfroknnkrllpjdgoddflgecpkimoijhiceacnaoloilqagmoirchgjjcopgrgjbegpoqccicqdjfpaklfiacijbdjiikqkqmaa\\n27 75 71 97 52 18 91 87 70 56 71 74 53 88 5 61 36 81 84 6 29 32 9 4 26 1 35 7 17 18 47 15 57 24 57 85 22 52 29 37 53 75 30 50 65 27 51 96 19 44 73 10 100 23 6 54 54 27 25 8 98 95 64 34 21 33 9 61 54 50 85 55 97 43 76 47 100 62 67 88 73 39 44 38 89 67 86 88 40 77 70 36 6 24 19 70 35 6 55 29\\n\", \"100\\needhjnnfpanpjcikblbnarprhrhjqeoqqgcqohfnfrpbfmiaqribpqqcbjelmknbbnibbmhqhqnjdmimahhkpgcrbedqjbjbdoii\\n92 53 76 84 78 88 90 58 87 31 58 39 25 47 33 34 78 30 52 69 26 17 3 38 2 7 95 19 7 40 99 20 57 71 95 81 17 69 88 6 19 20 41 49 24 1 29 91 9 70 95 36 26 17 81 82 48 38 13 74 84 17 11 23 21 74 61 24 2 95 34 2 46 10 95 64 38 8 25 70 95 27 1 27 97 49 86 75 69 39 15 29 35 63 30 18 37 26 87 40\\n\", \"10\\nqjrifrkfbg\\n63 7 14 79 20 31 33 10 9 26\\n\", \"100\\nfcrrgsbklknkqisnclphsgnoamneddiqnnqbcomjpnnqchgphjgiklabrmgbrckhdpedkrgalpbmoahqneesgkmbgiekarielrih\\n99 11 36 11 1 54 30 55 32 85 86 41 32 95 30 64 51 4 25 80 91 55 57 73 83 51 90 37 78 82 4 22 51 29 60 26 79 17 63 70 98 26 94 39 6 78 92 12 34 71 95 21 57 14 24 38 9 73 98 62 4 26 79 40 90 73 16 14 13 13 76 97 27 40 80 66 24 7 22 72 13 71 93 64 46 39 14 64 1 31 91 84 49 67 67 68 28 89 47 12\\n\", \"100\\nllaghdksecpacjoqdlfoekkaajpejpqsnhskkkasqodrdcbgoplsnbkdpjjdsiepprpnabsglffflkkmsimkakjfkhpedninkjim\\n72 89 37 2 19 20 28 10 49 57 66 5 4 50 66 29 97 60 94 43 97 36 51 7 60 45 42 49 73 4 56 28 59 68 98 23 70 42 22 30 68 63 1 46 65 49 75 7 20 97 10 55 87 11 7 70 99 84 87 32 93 44 23 33 90 10 60 73 69 59 24 40 68 99 100 72 74 54 72 54 31 48 46 49 54 13 19 47 38 94 36 74 74 10 74 15 34 10 66 22\\n\", \"10\\nqjqepaqjrc\\n2 51 12 8 47 48 47 69 31 67\\n\", \"100\\ndegqiqqsppfhidrmerftiignrihnsdooflhaonjtcdiofhjrntcifdbpgsoqrcgpllbfilejbblgkrfaakdoqqbfksiipsjlqqfi\\n74 8 48 17 23 12 46 40 54 33 32 97 52 59 28 3 47 15 8 94 95 65 67 91 42 96 56 100 45 83 98 41 2 40 38 54 88 76 16 62 13 85 86 78 6 96 7 75 41 63 66 92 97 79 40 70 30 55 50 85 53 19 56 46 41 74 19 20 61 53 93 74 100 22 47 64 27 66 62 49 18 87 87 62 35 51 37 50 22 71 10 100 79 84 3 85 40 81 92 39\\n\", \"100\\nlilbbnecoretoaanhaharbpqoaikpnriehqaaigjtsniclfblkqageojndfmilbngmkfhfblqmhmgakipgjslmemabgfcdsrettm\\n55 82 49 12 46 70 45 3 79 4 16 69 24 9 64 64 89 64 77 62 100 58 65 25 22 90 24 8 31 10 50 47 2 83 92 63 79 97 75 27 68 21 93 80 64 66 86 74 23 81 84 18 24 84 15 98 24 66 38 56 38 41 12 39 46 15 72 75 9 11 33 9 48 89 63 77 69 13 24 23 36 76 36 59 39 17 33 37 59 37 48 2 9 27 10 33 38 6 24 50\\n\", \"10\\ntaoqkbocpc\\n29 14 83 94 69 16 18 4 49 46\\n\", \"100\\nfekusmuhtflqkbhbcbadjtsaqhnfdqonsmunndlaftfdfibcuiqdabohaujklkhfttknjefjksnktfkekgkrrcodquqcttnqkeiq\\n54 43 13 35 76 48 81 100 17 59 52 71 35 66 57 2 62 38 49 73 61 88 15 68 99 47 11 26 3 47 54 53 96 41 41 99 42 46 50 87 59 27 41 62 55 47 44 95 48 90 80 11 59 78 58 50 85 5 23 52 63 46 76 56 98 14 26 65 28 25 87 8 21 15 51 83 51 11 16 33 55 19 23 88 85 14 61 22 88 33 27 48 19 31 50 82 29 69 75 17\\n\", \"100\\nsdsahsjliuojtidnhauithsrrmseagoiijjsulhblbnblhisodfircuaefgqbemhgmfiigekkuorqantauijtagssflkmmeokuqm\\n27 9 14 22 91 10 76 63 41 34 27 36 3 20 89 67 8 99 14 36 62 81 13 1 75 41 67 37 1 70 6 55 4 93 92 96 37 67 13 52 25 68 52 77 13 18 31 86 38 8 95 37 85 71 37 90 75 12 11 18 48 68 23 49 7 55 75 20 72 78 28 52 70 82 67 89 93 58 63 7 77 96 80 77 97 88 70 9 17 96 64 46 44 70 50 30 27 89 7 32\\n\", \"10\\ngterthaonk\\n73 58 73 27 84 37 40 66 71 94\\n\", \"100\\novkihhgldgfmibpnlptjcgrtgbcrleflheanrmvteivsrvenrvrugggfvhfbnnachgddvlojtsjtmnmgpfbugvltfjhbngotjagd\\n34 71 77 50 21 88 24 60 79 84 59 33 15 65 89 2 81 69 91 47 23 7 55 36 60 89 58 47 69 7 18 64 94 51 45 36 99 15 88 15 4 78 5 58 96 99 90 2 63 8 99 27 28 65 84 41 32 51 88 18 69 81 79 66 68 54 29 18 98 89 78 50 43 11 56 91 79 57 59 10 3 43 72 10 42 74 94 98 45 87 52 93 46 74 98 88 18 52 59 95\\n\", \"100\\nmqumjalldekakrqjhrvqomtstthcnmsnusfvfopiohggmlkpdqdkidupkaotgurecjohsthgiaorqafmctuitrnbdujekprnjtqd\\n4 45 78 33 43 46 15 23 4 56 43 2 87 28 21 63 22 21 59 10 29 100 61 70 40 91 18 67 55 29 63 66 7 90 83 37 90 36 47 84 70 27 8 61 55 69 68 97 49 35 17 57 54 58 58 65 30 58 76 84 58 95 35 59 68 91 82 69 42 42 18 94 87 74 71 9 25 3 18 92 17 20 29 99 46 52 94 81 82 50 85 90 75 17 1 35 16 73 91 18\\n\", \"10\\nnujfpdhamo\\n20 2 63 68 7 46 54 17 89 35\\n\", \"100\\ngselleupvmwtigmmjjctmvawlnscmoodqpidohgcfqcoavtvjsnbtfcgibcngrrkbduuuklwlqcguqmamhbduminclasseomtoun\\n7 6 42 56 70 25 63 20 42 10 71 99 94 76 14 1 99 100 32 21 94 30 3 13 17 40 9 73 26 67 75 72 97 56 40 77 52 76 23 52 54 29 52 47 33 51 35 13 78 35 22 46 86 56 10 21 87 89 53 77 75 8 95 76 37 94 32 67 65 52 68 92 64 100 64 11 11 2 6 94 43 67 17 36 91 46 18 66 3 42 68 41 81 17 37 85 7 36 39 85\\n\", \"100\\natgmmdpwlqtlwojdfaudwllahadnbruidpovejfpahttggnpghtvlgqoumssipncrowwftrbloqbkumsftnubijwcbpoanhchkwu\\n88 80 43 43 88 87 54 75 66 85 58 64 62 39 50 66 45 52 5 84 87 15 1 47 6 30 65 85 21 89 19 78 5 95 86 74 47 97 86 21 16 77 63 58 92 21 14 12 56 62 36 68 12 45 84 57 85 96 41 43 64 30 50 73 37 31 89 23 9 10 9 36 5 63 84 24 49 48 64 76 61 52 74 25 4 24 27 57 40 4 5 34 3 60 41 33 9 52 75 100\\n\", \"10\\nroacnkpldg\\n64 53 53 2 30 63 81 79 7 84\\n\", \"100\\nklpftlppaerfaqmhfafthvnuptjomiaejcbtfwsejksngtabnablefgxirtkfbcfacogolqwkawutbxadqarbxcaaijlodgtgdog\\n83 42 7 70 23 65 98 72 100 40 86 78 86 83 47 5 18 22 78 7 52 53 51 82 83 79 55 3 92 31 27 84 99 57 44 23 10 46 61 77 7 75 16 39 74 3 80 37 89 58 28 66 43 39 39 13 42 35 26 39 81 31 6 95 2 30 44 16 36 20 63 34 86 96 68 34 30 47 53 78 80 95 66 58 49 9 55 37 60 96 89 77 16 60 89 82 96 12 31 63\\n\", \"100\\nsxatqdotddqukjhmighutxddqloluxtkusflwjqtouxesplvpclpkkwspwcgvsjdxxxrfbfajqbclxemvakrixwwwkdpniebswvg\\n60 16 8 57 41 23 97 43 25 11 66 38 46 46 75 73 64 83 42 58 58 34 49 15 55 80 12 14 82 53 75 90 7 96 90 19 4 67 12 45 65 28 19 46 29 73 59 23 79 80 50 88 73 40 10 37 40 46 15 9 70 53 54 79 2 71 88 72 80 77 3 70 27 55 80 36 85 90 7 52 2 72 15 47 57 83 51 25 1 59 26 78 42 91 88 30 98 32 59 78\\n\", \"10\\nxvugurpobl\\n3 93 52 39 45 80 99 41 33 29\\n\", \"100\\nxjapcegkgtabkhmfcggmqttvxelnvorbuvhyssftxsjlveftfhuuvxdjvvnlnemmopkolcljibvhxdyyonynhgaguovxxjydgroo\\n64 78 72 80 68 1 37 40 62 62 93 40 61 94 80 100 33 53 23 81 19 72 3 58 36 29 98 25 50 91 84 92 1 62 47 52 67 15 95 9 53 26 71 28 24 50 18 44 4 85 51 85 4 33 61 93 97 81 92 6 94 61 22 1 67 74 43 70 95 87 53 77 8 81 69 42 62 84 4 62 28 20 99 76 98 73 87 5 22 51 10 25 51 3 36 76 89 91 19 53\\n\", \"100\\nbdhnnkoxmwsxaxgwykdphvdefqhmfjsvpeqacsrjuixikfnngcmwoodtersdarwtyfuiklorgfsmepthgtmhrubcymjhfqmsxkkb\\n37 52 73 63 94 63 32 95 87 37 85 9 33 45 8 73 82 6 80 37 24 58 97 92 20 19 66 40 48 13 36 97 9 6 93 53 58 32 46 74 19 75 82 39 74 24 96 35 86 7 69 7 31 31 36 29 91 92 80 76 84 80 73 89 67 11 99 21 47 41 94 12 48 56 88 60 5 31 54 36 46 100 60 73 14 51 84 97 59 13 47 22 73 38 40 24 87 15 50 68\\n\", \"10\\nhqdoyutwyj\\n39 37 42 72 68 97 22 87 51 69\\n\", \"100\\ndoreokncntzjcupgknnzekjpggwljnbvdhlemfldzputshtaxuizswyareobpngbsxfgljvilaxijygemqmoauuhhmridjrbzvfk\\n40 13 36 91 24 33 80 92 25 91 13 6 44 98 13 12 47 84 61 55 81 91 51 35 1 72 53 50 19 50 40 3 95 64 46 93 28 76 33 42 2 85 26 20 57 2 63 55 19 12 69 97 74 24 79 72 56 27 65 72 100 96 25 11 36 2 54 19 66 55 44 19 29 77 77 62 90 29 47 46 69 44 47 98 56 41 8 81 75 5 30 69 83 49 76 73 82 79 2 32\\n\", \"100\\nrnbmepccstmpkhsnymuuuauhbtxercmqqwuqgosdwtdafvkcfnqnhjqajldxjohjrlbjcrjvuvwdzxlyxuzsnqykqxxwlakdvahf\\n9 79 37 86 39 95 71 55 49 63 92 71 13 56 41 76 97 41 21 15 87 77 45 69 78 70 9 62 6 73 92 9 96 7 97 90 15 93 84 7 68 25 29 27 16 76 42 46 97 34 84 27 96 13 65 8 46 30 53 38 90 7 81 7 36 47 6 74 10 12 88 54 70 40 92 75 29 76 9 20 87 28 8 87 64 23 8 64 16 76 67 75 8 81 83 21 79 99 34 47\\n\", \"10\\npogfjssywv\\n83 76 36 1 83 14 44 49 73 22\\n\", \"10\\nababbbaaab\\n2 1 1 1 2 2 2 1 1 1\\n\", \"10\\nadbccdcaca\\n3 3 3 1 4 1 3 4 5 3\\n\", \"10\\nadaecdbeec\\n1 2 2 2 2 2 2 1 2 1\\n\", \"10\\ndacaccddde\\n4 5 5 1 3 5 5 5 5 4\\n\", \"10\\ndbdebedfdc\\n2 2 1 1 1 1 2 2 1 1\\n\", \"10\\ndcedcffbfd\\n3 4 3 3 3 1 4 4 5 4\\n\", \"10\\ncdeacbbdcb\\n2 2 2 2 1 1 1 2 2 1\\n\", \"10\\nafefedgebc\\n4 3 3 3 2 4 1 1 3 3\\n\", \"10\\nhafhfdcfbd\\n1 2 1 1 1 1 1 1 1 1\\n\", \"10\\nhgcafgabef\\n1 2 1 3 2 5 3 5 3 4\\n\", \"10\\ncabgcdaegf\\n2 1 2 2 2 2 1 1 2 1\\n\", \"10\\naeddcccegh\\n2 2 3 4 5 3 5 2 3 4\\n\", \"10\\nijjfjiahce\\n1 1 1 2 1 1 2 2 1 1\\n\", \"10\\nadiedbcbgb\\n1 5 4 3 2 5 4 4 1 2\\n\", \"10\\ndghgjfkddi\\n2 2 2 1 2 2 2 2 2 1\\n\", \"10\\njdcbjeidee\\n2 4 2 3 3 4 1 3 2 1\\n\", \"10\\nhdieiihkcd\\n1 2 1 2 2 2 2 2 1 1\\n\", \"10\\nhajbjgjcfk\\n5 4 4 3 5 4 3 4 2 1\\n\", \"10\\naelglcjlll\\n2 2 2 1 2 1 2 1 2 1\\n\", \"10\\nijambflljl\\n1 3 4 4 2 5 5 3 4 1\\n\", \"10\\nhgcbafgfff\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10\\njgneghedig\\n4 3 1 5 5 3 1 5 5 5\\n\", \"10\\ndninghgoeo\\n2 1 2 2 1 1 1 2 2 1\\n\", \"10\\namklleahme\\n5 4 4 1 1 4 1 3 2 1\\n\", \"10\\nkgbkloodei\\n1 1 1 1 1 2 1 2 1 1\\n\", \"10\\nklolmjmpgl\\n1 3 3 2 3 3 3 1 3 1\\n\", \"10\\nambqhimjpp\\n2 1 2 2 2 2 1 2 2 1\\n\", \"10\\nlqobdfadbc\\n4 1 1 2 4 3 5 4 4 2\\n\", \"10\\nkprqbgdere\\n1 2 1 1 2 2 2 1 2 1\\n\", \"10\\nmlgnrefmnl\\n5 1 4 3 1 2 1 1 1 3\\n\", \"10\\nkoomdonsge\\n2 2 2 2 2 1 2 1 1 1\\n\", \"10\\nrehnprefra\\n3 3 3 2 4 2 4 5 1 3\\n\", \"10\\nsjjndgohos\\n1 2 2 1 2 1 2 2 1 2\\n\", \"10\\nogggmeqlef\\n5 4 5 1 4 2 1 2 5 4\\n\", \"10\\nsabqfmegtd\\n2 2 1 2 1 1 2 2 2 2\\n\", \"10\\nchqsbejbfe\\n5 5 2 3 5 2 3 1 2 4\\n\", \"10\\nvbaulnfvbs\\n1 2 2 1 1 2 2 2 2 2\\n\", \"10\\ncqeoetddrd\\n3 3 2 3 2 1 1 2 3 4\\n\", \"10\\noprburkdvg\\n2 1 1 2 1 2 1 1 1 2\\n\", \"10\\nhvrcowvwri\\n4 3 5 3 4 1 4 1 3 4\\n\", \"10\\nrusgkmmixt\\n1 1 2 2 2 1 1 1 2 2\\n\", \"10\\njrhxthkmso\\n1 3 3 4 1 1 2 3 1 1\\n\", \"10\\njxymsqowvh\\n2 1 1 1 2 1 1 1 1 2\\n\", \"10\\nokcdifchye\\n5 4 2 4 3 5 4 1 1 2\\n\", \"10\\ncaezgakpiw\\n1 1 2 2 2 1 1 2 2 2\\n\", \"10\\nlbtsfgylki\\n5 3 5 5 1 5 1 3 3 2\\n\", \"8\\ncdcddcda\\n4 1 4 1 4 3 9 6\\n\"], \"outputs\": [\"8\\n\", \"26\\n\", \"17\\n\", \"4382\\n\", \"4494\\n\", \"4540\\n\", \"4466\\n\", \"4425\\n\", \"486\\n\", \"5112\\n\", \"4758\\n\", \"631\\n\", \"4486\\n\", \"4044\\n\", \"448\\n\", \"5144\\n\", \"4651\\n\", \"373\\n\", \"4956\\n\", \"4813\\n\", \"359\\n\", \"5234\\n\", \"5375\\n\", \"641\\n\", \"4555\\n\", \"5009\\n\", \"554\\n\", \"5128\\n\", \"4985\\n\", \"646\\n\", \"5089\\n\", \"4961\\n\", \"369\\n\", \"4597\\n\", \"5345\\n\", \"492\\n\", \"5174\\n\", \"4378\\n\", \"525\\n\", \"5115\\n\", \"5369\\n\", \"608\\n\", \"5301\\n\", \"4866\\n\", \"498\\n\", \"5046\\n\", \"5221\\n\", \"392\\n\", \"4895\\n\", \"4574\\n\", \"292\\n\", \"4938\\n\", \"4635\\n\", \"382\\n\", \"5419\\n\", \"4671\\n\", \"422\\n\", \"4867\\n\", \"4763\\n\", \"623\\n\", \"5552\\n\", \"5119\\n\", \"401\\n\", \"4936\\n\", \"4862\\n\", \"516\\n\", \"5145\\n\", \"4850\\n\", \"514\\n\", \"5401\\n\", \"5196\\n\", \"584\\n\", \"4957\\n\", \"5072\\n\", \"481\\n\", \"11\\n\", \"26\\n\", \"17\\n\", \"38\\n\", \"14\\n\", \"30\\n\", \"16\\n\", \"25\\n\", \"9\\n\", \"25\\n\", \"16\\n\", \"28\\n\", \"13\\n\", \"31\\n\", \"18\\n\", \"25\\n\", \"13\\n\", \"35\\n\", \"14\\n\", \"28\\n\", \"10\\n\", \"35\\n\", \"15\\n\", \"23\\n\", \"12\\n\", \"23\\n\", \"17\\n\", \"30\\n\", \"15\\n\", \"22\\n\", \"16\\n\", \"30\\n\", \"14\\n\", \"33\\n\", \"17\\n\", \"32\\n\", \"14\\n\", \"24\\n\", \"14\\n\", \"32\\n\", \"15\\n\", \"20\\n\", \"13\\n\", \"31\\n\", \"16\\n\", \"33\\n\", \"23\\n\"]}", "source": "primeintellect"}
|
A string a of length m is called antipalindromic iff m is even, and for each i (1 ≤ i ≤ m) a_{i} ≠ a_{m} - i + 1.
Ivan has a string s consisting of n lowercase Latin letters; n is even. He wants to form some string t that will be an antipalindromic permutation of s. Also Ivan has denoted the beauty of index i as b_{i}, and the beauty of t as the sum of b_{i} among all indices i such that s_{i} = t_{i}.
Help Ivan to determine maximum possible beauty of t he can get.
-----Input-----
The first line contains one integer n (2 ≤ n ≤ 100, n is even) — the number of characters in s.
The second line contains the string s itself. It consists of only lowercase Latin letters, and it is guaranteed that its letters can be reordered to form an antipalindromic string.
The third line contains n integer numbers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 100), where b_{i} is the beauty of index i.
-----Output-----
Print one number — the maximum possible beauty of t.
-----Examples-----
Input
8
abacabac
1 1 1 1 1 1 1 1
Output
8
Input
8
abaccaba
1 2 3 4 5 6 7 8
Output
26
Input
8
abacabca
1 2 3 4 4 3 2 1
Output
17
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"23 5\\n\", \"13 2\\n\", \"1 2\\n\", \"1 1\\n\", \"7 2\\n\", \"7 3\\n\", \"7 4\\n\", \"521325125150442808 10\\n\", \"1 4\\n\", \"9 4\\n\", \"3 4\\n\", \"144 4\\n\", \"59 4\\n\", \"78 4\\n\", \"192 4\\n\", \"107 4\\n\", \"552 5\\n\", \"680 5\\n\", \"808 5\\n\", \"1528 5\\n\", \"1656 5\\n\", \"26972 8\\n\", \"23100 8\\n\", \"19228 8\\n\", \"22652 8\\n\", \"26076 8\\n\", \"329438 10\\n\", \"12862 10\\n\", \"96286 10\\n\", \"12414 10\\n\", \"95838 10\\n\", \"1728568411 16\\n\", \"611684539 16\\n\", \"84735259 16\\n\", \"6967851387 16\\n\", \"2145934811 16\\n\", \"6795804571172 20\\n\", \"1038982654596 20\\n\", \"11277865770724 20\\n\", \"5525338821444 20\\n\", \"15764221937572 20\\n\", \"922239521698513045 30\\n\", \"923065764876596469 30\\n\", \"923892008054679893 30\\n\", \"924718251232763317 30\\n\", \"925544490115879445 30\\n\", \"926370733293962869 30\\n\", \"927196976472046293 30\\n\", \"928023215355162421 30\\n\", \"928849458533245845 30\\n\", \"855969764271400156 30\\n\", \"856796007449483580 30\\n\", \"857622246332599708 30\\n\", \"858448489510683132 30\\n\", \"859274728393799260 30\\n\", \"860100975866849980 30\\n\", \"860927214749966108 30\\n\", \"861753457928049532 30\\n\", \"862579701106132957 30\\n\", \"863405944284216381 30\\n\", \"374585535361966567 30\\n\", \"4 1\\n\", \"4 9\\n\", \"4 3\\n\", \"4 144\\n\", \"4 59\\n\", \"4 78\\n\", \"4 107\\n\", \"281474976710656 5\\n\", \"288230376151973890 5\\n\", \"36029346774812736 5\\n\", \"901283150305558530 5\\n\", \"288318372649779720 50\\n\", \"513703875844698663 50\\n\", \"287632104387196918 50\\n\", \"864690028406636543 58\\n\", \"576460752303423487 60\\n\", \"141012366262272 1\\n\", \"1100585377792 4\\n\", \"18598239186190594 9\\n\", \"18647719372456016 19\\n\", \"9297478914673158 29\\n\", \"668507368948226 39\\n\", \"1143595340402690 49\\n\", \"35527987183872 59\\n\", \"324634416758413825 9\\n\", \"577030480059438572 19\\n\", \"185505960265024385 29\\n\", \"57421517433081233 39\\n\", \"90131572647657641 49\\n\", \"732268459757413905 59\\n\", \"226111453445787190 9\\n\", \"478818723873062027 19\\n\", \"337790572680259391 29\\n\", \"168057637182978458 39\\n\", \"401486559567818547 49\\n\", \"828935109688089201 59\\n\", \"954687629161163764 9\\n\", \"287025268967992526 19\\n\", \"844118423640988373 29\\n\", \"128233154575908599 39\\n\", \"792058388714085231 49\\n\", \"827183623566145225 59\\n\", \"846113779983498737 9\\n\", \"780248358343081983 19\\n\", \"576460580458522095 29\\n\", \"540145805193625598 39\\n\", \"576388182371377103 49\\n\", \"567448991726268409 59\\n\", \"576460752303423487 9\\n\", \"576460752303423487 19\\n\", \"864691128455135231 29\\n\", \"864691128455135231 39\\n\", \"576460752303423487 49\\n\", \"864691128455135231 59\\n\", \"1 4\\n\", \"2 64\\n\", \"2 8\\n\", \"1 5\\n\", \"1 7\\n\", \"19 5\\n\", \"1 30\\n\"], \"outputs\": [\"Yes\\n3 3 2 1 0 \\n\", \"No\\n\", \"Yes\\n-1 -1 \\n\", \"Yes\\n0 \\n\", \"No\\n\", \"Yes\\n2 1 0 \\n\", \"Yes\\n1 1 1 0 \\n\", \"No\\n\", \"Yes\\n-2 -2 -2 -2 \\n\", \"Yes\\n2 2 -1 -1 \\n\", \"Yes\\n0 0 -1 -1 \\n\", \"Yes\\n6 6 3 3 \\n\", \"No\\n\", \"Yes\\n6 3 2 1 \\n\", \"Yes\\n6 6 5 5 \\n\", \"No\\n\", \"Yes\\n8 8 5 2 2 \\n\", \"Yes\\n8 8 7 5 3 \\n\", \"Yes\\n8 8 8 5 3 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n14 13 11 8 6 4 3 2 \\n\", \"Yes\\n14 12 11 9 5 4 3 2 \\n\", \"Yes\\n13 13 11 9 8 4 3 2 \\n\", \"Yes\\n14 12 11 6 5 4 3 2 \\n\", \"No\\n\", \"Yes\\n18 16 10 9 7 6 4 3 2 1 \\n\", \"Yes\\n12 12 12 9 5 4 3 2 0 0 \\n\", \"Yes\\n15 15 14 13 12 11 4 3 2 1 \\n\", \"Yes\\n12 12 12 6 5 4 3 2 0 0 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n28 28 26 22 21 20 18 16 15 12 7 5 4 3 1 0 \\n\", \"Yes\\n25 25 24 19 18 15 14 13 12 10 8 4 3 1 -1 -1 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n41 41 41 37 35 34 33 30 26 24 23 18 14 13 12 10 9 5 1 1 \\n\", \"Yes\\n38 38 38 37 36 32 31 30 29 27 21 20 16 13 11 9 7 1 0 0 \\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n58 58 58 55 54 51 50 46 45 44 41 40 39 38 37 36 34 32 30 29 28 23 21 19 17 15 7 4 2 0 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n58 58 58 55 54 52 50 48 46 41 38 36 35 32 31 29 25 19 18 15 12 11 10 8 7 5 4 2 -1 -1 \\n\", \"Yes\\n59 58 55 54 52 51 45 44 40 39 38 35 34 33 32 30 28 27 26 24 21 19 18 16 14 12 9 4 2 0 \\n\", \"Yes\\n57 57 57 57 57 57 55 54 52 51 49 48 45 40 38 34 33 28 27 22 19 18 17 10 9 6 5 4 2 0 \\n\", \"No\\n\", \"Yes\\n58 58 58 55 54 53 48 37 36 33 31 27 26 25 23 19 18 17 16 14 13 11 10 9 8 5 4 2 -1 -1 \\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n58 58 57 56 55 54 53 50 49 47 46 45 41 39 38 37 33 32 31 29 21 15 11 10 8 7 4 3 1 1 \\n\", \"No\\n\", \"Yes\\n59 57 56 55 54 53 51 50 47 46 40 39 38 36 28 26 25 22 21 16 15 14 13 12 10 9 6 4 3 2 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n58 58 57 56 55 54 53 52 50 48 47 44 37 36 34 30 26 25 24 23 22 18 12 9 8 6 5 4 3 2 \\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n2 \\n\", \"Yes\\n-1 -1 -1 -1 -1 -1 -1 -2 -2 \\n\", \"Yes\\n1 0 0 \\n\", \"Yes\\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -19 -20 -21 -21 \\n\", \"Yes\\n-3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -3 -4 -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 -30 \\n\", \"Yes\\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 \\n\", \"Yes\\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -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 -47 \\n\", \"Yes\\n46 46 46 45 45 \\n\", \"Yes\\n57 57 18 0 0 \\n\", \"Yes\\n55 39 15 11 6 \\n\", \"No\\n\", \"Yes\\n53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 53 46 44 35 30 27 17 14 9 2 1 0 -1 -2 -3 -4 -5 -6 -6 \\n\", \"Yes\\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 53 48 43 41 39 38 37 36 34 27 26 25 24 22 21 20 18 17 15 14 13 12 9 5 2 1 -1 -2 -3 -4 -5 -6 -7 -8 -9 -9 \\n\", \"Yes\\n57 56 55 54 53 52 51 50 48 47 46 44 43 42 41 40 39 38 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 13 12 10 9 8 7 6 5 4 2 1 \\n\", \"Yes\\n58 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 39 38 37 36 35 34 33 32 31 30 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 \\n\", \"Yes\\n57 57 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 \\n\", \"No\\n\", \"Yes\\n39 39 30 13 \\n\", \"Yes\\n54 49 44 41 40 21 18 8 1 \\n\", \"Yes\\n51 51 51 51 51 51 51 51 49 46 31 24 20 16 6 3 2 1 1 \\n\", \"Yes\\n49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 49 48 43 33 18 11 9 2 0 -1 -2 -3 -4 -4 \\n\", \"Yes\\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 32 22 16 15 9 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -13 \\n\", \"Yes\\n45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 45 44 36 35 27 25 19 12 0 -1 -2 -3 -4 -5 -6 -7 -8 -8 \\n\", \"Yes\\n40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 40 38 36 24 19 18 17 14 7 6 5 4 3 2 1 0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 \\n\", \"No\\n\", \"Yes\\n59 49 42 41 37 35 33 28 26 23 18 12 10 8 7 6 5 3 2 \\n\", \"Yes\\n54 54 54 54 54 54 54 54 54 54 52 49 48 43 42 39 37 36 29 24 22 20 15 9 8 7 -1 -2 -2 \\n\", \"Yes\\n52 52 52 52 52 52 52 52 52 52 52 52 51 50 39 36 31 30 28 27 26 24 20 11 10 8 7 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -10 \\n\", \"Yes\\n52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 52 45 44 42 41 37 36 28 25 23 21 20 18 17 7 5 3 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -12 \\n\", \"Yes\\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 53 51 48 47 43 41 38 35 31 30 28 20 13 10 9 4 -1 -2 -2 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n58 55 53 52 44 41 39 37 36 35 34 30 29 28 26 24 20 18 16 13 10 9 8 5 4 3 2 1 0 \\n\", \"Yes\\n54 54 54 54 54 54 54 54 54 52 50 48 43 42 41 40 39 34 33 32 31 30 28 26 25 20 18 16 13 12 11 8 7 4 3 0 -1 -2 -2 \\n\", \"Yes\\n54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 54 52 49 46 44 43 42 40 39 38 37 34 33 28 26 24 21 17 13 11 10 9 8 5 4 1 -1 -1 \\n\", \"Yes\\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 47 46 45 44 43 36 34 33 32 29 25 23 22 19 18 17 15 14 12 11 9 6 5 4 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -11 \\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n56 55 54 50 49 48 47 44 41 40 38 36 35 34 33 32 31 30 29 27 25 23 22 21 19 18 15 13 12 11 10 9 7 6 5 4 2 1 0 \\n\", \"Yes\\n56 56 56 56 56 56 56 56 56 56 55 54 53 52 51 50 48 47 46 45 44 42 39 38 37 35 30 29 28 26 23 21 19 17 16 15 14 12 11 9 8 6 5 3 2 1 -1 -2 -2 \\n\", \"Yes\\n55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 55 54 53 52 51 49 47 45 44 43 42 41 40 36 35 34 33 32 30 29 28 27 26 25 23 21 19 18 17 13 12 10 9 7 6 3 -1 -1 \\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n58 57 56 55 54 53 52 51 50 49 48 47 45 44 43 42 40 39 38 37 36 35 34 33 32 30 29 28 27 26 25 23 22 21 20 19 17 15 12 11 10 9 8 7 6 3 2 1 0 \\n\", \"Yes\\n56 56 56 56 56 56 56 55 54 52 51 50 49 48 47 46 45 44 43 41 40 39 38 36 35 32 31 30 29 28 27 25 24 23 22 21 20 19 18 17 16 14 13 11 10 9 8 7 6 5 4 3 -1 -2 -3 -4 -5 -6 -6 \\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"Yes\\n59 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 \\n\", \"Yes\\n-2 -2 -2 -2 \\n\", \"Yes\\n-5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 -5 \\n\", \"Yes\\n-2 -2 -2 -2 -2 -2 -2 -2 \\n\", \"Yes\\n-2 -2 -2 -3 -3 \\n\", \"Yes\\n-2 -2 -2 -3 -4 -5 -5 \\n\", \"Yes\\n3 3 1 -1 -1 \\n\", \"Yes\\n-4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 -15 -16 -17 -18 -18 \\n\"]}", "source": "primeintellect"}
|
Jamie is preparing a Codeforces round. He has got an idea for a problem, but does not know how to solve it. Help him write a solution to the following problem:
Find k integers such that the sum of two to the power of each number equals to the number n and the largest integer in the answer is as small as possible. As there may be multiple answers, you are asked to output the lexicographically largest one.
To be more clear, consider all integer sequence with length k (a_1, a_2, ..., a_{k}) with $\sum_{i = 1}^{k} 2^{a_{i}} = n$. Give a value $y = \operatorname{max}_{1 \leq i \leq k} a_{i}$ to each sequence. Among all sequence(s) that have the minimum y value, output the one that is the lexicographically largest.
For definitions of powers and lexicographical order see notes.
-----Input-----
The first line consists of two integers n and k (1 ≤ n ≤ 10^18, 1 ≤ k ≤ 10^5) — the required sum and the length of the sequence.
-----Output-----
Output "No" (without quotes) in a single line if there does not exist such sequence. Otherwise, output "Yes" (without quotes) in the first line, and k numbers separated by space in the second line — the required sequence.
It is guaranteed that the integers in the answer sequence fit the range [ - 10^18, 10^18].
-----Examples-----
Input
23 5
Output
Yes
3 3 2 1 0
Input
13 2
Output
No
Input
1 2
Output
Yes
-1 -1
-----Note-----
Sample 1:
2^3 + 2^3 + 2^2 + 2^1 + 2^0 = 8 + 8 + 4 + 2 + 1 = 23
Answers like (3, 3, 2, 0, 1) or (0, 1, 2, 3, 3) are not lexicographically largest.
Answers like (4, 1, 1, 1, 0) do not have the minimum y value.
Sample 2:
It can be shown there does not exist a sequence with length 2.
Sample 3:
$2^{-1} + 2^{-1} = \frac{1}{2} + \frac{1}{2} = 1$
Powers of 2:
If x > 0, then 2^{x} = 2·2·2·...·2 (x times).
If x = 0, then 2^{x} = 1.
If x < 0, then $2^{x} = \frac{1}{2^{-x}}$.
Lexicographical order:
Given two different sequences of the same length, (a_1, a_2, ... , a_{k}) and (b_1, b_2, ... , b_{k}), the first one is smaller than the second one for the lexicographical order, if and only if a_{i} < b_{i}, for the first i where a_{i} and b_{i} differ.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n1 1\\n\", \"2\\n1 2\\n\", \"3\\n1 2 1\\n\", \"2\\n1 3\\n\", \"2\\n3 5\\n\", \"2\\n9 10\\n\", \"2\\n6 8\\n\", \"3\\n0 0 0\\n\", \"2\\n223 58\\n\", \"2\\n106 227\\n\", \"2\\n125 123\\n\", \"3\\n31 132 7\\n\", \"2\\n41 29\\n\", \"3\\n103 286 100\\n\", \"3\\n9 183 275\\n\", \"3\\n19 88 202\\n\", \"3\\n234 44 69\\n\", \"3\\n244 241 295\\n\", \"1\\n6\\n\", \"1\\n231\\n\", \"2\\n241 289\\n\", \"2\\n200 185\\n\", \"2\\n218 142\\n\", \"3\\n124 47 228\\n\", \"3\\n134 244 95\\n\", \"1\\n0\\n\", \"1\\n10\\n\", \"1\\n2\\n\", \"1\\n1\\n\", \"1\\n99\\n\", \"2\\n44 27\\n\", \"2\\n280 173\\n\", \"2\\n29 47\\n\", \"2\\n16 26\\n\", \"2\\n58 94\\n\", \"2\\n17 28\\n\", \"2\\n59 96\\n\", \"2\\n164 101\\n\", \"2\\n143 88\\n\", \"2\\n69 112\\n\", \"2\\n180 111\\n\", \"2\\n159 98\\n\", \"2\\n183 113\\n\", \"2\\n162 100\\n\", \"2\\n230 142\\n\", \"2\\n298 184\\n\", \"2\\n144 233\\n\", \"2\\n0 0\\n\", \"2\\n173 280\\n\", \"2\\n180 111\\n\", \"2\\n251 155\\n\", \"2\\n114 185\\n\", \"2\\n156 253\\n\", \"2\\n144 233\\n\", \"2\\n0 0\\n\", \"2\\n14 23\\n\", \"2\\n2 1\\n\", \"2\\n70 43\\n\", \"2\\n49 30\\n\", \"2\\n150 243\\n\", \"2\\n6 10\\n\", \"2\\n152 246\\n\", \"2\\n13 8\\n\", \"2\\n293 181\\n\", \"2\\n15 9\\n\", \"2\\n295 182\\n\", \"2\\n62 38\\n\", \"2\\n80 130\\n\", \"2\\n40 65\\n\", \"1\\n248\\n\", \"1\\n10\\n\", \"2\\n216 91\\n\", \"1\\n234\\n\", \"2\\n140 193\\n\", \"3\\n151 97 120\\n\", \"1\\n213\\n\", \"3\\n119 251 222\\n\", \"3\\n129 148 141\\n\", \"1\\n147\\n\", \"2\\n124 194\\n\", \"3\\n184 222 102\\n\", \"3\\n101 186 223\\n\", \"3\\n0 87 87\\n\", \"3\\n144 33 177\\n\", \"3\\n49 252 205\\n\", \"3\\n49 126 79\\n\", \"3\\n152 66 218\\n\", \"3\\n181 232 93\\n\", \"3\\n15 150 153\\n\", \"3\\n191 50 141\\n\", \"3\\n162 230 68\\n\", \"3\\n4 19 23\\n\", \"3\\n222 129 95\\n\", \"3\\n38 16 54\\n\", \"3\\n254 227 29\\n\", \"3\\n196 45 233\\n\", \"3\\n70 45 107\\n\", \"3\\n190 61 131\\n\", \"3\\n0 173 173\\n\", \"3\\n50 69 119\\n\", \"1\\n108\\n\", \"1\\n15\\n\", \"1\\n85\\n\", \"1\\n291\\n\", \"1\\n1\\n\", \"2\\n11 222\\n\", \"2\\n218 127\\n\", \"2\\n280 24\\n\", \"2\\n298 281\\n\", \"3\\n275 70 60\\n\", \"3\\n299 299 298\\n\", \"3\\n299 299 299\\n\", \"3\\n299 299 299\\n\", \"2\\n298 299\\n\", \"2\\n299 299\\n\", \"1\\n299\\n\", \"3\\n299 290 288\\n\"], \"outputs\": [\"BitLGM\\n\", \"BitAryo\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitAryo\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitAryo\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitAryo\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitAryo\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\", \"BitLGM\\n\"]}", "source": "primeintellect"}
|
Since most contestants do not read this part, I have to repeat that Bitlandians are quite weird. They have their own jobs, their own working method, their own lives, their own sausages and their own games!
Since you are so curious about Bitland, I'll give you the chance of peeking at one of these games.
BitLGM and BitAryo are playing yet another of their crazy-looking genius-needed Bitlandish games. They've got a sequence of n non-negative integers a_1, a_2, ..., a_{n}. The players make moves in turns. BitLGM moves first. Each player can and must do one of the two following actions in his turn:
Take one of the integers (we'll denote it as a_{i}). Choose integer x (1 ≤ x ≤ a_{i}). And then decrease a_{i} by x, that is, apply assignment: a_{i} = a_{i} - x. Choose integer x $(1 \leq x \leq \operatorname{min}_{i = 1} a_{i})$. And then decrease all a_{i} by x, that is, apply assignment: a_{i} = a_{i} - x, for all i.
The player who cannot make a move loses.
You're given the initial sequence a_1, a_2, ..., a_{n}. Determine who wins, if both players plays optimally well and if BitLGM and BitAryo start playing the described game in this sequence.
-----Input-----
The first line contains an integer n (1 ≤ n ≤ 3).
The next line contains n integers a_1, a_2, ..., a_{n} (0 ≤ a_{i} < 300).
-----Output-----
Write the name of the winner (provided that both players play optimally well). Either "BitLGM" or "BitAryo" (without the quotes).
-----Examples-----
Input
2
1 1
Output
BitLGM
Input
2
1 2
Output
BitAryo
Input
3
1 2 1
Output
BitLGM
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"5\\nRURUU\\n-2 3\\n\", \"4\\nRULR\\n1 1\\n\", \"3\\nUUU\\n100 100\\n\", \"6\\nUDUDUD\\n0 1\\n\", \"100\\nURDLDDLLDDLDDDRRLLRRRLULLRRLUDUUDUULURRRDRRLLDRLLUUDLDRDLDDLDLLLULRURRUUDDLDRULRDRUDDDDDDULRDDRLRDDL\\n-59 -1\\n\", \"8\\nUUULLLUU\\n-3 0\\n\", \"9\\nUULUURRUU\\n6379095 -4\\n\", \"5\\nDUUUD\\n2 3\\n\", \"2\\nUD\\n2 0\\n\", \"5\\nLRLRL\\n-3 2\\n\", \"4\\nRRRR\\n-6 0\\n\", \"1\\nR\\n0 0\\n\", \"1\\nU\\n0 1\\n\", \"14\\nRULDRULDRULDRR\\n2 6\\n\", \"2\\nUU\\n-4 4\\n\", \"3\\nLRU\\n0 -1\\n\", \"4\\nDRRD\\n1 3\\n\", \"8\\nUUUUDDDD\\n5 -5\\n\", \"1\\nR\\n1 0\\n\", \"3\\nUUU\\n-1 0\\n\", \"28\\nDLUURUDLURRDLDRDLLUDDULDRLDD\\n-12 -2\\n\", \"1\\nR\\n0 1\\n\", \"20\\nRDURLUUUUUULRLUUURLL\\n8 4\\n\", \"10\\nURLRLURLRL\\n0 -2\\n\", \"16\\nLRLRLRLRLRLRLRLR\\n0 6\\n\", \"20\\nRLRDDRDRUDURRUDDULDL\\n8 6\\n\", \"52\\nRUUUDDRULRRDUDLLRLLLDDULRDULLULUURURDRLDDRLUURLUUDDD\\n1 47\\n\", \"2\\nUD\\n-2 0\\n\", \"2\\nLL\\n1 1\\n\", \"1\\nU\\n-1 0\\n\", \"83\\nDDLRDURDDDURDURLRRRUDLLDDRLLLDDRLULRLDRRULDDRRUUDLRUUUDLLLUUDURLLRLULDRRDDRRDDURLDR\\n4 -5\\n\", \"6\\nULDRLU\\n-1 5\\n\", \"38\\nUDDURLDURUUULDLRLRLURURRUUDURRDRUURULR\\n-3 3\\n\", \"2\\nRL\\n-2 0\\n\", \"1\\nU\\n0 -1\\n\", \"4\\nLRUD\\n2 2\\n\", \"67\\nRDLLULDLDLDDLDDLDRULDLULLULURLURRLULLLRULLRDRRDLRLURDRLRRLLUURURLUR\\n6 -5\\n\", \"62\\nLURLLRULDUDLDRRRRDDRLUDRUDRRURDLDRRULDULDULRLRRLDUURUUURDDLRRU\\n6 2\\n\", \"22\\nDUDDDRUDULDRRRDLURRUUR\\n-2 -2\\n\", \"386\\nRUDLURLUURDDLLLRLDURLRRDLDUUURLLRDLRRDLDRLDDURDURURDRLUULLDUULRULDLLLLDLUURRLRRRUDULRDDRDLDULRLDDRDDRLRLDLDULLULUDULLLDUUDURURDDLDRLUDDDDLDUDUURLUUDURRUDRLUDRLULLRLRRDLULDRRURUULLRDLDRLURDUDRLDLRLLUURLURDUUDRDURUDDLLDURURLLRRULURULRRLDLDRLLUUURURDRRRLRDRURULUDURRLRLDRUDLRRRRLLRURDUUDLLLLURDLRLRRDLDLLLDUUDDURRLLDDDDDULURLUDLRRURUUURLRRDLLDRDLDUDDDULLDDDRURRDUUDDDUURLDRRDLRLLRUUULLUDLR\\n-2993 495\\n\", \"3\\nUUU\\n-1 -2\\n\", \"41\\nRRDDRUDRURLDRRRLLDLDULRUDDDRRULDRLLDUULDD\\n-4 -1\\n\", \"25\\nURRDDULRDDURUDLDUDURUDDDL\\n1 -2\\n\", \"3\\nDUU\\n-1 -2\\n\", \"31\\nRRDLDRUUUDRULDDDRURRULRLULDULRD\\n0 -1\\n\", \"4\\nLDUR\\n0 0\\n\", \"43\\nDRURRUDUUDLLURUDURDDDUDRDLUDURRDRRDLRLURUDU\\n-1 5\\n\", \"13\\nUDLUUDUULDDLR\\n0 -1\\n\", \"5\\nLRLRD\\n-1 -2\\n\", \"55\\nLLULRLURRRURRLDDUURLRRRDURUDRLDDRRRDURDUDLUDLLLDDLUDDUD\\n5 -4\\n\", \"11\\nULDRRRURRLR\\n0 -1\\n\", \"40\\nDRURDRUDRUDUDDURRLLDRDDUUUULLLRDDUDULRUR\\n-4 0\\n\", \"85\\nURDDUUURDLURUDDRUDURUDDURUDLRDLLURDLDDLUDRDLDDLLRLUDLLRURUDULDURUDDRRUDULDLDUDLDDRDRL\\n1 -8\\n\", \"3\\nRRR\\n1 -2\\n\", \"61\\nDLUDLUDLUULDLDRDUDLLRULLULURLUDULDURDRLLLRLURDUURUUDLLLRDRLDU\\n-3 -4\\n\", \"60\\nLLDDDULDLDRUULRLLLLLDURUDUDRDRUDLLRDDDRRRDRRLUDDDRRRDDLDLULL\\n-4 0\\n\", \"93\\nDDRDRDUDRULDLDRDLLLUUDLULRLLDURRRURRLDRDDLDRLLLURLDDLLRURUDDRLULLLDUDDDRDLRURDDURDRURRUUULRDD\\n-4 -1\\n\", \"27\\nRLUUDUDDRRULRDDULDULRLDLDRL\\n0 -3\\n\", \"86\\nUDDURDUULURDUUUDDDLRLDRUDDUURDRRUUDUURRRLDRLLUUURDRRULDDDRLRRDLLDRLDLULDDULDLDLDDUULLR\\n10 -2\\n\", \"3\\nLLD\\n-2 -1\\n\", \"55\\nURRDRLLDRURDLRRRDRLRUURLRDRULURLULRURDULLDDDUUULLDRLLUD\\n-6 -3\\n\", \"4\\nLURR\\n0 0\\n\", \"60\\nDULDLRLLUULLURUDLDURRDDLDRUUUULRRRDLUDURULRDDLRRDLLRUUURLRDR\\n-4 1\\n\", \"1\\nU\\n0 0\\n\", \"34\\nDDRRURLDDULULLUDDLDRDUDDULDURRLRLR\\n1 3\\n\", \"30\\nLLUDLRLUULDLURURUDURDUDUDLUDRR\\n3 1\\n\", \"34\\nLDRUDLRLULDLUDRUUUDUURDULLURRUULRD\\n-4 2\\n\", \"31\\nRDLRLRLDUURURRDLULDLULUULURRDLU\\n-1 -2\\n\", \"60\\nDLURDLRDDURRLLLUULDRDLLDRDDUURURRURDLLRUDULRRURULDUDULRURLUU\\n5 -5\\n\", \"27\\nLRLULRDURDLRDRDURRRDDRRULLU\\n-2 -1\\n\", \"75\\nRDLLLURRDUDUDLLRURURDRRLUULDRLLULDUDDUUULRRRDLDDLULURDRLURRDRDDRURDRLRRLRUU\\n0 -3\\n\", \"15\\nUDLUULRLUULLUUR\\n-1 0\\n\", \"29\\nRRUULRLRUUUDLDRLDUUDLRDUDLLLU\\n-3 -2\\n\", \"49\\nLDDURLLLDLRDLRLDURLRDDLDRRRULLDDUULRURDUDUULLLLDD\\n2 -1\\n\", \"65\\nULRUDDLDULLLUDLRLDUUULLDRLRUDLDDRLLDLRRDRDRRUUUULDLRLRDDLULRDRDRD\\n-3 -2\\n\", \"93\\nLRRDULLDDULUDRLRRLLRDDDLRUUURLRUULDDDUDLLDRUDDDRDDLDLRRRRDLRULRUDLLLRDDRUUUDRUUDULRLRURRRRLUL\\n-9 -2\\n\", \"48\\nRLDRRRDLRRRRRLDLDLLLLLDLLDRLRLDRRLDDUUUDULDDLLDU\\n-5 5\\n\", \"60\\nLDUDUDRRLRUULLDRUURRRDULUUULUDRDLUDLLLLDUDLRRLRLLURDDDUDDDRU\\n3 3\\n\", \"77\\nDDURRDLDURUDDDLLRULRURRULRULLULRRLLRUULLULRRLDULRRDURUURRLDDLUDURLLURDULDUDUD\\n6 -7\\n\", \"15\\nDURRULRRULRLRDD\\n0 -1\\n\", \"6\\nULLUUD\\n-3 3\\n\", \"53\\nULULLRULUDRDRDDDULDUDDRULRURLLRLDRRRDDUDUDLLULLLDDDLD\\n1 4\\n\", \"67\\nDLULDRUURDLURRRRDDLRDRUDDUDRDRDRLDRDDDLURRDDURRDUDURRDRDLURRUUDULRL\\n-8 -1\\n\", \"77\\nLRRUDLDUDRDRURURURLDLLURLULDDURUDUUDDUDLLDULRLRLRRRRULLRRRDURRDLUDULRUURRLDLU\\n-6 -7\\n\", \"75\\nRDRDRDDDRRLLRDRRLRLDRLULLRDUUDRULRRRDLLDUUULRRRULUDLLDRRUUURUUUUDUULLDRRUDL\\n-6 -7\\n\", \"70\\nRDDULUDRDUDRDLRUDUDRUUUDLLLRDUUDLLURUDRLLLRUUDUDUDRURUDRRRLLUDLDRDRDDD\\n8 6\\n\", \"13\\nUUULRUDDRLUUD\\n13 -10\\n\", \"17\\nURURDULULDDDDLDLR\\n-1 -8\\n\", \"13\\nRRLUURUUDUUDL\\n0 -1\\n\", \"35\\nDLUDLDUUULLRLRDURDLLRUUUULUDUUDLDUR\\n-3 -4\\n\", \"17\\nLLRDURLURLRDLULRR\\n2 1\\n\", \"3\\nDDD\\n-1 -2\\n\", \"3\\nLUD\\n-2 1\\n\", \"18\\nDRULLLLLLRDULLULRR\\n-5 1\\n\", \"7\\nLRRDRDD\\n2 3\\n\", \"15\\nDLLLULDLDUURDDL\\n-1 0\\n\", \"84\\nUDRDDDRLRRRRDLLDLUULLRLRUDLRLDRDURLRDDDDDUULRRUURDLLDRRRUUUULLRDLDDDRRUDUUUDDLLLULUD\\n2 8\\n\", \"65\\nULLLLUDUDUUURRURLDRDLULRRDLLDDLRRDRURLDLLUDULLLDUDLLLULURDRLLULLL\\n-4 -7\\n\", \"69\\nUDUDLDUURLLUURRLDLRLDDDRRUUDULRULRDLRRLURLDLLRLURUDDURRDLDURUULDLLUDR\\n-3 -4\\n\", \"24\\nURURUDDULLDUURLDLUUUUDRR\\n-2 0\\n\", \"35\\nDDLUDDLDLDRURLRUDRRRLLRRLURLLURDDRD\\n1 2\\n\", \"88\\nLRLULDLDLRDLRULRRDURUULUDDDURRDLLLDDUUULLLRDLLLDRDDDURDUURURDDLLDURRLRDRLUULUDDLLLDLRLUU\\n7 -3\\n\", \"2\\nDD\\n0 0\\n\", \"69\\nLLRLLRLDLDLURLDRUUUULRDLLLURURUDLURDURRDRDRUUDUULRDLDRURLDUURRDRRULDL\\n0 -3\\n\", \"8\\nDDDRULDU\\n4 0\\n\", \"3\\nRLR\\n-3 0\\n\", \"45\\nDUDDURRUDUDRLRLULRUDUDLRULRDDDRUDRLRUDUURDULL\\n-2 -1\\n\", \"7\\nLUDDRRU\\n5 0\\n\", \"97\\nRRRUUULULRRLDDULLDRRRLRUDDDLDRLLULDUDUDLRUDRURDLUURDRDDDUULUDRRLDDRULURULRLDRDRDULUUUDULLDDLLDDDL\\n12 9\\n\", \"1\\nL\\n0 -1\\n\", \"1\\nU\\n1 0\\n\", \"83\\nLDRRLDRDUUURRRRULURRLLULDDULRRRRDDRUDRDRDDLDLDRLRULURDDLRRLRURURDURRRLULDRRDULRURUU\\n8 3\\n\", \"16\\nURRULDRLLUUDLULU\\n-9 7\\n\"], \"outputs\": [\"3\\n\", \"0\\n\", \"-1\\n\", \"-1\\n\", \"58\\n\", \"-1\\n\", \"-1\\n\", \"5\\n\", \"2\\n\", \"3\\n\", \"-1\\n\", \"-1\\n\", \"0\\n\", \"5\\n\", \"-1\\n\", \"1\\n\", \"4\\n\", \"-1\\n\", \"0\\n\", \"2\\n\", \"8\\n\", \"1\\n\", \"8\\n\", \"3\\n\", \"6\\n\", \"14\\n\", \"46\\n\", \"2\\n\", \"2\\n\", \"1\\n\", \"2\\n\", \"3\\n\", \"7\\n\", \"1\\n\", \"1\\n\", \"4\\n\", \"12\\n\", \"1\\n\", \"5\\n\", \"-1\\n\", \"3\\n\", \"7\\n\", \"1\\n\", \"2\\n\", \"2\\n\", \"0\\n\", \"-1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"3\\n\", \"5\\n\", \"1\\n\", \"2\\n\", \"8\\n\", \"8\\n\", \"8\\n\", \"1\\n\", \"6\\n\", \"0\\n\", \"9\\n\", \"1\\n\", \"-1\\n\", \"-1\\n\", \"4\\n\", \"3\\n\", \"3\\n\", \"4\\n\", \"7\\n\", \"3\\n\", \"5\\n\", \"4\\n\", \"3\\n\", \"6\\n\", \"2\\n\", \"9\\n\", \"10\\n\", \"4\\n\", \"12\\n\", \"2\\n\", \"1\\n\", \"8\\n\", \"17\\n\", \"14\\n\", \"12\\n\", \"9\\n\", \"-1\\n\", \"5\\n\", \"3\\n\", \"5\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"4\\n\", \"3\\n\", \"9\\n\", \"11\\n\", \"4\\n\", \"4\\n\", \"4\\n\", \"11\\n\", \"1\\n\", \"4\\n\", \"5\\n\", \"3\\n\", \"3\\n\", \"3\\n\", \"18\\n\", \"1\\n\", \"1\\n\", \"5\\n\", \"11\\n\"]}", "source": "primeintellect"}
|
Vasya has got a robot which is situated on an infinite Cartesian plane, initially in the cell $(0, 0)$. Robot can perform the following four kinds of operations: U — move from $(x, y)$ to $(x, y + 1)$; D — move from $(x, y)$ to $(x, y - 1)$; L — move from $(x, y)$ to $(x - 1, y)$; R — move from $(x, y)$ to $(x + 1, y)$.
Vasya also has got a sequence of $n$ operations. Vasya wants to modify this sequence so after performing it the robot will end up in $(x, y)$.
Vasya wants to change the sequence so the length of changed subsegment is minimum possible. This length can be calculated as follows: $maxID - minID + 1$, where $maxID$ is the maximum index of a changed operation, and $minID$ is the minimum index of a changed operation. For example, if Vasya changes RRRRRRR to RLRRLRL, then the operations with indices $2$, $5$ and $7$ are changed, so the length of changed subsegment is $7 - 2 + 1 = 6$. Another example: if Vasya changes DDDD to DDRD, then the length of changed subsegment is $1$.
If there are no changes, then the length of changed subsegment is $0$. Changing an operation means replacing it with some operation (possibly the same); Vasya can't insert new operations into the sequence or remove them.
Help Vasya! Tell him the minimum length of subsegment that he needs to change so that the robot will go from $(0, 0)$ to $(x, y)$, or tell him that it's impossible.
-----Input-----
The first line contains one integer number $n~(1 \le n \le 2 \cdot 10^5)$ — the number of operations.
The second line contains the sequence of operations — a string of $n$ characters. Each character is either U, D, L or R.
The third line contains two integers $x, y~(-10^9 \le x, y \le 10^9)$ — the coordinates of the cell where the robot should end its path.
-----Output-----
Print one integer — the minimum possible length of subsegment that can be changed so the resulting sequence of operations moves the robot from $(0, 0)$ to $(x, y)$. If this change is impossible, print $-1$.
-----Examples-----
Input
5
RURUU
-2 3
Output
3
Input
4
RULR
1 1
Output
0
Input
3
UUU
100 100
Output
-1
-----Note-----
In the first example the sequence can be changed to LULUU. So the length of the changed subsegment is $3 - 1 + 1 = 3$.
In the second example the given sequence already leads the robot to $(x, y)$, so the length of the changed subsegment is $0$.
In the third example the robot can't end his path in the cell $(x, y)$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1 3 8 1 1\\n\", \"4 2 9 4 2\\n\", \"5 5 25 4 3\\n\", \"100 100 1000000000000000000 100 100\\n\", \"3 2 15 2 2\\n\", \"4 1 8 3 1\\n\", \"3 2 8 2 1\\n\", \"4 2 9 4 1\\n\", \"1 3 7 1 1\\n\", \"2 2 8 2 1\\n\", \"3 1 6 2 1\\n\", \"5 6 30 5 4\\n\", \"3 8 134010 3 4\\n\", \"10 10 25 5 1\\n\", \"100 100 1000000000 16 32\\n\", \"100 100 1 23 39\\n\", \"1 1 1000000000 1 1\\n\", \"1 1 1 1 1\\n\", \"47 39 1772512 1 37\\n\", \"37 61 421692 24 49\\n\", \"89 97 875341288 89 96\\n\", \"100 1 1000000000000 100 1\\n\", \"1 100 1000000000000 1 100\\n\", \"2 4 6 1 4\\n\", \"2 4 6 1 3\\n\", \"2 4 49 1 1\\n\", \"3 3 26 1 1\\n\", \"5 2 77 4 2\\n\", \"2 5 73 2 3\\n\", \"5 2 81 5 1\\n\", \"4 5 93 1 2\\n\", \"4 4 74 4 1\\n\", \"5 3 47 2 1\\n\", \"5 4 61 1 1\\n\", \"4 4 95 1 1\\n\", \"2 5 36 1 3\\n\", \"5 2 9 5 1\\n\", \"4 1 50 1 1\\n\", \"3 2 83 1 2\\n\", \"3 5 88 1 5\\n\", \"4 2 89 1 2\\n\", \"2 1 1 1 1\\n\", \"5 3 100 2 1\\n\", \"4 4 53 3 1\\n\", \"4 3 1 3 3\\n\", \"3 5 1 2 1\\n\", \"5 2 2 4 1\\n\", \"3 3 1 3 2\\n\", \"1 1 1 1 1\\n\", \"1 1 100 1 1\\n\", \"4 30 766048376 1 23\\n\", \"3 90 675733187 1 33\\n\", \"11 82 414861345 1 24\\n\", \"92 10 551902461 1 6\\n\", \"18 83 706805205 1 17\\n\", \"1 12 943872212 1 1\\n\", \"91 15 237966754 78 6\\n\", \"58 66 199707458 15 9\\n\", \"27 34 77794947 24 4\\n\", \"22 89 981099971 16 48\\n\", \"10 44 222787770 9 25\\n\", \"9 64 756016805 7 55\\n\", \"91 86 96470485 12 43\\n\", \"85 53 576663715 13 1\\n\", \"2 21 196681588 2 18\\n\", \"8 29 388254841 6 29\\n\", \"2 59 400923999 2 43\\n\", \"3 71 124911502 1 67\\n\", \"1 17 523664480 1 4\\n\", \"11 27 151005021 3 15\\n\", \"7 32 461672865 4 11\\n\", \"2 90 829288586 1 57\\n\", \"17 5 370710486 2 1\\n\", \"88 91 6317 70 16\\n\", \"19 73 1193 12 46\\n\", \"84 10 405 68 8\\n\", \"92 80 20 9 69\\n\", \"69 21 203 13 16\\n\", \"63 22 1321 61 15\\n\", \"56 83 4572 35 22\\n\", \"36 19 684 20 15\\n\", \"33 2 1 8 2\\n\", \"76 74 1 38 39\\n\", \"1 71 1000000000000000000 1 5\\n\", \"13 89 1000000000000000000 10 14\\n\", \"1 35 1000000000000000000 1 25\\n\", \"81 41 1000000000000000000 56 30\\n\", \"4 39 1000000000000000000 3 32\\n\", \"21 49 1000000000000000000 18 11\\n\", \"91 31 1000000000000000000 32 7\\n\", \"51 99 1000000000000000000 48 79\\n\", \"5 99 1000000000000000000 4 12\\n\", \"100 100 1000000000000000000 1 1\\n\", \"100 100 1000000000000000000 31 31\\n\", \"1 100 1000000000000000000 1 1\\n\", \"1 100 1000000000000000000 1 35\\n\", \"100 1 1000000000000000000 1 1\\n\", \"100 1 1000000000000000000 35 1\\n\", \"1 1 1000000000000000000 1 1\\n\", \"3 2 5 1 1\\n\", \"100 100 10001 1 1\\n\", \"1 5 7 1 3\\n\", \"2 2 7 1 1\\n\", \"4 1 5 3 1\\n\", \"2 3 4 2 3\\n\", \"3 5 21 1 2\\n\", \"2 4 14 1 1\\n\", \"5 9 8 5 4\\n\", \"2 6 4 1 3\\n\", \"1 5 9 1 1\\n\", \"1 5 3 1 2\\n\"], \"outputs\": [\"3 2 3\", \"2 1 1\", \"1 1 1\", \"101010101010101 50505050505051 50505050505051\", \"4 2 3\", \"3 1 2\", \"2 1 2\", \"2 1 1\", \"3 2 3\", \"2 2 2\", \"3 1 3\", \"1 1 1\", \"8376 4188 4188\", \"1 0 0\", \"101011 50505 101010\", \"1 0 0\", \"1000000000 1000000000 1000000000\", \"1 1 1\", \"989 494 495\", \"192 96 192\", \"102547 51273 51274\", \"10101010101 5050505051 5050505051\", \"10000000000 10000000000 10000000000\", \"1 0 1\", \"1 0 1\", \"7 6 7\", \"4 2 3\", \"10 5 10\", \"8 7 7\", \"10 5 5\", \"6 3 4\", \"6 3 3\", \"4 2 4\", \"4 2 2\", \"8 4 4\", \"4 3 4\", \"1 0 1\", \"17 8 9\", \"21 10 11\", \"9 4 5\", \"15 7 8\", \"1 0 1\", \"9 4 9\", \"5 2 4\", \"1 0 0\", \"1 0 0\", \"1 0 0\", \"1 0 0\", \"1 1 1\", \"100 100 100\", \"8511649 4255824 4255825\", \"3754073 1877036 1877037\", \"505929 252964 252965\", \"606487 303243 303244\", \"500925 250462 250463\", \"78656018 78656017 78656018\", \"176272 88136 176272\", \"53086 26543 53085\", \"88004 44002 88004\", \"524934 262467 524933\", \"562596 281298 562596\", \"1476596 738298 1476595\", \"12464 6232 12464\", \"129530 64765 129529\", \"4682895 4682894 4682895\", \"1912586 956293 1912585\", \"3397662 3397661 3397661\", \"879658 439829 439829\", \"30803793 30803792 30803793\", \"559278 279639 559278\", \"2404547 1202273 2404546\", \"4607159 4607158 4607159\", \"4633882 2316941 4633881\", \"1 0 1\", \"1 0 1\", \"1 0 0\", \"1 0 0\", \"1 0 0\", \"1 0 0\", \"1 0 1\", \"1 1 1\", \"1 0 0\", \"1 0 0\", \"14084507042253522 14084507042253521 14084507042253522\", \"936329588014982 468164794007491 936329588014982\", \"28571428571428572 28571428571428571 28571428571428571\", \"304878048780488 152439024390244 304878048780488\", \"8547008547008547 4273504273504273 8547008547008547\", \"1020408163265307 510204081632653 1020408163265306\", \"358422939068101 179211469534050 358422939068101\", \"202020202020203 101010101010101 202020202020202\", \"2525252525252526 1262626262626263 2525252525252525\", \"101010101010101 50505050505051 50505050505051\", \"101010101010101 50505050505051 101010101010101\", \"10000000000000000 10000000000000000 10000000000000000\", \"10000000000000000 10000000000000000 10000000000000000\", \"10101010101010101 5050505050505051 5050505050505051\", \"10101010101010101 5050505050505051 10101010101010101\", \"1000000000000000000 1000000000000000000 1000000000000000000\", \"1 0 1\", \"2 1 1\", \"2 1 1\", \"2 1 2\", \"2 1 2\", \"1 0 0\", \"2 1 1\", \"2 1 2\", \"1 0 0\", \"1 0 1\", \"2 1 2\", \"1 0 1\"]}", "source": "primeintellect"}
|
On the Literature lesson Sergei noticed an awful injustice, it seems that some students are asked more often than others.
Seating in the class looks like a rectangle, where n rows with m pupils in each.
The teacher asks pupils in the following order: at first, she asks all pupils from the first row in the order of their seating, then she continues to ask pupils from the next row. If the teacher asked the last row, then the direction of the poll changes, it means that she asks the previous row. The order of asking the rows looks as follows: the 1-st row, the 2-nd row, ..., the n - 1-st row, the n-th row, the n - 1-st row, ..., the 2-nd row, the 1-st row, the 2-nd row, ...
The order of asking of pupils on the same row is always the same: the 1-st pupil, the 2-nd pupil, ..., the m-th pupil.
During the lesson the teacher managed to ask exactly k questions from pupils in order described above. Sergei seats on the x-th row, on the y-th place in the row. Sergei decided to prove to the teacher that pupils are asked irregularly, help him count three values: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei.
If there is only one row in the class, then the teacher always asks children from this row.
-----Input-----
The first and the only line contains five integers n, m, k, x and y (1 ≤ n, m ≤ 100, 1 ≤ k ≤ 10^18, 1 ≤ x ≤ n, 1 ≤ y ≤ m).
-----Output-----
Print three integers: the maximum number of questions a particular pupil is asked, the minimum number of questions a particular pupil is asked, how many times the teacher asked Sergei.
-----Examples-----
Input
1 3 8 1 1
Output
3 2 3
Input
4 2 9 4 2
Output
2 1 1
Input
5 5 25 4 3
Output
1 1 1
Input
100 100 1000000000000000000 100 100
Output
101010101010101 50505050505051 50505050505051
-----Note-----
The order of asking pupils in the first test: the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table; the pupil from the first row who seats at the third table; the pupil from the first row who seats at the first table, it means it is Sergei; the pupil from the first row who seats at the second table;
The order of asking pupils in the second test: the pupil from the first row who seats at the first table; the pupil from the first row who seats at the second table; the pupil from the second row who seats at the first table; the pupil from the second row who seats at the second table; the pupil from the third row who seats at the first table; the pupil from the third row who seats at the second table; the pupil from the fourth row who seats at the first table; the pupil from the fourth row who seats at the second table, it means it is Sergei; the pupil from the third row who seats at the first table;
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\nKuroo\\nShiro\\nKatie\\n\", \"7\\ntreasurehunt\\nthreefriends\\nhiCodeforces\\n\", \"1\\nabcabc\\ncbabac\\nababca\\n\", \"15\\nfoPaErcvJ\\nmZaxowpbt\\nmkuOlaHRE\\n\", \"1\\naaaaaaaaaa\\nAAAAAAcAAA\\nbbbbbbzzbb\\n\", \"60\\nddcZYXYbZbcXYcZdYbddaddYaZYZdaZdZZdXaaYdaZZZaXZXXaaZbb\\ndcdXcYbcaXYaXYcacYabYcbZYdacaYbYdXaccYXZZZdYbbYdcZZZbY\\nXaZXbbdcXaadcYdYYcbZdcaXaYZabbXZZYbYbcXbaXabcXbXadbZYZ\\n\", \"9174\\nbzbbbzzzbbzzccczzccczzbzbzcbzbbzccbzcccbccczzbbcbbzbzzzcbczbzbzzbbbczbbcbzzzbcbzczbcczb\\ndbzzzccdcdczzzzzcdczbbzcdzbcdbzzdczbzddcddbdbzzzczcczzbdcbbzccbzzzdzbzddcbzbdzdcczccbdb\\nzdczddzcdddddczdczdczdcdzczddzczdzddczdcdcdzczczzdzccdccczczdzczczdzcdddzddzccddcczczzd\\n\", \"727\\nbaabbabbbababbbbaaaabaabbaabababaaababaaababbbbababbbbbbbbbbaaabaabbbbbbbbaaaabaabbaaabaabbabaa\\nddcdcccccccdccdcdccdddcddcddcddddcdddcdcdccddcdddddccddcccdcdddcdcccdccccccdcdcdccccccdccccccdc\\nfffeefeffeefeeeeffefffeeefffeefffefeefefeeeffefefefefefefffffffeeeeeffffeefeeeeffffeeeeeefeffef\\n\", \"61\\nbzqiqprzfwddqwctcrhnkqcsnbmcmfmrgaljwieajfouvuiunmfbrehxchupmsdpwilwu\\njyxxujvxkwilikqeegzxlyiugflxqqbwbujzedqnlzucdnuipacatdhcozuvgktwvirhs\\ntqiahohijwfcetyyjlkfhfvkhdgllxmhyyhhtlhltcdspusyhwpwqzyagtsbaswaobwub\\n\", \"30\\njAjcdwkvcTYSYBBLniJIIIiubKWnqeDtUiaXSIPfhDTOrCWBQetm\\nPQPOTgqfBWzQvPNeEaUaPQGdUgldmOZsBtsIqZGGyXozntMpOsyY\\nNPfvGxMqIULNWOmUrHJfsqORUHkzKQfecXsTzgFCmUtFmIBudCJr\\n\", \"3\\nabcabcabcabcdddabc\\nzxytzytxxtytxyzxyt\\nfgffghfghffgghghhh\\n\", \"3\\naaaaa\\naaaaa\\naaaab\\n\", \"3\\naaaaaaa\\naaaabcd\\nabcdefg\\n\", \"3\\naaaaaaa\\naaabcde\\nabcdefg\\n\", \"3\\naaaaaaa\\naaaabbb\\nabcdefg\\n\", \"3\\naaa\\nbbb\\nabc\\n\", \"3\\naaaaa\\nabcde\\nabcde\\n\", \"3\\naaaaa\\nqwert\\nlkjhg\\n\", \"3\\naaaaa\\nbbbbb\\naabcd\\n\", \"3\\nabcde\\nfghij\\nkkkkk\\n\", \"4\\naaaabcd\\naaaabcd\\naaaaaaa\\n\", \"3\\naaaabb\\naabcde\\nabcdef\\n\", \"2\\naaab\\nabcd\\naaaa\\n\", \"3\\naaaaaa\\naaaaaa\\nabcdef\\n\", \"1\\nAAAAA\\nBBBBB\\nABCDE\\n\", \"1\\nabcde\\naaaaa\\naaaaa\\n\", \"4\\naaabbb\\nabfcde\\nabfcde\\n\", \"0\\naaa\\naab\\nccd\\n\", \"3\\naaaaa\\naaaaa\\naabbb\\n\", \"3\\nxxxxxx\\nxxxooo\\nabcdef\\n\", \"2\\noooo\\naaac\\nabcd\\n\", \"1\\naaaaaaa\\naaabcde\\nabcdefg\\n\", \"3\\nooooo\\naaabb\\nabcde\\n\", \"3\\naaaaa\\nqwert\\nqwery\\n\", \"2\\naaaaaa\\nbbbbbb\\naaaaab\\n\", \"3\\naabb\\naabb\\naabc\\n\", \"2\\naaa\\naab\\naab\\n\", \"3\\nbbbbcc\\nbbbbbb\\nsadfgh\\n\", \"3\\naaaaaacc\\nxxxxkkkk\\nxxxxkkkk\\n\", \"2\\naaaac\\nbbbbc\\nccccc\\n\", \"3\\naaaaaaaaa\\naaabbbbbb\\nabcdewert\\n\", \"3\\naaabc\\naaaab\\nabcde\\n\", \"3\\naaaaaaaa\\naaaaaaab\\naaaabbbb\\n\", \"2\\nabcdefg\\nabccccc\\nacccccc\\n\", \"3\\naaaaa\\naabcd\\nabcde\\n\", \"4\\naaabbb\\nabcdef\\nabcdef\\n\", \"4\\naaabbb\\naabdef\\nabcdef\\n\", \"3\\nabba\\nbbbb\\naaaa\\n\", \"3\\naaaaa\\nbbaaa\\nabcde\\n\", \"2\\naaa\\naaa\\nabc\\n\", \"3\\naaaaa\\nabcda\\nabcde\\n\", \"3\\naaaaa\\nabcde\\nbcdef\\n\", \"3\\naaabb\\naabbc\\nqwert\\n\", \"3\\naaaaaa\\naabbcc\\naabbcc\\n\", \"3\\nAAAAAA\\nAAAAAB\\nABCDEF\\n\", \"3\\nabc\\naac\\nbbb\\n\", \"2\\naaaab\\naabbc\\naabbc\\n\", \"2\\naaaaaab\\naaaaabb\\nabcdefg\\n\", \"3\\naaaaaaaaaaa\\nbbbbbbbbaaa\\nqwertyuiasd\\n\", \"3\\naaaa\\nbbbb\\naabb\\n\", \"3\\naaaabb\\naaabcd\\nabcdef\\n\", \"3\\naaa\\nabc\\nbbb\\n\", \"1\\naa\\nab\\nbb\\n\", \"1\\naacb\\nabcd\\naaaa\\n\", \"3\\naaaabb\\naaabbb\\nabcdef\\n\", \"3\\naaaa\\naaaa\\nabcd\\n\", \"2\\nabcd\\nabcd\\naaad\\n\", \"3\\naaa\\nbbb\\naab\\n\", \"3\\naaaaaa\\naaaaab\\naaaaaa\\n\", \"2\\naaab\\nabcd\\nabcd\\n\", \"3\\nooooo\\nShiro\\nKatie\\n\", \"3\\naaabb\\naabcd\\nabcde\\n\", \"4\\nabcd\\nabcd\\naaaa\\n\", \"4\\naaa\\nbbb\\naab\\n\", \"2\\nxxxx\\nyyyx\\nabcd\\n\", \"3\\nAAAAA\\nAAAAB\\nABCDE\\n\", \"3\\naaaacdc\\naaaaabc\\naaaaabc\\n\", \"3\\naaaaaa\\naabcde\\naabcde\\n\", \"3\\naaabb\\naaabb\\naaaaa\\n\", \"5\\nabbbbb\\ncbbbbb\\nabcdef\\n\", \"3\\naaaaaaaaa\\naaaaabbbb\\naaaaabbbb\\n\", \"4\\naaaaaab\\naaabbbb\\naaabbbb\\n\", \"3\\naaaabb\\naaaabb\\naaabbb\\n\", \"2\\naaaabb\\naaaaab\\nabcdef\\n\", \"2\\naaaaa\\naaaae\\nabcde\\n\", \"3\\naaaaaa\\nbbbcde\\nabcdef\\n\", \"4\\naaaabbb\\naabcdef\\naabcdef\\n\", \"2\\naaaaa\\naaaab\\nabcde\\n\", \"3\\naabbbbb\\naaabbbb\\nabcdefg\\n\", \"3\\nabcde\\naabcd\\naaaaa\\n\", \"5\\naaabbcc\\nabcdefg\\nabcdefg\\n\", \"3\\naabbb\\nabcde\\nabcde\\n\", \"0\\nbbb\\nabb\\nqer\\n\", \"5\\naabbbbb\\naaaaaaa\\nabcdefg\\n\", \"2\\naaaab\\naaaab\\naaabb\\n\", \"2\\naaaaaab\\naaaabbb\\naaaaccc\\n\", \"3\\naaaaaaaaaaaa\\naaaaaaaaaaab\\naaaaaabbbbbb\\n\", \"3\\naaabb\\nabcde\\naaaaa\\n\", \"3\\naaaaaac\\naaaaebc\\naaaaaac\\n\", \"3\\naaaaaa\\naaabbb\\nqwerty\\n\", \"3\\ncccca\\nabcde\\nabcde\\n\", \"100005\\nAA\\nBC\\nCC\\n\", \"3\\naaaa\\nbbbb\\nccca\\n\", \"3\\naaaaa\\nbcdef\\nbcdef\\n\", \"2\\naaab\\naabb\\nqwer\\n\", \"3\\nabcddd\\nabcdef\\nbbaaaa\\n\", \"2\\naaaa\\naaaa\\naabc\\n\", \"3\\naaaa\\naaaa\\naaab\\n\", \"3\\nabcddd\\nabcdef\\naaaaaa\\n\", \"1\\naaaa\\nabcd\\naaab\\n\"], \"outputs\": [\"Kuro\\n\", \"Shiro\\n\", \"Katie\\n\", \"Draw\\n\", \"Shiro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Katie\\n\", \"Draw\\n\", \"Katie\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Kuro\\n\", \"Draw\\n\", \"Katie\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Shiro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Katie\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Kuro\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Kuro\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Draw\\n\", \"Katie\\n\"]}", "source": "primeintellect"}
|
After the big birthday party, Katie still wanted Shiro to have some more fun. Later, she came up with a game called treasure hunt. Of course, she invited her best friends Kuro and Shiro to play with her.
The three friends are very smart so they passed all the challenges very quickly and finally reached the destination. But the treasure can only belong to one cat so they started to think of something which can determine who is worthy of the treasure. Instantly, Kuro came up with some ribbons.
A random colorful ribbon is given to each of the cats. Each color of the ribbon can be represented as an uppercase or lowercase Latin letter. Let's call a consecutive subsequence of colors that appears in the ribbon a subribbon. The beauty of a ribbon is defined as the maximum number of times one of its subribbon appears in the ribbon. The more the subribbon appears, the more beautiful is the ribbon. For example, the ribbon aaaaaaa has the beauty of $7$ because its subribbon a appears $7$ times, and the ribbon abcdabc has the beauty of $2$ because its subribbon abc appears twice.
The rules are simple. The game will have $n$ turns. Every turn, each of the cats must change strictly one color (at one position) in his/her ribbon to an arbitrary color which is different from the unchanged one. For example, a ribbon aaab can be changed into acab in one turn. The one having the most beautiful ribbon after $n$ turns wins the treasure.
Could you find out who is going to be the winner if they all play optimally?
-----Input-----
The first line contains an integer $n$ ($0 \leq n \leq 10^{9}$) — the number of turns.
Next 3 lines contain 3 ribbons of Kuro, Shiro and Katie one per line, respectively. Each ribbon is a string which contains no more than $10^{5}$ uppercase and lowercase Latin letters and is not empty. It is guaranteed that the length of all ribbons are equal for the purpose of fairness. Note that uppercase and lowercase letters are considered different colors.
-----Output-----
Print the name of the winner ("Kuro", "Shiro" or "Katie"). If there are at least two cats that share the maximum beauty, print "Draw".
-----Examples-----
Input
3
Kuroo
Shiro
Katie
Output
Kuro
Input
7
treasurehunt
threefriends
hiCodeforces
Output
Shiro
Input
1
abcabc
cbabac
ababca
Output
Katie
Input
15
foPaErcvJ
mZaxowpbt
mkuOlaHRE
Output
Draw
-----Note-----
In the first example, after $3$ turns, Kuro can change his ribbon into ooooo, which has the beauty of $5$, while reaching such beauty for Shiro and Katie is impossible (both Shiro and Katie can reach the beauty of at most $4$, for example by changing Shiro's ribbon into SSiSS and changing Katie's ribbon into Kaaaa). Therefore, the winner is Kuro.
In the fourth example, since the length of each of the string is $9$ and the number of turn is $15$, everyone can change their ribbons in some way to reach the maximal beauty of $9$ by changing their strings into zzzzzzzzz after 9 turns, and repeatedly change their strings into azzzzzzzz and then into zzzzzzzzz thrice. Therefore, the game ends in a draw.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.375
|
{"tests": "{\"inputs\": [\"27\\n\", \"3\\n\", \"25\\n\", \"9\\n\", \"91\\n\", \"57\\n\", \"31\\n\", \"555\\n\", \"700000001\\n\", \"5\\n\", \"7\\n\", \"11\\n\", \"13\\n\", \"15\\n\", \"17\\n\", \"19\\n\", \"21\\n\", \"23\\n\", \"29\\n\", \"79\\n\", \"99\\n\", \"27\\n\", \"55\\n\", \"79\\n\", \"585\\n\", \"245\\n\", \"793\\n\", \"133\\n\", \"681\\n\", \"981399\\n\", \"867773\\n\", \"654141\\n\", \"202985\\n\", \"784533\\n\", \"370359\\n\", \"396831\\n\", \"492211\\n\", \"838347\\n\", \"1098945\\n\", \"1313565\\n\", \"1349631\\n\", \"1357299\\n\", \"1357323\\n\", \"1357329\\n\", \"1388581\\n\", \"5275\\n\", \"9515\\n\", \"7847\\n\", \"7077\\n\", \"9531\\n\", \"7865\\n\", \"9675\\n\", \"8909\\n\", \"7147\\n\", \"8487\\n\", \"436273289\\n\", \"649580445\\n\", \"944193065\\n\", \"630045387\\n\", \"931103229\\n\", \"950664039\\n\", \"996104777\\n\", \"997255617\\n\", \"999962901\\n\", \"999995529\\n\", \"999995339\\n\", \"999998367\\n\", \"999999891\\n\", \"999999935\\n\", \"999999755\\n\", \"999999759\\n\", \"999999191\\n\", \"999999999\\n\", \"409449117\\n\", \"882499837\\n\", \"765615965\\n\", \"648732093\\n\", \"826815517\\n\", \"4898941\\n\", \"182982365\\n\", \"66098493\\n\", \"539149213\\n\", \"655957385\\n\", \"199999581\\n\", \"199998345\\n\", \"199991935\\n\", \"199986207\\n\", \"499991589\\n\", \"499984689\\n\", \"499984159\\n\", \"499966179\\n\", \"999995529\\n\", \"999995085\\n\", \"999991817\\n\", \"999991797\\n\", \"999991791\\n\", \"748859699\\n\", \"323845235\\n\", \"462409937\\n\", \"618047403\\n\", \"501148647\\n\", \"998017623\\n\", \"436273289\\n\", \"999999965\\n\", \"5\\n\", \"1000037\\n\", \"989898987\\n\", \"999999999\\n\", \"100000003\\n\"], \"outputs\": [\"3\\n2 2 23\", \"1\\n3\", \"2\\n2 23\", \"2\\n2 7\", \"2\\n2 89\", \"3\\n2 2 53\", \"1\\n31\", \"3\\n3 5 547\", \"1\\n700000001\", \"1\\n5\", \"1\\n7\", \"1\\n11\", \"1\\n13\", \"2\\n2 13\", \"1\\n17\", \"1\\n19\", \"2\\n2 19\", \"1\\n23\", \"1\\n29\", \"1\\n79\", \"2\\n2 97\", \"3\\n2 2 23\", \"2\\n2 53\", \"1\\n79\", \"3\\n3 5 577\", \"3\\n2 2 241\", \"3\\n3 3 787\", \"2\\n2 131\", \"3\\n2 2 677\", \"2\\n2 981397\", \"1\\n867773\", \"3\\n3 11 654127\", \"3\\n2 2 202981\", \"3\\n3 17 784513\", \"3\\n19 79 370261\", \"3\\n19 79 396733\", \"3\\n19 79 492113\", \"3\\n19 79 838249\", \"3\\n19 79 1098847\", \"3\\n19 79 1313467\", \"3\\n19 79 1349533\", \"3\\n19 79 1357201\", \"3\\n13 109 1357201\", \"3\\n19 109 1357201\", \"3\\n19 79 1388483\", \"2\\n2 5273\", \"3\\n2 2 9511\", \"3\\n3 3 7841\", \"3\\n3 5 7069\", \"3\\n3 7 9521\", \"3\\n5 7 7853\", \"3\\n3 11 9661\", \"3\\n3 13 8893\", \"3\\n5 13 7129\", \"3\\n3 17 8467\", \"3\\n3 277 436273009\", \"3\\n3 271 649580171\", \"3\\n7 251 944192807\", \"3\\n11 239 630045137\", \"3\\n3 223 931103003\", \"3\\n3 197 950663839\", \"3\\n7 173 996104597\", \"3\\n7 157 997255453\", \"3\\n19 109 999962773\", \"3\\n19 79 999995431\", \"3\\n5 43 999995291\", \"3\\n5 23 999998339\", \"3\\n3 5 999999883\", \"3\\n3 3 999999929\", \"3\\n2 2 999999751\", \"2\\n2 999999757\", \"1\\n999999191\", \"3\\n3 59 999999937\", \"3\\n2 2 409449113\", \"3\\n3 3 882499831\", \"3\\n5 23 765615937\", \"3\\n3 11 648732079\", \"3\\n3 11 826815503\", \"2\\n2 4898939\", \"3\\n5 13 182982347\", \"3\\n3 41 66098449\", \"1\\n539149213\", \"3\\n3 13 655957369\", \"3\\n19 79 199999483\", \"3\\n19 79 199998247\", \"3\\n19 79 199991837\", \"3\\n19 79 199986109\", \"3\\n19 79 499991491\", \"3\\n19 79 499984591\", \"3\\n19 79 499984061\", \"3\\n19 79 499966081\", \"3\\n19 79 999995431\", \"3\\n19 79 999994987\", \"3\\n11 137 999991669\", \"3\\n19 109 999991669\", \"3\\n13 109 999991669\", \"3\\n3 3 748859693\", \"3\\n3 3 323845229\", \"3\\n2 2 462409933\", \"3\\n3 13 618047387\", \"3\\n2 2 501148643\", \"2\\n2 998017621\", \"3\\n3 277 436273009\", \"3\\n5 23 999999937\", \"1\\n5\", \"1\\n1000037\", \"3\\n2 2 989898983\", \"3\\n3 59 999999937\", \"3\\n3 11 99999989\"]}", "source": "primeintellect"}
|
Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.
More formally, you are given an odd numer n. Find a set of numbers p_{i} (1 ≤ i ≤ k), such that
1 ≤ k ≤ 3
p_{i} is a prime
$\sum_{i = 1}^{k} p_{i} = n$
The numbers p_{i} do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.
-----Input-----
The single line contains an odd number n (3 ≤ n < 10^9).
-----Output-----
In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found.
In the second line print numbers p_{i} in any order. If there are multiple possible solutions, you can print any of them.
-----Examples-----
Input
27
Output
3
5 11 11
-----Note-----
A prime is an integer strictly larger than one that is divisible only by one and by itself.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 4\\n.*..\\n....\\n.*..\\n\", \"3 3\\n..*\\n.*.\\n*..\\n\", \"6 5\\n..*..\\n..*..\\n*****\\n..*..\\n..*..\\n..*..\\n\", \"1 10\\n**********\\n\", \"10 1\\n*\\n*\\n*\\n*\\n*\\n*\\n*\\n*\\n*\\n*\\n\", \"10 10\\n.........*\\n.........*\\n........**\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n\", \"10 10\\n..........\\n..........\\n....*.....\\n..........\\n..........\\n**..*.****\\n....*.....\\n....*.....\\n....*.....\\n..........\\n\", \"10 10\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n.........*\\n\", \"10 10\\n..........\\n..........\\n....*.....\\n..........\\n..........\\n..........\\n....*.....\\n....*.....\\n....*.....\\n..........\\n\", \"10 10\\n..........\\n..........\\n.**....***\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n\", \"10 10\\n..........\\n..........\\n..........\\n..........\\n..........\\n***.*.****\\n..........\\n..........\\n..........\\n..........\\n\", \"10 10\\n........*.\\n*.........\\n........*.\\n........*.\\n..........\\n..........\\n..........\\n........*.\\n.....*..*.\\n***.......\\n\", \"10 10\\n...*......\\n..........\\n.......*..\\n.*........\\n******.*.*\\n.*........\\n..........\\n..........\\n..........\\n..........\\n\", \"4 4\\n....\\n....\\n....\\n....\\n\", \"2 2\\n.*\\n*.\\n\", \"4 4\\n....\\n...*\\n....\\n*..*\\n\", \"4 4\\n*...\\n*...\\n....\\n****\\n\", \"4 4\\n..*.\\n....\\n...*\\n....\\n\", \"4 4\\n***.\\n....\\n*...\\n....\\n\", \"1 1\\n*\\n\", \"1 1\\n.\\n\", \"1 2\\n.*\\n\", \"1 3\\n...\\n\", \"2 1\\n.\\n*\\n\", \"2 2\\n**\\n**\\n\", \"2 3\\n*.*\\n...\\n\", \"3 1\\n*\\n*\\n*\\n\", \"3 2\\n*.\\n.*\\n.*\\n\", \"3 3\\n***\\n***\\n***\\n\", \"10 20\\n....................\\n.........*..........\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n...*................\\n....................\\n\", \"10 20\\n....................\\n.........*..........\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n...*..............*.\\n....................\\n\", \"10 20\\n....................\\n.........*..........\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n...*..............*.\\n.........*..........\\n\", \"10 20\\n....................\\n.........*..........\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n...*.....*........*.\\n.........*..........\\n\", \"2 2\\n..\\n.*\\n\", \"6 5\\n..*..\\n..*..\\n**.**\\n..*..\\n..*..\\n..*..\\n\", \"3 3\\n.*.\\n*.*\\n.*.\\n\", \"4 4\\n*...\\n....\\n....\\n...*\\n\", \"2 4\\n...*\\n...*\\n\", \"2 2\\n..\\n..\\n\", \"4 4\\n...*\\n....\\n....\\n*...\\n\", \"3 4\\n....\\n..*.\\n....\\n\", \"3 3\\n..*\\n.*.\\n..*\\n\", \"3 3\\n...\\n...\\n...\\n\", \"2 2\\n*.\\n.*\\n\", \"5 7\\n...*...\\n...*...\\n...*...\\n..*.*..\\n...*...\\n\", \"4 4\\n....\\n.*..\\n..*.\\n....\\n\", \"3 2\\n.*\\n*.\\n.*\\n\", \"3 12\\n...**.......\\n.....**.....\\n........*...\\n\", \"3 3\\n***\\n.*.\\n.*.\\n\", \"4 4\\n*.*.\\n..*.\\n.***\\n..*.\\n\", \"2 3\\n..*\\n**.\\n\", \"5 5\\n.....\\n.....\\n..*..\\n.....\\n.....\\n\", \"3 2\\n*.\\n.*\\n*.\\n\", \"5 5\\n.....\\n.....\\n.....\\n.....\\n.....\\n\", \"4 4\\n..*.\\n**.*\\n..*.\\n..*.\\n\", \"4 4\\n....\\n....\\n..*.\\n....\\n\", \"3 3\\n*..\\n*..\\n***\\n\", \"3 3\\n...\\n*.*\\n.*.\\n\", \"3 2\\n..\\n..\\n**\\n\", \"3 4\\n...*\\n...*\\n...*\\n\", \"4 4\\n.***\\n*...\\n*...\\n*...\\n\", \"5 5\\n..*..\\n..*..\\n**.**\\n..*..\\n..*..\\n\", \"6 5\\n..*..\\n..*..\\n*****\\n..*..\\n..*..\\n..*.*\\n\", \"3 3\\n...\\n.*.\\n..*\\n\", \"3 5\\n....*\\n....*\\n....*\\n\", \"3 3\\n...\\n...\\n.*.\\n\", \"3 3\\n*.*\\n.*.\\n...\\n\", \"3 3\\n*..\\n...\\n..*\\n\", \"2 3\\n..*\\n..*\\n\", \"2 2\\n**\\n.*\\n\", \"5 5\\n.....\\n..*..\\n.*.*.\\n..*..\\n.....\\n\", \"3 3\\n.*.\\n..*\\n...\\n\", \"3 3\\n..*\\n*..\\n*..\\n\", \"3 3\\n...\\n.*.\\n...\\n\", \"3 4\\n....\\n....\\n....\\n\", \"10 10\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n..........\\n\", \"5 4\\n.*..\\n*.**\\n.*..\\n.*..\\n.*..\\n\", \"3 3\\n..*\\n*..\\n...\\n\", \"3 3\\n*..\\n.*.\\n...\\n\", \"6 5\\n*.*..\\n..*..\\n*****\\n..*..\\n..*..\\n..*..\\n\", \"4 4\\n.*..\\n*.**\\n....\\n.*..\\n\", \"3 5\\n....*\\n....*\\n*****\\n\", \"3 3\\n..*\\n*..\\n..*\\n\", \"6 6\\n..*...\\n......\\n......\\n......\\n......\\n*....*\\n\", \"3 3\\n***\\n.*.\\n...\\n\", \"4 4\\n.*..\\n*...\\n.*..\\n.*..\\n\", \"3 3\\n...\\n..*\\n.*.\\n\", \"3 2\\n.*\\n*.\\n*.\\n\", \"4 2\\n**\\n.*\\n.*\\n.*\\n\", \"5 5\\n*...*\\n.....\\n.....\\n.....\\n..*..\\n\", \"3 3\\n**.\\n...\\n..*\\n\", \"3 3\\n*.*\\n*..\\n*.*\\n\", \"5 4\\n....\\n....\\n*..*\\n....\\n.*..\\n\", \"5 5\\n...*.\\n...*.\\n...*.\\n...*.\\n***.*\\n\", \"5 5\\n*****\\n*****\\n*****\\n*****\\n*****\\n\", \"3 3\\n.*.\\n*..\\n...\\n\", \"3 3\\n.*.\\n..*\\n.*.\\n\", \"5 3\\n.*.\\n.*.\\n.*.\\n***\\n...\\n\", \"3 3\\n*.*\\n...\\n*.*\\n\", \"2 3\\n.*.\\n*.*\\n\", \"3 10\\n.......*..\\n........*.\\n.........*\\n\", \"3 3\\n*..\\n**.\\n...\\n\", \"3 3\\n.*.\\n.*.\\n.**\\n\", \"2 4\\n....\\n....\\n\", \"4 4\\n*...\\n....\\n....\\n..**\\n\", \"4 4\\n****\\n****\\n****\\n****\\n\", \"5 5\\n.*...\\n.....\\n...*.\\n...*.\\n.....\\n\", \"3 2\\n.*\\n.*\\n*.\\n\", \"3 3\\n..*\\n..*\\n**.\\n\", \"6 3\\n...\\n...\\n...\\n...\\n**.\\n.*.\\n\", \"3 4\\n****\\n..*.\\n..*.\\n\", \"5 5\\n*..*.\\n.....\\n.....\\n.....\\n...*.\\n\", \"3 4\\n.*..\\n*.**\\n....\\n\", \"6 5\\n..*..\\n..*..\\n.*...\\n..*..\\n..*..\\n..*..\\n\"], \"outputs\": [\"YES\\n1 2\\n\", \"NO\\n\", \"YES\\n3 3\\n\", \"YES\\n1 1\\n\", \"YES\\n1 1\\n\", \"YES\\n3 10\\n\", \"YES\\n6 5\\n\", \"YES\\n1 10\\n\", \"YES\\n1 5\\n\", \"YES\\n3 2\\n\", \"YES\\n6 1\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1 1\\n\", \"YES\\n2 2\\n\", \"YES\\n4 4\\n\", \"YES\\n4 1\\n\", \"YES\\n3 3\\n\", \"YES\\n1 1\\n\", \"YES\\n1 1\\n\", \"YES\\n1 1\\n\", \"YES\\n1 2\\n\", \"YES\\n1 1\\n\", \"YES\\n1 1\\n\", \"NO\\n\", \"YES\\n1 1\\n\", \"YES\\n1 1\\n\", \"YES\\n1 2\\n\", \"NO\\n\", \"YES\\n9 10\\n\", \"YES\\n9 10\\n\", \"YES\\n9 10\\n\", \"YES\\n9 10\\n\", \"YES\\n1 2\\n\", \"YES\\n3 3\\n\", \"YES\\n2 2\\n\", \"YES\\n4 1\\n\", \"YES\\n1 4\\n\", \"YES\\n1 1\\n\", \"YES\\n4 4\\n\", \"YES\\n1 3\\n\", \"YES\\n2 3\\n\", \"YES\\n1 1\\n\", \"YES\\n2 1\\n\", \"YES\\n4 4\\n\", \"YES\\n3 2\\n\", \"YES\\n2 2\\n\", \"NO\\n\", \"YES\\n1 2\\n\", \"NO\\n\", \"YES\\n2 3\\n\", \"YES\\n1 3\\n\", \"YES\\n2 1\\n\", \"YES\\n1 1\\n\", \"YES\\n2 3\\n\", \"YES\\n1 3\\n\", \"YES\\n3 1\\n\", \"YES\\n2 2\\n\", \"YES\\n3 1\\n\", \"YES\\n1 4\\n\", \"YES\\n1 1\\n\", \"YES\\n3 3\\n\", \"NO\\n\", \"YES\\n3 2\\n\", \"YES\\n1 5\\n\", \"YES\\n1 2\\n\", \"YES\\n1 2\\n\", \"YES\\n3 1\\n\", \"YES\\n1 3\\n\", \"YES\\n1 2\\n\", \"YES\\n3 3\\n\", \"YES\\n2 2\\n\", \"YES\\n1 1\\n\", \"YES\\n1 2\\n\", \"YES\\n1 1\\n\", \"YES\\n1 1\\n\", \"YES\\n2 2\\n\", \"YES\\n2 3\\n\", \"YES\\n2 1\\n\", \"NO\\n\", \"YES\\n2 2\\n\", \"YES\\n3 5\\n\", \"YES\\n2 3\\n\", \"YES\\n6 3\\n\", \"YES\\n1 2\\n\", \"YES\\n2 2\\n\", \"YES\\n3 3\\n\", \"YES\\n1 1\\n\", \"YES\\n1 2\\n\", \"YES\\n1 3\\n\", \"YES\\n1 3\\n\", \"NO\\n\", \"YES\\n3 2\\n\", \"YES\\n5 4\\n\", \"NO\\n\", \"YES\\n2 2\\n\", \"YES\\n2 2\\n\", \"YES\\n4 2\\n\", \"NO\\n\", \"YES\\n2 2\\n\", \"NO\\n\", \"YES\\n2 1\\n\", \"YES\\n3 2\\n\", \"YES\\n1 1\\n\", \"YES\\n4 1\\n\", \"NO\\n\", \"YES\\n1 4\\n\", \"YES\\n3 2\\n\", \"YES\\n3 3\\n\", \"YES\\n5 2\\n\", \"YES\\n1 3\\n\", \"YES\\n1 4\\n\", \"YES\\n2 2\\n\", \"YES\\n3 3\\n\"]}", "source": "primeintellect"}
|
You are given a description of a depot. It is a rectangular checkered field of n × m size. Each cell in a field can be empty (".") or it can be occupied by a wall ("*").
You have one bomb. If you lay the bomb at the cell (x, y), then after triggering it will wipe out all walls in the row x and all walls in the column y.
You are to determine if it is possible to wipe out all walls in the depot by placing and triggering exactly one bomb. The bomb can be laid both in an empty cell or in a cell occupied by a wall.
-----Input-----
The first line contains two positive integers n and m (1 ≤ n, m ≤ 1000) — the number of rows and columns in the depot field.
The next n lines contain m symbols "." and "*" each — the description of the field. j-th symbol in i-th of them stands for cell (i, j). If the symbol is equal to ".", then the corresponding cell is empty, otherwise it equals "*" and the corresponding cell is occupied by a wall.
-----Output-----
If it is impossible to wipe out all walls by placing and triggering exactly one bomb, then print "NO" in the first line (without quotes).
Otherwise print "YES" (without quotes) in the first line and two integers in the second line — the coordinates of the cell at which the bomb should be laid. If there are multiple answers, print any of them.
-----Examples-----
Input
3 4
.*..
....
.*..
Output
YES
1 2
Input
3 3
..*
.*.
*..
Output
NO
Input
6 5
..*..
..*..
*****
..*..
..*..
..*..
Output
YES
3 3
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1\\n\", \"2\\n\", \"4\\n\", \"3\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\", \"100000\\n\", \"99991\\n\", \"30030\\n\", \"99594\\n\", \"91402\\n\", \"93493\\n\", \"96917\\n\", \"80555\\n\", \"30238\\n\", \"5447\\n\", \"5714\\n\", \"735\\n\", \"64\\n\", \"256\\n\", \"2048\\n\", \"32768\\n\", \"65536\\n\", \"23\\n\", \"12167\\n\", \"13\\n\", \"14\\n\", \"15\\n\", \"16\\n\", \"17\\n\", \"18\\n\", \"19\\n\", \"20\\n\", \"10609\\n\", \"93179\\n\", \"10859\\n\", \"677\\n\", \"919\\n\", \"7635\\n\", \"95835\\n\", \"92138\\n\", \"29019\\n\", \"64444\\n\", \"88373\\n\", \"88439\\n\", \"7710\\n\", \"7404\\n\", \"8616\\n\", \"92386\\n\", \"99622\\n\", \"92171\\n\", \"99360\\n\", \"90661\\n\", \"92213\\n\", \"91068\\n\", \"93378\\n\", \"98179\\n\", \"91286\\n\", \"91568\\n\", \"91086\\n\", \"95539\\n\", \"90740\\n\", \"94998\\n\", \"95042\\n\", \"92239\\n\", \"78088\\n\", \"74792\\n\", \"22028\\n\", \"36884\\n\", \"66917\\n\", \"36312\\n\", \"79162\\n\", \"42626\\n\", \"6752\\n\", \"611\\n\", \"2864\\n\", \"9304\\n\", \"1045\\n\", \"9376\\n\", \"8636\\n\", \"75232\\n\", \"48457\\n\", \"60255\\n\", \"54369\\n\", \"46654\\n\", \"83480\\n\", \"22799\\n\", \"68540\\n\", \"47539\\n\", \"64115\\n\", \"41764\\n\", \"99900\\n\", \"99911\\n\", \"99329\\n\", \"99945\\n\", \"99896\\n\", \"99936\\n\", \"82460\\n\", \"74074\\n\", \"55311\\n\", \"15015\\n\", \"77385\\n\", \"86632\\n\"], \"outputs\": [\"1\\n\", \"2\\n\", \"333333338\\n\", \"2\\n\", \"166666670\\n\", \"500000006\\n\", \"716666674\\n\", \"476190482\\n\", \"225000004\\n\", \"567460324\\n\", \"430555561\\n\", \"318181823\\n\", \"534174612\\n\", \"434191575\\n\", \"723188569\\n\", \"166105505\\n\", \"347601361\\n\", \"606807336\\n\", \"838672461\\n\", \"409222861\\n\", \"750441533\\n\", \"741627218\\n\", \"559826101\\n\", \"607779919\\n\", \"572467262\\n\", \"927439938\\n\", \"665668016\\n\", \"645842651\\n\", \"458595757\\n\", \"485745620\\n\", \"831671589\\n\", \"468253974\\n\", \"966666676\\n\", \"553571435\\n\", \"85780889\\n\", \"519841276\\n\", \"625000007\\n\", \"984514841\\n\", \"935537382\\n\", \"503257127\\n\", \"765292545\\n\", \"380490066\\n\", \"948537108\\n\", \"434774514\\n\", \"874467055\\n\", \"834924464\\n\", \"751784127\\n\", \"963174399\\n\", \"249303275\\n\", \"857337836\\n\", \"567687036\\n\", \"33998115\\n\", \"785109731\\n\", \"340579911\\n\", \"159998877\\n\", \"109597446\\n\", \"323804671\\n\", \"557358009\\n\", \"413855313\\n\", \"876201665\\n\", \"917827355\\n\", \"820319423\\n\", \"674222305\\n\", \"843541605\\n\", \"866047090\\n\", \"685679455\\n\", \"125860916\\n\", \"178533194\\n\", \"123894686\\n\", \"460012534\\n\", \"736315231\\n\", \"185311544\\n\", \"683829911\\n\", \"797695183\\n\", \"120075637\\n\", \"760262294\\n\", \"657550913\\n\", \"283204023\\n\", \"9522345\\n\", \"689855972\\n\", \"328389339\\n\", \"225651508\\n\", \"891558121\\n\", \"883481609\\n\", \"362881216\\n\", \"768818941\\n\", \"376862836\\n\", \"559402589\\n\", \"917128937\\n\", \"200047474\\n\", \"500907462\\n\", \"124910318\\n\", \"767471115\\n\", \"291762913\\n\", \"442384963\\n\", \"570892404\\n\", \"65880203\\n\", \"313467660\\n\", \"55921825\\n\", \"635418994\\n\", \"47143644\\n\", \"423867335\\n\", \"129595366\\n\", \"79287597\\n\", \"472079813\\n\", \"341088608\\n\", \"618014296\\n\", \"724140171\\n\", \"626563584\\n\"]}", "source": "primeintellect"}
|
Vivek initially has an empty array $a$ and some integer constant $m$.
He performs the following algorithm: Select a random integer $x$ uniformly in range from $1$ to $m$ and append it to the end of $a$. Compute the greatest common divisor of integers in $a$. In case it equals to $1$, break Otherwise, return to step $1$.
Find the expected length of $a$. It can be shown that it can be represented as $\frac{P}{Q}$ where $P$ and $Q$ are coprime integers and $Q\neq 0 \pmod{10^9+7}$. Print the value of $P \cdot Q^{-1} \pmod{10^9+7}$.
-----Input-----
The first and only line contains a single integer $m$ ($1 \leq m \leq 100000$).
-----Output-----
Print a single integer — the expected length of the array $a$ written as $P \cdot Q^{-1} \pmod{10^9+7}$.
-----Examples-----
Input
1
Output
1
Input
2
Output
2
Input
4
Output
333333338
-----Note-----
In the first example, since Vivek can choose only integers from $1$ to $1$, he will have $a=[1]$ after the first append operation, and after that quit the algorithm. Hence the length of $a$ is always $1$, so its expected value is $1$ as well.
In the second example, Vivek each time will append either $1$ or $2$, so after finishing the algorithm he will end up having some number of $2$'s (possibly zero), and a single $1$ in the end. The expected length of the list is $1\cdot \frac{1}{2} + 2\cdot \frac{1}{2^2} + 3\cdot \frac{1}{2^3} + \ldots = 2$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6 10\\n\", \"21 31\\n\", \"5 10\\n\", \"1924 5834\\n\", \"9911 666013\\n\", \"1 1\\n\", \"69 4295\\n\", \"948248258 533435433\\n\", \"953 1349\\n\", \"999999973 800000007\\n\", \"112342324 524224233\\n\", \"1021211 59555555\\n\", \"1000000000 1000000000\\n\", \"199999943 999999973\\n\", \"2 999999973\\n\", \"199999973 99999937\\n\", \"851187514 983401693\\n\", \"414459569 161124945\\n\", \"59774131 414357411\\n\", \"588854730 468415815\\n\", \"166027408 867208246\\n\", \"416882693 26430642\\n\", \"63906772 377040487\\n\", \"573707893 93108818\\n\", \"498599067 627630818\\n\", \"41698727 40343\\n\", \"21184942 66889\\n\", \"584924132 27895\\n\", \"34504222 65532\\n\", \"397410367 96163\\n\", \"772116208 99741\\n\", \"721896242 62189\\n\", \"480432805 79482\\n\", \"526157284 30640\\n\", \"509022792 57335\\n\", \"13911 866384789\\n\", \"43736 145490995\\n\", \"27522 656219918\\n\", \"3904 787488950\\n\", \"64320 203032344\\n\", \"19430 993947341\\n\", \"89229 680338802\\n\", \"22648 30366541\\n\", \"89598 155519475\\n\", \"80536 791328168\\n\", \"55138 453739731\\n\", \"20827 81894\\n\", \"15162 60885\\n\", \"33261 83156\\n\", \"12567 44055\\n\", \"36890 51759\\n\", \"69731 73202\\n\", \"92037 8625\\n\", \"51783 5491\\n\", \"39204 15357\\n\", \"11 16\\n\", \"5 18\\n\", \"1 113\\n\", \"18 102\\n\", \"13 33\\n\", \"22 51\\n\", \"1 114\\n\", \"10 12\\n\", \"24 9\\n\", \"21 1\\n\", \"5 14\\n\", \"273301753 369183717\\n\", \"83893226 440673790\\n\", \"391320363 805801085\\n\", \"350089529 67401533\\n\", \"356318639 545297094\\n\", \"456039936 216657167\\n\", \"200869227 429021875\\n\", \"724338885 158040565\\n\", \"354798648 439745337\\n\", \"152408121 368230838\\n\", \"532851498 235555724\\n\", \"571244721 233692396\\n\", \"434431270 432744926\\n\", \"845961672 92356861\\n\", \"861681496 158472265\\n\", \"358415973 475293324\\n\", \"179237079 691088384\\n\", \"159488527 938932258\\n\", \"173726711 47100867\\n\", \"113701457 374868637\\n\", \"49160468 106133716\\n\", \"258834406 21427940\\n\", \"209853278 238360826\\n\", \"833630757 5203048\\n\", \"898985699 25761857\\n\", \"882561035 53440816\\n\", \"844002269 45400923\\n\", \"890747621 58942406\\n\", \"823409948 63146277\\n\", \"806104369 75421522\\n\", \"950485973 21039711\\n\", \"904189980 653467036\\n\", \"986866706 981520552\\n\", \"987324114 296975438\\n\", \"932939238 454247778\\n\", \"997908364 240589278\\n\", \"2 3\\n\", \"5 11\\n\", \"2 2\\n\", \"2 6\\n\", \"6 9\\n\", \"1000000000 264865600\\n\"], \"outputs\": [\"2\", \"9\", \"0\", \"31\", \"318140\", \"0\", \"2044\", \"296190217\", \"235\", \"199999823\", \"299539585\", \"309115\", \"0\", \"200000072\", \"191\", \"99\", \"74311739\", \"92209679\", \"11142525\", \"13339845\", \"67699538\", \"9064999\", \"40471133\", \"3010997\", \"17527937\", \"19511\", \"573052\", \"34377766\", \"54883\", \"44330\", \"703606\", \"150930\", \"480273841\", \"8006\", \"5508\", \"488042\", \"242015\", \"38975\", \"577695\", \"17588\", \"43194827\", \"16502224\", \"509701\", \"1581691\", \"4581\", \"26632191\", \"40240\", \"79\", \"16634\", \"3177\", \"7717\", \"3160\", \"643\", \"6082\", \"8490\", \"4\", \"8\", \"0\", \"3\", \"7\", \"7\", \"0\", \"0\", \"6\", \"0\", \"4\", \"14344139\", \"5301915\", \"23160359\", \"3270466\", \"21638271\", \"22725602\", \"27283421\", \"125108595\", \"69934797\", \"63414596\", \"61740050\", \"103859929\", \"645482\", \"661247950\", \"75930812\", \"109093431\", \"332614226\", \"100326050\", \"16212055\", \"16882133\", \"7812780\", \"154466\", \"18207106\", \"823224661\", \"12204397\", \"775679403\", \"353899750\", \"107418637\", \"697117394\", \"5765461\", \"443683420\", \"98701796\", \"2171784\", \"48198900\", \"24443682\", \"138070265\", \"0\", \"1\", \"0\", \"0\", \"0\", \"102701600\"]}", "source": "primeintellect"}
|
Neko loves divisors. During the latest number theory lesson, he got an interesting exercise from his math teacher.
Neko has two integers $a$ and $b$. His goal is to find a non-negative integer $k$ such that the least common multiple of $a+k$ and $b+k$ is the smallest possible. If there are multiple optimal integers $k$, he needs to choose the smallest one.
Given his mathematical talent, Neko had no trouble getting Wrong Answer on this problem. Can you help him solve it?
-----Input-----
The only line contains two integers $a$ and $b$ ($1 \le a, b \le 10^9$).
-----Output-----
Print the smallest non-negative integer $k$ ($k \ge 0$) such that the lowest common multiple of $a+k$ and $b+k$ is the smallest possible.
If there are many possible integers $k$ giving the same value of the least common multiple, print the smallest one.
-----Examples-----
Input
6 10
Output
2
Input
21 31
Output
9
Input
5 10
Output
0
-----Note-----
In the first test, one should choose $k = 2$, as the least common multiple of $6 + 2$ and $10 + 2$ is $24$, which is the smallest least common multiple possible.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.875
|
{"tests": "{\"inputs\": [\"2 6\\n2 3\\n\", \"36 5\\n10 16\\n\", \"3 5\\n2 1\\n\", \"36 5\\n10 12\\n\", \"1 1\\n1 1\\n\", \"2 1\\n1 2\\n\", \"3 6\\n2 1\\n\", \"1 27\\n1 1\\n\", \"2 5\\n20 2\\n\", \"40 5\\n150 36\\n\", \"60 1080\\n60 45\\n\", \"2160 3240\\n7200 384\\n\", \"51840 900\\n48 27000\\n\", \"100 200\\n7200 25\\n\", \"112500 96\\n375 2400\\n\", \"432000 3000\\n4800 10000\\n\", \"7 1\\n1 7\\n\", \"12 39\\n13 3\\n\", \"906992640 544195584\\n906992640 725594112\\n\", \"859963392 644972544\\n725594112 967458816\\n\", \"644972544 886837248\\n725594112 886837248\\n\", \"243 216\\n6 1\\n\", \"400 2500000\\n1000000 1000\\n\", \"10000 100000\\n2 1000000000\\n\", \"25000000 80\\n128 23437500\\n\", \"62500000 96\\n256 7812500\\n\", \"1280 2343750\\n25600 312500\\n\", \"15625 1152000\\n1562500 5760\\n\", \"9000000 12000\\n6250 480000\\n\", \"1920 50000000\\n78125 25600\\n\", \"5625000 19200\\n1125000 96000\\n\", \"45 800000000\\n288000000 500\\n\", \"750000000 725594112\\n716636160 675000000\\n\", \"10000079 1\\n10000079 1\\n\", \"1 30000237\\n10000079 1\\n\", \"10000079 1\\n6 10000079\\n\", \"3 540004266\\n60000474 27\\n\", \"720005688 725594112\\n816293376 960007584\\n\", \"859963392 816293376\\n967458816 859963392\\n\", \"644972544 816293376\\n544195584 816293376\\n\", \"99999989 1\\n1 99999989\\n\", \"99999989 9\\n1 99999989\\n\", \"199999978 2\\n599999934 3\\n\", \"544195584 899999901\\n599999934 967458816\\n\", \"8 8\\n1 1\\n\", \"31 15\\n36 25\\n\", \"68 34\\n84 78\\n\", \"894 197\\n325 232\\n\", \"41764 97259\\n54586 18013\\n\", \"333625 453145\\n800800 907251\\n\", \"4394826 2233224\\n609367 3364334\\n\", \"13350712 76770926\\n61331309 8735000\\n\", \"844212449 863672439\\n410956265 742052168\\n\", \"22295873 586964387\\n4736819 472714349\\n\", \"905412001 865545936\\n598517372 498343827\\n\", \"378462721 734062076\\n42554822 374230201\\n\", \"261578849 307610920\\n636335376 399859678\\n\", \"144694977 881159765\\n80372825 425489156\\n\", \"35135676 3879\\n841304242 18\\n\", \"57946752 619939008\\n114816 331164\\n\", \"171 162\\n9 57\\n\", \"2592 4950\\n60 2970\\n\", \"90315 96\\n48 30105\\n\", \"5832 45693720\\n10154160 108\\n\", \"5832 45693720\\n10154160 108\\n\", \"1 911953772\\n39650164 23\\n\", \"3 707552887\\n6 707552887\\n\", \"806410824 11\\n2 369604961\\n\", \"144 980783074\\n24786 461544976\\n\", \"614363206 2\\n2 307181603\\n\", \"1336608 1650\\n18711 3182400\\n\", \"472586400 448\\n1050192 8400\\n\", \"497664 367567200\\n3304800 55351296\\n\", \"916090560 291133440\\n628176384 424569600\\n\", \"556792704 718502400\\n640493568 832809600\\n\", \"320 162162\\n8736 1980\\n\", \"25740 6048\\n38918880 81\\n\", \"90720 35582976\\n294840 9237888\\n\", \"870912 1924560\\n544195584 35925120\\n\", \"846526464 537477120\\n806215680 952342272\\n\", \"862202880 967458816\\n595213920 886837248\\n\", \"564350976 623557440\\n775982592 604661760\\n\", \"775982592 716636160\\n906992640 919683072\\n\", \"806215680 940584960\\n627056640 537477120\\n\", \"537477120 560431872\\n627056640 720555264\\n\", \"564350976 906992640\\n836075520 816293376\\n\", \"591224832 529079040\\n574801920 725594112\\n\", \"816293376 881798400\\n612220032 783820800\\n\", \"862202880 764411904\\n997691904 836075520\\n\", \"766402560 725594112\\n680244480 689762304\\n\", \"766402560 816293376\\n680244480 581986944\\n\", \"952342272 554273280\\n646652160 725594112\\n\", \"739031040 564350976\\n644972544 862202880\\n\", \"831409920 564350976\\n574801920 725594112\\n\", \"1 1\\n774840978 774840978\\n\", \"725594112 725594112\\n1 1\\n\", \"1 1\\n536870912 536870912\\n\", \"573308928 573308928\\n1 1\\n\", \"1 1\\n918330048 918330048\\n\", \"1 1\\n688747536 688747536\\n\", \"536870912 536870912\\n387420489 387420489\\n\", \"967458816 967458816\\n967458816 967458816\\n\", \"1 1\\n65536 65536\\n\", \"387420489 387420489\\n536870912 536870912\\n\", \"999999937 999999937\\n999999937 999999937\\n\", \"387420489 774840978\\n774840978 645700815\\n\"], \"outputs\": [\"1\\n1 6\\n2 3\\n\", \"3\\n16 5\\n5 16\\n\", \"-1\\n\", \"1\\n24 5\\n10 12\\n\", \"0\\n1 1\\n1 1\\n\", \"0\\n2 1\\n1 2\\n\", \"4\\n1 2\\n2 1\\n\", \"6\\n1 1\\n1 1\\n\", \"2\\n2 5\\n5 2\\n\", \"6\\n40 5\\n25 8\\n\", \"5\\n5 540\\n60 45\\n\", \"5\\n640 2160\\n3600 384\\n\", \"6\\n1440 900\\n48 27000\\n\", \"4\\n100 200\\n800 25\\n\", \"4\\n9375 96\\n375 2400\\n\", \"6\\n16000 3000\\n4800 10000\\n\", \"0\\n7 1\\n1 7\\n\", \"4\\n1 39\\n13 3\\n\", \"2\\n604661760 544195584\\n453496320 725594112\\n\", \"6\\n214990848 644972544\\n143327232 967458816\\n\", \"3\\n322486272 886837248\\n322486272 886837248\\n\", \"16\\n1 6\\n6 1\\n\", \"0\\n400 2500000\\n1000000 1000\\n\", \"1\\n10000 100000\\n1 1000000000\\n\", \"1\\n25000000 80\\n128 15625000\\n\", \"2\\n31250000 64\\n256 7812500\\n\", \"3\\n1280 1562500\\n6400 312500\\n\", \"1\\n15625 576000\\n1562500 5760\\n\", \"6\\n250000 12000\\n6250 480000\\n\", \"6\\n40 50000000\\n78125 25600\\n\", \"0\\n5625000 19200\\n1125000 96000\\n\", \"2\\n45 800000000\\n72000000 500\\n\", \"3\\n500000000 483729408\\n358318080 675000000\\n\", \"0\\n10000079 1\\n10000079 1\\n\", \"2\\n1 10000079\\n10000079 1\\n\", \"3\\n10000079 1\\n1 10000079\\n\", \"0\\n3 540004266\\n60000474 27\\n\", \"1\\n720005688 725594112\\n544195584 960007584\\n\", \"5\\n254803968 816293376\\n241864704 859963392\\n\", \"5\\n161243136 816293376\\n161243136 816293376\\n\", \"0\\n99999989 1\\n1 99999989\\n\", \"4\\n99999989 1\\n1 99999989\\n\", \"3\\n199999978 2\\n199999978 2\\n\", \"5\\n161243136 899999901\\n299999967 483729408\\n\", \"6\\n1 1\\n1 1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"4\\n3903964 3879\\n841304242 18\\n\", \"24\\n92 413292672\\n114816 331164\\n\", \"7\\n19 27\\n9 57\\n\", \"7\\n36 4950\\n60 2970\\n\", \"3\\n30105 48\\n48 30105\\n\", \"10\\n24 45693720\\n10154160 108\\n\", \"10\\n24 45693720\\n10154160 108\\n\", \"0\\n1 911953772\\n39650164 23\\n\", \"1\\n3 707552887\\n3 707552887\\n\", \"4\\n67200902 11\\n2 369604961\\n\", \"8\\n144 980783074\\n306 461544976\\n\", \"1\\n307181603 2\\n2 307181603\\n\", \"6\\n1336608 1650\\n693 3182400\\n\", \"5\\n19691100 448\\n1050192 8400\\n\", \"0\\n497664 367567200\\n3304800 55351296\\n\", \"0\\n916090560 291133440\\n628176384 424569600\\n\", \"2\\n371195136 718502400\\n320246784 832809600\\n\", \"2\\n160 108108\\n8736 1980\\n\", \"6\\n25740 6048\\n1921920 81\\n\", \"5\\n22680 35582976\\n87360 9237888\\n\", \"16\\n870912 1924560\\n46656 35925120\\n\", \"4\\n423263232 537477120\\n238878720 952342272\\n\", \"7\\n107775360 967458816\\n117573120 886837248\\n\", \"2\\n376233984 623557440\\n387991296 604661760\\n\", \"1\\n775982592 716636160\\n604661760 919683072\\n\", \"2\\n358318080 940584960\\n627056640 537477120\\n\", \"1\\n537477120 560431872\\n418037760 720555264\\n\", \"2\\n376233984 906992640\\n418037760 816293376\\n\", \"2\\n394149888 529079040\\n287400960 725594112\\n\", \"1\\n544195584 881798400\\n612220032 783820800\\n\", \"6\\n215550720 764411904\\n197074944 836075520\\n\", \"5\\n191600640 725594112\\n201553920 689762304\\n\", \"7\\n95800320 816293376\\n134369280 581986944\\n\", \"3\\n423263232 554273280\\n323326080 725594112\\n\", \"2\\n492687360 564350976\\n322486272 862202880\\n\", \"3\\n369515520 564350976\\n287400960 725594112\\n\", \"74\\n1 1\\n1 1\\n\", \"68\\n1 1\\n1 1\\n\", \"58\\n1 1\\n1 1\\n\", \"64\\n1 1\\n1 1\\n\", \"72\\n1 1\\n1 1\\n\", \"72\\n1 1\\n1 1\\n\", \"58\\n128 536870912\\n262144 262144\\n\", \"0\\n967458816 967458816\\n967458816 967458816\\n\", \"32\\n1 1\\n1 1\\n\", \"58\\n262144 262144\\n128 536870912\\n\", \"0\\n999999937 999999937\\n999999937 999999937\\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
Polycarpus likes giving presents to Paraskevi. He has bought two chocolate bars, each of them has the shape of a segmented rectangle. The first bar is a_1 × b_1 segments large and the second one is a_2 × b_2 segments large.
Polycarpus wants to give Paraskevi one of the bars at the lunch break and eat the other one himself. Besides, he wants to show that Polycarpus's mind and Paraskevi's beauty are equally matched, so the two bars must have the same number of squares.
To make the bars have the same number of squares, Polycarpus eats a little piece of chocolate each minute. Each minute he does the following: he either breaks one bar exactly in half (vertically or horizontally) and eats exactly a half of the bar, or he chips of exactly one third of a bar (vertically or horizontally) and eats exactly a third of the bar.
In the first case he is left with a half, of the bar and in the second case he is left with two thirds of the bar.
Both variants aren't always possible, and sometimes Polycarpus cannot chip off a half nor a third. For example, if the bar is 16 × 23, then Polycarpus can chip off a half, but not a third. If the bar is 20 × 18, then Polycarpus can chip off both a half and a third. If the bar is 5 × 7, then Polycarpus cannot chip off a half nor a third.
What is the minimum number of minutes Polycarpus needs to make two bars consist of the same number of squares? Find not only the required minimum number of minutes, but also the possible sizes of the bars after the process.
-----Input-----
The first line of the input contains integers a_1, b_1 (1 ≤ a_1, b_1 ≤ 10^9) — the initial sizes of the first chocolate bar. The second line of the input contains integers a_2, b_2 (1 ≤ a_2, b_2 ≤ 10^9) — the initial sizes of the second bar.
You can use the data of type int64 (in Pascal), long long (in С++), long (in Java) to process large integers (exceeding 2^31 - 1).
-----Output-----
In the first line print m — the sought minimum number of minutes. In the second and third line print the possible sizes of the bars after they are leveled in m minutes. Print the sizes using the format identical to the input format. Print the sizes (the numbers in the printed pairs) in any order. The second line must correspond to the first bar and the third line must correspond to the second bar. If there are multiple solutions, print any of them.
If there is no solution, print a single line with integer -1.
-----Examples-----
Input
2 6
2 3
Output
1
1 6
2 3
Input
36 5
10 16
Output
3
16 5
5 16
Input
3 5
2 1
Output
-1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 2 30\\n4 3\\n\", \"2 2 7\\n4 3\\n\", \"3 1 1\\n1 1 1\\n\", \"25 25 25\\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\\n\", \"13 1 60\\n3 6 3 4 3 5 1 4 4 4 3 4 3\\n\", \"10 10 1002\\n5 6 5 3 4 3 3 2 6 4\\n\", \"7 6 14\\n1 3 2 4 1 1 6\\n\", \"8 7 169\\n4 3 4 3 5 5 2 5\\n\", \"1 0 384338286\\n384338286\\n\", \"10 6 14\\n1 1 1 2 2 2 1 1 2 1\\n\", \"10 8 35\\n3 3 2 3 1 1 3 3 2 2\\n\", \"5 3 364332\\n8 6 4 6 9\\n\", \"4 2 6227020842\\n17 15 13 10\\n\", \"25 15 38\\n2 1 2 1 1 2 1 2 1 2 1 1 2 2 2 2 2 1 1 1 2 1 2 1 2\\n\", \"25 1 25\\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\\n\", \"23 22 2557\\n109 117 119 123 117 122 106 100 108 105 119 105 108 120 113 101 115 101 114 123 101 100 111\\n\", \"25 21 7825123418112377\\n19 20 17 20 18 19 17 20 19 18 18 20 17 20 18 17 20 19 19 20 17 17 18 17 19\\n\", \"25 9 137\\n4 3 1 4 1 2 2 1 1 1 4 4 3 4 4 3 2 1 3 2 4 2 4 1 4\\n\", \"17 17 2925\\n5 6 6 5 5 5 5 6 5 5 6 6 6 5 5 6 6\\n\", \"25 16 13326087796\\n157576937 627434432 942652043 706432863 631136945 714549755 465703470 663358517 695561723 249240606 833566455 396564536 758483017 253748999 978210764 530023233 193812243 317718202 184788435 892848108 150420430 330992298 780787784 196460118 674015883\\n\", \"25 19 6402373705728432\\n18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18 18\\n\", \"25 20 7469435990016370\\n18 17 18 18 18 17 18 18 17 18 18 17 18 17 17 18 18 17 17 17 18 17 18 18 17\\n\", \"25 4 8954954072064251\\n17 18 16 17 17 20 18 16 17 19 20 17 16 19 20 17 16 18 17 16 17 16 17 16 19\\n\", \"25 18 7134671351808397\\n17 17 18 18 21 20 21 20 19 17 21 18 16 17 18 18 17 20 18 20 18 16 18 21 21\\n\", \"25 2 376618217984000\\n17 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 16 1000000000 2345 34521 6587 4564536 234134 12344 23561 2341 2345 324523 123123 4567 8976 345 2134\\n\", \"25 25 2000000023\\n1000000000 1000000000 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1\\n\", \"25 13 2000000023\\n1000000000 1000000000 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\\n\", \"25 19 2000000023\\n1000000000 1000000000 1 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\\n\", \"25 25 2000005023\\n1000000000 1000000000 5000 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\\n\", \"24 21 732472010010838\\n16 4 10 14 4 1 14 8 2 17 8 11 2 7 13 7 7 3 14 10 7 17 17 10\\n\", \"23 1 43165708951941\\n8 6 9 17 1 14 1 12 13 5 15 18 16 8 9 4 8 13 16 7 11 13 1\\n\", \"23 14 376709893904263\\n14 6 11 4 16 10 13 2 10 6 10 11 6 14 17 7 2 17 17 13 8 1 2\\n\", \"25 23 355687987299309\\n14 15 11 2 6 15 14 9 1 4 7 18 2 17 3 3 2 11 6 18 13 14 2 11 12\\n\", \"25 6 355781798669775\\n14 2 13 17 12 18 10 11 18 2 6 18 1 5 9 3 2 3 14 1 1 18 12 11 10\\n\", \"24 23 6779165946558798\\n481199252 6 12 2 5 4 6 15 3 12 14 18 8 6 13 4 17 12 3 2 13 14 16 8\\n\", \"24 22 93579450246\\n54748096 75475634 6 12 18 1 12 13 11 7 10 17 9 9 10 9 6 14 14 15 5 5 15 13\\n\", \"24 21 711557276608128\\n923264237 374288891 535590429 18 17 17 8 14 15 3 4 11 15 2 7 13 8 12 13 3 5 14 10 14\\n\", \"24 20 6402470099308437\\n496813081 673102149 561219907 730593611 4 2 15 11 10 12 3 13 16 1 10 8 18 14 6 6 14 6 9 11\\n\", \"24 19 22239162909709\\n365329221 412106895 291882089 564718673 358502890 3 7 13 18 8 7 12 3 8 7 12 2 8 4 12 6 9 15 16\\n\", \"24 18 6402551633230723\\n643910770 5887448 757703054 544067926 902981667 712695184 3 14 4 11 3 14 4 11 4 7 8 10 7 11 6 18 14 13\\n\", \"24 17 6758151602395830\\n72235422 449924898 783332532 378192988 592684636 147499872 343857831 12 17 7 14 12 2 14 1 11 11 12 10 18 16 5 5 18\\n\", \"24 16 376613867481065\\n940751563 43705451 513994713 652509537 432130709 317463343 687041819 58265855 7 3 14 10 11 17 16 16 17 10 13 2 3 5 18 5\\n\", \"24 15 376715306932970\\n514300407 782710197 539624191 631858791 976609486 752268030 30225807 279200011 467188665 12 18 5 4 2 13 10 1 13 16 1 13 14 17 6\\n\", \"23 13 357006388025624\\n598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754 223219513 9 17 13 13 17 15 5 2 15 8 2 7 8\\n\", \"23 12 357087149917608\\n26521171 379278816 8989449 50899375 935650934 529615950 494390299 427618702 979962232 602512657 429731081 1 10 2 14 9 3 18 17 15 16 12 7\\n\", \"23 11 18015396922\\n895037311 678092074 34618927 179991732 480129711 404612126 132541583 648552857 967299118 276773097 341033928 482750975 1 1 11 14 13 2 16 13 7 7 2\\n\", \"23 10 5498434429\\n468586155 417096820 205472596 159340986 464799976 839416813 475725571 869487013 249603301 246000832 807626376 125583769 129772276 8 8 18 15 4 9 16 7 7 11\\n\", \"23 9 7822306195\\n747167704 715910077 936134778 138690239 714311457 9380284 523942263 795453872 826874779 625293976 864153416 63383860 9374518 851872013 9 13 8 3 8 4 17 16 7\\n\", \"23 8 6129434724\\n615683844 454914823 961764255 972815301 258790234 444184972 162093547 16388028 814211665 299554415 625713159 1183950 34200951 73842336 394092460 17 14 1 10 11 4 7 6\\n\", \"23 7 6584075104\\n189232688 48695377 692426437 952164554 243460498 173956955 210310239 237322183 96515847 678847559 682240199 498792552 208770488 736004147 176573082 279397774 12 3 17 9 4 17 1\\n\", \"23 6 6423305153580378\\n912524637 347508634 863280107 226481104 787939275 48953130 553494227 458256339 673787326 353107999 298575751 436592642 233596921 957974470 254020999 707869688 64999512 1 16 12 14 2 18\\n\", \"23 5 6403689500951790\\n486073481 86513380 593942288 60606166 627385348 778725113 896678215 384223198 661124212 882144246 60135494 374392733 408166459 179944793 331468916 401182818 69503967 798728037 15 18 6 11 5\\n\", \"23 4 355697995919632\\n764655030 680293934 914539062 744988123 317088317 653721289 239862203 605157354 943428394 261437390 821695238 312192823 432992892 547139308 408916833 829654733 223751525 672158759 193787527 17 9 17 1\\n\", \"25 5 355697433057426\\n586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499 661699500 14 17 5 5 12\\n\", \"22 1 15078298178\\n160137548 807874739 723325809 995465063 693137631 646771913 971489138 603747543 801665542 882310956 163114045 892278880 371370111 459773357 909727810 630170326 940240523 886200899 882106547 953987440 703402350 8\\n\", \"22 0 11671182837\\n733686393 546879484 748955287 974814317 532583704 671511192 314673126 824681699 789002429 261604100 219641085 389887482 250972352 976710976 987175727 58642240 534679569 759631621 26403492 101051189 178325936 789669437\\n\", \"23 0 10202579405\\n162011045 845692742 774584765 103906675 222286673 251540072 657857114 45615854 71306611 790640347 835976636 327687572 570766082 48938195 769656348 341889962 393959831 928029640 320443541 248114937 798473713 159552755 533648295\\n\", \"24 0 12493321628\\n30527185 439473295 505246946 83255928 766765450 981312055 706073806 971582714 648578089 464900787 597536380 265487663 450368323 565875814 847104265 475394581 693431581 241651850 464740486 100211390 418621491 969627560 755522678 50031311\\n\", \"25 0 12982465295\\n604076030 178478041 676100616 622413694 606211522 711084038 344225090 192516869 635914975 139161226 359096124 908320457 770162052 933070329 69776374 758642303 552711844 820115276 609037430 392499330 598577781 484735069 272364358 72345168 670829299\\n\", \"24 23 20929016909621\\n481199252 6 12 2 5 4 6 15 3 12 14 18 8 6 13 4 17 12 3 2 13 14 16 8\\n\", \"24 21 355689301156580\\n923264237 374288891 535590429 18 17 17 8 14 15 3 4 11 15 2 7 13 8 12 13 3 5 14 10 14\\n\", \"24 16 20926395674529\\n940751563 43705451 513994713 652509537 432130709 317463343 687041819 58265855 7 3 14 10 11 17 16 16 17 10 13 2 3 5 18 5\\n\", \"23 13 711377554159955\\n598196518 640274071 983359971 71550121 96204862 799843967 446173607 796619138 402690754 223219513 9 17 13 13 17 15 5 2 15 8 2 7 8\\n\", \"23 8 90819114674\\n615683844 454914823 961764255 972815301 258790234 444184972 162093547 16388028 814211665 299554415 625713159 1183950 34200951 73842336 394092460 17 14 1 10 11 4 7 6\\n\", \"25 5 7183838143\\n586588704 509061481 552472140 16115810 148658854 66743034 628305150 677780684 519361360 208050516 401554301 954478790 346543678 387546138 832279893 641889899 80960260 717802881 588066499 661699500 14 17 5 5 12\\n\", \"22 0 7002300855\\n733686393 546879484 748955287 974814317 532583704 671511192 314673126 824681699 789002429 261604100 219641085 389887482 250972352 976710976 987175727 58642240 534679569 759631621 26403492 101051189 178325936 789669437\\n\", \"25 0 8812325752\\n604076030 178478041 676100616 622413694 606211522 711084038 344225090 192516869 635914975 139161226 359096124 908320457 770162052 933070329 69776374 758642303 552711844 820115276 609037430 392499330 598577781 484735069 272364358 72345168 670829299\\n\", \"23 12 1307674408320\\n818219322 490480030 946157371 335075927 504332527 696433549 421447064 242605730 513711473 879700707 875141086 8 18 5 8 18 2 2 2 11 15 10 1\\n\", \"23 9 356999252684127\\n672509980 76127167 93413008 709188915 563436455 432103889 115272158 698233775 382556143 771342465 178361701 711213646 803513458 87049574 16 18 5 17 5 15 9 10 18\\n\", \"22 7 94086626507\\n400086390 24218459 946613393 146658464 240900479 960251651 888572685 326830726 485573749 506482600 828508367 964019704 563712967 891568106 732815759 7 7 14 1 2 1 18\\n\", \"23 19 694110791\\n694105695 469829284 490636148 769880615 1 12 7 9 18 15 15 7 7 6 18 2 5 1 2 15 15 15 17\\n\", \"23 15 19\\n40331947 578270895 19785190 374648773 533884491 64268719 268359611 970419752 12 16 17 3 1 4 9 2 11 10 7 15 1 3 7\\n\", \"23 2 5065472115\\n428801639 184568779 477337858 18989778 249804431 579004904 679880522 901530462 200642926 941909941 377757672 300378484 103633484 503801915 910270476 13399319 214483686 671551510 986061470 346894110 521433581 12 5\\n\", \"23 2 4048109324\\n770994128 412395956 564263966 104420757 877068479 285202875 550663793 644680192 709693551 190709580 978965731 122048808 648617624 375329937 297799155 929741838 337809699 382782724 945661847 136720969 898777264 4 10\\n\", \"22 11 355777681121374\\n352861197 501423986 564719989 916003293 908603727 959086385 17789414 583680997 826780019 112458769 227300308 12 17 14 6 3 12 10 2 11 8 12\\n\", \"23 5 5657256853\\n61927663 677005715 711975626 730307769 817964551 549532534 856838700 189052146 695624689 4100527 530520923 59586998 333673225 125072914 526575822 99222914 877574527 650143337 5 11 3 4 6\\n\", \"22 16 22231735758643\\n447311584 102302533 183282606 937122147 163131823 371482325 4 16 16 9 10 15 6 16 4 10 14 8 12 10 2 2\\n\", \"23 17 6759458873943562\\n14702469 303954345 330082221 499652598 895733207 843334564 15 5 12 4 12 14 4 18 17 18 4 3 12 6 2 2 5\\n\", \"22 19 6402375527188783\\n669424209 895126102 256910425 17 17 8 11 17 1 18 14 7 4 1 15 5 8 15 10 10 10 13\\n\", \"22 8 6960722973\\n425715868 3567713 786059466 876430447 879051763 886218511 170876867 706123870 247133492 299058498 853334800 185990027 641160884 174815828 6 1 18 2 5 7 14 5\\n\", \"25 20 1308180371599\\n731464501 285497487 892432116 218274129 458569375 3 14 17 11 16 7 15 16 3 1 5 11 16 11 15 13 7 5 10 10\\n\", \"25 17 1311878711325\\n757093979 264846740 436910893 243013408 801753363 254065895 579134035 609847689 15 10 9 4 13 7 18 3 14 5 2 15 8 12 7 15 17\\n\", \"25 2 3288144341\\n782723456 393939098 126613862 677818096 144937351 475000050 861438217 284108128 274856175 88383185 912041882 3941587 489034386 211074902 308950662 308611657 417645457 784954245 947958718 464312042 578753998 973835975 805832248 17 18\\n\", \"25 4 5095166378\\n953577126 373288351 966059935 552814271 193154043 400966910 143742399 663401272 36415918 26183275 936868315 520879206 566482303 639546816 313455116 182042379 711685505 932017994 422882304 979419551 800628381 18 2 4 5\\n\", \"25 9 1399657417\\n684239308 207413413 510538712 577553550 831305327 326933769 426046582 192437520 652751470 963983365 111437852 593106425 348962924 332859946 467702674 495664590 4 12 4 6 2 1 18 9 12\\n\", \"3 1 24\\n4 10 14\\n\", \"25 25 3000005022\\n1000000000 1000000000 5000 1000000000 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\\n\", \"25 25 1000005024\\n1000000000 1 5000 1 2 1 1 1 2 1 1 1 2 1 2 1 2 1 2 1 2 1 2 2 1\\n\", \"25 25 12\\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\\n\", \"25 13 64182542054562\\n10 13 10 11 14 15 16 16 16 13 11 12 13 16 15 15 13 16 13 12 14 11 11 14 14\\n\", \"25 25 6758073589000599\\n7 6 13 15 3 2 4 18 1 17 13 17 9 5 16 17 12 18 3 9 17 8 1 7 9\\n\", \"25 23 6780291602197838\\n6 13 18 8 4 7 15 2 17 1 16 8 4 16 10 18 17 9 14 1 14 2 8 11 15\\n\", \"25 2 12680562939\\n715049313 915998492 578565942 855855826 497510114 582399573 930430334 286893113 391355789 331145449 93832233 202504960 728884607 204451031 664271485 292928862 572940745 227069487 402758132 446406368 779727087 595211160 904571581 16 18\\n\", \"25 2 11195364025\\n98718117 970465012 358887575 342461819 363429300 22954887 226633382 276685273 929524398 919300070 611367092 828471311 346387103 140272916 158548966 957310154 619598695 481800204 62782071 980986351 636091193 761224761 26106419 18 17\\n\", \"25 21 355687471641600\\n757093979 436910893 801753363 43545600 3 4 5 6 7 8 9 10 11 12 13 13 14 14 15 15 15 16 16 17 17\\n\", \"25 0 12\\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\\n\", \"1 1 1\\n1\\n\", \"25 25 10000000000000000\\n2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 1 2 3 4 5 6 7 8 9 10\\n\", \"25 25 1307674368024\\n15 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\", \"25 25 10000000000000000\\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\\n\", \"25 25 6780385530509849\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 32768 65536 131072 262144 524288 1048576 2097152\\n\", \"25 25 12345678912345\\n850721285 30306609 347099405 96957258 314543014 652545309 470894833 754515549 609681909 430315134 826092337 795319741 19167845 135991499 395492127 459806108 925737587 385950327 672837854 485396408 132630282 743562669 239478998 748888777 156720060\\n\"], \"outputs\": [\"1\\n\", \"1\\n\", \"6\\n\", \"33554432\\n\", \"155\\n\", \"124\\n\", \"84\\n\", \"24\\n\", \"1\\n\", \"848\\n\", \"203\\n\", \"1\\n\", \"1\\n\", \"29703676\\n\", \"26\\n\", \"1\\n\", \"175\\n\", \"2310192318\\n\", \"4774\\n\", \"1\\n\", \"25\\n\", \"2310\\n\", \"0\\n\", \"160\\n\", \"1\\n\", \"9422602240\\n\", \"10195317702\\n\", \"10238328832\\n\", \"3105865728\\n\", \"19440\\n\", \"0\\n\", \"16956\\n\", \"96\\n\", \"0\\n\", \"6264\\n\", \"2352\\n\", \"348\\n\", \"600\\n\", \"108\\n\", \"648\\n\", \"192\\n\", \"64\\n\", \"24\\n\", \"64\\n\", \"4\\n\", \"32\\n\", \"2\\n\", \"3\\n\", \"2\\n\", \"6\\n\", \"4\\n\", \"1\\n\", \"4\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1007724\\n\", \"38360\\n\", \"4000\\n\", \"24\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"16\\n\", \"24564\\n\", \"331\\n\", \"1\\n\", \"1\\n\", \"6\\n\", \"1\\n\", \"3573\\n\", \"128\\n\", \"1886\\n\", \"8\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"2\\n\", \"1104076800\\n\", \"8662843392\\n\", \"21300428800\\n\", \"2400\\n\", \"128\\n\", \"2336\\n\", \"0\\n\", \"0\\n\", \"4\\n\", \"5200300\\n\", \"2\\n\", \"0\\n\", \"16777216\\n\", \"0\\n\", \"4\\n\", \"0\\n\"]}", "source": "primeintellect"}
|
Anya loves to fold and stick. Today she decided to do just that.
Anya has n cubes lying in a line and numbered from 1 to n from left to right, with natural numbers written on them. She also has k stickers with exclamation marks. We know that the number of stickers does not exceed the number of cubes.
Anya can stick an exclamation mark on the cube and get the factorial of the number written on the cube. For example, if a cube reads 5, then after the sticking it reads 5!, which equals 120.
You need to help Anya count how many ways there are to choose some of the cubes and stick on some of the chosen cubes at most k exclamation marks so that the sum of the numbers written on the chosen cubes after the sticking becomes equal to S. Anya can stick at most one exclamation mark on each cube. Can you do it?
Two ways are considered the same if they have the same set of chosen cubes and the same set of cubes with exclamation marks.
-----Input-----
The first line of the input contains three space-separated integers n, k and S (1 ≤ n ≤ 25, 0 ≤ k ≤ n, 1 ≤ S ≤ 10^16) — the number of cubes and the number of stickers that Anya has, and the sum that she needs to get.
The second line contains n positive integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the numbers, written on the cubes. The cubes in the input are described in the order from left to right, starting from the first one.
Multiple cubes can contain the same numbers.
-----Output-----
Output the number of ways to choose some number of cubes and stick exclamation marks on some of them so that the sum of the numbers became equal to the given number S.
-----Examples-----
Input
2 2 30
4 3
Output
1
Input
2 2 7
4 3
Output
1
Input
3 1 1
1 1 1
Output
6
-----Note-----
In the first sample the only way is to choose both cubes and stick an exclamation mark on each of them.
In the second sample the only way is to choose both cubes but don't stick an exclamation mark on any of them.
In the third sample it is possible to choose any of the cubes in three ways, and also we may choose to stick or not to stick the exclamation mark on it. So, the total number of ways is six.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"11 3\\n\", \"11 6\\n\", \"20 20\\n\", \"14 5\\n\", \"1000000 100\\n\", \"1 1\\n\", \"2 1\\n\", \"100 4\\n\", \"502333439 2047\\n\", \"773014587697599 31\\n\", \"946338791423 262143\\n\", \"1000000000 4\\n\", \"13 2\\n\", \"1073741821 2\\n\", \"1000000000 100\\n\", \"1000000000 1000000000\\n\", \"766540997167959122 63301807306884502\\n\", \"767367244641009842 196001098285659518\\n\", \"768193483524125970 149607803130614508\\n\", \"766540997167959122 81305011918141103\\n\", \"767367244641009842 63001562824270\\n\", \"768193483524125970 8159388687\\n\", \"1000000000 999999999\\n\", \"1000000000 999999000\\n\", \"1000000000000000000 1\\n\", \"1000000000000000000 5\\n\", \"1000000000000000000 100\\n\", \"1000000000000000000 10000\\n\", \"1000000000000000000 100000000\\n\", \"1000000000000000000 1000000000\\n\", \"1000000000000000000 10000000000\\n\", \"1000000000000000000 100000000000\\n\", \"1000000000000000000 1000000000000\\n\", \"769019726702209394 20139642645754149\\n\", \"769845965585325522 101455278609352655\\n\", \"770672213058376242 76549913585534528\\n\", \"771498451941492370 9554452753411241\\n\", \"772324690824608498 350731058390952223\\n\", \"773150934002691922 35259246518088815\\n\", \"996517375802030514 562680741796166004\\n\", \"997343614685146642 371441227995459449\\n\", \"998169857863230066 216532832678151994\\n\", \"998996101041313490 69229635334469840\\n\", \"999822344219396914 31594516399528593\\n\", \"500648583102513041 27328990834120804\\n\", \"501474821985629169 20453276907988902\\n\", \"502301069458679889 157958605549950521\\n\", \"503127308341796017 87673697275461928\\n\", \"503953551519879441 107364070317088317\\n\", \"738505179452405422 45979222492061590\\n\", \"739331418335521551 128388023680008325\\n\", \"740157665808572271 34928303706093932\\n\", \"740983904691688399 137594355695562348\\n\", \"741810147869771823 28801222604168636\\n\", \"742636386752887951 316193697166926237\\n\", \"743462629930971375 185994815084963322\\n\", \"744288873109054799 87172378778063481\\n\", \"745115111992170927 106980481324722563\\n\", \"745941355170254351 284128592904320663\\n\", \"757120946248004542 159477335321753086\\n\", \"769019726702209394 53103\\n\", \"769845965585325522 1\\n\", \"770672213058376242 1\\n\", \"771498451941492370 41969263080453422\\n\", \"772324690824608498 28027536140678\\n\", \"773150934002691922 2872807266\\n\", \"996517375802030514 1\\n\", \"997343614685146642 979695858355714436\\n\", \"998169857863230066 1216910439614592\\n\", \"998996101041313490 325823891227\\n\", \"999822344219396914 7494606\\n\", \"500648583102513041 1\\n\", \"501474821985629169 1\\n\", \"502301069458679889 263489722252521919\\n\", \"503127308341796017 287766911826129\\n\", \"503953551519879441 63329862130\\n\", \"738505179452405422 173\\n\", \"739331418335521551 1\\n\", \"740157665808572271 1\\n\", \"740983904691688399 3157918256124620\\n\", \"741810147869771823 1158226091274\\n\", \"742636386752887951 45068330\\n\", \"743462629930971375 31\\n\", \"744288873109054799 1\\n\", \"745115111992170927 1\\n\", \"745941355170254351 1530914670906842\\n\", \"757120946248004542 1009900747\\n\", \"14465449852927 34359738367\\n\", \"1825593951 31\\n\", \"2147483647 2147483647\\n\", \"27386360746737663 274877906943\\n\", \"21968524033392639 4194303\\n\", \"4244114883215359 2199023255551\\n\", \"1962727058112511 8191\\n\", \"4294967295 2147483647\\n\", \"11225337262243839 536870911\\n\", \"429496729599 8589934591\\n\", \"6597069766655 68719476735\\n\", \"81067507711 536870911\\n\", \"356198383615 262143\\n\", \"17276479 31\\n\"], \"outputs\": [\"5\\n\", \"4\\n\", \"1\\n\", \"6\\n\", \"31248\\n\", \"1\\n\", \"2\\n\", \"48\\n\", \"490559\\n\", \"48313411731099\\n\", \"7219991\\n\", \"499999998\\n\", \"12\\n\", \"1073741820\\n\", \"31249998\\n\", \"1\\n\", \"40\\n\", \"8\\n\", \"10\\n\", \"20\\n\", \"43618\\n\", \"357717964\\n\", \"2\\n\", \"2\\n\", \"1000000000000000000\\n\", \"499999999999999998\\n\", \"31249999999999998\\n\", \"244140624999998\\n\", \"29802322386\\n\", \"3725290296\\n\", \"232830642\\n\", \"29103828\\n\", \"3637976\\n\", \"84\\n\", \"20\\n\", \"20\\n\", \"170\\n\", \"4\\n\", \"82\\n\", \"4\\n\", \"6\\n\", \"12\\n\", \"52\\n\", \"108\\n\", \"54\\n\", \"54\\n\", \"6\\n\", \"12\\n\", \"12\\n\", \"40\\n\", \"18\\n\", \"80\\n\", \"18\\n\", \"80\\n\", \"4\\n\", \"8\\n\", \"20\\n\", \"18\\n\", \"8\\n\", \"10\\n\", \"46937239178600\\n\", \"769845965585325522\\n\", \"770672213058376242\\n\", \"42\\n\", \"87800\\n\", \"720052916\\n\", \"996517375802030514\\n\", \"2\\n\", \"1772\\n\", \"7268652\\n\", \"476752445322\\n\", \"500648583102513041\\n\", \"501474821985629169\\n\", \"4\\n\", \"3574\\n\", \"29333954\\n\", \"11539143428943834\\n\", \"739331418335521551\\n\", \"740157665808572271\\n\", \"656\\n\", \"1349344\\n\", \"44264578028\\n\", \"46466414370685710\\n\", \"744288873109054799\\n\", \"745115111992170927\\n\", \"1324\\n\", \"2820495314\\n\", \"841\\n\", \"114099621\\n\", \"1\\n\", \"199261\\n\", \"10475408569\\n\", \"3859\\n\", \"479181410671\\n\", \"3\\n\", \"41817639\\n\", \"99\\n\", \"191\\n\", \"301\\n\", \"2717577\\n\", \"1079779\\n\"]}", "source": "primeintellect"}
|
At first, let's define function $f(x)$ as follows: $$ \begin{matrix} f(x) & = & \left\{ \begin{matrix} \frac{x}{2} & \mbox{if } x \text{ is even} \\ x - 1 & \mbox{otherwise } \end{matrix} \right. \end{matrix} $$
We can see that if we choose some value $v$ and will apply function $f$ to it, then apply $f$ to $f(v)$, and so on, we'll eventually get $1$. Let's write down all values we get in this process in a list and denote this list as $path(v)$. For example, $path(1) = [1]$, $path(15) = [15, 14, 7, 6, 3, 2, 1]$, $path(32) = [32, 16, 8, 4, 2, 1]$.
Let's write all lists $path(x)$ for every $x$ from $1$ to $n$. The question is next: what is the maximum value $y$ such that $y$ is contained in at least $k$ different lists $path(x)$?
Formally speaking, you need to find maximum $y$ such that $\left| \{ x ~|~ 1 \le x \le n, y \in path(x) \} \right| \ge k$.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 10^{18}$).
-----Output-----
Print the only integer — the maximum value that is contained in at least $k$ paths.
-----Examples-----
Input
11 3
Output
5
Input
11 6
Output
4
Input
20 20
Output
1
Input
14 5
Output
6
Input
1000000 100
Output
31248
-----Note-----
In the first example, the answer is $5$, since $5$ occurs in $path(5)$, $path(10)$ and $path(11)$.
In the second example, the answer is $4$, since $4$ occurs in $path(4)$, $path(5)$, $path(8)$, $path(9)$, $path(10)$ and $path(11)$.
In the third example $n = k$, so the answer is $1$, since $1$ is the only number occuring in all paths for integers from $1$ to $20$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 3 2 2 -1 1\\n\", \"4 4 2 0 1 1\\n\", \"10 10 10 1 -1 0\\n\", \"1000000000 1000000000 1 1000000000 0 1\\n\", \"2 1 1 0 -1 -1\\n\", \"4 2 1 2 1 1\\n\", \"5 3 4 3 1 -1\\n\", \"15 9 1 1 1 1\\n\", \"15 9 1 1 -1 -1\\n\", \"15 9 2 1 1 1\\n\", \"15 9 2 1 -1 1\\n\", \"1000000000 999999999 999999998 999999999 -1 -1\\n\", \"1000000000 999999999 999999998 999999999 -1 1\\n\", \"15 9 3 2 1 1\\n\", \"15 9 3 2 1 -1\\n\", \"4 4 0 1 0 1\\n\", \"4 4 4 2 0 -1\\n\", \"1000000000 999999999 999999999 999999999 1 1\\n\", \"1000000000 999999999 999999998 999999999 1 1\\n\", \"1000000000 999999999 999999998 999999999 1 -1\\n\", \"1000000000 999999999 999999998 999999999 0 1\\n\", \"1000000000 999999999 999999998 999999999 -1 0\\n\", \"1 99 0 16 -1 1\\n\", \"6 8 1 1 1 1\\n\", \"6 10 1 1 1 1\\n\", \"8 6 7 1 -1 1\\n\", \"10009 10007 1 1 1 1\\n\", \"10007 10009 10006 10008 -1 -1\\n\", \"1000 999 1 998 1 -1\\n\", \"500 500 250 250 -1 1\\n\", \"2705444 415131525 949293 337120042 1 -1\\n\", \"603278410 844534002 499505824 32181172 1 -1\\n\", \"316347709 122791181 255721626 19148895 -1 1\\n\", \"226591495 303844168 64300938 148467902 -1 -1\\n\", \"682138812 116415655 516825996 73682791 -1 1\\n\", \"305675046 505376350 144451750 295580797 -1 1\\n\", \"313157692 571680270 238352863 235464142 1 -1\\n\", \"120717601 973035857 103171773 511250918 -1 1\\n\", \"41373770 597127671 31867608 404367855 -1 1\\n\", \"827285013 307724101 775951207 175683367 -1 -1\\n\", \"110474424 613900860 31471099 442410471 -1 1\\n\", \"84035810 39157280 10865763 24269978 1 -1\\n\", \"75744115 329085002 22395692 81831548 -1 1\\n\", \"20597226 82154419 5899110 71189386 1 1\\n\", \"550269655 264187669 141601786 53516425 1 -1\\n\", \"224819588 978615384 68538326 805268586 1 1\\n\", \"979444430 110858783 607921615 88320790 1 -1\\n\", \"853950494 911554949 428001551 108479491 1 1\\n\", \"810387002 412176212 187695958 236085023 1 1\\n\", \"20877471 722211317 8457280 75966699 -1 -1\\n\", \"542708351 3475408 103232934 399149 1 1\\n\", \"30609041 976052297 4229728 158676967 -1 1\\n\", \"495082283 937762241 250777046 412284609 1 1\\n\", \"68076815 985943633 40657983 165191148 1 -1\\n\", \"209408006 202717192 115684862 96677080 -1 -1\\n\", \"651520659 433737829 645844796 133999548 1 -1\\n\", \"835624982 341676615 379293679 54053933 1 -1\\n\", \"943609111 405753192 556398014 348647907 1 -1\\n\", \"590709848 332238455 546245223 240305069 -1 1\\n\", \"320049957 92820858 176731509 15650804 1 1\\n\", \"233140029 827954502 99465884 170396111 1 1\\n\", \"760904646 962606170 641547160 113696561 -1 1\\n\", \"584801838 775270595 121061956 644380885 -1 1\\n\", \"141190266 126518281 76515989 109124404 1 1\\n\", \"225067174 487662889 175063389 447988824 1 1\\n\", \"814170008 703690544 6953086 439080555 -1 1\\n\", \"12671644 216092609 3707378 92213588 1 1\\n\", \"686521539 766868053 668178904 36804229 1 1\\n\", \"43760214 59779641 32562470 43565961 -1 1\\n\", \"281776735 833828834 271604381 491447288 -1 1\\n\", \"362762211 732244195 63812822 258610562 -1 1\\n\", \"312319019 933972106 103989975 544805243 1 -1\\n\", \"142096067 231234738 40134344 206132422 -1 1\\n\", \"289285219 692430999 249276742 628721059 1 -1\\n\", \"490696330 492707826 183410939 115542637 -1 -1\\n\", \"916524063 555774494 499847875 268662592 -1 1\\n\", \"101123973 722433301 46988094 586973439 -1 1\\n\", \"808357574 854008109 9323335 342356143 -1 -1\\n\", \"257447593 468889343 162885112 15431794 1 1\\n\", \"688226257 305863798 134250684 285725084 -1 -1\\n\", \"836255310 741706431 648685681 396741892 1 -1\\n\", \"480678700 670120443 423401724 177051387 1 1\\n\", \"35550087 590484118 10858303 37118846 1 1\\n\", \"491475453 334831307 136826756 228553610 1 -1\\n\", \"172057628 368934073 117631597 83410362 1 1\\n\", \"611927194 869083092 295778083 541333563 -1 -1\\n\", \"329666407 901295668 90510437 485008861 1 -1\\n\", \"978089453 426264909 388420346 53798427 -1 1\\n\", \"242449067 548221648 24810672 63078584 1 1\\n\", \"583053442 353408 240939980 17207 -1 1\\n\", \"10 9 8 9 -1 1\\n\", \"999999997 999999999 500 500 -1 1\\n\", \"1000000000 1000000000 999 100 -1 -1\\n\", \"7 5 2 3 1 0\\n\", \"11 13 5 7 -1 -1\\n\", \"500 1000 200 200 1 1\\n\", \"500 995 1 1 1 1\\n\", \"1 100 0 1 1 1\\n\", \"1 100 0 1 1 0\\n\", \"999999999 999999998 2 3 -1 1\\n\", \"500000000 499999999 499999999 499999999 1 1\\n\"], \"outputs\": [\"0 0\", \"-1\", \"-1\", \"-1\", \"0 1\", \"-1\", \"0 3\", \"15 9\", \"0 0\", \"-1\", \"15 0\", \"1000000000 999999999\", \"1000000000 999999999\", \"-1\", \"-1\", \"0 4\", \"4 0\", \"1000000000 0\", \"0 999999999\", \"0 999999999\", \"-1\", \"0 999999999\", \"1 99\", \"0 8\", \"6 10\", \"0 0\", \"10009 10007\", \"0 0\", \"1000 999\", \"0 500\", \"2705444 415131525\", \"603278410 844534002\", \"316347709 0\", \"0 303844168\", \"0 116415655\", \"-1\", \"-1\", \"120717601 0\", \"41373770 597127671\", \"827285013 307724101\", \"-1\", \"-1\", \"0 0\", \"0 0\", \"550269655 0\", \"224819588 978615384\", \"979444430 110858783\", \"853950494 0\", \"-1\", \"0 722211317\", \"542708351 3475408\", \"30609041 0\", \"495082283 0\", \"0 985943633\", \"209408006 202717192\", \"0 0\", \"835624982 0\", \"943609111 0\", \"0 0\", \"-1\", \"233140029 827954502\", \"-1\", \"0 775270595\", \"0 126518281\", \"225067174 487662889\", \"-1\", \"12671644 0\", \"686521539 0\", \"-1\", \"281776735 833828834\", \"362762211 732244195\", \"0 0\", \"0 231234738\", \"0 692430999\", \"490696330 0\", \"916524063 555774494\", \"101123973 0\", \"0 0\", \"-1\", \"0 305863798\", \"-1\", \"480678700 670120443\", \"35550087 590484118\", \"491475453 334831307\", \"172057628 368934073\", \"0 869083092\", \"-1\", \"0 426264909\", \"0 548221648\", \"-1\", \"10 9\", \"0 0\", \"-1\", \"-1\", \"0 0\", \"0 1000\", \"500 0\", \"1 100\", \"-1\", \"999999999 0\", \"500000000 0\"]}", "source": "primeintellect"}
|
Consider a billiard table of rectangular size $n \times m$ with four pockets. Let's introduce a coordinate system with the origin at the lower left corner (see the picture). [Image]
There is one ball at the point $(x, y)$ currently. Max comes to the table and strikes the ball. The ball starts moving along a line that is parallel to one of the axes or that makes a $45^{\circ}$ angle with them. We will assume that: the angles between the directions of the ball before and after a collision with a side are equal, the ball moves indefinitely long, it only stops when it falls into a pocket, the ball can be considered as a point, it falls into a pocket if and only if its coordinates coincide with one of the pockets, initially the ball is not in a pocket.
Note that the ball can move along some side, in this case the ball will just fall into the pocket at the end of the side.
Your task is to determine whether the ball will fall into a pocket eventually, and if yes, which of the four pockets it will be.
-----Input-----
The only line contains $6$ integers $n$, $m$, $x$, $y$, $v_x$, $v_y$ ($1 \leq n, m \leq 10^9$, $0 \leq x \leq n$; $0 \leq y \leq m$; $-1 \leq v_x, v_y \leq 1$; $(v_x, v_y) \neq (0, 0)$) — the width of the table, the length of the table, the $x$-coordinate of the initial position of the ball, the $y$-coordinate of the initial position of the ball, the $x$-component of its initial speed and the $y$-component of its initial speed, respectively. It is guaranteed that the ball is not initially in a pocket.
-----Output-----
Print the coordinates of the pocket the ball will fall into, or $-1$ if the ball will move indefinitely.
-----Examples-----
Input
4 3 2 2 -1 1
Output
0 0
Input
4 4 2 0 1 1
Output
-1
Input
10 10 10 1 -1 0
Output
-1
-----Note-----
The first sample: [Image]
The second sample: [Image]
In the third sample the ball will never change its $y$ coordinate, so the ball will never fall into a pocket.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 2 30 4\\n6 14 25 48\\n\", \"123 1 2143435 4\\n123 11 -5453 141245\\n\", \"123 1 2143435 4\\n54343 -13 6 124\\n\", \"3 2 25 2\\n379195692 -69874783\\n\", \"3 2 30 3\\n-691070108 -934106649 -220744807\\n\", \"3 3 104 17\\n9 -73896485 -290898562 5254410 409659728 -916522518 -435516126 94354167 262981034 -375897180 -80186684 -173062070 -288705544 -699097793 -11447747 320434295 503414250\\n\", \"-1000000000 -1000000000 1 1\\n232512888\\n\", \"11 0 228 5\\n-1 0 1 5 -11245\\n\", \"11 0 228 5\\n-1 -17 1 5 -11245\\n\", \"0 0 2143435 5\\n-1 -153 1 5 -11245\\n\", \"123 0 2143435 4\\n5433 0 123 -645\\n\", \"123 -1 2143435 5\\n-123 0 12 5 -11245\\n\", \"123 0 21 4\\n543453 -123 6 1424\\n\", \"3 2 115 16\\n24 48 12 96 3 720031148 -367712651 -838596957 558177735 -963046495 -313322487 -465018432 -618984128 -607173835 144854086 178041956\\n\", \"-3 0 92055 36\\n-92974174 -486557474 -663622151 695596393 177960746 -563227474 -364263320 -676254242 -614140218 71456762 -764104225 705056581 -106398436 332755134 -199942822 -732751692 658942664 677739866 886535704 183687802 -784248291 -22550621 -938674499 637055091 -704750213 780395802 778342470 -999059668 -794361783 796469192 215667969 354336794 -60195289 -885080928 -290279020 201221317\\n\", \"0 -3 2143435 5\\n-1 0 1 5 -11245\\n\", \"123 -1 2143435 5\\n-123 0 123 -5453 141245\\n\", \"123 0 2143435 4\\n5433 0 -123 -645\\n\", \"11 0 2 5\\n-1 0 1 5 -11245\\n\", \"2 2 4 1\\n2\\n\", \"1 -2 1000000000 1\\n0\\n\", \"0 8 10 1\\n5\\n\", \"-1000 0 10 1\\n5\\n\", \"0 2 2143435 4\\n54343 -13 6 124\\n\", \"0 8 5 1\\n9\\n\", \"-10 1 5 1\\n100\\n\", \"123 -1 2143435 4\\n54343 -13 6 123\\n\", \"-5 -1 10 1\\n-5\\n\", \"2 0 1 1\\n2\\n\", \"0 5 8 1\\n10\\n\", \"0 5 100 2\\n34 56\\n\", \"15 -1 15 4\\n15 -15 1 2\\n\", \"10 -1 2 1\\n1\\n\", \"2 0 2 1\\n2\\n\", \"4 0 4 1\\n0\\n\", \"10 10 10 1\\n123\\n\", \"2 2 4 1\\n3\\n\", \"0 1 1 1\\n0\\n\", \"3 2 30 1\\n3\\n\", \"1000000000 100000 1000000000 4\\n5433 13 6 0\\n\", \"-2 0 1 1\\n1\\n\", \"2 -1 10 1\\n2\\n\", \"1 -1 2 1\\n1\\n\", \"0 10 10 1\\n2\\n\", \"0 35 2 1\\n3\\n\", \"3 1 3 1\\n5\\n\", \"3 2 3 4\\n6 14 25 48\\n\", \"0 69 12 1\\n1\\n\", \"100 0 100000 1\\n100\\n\", \"0 4 1000 3\\n5 6 7\\n\", \"0 2 100 1\\n5\\n\", \"3 2 24 4\\n6 14 25 48\\n\", \"0 4 1 1\\n2\\n\", \"1 5 10000 1\\n125\\n\", \"2 -1 1 1\\n1\\n\", \"0 3 100 1\\n5\\n\", \"0 3 3 1\\n1\\n\", \"0 2 5 1\\n1\\n\", \"5 -1 100 1\\n5\\n\", \"-20 0 10 1\\n0\\n\", \"3 0 1 1\\n3\\n\", \"2 -1 3 1\\n2\\n\", \"1 1 1000000000 1\\n100\\n\", \"5 -1 3 1\\n0\\n\", \"0 5 10 1\\n2\\n\", \"123 0 125 1\\n123\\n\", \"2 -1 100 1\\n2\\n\", \"5 2 100 1\\n5\\n\", \"-5 0 1 1\\n1\\n\", \"-3 0 1 1\\n-3\\n\", \"2 -2 10 1\\n1\\n\", \"0 2 30 4\\n6 14 25 48\\n\", \"1 -1 1 1\\n1\\n\", \"2 -1 6 1\\n2\\n\", \"-3 1 100 1\\n-3\\n\", \"1 0 2 1\\n1\\n\", \"1000000000 999999998 1000000000 1\\n0\\n\", \"1 0 2143435 4\\n1 -123 -5453 141245\\n\", \"-1000 0 100 1\\n-1000\\n\", \"100 10 2 1\\n100\\n\", \"-3 1 100 1\\n3\\n\", \"123 -1 10000 1\\n123\\n\", \"1 -1 2143435 4\\n1 -123 -5453 141245\\n\", \"5 1 5 5\\n1 2 3 4 0\\n\", \"-100 -1 1 1\\n1\\n\", \"10 -1 3 2\\n10 8\\n\", \"-10 0 5 1\\n0\\n\", \"3 0 3 1\\n0\\n\", \"2 0 2 1\\n-1\\n\", \"5 0 20 1\\n5\\n\", \"-4 1 1 1\\n0\\n\", \"11 0 1111 1\\n11\\n\", \"2 0 3 1\\n2\\n\", \"-1 -1 2143435 4\\n-1 -123 -5453 141245\\n\", \"-100 0 50 1\\n0\\n\", \"5 1 2 1\\n2\\n\", \"3 0 3 1\\n4\\n\", \"0 23 3 1\\n3\\n\", \"-1000 0 100 1\\n2\\n\", \"1 -1 10 1\\n1\\n\"], \"outputs\": [\"3\", \"0\", \"inf\", \"4\", \"4\", \"3\", \"0\", \"1\", \"inf\", \"inf\", \"0\", \"inf\", \"0\", \"1\", \"inf\", \"0\", \"0\", \"1\", \"0\", \"1\", \"30\", \"inf\", \"0\", \"inf\", \"inf\", \"0\", \"inf\", \"inf\", \"0\", \"inf\", \"inf\", \"0\", \"0\", \"inf\", \"1\", \"1\", \"2\", \"0\", \"3\", \"1\", \"0\", \"inf\", \"inf\", \"inf\", \"inf\", \"inf\", \"1\", \"inf\", \"inf\", \"inf\", \"inf\", \"3\", \"inf\", \"5\", \"0\", \"inf\", \"inf\", \"inf\", \"inf\", \"0\", \"0\", \"inf\", \"inf\", \"0\", \"inf\", \"inf\", \"inf\", \"4\", \"0\", \"0\", \"3\", \"inf\", \"inf\", \"inf\", \"0\", \"inf\", \"1\", \"inf\", \"0\", \"0\", \"inf\", \"inf\", \"inf\", \"inf\", \"0\", \"0\", \"0\", \"1\", \"inf\", \"inf\", \"0\", \"inf\", \"inf\", \"inf\", \"0\", \"0\", \"inf\", \"inf\", \"0\", \"inf\"]}", "source": "primeintellect"}
|
Masha really loves algebra. On the last lesson, her strict teacher Dvastan gave she new exercise.
You are given geometric progression b defined by two integers b_1 and q. Remind that a geometric progression is a sequence of integers b_1, b_2, b_3, ..., where for each i > 1 the respective term satisfies the condition b_{i} = b_{i} - 1·q, where q is called the common ratio of the progression. Progressions in Uzhlyandia are unusual: both b_1 and q can equal 0. Also, Dvastan gave Masha m "bad" integers a_1, a_2, ..., a_{m}, and an integer l.
Masha writes all progression terms one by one onto the board (including repetitive) while condition |b_{i}| ≤ l is satisfied (|x| means absolute value of x). There is an exception: if a term equals one of the "bad" integers, Masha skips it (doesn't write onto the board) and moves forward to the next term.
But the lesson is going to end soon, so Masha has to calculate how many integers will be written on the board. In order not to get into depression, Masha asked you for help: help her calculate how many numbers she will write, or print "inf" in case she needs to write infinitely many integers.
-----Input-----
The first line of input contains four integers b_1, q, l, m (-10^9 ≤ b_1, q ≤ 10^9, 1 ≤ l ≤ 10^9, 1 ≤ m ≤ 10^5) — the initial term and the common ratio of progression, absolute value of maximal number that can be written on the board and the number of "bad" integers, respectively.
The second line contains m distinct integers a_1, a_2, ..., a_{m} (-10^9 ≤ a_{i} ≤ 10^9) — numbers that will never be written on the board.
-----Output-----
Print the only integer, meaning the number of progression terms that will be written on the board if it is finite, or "inf" (without quotes) otherwise.
-----Examples-----
Input
3 2 30 4
6 14 25 48
Output
3
Input
123 1 2143435 4
123 11 -5453 141245
Output
0
Input
123 1 2143435 4
54343 -13 6 124
Output
inf
-----Note-----
In the first sample case, Masha will write integers 3, 12, 24. Progression term 6 will be skipped because it is a "bad" integer. Terms bigger than 24 won't be written because they exceed l by absolute value.
In the second case, Masha won't write any number because all terms are equal 123 and this is a "bad" integer.
In the third case, Masha will write infinitely integers 123.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"4 8\\n..w..w..\\n........\\n........\\n..w..w..\\n\", \"5 6\\n......\\n.w....\\n......\\n..w...\\n......\\n\", \"2 4\\n....\\n.w..\\n\", \"2 6\\nw..w.w\\n...w..\\n\", \"9 4\\n....\\n....\\n....\\n....\\n....\\n..w.\\n....\\n....\\n.w..\\n\", \"10 4\\n....\\n.w..\\n....\\n....\\n.w..\\n....\\n....\\n....\\n....\\n....\\n\", \"4 10\\n..........\\n..........\\n.w..w.....\\n..........\\n\", \"3 3\\n...\\nw.w\\n...\\n\", \"1 1\\nw\\n\", \"2 1\\nw\\n.\\n\", \"2 1\\nw\\nw\\n\", \"1 2\\nww\\n\", \"2 2\\nww\\n..\\n\", \"2 2\\n.w\\n.w\\n\", \"2 2\\n..\\nww\\n\", \"2 2\\nw.\\nw.\\n\", \"2 2\\nw.\\n.w\\n\", \"2 2\\n..\\nw.\\n\", \"3 3\\n...\\n..w\\nw..\\n\", \"3 3\\n.w.\\n..w\\n...\\n\", \"4 4\\nw...\\n..w.\\n....\\n....\\n\", \"4 6\\n....w.\\n......\\n.w....\\n......\\n\", \"4 6\\n....w.\\n......\\n......\\n.w....\\n\", \"4 6\\nw...w.\\n......\\n......\\n.w....\\n\", \"4 6\\nw.....\\n......\\n......\\n.w....\\n\", \"4 6\\nw....w\\n......\\n.....w\\n.w....\\n\", \"7 3\\n...\\n...\\n...\\n..w\\n...\\nw..\\n...\\n\", \"7 3\\n...\\n...\\n...\\n.w.\\n..w\\nw..\\n...\\n\", \"7 3\\n...\\n...\\n...\\n.w.\\nw.w\\nw..\\n...\\n\", \"5 7\\n.......\\n.......\\n.......\\n.www...\\n.......\\n\", \"5 7\\n.......\\n.wwww..\\n.......\\n.......\\n.......\\n\", \"5 7\\n.......\\n.w.....\\n.w.....\\n.w.....\\n.w.....\\n\", \"1 7\\nw.....w\\n\", \"6 9\\n.w.......\\n.........\\n.........\\n.........\\n.w.......\\n......w..\\n\", \"6 9\\n...ww....\\n.........\\n.........\\n.........\\n.........\\n......w..\\n\", \"6 9\\n.......w.\\n.........\\n.........\\n.........\\n.........\\n......w..\\n\", \"8 10\\n..........\\n...w......\\n.....w....\\n.w........\\n....w.....\\n..........\\n..........\\n..........\\n\", \"8 10\\n..........\\n...w......\\n.....w....\\n.w........\\n..........\\n....w.....\\n..........\\n..........\\n\", \"8 10\\n..........\\n...w......\\n..........\\n.w........\\n..........\\n....w.....\\n..........\\n..........\\n\", \"8 10\\n..........\\n..........\\n.....w....\\n.w........\\n..........\\n....w.....\\n..........\\n..........\\n\", \"8 10\\n..........\\n...w......\\n..........\\n..........\\n..........\\n....w.....\\n..........\\n..........\\n\", \"5 4\\n....\\n....\\n....\\nw...\\n....\\n\", \"5 4\\n....\\nw...\\n...w\\n.w..\\n..w.\\n\", \"5 4\\nw..w\\n...w\\nw...\\n..w.\\n....\\n\", \"5 4\\nwwww\\nwwww\\nwwww\\nwwww\\nwwww\\n\", \"5 4\\n..w.\\n..ww\\n.www\\n.w..\\nwwww\\n\", \"5 4\\n....\\n.w..\\n....\\n.w..\\n....\\n\", \"5 4\\nw...\\n....\\n...w\\n....\\n....\\n\", \"5 4\\nwwww\\nw..w\\nwwww\\n.www\\n..ww\\n\", \"5 4\\n..w.\\n....\\n...w\\n..w.\\nw...\\n\", \"6 5\\n.w...\\n.....\\n.....\\n.....\\nw....\\n.....\\n\", \"8 16\\n................\\n................\\n................\\n................\\n............w...\\n................\\n................\\n..............w.\\n\", \"3 10\\n.......w..\\n........w.\\n......w...\\n\", \"10 3\\n...\\n...\\n...\\n...\\n...\\n...\\n.w.\\n..w\\nw..\\n...\\n\", \"1 2\\n.w\\n\", \"2 2\\n.w\\n..\\n\", \"5 2\\n..\\n.w\\nww\\n..\\n..\\n\", \"1 6\\n..w...\\n\", \"4 4\\n..w.\\n....\\n....\\n....\\n\", \"6 2\\nw.\\n..\\n..\\n..\\n..\\n..\\n\", \"3 2\\n..\\n.w\\n..\\n\", \"5 6\\n......\\n......\\n.ww...\\n......\\n......\\n\", \"1 4\\nw...\\n\", \"4 2\\nw.\\n..\\n..\\n..\\n\", \"6 3\\n...\\n...\\nw.w\\n...\\nwww\\n...\\n\", \"2 1\\n.\\nw\\n\", \"5 5\\n.....\\n.....\\n.....\\n.w...\\n.....\\n\", \"1 5\\nw....\\n\", \"4 3\\nw..\\n...\\n...\\n...\\n\", \"6 1\\n.\\n.\\nw\\n.\\n.\\n.\\n\", \"2 5\\n.....\\nww...\\n\", \"5 5\\n.....\\n.....\\n..ww.\\n.....\\n.....\\n\", \"1 3\\n..w\\n\", \"4 1\\n.\\nw\\n.\\n.\\n\", \"6 2\\n..\\n.w\\n..\\n..\\n..\\n..\\n\", \"2 1\\nw\\n.\\n\", \"5 1\\n.\\n.\\n.\\nw\\n.\\n\", \"1 5\\n....w\\n\", \"4 3\\n..w\\nw.w\\n...\\n...\\n\", \"6 1\\nw\\n.\\n.\\n.\\n.\\n.\\n\", \"2 1\\nw\\n.\\n\", \"5 5\\n.....\\n...w.\\n.....\\n.....\\n.w...\\n\", \"1 3\\n.w.\\n\", \"4 1\\n.\\n.\\n.\\nw\\n\", \"4 2\\n..\\nw.\\n.w\\n..\\n\", \"6 6\\n......\\nw.....\\n...w..\\n.w....\\n......\\n......\\n\", \"3 6\\n......\\n....w.\\n......\\n\", \"5 4\\nw.w.\\nw...\\nwww.\\n....\\n....\\n\", \"2 2\\n..\\nw.\\n\", \"4 2\\n..\\n..\\nw.\\n..\\n\", \"1 6\\n.....w\\n\", \"3 4\\nw...\\n..w.\\n.ww.\\n\", \"5 2\\n..\\n..\\n..\\n..\\nw.\\n\", \"2 2\\n..\\nw.\\n\", \"2 1\\nw\\n.\\n\", \"4 1\\n.\\n.\\nw\\n.\\n\", \"1 5\\nw....\\n\", \"3 3\\n...\\n...\\n.w.\\n\", \"6 1\\n.\\nw\\n.\\n.\\n.\\n.\\n\", \"2 1\\n.\\nw\\n\", \"5 5\\n.w...\\n.....\\n.....\\n.....\\n.....\\n\", \"1 3\\n..w\\n\", \"3 1\\n.\\n.\\nw\\n\", \"6 1\\n.\\n.\\n.\\n.\\n.\\nw\\n\", \"6 3\\n...\\n...\\n...\\n...\\n...\\n.w.\\n\"], \"outputs\": [\"..w++w..\\n..+..+..\\n..+..+..\\n..w++w..\\n\", \"......\\n+w+...\\n+.+...\\n++w...\\n......\\n\", \"....\\n.w..\\n\", \"-1\\n\", \"....\\n....\\n....\\n....\\n....\\n++w+\\n+..+\\n+..+\\n+w++\\n\", \"....\\n+w++\\n+..+\\n+..+\\n+w++\\n....\\n....\\n....\\n....\\n....\\n\", \".++++.....\\n.+..+.....\\n.w..w.....\\n.++++.....\\n\", \"+++\\nw.w\\n+++\\n\", \"w\\n\", \"w\\n.\\n\", \"-1\\n\", \"-1\\n\", \"ww\\n++\\n\", \"+w\\n+w\\n\", \"++\\nww\\n\", \"w+\\nw+\\n\", \"w+\\n+w\\n\", \"..\\nw.\\n\", \"+++\\n+.w\\nw++\\n\", \".w+\\n.+w\\n...\\n\", \"w++.\\n+.w.\\n+++.\\n....\\n\", \".+++w.\\n.+..+.\\n.w..+.\\n.++++.\\n\", \".+++w.\\n.+..+.\\n.+..+.\\n.w+++.\\n\", \"-1\\n\", \"w+++..\\n+..+..\\n+..+..\\n+w++..\\n\", \"-1\\n\", \"...\\n...\\n...\\n++w\\n+.+\\nw++\\n...\\n\", \"...\\n...\\n...\\n+w+\\n+.w\\nw++\\n...\\n\", \"...\\n...\\n...\\n+w+\\nw.w\\nw++\\n...\\n\", \".......\\n.+++...\\n.+.+...\\n.www...\\n.......\\n\", \".......\\n.wwww..\\n.+..+..\\n.+..+..\\n.++++..\\n\", \".......\\n.w+++..\\n.w..+..\\n.w..+..\\n.w+++..\\n\", \"-1\\n\", \".w+++++..\\n.+....+..\\n.+....+..\\n.+....+..\\n.w....+..\\n.+++++w..\\n\", \"...ww++++\\n...+....+\\n...+....+\\n...+....+\\n...+....+\\n...+++w++\\n\", \"..+++++w.\\n..+....+.\\n..+....+.\\n..+....+.\\n..+....+.\\n..++++w+.\\n\", \"-1\\n\", \"..........\\n.++w++....\\n.+...w....\\n.w...+....\\n.+...+....\\n.+++w+....\\n..........\\n..........\\n\", \"..........\\n.++w++....\\n.+...+....\\n.w...+....\\n.+...+....\\n.+++w+....\\n..........\\n..........\\n\", \"..........\\n.+++++....\\n.+...w....\\n.w...+....\\n.+...+....\\n.+++w+....\\n..........\\n..........\\n\", \"..........\\n+++w+.....\\n+...+.....\\n+...+.....\\n+...+.....\\n++++w.....\\n..........\\n..........\\n\", \"....\\n....\\n....\\nw...\\n....\\n\", \"-1\\n\", \"w++w\\n+..w\\nw..+\\n++w+\\n....\\n\", \"-1\\n\", \"-1\\n\", \"....\\n+w+.\\n+.+.\\n+w+.\\n....\\n\", \"w+++\\n+..+\\n+..w\\n++++\\n....\\n\", \"-1\\n\", \"-1\\n\", \"+w+++\\n+...+\\n+...+\\n+...+\\nw++++\\n.....\\n\", \"................\\n................\\n................\\n................\\n............w+++\\n............+..+\\n............+..+\\n............++w+\\n\", \"......+w+.\\n......+.w.\\n......w++.\\n\", \"...\\n...\\n...\\n...\\n...\\n...\\n+w+\\n+.w\\nw++\\n...\\n\", \".w\\n\", \".w\\n..\\n\", \"..\\n+w\\nww\\n..\\n..\\n\", \"..w...\\n\", \"..w.\\n....\\n....\\n....\\n\", \"w.\\n..\\n..\\n..\\n..\\n..\\n\", \"..\\n.w\\n..\\n\", \"......\\n......\\n.ww...\\n.++...\\n......\\n\", \"w...\\n\", \"w.\\n..\\n..\\n..\\n\", \"...\\n...\\nw+w\\n+.+\\nwww\\n...\\n\", \".\\nw\\n\", \".....\\n.....\\n.....\\n.w...\\n.....\\n\", \"w....\\n\", \"w..\\n...\\n...\\n...\\n\", \".\\n.\\nw\\n.\\n.\\n.\\n\", \"++...\\nww...\\n\", \".....\\n.....\\n..ww.\\n..++.\\n.....\\n\", \"..w\\n\", \".\\nw\\n.\\n.\\n\", \"..\\n.w\\n..\\n..\\n..\\n..\\n\", \"w\\n.\\n\", \".\\n.\\n.\\nw\\n.\\n\", \"....w\\n\", \"++w\\nw.w\\n+++\\n...\\n\", \"w\\n.\\n.\\n.\\n.\\n.\\n\", \"w\\n.\\n\", \".....\\n+++w.\\n+..+.\\n+..+.\\n+w++.\\n\", \".w.\\n\", \".\\n.\\n.\\nw\\n\", \"..\\nw+\\n+w\\n..\\n\", \"++++..\\nw..+..\\n+..w..\\n+w++..\\n......\\n......\\n\", \"......\\n....w.\\n......\\n\", \"w+w.\\nw.+.\\nwww.\\n....\\n....\\n\", \"..\\nw.\\n\", \"..\\n..\\nw.\\n..\\n\", \".....w\\n\", \"w++.\\n+.w.\\n+ww.\\n\", \"..\\n..\\n..\\n..\\nw.\\n\", \"..\\nw.\\n\", \"w\\n.\\n\", \".\\n.\\nw\\n.\\n\", \"w....\\n\", \"...\\n...\\n.w.\\n\", \".\\nw\\n.\\n.\\n.\\n.\\n\", \".\\nw\\n\", \".w...\\n.....\\n.....\\n.....\\n.....\\n\", \"..w\\n\", \".\\n.\\nw\\n\", \".\\n.\\n.\\n.\\n.\\nw\\n\", \"...\\n...\\n...\\n...\\n...\\n.w.\\n\"]}", "source": "primeintellect"}
|
Innocentius has a problem — his computer monitor has broken. Now some of the pixels are "dead", that is, they are always black. As consequence, Innocentius can't play the usual computer games. He is recently playing the following game with his younger brother Polycarpus.
Innocentius is touch-typing a program that paints a white square one-pixel wide frame on the black screen. As the monitor is broken, some pixels that should be white remain black. Polycarpus should look at what the program displayed on the screen and guess the position and size of the frame Innocentius has painted. Polycarpus doesn't like the game but Innocentius persuaded brother to play as "the game is good for the imagination and attention".
Help Polycarpus, automatize his part in the gaming process. Write the code that finds such possible square frame that: the frame's width is 1 pixel, the frame doesn't go beyond the borders of the screen, all white pixels of the monitor are located on the frame, of all frames that satisfy the previous three conditions, the required frame must have the smallest size.
Formally, a square frame is represented by such pixels of the solid square, that are on the square's border, that is, are not fully surrounded by the other pixels of the square. For example, if the frame's size is d = 3, then it consists of 8 pixels, if its size is d = 2, then it contains 4 pixels and if d = 1, then the frame is reduced to a single pixel.
-----Input-----
The first line contains the resolution of the monitor as a pair of integers n, m (1 ≤ n, m ≤ 2000). The next n lines contain exactly m characters each — the state of the monitor pixels at the moment of the game. Character "." (period, ASCII code 46) corresponds to the black pixel, and character "w" (lowercase English letter w) corresponds to the white pixel. It is guaranteed that at least one pixel of the monitor is white.
-----Output-----
Print the monitor screen. Represent the sought frame by characters "+" (the "plus" character). The pixels that has become white during the game mustn't be changed. Print them as "w". If there are multiple possible ways to position the frame of the minimum size, print any of them.
If the required frame doesn't exist, then print a single line containing number -1.
-----Examples-----
Input
4 8
..w..w..
........
........
..w..w..
Output
..w++w..
..+..+..
..+..+..
..w++w..
Input
5 6
......
.w....
......
..w...
......
Output
......
+w+...
+.+...
++w...
......
Input
2 4
....
.w..
Output
....
.w..
Input
2 6
w..w.w
...w..
Output
-1
-----Note-----
In the first sample the required size of the optimal frame equals 4. In the second sample the size of the optimal frame equals 3. In the third sample, the size of the optimal frame is 1. In the fourth sample, the required frame doesn't exist.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"6\\n1 3 4 5 6 9\\n\", \"3\\n998 999 1000\\n\", \"5\\n1 2 3 4 5\\n\", \"1\\n1\\n\", \"2\\n1 2\\n\", \"2\\n999 1000\\n\", \"9\\n1 4 5 6 7 100 101 102 103\\n\", \"100\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100\\n\", \"8\\n6 8 9 11 14 18 19 20\\n\", \"2\\n1 7\\n\", \"1\\n779\\n\", \"5\\n3 8 25 37 43\\n\", \"73\\n38 45 46 95 98 99 103 157 164 175 184 193 208 251 258 276 279 282 319 329 336 344 349 419 444 452 490 499 507 508 519 542 544 553 562 576 579 590 594 603 634 635 648 659 680 686 687 688 695 698 743 752 757 774 776 779 792 809 860 879 892 911 918 927 928 945 947 951 953 958 959 960 983\\n\", \"15\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15\\n\", \"63\\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\\n\", \"100\\n252 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 409 410 425 426 604 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895\\n\", \"95\\n34 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 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 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 911 912 913\\n\", \"90\\n126 239 240 241 242 253 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 600 601 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 934 935\\n\", \"85\\n52 53 54 55 56 57 58 59 60 61 62 63 64 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 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 333 334 453 454 455 456 457 458 459 460 461 462 463 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624\\n\", \"80\\n237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 408 409 410 411 412 413 414 415 416 417 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 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\\n\", \"70\\n72 73 74 75 76 77 78 79 80 81 82 354 355 356 357 358 359 360 361 362 363 364 365 366 367 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 764 765 766 767 768 769 770 794 795 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826\\n\", \"75\\n327 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\\n\", \"60\\n12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 134 135 136 137 353 354 355 356 357 358 359 360 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\\n\", \"65\\n253 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 533 614 615 864\\n\", \"55\\n67 68 69 70 160 161 162 163 164 165 166 167 168 169 170 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 960\\n\", \"50\\n157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 632 633 634 635 636 637 638\\n\", \"45\\n145 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 333 334 831 832 978 979 980 981\\n\", \"100\\n901 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\\n\", \"10\\n1 2 3 4 5 6 7 8 9 10\\n\", \"10\\n991 992 993 994 995 996 997 998 999 1000\\n\", \"39\\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\\n\", \"42\\n959 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\\n\", \"100\\n144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 198 199 200 201 202 203 204 205 206 207 208 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 376 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 904 905 997\\n\", \"95\\n9 10 11 12 13 134 271 272 273 274 275 276 277 278 290 291 292 293 294 295 296 297 298 299 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 620 621 622 623 624 625 626 627 628 629 630 631 632 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 952\\n\", \"90\\n20 21 22 23 24 25 56 57 58 59 60 61 62 63 64 84 85 404 405 406 407 408 409 410 420 421 422 423 424 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 491 492 588 589 590 652 653 654 655 656 657 754 755 756 757 758 759 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 982 983 984 985 986 987 988 989 990 991 992 995\\n\", \"85\\n40 41 42 43 44 69 70 71 72 73 305 306 307 308 309 333 334 335 336 337 338 339 340 341 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 717 718 719 720 721 862 863 864 865 866 867 868 869 870 871 872 873 874 945 946 947 948 949 950\\n\", \"80\\n87 88 89 90 91 92 93 94 95 96 97 98 99 173 174 175 176 177 178 179 180 184 185 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 550 551 552 553 554 555 650 702 703 704 705 706 707 708 709 710 727 728 729 730 731 798 799 800 831 832 833 869 870 980 981 982 983 984 985 986 987 988 989 990 991 992\\n\", \"1\\n1000\\n\", \"2\\n998 999\\n\", \"2\\n3 4\\n\", \"3\\n9 10 11\\n\", \"6\\n4 5 6 7 8 9\\n\", \"5\\n5 6 7 8 9\\n\", \"8\\n1 2 5 6 7 8 9 11\\n\", \"4\\n1 2 3 6\\n\", \"4\\n1 2 3 66\\n\", \"7\\n1 2 5 6 7 8 9\\n\", \"2\\n2 4\\n\", \"8\\n1 2 5 6 7 8 9 1000\\n\", \"2\\n1 1000\\n\", \"4\\n3 4 5 6\\n\", \"5\\n2 3 4 5 6\\n\", \"6\\n1 2 3 4 5 7\\n\", \"6\\n1 996 997 998 999 1000\\n\", \"5\\n1 2 3 4 6\\n\", \"6\\n1 2 3 5 6 7\\n\", \"3\\n3 4 5\\n\", \"1\\n5\\n\", \"3\\n2 3 4\\n\", \"7\\n1 3 5 997 998 999 1000\\n\", \"4\\n3 4 5 10\\n\", \"3\\n997 998 999\\n\", \"7\\n1 2 3 4 6 7 8\\n\", \"2\\n2 3\\n\", \"7\\n2 3 4 6 997 998 999\\n\", \"1\\n2\\n\", \"3\\n4 5 6\\n\", \"2\\n5 6\\n\", \"7\\n1 2 3 997 998 999 1000\\n\", \"4\\n1 3 999 1000\\n\", \"5\\n1 3 5 7 9\\n\", \"6\\n1 2 3 4 5 10\\n\", \"4\\n1 2 999 1000\\n\", \"2\\n10 20\\n\", \"5\\n2 3 4 5 10\\n\", \"4\\n2 3 4 5\\n\", \"42\\n35 145 153 169 281 292 299 322 333 334 358 382 391 421 436 447 464 467 478 491 500 538 604 667 703 705 716 718 724 726 771 811 827 869 894 895 902 912 942 961 962 995\\n\", \"3\\n10 11 12\\n\", \"7\\n1 2 3 4 6 9 18\\n\", \"5\\n1 2 3 4 800\\n\", \"5\\n1 2 3 4 1000\\n\", \"5\\n1 997 998 999 1000\\n\", \"6\\n1 2 6 7 8 9\\n\", \"4\\n1 2 3 5\\n\", \"9\\n1 2 3 7 8 9 10 11 13\\n\", \"4\\n1 2 5 6\\n\", \"6\\n1 2 5 6 7 8\\n\", \"5\\n1 2 3 999 1000\\n\", \"100\\n656 658 660 662 664 666 668 670 672 674 676 678 680 682 684 686 688 690 692 694 696 698 700 702 704 706 708 710 712 714 716 718 720 722 724 726 728 730 732 734 736 738 740 742 744 746 748 750 752 754 756 758 760 762 764 766 768 770 772 774 776 778 780 782 784 786 788 790 792 794 796 798 800 802 804 806 808 810 812 814 816 818 820 822 824 826 828 830 832 834 836 838 840 842 844 848 850 852 999 1000\\n\", \"3\\n1 2 9\\n\", \"8\\n2 3 4 5 997 998 999 1000\\n\", \"9\\n1 2 3 4 6 7 9 10 12\\n\", \"4\\n1 2 7 8\\n\", \"3\\n1 2 5\\n\", \"5\\n1 2 998 999 1000\\n\", \"4\\n1 2 3 7\\n\", \"7\\n2 4 6 997 998 999 1000\\n\", \"5\\n1 2 3 5 6\\n\", \"6\\n3 4 5 998 999 1000\\n\"], \"outputs\": [\"2\", \"2\", \"4\", \"0\", \"1\", \"1\", \"2\", \"99\", \"1\", \"0\", \"0\", \"0\", \"1\", \"14\", \"62\", \"70\", \"35\", \"44\", \"23\", \"25\", \"19\", \"72\", \"24\", \"59\", \"21\", \"20\", \"35\", \"99\", \"9\", \"9\", \"38\", \"41\", \"16\", \"20\", \"15\", \"18\", \"13\", \"0\", \"0\", \"0\", \"1\", \"4\", \"3\", \"3\", \"2\", \"2\", \"3\", \"0\", \"3\", \"0\", \"2\", \"3\", \"4\", \"4\", \"3\", \"2\", \"1\", \"0\", \"1\", \"3\", \"1\", \"1\", \"3\", \"0\", \"1\", \"0\", \"1\", \"0\", \"3\", \"1\", \"0\", \"4\", \"1\", \"0\", \"2\", \"2\", \"0\", \"1\", \"3\", \"3\", \"3\", \"3\", \"2\", \"2\", \"3\", \"1\", \"2\", \"2\", \"1\", \"1\", \"3\", \"3\", \"1\", \"1\", \"2\", \"2\", \"3\", \"2\", \"2\"]}", "source": "primeintellect"}
|
JATC and his friend Giraffe are currently in their room, solving some problems. Giraffe has written on the board an array $a_1$, $a_2$, ..., $a_n$ of integers, such that $1 \le a_1 < a_2 < \ldots < a_n \le 10^3$, and then went to the bathroom.
JATC decided to prank his friend by erasing some consecutive elements in the array. Since he doesn't want for the prank to go too far, he will only erase in a way, such that Giraffe can still restore the array using the information from the remaining elements. Because Giraffe has created the array, he's also aware that it's an increasing array and all the elements are integers in the range $[1, 10^3]$.
JATC wonders what is the greatest number of elements he can erase?
-----Input-----
The first line of the input contains a single integer $n$ ($1 \le n \le 100$) — the number of elements in the array.
The second line of the input contains $n$ integers $a_i$ ($1 \le a_1<a_2<\dots<a_n \le 10^3$) — the array written by Giraffe.
-----Output-----
Print a single integer — the maximum number of consecutive elements in the array that JATC can erase.
If it is impossible to erase even a single element, print $0$.
-----Examples-----
Input
6
1 3 4 5 6 9
Output
2
Input
3
998 999 1000
Output
2
Input
5
1 2 3 4 5
Output
4
-----Note-----
In the first example, JATC can erase the third and fourth elements, leaving the array $[1, 3, \_, \_, 6, 9]$. As you can see, there is only one way to fill in the blanks.
In the second example, JATC can erase the second and the third elements. The array will become $[998, \_, \_]$. Because all the elements are less than or equal to $1000$, the array is still can be restored. Note, that he can't erase the first $2$ elements.
In the third example, JATC can erase the first $4$ elements. Since all the elements are greater than or equal to $1$, Giraffe can still restore the array. Note, that he can't erase the last $4$ elements.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 3 2 3\\n\", \"12 17 9 40\\n\", \"1 1 1 1\\n\", \"10 10 5 100\\n\", \"7 1 1 4\\n\", \"1000 1000 59 100000\\n\", \"100000 100000 1000 100000\\n\", \"100000 100000 100000 100000\\n\", \"3 100000 2 88700\\n\", \"200 100000 55 100000\\n\", \"74 2 1 36\\n\", \"2 59 1 112\\n\", \"96 33 24 928\\n\", \"20 78 8 997\\n\", \"44 22 13 515\\n\", \"68 66 33 2353\\n\", \"96 7 4 534\\n\", \"20 59 2 88\\n\", \"45 3 1 35\\n\", \"69 48 18 167\\n\", \"34994 5189 2572 83748\\n\", \"51122 86737 45712 45929\\n\", \"1308 96219 150 13599\\n\", \"84732 45064 24231 99973\\n\", \"860 93908 193 29450\\n\", \"51580 42753 1589 91632\\n\", \"67708 58893 32854 21110\\n\", \"51133 7737 2779 83291\\n\", \"67261 65094 36712 36961\\n\", \"17981 81234 438 66438\\n\", \"86852 96025 86852 82059\\n\", \"96877 86600 86600 94110\\n\", \"93240 88881 88881 94245\\n\", \"90706 97197 90706 96593\\n\", \"93289 95214 93289 96084\\n\", \"90755 85790 85790 98432\\n\", \"80779 83807 80779 97924\\n\", \"98246 89266 89266 80270\\n\", \"80828 99843 80828 99763\\n\", \"98295 88157 88157 82110\\n\", \"52329 55202 45142 8532\\n\", \"68457 4046 983 38009\\n\", \"18644 46233 17019 62575\\n\", \"2068 62373 1084 92053\\n\", \"18196 43921 15918 54235\\n\", \"68916 60062 7636 83712\\n\", \"85044 8906 4115 45894\\n\", \"68468 33559 15324 99563\\n\", \"84596 49699 46033 61745\\n\", \"35316 31247 27829 91223\\n\", \"51444 47388 21532 20700\\n\", \"67572 96232 61366 50178\\n\", \"17759 38418 4313 7448\\n\", \"1183 87263 148 4221\\n\", \"84607 36107 29486 33699\\n\", \"68031 52248 51042 20073\\n\", \"84159 1092 683 49550\\n\", \"67583 49936 46141 11732\\n\", \"51007 74589 14733 41209\\n\", \"34431 23433 19371 27583\\n\", \"52 45 38 49\\n\", \"80 89 32 26\\n\", \"74 63 30 92\\n\", \"2 20 1 14\\n\", \"22 60 13 48\\n\", \"50 5 4 29\\n\", \"74 49 48 99\\n\", \"2 89 2 80\\n\", \"22 38 9 58\\n\", \"50 86 11 36\\n\", \"98155 95063 95062 98875\\n\", \"95606 98563 95342 99783\\n\", \"95468 97642 95176 95192\\n\", \"96394 96141 96028 96100\\n\", \"100000 1 1 99999\\n\", \"100000 100000 1 100000\\n\", \"100000 100000 100000 1\\n\", \"88888 99999 77777 1\\n\", \"77777 99999 77777 7\\n\", \"100000 100000 1 1\\n\", \"3689 2691 1885 47808\\n\", \"3907 4563 2248 99346\\n\", \"1785 3525 1785 82536\\n\", \"4761 2433 2433 46586\\n\", \"3106 2359 1558 16919\\n\", \"3291 1679 1679 70630\\n\", \"6439 5463 3240 91287\\n\", \"10000 10000 3000 100000\\n\", \"7159 6332 3563 82463\\n\", \"8402 6135 4222 85384\\n\", \"8946 8108 4509 80203\\n\", \"9199 8137 4561 82660\\n\", \"8208 8895 4508 97736\\n\", \"9513 11191 5633 90250\\n\", \"11562 20387 10218 95794\\n\", \"80000 80000 40000 100000\\n\", \"7 100 4 12\\n\"], \"outputs\": [\"2.0000000000\\n\", \"32.8333333333\\n\", \"1.0000000000\\n\", \"25.0000000000\\n\", \"0.5714285714\\n\", \"392.2854657164\\n\", \"10.2028343872\\n\", \"100000.0000000000\\n\", \"1.7740177402\\n\", \"20.7303724833\\n\", \"0.2432432432\\n\", \"0.9491525424\\n\", \"299.8356164384\\n\", \"55.2026002167\\n\", \"139.7312500000\\n\", \"930.8962418301\\n\", \"14.6129032258\\n\", \"0.3194192377\\n\", \"0.2592592593\\n\", \"33.5657568238\\n\", \"6526.6982502848\\n\", \"45929.0000000000\\n\", \"2.7480097244\\n\", \"40039.1022280255\\n\", \"17.5230504355\\n\", \"112.4258885780\\n\", \"19898.0903744083\\n\", \"2682.4996497742\\n\", \"36961.0000000000\\n\", \"8.9916815389\\n\", \"82059.0000000000\\n\", \"94110.0000000000\\n\", \"94245.0000000000\\n\", \"96593.0000000000\\n\", \"96084.0000000000\\n\", \"98432.0000000000\\n\", \"97924.0000000000\\n\", \"80270.0000000000\\n\", \"99763.0000000000\\n\", \"82110.0000000000\\n\", \"8532.0000000000\\n\", \"177.6486146644\\n\", \"36452.6416224542\\n\", \"1628.0869962473\\n\", \"30828.1934723611\\n\", \"1519.2830994297\\n\", \"2003.8686025940\\n\", \"24124.0525512989\\n\", \"61745.0000000000\\n\", \"91223.0000000000\\n\", \"12407.9770445558\\n\", \"50178.0000000000\\n\", \"302.0942031080\\n\", \"1.0244272005\\n\", \"18026.3545226951\\n\", \"20073.0000000000\\n\", \"405.4128682152\\n\", \"11732.0000000000\\n\", \"4119.5718891113\\n\", \"27583.0000000000\\n\", \"49.0000000000\\n\", \"9.3680506685\\n\", \"53.8823529412\\n\", \"0.3500000000\\n\", \"13.0000000000\\n\", \"2.4680851064\\n\", \"99.0000000000\\n\", \"1.8181818182\\n\", \"11.1857142857\\n\", \"1.4328947368\\n\", \"98875.0000000000\\n\", \"99783.0000000000\\n\", \"95192.0000000000\\n\", \"96100.0000000000\\n\", \"0.9999900000\\n\", \"0.0000100000\\n\", \"1.0000000000\\n\", \"1.0000000000\\n\", \"7.0000000000\\n\", \"0.0000000001\\n\", \"47808.0000000000\\n\", \"95853.0468547766\\n\", \"82534.7300402068\\n\", \"46586.0000000000\\n\", \"16897.4346155270\\n\", \"70630.0000000000\\n\", \"91097.0460375450\\n\", \"18362.1002496817\\n\", \"81427.6340771341\\n\", \"85384.0000000000\\n\", \"80188.7715868009\\n\", \"81268.3728190748\\n\", \"97736.0000000000\\n\", \"90250.0000000000\\n\", \"95794.0000000000\\n\", \"99625.0947119987\\n\", \"0.4948453608\\n\"]}", "source": "primeintellect"}
|
While Grisha was celebrating New Year with Ded Moroz, Misha gifted Sasha a small rectangular pond of size n × m, divided into cells of size 1 × 1, inhabited by tiny evil fishes (no more than one fish per cell, otherwise they'll strife!).
The gift bundle also includes a square scoop of size r × r, designed for fishing. If the lower-left corner of the scoop-net is located at cell (x, y), all fishes inside the square (x, y)...(x + r - 1, y + r - 1) get caught. Note that the scoop-net should lie completely inside the pond when used.
Unfortunately, Sasha is not that skilled in fishing and hence throws the scoop randomly. In order to not frustrate Sasha, Misha decided to release k fishes into the empty pond in such a way that the expected value of the number of caught fishes is as high as possible. Help Misha! In other words, put k fishes in the pond into distinct cells in such a way that when the scoop-net is placed into a random position among (n - r + 1)·(m - r + 1) possible positions, the average number of caught fishes is as high as possible.
-----Input-----
The only line contains four integers n, m, r, k (1 ≤ n, m ≤ 10^5, 1 ≤ r ≤ min(n, m), 1 ≤ k ≤ min(n·m, 10^5)).
-----Output-----
Print a single number — the maximum possible expected number of caught fishes.
You answer is considered correct, is its absolute or relative error does not exceed 10^{ - 9}. Namely, let your answer be a, and the jury's answer be b. Your answer is considered correct, if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-9}$.
-----Examples-----
Input
3 3 2 3
Output
2.0000000000
Input
12 17 9 40
Output
32.8333333333
-----Note-----
In the first example you can put the fishes in cells (2, 1), (2, 2), (2, 3). In this case, for any of four possible positions of the scoop-net (highlighted with light green), the number of fishes inside is equal to two, and so is the expected value. [Image]
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n2 2 2 2\\n\", \"1\\n0\\n\", \"3\\n-3 -3 2\\n\", \"10\\n2 10 6 8 -4 -11 -10 3 -3 8\\n\", \"10\\n8 6 3 9 8 7 7 7 7 6\\n\", \"8\\n-3 -11 -4 -8 -4 -5 -3 -2\\n\", \"10\\n6 1 -11 -10 -9 -8 8 -1 -10 1\\n\", \"6\\n10 -11 -8 -11 -11 10\\n\", \"3\\n-2 -3 -4\\n\", \"5\\n0 0 0 -4 -3\\n\", \"1\\n-3\\n\", \"3\\n-10 1 2\\n\", \"2\\n0 0\\n\", \"3\\n-1 -1 -1\\n\", \"3\\n0 0 1\\n\", \"3\\n-9 0 0\\n\", \"3\\n0 -6 4\\n\", \"5\\n-1 -1 -1 2 2\\n\", \"1\\n-1\\n\", \"3\\n-5 -1 1\\n\", \"4\\n0 0 0 0\\n\", \"3\\n10 10 -10\\n\", \"3\\n2 1 -2\\n\", \"3\\n-1 1 1\\n\", \"3\\n-4 0 2\\n\", \"5\\n-1 -1 -1 -1 -1\\n\", \"6\\n-1 -2 -3 0 0 0\\n\", \"3\\n-9 -8 -7\\n\", \"2\\n-1 -1\\n\", \"3\\n0 -1 -1\\n\", \"3\\n-1 0 1\\n\", \"2\\n0 -1\\n\", \"3\\n10 -14 -20\\n\", \"3\\n-10 2 3\\n\", \"3\\n-4 -5 -1\\n\", \"3\\n0 2 5\\n\", \"3\\n4 0 -4\\n\", \"3\\n1 1 -1\\n\", \"5\\n-10 -10 -10 -10 -2\\n\", \"5\\n0 0 0 0 -5\\n\", \"6\\n0 0 0 -4 -6 -7\\n\", \"5\\n10 11 -1 -2 -3\\n\", \"3\\n-6 4 3\\n\", \"1\\n4\\n\", \"3\\n-3 2 3\\n\", \"4\\n0 1 2 3\\n\", \"3\\n3 3 -2\\n\", \"3\\n-3 -2 -2\\n\", \"3\\n0 -1 1\\n\", \"3\\n0 0 -1\\n\", \"5\\n-4 0 0 0 1\\n\", \"3\\n-3 2 2\\n\", \"3\\n1 1 -10\\n\", \"3\\n-4 1 2\\n\", \"3\\n-5 1 -1\\n\", \"3\\n-1 -2 -3\\n\", \"3\\n0 0 0\\n\", \"5\\n-100 1 2 3 4\\n\", \"3\\n1 0 -1\\n\", \"1\\n5\\n\", \"3\\n-1 -1 0\\n\", \"5\\n2 4 6 8 10\\n\", \"6\\n-5 0 0 0 0 0\\n\", \"5\\n5 3 2 2 -10\\n\", \"1\\n-10\\n\", \"3\\n-79 -58 -55\\n\", \"4\\n2 2 0 0\\n\", \"3\\n-5 1 2\\n\", \"5\\n1 1 1 1 -1\\n\", \"4\\n3 3 3 -3\\n\", \"5\\n-2 -3 -7 -4 3\\n\", \"7\\n-1 -1 -1 -14 -16 -18 -20\\n\", \"3\\n4 -8 3\\n\", \"3\\n-5 3 3\\n\", \"1\\n-2\\n\", \"5\\n0 0 0 0 0\\n\", \"3\\n-3 -3 -3\\n\", \"4\\n0 0 -1 -1\\n\", \"3\\n-4 0 0\\n\", \"4\\n-1 -1 0 0\\n\", \"3\\n-3 3 2\\n\", \"3\\n0 -2 -3\\n\", \"4\\n8 3 1 0\\n\", \"5\\n5 5 -1 -1 -1\\n\", \"3\\n10 10 -8\\n\", \"6\\n-3 -2 0 0 1 2\\n\", \"3\\n0 -1 -2\\n\", \"3\\n-6 0 4\\n\", \"5\\n-3 -5 -7 2 4\\n\", \"5\\n-6 -5 -3 2 3\\n\", \"3\\n-9 -8 1\\n\", \"3\\n-5 1 1\\n\", \"5\\n-150 -100 -100 -100 100\\n\", \"3\\n-200 50 60\\n\", \"3\\n2 2 -7\\n\", \"3\\n-8 -7 5\\n\"], \"outputs\": [\"-3 -3 -3 -3 \", \"0 \", \"-3 -3 2 \", \"-3 -11 -7 -9 -4 -11 -10 -4 -3 -9 \", \"-9 -7 -4 -10 -9 -8 -8 -8 -8 -7 \", \"-3 -11 -4 -8 -4 -5 -3 -2 \", \"-7 -2 -11 -10 -9 -8 -9 -1 -10 -2 \", \"-11 -11 -8 -11 -11 -11 \", \"-2 -3 3 \", \"-1 -1 -1 3 -3 \", \"2 \", \"9 -2 -3 \", \"-1 -1 \", \"0 -1 -1 \", \"-1 -1 1 \", \"8 -1 -1 \", \"-1 5 -5 \", \"-1 -1 -1 2 -3 \", \"0 \", \"4 -1 -2 \", \"-1 -1 -1 -1 \", \"10 -11 -10 \", \"2 -2 -2 \", \"-1 1 -2 \", \"3 -1 -3 \", \"0 -1 -1 -1 -1 \", \"-1 -2 -3 -1 -1 -1 \", \"8 -8 -7 \", \"-1 -1 \", \"0 -1 -1 \", \"-1 -1 1 \", \"-1 -1 \", \"-11 -14 19 \", \"9 -3 -4 \", \"-4 4 -1 \", \"-1 -3 5 \", \"4 -1 -4 \", \"1 -2 -1 \", \"9 -10 -10 -10 -2 \", \"-1 -1 -1 -1 4 \", \"-1 -1 -1 -4 -6 -7 \", \"-11 11 -1 -2 -3 \", \"5 -5 -4 \", \"4 \", \"-3 -3 3 \", \"-1 -2 -3 -4 \", \"3 -4 -2 \", \"2 -2 -2 \", \"-1 -1 1 \", \"0 -1 -1 \", \"3 -1 -1 -1 -2 \", \"2 -3 -3 \", \"-2 -2 9 \", \"3 -2 -3 \", \"4 -2 -1 \", \"-1 -2 2 \", \"0 -1 -1 \", \"99 -2 -3 -4 -5 \", \"1 -1 -1 \", \"5 \", \"0 -1 -1 \", \"-3 -5 -7 -9 10 \", \"-5 -1 -1 -1 -1 -1 \", \"-6 -4 -3 -3 9 \", \"9 \", \"78 -58 -55 \", \"-3 -3 -1 -1 \", \"4 -2 -3 \", \"1 -2 -2 -2 -1 \", \"-4 -4 -4 -3 \", \"-2 -3 6 -4 -4 \", \"-1 -1 -1 -14 -16 -18 19 \", \"-5 7 -4 \", \"4 -4 -4 \", \"1 \", \"0 -1 -1 -1 -1 \", \"2 -3 -3 \", \"-1 -1 -1 -1 \", \"3 -1 -1 \", \"-1 -1 -1 -1 \", \"-3 3 -3 \", \"-1 -2 2 \", \"-9 -4 -2 -1 \", \"5 -6 -1 -1 -1 \", \"10 -11 -8 \", \"-3 -2 -1 -1 -2 -3 \", \"-1 -1 1 \", \"5 -1 -5 \", \"-3 -5 6 -3 -5 \", \"5 -5 -3 -3 -4 \", \"8 -8 -2 \", \"4 -2 -2 \", \"149 -100 -100 -100 -101 \", \"199 -51 -61 \", \"-3 -3 6 \", \"7 -7 -6 \"]}", "source": "primeintellect"}
|
Nick had received an awesome array of integers $a=[a_1, a_2, \dots, a_n]$ as a gift for his $5$ birthday from his mother. He was already going to explore its various properties but after unpacking he was disappointed a lot because the product $a_1 \cdot a_2 \cdot \dots a_n$ of its elements seemed to him not large enough.
He was ready to throw out the array, but his mother reassured him. She told him, that array would not be spoiled after the following operation: choose any index $i$ ($1 \le i \le n$) and do $a_i := -a_i - 1$.
For example, he can change array $[3, -1, -4, 1]$ to an array $[-4, -1, 3, 1]$ after applying this operation to elements with indices $i=1$ and $i=3$.
Kolya had immediately understood that sometimes it's possible to increase the product of integers of the array a lot. Now he has decided that he wants to get an array with the maximal possible product of integers using only this operation with its elements (possibly zero, one or more times, as many as he wants), it is not forbidden to do this operation several times for the same index.
Help Kolya and print the array with the maximal possible product of elements $a_1 \cdot a_2 \cdot \dots a_n$ which can be received using only this operation in some order.
If there are multiple answers, print any of them.
-----Input-----
The first line contains integer $n$ ($1 \leq n \leq 10^{5}$) — number of integers in the array.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($-10^{6} \leq a_i \leq 10^{6}$) — elements of the array
-----Output-----
Print $n$ numbers — elements of the array with the maximal possible product of elements which can be received using only this operation in some order from the given array.
If there are multiple answers, print any of them.
-----Examples-----
Input
4
2 2 2 2
Output
-3 -3 -3 -3
Input
1
0
Output
0
Input
3
-3 -3 2
Output
-3 -3 2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 2 2\\n\", \"2 1 2\\n\", \"1 1 3\\n\", \"3 2 1\\n\", \"100 100 100\\n\", \"1 100 100\\n\", \"100 1 100\\n\", \"100 100 1\\n\", \"1 100 99\\n\", \"99 1 100\\n\", \"100 99 1\\n\", \"100 1 99\\n\", \"1 99 100\\n\", \"99 100 1\\n\", \"1 1 1\\n\", \"100 100 2\\n\", \"100 2 100\\n\", \"2 100 100\\n\", \"3 3 3\\n\", \"44 54 32\\n\", \"100 90 5\\n\", \"90 5 100\\n\", \"5 100 90\\n\", \"100 5 90\\n\", \"5 90 100\\n\", \"90 100 5\\n\", \"4 4 4\\n\", \"35 38 78\\n\", \"100 98 99\\n\", \"98 100 99\\n\", \"98 99 100\\n\", \"100 99 98\\n\", \"99 100 98\\n\", \"99 98 100\\n\", \"5 5 5\\n\", \"100 100 99\\n\", \"100 99 100\\n\", \"99 100 100\\n\", \"100 99 99\\n\", \"99 100 99\\n\", \"99 99 100\\n\", \"19 18 23\\n\", \"80 80 80\\n\", \"80 80 78\\n\", \"80 80 79\\n\", \"80 80 81\\n\", \"80 78 80\\n\", \"80 79 80\\n\", \"80 81 80\\n\", \"78 80 80\\n\", \"79 80 80\\n\", \"81 80 80\\n\", \"2 1 1\\n\", \"1 2 1\\n\", \"1 1 2\\n\", \"2 2 1\\n\", \"1 2 2\\n\", \"1 2 3\\n\", \"1 3 2\\n\", \"2 3 1\\n\", \"3 1 2\\n\", \"2 1 3\\n\", \"10 2 69\\n\", \"99 99 99\\n\", \"1 100 68\\n\", \"1 100 69\\n\", \"100 68 1\\n\", \"100 69 1\\n\", \"68 1 100\\n\", \"69 1 100\\n\", \"40 100 50\\n\", \"41 100 50\\n\", \"100 50 40\\n\", \"100 50 41\\n\", \"50 40 100\\n\", \"50 41 100\\n\", \"4 3 2\\n\", \"3 3 2\\n\", \"3 2 4\\n\", \"3 2 3\\n\", \"2 4 3\\n\", \"2 3 3\\n\", \"94 62 53\\n\", \"92 42 99\\n\", \"57 88 2\\n\", \"49 85 47\\n\", \"48 16 81\\n\", \"39 96 87\\n\", \"100 91 51\\n\", \"90 92 97\\n\", \"86 25 84\\n\", \"80 1 89\\n\", \"67 95 88\\n\", \"50 93 89\\n\", \"27 71 76\\n\", \"18 47 22\\n\"], \"outputs\": [\"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.150000000000 0.300000000000 0.550000000000\\n\", \"0.057142857143 0.657142857143 0.285714285714\\n\", \"0.487662337662 0.072077922078 0.440259740260\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.366003713151 0.633996286849 0.000000000000\\n\", \"0.000000000000 0.366003713151 0.633996286849\\n\", \"0.633996286849 0.000000000000 0.366003713151\\n\", \"0.369700913626 0.630299086374 0.000000000000\\n\", \"0.000000000000 0.369700913626 0.630299086374\\n\", \"0.630299086374 0.000000000000 0.369700913626\\n\", \"0.000000000000 0.362287378787 0.637712621213\\n\", \"0.362287378787 0.637712621213 0.000000000000\\n\", \"0.637712621213 0.000000000000 0.362287378787\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.405362332237 0.000000000000 0.594637667763\\n\", \"0.000000000000 0.594637667763 0.405362332237\\n\", \"0.594637667763 0.405362332237 0.000000000000\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.106782618787 0.143399200449 0.749818180764\\n\", \"0.082441556638 0.000000001849 0.917558441513\\n\", \"0.000000001849 0.917558441513 0.082441556638\\n\", \"0.917558441513 0.082441556638 0.000000001849\\n\", \"0.000000005097 0.850289405958 0.149710588945\\n\", \"0.850289405958 0.149710588945 0.000000005097\\n\", \"0.149710588945 0.000000005097 0.850289405958\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.686231300287 0.301686382598 0.012082317115\\n\", \"0.336951942791 0.350590779089 0.312457278120\\n\", \"0.329240307786 0.316221888918 0.354537803296\\n\", \"0.350590779089 0.312457278120 0.336951942791\\n\", \"0.316221888918 0.354537803296 0.329240307786\\n\", \"0.312457278120 0.336951942791 0.350590779089\\n\", \"0.354537803296 0.329240307786 0.316221888918\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.320730423530 0.341631521601 0.337638054869\\n\", \"0.341631521601 0.337638054869 0.320730423530\\n\", \"0.337638054869 0.320730423530 0.341631521601\\n\", \"0.328877908413 0.346125932336 0.324996159251\\n\", \"0.324996159251 0.328877908413 0.346125932336\\n\", \"0.346125932336 0.324996159251 0.328877908413\\n\", \"0.367367874268 0.441556405078 0.191075720654\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.304007530347 0.347995449492 0.347997020160\\n\", \"0.318598848470 0.340767700830 0.340633450700\\n\", \"0.348184483745 0.325727680711 0.326087835544\\n\", \"0.347995449492 0.347997020160 0.304007530347\\n\", \"0.340767700830 0.340633450700 0.318598848470\\n\", \"0.325727680711 0.326087835544 0.348184483745\\n\", \"0.347997020160 0.304007530347 0.347995449492\\n\", \"0.340633450700 0.318598848470 0.340767700830\\n\", \"0.326087835544 0.348184483745 0.325727680711\\n\", \"0.333333333333 0.133333333333 0.533333333333\\n\", \"0.533333333333 0.333333333333 0.133333333333\\n\", \"0.133333333333 0.533333333333 0.333333333333\\n\", \"0.550000000000 0.150000000000 0.300000000000\\n\", \"0.300000000000 0.550000000000 0.150000000000\\n\", \"0.174025974026 0.692207792208 0.133766233766\\n\", \"0.440259740260 0.487662337662 0.072077922078\\n\", \"0.692207792208 0.133766233766 0.174025974026\\n\", \"0.133766233766 0.174025974026 0.692207792208\\n\", \"0.072077922078 0.440259740260 0.487662337662\\n\", \"0.000000000001 0.979592460371 0.020407539628\\n\", \"0.333333333333 0.333333333333 0.333333333333\\n\", \"0.504856156201 0.495143843799 0.000000000000\\n\", \"0.499807252268 0.500192747732 0.000000000000\\n\", \"0.495143843799 0.000000000000 0.504856156201\\n\", \"0.500192747732 0.000000000000 0.499807252268\\n\", \"0.000000000000 0.504856156201 0.495143843799\\n\", \"0.000000000000 0.499807252268 0.500192747732\\n\", \"0.504950275130 0.003137391318 0.491912333552\\n\", \"0.471692521594 0.003711367492 0.524596110914\\n\", \"0.003137391318 0.491912333552 0.504950275130\\n\", \"0.003711367492 0.524596110914 0.471692521594\\n\", \"0.491912333552 0.504950275130 0.003137391318\\n\", \"0.524596110914 0.471692521594 0.003711367492\\n\", \"0.380033049657 0.128974183711 0.490992766632\\n\", \"0.448942486085 0.194141929499 0.356915584416\\n\", \"0.128974183711 0.490992766632 0.380033049657\\n\", \"0.194141929499 0.356915584416 0.448942486085\\n\", \"0.490992766632 0.380033049657 0.128974183711\\n\", \"0.356915584416 0.448942486085 0.194141929499\\n\", \"0.032741579903 0.688734095294 0.278524324802\\n\", \"0.156634527800 0.841252178878 0.002113293322\\n\", \"0.628039075774 0.000000000036 0.371960924190\\n\", \"0.185241468442 0.036259808833 0.778498722726\\n\", \"0.009800033922 0.990059771027 0.000140195051\\n\", \"0.856896275913 0.001822013551 0.141281710536\\n\", \"0.008569274339 0.316910121953 0.674520603708\\n\", \"0.412664975931 0.267301641052 0.320033383016\\n\", \"0.016023421282 0.983316299665 0.000660279053\\n\", \"0.000000000000 0.404923676688 0.595076323312\\n\", \"0.419687207048 0.074718763764 0.505594029188\\n\", \"0.693218455167 0.011706551519 0.295074993314\\n\", \"0.954421631610 0.002613537210 0.042964831180\\n\", \"0.741659614574 0.008276779449 0.250063605977\\n\"]}", "source": "primeintellect"}
|
The Bad Luck Island is inhabited by three kinds of species: r rocks, s scissors and p papers. At some moments of time two random individuals meet (all pairs of individuals can meet equiprobably), and if they belong to different species, then one individual kills the other one: a rock kills scissors, scissors kill paper, and paper kills a rock. Your task is to determine for each species what is the probability that this species will be the only one to inhabit this island after a long enough period of time.
-----Input-----
The single line contains three integers r, s and p (1 ≤ r, s, p ≤ 100) — the original number of individuals in the species of rock, scissors and paper, respectively.
-----Output-----
Print three space-separated real numbers: the probabilities, at which the rocks, the scissors and the paper will be the only surviving species, respectively. The answer will be considered correct if the relative or absolute error of each number doesn't exceed 10^{ - 9}.
-----Examples-----
Input
2 2 2
Output
0.333333333333 0.333333333333 0.333333333333
Input
2 1 2
Output
0.150000000000 0.300000000000 0.550000000000
Input
1 1 3
Output
0.057142857143 0.657142857143 0.285714285714
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n\", \"6\\n\", \"1\\n\", \"17\\n\", \"67\\n\", \"10\\n\", \"14\\n\", \"22\\n\", \"23\\n\", \"246\\n\", \"902\\n\", \"1000000000\\n\", \"1998\\n\", \"2222222\\n\", \"2222226\\n\", \"1111110\\n\", \"9999998\\n\", \"1024\\n\", \"8388608\\n\", \"4\\n\", \"8\\n\", \"16\\n\", \"492\\n\", \"493824\\n\", \"493804\\n\", \"493800\\n\", \"2048\\n\", \"8388612\\n\", \"44\\n\", \"444\\n\", \"4444\\n\", \"44444\\n\", \"444444\\n\", \"4444444\\n\", \"100000000\\n\", \"2\\n\", \"3\\n\", \"5\\n\", \"7\\n\", \"9\\n\", \"11\\n\", \"13\\n\", \"15\\n\", \"19\\n\", \"111\\n\", \"113\\n\", \"115\\n\", \"117\\n\", \"119\\n\", \"111111\\n\", \"111113\\n\", \"111115\\n\", \"111117\\n\", \"111119\\n\", \"9999993\\n\", \"9999979\\n\", \"9999990\\n\", \"9999991\\n\", \"9999992\\n\", \"9999973\\n\", \"9999994\\n\", \"9999995\\n\", \"9999996\\n\", \"9999997\\n\", \"9999978\\n\", \"99999993\\n\", \"99999979\\n\", \"99999990\\n\", \"99999991\\n\", \"99999992\\n\", \"99999973\\n\", \"99999994\\n\", \"99999995\\n\", \"99999996\\n\", \"99999997\\n\", \"99999978\\n\", \"987654323\\n\", \"2\\n\", \"4\\n\", \"8\\n\", \"64\\n\", \"999999999\\n\", \"16\\n\", \"999999937\\n\", \"999999998\\n\", \"433494437\\n\", \"484916147\\n\", \"999999929\\n\", \"982451653\\n\", \"2048\\n\"], \"outputs\": [\"4 5\", \"8 10\", \"-1\", \"144 145\", \"2244 2245\", \"24 26\", \"48 50\", \"120 122\", \"264 265\", \"15128 15130\", \"203400 203402\", \"1250000000 750000000\", \"998000 998002\", \"1234567654320 1234567654322\", \"1234572098768 1234572098770\", \"308641358024 308641358026\", \"24999990000000 24999990000002\", \"1280 768\", \"10485760 6291456\", \"5 3\", \"10 6\", \"20 12\", \"615 369\", \"617280 370368\", \"617255 370353\", \"617250 370350\", \"2560 1536\", \"10485765 6291459\", \"55 33\", \"555 333\", \"5555 3333\", \"55555 33333\", \"555555 333333\", \"5555555 3333333\", \"125000000 75000000\", \"-1\", \"4 5\", \"12 13\", \"24 25\", \"40 41\", \"60 61\", \"84 85\", \"112 113\", \"180 181\", \"6160 6161\", \"6384 6385\", \"6612 6613\", \"6844 6845\", \"7080 7081\", \"6172827160 6172827161\", \"6173049384 6173049385\", \"6173271612 6173271613\", \"6173493844 6173493845\", \"6173716080 6173716081\", \"49999930000024 49999930000025\", \"49999790000220 49999790000221\", \"24999950000024 24999950000026\", \"49999910000040 49999910000041\", \"12499990 7499994\", \"49999730000364 49999730000365\", \"24999970000008 24999970000010\", \"49999950000012 49999950000013\", \"12499995 7499997\", \"49999970000004 49999970000005\", \"24999890000120 24999890000122\", \"4999999300000024 4999999300000025\", \"4999997900000220 4999997900000221\", \"2499999500000024 2499999500000026\", \"4999999100000040 4999999100000041\", \"124999990 74999994\", \"4999997300000364 4999997300000365\", \"2499999700000008 2499999700000010\", \"4999999500000012 4999999500000013\", \"124999995 74999997\", \"4999999700000004 4999999700000005\", \"2499998900000120 2499998900000122\", \"487730530870294164 487730530870294165\", \"-1\", \"5 3\", \"10 6\", \"80 48\", \"499999999000000000 499999999000000001\", \"20 12\", \"499999937000001984 499999937000001985\", \"249999999000000000 249999999000000002\", \"93958713454973484 93958713454973485\", \"117571834810662804 117571834810662805\", \"499999929000002520 499999929000002521\", \"482605625241216204 482605625241216205\", \"2560 1536\"]}", "source": "primeintellect"}
|
Katya studies in a fifth grade. Recently her class studied right triangles and the Pythagorean theorem. It appeared, that there are triples of positive integers such that you can construct a right triangle with segments of lengths corresponding to triple. Such triples are called Pythagorean triples.
For example, triples (3, 4, 5), (5, 12, 13) and (6, 8, 10) are Pythagorean triples.
Here Katya wondered if she can specify the length of some side of right triangle and find any Pythagorean triple corresponding to such length? Note that the side which length is specified can be a cathetus as well as hypotenuse.
Katya had no problems with completing this task. Will you do the same?
-----Input-----
The only line of the input contains single integer n (1 ≤ n ≤ 10^9) — the length of some side of a right triangle.
-----Output-----
Print two integers m and k (1 ≤ m, k ≤ 10^18), such that n, m and k form a Pythagorean triple, in the only line.
In case if there is no any Pythagorean triple containing integer n, print - 1 in the only line. If there are many answers, print any of them.
-----Examples-----
Input
3
Output
4 5
Input
6
Output
8 10
Input
1
Output
-1
Input
17
Output
144 145
Input
67
Output
2244 2245
-----Note-----[Image]
Illustration for the first sample.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 4\\n\", \"5 3\\n\", \"1 1\\n\", \"744 18\\n\", \"47879 10\\n\", \"1000000000000000000 1000000000000000000\\n\", \"657180569218773599 42\\n\", \"442762254977842799 30\\n\", \"474158606260730555 1\\n\", \"807873101233533988 39\\n\", \"423 7\\n\", \"264306177888923090 5\\n\", \"998857801526481788 87\\n\", \"999684044704565212 28\\n\", \"319575605003866172 71\\n\", \"755804560577415016 17\\n\", \"72712630136142067 356370939\\n\", \"807264258068668062 33080422\\n\", \"808090496951784190 311661970\\n\", \"808916740129867614 180178111\\n\", \"1 2\\n\", \"2 1\\n\", \"57334064998850639 19\\n\", \"144353716412182199 11\\n\", \"411002215096001759 11\\n\", \"347116374613371527 3\\n\", \"518264351335130399 37\\n\", \"192435891235905239 11\\n\", \"491802505049361659 7\\n\", \"310113769227703889 3\\n\", \"876240758958364799 41\\n\", \"173284263472319999 33\\n\", \"334366426725130799 29\\n\", \"415543470272330399 26\\n\", \"631689521541558479 22\\n\", \"581859366558790319 14\\n\", \"224113913709159599 10\\n\", \"740368848764104559 21\\n\", \"895803074828822159 17\\n\", \"400349974997012039 13\\n\", \"205439024252247599 5\\n\", \"197688463911338399 39\\n\", \"283175367224349599 39\\n\", \"893208176423362799 31\\n\", \"440681012669897999 27\\n\", \"947403664618451039 19\\n\", \"232435556779345919 19\\n\", \"504428493840551279 23\\n\", \"30019549241681999 20\\n\", \"648000813924303839 16\\n\", \"763169499725761451 488954176053755860\\n\", \"199398459594277592 452260924647536414\\n\", \"635627415167826436 192195636386541160\\n\", \"71856370741375281 155502380685354417\\n\", \"731457367464667229 118809129279134971\\n\", \"167686318743248777 858743836723172421\\n\", \"603915274316797622 822050585316952974\\n\", \"647896534275160623 65689274138731296\\n\", \"648722777453244047 501918229712280140\\n\", \"649549020631327471 41923378183538525\\n\", \"650375259514443599 597748177714153637\\n\", \"651201506987494319 33977137582669778\\n\", \"652027745870610447 470206093156218622\\n\", \"652853989048693871 906435048729767466\\n\", \"653680227931809999 342664004303316311\\n\", \"654506475404860719 375019787446735639\\n\", \"655332714287976847 438493956600157103\\n\", \"166512305365727033 900267947832156186\\n\", \"167338548543810457 336496907700672326\\n\", \"168164787426926585 772725863274221171\\n\", \"523 3\\n\", \"39211 6\\n\", \"22151 9\\n\", \"1 3\\n\", \"47 5\\n\", \"999999998999999999 1000000000\\n\", \"11 6\\n\", \"7 4\\n\", \"1 10\\n\", \"9 5\\n\", \"2519 20\\n\", \"700001 3\\n\", \"13 7\\n\", \"999999 10000\\n\", \"1 4\\n\", \"232792559 30\\n\", \"1 5\\n\", \"5 4\\n\", \"5 8\\n\", \"55 4\\n\"], \"outputs\": [\"No\\n\", \"Yes\\n\", \"Yes\\n\", \"No\\n\", \"Yes\\n\", \"No\\n\", \"Yes\\n\", \"Yes\\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\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\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\\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\"]}", "source": "primeintellect"}
|
Imp is watching a documentary about cave painting. [Image]
Some numbers, carved in chaotic order, immediately attracted his attention. Imp rapidly proposed a guess that they are the remainders of division of a number n by all integers i from 1 to k. Unfortunately, there are too many integers to analyze for Imp.
Imp wants you to check whether all these remainders are distinct. Formally, he wants to check, if all $n \text{mod} i$, 1 ≤ i ≤ k, are distinct, i. e. there is no such pair (i, j) that: 1 ≤ i < j ≤ k, $n \operatorname{mod} i = n \operatorname{mod} j$, where $x \operatorname{mod} y$ is the remainder of division x by y.
-----Input-----
The only line contains two integers n, k (1 ≤ n, k ≤ 10^18).
-----Output-----
Print "Yes", if all the remainders are distinct, and "No" otherwise.
You can print each letter in arbitrary case (lower or upper).
-----Examples-----
Input
4 4
Output
No
Input
5 3
Output
Yes
-----Note-----
In the first sample remainders modulo 1 and 4 coincide.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 1\\n-1 0 1\\n\", \"2 1\\n1 0\\n\", \"1 1\\n-1\\n\", \"1 0\\n-1\\n\", \"1 1\\n0\\n\", \"5 1\\n-1 -1 -1 -1 -1\\n\", \"5 0\\n-1 -1 -1 -1 -1\\n\", \"10 1\\n1 1 1 1 0 0 0 1 0 0\\n\", \"50 1\\n-1 -1 1 0 1 1 0 -1 1 0 -1 -1 0 0 -1 -1 0 1 1 -1 1 0 -1 1 1 -1 -1 -1 1 -1 -1 0 -1 0 -1 0 0 -1 -1 0 1 -1 0 1 -1 1 0 -1 -1 1\\n\", \"20 1\\n0 0 -1 0 1 1 1 1 -1 -1 1 1 1 -1 0 0 1 1 1 0\\n\", \"30 0\\n1 0 1 1 0 -1 0 1 -1 0 1 -1 0 -1 1 1 -1 1 0 1 0 -1 1 1 0 1 -1 0 1 1\\n\", \"40 1\\n-1 1 1 1 0 -1 -1 1 1 -1 1 1 1 0 0 -1 1 0 1 -1 -1 1 0 1 1 0 1 0 0 -1 -1 1 -1 1 1 1 1 0 -1 0\\n\", \"50 1\\n-1 -1 0 -1 1 0 1 0 1 -1 -1 0 0 0 -1 0 0 -1 0 1 -1 0 1 -1 1 -1 1 -1 -1 1 -1 -1 0 1 1 0 0 0 1 -1 -1 1 0 0 -1 0 1 1 0 0\\n\", \"50 1\\n-1 -1 -1 -1 -1 0 -1 -1 -1 0 1 0 -1 0 1 -1 -1 -1 1 0 1 -1 0 1 0 1 0 0 1 1 -1 1 -1 -1 1 1 -1 -1 0 -1 -1 1 -1 1 -1 1 1 0 0 -1\\n\", \"3 1\\n0 -1 -1\\n\", \"4 0\\n1 -1 1 0\\n\", \"21 0\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"29 1\\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\\n\", \"41 0\\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\\n\", \"3 0\\n0 0 0\\n\", \"38 1\\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\\n\", \"25 1\\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\\n\", \"30 0\\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\\n\", \"46 0\\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\\n\", \"10 0\\n1 0 -1 1 -1 0 0 1 1 0\\n\", \"6 0\\n-1 0 -1 1 1 1\\n\", \"7 0\\n1 0 1 1 -1 1 1\\n\", \"9 0\\n0 -1 -1 -1 -1 -1 1 0 -1\\n\", \"6 1\\n1 -1 -1 -1 0 0\\n\", \"6 0\\n0 -1 -1 0 0 -1\\n\", \"8 0\\n-1 0 1 -1 1 -1 1 1\\n\", \"6 1\\n1 1 0 -1 -1 -1\\n\", \"22 1\\n0 -1 1 0 0 1 1 1 -1 -1 1 1 1 -1 1 1 0 0 -1 0 1 1\\n\", \"47 1\\n0 -1 0 1 0 -1 1 -1 1 -1 1 -1 0 0 -1 0 -1 1 -1 -1 0 1 -1 1 0 0 1 -1 0 1 0 1 0 1 0 1 -1 -1 1 -1 -1 -1 0 1 1 0 1\\n\", \"2 1\\n0 1\\n\", \"36 1\\n-1 0 0 1 1 0 -1 -1 -1 -1 1 1 0 -1 0 1 0 -1 0 -1 0 1 0 -1 -1 0 1 -1 0 -1 0 -1 1 0 1 1\\n\", \"37 0\\n0 -1 0 0 0 -1 0 1 0 0 -1 0 -1 -1 0 1 1 0 -1 -1 -1 -1 1 -1 0 0 0 1 -1 -1 1 -1 1 1 -1 -1 -1\\n\", \"4 1\\n1 -1 -1 1\\n\", \"35 0\\n0 0 -1 -1 1 -1 1 -1 1 0 1 0 -1 0 1 1 -1 1 -1 0 0 -1 0 0 1 -1 -1 0 1 1 -1 1 1 1 -1\\n\", \"25 1\\n1 0 0 -1 -1 0 1 0 -1 1 0 0 0 -1 0 0 1 -1 -1 1 -1 -1 -1 1 1\\n\", \"36 1\\n-1 0 -1 -1 1 0 0 -1 1 0 0 -1 1 -1 1 0 1 0 0 0 1 1 1 0 1 1 0 -1 1 -1 0 0 0 1 1 -1\\n\", \"9 1\\n-1 -1 1 1 1 -1 -1 0 1\\n\", \"36 0\\n-1 0 0 -1 -1 -1 0 -1 0 1 -1 -1 1 1 -1 1 0 0 1 -1 1 1 -1 0 0 1 1 1 -1 1 1 -1 1 1 1 -1\\n\", \"10 1\\n1 1 1 -1 0 -1 -1 1 1 0\\n\", \"7 0\\n1 0 -1 1 -1 1 0\\n\", \"2 0\\n-1 0\\n\", \"5 1\\n-1 1 0 0 -1\\n\", \"2 0\\n-1 -1\\n\", \"4 1\\n0 1 -1 -1\\n\", \"5 0\\n-1 0 0 0 1\\n\", \"17 0\\n0 -1 -1 0 1 -1 0 0 -1 -1 0 -1 -1 -1 0 0 0\\n\", \"10 0\\n1 -1 0 1 1 -1 -1 0 1 0\\n\", \"31 0\\n1 -1 -1 0 -1 0 -1 -1 0 -1 -1 -1 1 1 0 1 -1 1 1 0 0 -1 0 1 -1 1 0 -1 1 -1 -1\\n\", \"41 1\\n0 0 -1 1 -1 -1 1 -1 -1 1 -1 1 -1 1 -1 0 1 1 1 0 0 1 1 -1 0 0 1 0 0 1 1 1 -1 0 -1 1 0 1 1 1 1\\n\", \"37 1\\n1 -1 1 -1 -1 -1 0 1 -1 -1 1 0 0 0 1 1 -1 0 -1 1 -1 0 1 -1 -1 -1 -1 -1 0 -1 0 0 -1 0 -1 -1 -1\\n\", \"31 0\\n1 0 1 1 0 0 0 -1 -1 -1 -1 -1 0 1 1 1 0 -1 1 -1 -1 1 -1 1 1 0 0 1 1 -1 0\\n\", \"4 1\\n1 0 1 0\\n\", \"26 1\\n1 -1 1 1 1 1 -1 1 -1 1 -1 -1 0 -1 -1 -1 1 0 -1 -1 0 1 -1 0 1 0\\n\", \"28 1\\n0 0 1 1 -1 1 -1 1 0 -1 -1 -1 0 -1 0 -1 1 0 -1 1 0 -1 -1 0 -1 1 1 -1\\n\", \"24 1\\n0 0 0 1 1 0 -1 0 -1 1 -1 -1 0 0 1 1 0 -1 0 0 0 0 1 1\\n\", \"17 0\\n-1 0 -1 1 0 0 1 1 -1 -1 -1 -1 -1 1 1 -1 -1\\n\", \"42 1\\n0 1 -1 0 -1 0 -1 1 -1 1 0 1 1 -1 0 -1 -1 1 -1 -1 0 -1 1 -1 0 1 0 1 -1 1 -1 1 0 0 -1 0 1 0 1 1 0 0\\n\", \"3 0\\n0 -1 -1\\n\", \"9 1\\n0 1 -1 -1 -1 -1 1 1 1\\n\", \"9 0\\n1 1 0 0 1 -1 -1 0 0\\n\", \"14 1\\n-1 0 0 1 -1 0 0 0 -1 -1 0 -1 0 0\\n\", \"20 0\\n1 -1 1 -1 -1 -1 0 1 1 0 1 0 -1 1 1 -1 1 0 1 1\\n\", \"18 0\\n1 1 1 -1 0 -1 -1 0 -1 -1 0 0 -1 0 -1 0 -1 1\\n\", \"16 0\\n1 -1 0 0 0 -1 -1 -1 0 -1 -1 1 0 0 -1 1\\n\", \"27 1\\n-1 0 -1 -1 -1 0 1 -1 1 0 0 -1 0 1 0 0 0 -1 -1 1 -1 -1 -1 0 1 0 0\\n\", \"2 0\\n-1 1\\n\", \"34 1\\n1 0 -1 0 0 0 -1 1 0 1 1 1 1 1 1 -1 0 0 1 0 -1 -1 -1 1 -1 -1 -1 1 1 1 -1 1 1 -1\\n\", \"17 0\\n1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 -1 0\\n\", \"16 0\\n-1 0 0 1 0 0 0 0 -1 -1 -1 -1 1 1 0 1\\n\", \"17 0\\n0 0 0 0 0 1 -1 -1 -1 1 -1 1 0 0 1 -1 -1\\n\", \"38 0\\n-1 -1 1 1 -1 -1 1 -1 0 1 -1 1 1 1 -1 1 0 1 0 -1 1 -1 -1 0 0 1 -1 -1 0 -1 0 -1 -1 0 1 0 -1 0\\n\", \"33 0\\n0 1 -1 -1 -1 1 -1 1 1 -1 -1 -1 -1 0 1 0 -1 0 0 -1 1 -1 -1 0 0 -1 0 0 1 0 1 1 1\\n\", \"32 1\\n0 0 1 0 -1 0 1 -1 -1 -1 0 1 0 0 1 0 -1 -1 1 1 1 0 0 1 -1 -1 1 0 0 -1 0 1\\n\", \"6 0\\n-1 1 1 -1 -1 -1\\n\", \"27 1\\n0 -1 1 0 -1 1 1 -1 0 -1 0 0 0 -1 -1 0 0 -1 -1 0 -1 0 -1 0 0 1 1\\n\", \"27 1\\n0 -1 -1 1 1 1 -1 1 0 0 1 -1 -1 1 -1 1 1 1 1 1 0 0 0 0 -1 -1 0\\n\", \"17 1\\n0 -1 -1 0 0 1 -1 -1 0 0 -1 1 0 -1 1 0 0\\n\", \"34 0\\n1 1 1 0 0 0 0 1 0 0 1 -1 1 1 -1 0 -1 1 1 1 0 1 1 -1 0 0 1 -1 -1 0 0 0 -1 -1\\n\", \"31 1\\n1 0 0 0 0 0 0 0 -1 0 0 0 1 -1 -1 -1 0 0 -1 0 1 -1 1 0 1 1 1 1 -1 -1 1\\n\", \"48 1\\n1 0 0 0 1 -1 1 1 0 -1 0 -1 1 1 0 -1 -1 -1 0 0 0 1 0 1 0 -1 -1 -1 -1 1 0 1 -1 -1 -1 1 -1 0 1 0 0 1 -1 0 -1 0 0 0\\n\", \"5 0\\n0 -1 0 0 0\\n\", \"43 0\\n1 0 0 -1 0 -1 0 -1 1 1 -1 1 -1 0 0 1 -1 -1 -1 0 0 -1 1 -1 -1 1 0 0 1 -1 0 -1 -1 -1 -1 -1 1 1 0 -1 -1 -1 0\\n\", \"11 1\\n1 0 1 0 -1 1 0 -1 -1 0 0\\n\", \"13 1\\n-1 1 0 0 -1 0 -1 1 -1 -1 1 1 0\\n\"], \"outputs\": [\"6\", \"1\", \"2\", \"0\", \"1\", \"16512\", \"16256\", \"185921272\", \"803313751\", \"483548109\", \"40673917\", \"73320910\", \"772364444\", \"279519499\", \"18\", \"64\", \"0\", \"733922348\", \"0\", \"0\", \"0\", \"322050759\", \"549790477\", \"480432768\", \"743685088\", \"61440\", \"2359296\", \"560111071\", \"131072\", \"135168\", \"56964601\", \"133120\", \"981309322\", \"716651774\", \"1\", \"693536347\", \"915368288\", \"120\", \"45647242\", \"66699122\", \"77953873\", \"608326411\", \"152782818\", \"487370169\", \"4194304\", \"3\", \"1920\", \"6\", \"136\", \"1088\", \"310296666\", \"487370169\", \"304540143\", \"589337580\", \"916646835\", \"253181331\", \"32\", \"996763118\", \"618844160\", \"189147304\", \"555719737\", \"386658717\", \"14\", \"755810045\", \"438952513\", \"829277977\", \"841268608\", \"557382306\", \"807669877\", \"61073361\", \"3\", \"132603129\", \"585862415\", \"878929813\", \"427689083\", \"502273788\", \"52976952\", \"247728070\", \"267264\", \"28918236\", \"69931865\", \"427689083\", \"115086916\", \"186475897\", \"763606955\", \"768\", \"477560567\", \"67049563\", \"621572676\"]}", "source": "primeintellect"}
|
Kuro has recently won the "Most intelligent cat ever" contest. The three friends then decided to go to Katie's home to celebrate Kuro's winning. After a big meal, they took a small break then started playing games.
Kuro challenged Katie to create a game with only a white paper, a pencil, a pair of scissors and a lot of arrows (you can assume that the number of arrows is infinite). Immediately, Katie came up with the game called Topological Parity.
The paper is divided into $n$ pieces enumerated from $1$ to $n$. Shiro has painted some pieces with some color. Specifically, the $i$-th piece has color $c_{i}$ where $c_{i} = 0$ defines black color, $c_{i} = 1$ defines white color and $c_{i} = -1$ means that the piece hasn't been colored yet.
The rules of the game is simple. Players must put some arrows between some pairs of different pieces in such a way that for each arrow, the number in the piece it starts from is less than the number of the piece it ends at. Also, two different pieces can only be connected by at most one arrow. After that the players must choose the color ($0$ or $1$) for each of the unpainted pieces. The score of a valid way of putting the arrows and coloring pieces is defined as the number of paths of pieces of alternating colors. For example, $[1 \to 0 \to 1 \to 0]$, $[0 \to 1 \to 0 \to 1]$, $[1]$, $[0]$ are valid paths and will be counted. You can only travel from piece $x$ to piece $y$ if and only if there is an arrow from $x$ to $y$.
But Kuro is not fun yet. He loves parity. Let's call his favorite parity $p$ where $p = 0$ stands for "even" and $p = 1$ stands for "odd". He wants to put the arrows and choose colors in such a way that the score has the parity of $p$.
It seems like there will be so many ways which satisfy Kuro. He wants to count the number of them but this could be a very large number. Let's help him with his problem, but print it modulo $10^{9} + 7$.
-----Input-----
The first line contains two integers $n$ and $p$ ($1 \leq n \leq 50$, $0 \leq p \leq 1$) — the number of pieces and Kuro's wanted parity.
The second line contains $n$ integers $c_{1}, c_{2}, ..., c_{n}$ ($-1 \leq c_{i} \leq 1$) — the colors of the pieces.
-----Output-----
Print a single integer — the number of ways to put the arrows and choose colors so the number of valid paths of alternating colors has the parity of $p$.
-----Examples-----
Input
3 1
-1 0 1
Output
6
Input
2 1
1 0
Output
1
Input
1 1
-1
Output
2
-----Note-----
In the first example, there are $6$ ways to color the pieces and add the arrows, as are shown in the figure below. The scores are $3, 3, 5$ for the first row and $5, 3, 3$ for the second row, both from left to right.
[Image]
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 595\\n43 2\\n300 4\\n554 10\\n\", \"1 1\\n1 1\\n\", \"2 50\\n20 0\\n3 1\\n\", \"5 240\\n13 0\\n50 25\\n60 5\\n155 70\\n165 70\\n\", \"1 100000\\n99998 0\\n\", \"1 100000\\n100000 0\\n\", \"1 100000\\n1 0\\n\", \"2 100000\\n1 0\\n100000 0\\n\", \"7 300\\n50 8\\n49 6\\n246 1\\n123 3\\n227 2\\n183 5\\n158 7\\n\", \"7 300\\n262 17\\n97 27\\n108 30\\n45 28\\n126 18\\n299 28\\n120 30\\n\", \"7 300\\n163 21\\n111 27\\n210 61\\n183 53\\n237 25\\n275 9\\n80 6\\n\", \"25 100000\\n69213 4\\n76932 3\\n84327 3\\n93894 2\\n64725 1\\n87331 1\\n58612 3\\n79789 1\\n93768 3\\n59583 5\\n50523 3\\n97497 4\\n3051 1\\n79960 0\\n776 5\\n36189 1\\n15585 5\\n6881 0\\n54720 0\\n30083 4\\n4470 3\\n77336 2\\n96150 1\\n59705 3\\n59300 1\\n\", \"25 100000\\n1003 26\\n32756 9\\n93227 12\\n51400 17\\n36812 10\\n84422 35\\n76490 19\\n1740 10\\n54632 29\\n12367 32\\n18339 34\\n41068 34\\n65607 23\\n14131 23\\n54870 4\\n23147 3\\n47036 5\\n88376 9\\n93195 5\\n54299 13\\n49172 20\\n23718 17\\n68635 38\\n15559 40\\n34105 25\\n\", \"25 100000\\n2397 163\\n59750 898\\n5833 905\\n79846 911\\n57098 569\\n21028 1367\\n32857 1352\\n72624 1434\\n44720 70\\n77542 444\\n92200 39\\n51088 366\\n34147 317\\n80149 1401\\n54988 344\\n67064 474\\n70805 464\\n28718 409\\n51331 1453\\n90984 670\\n18438 457\\n56734 1419\\n46141 370\\n70406 1275\\n92283 124\\n\", \"25 100000\\n3174 736\\n88732 1969\\n61424 1015\\n77143 1483\\n56805 2063\\n25558 249\\n48637 2511\\n68912 63\\n27671 733\\n60995 2972\\n6179 2108\\n8416 702\\n50179 1554\\n37107 2862\\n21129 2673\\n45776 2144\\n67145 1674\\n94506 1588\\n25711 345\\n46646 2072\\n86481 2761\\n60011 2644\\n20236 2068\\n52333 1034\\n60023 2496\\n\", \"25 100000\\n37809 0\\n26927 0\\n73733 0\\n3508 1\\n94260 1\\n23325 1\\n41305 1\\n23520 1\\n52508 0\\n69475 1\\n48923 1\\n70614 1\\n31179 1\\n57324 1\\n42182 1\\n38945 1\\n9973 1\\n32264 0\\n49874 0\\n63512 0\\n6361 1\\n55979 1\\n67515 0\\n65894 1\\n77805 0\\n\", \"25 100000\\n67601 52855\\n66459 75276\\n53190 93454\\n5275 6122\\n32094 97379\\n17446 70386\\n56808 9614\\n55202 88461\\n92365 45788\\n2628 72300\\n9441 59772\\n9639 14290\\n58057 92489\\n97535 38675\\n32763 11599\\n33911 80066\\n57681 95815\\n68874 34661\\n7976 42928\\n95943 72831\\n50029 47657\\n99199 86401\\n12561 24225\\n23715 50617\\n81108 29201\\n\", \"2 100000\\n66809 5\\n78732 1939\\n\", \"2 100000\\n77287 0\\n83316 3414\\n\", \"2 100000\\n35991 7\\n80242 6536\\n\", \"6 100000\\n27838 4\\n90673 9\\n57946 7\\n99524 213\\n53425 2780\\n87008 2622\\n\", \"6 100000\\n99736 10\\n33892 1\\n81001 5\\n5905 7\\n33908 611\\n5214 2632\\n\", \"6 100000\\n27886 7\\n77187 4\\n9738 6\\n96734 9\\n16855 6\\n49676 2337\\n\", \"25 100000\\n53612 0\\n66075 2\\n8932 3\\n7833 2\\n37244 1\\n63538 0\\n50612 3\\n74352 3\\n97233 3\\n95687 3\\n52621 0\\n90354 0\\n31586 2\\n90526 2\\n47695 0\\n8865 8069\\n27202 2921\\n1257 10197\\n5010 3753\\n11629 9377\\n35282 21983\\n64622 12777\\n80868 16988\\n1749 8264\\n35995 22668\\n\", \"5 100000\\n52050 4\\n29238 4\\n44565 1\\n45433 3\\n44324 2\\n\", \"10 100000\\n11743 1\\n8885 3\\n81551 3\\n1155 1\\n98002 2\\n67313 2\\n86920 4\\n31643 2\\n10059 3\\n34150 3\\n\", \"20 100000\\n24699 3\\n6009 2\\n9602 4\\n53413 1\\n35177 3\\n53750 4\\n13364 4\\n48839 3\\n35504 3\\n69424 1\\n76044 1\\n17849 2\\n50355 1\\n7354 3\\n21986 4\\n75971 4\\n64508 4\\n24995 2\\n42227 1\\n53574 2\\n\", \"40 100000\\n7969 3\\n37169 1\\n41741 2\\n67002 1\\n90862 2\\n64649 2\\n16209 3\\n73780 1\\n21884 2\\n68703 1\\n34726 3\\n48184 1\\n91305 4\\n81813 2\\n63415 3\\n55828 3\\n8107 2\\n34478 3\\n45085 1\\n75184 3\\n55945 2\\n17811 2\\n6071 3\\n39736 2\\n61691 1\\n32048 4\\n92316 1\\n67014 4\\n1653 1\\n74500 3\\n37485 1\\n14969 2\\n66752 2\\n9979 3\\n64317 2\\n8879 2\\n49018 1\\n27012 2\\n52171 4\\n34163 2\\n\", \"5 100000\\n43626 2\\n13034 2\\n64492 2\\n10136 4\\n79129 1\\n\", \"10 100000\\n17014 7\\n53882 3\\n18443 3\\n53503 2\\n56680 8\\n87349 4\\n84815 4\\n78531 8\\n6275 1\\n37670 2\\n\", \"20 100000\\n38470 3\\n47432 1\\n58503 3\\n5373 4\\n35996 2\\n3486 7\\n45511 2\\n99630 5\\n52747 6\\n9906 2\\n20924 8\\n53193 2\\n39577 2\\n7813 2\\n89583 6\\n6600 6\\n3596 1\\n11860 2\\n26607 2\\n75001 1\\n\", \"40 100000\\n42798 2\\n54533 2\\n515 3\\n85575 1\\n10710 6\\n96647 1\\n41385 4\\n22031 3\\n95479 2\\n36936 8\\n75970 5\\n50569 3\\n40085 1\\n545 4\\n79766 4\\n7705 3\\n98717 2\\n98492 1\\n60058 2\\n18385 3\\n82164 2\\n62091 6\\n24621 8\\n86841 7\\n38419 2\\n31588 1\\n45307 1\\n81328 8\\n2012 7\\n33914 3\\n11834 8\\n35316 2\\n41871 2\\n51727 5\\n93223 7\\n39536 8\\n81006 3\\n64163 2\\n58846 2\\n54803 1\\n\", \"5 100000\\n72890 3\\n6854 1\\n943 3\\n71191 2\\n93457 1\\n\", \"10 100000\\n94219 1\\n71825 1\\n99448 2\\n61315 4\\n69817 15\\n21753 16\\n94006 11\\n53877 1\\n28419 10\\n20564 12\\n\", \"20 100000\\n5086 2\\n36539 1\\n71556 11\\n58140 8\\n65788 13\\n96162 4\\n17309 9\\n53576 8\\n64003 16\\n6754 3\\n8130 16\\n32836 2\\n5623 2\\n49613 4\\n44487 4\\n83608 4\\n22645 14\\n4509 2\\n92784 2\\n28021 2\\n\", \"40 100000\\n83643 2\\n40674 2\\n37656 3\\n76252 1\\n81854 14\\n78210 2\\n63394 14\\n67188 6\\n24556 5\\n30841 11\\n91521 16\\n61626 2\\n77040 9\\n85555 3\\n68349 2\\n76270 2\\n56711 13\\n60381 6\\n74757 11\\n58602 12\\n83014 11\\n10344 2\\n18259 14\\n41836 4\\n26770 2\\n8245 8\\n82226 8\\n68545 2\\n13026 15\\n95537 7\\n6463 1\\n89800 1\\n16070 2\\n9389 5\\n98033 3\\n19102 11\\n84955 4\\n61018 13\\n751 4\\n68501 5\\n\", \"5 100000\\n25350 21\\n96944 27\\n39618 10\\n41361 5\\n6591 1\\n\", \"10 100000\\n74302 10\\n38566 27\\n30455 11\\n1678 4\\n3938 24\\n59873 6\\n90244 29\\n93429 6\\n43547 28\\n55198 20\\n\", \"20 100000\\n86420 1\\n47113 13\\n64472 1\\n53043 9\\n13420 14\\n76914 4\\n94265 5\\n58960 32\\n37738 2\\n62910 8\\n84632 13\\n12139 1\\n7152 29\\n88101 6\\n7610 6\\n26751 3\\n20745 14\\n18315 8\\n28921 1\\n21476 2\\n\", \"40 100000\\n52994 2\\n23288 15\\n81416 16\\n81533 16\\n34292 16\\n33769 9\\n83905 26\\n66312 5\\n68536 27\\n25739 4\\n47063 28\\n52941 13\\n32163 1\\n73306 14\\n95733 16\\n88459 2\\n1439 4\\n81112 6\\n7142 8\\n22978 17\\n40445 4\\n35423 2\\n30283 5\\n89053 6\\n45961 16\\n47050 8\\n69093 2\\n697 7\\n56337 23\\n48408 20\\n43287 18\\n454 11\\n954 4\\n45261 3\\n82023 2\\n21357 5\\n57677 2\\n36910 2\\n59441 3\\n85506 3\\n\", \"5 100000\\n79901 42\\n54923 2\\n62869 4\\n65551 27\\n87048 4\\n\", \"10 100000\\n40506 6\\n34059 5\\n38905 34\\n83603 11\\n66381 8\\n93554 4\\n7544 19\\n86566 4\\n25352 4\\n96048 16\\n\", \"20 100000\\n95468 23\\n90408 16\\n87565 4\\n75513 4\\n20971 2\\n25009 29\\n33037 29\\n40038 2\\n58148 19\\n8408 2\\n60320 15\\n42740 3\\n44945 2\\n21695 8\\n59723 38\\n73068 2\\n72608 19\\n91778 12\\n53661 4\\n77225 46\\n\", \"40 100000\\n34512 2\\n28710 30\\n42353 20\\n28138 11\\n818 42\\n40056 1\\n68439 8\\n43563 42\\n3766 14\\n19516 25\\n54016 62\\n93742 41\\n98921 3\\n50948 8\\n58432 2\\n58209 7\\n55704 18\\n77002 8\\n82500 16\\n498 2\\n88306 12\\n17568 3\\n88313 1\\n93767 7\\n12186 2\\n79225 2\\n1910 8\\n60198 29\\n89693 2\\n49128 2\\n40818 8\\n34413 12\\n20499 1\\n3649 3\\n21079 3\\n9349 2\\n32774 38\\n14759 26\\n79319 6\\n44325 37\\n\", \"5 100000\\n95719 2\\n83337 69\\n17427 124\\n73738 1\\n59503 41\\n\", \"10 100000\\n72759 89\\n31969 4\\n84006 24\\n7486 45\\n1600 5\\n54176 2\\n59014 6\\n76704 119\\n59238 1\\n29271 2\\n\", \"20 100000\\n50897 12\\n82689 22\\n55442 28\\n32615 6\\n48930 81\\n25243 5\\n38752 110\\n45025 16\\n43729 2\\n82637 1\\n89951 10\\n58373 1\\n1389 7\\n20683 2\\n12366 127\\n66021 4\\n17264 27\\n55759 12\\n13239 1\\n18370 53\\n\", \"40 100000\\n67499 128\\n18678 3\\n32621 61\\n46926 107\\n41174 20\\n90207 127\\n25076 18\\n78735 14\\n68443 8\\n28831 2\\n83000 75\\n52968 115\\n58919 4\\n77318 18\\n78727 55\\n19986 59\\n85666 95\\n75610 11\\n55390 23\\n59376 12\\n87643 63\\n55139 42\\n38661 80\\n457 21\\n1886 9\\n61516 71\\n14324 103\\n28627 2\\n64006 3\\n47570 7\\n71651 17\\n34118 107\\n45277 14\\n31144 4\\n70921 74\\n8388 4\\n32174 11\\n22012 6\\n67839 5\\n51280 10\\n\", \"5 100000\\n2742 8\\n53984 236\\n69767 231\\n45509 2\\n39889 59\\n\", \"10 100000\\n54735 2\\n98665 153\\n17472 2\\n26292 12\\n44348 22\\n54855 15\\n28437 98\\n94916 4\\n10408 23\\n99667 189\\n\", \"20 100000\\n11672 105\\n94527 8\\n83821 4\\n37084 55\\n60655 24\\n16189 4\\n34135 85\\n34867 2\\n55552 7\\n52666 49\\n66146 74\\n6273 2\\n13905 59\\n20381 4\\n59843 83\\n53964 38\\n24508 4\\n77118 4\\n15930 3\\n62737 1\\n\", \"40 100000\\n68637 250\\n15718 58\\n26714 15\\n49786 15\\n13359 8\\n28367 2\\n62024 97\\n46061 52\\n61112 96\\n72226 233\\n70981 28\\n45379 1\\n28398 4\\n41275 8\\n12280 133\\n75146 9\\n62439 214\\n26526 32\\n44676 3\\n19031 2\\n14260 195\\n19053 45\\n58423 3\\n89174 4\\n36613 8\\n58708 32\\n19140 2\\n34072 219\\n99129 5\\n7006 80\\n87999 8\\n38558 7\\n50309 238\\n77671 1\\n17665 73\\n95834 12\\n72684 9\\n23193 81\\n57013 53\\n58594 9\\n\", \"5 100000\\n63303 72\\n97883 4\\n12457 96\\n66892 6\\n92884 6\\n\", \"10 100000\\n57437 57\\n78480 2\\n30047 2\\n22974 16\\n19579 201\\n25666 152\\n77014 398\\n94142 2\\n65837 442\\n69836 23\\n\", \"20 100000\\n29764 28\\n87214 24\\n43812 151\\n22119 512\\n36641 38\\n52113 29\\n56955 155\\n13605 14\\n99224 7\\n48614 2\\n64555 215\\n71439 8\\n78995 60\\n84075 103\\n7907 15\\n79915 237\\n69409 4\\n98226 154\\n23889 4\\n91844 100\\n\", \"40 100000\\n96037 20\\n46624 124\\n376 24\\n21579 329\\n30814 16\\n93353 2\\n37876 5\\n31134 15\\n91879 101\\n56921 3\\n60149 1\\n32051 12\\n87665 1\\n43512 6\\n99773 2\\n93817 8\\n4019 448\\n21051 1\\n41295 98\\n9402 89\\n6576 498\\n37085 50\\n8593 3\\n611 17\\n4320 411\\n72688 30\\n81747 8\\n9120 147\\n70791 95\\n29492 43\\n11656 162\\n37753 105\\n19543 72\\n86959 2\\n17301 2\\n49114 152\\n76580 19\\n27610 10\\n81365 2\\n31055 159\\n\", \"5 100000\\n86592 146\\n14936 12\\n74772 251\\n14953 2\\n82726 247\\n\", \"10 100000\\n36153 5\\n75526 126\\n70668 438\\n84951 4\\n66650 1\\n13780 312\\n70504 798\\n1119 395\\n41802 2\\n69442 106\\n\", \"20 100000\\n60719 128\\n50622 18\\n63673 358\\n54655 4\\n29105 1\\n63976 7\\n96998 334\\n65216 723\\n52540 12\\n1268 666\\n8242 2\\n86941 140\\n99111 27\\n2965 11\\n25870 135\\n29573 339\\n99204 13\\n36279 30\\n86150 232\\n67144 76\\n\", \"40 100000\\n46403 17\\n54955 61\\n74185 12\\n5141 2\\n48606 729\\n68203 73\\n73631 118\\n79515 577\\n51004 20\\n68430 16\\n82547 4\\n39436 56\\n59971 2\\n13164 543\\n16471 7\\n86520 42\\n47054 264\\n69354 8\\n84857 8\\n71801 45\\n41099 8\\n94095 8\\n24142 1\\n25537 6\\n59382 3\\n62270 32\\n2989 48\\n14329 354\\n152 8\\n450 10\\n91698 20\\n17145 6\\n37249 63\\n96026 20\\n24555 2\\n99362 588\\n21434 3\\n29806 217\\n57636 5\\n24354 22\\n\", \"5 100000\\n88825 16\\n42009 4\\n12536 6\\n27456 2\\n97947 64\\n\", \"10 100000\\n1635 8\\n33823 61\\n5721 646\\n48628 1504\\n74630 49\\n75538 1163\\n57979 176\\n10592 6\\n49836 8\\n13039 1427\\n\", \"20 100000\\n96994 121\\n52505 16\\n39110 4\\n550 203\\n60219 6\\n19241 443\\n33570 7\\n48536 1\\n42760 61\\n45069 4\\n38141 17\\n60419 50\\n98857 9\\n73167 66\\n17284 96\\n38049 1061\\n12937 15\\n8136 2\\n29734 185\\n31184 19\\n\", \"40 100000\\n97514 53\\n80797 379\\n84354 292\\n79244 2\\n50047 431\\n44535 1989\\n55021 15\\n73792 98\\n6532 185\\n24440 1986\\n11045 54\\n95293 24\\n83588 1129\\n80713 4\\n36999 837\\n33125 1\\n81815 4\\n6354 2\\n11472 2\\n47815 178\\n24587 339\\n44181 2\\n52337 521\\n76224 47\\n51300 241\\n45542 87\\n38184 1398\\n92802 8\\n60559 70\\n6458 54\\n35620 3\\n57750 11\\n57175 4\\n65095 8\\n10390 387\\n13810 182\\n88779 1\\n30393 1\\n67934 35\\n65584 11\\n\", \"5 100000\\n66409 12\\n63802 2\\n95034 9\\n82818 1288\\n45078 227\\n\", \"10 100000\\n3219 7\\n12223 56\\n90921 27\\n71142 1398\\n87964 839\\n16499 8\\n72444 32\\n67739 130\\n93403 4\\n3846 3\\n\", \"20 100000\\n55345 8\\n65637 356\\n70322 88\\n16632 31\\n10631 854\\n76026 12\\n38962 8\\n26462 1\\n11676 122\\n76312 4\\n89117 687\\n57003 11\\n70170 266\\n64422 46\\n16054 2\\n93472 877\\n15206 24\\n39406 1149\\n99456 889\\n76963 2\\n\", \"40 100000\\n82729 23\\n20257 23\\n35728 2\\n25011 12\\n4960 71\\n21761 33\\n44761 14\\n71668 843\\n98965 53\\n80881 535\\n28561 404\\n61276 999\\n97500 851\\n19183 245\\n78699 876\\n63107 4\\n2802 478\\n62470 148\\n28013 26\\n350 1529\\n70579 8\\n71417 797\\n33173 1\\n19413 25\\n38142 191\\n72645 260\\n35515 2\\n28804 16\\n41640 2\\n21600 16\\n893 437\\n7071 368\\n75545 395\\n98218 1005\\n97927 3\\n43976 1\\n76398 2\\n10460 632\\n36563 38\\n37813 1254\\n\", \"5 100000\\n13264 13\\n67967 581\\n9017 12\\n22564 4\\n75202 981\\n\", \"10 100000\\n31514 7\\n43285 4660\\n39669 3899\\n60022 838\\n33584 643\\n78825 16\\n824 32\\n51664 31\\n15433 476\\n14295 591\\n\", \"20 100000\\n76900 749\\n4459 3\\n94269 2\\n82747 213\\n4707 2\\n25269 4510\\n20680 975\\n76445 105\\n69770 26\\n98437 138\\n9149 1727\\n542 1\\n4528 956\\n99559 3050\\n16375 86\\n2140 1295\\n59410 15\\n25894 7727\\n48176 1251\\n75691 962\\n\", \"40 100000\\n97318 1810\\n83374 13\\n5633 437\\n88352 47\\n95345 59\\n17545 249\\n24102 22\\n51457 1\\n76529 1\\n37126 18\\n49452 16\\n57843 23\\n9831 18\\n1455 3\\n11806 86\\n37145 2\\n88995 14\\n68601 14\\n43229 6\\n1611 3\\n30150 1479\\n55553 2\\n13132 50\\n16914 13\\n25556 63\\n89903 6883\\n56210 1\\n53913 3747\\n21131 798\\n46002 13\\n95645 2\\n87403 3155\\n34836 8\\n12090 61\\n13655 25\\n33060 54\\n42493 258\\n90629 3899\\n30302 2\\n95065 78\\n\", \"5 100000\\n37011 9701\\n74984 679\\n18318 55\\n92053 173\\n26429 12487\\n\", \"10 100000\\n11670 1339\\n79595 481\\n53274 401\\n14356 102\\n96605 13\\n2355 233\\n54983 6904\\n47863 49\\n27611 11\\n96114 336\\n\", \"20 100000\\n61697 2\\n97163 1\\n45531 2964\\n41121 1\\n55732 4965\\n12614 10451\\n48412 185\\n834 4\\n53784 337\\n27676 61\\n31448 120\\n73540 9753\\n51358 3568\\n31327 4576\\n69903 2048\\n48288 8116\\n54268 41\\n89314 10612\\n32624 16\\n83135 62\\n\", \"40 100000\\n3459 2\\n86272 5148\\n24317 160\\n44251 1415\\n26597 1\\n1319 256\\n92116 4\\n38907 3\\n60128 6673\\n71018 2\\n35857 936\\n97060 2\\n4950 6165\\n63923 4\\n75390 2346\\n83335 2\\n57524 6\\n99812 3\\n32248 206\\n48786 3185\\n69204 16143\\n55261 7\\n67356 2\\n86284 148\\n19119 3\\n45733 369\\n85011 73\\n73772 106\\n64294 33\\n53040 26\\n86208 12520\\n77019 1573\\n52972 2928\\n9979 352\\n39446 303\\n51300 3353\\n49439 639\\n53349 620\\n37475 1303\\n53218 12257\\n\", \"5 100000\\n89743 8\\n64030 13\\n33057 439\\n69697 34\\n28568 11302\\n\", \"10 100000\\n308 1\\n27837 235\\n74223 8762\\n25432 10\\n62498 5795\\n65172 3223\\n39762 48\\n74347 1\\n6364 1523\\n73376 8\\n\", \"20 100000\\n32216 25\\n1771 1876\\n29601 4397\\n65385 2\\n75865 1\\n97013 28\\n60770 1816\\n17137 32\\n32943 15\\n5320 5\\n10846 7383\\n77785 13\\n62852 369\\n78343 7\\n86849 14387\\n80901 546\\n42168 3254\\n99786 32092\\n93242 24\\n14005 53\\n\", \"40 100000\\n8644 429\\n97881 2766\\n98955 25663\\n8679 187\\n54897 23213\\n64306 4647\\n46280 23471\\n31464 3\\n35532 2\\n95998 1352\\n28824 3\\n99405 3856\\n47271 13832\\n66959 7\\n50599 11\\n70318 293\\n84159 236\\n10893 1914\\n54437 15065\\n4468 3\\n91940 32106\\n87980 50\\n81589 378\\n8783 23\\n11417 690\\n2733 259\\n84915 26\\n15315 2880\\n60017 3214\\n58220 1\\n17160 185\\n60640 10496\\n46075 143\\n12251 2938\\n6582 12\\n7234 827\\n32344 830\\n3330 18\\n48612 290\\n47531 14241\\n\", \"5 100000\\n54710 49\\n23118 497\\n25124 113\\n8533 204\\n6259 78\\n\", \"10 100000\\n17296 29\\n91310 2\\n57522 122\\n3226 3493\\n56545 798\\n34449 65176\\n52982 57\\n63054 20\\n85401 26\\n35366 40\\n\", \"20 100000\\n48315 147\\n18844 54412\\n53410 113\\n47381 299\\n47399 4\\n43189 2182\\n44092 269\\n86931 4\\n69501 21297\\n7463 152\\n748 3195\\n21275 2\\n91263 2853\\n70156 4\\n94007 11073\\n73642 27\\n10505 88\\n48437 56\\n45377 3297\\n44125 328\\n\", \"40 100000\\n97613 14\\n21950 98\\n79071 6\\n17398 4\\n52818 26\\n86382 74\\n45221 20\\n34027 4550\\n37075 16\\n64440 15989\\n16227 277\\n55118 887\\n89050 678\\n14236 3\\n23333 24\\n95767 7042\\n76449 294\\n34947 62\\n93092 3916\\n10791 1852\\n10371 84\\n11819 36794\\n3774 22\\n20470 574\\n69834 216\\n86866 21\\n48346 11\\n79493 27990\\n54723 4\\n7406 963\\n21932 18679\\n98450 13060\\n28964 915\\n86494 14\\n6303 392\\n865 3624\\n31750 23\\n65411 241\\n8209 312\\n15896 17139\\n\", \"3 100000\\n3 1200\\n1205 0\\n80000 78793\\n\", \"3 100000\\n20001 78793\\n98796 0\\n99998 1200\\n\", \"8 100000\\n1217 0\\n1208 0\\n1220 0\\n3 1200\\n1205 0\\n1214 0\\n1211 0\\n80000 78778\\n\", \"8 100000\\n98796 0\\n20001 78778\\n98790 0\\n98781 0\\n98787 0\\n98793 0\\n98784 0\\n99998 1200\\n\"], \"outputs\": [\"281\\n\", \"0\\n\", \"30\\n\", \"26\\n\", \"99997\\n\", \"99999\\n\", \"99999\\n\", \"99998\\n\", \"126\\n\", \"94\\n\", \"89\\n\", \"49963\\n\", \"49765\\n\", \"40507\\n\", \"26632\\n\", \"49992\\n\", \"0\\n\", \"66803\\n\", \"77286\\n\", \"49205\\n\", \"50644\\n\", \"49057\\n\", \"47987\\n\", \"2144\\n\", \"52045\\n\", \"50084\\n\", \"49985\\n\", \"49936\\n\", \"51453\\n\", \"50085\\n\", \"49970\\n\", \"49894\\n\", \"64333\\n\", \"50054\\n\", \"49922\\n\", \"49811\\n\", \"55550\\n\", \"50083\\n\", \"49883\\n\", \"49732\\n\", \"54920\\n\", \"49985\\n\", \"49854\\n\", \"49554\\n\", \"53474\\n\", \"50444\\n\", \"49715\\n\", \"48822\\n\", \"50997\\n\", \"50425\\n\", \"49678\\n\", \"48168\\n\", \"50677\\n\", \"49615\\n\", \"48450\\n\", \"48015\\n\", \"59565\\n\", \"49678\\n\", \"47933\\n\", \"46585\\n\", \"51045\\n\", \"46506\\n\", \"47971\\n\", \"41284\\n\", \"49807\\n\", \"51101\\n\", \"45965\\n\", \"43774\\n\", \"51652\\n\", \"44144\\n\", \"34689\\n\", \"35469\\n\", \"38278\\n\", \"41632\\n\", \"7753\\n\", \"15210\\n\", \"40041\\n\", \"41919\\n\", \"20505\\n\", \"7924\\n\", \"51421\\n\", \"375\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"6\\n\", \"6\\n\"]}", "source": "primeintellect"}
|
The mayor of the Central Town wants to modernize Central Street, represented in this problem by the $(Ox)$ axis.
On this street, there are $n$ antennas, numbered from $1$ to $n$. The $i$-th antenna lies on the position $x_i$ and has an initial scope of $s_i$: it covers all integer positions inside the interval $[x_i - s_i; x_i + s_i]$.
It is possible to increment the scope of any antenna by $1$, this operation costs $1$ coin. We can do this operation as much as we want (multiple times on the same antenna if we want).
To modernize the street, we need to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna. Note that it is authorized to cover positions outside $[1; m]$, even if it's not required.
What is the minimum amount of coins needed to achieve this modernization?
-----Input-----
The first line contains two integers $n$ and $m$ ($1 \le n \le 80$ and $n \le m \le 100\ 000$).
The $i$-th of the next $n$ lines contains two integers $x_i$ and $s_i$ ($1 \le x_i \le m$ and $0 \le s_i \le m$).
On each position, there is at most one antenna (values $x_i$ are pairwise distinct).
-----Output-----
You have to output a single integer: the minimum amount of coins required to make all integer positions from $1$ to $m$ inclusive covered by at least one antenna.
-----Examples-----
Input
3 595
43 2
300 4
554 10
Output
281
Input
1 1
1 1
Output
0
Input
2 50
20 0
3 1
Output
30
Input
5 240
13 0
50 25
60 5
155 70
165 70
Output
26
-----Note-----
In the first example, here is a possible strategy:
Increase the scope of the first antenna by $40$, so that it becomes $2 + 40 = 42$. This antenna will cover interval $[43 - 42; 43 + 42]$ which is $[1; 85]$ Increase the scope of the second antenna by $210$, so that it becomes $4 + 210 = 214$. This antenna will cover interval $[300 - 214; 300 + 214]$, which is $[86; 514]$ Increase the scope of the third antenna by $31$, so that it becomes $10 + 31 = 41$. This antenna will cover interval $[554 - 41; 554 + 41]$, which is $[513; 595]$
Total cost is $40 + 210 + 31 = 281$. We can prove that it's the minimum cost required to make all positions from $1$ to $595$ covered by at least one antenna.
Note that positions $513$ and $514$ are in this solution covered by two different antennas, but it's not important.
—
In the second example, the first antenna already covers an interval $[0; 2]$ so we have nothing to do.
Note that the only position that we needed to cover was position $1$; positions $0$ and $2$ are covered, but it's not important.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 1 2\\n\", \"2 1 5\\n\", \"3 1 1\\n\", \"5 5 5\\n\", \"4 0 0\\n\", \"6 0 6\\n\", \"6 6 0\\n\", \"2 1 2\\n\", \"100000000 1 0\\n\", \"2 0 0\\n\", \"2 100000000 100000000\\n\", \"2 100000000 0\\n\", \"2 0 100000000\\n\", \"100000000 0 0\\n\", \"100000000 100000000 100000000\\n\", \"100000000 100000000 0\\n\", \"100000000 0 100000000\\n\", \"2 50000000 0\\n\", \"2 50000000 100000000\\n\", \"2 50000000 0\\n\", \"2 50000000 100000000\\n\", \"100000000 50000000 0\\n\", \"100000000 50000000 100000000\\n\", \"100000000 50000000 0\\n\", \"100000000 50000000 100000000\\n\", \"96212915 66569231 66289469\\n\", \"39969092 91869601 91924349\\n\", \"26854436 29462638 67336233\\n\", \"39201451 80233602 30662934\\n\", \"92820995 96034432 40568102\\n\", \"81913246 61174868 31286889\\n\", \"74790405 66932852 48171076\\n\", \"88265295 26984472 18821097\\n\", \"39858798 77741429 44017779\\n\", \"70931513 41663344 29095671\\n\", \"68251617 52232534 34187120\\n\", \"44440915 82093126 57268128\\n\", \"61988457 90532323 72913492\\n\", \"13756397 41019327 86510346\\n\", \"84963589 37799442 20818727\\n\", \"99338896 62289589 49020203\\n\", \"1505663 3257962 1039115\\n\", \"80587587 25402325 8120971\\n\", \"64302230 83635846 22670768\\n\", \"6508457 32226669 8706339\\n\", \"1389928 84918086 54850899\\n\", \"37142108 10188690 35774598\\n\", \"86813943 11824369 38451380\\n\", \"14913475 61391038 9257618\\n\", \"25721978 63666459 14214946\\n\", \"73363656 63565575 76409698\\n\", \"34291060 92893503 64680754\\n\", \"85779772 26434899 86820336\\n\", \"7347370 2098650 66077918\\n\", \"28258585 6194848 49146833\\n\", \"9678 133 5955\\n\", \"9251 4756 2763\\n\", \"1736 5628 2595\\n\", \"5195 1354 2885\\n\", \"1312 5090 9909\\n\", \"8619 6736 9365\\n\", \"151 7023 3093\\n\", \"5992 2773 6869\\n\", \"3894 9921 3871\\n\", \"1006 9237 1123\\n\", \"9708 3254 2830\\n\", \"1504 1123 626\\n\", \"8642 5709 51\\n\", \"8954 4025 7157\\n\", \"4730 8020 8722\\n\", \"2500 5736 4002\\n\", \"6699 4249 1068\\n\", \"4755 6759 4899\\n\", \"8447 1494 4432\\n\", \"6995 4636 8251\\n\", \"4295 9730 4322\\n\", \"8584 4286 9528\\n\", \"174 6826 355\\n\", \"5656 7968 3400\\n\", \"2793 175 3594\\n\", \"2888 9056 3931\\n\", \"6222 7124 6784\\n\", \"8415 8714 2475\\n\", \"2179 7307 8608\\n\", \"1189 1829 6875\\n\"], \"outputs\": [\"12\\n\", \"6\\n\", \"5\\n\", \"60\\n\", \"0\\n\", \"30\\n\", \"30\\n\", \"3\\n\", \"99999999\\n\", \"0\\n\", \"200000000\\n\", \"100000000\\n\", \"100000000\\n\", \"0\\n\", \"266578227200000000\\n\", \"9999999900000000\\n\", \"9999999900000000\\n\", \"50000000\\n\", \"150000000\\n\", \"50000000\\n\", \"150000000\\n\", \"4999999950000000\\n\", \"191720992950000000\\n\", \"4999999950000000\\n\", \"191720992950000000\\n\", \"170023209909758400\\n\", \"93003696194821620\\n\", \"30373819153055635\\n\", \"50953283386656312\\n\", \"158135215198065044\\n\", \"96084588586645841\\n\", \"111690840882243696\\n\", \"52835608063500861\\n\", \"59709461677488470\\n\", \"64816798089350400\\n\", \"75694251898945158\\n\", \"77907273273831800\\n\", \"130757350538583270\\n\", \"19895886795999000\\n\", \"63754887412974663\\n\", \"146320678028775569\\n\", \"60023256524142\\n\", \"32044560697691212\\n\", \"77790985833197594\\n\", \"2645634460061466\\n\", \"1953921305304795\\n\", \"19009588918065432\\n\", \"51645349299460766\\n\", \"9761450207212562\\n\", \"20847031763747988\\n\", \"133919836504944416\\n\", \"66960630525688676\\n\", \"114681463889615136\\n\", \"3070602135161752\\n\", \"14441957862691571\\n\", \"196970292\\n\", \"448302621\\n\", \"73441521\\n\", \"130236572\\n\", \"98808420\\n\", \"900966230\\n\", \"5267919\\n\", \"340564941\\n\", \"299508763\\n\", \"38974261\\n\", \"391502526\\n\", \"13538132\\n\", \"135655830\\n\", \"641304164\\n\", \"484587068\\n\", \"136264140\\n\", \"196812772\\n\", \"336456318\\n\", \"298387478\\n\", \"561476311\\n\", \"346320888\\n\", \"738058224\\n\", \"2889605\\n\", \"379249528\\n\", \"36405762\\n\", \"204521173\\n\", \"547839384\\n\", \"545452719\\n\", \"192281235\\n\", \"46521099\\n\"]}", "source": "primeintellect"}
|
R3D3 spent some time on an internship in MDCS. After earning enough money, he decided to go on a holiday somewhere far, far away. He enjoyed suntanning, drinking alcohol-free cocktails and going to concerts of popular local bands. While listening to "The White Buttons" and their hit song "Dacan the Baker", he met another robot for whom he was sure is the love of his life. Well, his summer, at least. Anyway, R3D3 was too shy to approach his potential soulmate, so he decided to write her a love letter. However, he stumbled upon a problem. Due to a terrorist threat, the Intergalactic Space Police was monitoring all letters sent in the area. Thus, R3D3 decided to invent his own alphabet, for which he was sure his love would be able to decipher.
There are n letters in R3D3’s alphabet, and he wants to represent each letter as a sequence of '0' and '1', so that no letter’s sequence is a prefix of another letter's sequence. Since the Intergalactic Space Communications Service has lately introduced a tax for invented alphabets, R3D3 must pay a certain amount of money for each bit in his alphabet’s code (check the sample test for clarifications). He is too lovestruck to think clearly, so he asked you for help.
Given the costs c_0 and c_1 for each '0' and '1' in R3D3’s alphabet, respectively, you should come up with a coding for the alphabet (with properties as above) with minimum total cost.
-----Input-----
The first line of input contains three integers n (2 ≤ n ≤ 10^8), c_0 and c_1 (0 ≤ c_0, c_1 ≤ 10^8) — the number of letters in the alphabet, and costs of '0' and '1', respectively.
-----Output-----
Output a single integer — minimum possible total a cost of the whole alphabet.
-----Example-----
Input
4 1 2
Output
12
-----Note-----
There are 4 letters in the alphabet. The optimal encoding is "00", "01", "10", "11". There are 4 zeroes and 4 ones used, so the total cost is 4·1 + 4·2 = 12.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n\", \"3\\n\", \"2\\n\", \"5\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"1\\n\", \"21\\n\", \"14\\n\", \"360561\\n\", \"25\\n\", \"85\\n\", \"699049\\n\", \"699047\\n\", \"6\\n\", \"10\\n\", \"699050\\n\", \"699048\\n\", \"1000000\\n\", \"786432\\n\", \"750096\\n\", \"10922\\n\", \"699051\\n\", \"87380\\n\", \"308545\\n\", \"16\\n\", \"20\\n\", \"170\\n\", \"22\\n\", \"84\\n\", \"174762\\n\", \"341\\n\", \"17\\n\", \"530259\\n\", \"181407\\n\", \"5461\\n\", \"21844\\n\", \"472032\\n\", \"325193\\n\", \"43689\\n\", \"43690\\n\", \"31\\n\", \"524288\\n\", \"546029\\n\", \"5460\\n\", \"26\\n\", \"682\\n\", \"621012\\n\", \"19\\n\", \"334846\\n\", \"549836\\n\", \"797049\\n\", \"174761\\n\", \"320507\\n\", \"699046\\n\", \"681\\n\", \"28\\n\", \"87381\\n\", \"27\\n\", \"503375\\n\", \"557479\\n\", \"11\\n\", \"13156\\n\", \"349525\\n\", \"10921\\n\", \"259060\\n\", \"21845\\n\", \"175466\\n\", \"796867\\n\", \"527730\\n\", \"737480\\n\", \"740812\\n\", \"631649\\n\", \"1365\\n\", \"581472\\n\", \"622262\\n\", \"42\\n\", \"629191\\n\", \"12\\n\", \"2730\\n\", \"988727\\n\", \"999999\\n\", \"169\\n\"], \"outputs\": [\"1\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
Recall that a binary search tree is a rooted binary tree, whose nodes each store a key and each have at most two distinguished subtrees, left and right. The key in each node must be greater than any key stored in the left subtree, and less than any key stored in the right subtree.
The depth of a vertex is the number of edges on the simple path from the vertex to the root. In particular, the depth of the root is $0$.
Let's call a binary search tree perfectly balanced if there doesn't exist a binary search tree with the same number of vertices that has a strictly smaller sum of depths of its vertices.
Let's call a binary search tree with integer keys striped if both of the following conditions are satisfied for every vertex $v$: If $v$ has a left subtree whose root is $u$, then the parity of the key of $v$ is different from the parity of the key of $u$. If $v$ has a right subtree whose root is $w$, then the parity of the key of $v$ is the same as the parity of the key of $w$.
You are given a single integer $n$. Find the number of perfectly balanced striped binary search trees with $n$ vertices that have distinct integer keys between $1$ and $n$, inclusive. Output this number modulo $998\,244\,353$.
-----Input-----
The only line contains a single integer $n$ ($1 \le n \le 10^6$), denoting the required number of vertices.
-----Output-----
Output the number of perfectly balanced striped binary search trees with $n$ vertices and distinct integer keys between $1$ and $n$, inclusive, modulo $998\,244\,353$.
-----Examples-----
Input
4
Output
1
Input
3
Output
0
-----Note-----
In the first example, this is the only tree that satisfies the conditions: $\left. \begin{array}{l}{\text{perfectly balanced}} \\{\text{striped}} \\{\text{binary search tree}} \end{array} \right.$
In the second example, here are various trees that don't satisfy some condition: [Image]
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n\", \"6\\n\", \"4\\n\", \"1\\n\", \"24\\n\", \"200560490130\\n\", \"999999999989\\n\", \"1000000000000\\n\", \"999966000289\\n\", \"991921850317\\n\", \"997167959139\\n\", \"244641009859\\n\", \"483524125987\\n\", \"726702209411\\n\", \"965585325539\\n\", \"213058376259\\n\", \"690824608515\\n\", \"551519879446\\n\", \"179452405440\\n\", \"665808572289\\n\", \"438282886646\\n\", \"451941492387\\n\", \"934002691939\\n\", \"375802030518\\n\", \"614685146646\\n\", \"857863230070\\n\", \"101041313494\\n\", \"344219396918\\n\", \"583102513046\\n\", \"821985629174\\n\", \"69458679894\\n\", \"308341796022\\n\", \"418335521569\\n\", \"904691688417\\n\", \"147869771841\\n\", \"386752887969\\n\", \"629930971393\\n\", \"873109054817\\n\", \"111992170945\\n\", \"355170254369\\n\", \"946248004555\\n\", \"185131120683\\n\", \"432604171403\\n\", \"671487287531\\n\", \"914665370955\\n\", \"157843454379\\n\", \"401021537803\\n\", \"639904653932\\n\", \"878787770060\\n\", \"126260820780\\n\", \"713043603670\\n\", \"956221687094\\n\", \"199399770518\\n\", \"681460970070\\n\", \"924639053494\\n\", \"167817136918\\n\", \"406700253046\\n\", \"645583369174\\n\", \"893056419894\\n\", \"484134170081\\n\", \"723017286209\\n\", \"966195369633\\n\", \"205078485761\\n\", \"452551536481\\n\", \"691434652609\\n\", \"934612736033\\n\", \"173495852161\\n\", \"416673935585\\n\", \"659852019009\\n\", \"287784545004\\n\", \"526667661132\\n\", \"769845744556\\n\", \"8728860684\\n\", \"256201911404\\n\", \"495085027532\\n\", \"738263110956\\n\", \"981441194380\\n\", \"220324310508\\n\", \"463502393932\\n\", \"54580144118\\n\", \"2038074743\\n\", \"252097800623\\n\", \"518649879439\\n\", \"963761198400\\n\"], \"outputs\": [\"1 2\\n\", \"2 3\\n\", \"1 4\\n\", \"1 1\\n\", \"8 3\\n\", \"448630 447051\\n\", \"1 999999999989\\n\", \"4096 244140625\\n\", \"1 999966000289\\n\", \"1 991921850317\\n\", \"1043317 955767\\n\", \"15703 15579253\\n\", \"1967 245818061\\n\", \"623971 1164641\\n\", \"163 5923836353\\n\", \"3 71019458753\\n\", \"45 15351657967\\n\", \"142 3883942813\\n\", \"429120 418187\\n\", \"8043 82781123\\n\", \"652531 671666\\n\", \"427623 1056869\\n\", \"23 40608812693\\n\", \"438918 856201\\n\", \"6 102447524441\\n\", \"1040215 824698\\n\", \"176374 572881\\n\", \"2 172109698459\\n\", \"2 291551256523\\n\", \"2 410992814587\\n\", \"6 11576446649\\n\", \"234 1317699983\\n\", \"119 3515424551\\n\", \"576747 1568611\\n\", \"314347 470403\\n\", \"147 2630972027\\n\", \"16938637 37189\\n\", \"5981551 145967\\n\", \"459005 243989\\n\", \"7 50738607767\\n\", \"1855 510106741\\n\", \"213 869160191\\n\", \"2083223 207661\\n\", \"389527 1723853\\n\", \"105 8711098771\\n\", \"382083 413113\\n\", \"583081 687763\\n\", \"1004 637355233\\n\", \"1274860 689321\\n\", \"22380 5641681\\n\", \"1056710 674777\\n\", \"1024054 933761\\n\", \"12662 15747889\\n\", \"910590 748373\\n\", \"598 1546219153\\n\", \"94606 1773853\\n\", \"2 203350126523\\n\", \"7222 89391217\\n\", \"102 8755455097\\n\", \"1186583 408007\\n\", \"528287 1368607\\n\", \"39 24774240247\\n\", \"185921 1103041\\n\", \"11 41141048771\\n\", \"1005947 687347\\n\", \"89 10501266697\\n\", \"1 173495852161\\n\", \"309655 1345607\\n\", \"2104677 313517\\n\", \"482119 596916\\n\", \"214836 2451487\\n\", \"1229116 626341\\n\", \"348 25082933\\n\", \"4 64050477851\\n\", \"53932 9179801\\n\", \"4956 148963501\\n\", \"438980 2235731\\n\", \"12 18360359209\\n\", \"2372 195405731\\n\", \"2 27290072059\\n\", \"1 2038074743\\n\", \"1 252097800623\\n\", \"1 518649879439\\n\", \"969408 994175\\n\"]}", "source": "primeintellect"}
|
Today, Osama gave Fadi an integer $X$, and Fadi was wondering about the minimum possible value of $max(a, b)$ such that $LCM(a, b)$ equals $X$. Both $a$ and $b$ should be positive integers.
$LCM(a, b)$ is the smallest positive integer that is divisible by both $a$ and $b$. For example, $LCM(6, 8) = 24$, $LCM(4, 12) = 12$, $LCM(2, 3) = 6$.
Of course, Fadi immediately knew the answer. Can you be just like Fadi and find any such pair?
-----Input-----
The first and only line contains an integer $X$ ($1 \le X \le 10^{12}$).
-----Output-----
Print two positive integers, $a$ and $b$, such that the value of $max(a, b)$ is minimum possible and $LCM(a, b)$ equals $X$. If there are several possible such pairs, you can print any.
-----Examples-----
Input
2
Output
1 2
Input
6
Output
2 3
Input
4
Output
1 4
Input
1
Output
1 1
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n2 7 28\\n\", \"1\\n1\\n\", \"1\\n548\\n\", \"1\\n963837006\\n\", \"10\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10\\n26 723 970 13 422 968 875 329 234 983\\n\", \"10\\n319645572 758298525 812547177 459359946 355467212 304450522 807957797 916787906 239781206 242840396\\n\", \"100\\n1 1 1 1 2 1 1 1 1 1 2 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 2 2 1 1 2 1 1 1 2 2 2 1 1 1 2 1 2 2 1 2 1 1 2 2 1 2 1 2 1 2 2 1 1 1 2 1 1 2 1 2 1 2 2 2 1 2 1 2 2 2 1 2 2 1 1 1 1 2 2 2 2 2 2 2 1 1 1 2 1 2 1\\n\", \"100\\n591 417 888 251 792 847 685 3 182 461 102 348 555 956 771 901 712 878 580 631 342 333 285 899 525 725 537 718 929 653 84 788 104 355 624 803 253 853 201 995 536 184 65 205 540 652 549 777 248 405 677 950 431 580 600 846 328 429 134 983 526 103 500 963 400 23 276 704 570 757 410 658 507 620 984 244 486 454 802 411 985 303 635 283 96 597 855 775 139 839 839 61 219 986 776 72 729 69 20 917\\n\", \"5\\n472882027 472882027 472882027 472882027 472882027\\n\", \"2\\n1000000000 1000000000\\n\", \"2\\n8 6\\n\", \"3\\n100000000 1000000000 1000000000\\n\", \"5\\n1 2 3 4 5\\n\", \"20\\n2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000 2 1000000000\\n\", \"2\\n223092870 23\\n\", \"2\\n100000003 100000003\\n\", \"2\\n999999937 999999937\\n\", \"4\\n999 999999937 999999937 999\\n\", \"2\\n999999929 999999929\\n\", \"2\\n1049459 2098918\\n\", \"2\\n352229 704458\\n\", \"2\\n7293 4011\\n\", \"2\\n5565651 3999930\\n\", \"2\\n997 997\\n\", \"3\\n9994223 9994223 9994223\\n\", \"2\\n99999998 1000000000\\n\", \"3\\n1000000000 1000000000 1000000000\\n\", \"2\\n130471 130471\\n\", \"3\\n1000000000 2 2\\n\", \"2\\n223092870 66526\\n\", \"14\\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491 436077930 570018449\\n\", \"2\\n3996017 3996017\\n\", \"2\\n999983 999983\\n\", \"2\\n618575685 773990454\\n\", \"3\\n9699690 3 7\\n\", \"2\\n999999999 999999996\\n\", \"2\\n99999910 99999910\\n\", \"12\\n1000000000 1000000000 223092870 223092870 6 105 2 2 510510 510510 999999491 999999491\\n\", \"3\\n999999937 999999937 999999937\\n\", \"2\\n99839 99839\\n\", \"3\\n19999909 19999909 19999909\\n\", \"4\\n1 1000000000 1 1000000000\\n\", \"2\\n64006 64006\\n\", \"2\\n1956955 1956955\\n\", \"3\\n1 1000000000 1000000000\\n\", \"2\\n982451707 982451707\\n\", \"2\\n999999733 999999733\\n\", \"3\\n999999733 999999733 999999733\\n\", \"2\\n3257 3257\\n\", \"2\\n223092870 181598\\n\", \"3\\n959919409 105935 105935\\n\", \"2\\n510510 510510\\n\", \"3\\n223092870 1000000000 1000000000\\n\", \"14\\n1000000000 2 1000000000 3 1000000000 6 1000000000 1000000000 15 1000000000 1000000000 1000000000 100000000 1000\\n\", \"7\\n1 982451653 982451653 1 982451653 982451653 982451653\\n\", \"2\\n100000007 100000007\\n\", \"3\\n999999757 999999757 999999757\\n\", \"3\\n99999989 99999989 99999989\\n\", \"5\\n2 4 982451707 982451707 3\\n\", \"2\\n20000014 20000014\\n\", \"2\\n99999989 99999989\\n\", \"2\\n111546435 111546435\\n\", \"2\\n55288874 33538046\\n\", \"5\\n179424673 179424673 179424673 179424673 179424673\\n\", \"2\\n199999978 199999978\\n\", \"2\\n1000000000 2\\n\", \"3\\n19999897 19999897 19999897\\n\", \"2\\n19999982 19999982\\n\", \"2\\n10000007 10000007\\n\", \"3\\n999999937 999999937 2\\n\", \"5\\n2017 2017 2017 2017 2017\\n\", \"2\\n19999909 39999818\\n\", \"2\\n62615533 7919\\n\", \"5\\n39989 39989 33 31 29\\n\", \"2\\n1000000000 100000\\n\", \"2\\n1938 10010\\n\", \"2\\n199999 199999\\n\", \"2\\n107273 107273\\n\", \"3\\n49999 49999 49999\\n\", \"2\\n1999966 1999958\\n\", \"2\\n86020 300846\\n\", \"2\\n999999997 213\\n\", \"2\\n200000014 200000434\\n\"], \"outputs\": [\"1\\n2 7 1 28\\n\", \"0\\n1\\n\", \"0\\n548\\n\", \"0\\n963837006\\n\", \"0\\n1 1 1 1 1 1 1 1 1 1\\n\", \"2\\n26 723 970 13 422 1 968 875 1 329 234 983\\n\", \"7\\n319645572 1 758298525 1 812547177 1 459359946 1 355467212 1 304450522 807957797 916787906 1 239781206 1 242840396\\n\", \"19\\n1 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 2 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 2 1 1 1 2 1 2 1 2 1 1 1 2 1 2 1 2 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 1 2 1 2 1 2 1 2 1 2 1 2 1 2 1 1 1 2 1 2 1\\n\", \"38\\n591 1 417 1 888 251 792 1 847 685 3 182 461 102 1 348 1 555 956 771 901 712 1 878 1 580 631 342 1 333 1 285 899 525 1 725 537 718 929 653 84 1 788 1 104 355 624 803 1 253 853 201 995 536 1 184 65 1 205 1 540 1 652 549 1 777 248 405 677 950 431 580 1 600 1 846 1 328 429 134 983 526 103 500 963 400 23 1 276 1 704 1 570 757 410 1 658 507 620 1 984 1 244 1 486 1 454 1 802 411 985 303 635 283 96 1 597 1 855 1 775 139 839 1 839 61 219 986 1 776 1 72 1 729 1 69 20 917\\n\", \"4\\n472882027 1 472882027 1 472882027 1 472882027 1 472882027\\n\", \"1\\n1000000000 1 1000000000\\n\", \"1\\n8 1 6\\n\", \"2\\n100000000 1 1000000000 1 1000000000\\n\", \"0\\n1 2 3 4 5\\n\", \"19\\n2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000 1 2 1 1000000000\\n\", \"1\\n223092870 1 23\\n\", \"1\\n100000003 1 100000003\\n\", \"1\\n999999937 1 999999937\\n\", \"1\\n999 999999937 1 999999937 999\\n\", \"1\\n999999929 1 999999929\\n\", \"1\\n1049459 1 2098918\\n\", \"1\\n352229 1 704458\\n\", \"1\\n7293 1 4011\\n\", \"1\\n5565651 1 3999930\\n\", \"1\\n997 1 997\\n\", \"2\\n9994223 1 9994223 1 9994223\\n\", \"1\\n99999998 1 1000000000\\n\", \"2\\n1000000000 1 1000000000 1 1000000000\\n\", \"1\\n130471 1 130471\\n\", \"2\\n1000000000 1 2 1 2\\n\", \"1\\n223092870 1 66526\\n\", \"10\\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491 436077930 1 570018449\\n\", \"1\\n3996017 1 3996017\\n\", \"1\\n999983 1 999983\\n\", \"1\\n618575685 1 773990454\\n\", \"1\\n9699690 1 3 7\\n\", \"1\\n999999999 1 999999996\\n\", \"1\\n99999910 1 99999910\\n\", \"9\\n1000000000 1 1000000000 1 223092870 1 223092870 1 6 1 105 2 1 2 1 510510 1 510510 999999491 1 999999491\\n\", \"2\\n999999937 1 999999937 1 999999937\\n\", \"1\\n99839 1 99839\\n\", \"2\\n19999909 1 19999909 1 19999909\\n\", \"0\\n1 1000000000 1 1000000000\\n\", \"1\\n64006 1 64006\\n\", \"1\\n1956955 1 1956955\\n\", \"1\\n1 1000000000 1 1000000000\\n\", \"1\\n982451707 1 982451707\\n\", \"1\\n999999733 1 999999733\\n\", \"2\\n999999733 1 999999733 1 999999733\\n\", \"1\\n3257 1 3257\\n\", \"1\\n223092870 1 181598\\n\", \"2\\n959919409 1 105935 1 105935\\n\", \"1\\n510510 1 510510\\n\", \"2\\n223092870 1 1000000000 1 1000000000\\n\", \"11\\n1000000000 1 2 1 1000000000 3 1000000000 1 6 1 1000000000 1 1000000000 1 15 1 1000000000 1 1000000000 1 1000000000 1 100000000 1 1000\\n\", \"3\\n1 982451653 1 982451653 1 982451653 1 982451653 1 982451653\\n\", \"1\\n100000007 1 100000007\\n\", \"2\\n999999757 1 999999757 1 999999757\\n\", \"2\\n99999989 1 99999989 1 99999989\\n\", \"2\\n2 1 4 982451707 1 982451707 3\\n\", \"1\\n20000014 1 20000014\\n\", \"1\\n99999989 1 99999989\\n\", \"1\\n111546435 1 111546435\\n\", \"1\\n55288874 1 33538046\\n\", \"4\\n179424673 1 179424673 1 179424673 1 179424673 1 179424673\\n\", \"1\\n199999978 1 199999978\\n\", \"1\\n1000000000 1 2\\n\", \"2\\n19999897 1 19999897 1 19999897\\n\", \"1\\n19999982 1 19999982\\n\", \"1\\n10000007 1 10000007\\n\", \"1\\n999999937 1 999999937 2\\n\", \"4\\n2017 1 2017 1 2017 1 2017 1 2017\\n\", \"1\\n19999909 1 39999818\\n\", \"1\\n62615533 1 7919\\n\", \"1\\n39989 1 39989 33 31 29\\n\", \"1\\n1000000000 1 100000\\n\", \"1\\n1938 1 10010\\n\", \"1\\n199999 1 199999\\n\", \"1\\n107273 1 107273\\n\", \"2\\n49999 1 49999 1 49999\\n\", \"1\\n1999966 1 1999958\\n\", \"1\\n86020 1 300846\\n\", \"1\\n999999997 1 213\\n\", \"1\\n200000014 1 200000434\\n\"]}", "source": "primeintellect"}
|
You are given an array of n elements, you must make it a co-prime array in as few moves as possible.
In each move you can insert any positive integral number you want not greater than 10^9 in any place in the array.
An array is co-prime if any two adjacent numbers of it are co-prime.
In the number theory, two integers a and b are said to be co-prime if the only positive integer that divides both of them is 1.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 1000) — the number of elements in the given array.
The second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the elements of the array a.
-----Output-----
Print integer k on the first line — the least number of elements needed to add to the array a to make it co-prime.
The second line should contain n + k integers a_{j} — the elements of the array a after adding k elements to it. Note that the new array should be co-prime, so any two adjacent values should be co-prime. Also the new array should be got from the original array a by adding k elements to it.
If there are multiple answers you can print any one of them.
-----Example-----
Input
3
2 7 28
Output
1
2 7 9 28
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.25
|
{"tests": "{\"inputs\": [\"39\\n\", \"1\\n\", \"7\\n\", \"1000000\\n\", \"524288\\n\", \"524289\\n\", \"524287\\n\", \"699050\\n\", \"349525\\n\", \"2\\n\", \"5\\n\", \"6\\n\", \"11\\n\", \"13\\n\", \"545860\\n\", \"917503\\n\", \"174762\\n\", \"43690\\n\", \"10922\\n\", \"2730\\n\", \"682\\n\", \"170\\n\", \"42\\n\", \"87381\\n\", \"21845\\n\", \"5461\\n\", \"1365\\n\", \"341\\n\", \"85\\n\", \"21\\n\", \"4\\n\", \"3\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"12\\n\", \"14\\n\", \"15\\n\", \"16\\n\", \"17\\n\", \"18\\n\", \"19\\n\", \"20\\n\", \"22\\n\", \"23\\n\", \"24\\n\", \"25\\n\", \"26\\n\", \"27\\n\", \"28\\n\", \"29\\n\", \"30\\n\", \"31\\n\", \"32\\n\", \"33\\n\", \"34\\n\", \"35\\n\", \"36\\n\", \"98\\n\", \"130\\n\", \"354\\n\", \"949\\n\", \"1557\\n\", \"2677\\n\", \"5845\\n\", \"11061\\n\", \"32661\\n\", \"62453\\n\", \"75861\\n\", \"187573\\n\", \"364821\\n\", \"524416\\n\", \"540673\\n\", \"794628\\n\", \"524641\\n\", \"524636\\n\", \"592548\\n\", \"895360\\n\", \"542413\\n\", \"885114\\n\", \"575965\\n\", \"896794\\n\", \"776441\\n\", \"761841\\n\", \"842719\\n\", \"769527\\n\", \"704511\\n\", \"915455\\n\"], \"outputs\": [\"4\\n5 3 \", \"0\\n\", \"0\\n\", \"7\\n14 6 9 15 \", \"1\\n19 \", \"2\\n19 \", \"0\\n\", \"19\\n1 2 4 6 8 10 12 14 16 18 \", \"19\\n0 1 3 5 7 9 11 13 15 17 \", \"1\\n1 \", \"2\\n2 \", \"1\\n1 \", \"3\\n0 2 \", \"2\\n2 \", \"11\\n19 2 6 10 12 14 \", \"3\\n0 17 \", \"17\\n1 2 4 6 8 10 12 14 16 \", \"15\\n1 2 4 6 8 10 12 14 \", \"13\\n1 2 4 6 8 10 12 \", \"11\\n1 2 4 6 8 10 \", \"9\\n1 2 4 6 8 \", \"7\\n1 2 4 6 \", \"5\\n1 2 4 \", \"17\\n0 1 3 5 7 9 11 13 15 \", \"15\\n0 1 3 5 7 9 11 13 \", \"13\\n0 1 3 5 7 9 11 \", \"11\\n0 1 3 5 7 9 \", \"9\\n0 1 3 5 7 \", \"7\\n0 1 3 5 \", \"5\\n0 1 3 \", \"1\\n2 \", \"0\\n\", \"1\\n3 \", \"2\\n3 \", \"3\\n1 2 \", \"1\\n2 \", \"1\\n1 \", \"0\\n\", \"1\\n4 \", \"2\\n4 \", \"3\\n4 1 \", \"4\\n2 4 \", \"3\\n2 3 \", \"3\\n1 3 \", \"3\\n0 3 \", \"1\\n3 \", \"2\\n3 \", \"3\\n1 2 \", \"3\\n0 2 \", \"1\\n2 \", \"2\\n2 \", \"1\\n1 \", \"0\\n\", \"1\\n5 \", \"2\\n5 \", \"3\\n5 1 \", \"4\\n2 5 \", \"3\\n5 2 \", \"3\\n5 1 \", \"3\\n7 1 \", \"5\\n5 1 7 \", \"7\\n0 1 3 6 \", \"7\\n9 0 2 4 \", \"11\\n0 1 3 7 8 10 \", \"11\\n0 1 3 5 8 11 \", \"13\\n0 1 3 6 7 10 12 \", \"7\\n7 0 2 4 \", \"9\\n0 1 3 10 11 \", \"13\\n16 0 2 4 6 11 13 \", \"15\\n0 1 3 6 8 9 13 16 \", \"13\\n15 0 2 4 8 12 17 \", \"3\\n19 7 \", \"5\\n19 0 14 \", \"5\\n18 2 13 \", \"9\\n5 0 7 19 9 \", \"9\\n2 5 7 19 9 \", \"13\\n19 2 5 7 9 11 16 \", \"11\\n7 9 10 12 14 17 \", \"15\\n0 1 4 5 8 19 11 14 \", \"11\\n1 2 7 15 9 17 \", \"15\\n0 1 5 14 9 11 19 16 \", \"13\\n1 2 8 5 12 14 17 \", \"11\\n3 0 11 8 13 18 \", \"9\\n4 0 13 14 18 \", \"11\\n0 5 10 13 16 17 \", \"9\\n0 3 9 14 18 \", \"7\\n0 14 16 18 \", \"5\\n0 11 17 \"]}", "source": "primeintellect"}
|
Cat Furrier Transform is a popular algorithm among cat programmers to create longcats. As one of the greatest cat programmers ever exist, Neko wants to utilize this algorithm to create the perfect longcat.
Assume that we have a cat with a number $x$. A perfect longcat is a cat with a number equal $2^m - 1$ for some non-negative integer $m$. For example, the numbers $0$, $1$, $3$, $7$, $15$ and so on are suitable for the perfect longcats.
In the Cat Furrier Transform, the following operations can be performed on $x$: (Operation A): you select any non-negative integer $n$ and replace $x$ with $x \oplus (2^n - 1)$, with $\oplus$ being a bitwise XOR operator. (Operation B): replace $x$ with $x + 1$.
The first applied operation must be of type A, the second of type B, the third of type A again, and so on. Formally, if we number operations from one in the order they are executed, then odd-numbered operations must be of type A and the even-numbered operations must be of type B.
Neko wants to produce perfect longcats at industrial scale, thus for each cat Neko only wants to perform at most $40$ operations. Can you help Neko writing a transformation plan?
Note that it is not required to minimize the number of operations. You just need to use no more than $40$ operations.
-----Input-----
The only line contains a single integer $x$ ($1 \le x \le 10^6$).
-----Output-----
The first line should contain a single integer $t$ ($0 \le t \le 40$) — the number of operations to apply.
Then for each odd-numbered operation print the corresponding number $n_i$ in it. That is, print $\lceil \frac{t}{2} \rceil$ integers $n_i$ ($0 \le n_i \le 30$), denoting the replacement $x$ with $x \oplus (2^{n_i} - 1)$ in the corresponding step.
If there are multiple possible answers, you can print any of them. It is possible to show, that there is at least one answer in the constraints of this problem.
-----Examples-----
Input
39
Output
4
5 3
Input
1
Output
0
Input
7
Output
0
-----Note-----
In the first test, one of the transforms might be as follows: $39 \to 56 \to 57 \to 62 \to 63$. Or more precisely: Pick $n = 5$. $x$ is transformed into $39 \oplus 31$, or $56$. Increase $x$ by $1$, changing its value to $57$. Pick $n = 3$. $x$ is transformed into $57 \oplus 7$, or $62$. Increase $x$ by $1$, changing its value to $63 = 2^6 - 1$.
In the second and third test, the number already satisfies the goal requirement.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4 10 13 10 3 1\\n\", \"1 4 6 2 2 1\\n\", \"3 10 15 17 9 2\\n\", \"4 9 30 3 3 1\\n\", \"4 9 13 2 3 1\\n\", \"4 9 13 1 1 1\\n\", \"1 9 10 6 6 3\\n\", \"4 9 24 10 3 1\\n\", \"4 9 20 10 3 1\\n\", \"1 8 10 8 3 3\\n\", \"2 9 10 4 6 3\\n\", \"2 9 10 6 3 3\\n\", \"1 9 10 7 3 3\\n\", \"1 9 10 9 5 3\\n\", \"2 9 10 6 5 3\\n\", \"1 9 10 5 5 3\\n\", \"2 9 10 9 3 3\\n\", \"1 9 10 9 5 3\\n\", \"1 8 10 3 3 3\\n\", \"1 9 10 5 5 3\\n\", \"2 9 10 5 3 3\\n\", \"2 9 10 8 5 3\\n\", \"2 9 10 9 5 3\\n\", \"1 9 10 4 5 3\\n\", \"1 8 10 5 5 3\\n\", \"2 9 10 9 5 3\\n\", \"15 30 100 8 8 5\\n\", \"15 30 100 58 81 5\\n\", \"15 30 100 601 76 5\\n\", \"15 30 100 7193 39 5\\n\", \"15 30 100 40766 18 5\\n\", \"15 30 100 243890 31 5\\n\", \"4 9 30 10 3 1\\n\", \"56 90 100 9 56 9\\n\", \"29 62 100 88 37 9\\n\", \"712 950 1000 98 727 92\\n\", \"7788 8844 10000 70 4902 63\\n\", \"49 67 100 986 29 7\\n\", \"190 212 1000 103 795 3\\n\", \"5234 7681 10000 985 8825 847\\n\", \"94603 96309 100000 728 25633 556\\n\", \"30 73 100 5089 24 9\\n\", \"330 357 1000 625 129 8\\n\", \"5010 6384 10000 9022 3213 187\\n\", \"7 17 100 56205 62 2\\n\", \"626 705 1000 10072 858 35\\n\", \"1727 5232 10000 67443 5399 62\\n\", \"10995 85967 100000 47813 44507 2442\\n\", \"845391 929573 1000000 87612 108825 1400\\n\", \"78 90 100 535782 61 4\\n\", \"2846 8620 10000 466361 3155 1292\\n\", \"138623 763216 1000000 366229 316563 160243\\n\", \"111724 287004 931554 512877 139642 23002\\n\", \"70276 182564 238201 222757 154128 55592\\n\", \"65775 300705 686095 383961 189161 72083\\n\", \"303226 381701 395142 301908 2696 244\\n\", \"451924 493579 637450 231345 530245 20087\\n\", \"67933 96355 131374 588846 12918 4897\\n\", \"149195 164613 287623 72041 223411 5390\\n\", \"448887 492030 560100 388288 354938 20867\\n\", \"435582 479389 540004 905521 413521 1624\\n\", \"64887 100252 122962 146510 74262 15718\\n\", \"246310 320553 585881 278070 443362 23788\\n\", \"154137 199509 247827 186170 112705 19967\\n\", \"652284 765064 966501 110259 224662 46292\\n\", \"1437 1945 9737 17190 7829 114\\n\", \"61880 74283 78517 551852 20330 1475\\n\", \"196112 214848 221935 465535 132387 3661\\n\", \"20296 469893 481654 239118 236770 20582\\n\", \"476636 647171 684372 48498 122589 5636\\n\", \"140 149 150 13 78 3\\n\", \"140 149 150 16 36 3\\n\", \"140 149 150 13 134 3\\n\", \"140 149 150 11 76 3\\n\", \"1400 1490 1500 78 292 40\\n\", \"1400 1490 1500 89 829 40\\n\", \"1400 1490 1500 75 585 40\\n\", \"1400 1490 1500 67 240 40\\n\", \"1400 1490 1500 64 276 40\\n\", \"1400 1490 1500 43 926 40\\n\", \"1400 1490 1500 83 1362 40\\n\", \"140 149 150 18 80 3\\n\", \"4 9 25 10 3 1\\n\"], \"outputs\": [\"4.3750000000\\n\", \"-1\\n\", \"11.3333333333\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"4.5000000000\\n\", \"4.7368421053\\n\", \"4.6666666667\\n\", \"3.4285714286\\n\", \"2.6666666667\\n\", \"-1\\n\", \"3.0000000000\\n\", \"5.4000000000\\n\", \"3.0000000000\\n\", \"3.0000000000\\n\", \"3.0000000000\\n\", \"5.4000000000\\n\", \"-1\\n\", \"3.0000000000\\n\", \"-1\\n\", \"4.0000000000\\n\", \"4.5000000000\\n\", \"2.4000000000\\n\", \"-1\\n\", \"4.5000000000\\n\", \"-1\\n\", \"48.8764044944\\n\", \"479.5212765957\\n\", \"4118.1297709924\\n\", \"20114.8026315789\\n\", \"131595.3237410072\\n\", \"-1\\n\", \"-1\\n\", \"43.5887850467\\n\", \"-1\\n\", \"-1\\n\", \"361.2079207921\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"2223.7647058824\\n\", \"-1\\n\", \"3713.0485021398\\n\", \"40017.9600000000\\n\", \"7449.8491484185\\n\", \"43315.9683953342\\n\", \"29321.4167104074\\n\", \"12769.2918746832\\n\", \"153080.5714285714\\n\", \"210537.3673812111\\n\", \"-1\\n\", \"257255.6532044368\\n\", \"-1\\n\", \"-1\\n\", \"57074.3018919422\\n\", \"-1\\n\", \"188927.5585923950\\n\", \"-1\\n\", \"-1\\n\", \"405317.7264116302\\n\", \"65461.4966203183\\n\", \"197686.6564327557\\n\", \"-1\\n\", \"-1\\n\", \"14064.2286640989\\n\", \"107291.2729442180\\n\", \"82508.1717726175\\n\", \"155898.4832985775\\n\", \"12660.0741578319\\n\", \"-1\\n\", \"-1\\n\", \"3.0588235294\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\"]}", "source": "primeintellect"}
|
It's a beautiful April day and Wallace is playing football with his friends. But his friends do not know that Wallace actually stayed home with Gromit and sent them his robotic self instead. Robo-Wallace has several advantages over the other guys. For example, he can hit the ball directly to the specified point. And yet, the notion of a giveaway is foreign to him. The combination of these features makes the Robo-Wallace the perfect footballer — as soon as the ball gets to him, he can just aim and hit the goal. He followed this tactics in the first half of the match, but he hit the goal rarely. The opposing team has a very good goalkeeper who catches most of the balls that fly directly into the goal. But Robo-Wallace is a quick thinker, he realized that he can cheat the goalkeeper. After all, they are playing in a football box with solid walls. Robo-Wallace can kick the ball to the other side, then the goalkeeper will not try to catch the ball. Then, if the ball bounces off the wall and flies into the goal, the goal will at last be scored.
Your task is to help Robo-Wallace to detect a spot on the wall of the football box, to which the robot should kick the ball, so that the ball bounces once and only once off this wall and goes straight to the goal. In the first half of the match Robo-Wallace got a ball in the head and was severely hit. As a result, some of the schemes have been damaged. Because of the damage, Robo-Wallace can only aim to his right wall (Robo-Wallace is standing with his face to the opposing team's goal).
The football box is rectangular. Let's introduce a two-dimensional coordinate system so that point (0, 0) lies in the lower left corner of the field, if you look at the box above. Robo-Wallace is playing for the team, whose goal is to the right. It is an improvised football field, so the gate of Robo-Wallace's rivals may be not in the middle of the left wall. [Image]
In the given coordinate system you are given: y_1, y_2 — the y-coordinates of the side pillars of the goalposts of robo-Wallace's opponents; y_{w} — the y-coordinate of the wall to which Robo-Wallace is aiming; x_{b}, y_{b} — the coordinates of the ball's position when it is hit; r — the radius of the ball.
A goal is scored when the center of the ball crosses the OY axis in the given coordinate system between (0, y_1) and (0, y_2). The ball moves along a straight line. The ball's hit on the wall is perfectly elastic (the ball does not shrink from the hit), the angle of incidence equals the angle of reflection. If the ball bounces off the wall not to the goal, that is, if it hits the other wall or the goal post, then the opposing team catches the ball and Robo-Wallace starts looking for miscalculation and gets dysfunctional. Such an outcome, if possible, should be avoided. We assume that the ball touches an object, if the distance from the center of the ball to the object is no greater than the ball radius r.
-----Input-----
The first and the single line contains integers y_1, y_2, y_{w}, x_{b}, y_{b}, r (1 ≤ y_1, y_2, y_{w}, x_{b}, y_{b} ≤ 10^6; y_1 < y_2 < y_{w}; y_{b} + r < y_{w}; 2·r < y_2 - y_1).
It is guaranteed that the ball is positioned correctly in the field, doesn't cross any wall, doesn't touch the wall that Robo-Wallace is aiming at. The goal posts can't be located in the field corners.
-----Output-----
If Robo-Wallace can't score a goal in the described manner, print "-1" (without the quotes). Otherwise, print a single number x_{w} — the abscissa of his point of aiming.
If there are multiple points of aiming, print the abscissa of any of them. When checking the correctness of the answer, all comparisons are made with the permissible absolute error, equal to 10^{ - 8}.
It is recommended to print as many characters after the decimal point as possible.
-----Examples-----
Input
4 10 13 10 3 1
Output
4.3750000000
Input
1 4 6 2 2 1
Output
-1
Input
3 10 15 17 9 2
Output
11.3333333333
-----Note-----
Note that in the first and third samples other correct values of abscissa x_{w} are also possible.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"hi\\nbob\\n\", \"abca\\naccepted\\n\", \"abacaba\\nabcdcba\\n\", \"lo\\neuhaqdhhzlnkmqnakgwzuhurqlpmdm\\n\", \"aaeojkdyuilpdvyewjfrftkpcobhcumwlaoiocbfdtvjkhgda\\nmlmarpivirqbxcyhyerjoxlslyfzftrylpjyouypvk\\n\", \"npnkmawey\\nareakefvowledfriyjejqnnaeqheoh\\n\", \"fdtffutxkujflswyddvhusfcook\\nkavkhnhphcvckogqqqqhdmgwjdfenzizrebefsbuhzzwhzvc\\n\", \"abacaba\\naa\\n\", \"edbcd\\nd\\n\", \"abc\\nksdksdsdsnabc\\n\", \"abxzxzxzzaba\\naba\\n\", \"abcd\\nzzhabcd\\n\", \"aa\\naa\\n\", \"test\\nt\\n\", \"aa\\na\\n\", \"aaaabbbbaaaa\\naba\\n\", \"aa\\nzzaa\\n\", \"zhbt\\nztjihmhebkrztefpwty\\n\", \"aaaaaaaaaaaaaaaaaaaa\\naaaaaaaa\\n\", \"abba\\naba\\n\", \"abbba\\naba\\n\", \"aaaaaaaaaaaa\\naaaaaaaaaaaa\\n\", \"aaa\\naa\\n\", \"aaaaaaaaaaaa\\naaa\\n\", \"aaaaabbbbbbaaaaaa\\naba\\n\", \"ashfaniosafapisfasipfaspfaspfaspfapsfjpasfshvcmvncxmvnxcvnmcxvnmxcnvmcvxvnxmcvxcmvh\\nashish\\n\", \"a\\na\\n\", \"aaaab\\naab\\n\", \"aaaaa\\naaaa\\n\", \"a\\naaa\\n\", \"aaaaaabbbbbbaaaaaa\\naba\\n\", \"def\\nabcdef\\n\", \"aaaaaaaaa\\na\\n\", \"bababsbs\\nabs\\n\", \"hddddddack\\nhackyz\\n\", \"aba\\na\\n\", \"ofih\\nihfsdf\\n\", \"b\\nabb\\n\", \"lctsczqr\\nqvkp\\n\", \"dedcbaa\\ndca\\n\", \"haddack\\nhack\\n\", \"abcabc\\nabc\\n\", \"asdf\\ngasdf\\n\", \"abab\\nab\\n\", \"aaaaaaa\\naaa\\n\", \"asdf\\nfasdf\\n\", \"bbaabb\\nab\\n\", \"accac\\nbaacccbcccabaabbcacbbcccacbaabaaac\\n\", \"az\\naaazazaa\\n\", \"bbacaabbaaa\\nacaabcaa\\n\", \"c\\ncbcbcbbacacacbccaaccbcabaaabbaaa\\n\", \"bacb\\nccacacbacbccbbccccaccccccbcbabbbaababa\\n\", \"ac\\naacacaacbaaacbbbabacaca\\n\", \"a\\nzazaa\\n\", \"abcd\\nfaaaabbbbccccdddeda\\n\", \"abcde\\nfabcde\\n\", \"a\\nab\\n\", \"ababbbbbbbbbbbb\\nabbbbb\\n\", \"bbbbaabbababbaaaaababbaaabbbbaaabbbababbbbabaabababaabaaabbbabababbbabababaababaaaaa\\nbbabaaaabaaaabbaaabbbabaaabaabbbababbbbbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\\n\", \"ab\\naba\\n\", \"aa\\naaaa\\n\", \"aaaaabbbaaaaa\\naabbaa\\n\", \"aaaaaaaaa\\naaaa\\n\", \"abbcc\\naca\\n\", \"b\\ncb\\n\", \"aac\\naaa\\n\", \"ba\\nbb\\n\", \"a\\nb\\n\", \"gkvubrvpbhsfiuyha\\nihotmn\\n\", \"ccccabccbb\\ncbbabcc\\n\", \"babababbaaabb\\nabbab\\n\", \"njtdhyqundyedsjyvy\\nypjrs\\n\", \"uglyqhkpruxoakm\\ncixxkpaaoodpuuh\\n\", \"a\\naaaaaaaaa\\n\", \"aaa\\naaaaa\\n\", \"abcabbcbcccbccbbcc\\nacbcaabbbbcabbbaca\\n\", \"caacacaacbaa\\nacbbbabacacac\\n\", \"aa\\naaab\\n\", \"acbc\\ncacacbac\\n\", \"bacbcaacabbaacb\\ncbbaaccccbcaacacaabb\\n\", \"baababaaaab\\nbaababbbbbbb\\n\", \"aaxyaba\\naaba\\n\"], \"outputs\": [\"-\\n\", \"ac\\n\", \"abcba\\n\", \"-\\n\", \"ouypvk\\n\", \"a\\n\", \"kvc\\n\", \"aa\\n\", \"d\\n\", \"abc\\n\", \"aba\\n\", \"abcd\\n\", \"aa\\n\", \"t\\n\", \"a\\n\", \"aba\\n\", \"aa\\n\", \"zt\\n\", \"aaaaaaaa\\n\", \"aba\\n\", \"aba\\n\", \"aaaaaaaaaaaa\\n\", \"aa\\n\", \"aaa\\n\", \"aba\\n\", \"ashish\\n\", \"a\\n\", \"aab\\n\", \"aaaa\\n\", \"a\\n\", \"aba\\n\", \"def\\n\", \"a\\n\", \"abs\\n\", \"hack\\n\", \"a\\n\", \"ih\\n\", \"b\\n\", \"q\\n\", \"dca\\n\", \"hack\\n\", \"abc\\n\", \"asdf\\n\", \"ab\\n\", \"aaa\\n\", \"asdf\\n\", \"ab\\n\", \"aac\\n\", \"a\\n\", \"acaabaa\\n\", \"c\\n\", \"ba\\n\", \"a\\n\", \"a\\n\", \"a\\n\", \"abcde\\n\", \"a\\n\", \"abbbbb\\n\", \"bbbbbbbabbababbaababbbaaabababababbbbaaababaaaaab\\n\", \"ab\\n\", \"aa\\n\", \"aabbaa\\n\", \"aaaa\\n\", \"ac\\n\", \"b\\n\", \"aa\\n\", \"b\\n\", \"-\\n\", \"ih\\n\", \"cabcc\\n\", \"abbab\\n\", \"ys\\n\", \"uh\\n\", \"a\\n\", \"aaa\\n\", \"acbc\\n\", \"aacacac\\n\", \"aa\\n\", \"ac\\n\", \"cbcaabb\\n\", \"baababb\\n\", \"aaba\\n\"]}", "source": "primeintellect"}
|
You are given two strings a and b. You have to remove the minimum possible number of consecutive (standing one after another) characters from string b in such a way that it becomes a subsequence of string a. It can happen that you will not need to remove any characters at all, or maybe you will have to remove all of the characters from b and make it empty.
Subsequence of string s is any such string that can be obtained by erasing zero or more characters (not necessarily consecutive) from string s.
-----Input-----
The first line contains string a, and the second line — string b. Both of these strings are nonempty and consist of lowercase letters of English alphabet. The length of each string is no bigger than 10^5 characters.
-----Output-----
On the first line output a subsequence of string a, obtained from b by erasing the minimum number of consecutive characters.
If the answer consists of zero characters, output «-» (a minus sign).
-----Examples-----
Input
hi
bob
Output
-
Input
abca
accepted
Output
ac
Input
abacaba
abcdcba
Output
abcba
-----Note-----
In the first example strings a and b don't share any symbols, so the longest string that you can get is empty.
In the second example ac is a subsequence of a, and at the same time you can obtain it by erasing consecutive symbols cepted from string b.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.625
|
{"tests": "{\"inputs\": [\"4\\n0 1 1 0\\n\", \"2\\n1 1\\n\", \"1\\n0\\n\", \"4\\n0 0 0 0\\n\", \"6\\n0 0 0 0 0 1\\n\", \"20\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n\", \"20\\n1 1 1 0 1 0 1 1 0 1 1 1 0 1 0 0 1 1 0 0\\n\", \"1\\n1\\n\", \"2\\n0 0\\n\", \"2\\n0 1\\n\", \"2\\n1 0\\n\", \"3\\n0 0 0\\n\", \"3\\n0 0 1\\n\", \"3\\n0 1 0\\n\", \"3\\n0 1 1\\n\", \"3\\n1 0 0\\n\", \"3\\n1 0 1\\n\", \"3\\n1 1 0\\n\", \"3\\n1 1 1\\n\", \"4\\n0 0 0 1\\n\", \"4\\n0 0 1 0\\n\", \"4\\n0 0 1 1\\n\", \"4\\n0 1 0 0\\n\", \"4\\n0 1 0 1\\n\", \"4\\n0 1 1 1\\n\", \"4\\n1 0 0 0\\n\", \"4\\n1 0 0 1\\n\", \"4\\n1 0 1 0\\n\", \"4\\n1 0 1 1\\n\", \"4\\n1 1 0 0\\n\", \"4\\n1 1 0 1\\n\", \"4\\n1 1 1 0\\n\", \"4\\n1 1 1 1\\n\", \"5\\n0 0 0 0 0\\n\", \"5\\n0 0 0 0 1\\n\", \"5\\n0 0 0 1 0\\n\", \"5\\n0 0 0 1 1\\n\", \"5\\n0 0 1 0 0\\n\", \"5\\n0 0 1 0 1\\n\", \"5\\n0 0 1 1 0\\n\", \"5\\n0 0 1 1 1\\n\", \"5\\n0 1 0 0 0\\n\", \"5\\n0 1 0 0 1\\n\", \"5\\n0 1 0 1 0\\n\", \"5\\n0 1 0 1 1\\n\", \"5\\n0 1 1 0 0\\n\", \"5\\n0 1 1 0 1\\n\", \"5\\n0 1 1 1 0\\n\", \"5\\n0 1 1 1 1\\n\", \"5\\n1 0 0 0 0\\n\", \"5\\n1 0 0 0 1\\n\", \"5\\n1 0 0 1 0\\n\", \"5\\n1 0 0 1 1\\n\", \"5\\n1 0 1 0 0\\n\", \"5\\n1 0 1 0 1\\n\", \"5\\n1 0 1 1 0\\n\", \"5\\n1 0 1 1 1\\n\", \"5\\n1 1 0 0 0\\n\", \"5\\n1 1 0 0 1\\n\", \"5\\n1 1 0 1 0\\n\", \"5\\n1 1 0 1 1\\n\", \"5\\n1 1 1 0 0\\n\", \"5\\n1 1 1 0 1\\n\", \"5\\n1 1 1 1 0\\n\", \"5\\n1 1 1 1 1\\n\", \"6\\n1 1 1 1 0 0\\n\", \"6\\n0 1 1 1 0 0\\n\", \"6\\n1 1 1 0 0 0\\n\", \"6\\n0 0 0 0 0 0\\n\", \"6\\n1 0 0 1 0 0\\n\", \"6\\n1 0 1 1 0 0\\n\", \"6\\n0 0 1 1 0 0\\n\", \"6\\n0 0 0 1 0 0\\n\", \"6\\n0 0 1 0 0 0\\n\", \"200\\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 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\\n\", \"40\\n1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\\n\", \"40\\n0 0 1 0 0 0 0 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\\n\", \"40\\n0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0\\n\", \"40\\n1 1 0 1 0 1 1 1 1 1 0 1 0 0 1 1 1 0 0 0 0 1 1 1 1 1 0 1 0 0 0 1 0 1 0 0 1 0 0 0\\n\", \"45\\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\\n\", \"20\\n1 1 1 1 1 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0\\n\"], \"outputs\": [\"YES\\n0->1->1->0\\n\", \"NO\\n\", \"YES\\n0\\n\", \"YES\\n0->(0->0)->0\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1->1->1->0->1->0->1->1->0->1->1->1->0->1->0->(0->(1->1->0))->0\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1->0\\n\", \"YES\\n(0->0)->0\\n\", \"NO\\n\", \"YES\\n0->1->0\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1->1->0\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n0->0->1->0\\n\", \"NO\\n\", \"YES\\n(0->(1->0))->0\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1->(0->0)->0\\n\", \"NO\\n\", \"YES\\n1->0->1->0\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1->1->1->0\\n\", \"NO\\n\", \"YES\\n0->0->(0->0)->0\\n\", \"NO\\n\", \"YES\\n0->0->0->1->0\\n\", \"NO\\n\", \"YES\\n0->(0->(1->0))->0\\n\", \"NO\\n\", \"YES\\n0->0->1->1->0\\n\", \"NO\\n\", \"YES\\n0->1->(0->0)->0\\n\", \"NO\\n\", \"YES\\n0->1->0->1->0\\n\", \"NO\\n\", \"YES\\n(0->(1->1->0))->0\\n\", \"NO\\n\", \"YES\\n0->1->1->1->0\\n\", \"NO\\n\", \"YES\\n1->0->(0->0)->0\\n\", \"NO\\n\", \"YES\\n1->0->0->1->0\\n\", \"NO\\n\", \"YES\\n1->(0->(1->0))->0\\n\", \"NO\\n\", \"YES\\n1->0->1->1->0\\n\", \"NO\\n\", \"YES\\n1->1->(0->0)->0\\n\", \"NO\\n\", \"YES\\n1->1->0->1->0\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1->1->1->1->0\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n(0->(1->1->1->0))->0\\n\", \"YES\\n1->1->1->(0->0)->0\\n\", \"YES\\n0->0->0->(0->0)->0\\n\", \"YES\\n1->0->(0->(1->0))->0\\n\", \"YES\\n1->(0->(1->1->0))->0\\n\", \"YES\\n0->(0->(1->1->0))->0\\n\", \"YES\\n0->0->(0->(1->0))->0\\n\", \"YES\\n0->0->1->(0->0)->0\\n\", \"NO\\n\", \"YES\\n1->0->1->0->1->0->1->(0->(1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->0))->0\\n\", \"YES\\n0->0->1->0->0->0->0->0->0->1->1->0->1->0->1->0->1->(0->(1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->0))->0\\n\", \"YES\\n(0->(1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->1->0))->0\\n\", \"YES\\n1->1->0->1->0->1->1->1->1->1->0->1->0->0->1->1->1->0->0->0->0->1->1->1->1->1->0->1->0->0->0->1->0->1->0->0->1->(0->0)->0\\n\", \"YES\\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\\n\", \"YES\\n1->1->1->1->1->0->0->0->0->0->1->1->1->1->1->0->0->(0->0)->0\\n\"]}", "source": "primeintellect"}
|
Implication is a function of two logical arguments, its value is false if and only if the value of the first argument is true and the value of the second argument is false.
Implication is written by using character '$\rightarrow$', and the arguments and the result of the implication are written as '0' (false) and '1' (true). According to the definition of the implication:
$0 \rightarrow 0 = 1$
$0 \rightarrow 1 = 1$
$1 \rightarrow 0 = 0$
$1 \rightarrow 1 = 1$
When a logical expression contains multiple implications, then when there are no brackets, it will be calculated from left to fight. For example,
$0 \rightarrow 0 \rightarrow 0 =(0 \rightarrow 0) \rightarrow 0 = 1 \rightarrow 0 = 0$.
When there are brackets, we first calculate the expression in brackets. For example,
$0 \rightarrow(0 \rightarrow 0) = 0 \rightarrow 1 = 1$.
For the given logical expression $a_{1} \rightarrow a_{2} \rightarrow a_{3} \rightarrow \cdots \cdots a_{n}$ determine if it is possible to place there brackets so that the value of a logical expression is false. If it is possible, your task is to find such an arrangement of brackets.
-----Input-----
The first line contains integer n (1 ≤ n ≤ 100 000) — the number of arguments in a logical expression.
The second line contains n numbers a_1, a_2, ..., a_{n} ($a_{i} \in \{0,1 \}$), which means the values of arguments in the expression in the order they occur.
-----Output-----
Print "NO" (without the quotes), if it is impossible to place brackets in the expression so that its value was equal to 0.
Otherwise, print "YES" in the first line and the logical expression with the required arrangement of brackets in the second line.
The expression should only contain characters '0', '1', '-' (character with ASCII code 45), '>' (character with ASCII code 62), '(' and ')'. Characters '-' and '>' can occur in an expression only paired like that: ("->") and represent implication. The total number of logical arguments (i.e. digits '0' and '1') in the expression must be equal to n. The order in which the digits follow in the expression from left to right must coincide with a_1, a_2, ..., a_{n}.
The expression should be correct. More formally, a correct expression is determined as follows: Expressions "0", "1" (without the quotes) are correct. If v_1, v_2 are correct, then v_1->v_2 is a correct expression. If v is a correct expression, then (v) is a correct expression.
The total number of characters in the resulting expression mustn't exceed 10^6.
If there are multiple possible answers, you are allowed to print any of them.
-----Examples-----
Input
4
0 1 1 0
Output
YES
(((0)->1)->(1->0))
Input
2
1 1
Output
NO
Input
1
0
Output
YES
0
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"13\\n8380011223344\\n\", \"15\\n807345619350641\\n\", \"19\\n8181818181111111111\\n\", \"29\\n88811188118181818118111111111\\n\", \"15\\n980848088815548\\n\", \"13\\n9999999998888\\n\", \"13\\n0000008888888\\n\", \"13\\n2480011223348\\n\", \"17\\n87879887989788999\\n\", \"21\\n123456788888812378910\\n\", \"15\\n008880000000000\\n\", \"15\\n888888888888888\\n\", \"15\\n118388111881111\\n\", \"13\\n8489031863524\\n\", \"17\\n88818818888888888\\n\", \"13\\n8899989999989\\n\", \"13\\n1111111111188\\n\", \"13\\n4366464181897\\n\", \"21\\n888888888888888888888\\n\", \"15\\n778887777777777\\n\", \"13\\n8830011223344\\n\", \"13\\n8888888888848\\n\", \"13\\n1181111111111\\n\", \"13\\n8000000000000\\n\", \"13\\n1885498606803\\n\", \"15\\n008888888888808\\n\", \"15\\n961618782888818\\n\", \"13\\n8789816534772\\n\", \"13\\n8898173131489\\n\", \"13\\n8800000000000\\n\", \"13\\n2808118288444\\n\", \"15\\n880000000000000\\n\", \"13\\n8086296018422\\n\", \"13\\n1841516902093\\n\", \"31\\n0088888888888880000000000088888\\n\", \"13\\n8559882884055\\n\", \"13\\n3348729291920\\n\", \"17\\n00000000088888888\\n\", \"13\\n3388888888888\\n\", \"17\\n11111118888888888\\n\", \"13\\n6831940550586\\n\", \"15\\n008888888888888\\n\", \"13\\n8701234567790\\n\", \"13\\n2822222225888\\n\", \"13\\n0178528856351\\n\", \"13\\n0088888888880\\n\", \"15\\n181888888888888\\n\", \"109\\n8800880880088088880888808880888088800880888088088088888080880000080000800000808008008800080008000888000808880\\n\", \"47\\n08800008800800000088088008800080088800000808008\\n\", \"13\\n2828222222222\\n\", \"95\\n00008080008880080880888888088800008888000888800800000808808800888888088080888808880080808088008\\n\", \"71\\n08880000000000808880808800880000008888808008008080880808088808808888080\\n\", \"41\\n00008080008088080080888088800808808008880\\n\", \"23\\n88338486848889054012825\\n\", \"23\\n11868668827888348121163\\n\", \"13\\n2877892266089\\n\", \"19\\n1845988185966619131\\n\", \"17\\n28681889938480569\\n\", \"19\\n8881328076293351500\\n\", \"13\\n8665978038580\\n\", \"13\\n8896797594523\\n\", \"23\\n79818882846090973951051\\n\", \"19\\n8848893007368770958\\n\", \"21\\n860388889843547436129\\n\", \"13\\n0880080008088\\n\", \"17\\n83130469783251338\\n\", \"13\\n1341126906009\\n\", \"23\\n83848888383730797684584\\n\", \"15\\n488081563941254\\n\", \"21\\n974378875888933268270\\n\", \"13\\n2488666312263\\n\", \"15\\n880082334812345\\n\", \"15\\n348808698904345\\n\", \"15\\n200080200228220\\n\", \"41\\n11111111111111188888888888888812345674901\\n\", \"19\\n5501838801564629168\\n\", \"15\\n000000000000000\\n\", \"23\\n88888888888888888888888\\n\", \"23\\n00000000000000000000000\\n\", \"33\\n888888888880000000000900000000000\\n\"], \"outputs\": [\"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"YES\\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\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\"]}", "source": "primeintellect"}
|
A telephone number is a sequence of exactly $11$ digits such that its first digit is 8.
Vasya and Petya are playing a game. Initially they have a string $s$ of length $n$ ($n$ is odd) consisting of digits. Vasya makes the first move, then players alternate turns. In one move the player must choose a character and erase it from the current string. For example, if the current string 1121, after the player's move it may be 112, 111 or 121. The game ends when the length of string $s$ becomes 11. If the resulting string is a telephone number, Vasya wins, otherwise Petya wins.
You have to determine if Vasya has a winning strategy (that is, if Vasya can win the game no matter which characters Petya chooses during his moves).
-----Input-----
The first line contains one integer $n$ ($13 \le n < 10^5$, $n$ is odd) — the length of string $s$.
The second line contains the string $s$ ($|s| = n$) consisting only of decimal digits.
-----Output-----
If Vasya has a strategy that guarantees him victory, print YES.
Otherwise print NO.
-----Examples-----
Input
13
8380011223344
Output
YES
Input
15
807345619350641
Output
NO
-----Note-----
In the first example Vasya needs to erase the second character. Then Petya cannot erase a character from the remaining string 880011223344 so that it does not become a telephone number.
In the second example after Vasya's turn Petya can erase one character character 8. The resulting string can't be a telephone number, because there is no digit 8 at all.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"hw?ap*yn?eww*ye*ar\\n12\\n\", \"ab?a\\n2\\n\", \"ab?a\\n3\\n\", \"ababb\\n5\\n\", \"ab?a\\n1\\n\", \"z\\n1\\n\", \"n\\n96\\n\", \"c*b*dosavq*gwy*e*j?jx?t?li*m?fik*m*l?i?b?z?kv*wm*u*j?h?o?hg*c*hf?l*n*dl*q*t?bi*m?g*c*k?p*e*di*o?iqfn*sj?k*t?zyqz*ihjpt?a?vr?a*r\\n83\\n\", \"a?u?kb*exg?l*z?xc?gbpbms*vc?ll*u*qy*g*k?k*ky?n?r?qur?m*kyr*gd?o*t*hw*hzk*u*vq*j*v*ag*ljyiu?uy*qqub?y?hbp*zsr*u*m*a?hx*ca*vvn?c\\n55\\n\", \"jkhu?wd?fxtgkrqmqukirdwywr?yk?hmdz?xghwgkr?pkbvsx?xe?l?\\n57\\n\", \"gfkesp?jh?enf?rnu?riyu?mcvtswlzerx?mumzrqh?aqbbdujqwdwezqrsn?hqxpxsq?rh?cqgzxlchgtoyevlrojxovstvo?bw\\n79\\n\", \"s?g?h?e?m?h?i?t?m?e?y?z?r?a?c?r?p?v?f?o?r?z?q?t?s?c?o?z?h?z\\n34\\n\", \"uduzhzchjkaddukfwqngffblohjmqbgyfrzomuznircygatbxoyfxflurhoewioptyqlpoozlksyxrntwsqozghcamszlgeawisninpntpwpuemybjwmhwmpqkurkrnjzfoppmoopwrmpylvhtntghxkavveeyfmdqsvuqiflyemklnshfrtskmyhkbzhwmlaqcasjbw\\n200\\n\", \"gpejouiegzleonpiwdchbwdkjdrqsxvydqjqilapciriackdiamzxvxizagjouqhoagefmildgxxxafuxuingzaosxjzmuwlfpfccjllogrwlfxpacgdgxmqgzguqqmwynmutfpnuigclbsphhimpvsckcnxrvenhvtgegkxemybpluactvv\\n91\\n\", \"wd?t?a?fk?pnuuetr?emvsfrppk?o?emnskin?pn?qyv?d?rs?hvmqtwew?sy?efn?badndz?p?xixeeiofsfqewp?t?f?sgdlcw\\n63\\n\", \"c?dhff?f?y?m?h?i?fj?v?rz?v?bh?m?m?t?x?g?yn?e?a?q?fb?t?k?xvsk?v?i?a?zcrz?f?i?c?ge?jo?g?j?l?suj?u?c?h?\\n15\\n\", \"m?tsw\\n98\\n\", \"z*mt*o?mxh?g\\n11\\n\", \"npra?bhx?rr*w?f*t\\n14\\n\", \"d*b*w?j?n*kc?e?rdp*ca?u*gg?\\n29\\n\", \"zymhgthoob\\n10\\n\", \"flvlowstjhhx\\n6\\n\", \"grzlreuaqtgs\\n12\\n\", \"gqososjozfdbrdlkggisefpuruqcqvstqnfktvysoiauxumctikhwuvdbetvpbzlcqhgsjdzzzgburoayzsdkhfkfdwunmxt\\n94\\n\", \"mxneywurhzffwkfkrcmesdczjpeqgxfttmomdhgwwndudvabntrwegfouthzjrhjqancqgcputqzdvgsqzivuctnpzjbgjdo\\n96\\n\", \"cqbpdkhounszhavfvgjqogwnwblypesjyvjiqxartehljficmjcfvgiwcknmilplixlbcuzifkgxvawlhmzufjgxhkfodihhsguc\\n100\\n\", \"afwugkkewbpehxxokgqrldztdxclciigzqbwipfpbuzmlksbvphclblhslgujqfdyjgwkbakiketyhgnlqroeqecuwxriqmmkuky\\n10\\n\", \"f?\\n1\\n\", \"n?l\\n2\\n\", \"s?l\\n8\\n\", \"u?wp?v?k?yxlp\\n7\\n\", \"mrx?ut?aefu?mr?ivh?kt?jpirdn?cjgpk?s?dd\\n11\\n\", \"u?q?l?x?g?g?u?l?l?f?z?q\\n8\\n\", \"zr\\n7\\n\", \"n*\\n98\\n\", \"w*r\\n15\\n\", \"k*n\\n2\\n\", \"zm*g*ho*mo\\n12\\n\", \"np*lr*lg*br*t*x\\n26\\n\", \"db*wm*zn*k*ibe*w*x*d*f\\n42\\n\", \"aobs*fhm*w*da*u*a*s*b*l*qxnfbv*ct*nmt*x*t*g*n*oni*oo*c*bu*to*eooa*\\n43\\n\", \"n*zc*lb*e*ppp*\\n14\\n\", \"ya*tspfh*qmjmhx*ja*ql*w*i*vt*g*hehet*x*t*j*uo*o*s*p*bv*\\n29\\n\", \"nze*bf*wq*bx*idy*ml*sn*y*cpp*u*cz*v*ht*e*mwlq*izh*p*uq*v*j*r*z*r*n\\n45\\n\", \"cb*dhu*s*hv*vjow*w*lps*y*jq*a*th*j*im*c*vicni*p*i*l*czfg*vw*hzf*g*hfdh*suh*a*f*x*r*j*nlq*t*w*h*imtku\\n9\\n\", \"a*wgkw*ph*xkq*l*z*d*c*cizbi*f*bzls*v*hl*l*s*gjf*y*gk*aie*y*g*lreeux*imkku*rg*c*s*ot*hea*izkos*nqj*va\\n66\\n\", \"w*r?\\n3\\n\", \"k*n?\\n99\\n\", \"gj?g\\n10\\n\", \"h*y?i\\n95\\n\", \"c*vb*a*r\\n12\\n\", \"au*e?f*h?hdza*sp*zxw*i*qc?x?m*t*xf?nciic?a*doi?o?t*q*v?r?hl?r?ol?l?pu*p?m?zz*a*k\\n35\\n\", \"cii*f*hrlorz*a?l\\n17\\n\", \"y?f*sp*f*ha?ji*e?j*ac?w*iag*h*ei*w?xp*d*qol?b*vz*mx?l*n?nxw?n?mu*syi*tb\\n26\\n\", \"n*zj*aw?jx*i*d*yc?srcm?u?w*r?hvmk?qq*g*jud*nrn*ng*x*v?cc*dg*wsnudwejta?pee*kc*x*tz?\\n72\\n\", \"ab*\\n10\\n\", \"a*b?\\n200\\n\", \"aa*a\\n7\\n\", \"a*\\n2\\n\", \"abab*b?\\n3\\n\", \"kek*\\n100\\n\", \"a*\\n20\\n\", \"a*\\n100\\n\", \"a*\\n30\\n\", \"a*\\n3\\n\", \"a*b*c*d*e*f\\n100\\n\", \"ab*cdefghijkl\\n10\\n\", \"a*\\n5\\n\", \"a*\\n10\\n\", \"ab*a\\n10\\n\", \"p*\\n5\\n\", \"a*\\n12\\n\", \"a*\\n4\\n\", \"a?b*\\n12\\n\", \"a*b\\n5\\n\", \"abc*\\n2\\n\", \"aba?a*\\n5\\n\", \"a*a\\n5\\n\", \"h*\\n12\\n\"], \"outputs\": [\"hwapppyewyar\", \"aa\", \"aba\", \"ababb\", \"Impossible\", \"z\", \"Impossible\", \"ccccccccccccccccccccccccccccccccccccccccccccccccccccdosavgwjlfikwhhdbdiqfszyqihjpvr\", \"aukbbbbbbbbbbbbbexxgbpbmvlqkqukyghhzvaljyiuqquhbzshcvvc\", \"Impossible\", \"gfkespjenrnriymcvtswlzermumzrqaqbbdujqwdwezqrshqxpxsrcqgzxlchgtoyevlrojxovstvbw\", \"Impossible\", \"uduzhzchjkaddukfwqngffblohjmqbgyfrzomuznircygatbxoyfxflurhoewioptyqlpoozlksyxrntwsqozghcamszlgeawisninpntpwpuemybjwmhwmpqkurkrnjzfoppmoopwrmpylvhtntghxkavveeyfmdqsvuqiflyemklnshfrtskmyhkbzhwmlaqcasjbw\", \"Impossible\", \"wdtafpnuuetemvsfrppemnskipqyrhvmqtwesefbadndxixeeiofsfqewsgdlcw\", \"Impossible\", \"Impossible\", \"zzzzzzzmmxg\", \"nprabhxrrrrrrt\", \"ddddddddddddddddddddddddkrdcg\", \"zymhgthoob\", \"Impossible\", \"grzlreuaqtgs\", \"Impossible\", \"mxneywurhzffwkfkrcmesdczjpeqgxfttmomdhgwwndudvabntrwegfouthzjrhjqancqgcputqzdvgsqzivuctnpzjbgjdo\", \"cqbpdkhounszhavfvgjqogwnwblypesjyvjiqxartehljficmjcfvgiwcknmilplixlbcuzifkgxvawlhmzufjgxhkfodihhsguc\", \"Impossible\", \"f\", \"nl\", \"Impossible\", \"uwpyxlp\", \"Impossible\", \"uqlxgguq\", \"Impossible\", \"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn\", \"wwwwwwwwwwwwwwr\", \"kn\", \"zmmmmmmmmhmo\", \"npppppppppppppppppppppllbx\", \"dbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbwzibf\", \"aobsssssssssssssssssssssfhdqxnfbcnmonobteoo\", \"nnnnnnnnnnzlpp\", \"yaaaaaaaaaatspfqmjmhjqvheheub\", \"nzeeeeeeeeeeeeeeeeeeeeeeeeebwbidmscpchmwlizun\", \"Impossible\", \"aaaaaaaaaaaaaaaaaaaaaaaaaawgkpxkcizbbzlhgjgailreeuimkkroheizkonqva\", \"www\", \"kkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\", \"Impossible\", \"hhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhi\", \"ccccccccccvr\", \"auuuuuuuuuuuuuuuhdzszxqxnciidohopzk\", \"ciiiiiiiiiihrlorl\", \"yffffffshjaiaexqovmnxmsytb\", \"nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnzajysrchvmqjunrncdwsnudwejtpekt\", \"abbbbbbbbb\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaaaaaa\", \"aa\", \"aba\", \"kekkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk\", \"aaaaaaaaaaaaaaaaaaaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\", \"aaa\", \"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaf\", \"Impossible\", \"aaaaa\", \"aaaaaaaaaa\", \"abbbbbbbba\", \"ppppp\", \"aaaaaaaaaaaa\", \"aaaa\", \"abbbbbbbbbbb\", \"aaaab\", \"ab\", \"abaaa\", \"aaaaa\", \"hhhhhhhhhhhh\"]}", "source": "primeintellect"}
|
Andrey received a postcard from Irina. It contained only the words "Hello, Andrey!", and a strange string consisting of lowercase Latin letters, snowflakes and candy canes. Andrey thought that this string is an encrypted message, and decided to decrypt it.
Andrey noticed that snowflakes and candy canes always stand after the letters, so he supposed that the message was encrypted as follows. Candy cane means that the letter before it can be removed, or can be left. A snowflake means that the letter before it can be removed, left, or repeated several times.
For example, consider the following string: [Image]
This string can encode the message «happynewyear». For this, candy canes and snowflakes should be used as follows: candy cane 1: remove the letter w, snowflake 1: repeat the letter p twice, candy cane 2: leave the letter n, snowflake 2: remove the letter w, snowflake 3: leave the letter e.
[Image]
Please note that the same string can encode different messages. For example, the string above can encode «hayewyar», «happpppynewwwwwyear», and other messages.
Andrey knows that messages from Irina usually have a length of $k$ letters. Help him to find out if a given string can encode a message of $k$ letters, and if so, give an example of such a message.
-----Input-----
The first line contains the string received in the postcard. The string consists only of lowercase Latin letters, as well as the characters «*» and «?», meaning snowflake and candy cone, respectively. These characters can only appear immediately after the letter. The length of the string does not exceed $200$.
The second line contains an integer number $k$ ($1 \leq k \leq 200$), the required message length.
-----Output-----
Print any message of length $k$ that the given string can encode, or «Impossible» if such a message does not exist.
-----Examples-----
Input
hw?ap*yn?eww*ye*ar
12
Output
happynewyear
Input
ab?a
2
Output
aa
Input
ab?a
3
Output
aba
Input
ababb
5
Output
ababb
Input
ab?a
1
Output
Impossible
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1 2 1000\\n\", \"2 2 1000\\n\", \"5 3 1103\\n\", \"2 17 10000\\n\", \"3 9 10000\\n\", \"6 64 941761822\\n\", \"183 3 46847167\\n\", \"472 44 364550669\\n\", \"510 76 811693420\\n\", \"783 30 602209107\\n\", \"863 47 840397713\\n\", \"422 22 411212542\\n\", \"370 9 385481464\\n\", \"312 41 915197716\\n\", \"261 32 49719977\\n\", \"434 6 56571287\\n\", \"355 3 945669623\\n\", \"905 71 999142682\\n\", \"900 84 526417573\\n\", \"387 3 521021345\\n\", \"246 33 996704992\\n\", \"443 29 106807555\\n\", \"621 43 356382217\\n\", \"782 84 643445347\\n\", \"791 23 94030462\\n\", \"543 98 508536403\\n\", \"20 96 238661639\\n\", \"845 60 888437864\\n\", \"998 85 501663165\\n\", \"123 72 56222855\\n\", \"12 39 618421525\\n\", \"462 35 144751085\\n\", \"674 22 494819681\\n\", \"650 66 579060528\\n\", \"432 80 133016247\\n\", \"176 70 196445230\\n\", \"393 71 933802677\\n\", \"37 92 9838905\\n\", \"993 26 108974437\\n\", \"433 93 36915724\\n\", \"957 88 512982771\\n\", \"170 94 82742818\\n\", \"624 33 145653575\\n\", \"56 48 961996131\\n\", \"889 6 225765429\\n\", \"1 93 727895661\\n\", \"470 61 617307737\\n\", \"520 94 712232167\\n\", \"531 78 460047919\\n\", \"776 32 523607700\\n\", \"648 74 329538445\\n\", \"885 6 743810885\\n\", \"712 53 592302770\\n\", \"426 72 589297447\\n\", \"561 69 310141994\\n\", \"604 97 26180786\\n\", \"586 32 846994504\\n\", \"514 67 260591607\\n\", \"429 45 103817253\\n\", \"767 27 364988776\\n\", \"497 33 479662107\\n\", \"262 71 404639692\\n\", \"125 33 152527721\\n\", \"857 98 70814341\\n\", \"375 79 416634034\\n\", \"886 10 902171654\\n\", \"335 28 979397289\\n\", \"769 30 474381420\\n\", \"736 31 26855044\\n\", \"891 7 814335325\\n\", \"346 23 947672082\\n\", \"1000 1 382210711\\n\", \"1 1 10000\\n\", \"1000 100 777767777\\n\", \"1000 13 10619863\\n\", \"1 100 1000\\n\", \"11 11 11\\n\", \"1 1 1\\n\", \"1 2 2\\n\"], \"outputs\": [\"4\", \"45\", \"590\", \"5\", \"252\", \"46530\", \"29891566\", \"122479316\", \"546301720\", \"279682329\", \"433465398\", \"63862621\", \"163845824\", \"912219984\", \"19320923\", \"56257936\", \"219132384\", \"825882209\", \"281234824\", \"435545521\", \"385601286\", \"7872021\", \"251594310\", \"208138038\", \"41862326\", \"117587951\", \"198761428\", \"193926448\", \"145180249\", \"32350599\", \"115875938\", \"79931198\", \"19590614\", \"224930740\", \"25032672\", \"64904804\", \"366541352\", \"7980021\", \"87469631\", \"20722839\", \"161742313\", \"1117330\", \"99048377\", \"199203510\", \"193135878\", \"0\", \"428782123\", \"199435818\", \"117748792\", \"309970800\", \"177655063\", \"297512873\", \"147693148\", \"316207784\", \"245538618\", \"6950800\", \"579729448\", \"88291586\", \"41335161\", \"259490746\", \"84548778\", \"93447345\", \"59122415\", \"58423075\", \"175150318\", \"134375492\", \"675105408\", \"157049322\", \"24225276\", \"611862019\", \"59151110\", \"372462157\", \"9\", \"577920877\", \"8796170\", \"0\", \"7\", \"0\", \"0\"]}", "source": "primeintellect"}
|
Amr doesn't like Maths as he finds it really boring, so he usually sleeps in Maths lectures. But one day the teacher suspected that Amr is sleeping and asked him a question to make sure he wasn't.
First he gave Amr two positive integers n and k. Then he asked Amr, how many integer numbers x > 0 exist such that: Decimal representation of x (without leading zeroes) consists of exactly n digits; There exists some integer y > 0 such that: $y \operatorname{mod} k = 0$; decimal representation of y is a suffix of decimal representation of x.
As the answer to this question may be pretty huge the teacher asked Amr to output only its remainder modulo a number m.
Can you help Amr escape this embarrassing situation?
-----Input-----
Input consists of three integers n, k, m (1 ≤ n ≤ 1000, 1 ≤ k ≤ 100, 1 ≤ m ≤ 10^9).
-----Output-----
Print the required number modulo m.
-----Examples-----
Input
1 2 1000
Output
4
Input
2 2 1000
Output
45
Input
5 3 1103
Output
590
-----Note-----
A suffix of a string S is a non-empty string that can be obtained by removing some number (possibly, zero) of first characters from S.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"4\\n11\\n27\\n27\\n11\\n\", \"2\\n6\\n6\\n\", \"6\\n10\\n20\\n30\\n20\\n10\\n20\\n\", \"6\\n1\\n1\\n2\\n2\\n3\\n3\\n\", \"2\\n1\\n100\\n\", \"2\\n1\\n1\\n\", \"2\\n100\\n100\\n\", \"14\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n\", \"100\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n\", \"2\\n50\\n100\\n\", \"2\\n99\\n100\\n\", \"4\\n4\\n4\\n5\\n5\\n\", \"10\\n10\\n10\\n10\\n10\\n10\\n23\\n23\\n23\\n23\\n23\\n\", \"20\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n11\\n11\\n11\\n11\\n11\\n11\\n11\\n11\\n11\\n11\\n\", \"40\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n20\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n30\\n\", \"58\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"98\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n\", \"100\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n\", \"100\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n\", \"100\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n\", \"100\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n29\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n\", \"100\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n88\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n\", \"100\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n\", \"100\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n\", \"100\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n14\\n\", \"100\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n23\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n21\\n\", \"100\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n\", \"100\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n3\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n\", \"100\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n34\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n\", \"100\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n19\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n32\\n\", \"100\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n85\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n\", \"100\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n43\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n\", \"100\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n96\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n95\\n\", \"100\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n4\\n\", \"100\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n\", \"100\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n87\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n\", \"100\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n13\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n24\\n\", \"100\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n49\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n\", \"100\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n15\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n94\\n\", \"100\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n42\\n\", \"100\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n16\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n35\\n\", \"100\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n33\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n44\\n\", \"100\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n54\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n98\\n\", \"100\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n81\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n\", \"100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n\", \"100\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"40\\n20\\n20\\n30\\n30\\n20\\n20\\n20\\n30\\n30\\n20\\n20\\n30\\n30\\n30\\n30\\n20\\n30\\n30\\n30\\n30\\n20\\n20\\n30\\n30\\n30\\n20\\n30\\n20\\n30\\n20\\n30\\n20\\n20\\n20\\n30\\n20\\n20\\n20\\n30\\n30\\n\", \"58\\n100\\n100\\n100\\n100\\n100\\n1\\n1\\n1\\n1\\n1\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n100\\n1\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n100\\n1\\n1\\n100\\n1\\n1\\n1\\n100\\n1\\n1\\n1\\n1\\n100\\n1\\n100\\n100\\n100\\n100\\n100\\n1\\n1\\n100\\n100\\n100\\n100\\n1\\n100\\n1\\n1\\n1\\n1\\n1\\n\", \"98\\n2\\n99\\n99\\n99\\n99\\n2\\n99\\n99\\n99\\n2\\n2\\n99\\n2\\n2\\n2\\n2\\n99\\n99\\n2\\n99\\n2\\n2\\n99\\n99\\n99\\n99\\n2\\n2\\n99\\n2\\n99\\n99\\n2\\n2\\n99\\n2\\n99\\n2\\n99\\n2\\n2\\n2\\n99\\n2\\n2\\n2\\n2\\n99\\n99\\n99\\n99\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n99\\n2\\n99\\n99\\n2\\n2\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n99\\n2\\n99\\n2\\n99\\n2\\n2\\n2\\n99\\n99\\n99\\n99\\n99\\n99\\n2\\n99\\n99\\n2\\n2\\n2\\n2\\n2\\n99\\n99\\n99\\n2\\n\", \"100\\n100\\n1\\n100\\n1\\n1\\n100\\n1\\n1\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n100\\n1\\n1\\n1\\n100\\n1\\n100\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n1\\n1\\n1\\n1\\n1\\n100\\n1\\n100\\n100\\n100\\n1\\n100\\n100\\n1\\n100\\n1\\n1\\n100\\n100\\n100\\n1\\n100\\n100\\n1\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n1\\n1\\n100\\n100\\n100\\n100\\n100\\n100\\n1\\n100\\n100\\n1\\n100\\n100\\n1\\n100\\n1\\n1\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n1\\n1\\n1\\n1\\n100\\n1\\n1\\n100\\n1\\n100\\n100\\n1\\n100\\n1\\n100\\n\", \"100\\n2\\n2\\n2\\n1\\n1\\n1\\n2\\n2\\n1\\n1\\n1\\n2\\n2\\n1\\n2\\n2\\n1\\n2\\n2\\n1\\n1\\n2\\n1\\n2\\n2\\n2\\n2\\n2\\n1\\n2\\n1\\n2\\n1\\n1\\n2\\n2\\n2\\n1\\n1\\n2\\n2\\n1\\n2\\n1\\n1\\n2\\n1\\n1\\n1\\n2\\n2\\n1\\n2\\n2\\n2\\n1\\n1\\n2\\n1\\n2\\n2\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n2\\n2\\n2\\n1\\n2\\n2\\n2\\n2\\n1\\n1\\n2\\n1\\n1\\n1\\n2\\n1\\n2\\n1\\n1\\n2\\n2\\n2\\n1\\n1\\n1\\n2\\n2\\n2\\n1\\n1\\n2\\n2\\n\", \"100\\n99\\n99\\n100\\n99\\n99\\n100\\n100\\n99\\n99\\n100\\n99\\n100\\n100\\n100\\n100\\n100\\n100\\n99\\n100\\n100\\n99\\n100\\n99\\n100\\n100\\n99\\n99\\n100\\n99\\n100\\n99\\n99\\n100\\n99\\n100\\n100\\n99\\n99\\n100\\n100\\n100\\n100\\n100\\n99\\n100\\n99\\n100\\n99\\n100\\n100\\n100\\n100\\n100\\n100\\n99\\n99\\n99\\n100\\n99\\n99\\n99\\n99\\n99\\n99\\n100\\n100\\n99\\n100\\n100\\n99\\n99\\n100\\n100\\n99\\n100\\n100\\n99\\n100\\n99\\n99\\n100\\n99\\n99\\n100\\n99\\n99\\n100\\n99\\n100\\n99\\n100\\n100\\n99\\n99\\n99\\n100\\n99\\n100\\n100\\n99\\n\", \"100\\n42\\n42\\n42\\n29\\n29\\n42\\n42\\n42\\n29\\n42\\n29\\n29\\n29\\n42\\n29\\n29\\n42\\n29\\n42\\n29\\n42\\n29\\n42\\n42\\n42\\n42\\n29\\n29\\n42\\n29\\n29\\n42\\n29\\n42\\n29\\n42\\n29\\n29\\n42\\n29\\n29\\n42\\n42\\n42\\n29\\n29\\n29\\n29\\n42\\n29\\n29\\n29\\n29\\n29\\n29\\n42\\n42\\n29\\n42\\n29\\n42\\n42\\n29\\n29\\n29\\n42\\n42\\n29\\n42\\n42\\n42\\n29\\n29\\n42\\n29\\n29\\n29\\n42\\n42\\n29\\n29\\n29\\n42\\n29\\n42\\n42\\n29\\n42\\n42\\n42\\n42\\n42\\n29\\n42\\n29\\n29\\n29\\n29\\n29\\n42\\n\", \"100\\n98\\n98\\n98\\n88\\n88\\n88\\n88\\n98\\n88\\n88\\n88\\n88\\n88\\n98\\n88\\n98\\n88\\n98\\n88\\n98\\n98\\n98\\n98\\n98\\n98\\n88\\n98\\n88\\n88\\n88\\n98\\n88\\n88\\n98\\n88\\n98\\n88\\n98\\n98\\n88\\n98\\n88\\n98\\n98\\n98\\n98\\n88\\n98\\n98\\n88\\n88\\n88\\n88\\n98\\n98\\n98\\n98\\n88\\n98\\n88\\n98\\n98\\n88\\n88\\n98\\n98\\n88\\n88\\n98\\n88\\n98\\n88\\n98\\n88\\n98\\n98\\n88\\n88\\n98\\n98\\n98\\n98\\n88\\n88\\n98\\n98\\n88\\n98\\n88\\n98\\n98\\n88\\n98\\n98\\n88\\n88\\n98\\n88\\n98\\n98\\n\", \"100\\n100\\n100\\n100\\n1\\n100\\n1\\n1\\n1\\n100\\n1\\n1\\n1\\n1\\n100\\n1\\n100\\n1\\n100\\n1\\n100\\n100\\n100\\n1\\n100\\n1\\n1\\n1\\n100\\n1\\n1\\n1\\n1\\n1\\n100\\n100\\n1\\n100\\n1\\n1\\n100\\n1\\n1\\n100\\n1\\n100\\n100\\n100\\n1\\n100\\n100\\n100\\n1\\n100\\n1\\n100\\n100\\n100\\n1\\n1\\n100\\n100\\n100\\n100\\n1\\n100\\n36\\n100\\n1\\n100\\n1\\n100\\n100\\n100\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n100\\n1\\n1\\n100\\n100\\n100\\n100\\n100\\n1\\n100\\n1\\n100\\n1\\n1\\n100\\n100\\n1\\n100\\n\", \"100\\n2\\n1\\n1\\n2\\n2\\n1\\n1\\n1\\n1\\n2\\n1\\n1\\n1\\n2\\n2\\n2\\n1\\n1\\n1\\n2\\n1\\n2\\n2\\n2\\n2\\n1\\n1\\n2\\n1\\n1\\n2\\n1\\n27\\n1\\n1\\n1\\n2\\n2\\n2\\n1\\n2\\n1\\n2\\n1\\n1\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n2\\n1\\n2\\n2\\n2\\n2\\n1\\n2\\n1\\n1\\n1\\n1\\n1\\n2\\n1\\n1\\n1\\n2\\n2\\n2\\n2\\n2\\n2\\n1\\n1\\n1\\n1\\n2\\n2\\n1\\n2\\n2\\n1\\n1\\n1\\n2\\n1\\n2\\n2\\n1\\n1\\n2\\n1\\n1\\n1\\n2\\n2\\n1\\n\", \"100\\n99\\n99\\n100\\n99\\n99\\n100\\n100\\n100\\n99\\n100\\n99\\n99\\n100\\n99\\n99\\n99\\n99\\n99\\n99\\n100\\n100\\n100\\n99\\n100\\n100\\n99\\n100\\n99\\n100\\n100\\n99\\n100\\n99\\n99\\n99\\n100\\n99\\n10\\n99\\n100\\n100\\n100\\n99\\n100\\n100\\n100\\n100\\n100\\n100\\n100\\n99\\n100\\n100\\n100\\n99\\n99\\n100\\n99\\n100\\n99\\n100\\n100\\n99\\n99\\n99\\n99\\n100\\n99\\n100\\n100\\n100\\n100\\n100\\n100\\n99\\n99\\n100\\n100\\n99\\n99\\n99\\n99\\n99\\n99\\n100\\n99\\n99\\n100\\n100\\n99\\n100\\n99\\n99\\n100\\n99\\n99\\n99\\n99\\n100\\n100\\n\", \"100\\n29\\n43\\n43\\n29\\n43\\n29\\n29\\n29\\n43\\n29\\n29\\n29\\n29\\n43\\n29\\n29\\n29\\n29\\n43\\n29\\n29\\n29\\n43\\n29\\n29\\n29\\n43\\n43\\n43\\n43\\n43\\n43\\n29\\n29\\n43\\n43\\n43\\n29\\n43\\n43\\n43\\n29\\n29\\n29\\n43\\n29\\n29\\n29\\n43\\n43\\n43\\n43\\n29\\n29\\n29\\n29\\n43\\n29\\n43\\n43\\n29\\n29\\n43\\n43\\n29\\n29\\n95\\n29\\n29\\n29\\n43\\n43\\n29\\n29\\n29\\n29\\n29\\n43\\n43\\n43\\n43\\n29\\n29\\n43\\n43\\n43\\n43\\n43\\n43\\n29\\n43\\n43\\n43\\n43\\n43\\n43\\n29\\n43\\n29\\n43\\n\", \"100\\n98\\n98\\n98\\n88\\n88\\n88\\n88\\n98\\n98\\n88\\n98\\n88\\n98\\n88\\n88\\n88\\n88\\n88\\n98\\n98\\n88\\n98\\n98\\n98\\n88\\n88\\n88\\n98\\n98\\n88\\n88\\n88\\n98\\n88\\n98\\n88\\n98\\n88\\n88\\n98\\n98\\n98\\n88\\n88\\n98\\n98\\n88\\n88\\n88\\n88\\n88\\n98\\n98\\n98\\n88\\n98\\n88\\n88\\n98\\n98\\n88\\n98\\n88\\n88\\n98\\n88\\n88\\n98\\n27\\n88\\n88\\n88\\n98\\n98\\n88\\n88\\n98\\n98\\n98\\n98\\n98\\n88\\n98\\n88\\n98\\n98\\n98\\n98\\n88\\n88\\n98\\n88\\n98\\n88\\n98\\n98\\n88\\n98\\n98\\n88\\n\", \"100\\n50\\n1\\n1\\n50\\n50\\n50\\n50\\n1\\n50\\n100\\n50\\n50\\n50\\n100\\n1\\n100\\n1\\n100\\n50\\n50\\n50\\n50\\n50\\n1\\n50\\n1\\n100\\n1\\n1\\n50\\n100\\n50\\n50\\n100\\n50\\n50\\n100\\n1\\n50\\n50\\n100\\n1\\n1\\n50\\n1\\n100\\n50\\n50\\n100\\n100\\n1\\n100\\n1\\n50\\n100\\n50\\n50\\n1\\n1\\n50\\n100\\n50\\n100\\n100\\n100\\n50\\n50\\n1\\n1\\n50\\n100\\n1\\n50\\n100\\n100\\n1\\n50\\n50\\n50\\n100\\n50\\n50\\n100\\n1\\n50\\n50\\n50\\n50\\n1\\n50\\n50\\n50\\n50\\n1\\n50\\n50\\n100\\n1\\n50\\n100\\n\", \"100\\n45\\n45\\n45\\n45\\n45\\n45\\n44\\n44\\n44\\n43\\n45\\n44\\n44\\n45\\n44\\n44\\n45\\n44\\n43\\n44\\n43\\n43\\n43\\n45\\n43\\n45\\n44\\n45\\n43\\n44\\n45\\n45\\n45\\n45\\n45\\n45\\n45\\n45\\n43\\n45\\n43\\n43\\n45\\n44\\n45\\n45\\n45\\n44\\n45\\n45\\n45\\n45\\n45\\n45\\n44\\n43\\n45\\n45\\n43\\n44\\n45\\n45\\n45\\n45\\n44\\n45\\n45\\n45\\n43\\n43\\n44\\n44\\n43\\n45\\n43\\n45\\n45\\n45\\n44\\n44\\n43\\n43\\n44\\n44\\n44\\n43\\n45\\n43\\n44\\n43\\n45\\n43\\n43\\n45\\n45\\n44\\n45\\n43\\n43\\n45\\n\", \"100\\n12\\n12\\n97\\n15\\n97\\n12\\n15\\n97\\n12\\n97\\n12\\n12\\n97\\n12\\n15\\n12\\n12\\n15\\n12\\n12\\n97\\n12\\n12\\n15\\n15\\n12\\n97\\n15\\n12\\n97\\n15\\n12\\n12\\n15\\n15\\n15\\n97\\n15\\n97\\n12\\n12\\n12\\n12\\n12\\n97\\n12\\n97\\n12\\n15\\n15\\n12\\n15\\n12\\n15\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n12\\n97\\n97\\n12\\n12\\n97\\n12\\n97\\n97\\n15\\n97\\n12\\n97\\n97\\n12\\n12\\n12\\n97\\n97\\n15\\n12\\n12\\n15\\n12\\n15\\n97\\n97\\n12\\n15\\n12\\n12\\n97\\n12\\n15\\n15\\n15\\n15\\n12\\n12\\n\", \"12\\n2\\n3\\n1\\n3\\n3\\n1\\n2\\n1\\n2\\n1\\n3\\n2\\n\", \"48\\n99\\n98\\n100\\n100\\n99\\n100\\n99\\n100\\n100\\n98\\n99\\n98\\n98\\n99\\n98\\n99\\n98\\n100\\n100\\n98\\n100\\n98\\n99\\n100\\n98\\n99\\n98\\n99\\n99\\n100\\n98\\n99\\n99\\n98\\n100\\n99\\n98\\n99\\n98\\n100\\n100\\n100\\n99\\n98\\n99\\n98\\n100\\n100\\n\", \"96\\n30\\n10\\n20\\n20\\n30\\n30\\n20\\n10\\n20\\n30\\n30\\n30\\n30\\n10\\n10\\n30\\n20\\n30\\n10\\n10\\n10\\n30\\n10\\n30\\n10\\n10\\n20\\n30\\n30\\n30\\n30\\n10\\n20\\n20\\n30\\n10\\n30\\n20\\n30\\n20\\n20\\n10\\n10\\n30\\n30\\n10\\n10\\n10\\n30\\n10\\n10\\n10\\n10\\n30\\n20\\n20\\n20\\n30\\n10\\n10\\n20\\n20\\n30\\n20\\n20\\n30\\n10\\n30\\n20\\n20\\n20\\n10\\n30\\n20\\n30\\n20\\n20\\n20\\n30\\n20\\n20\\n20\\n30\\n10\\n20\\n30\\n20\\n30\\n20\\n10\\n10\\n10\\n10\\n10\\n20\\n10\\n\", \"96\\n97\\n78\\n78\\n78\\n97\\n78\\n34\\n78\\n78\\n97\\n97\\n78\\n34\\n34\\n34\\n34\\n34\\n34\\n97\\n97\\n34\\n34\\n97\\n78\\n97\\n78\\n34\\n34\\n97\\n78\\n97\\n34\\n34\\n97\\n97\\n78\\n97\\n97\\n78\\n97\\n78\\n78\\n97\\n97\\n97\\n97\\n34\\n34\\n34\\n78\\n97\\n78\\n34\\n78\\n97\\n34\\n78\\n34\\n78\\n34\\n97\\n78\\n78\\n78\\n78\\n34\\n78\\n78\\n78\\n34\\n97\\n34\\n34\\n78\\n34\\n34\\n34\\n97\\n34\\n34\\n97\\n34\\n34\\n97\\n97\\n78\\n34\\n78\\n78\\n97\\n97\\n97\\n78\\n97\\n78\\n97\\n\", \"4\\n1\\n3\\n3\\n3\\n\", \"6\\n1\\n1\\n1\\n1\\n2\\n2\\n\", \"4\\n1\\n1\\n1\\n2\\n\", \"4\\n1\\n2\\n2\\n2\\n\", \"4\\n1\\n2\\n3\\n4\\n\", \"8\\n1\\n1\\n2\\n2\\n3\\n3\\n4\\n4\\n\", \"4\\n1\\n3\\n2\\n4\\n\", \"4\\n10\\n10\\n10\\n20\\n\", \"4\\n11\\n12\\n13\\n13\\n\", \"4\\n1\\n1\\n1\\n3\\n\", \"6\\n1\\n1\\n2\\n2\\n2\\n2\\n\", \"10\\n1\\n1\\n2\\n2\\n2\\n3\\n3\\n4\\n4\\n4\\n\"], \"outputs\": [\"YES\\n11 27\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n1 100\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n14 32\\n\", \"YES\\n50 100\\n\", \"YES\\n99 100\\n\", \"YES\\n4 5\\n\", \"YES\\n10 23\\n\", \"YES\\n11 34\\n\", \"YES\\n20 30\\n\", \"YES\\n1 100\\n\", \"YES\\n2 99\\n\", \"YES\\n1 100\\n\", \"YES\\n1 2\\n\", \"YES\\n99 100\\n\", \"YES\\n29 43\\n\", \"YES\\n88 98\\n\", \"YES\\n2 34\\n\", \"YES\\n23 94\\n\", \"YES\\n14 15\\n\", \"YES\\n21 23\\n\", \"YES\\n32 98\\n\", \"YES\\n3 4\\n\", \"YES\\n12 34\\n\", \"YES\\n19 32\\n\", \"YES\\n54 85\\n\", \"YES\\n12 43\\n\", \"YES\\n95 96\\n\", \"YES\\n4 33\\n\", \"YES\\n98 99\\n\", \"YES\\n12 87\\n\", \"YES\\n13 24\\n\", \"YES\\n12 49\\n\", \"YES\\n15 94\\n\", \"YES\\n33 42\\n\", \"YES\\n16 35\\n\", \"YES\\n33 44\\n\", \"YES\\n54 98\\n\", \"YES\\n12 81\\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\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\"]}", "source": "primeintellect"}
|
Petya and Vasya decided to play a game. They have n cards (n is an even number). A single integer is written on each card.
Before the game Petya will choose an integer and after that Vasya will choose another integer (different from the number that Petya chose). During the game each player takes all the cards with number he chose. For example, if Petya chose number 5 before the game he will take all cards on which 5 is written and if Vasya chose number 10 before the game he will take all cards on which 10 is written.
The game is considered fair if Petya and Vasya can take all n cards, and the number of cards each player gets is the same.
Determine whether Petya and Vasya can choose integer numbers before the game so that the game is fair.
-----Input-----
The first line contains a single integer n (2 ≤ n ≤ 100) — number of cards. It is guaranteed that n is an even number.
The following n lines contain a sequence of integers a_1, a_2, ..., a_{n} (one integer per line, 1 ≤ a_{i} ≤ 100) — numbers written on the n cards.
-----Output-----
If it is impossible for Petya and Vasya to choose numbers in such a way that the game will be fair, print "NO" (without quotes) in the first line. In this case you should not print anything more.
In the other case print "YES" (without quotes) in the first line. In the second line print two distinct integers — number that Petya should choose and the number that Vasya should choose to make the game fair. If there are several solutions, print any of them.
-----Examples-----
Input
4
11
27
27
11
Output
YES
11 27
Input
2
6
6
Output
NO
Input
6
10
20
30
20
10
20
Output
NO
Input
6
1
1
2
2
3
3
Output
NO
-----Note-----
In the first example the game will be fair if, for example, Petya chooses number 11, and Vasya chooses number 27. Then the will take all cards — Petya will take cards 1 and 4, and Vasya will take cards 2 and 3. Thus, each of them will take exactly two cards.
In the second example fair game is impossible because the numbers written on the cards are equal, but the numbers that Petya and Vasya should choose should be distinct.
In the third example it is impossible to take all cards. Petya and Vasya can take at most five cards — for example, Petya can choose number 10 and Vasya can choose number 20. But for the game to be fair it is necessary to take 6 cards.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2 2\\n5 8\\n\", \"1 2\\n7 1\\n\", \"1 2\\n4 4\\n\", \"1 4\\n2 2 1 2\\n\", \"10000 100\\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9938\\n\", \"100 15\\n165 26 83 64 235 48 36 51 3 18 5 10 9 6 5\\n\", \"1 4\\n2 2 2 2\\n\", \"5691 91\\n6573 1666 2158 2591 4636 886 263 4217 389 29 1513 1172 617 2012 1855 798 1588 979 152 37 890 375 1091 839 385 382 1 255 117 289 119 224 182 69 19 71 115 13 4 22 35 2 60 12 6 12 19 9 3 2 2 6 5 1 7 7 3 1 5 1 7 1 4 1 1 3 2 1 2 1 1 2 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 5631\\n\", \"2000 50\\n203 89 1359 3105 898 1381 248 365 108 766 961 630 265 819 838 125 1751 289 177 81 131 564 102 95 49 74 92 101 19 17 156 5 5 4 20 9 25 16 16 2 8 5 4 2 1 3 4 1 3 2\\n\", \"10000 100\\n800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800 800\\n\", \"10000 100\\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 2050 1074 605 979 1724 1608 672 88 1243 129 718 544 3590 37 187 600 738 34 64 316 58 6 84 252 75 68 40 68 4 29 29 8 13 11 5 1 5 1 3 2 1 1 1 2 3 4 1 1 2 2 2 1 1 1 1 1 1 1 1 1 1 3\\n\", \"8459 91\\n778 338 725 1297 115 540 1452 2708 193 1806 1496 1326 2648 176 199 93 342 3901 2393 2718 800 3434 657 4037 291 690 1957 3280 73 6011 2791 1987 440 455 444 155 261 234 829 1309 1164 616 34 627 107 213 52 110 323 81 98 8 7 73 20 12 56 3 40 12 8 7 69 1 14 3 6 2 6 8 3 5 4 4 3 1 1 4 2 1 1 1 8 2 2 2 1 1 1 2 8421\\n\", \"1 3\\n2 3 2\\n\", \"10000 91\\n2351 1402 1137 2629 4718 1138 1839 1339 2184 2387 165 370 918 1476 2717 879 1152 5367 3940 608 941 766 1256 656 2768 916 4176 489 1989 1633 2725 2329 2795 1970 667 340 1275 120 870 488 225 59 64 255 207 3 37 127 19 224 34 283 144 50 132 60 57 29 18 6 7 4 4 15 3 5 1 10 5 2 3 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 9948\\n\", \"10000 83\\n64 612 2940 2274 1481 1713 860 1264 104 5616 2574 5292 4039 292 1416 854 3854 1140 4344 3904 1720 1968 442 884 2032 875 291 677 2780 3074 3043 2997 407 727 344 511 156 321 134 51 382 336 591 52 134 39 104 10 20 15 24 2 70 39 14 16 16 25 1 6 2 2 1 1 1 2 4 2 1 2 1 2 1 1 1 1 1 1 1 1 1 1 9968\\n\", \"4000 71\\n940 1807 57 715 532 212 3842 2180 2283 744 1453 800 1945 380 2903 293 633 391 2866 256 102 46 228 1099 434 210 244 14 27 4 63 53 3 9 36 25 1 12 2 14 12 28 2 28 8 5 11 8 2 3 6 4 1 1 1 3 2 1 1 1 2 2 1 1 1 1 1 2 1 1 3966\\n\", \"3403 59\\n1269 1612 453 795 1216 941 19 44 1796 324 2019 1397 651 382 841 2003 3013 638 1007 1001 351 95 394 149 125 13 116 183 20 78 208 19 152 10 151 177 16 23 17 22 8 1 3 2 6 1 5 3 13 1 8 4 3 4 4 4 2 2 3378\\n\", \"2393 33\\n1381 2210 492 3394 912 2927 1189 269 66 102 104 969 395 385 369 354 251 28 203 334 20 10 156 29 61 13 30 4 1 32 2 2 2436\\n\", \"10000 100\\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9939\\n\", \"10000 89\\n1001 1531 2489 457 1415 617 2057 2658 3030 789 2500 3420 1550 376 720 78 506 293 1978 383 3195 2036 891 1741 1817 486 2650 360 2250 2531 3250 1612 2759 603 5321 1319 791 1507 265 174 877 1861 572 172 580 536 777 165 169 11 125 31 186 113 78 27 25 37 8 21 48 24 4 33 35 13 15 1 3 2 2 8 3 5 1 1 6 1 1 2 1 1 2 2 1 1 2 1 9953\\n\", \"4 16\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"10000 71\\n110 14 2362 260 423 881 1296 3904 1664 849 57 631 1922 917 4832 1339 3398 4578 59 2663 2223 698 4002 3013 747 699 1230 2750 239 1409 6291 2133 1172 5824 181 797 26 281 574 557 19 82 624 387 278 53 64 163 22 617 15 35 42 48 14 140 171 36 28 22 5 49 17 5 10 14 13 1 3 3 9979\\n\", \"3495 83\\n2775 2523 1178 512 3171 1159 1382 2146 2192 1823 799 231 502 16 99 309 656 665 222 285 11 106 244 137 241 45 41 29 485 6 62 38 94 5 7 93 48 5 10 13 2 1 2 1 4 8 5 9 4 6 1 1 1 3 4 3 7 1 2 3 1 1 7 1 1 2 1 1 1 1 1 1 2 1 1 1 1 1 1 1 1 1 3443\\n\", \"1000 40\\n1701 1203 67 464 1884 761 11 559 29 115 405 133 174 63 147 93 41 19 1 15 41 8 33 4 4 1 4 1 1 2 1 2 1 1 2 1 1 2 1 4\\n\", \"347 20\\n55 390 555 426 140 360 29 115 23 113 58 30 33 1 23 3 35 5 7 363\\n\", \"10000 100\\n749 2244 949 2439 2703 44 2394 124 285 3694 3609 717 1413 155 974 1778 1448 1327 1487 3458 319 1395 3783 2184 2062 43 826 38 3276 807 1837 4635 171 1386 1768 1128 2020 2536 800 782 3058 174 455 83 647 595 658 109 33 23 70 39 38 1 6 35 94 9 22 12 6 1 2 2 4 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 1 1 1 2 1 1 1 1 1 1 1 1 1 1 1 1 1 9940\\n\", \"10000 93\\n1388 119 711 23 4960 4002 2707 188 813 1831 334 543 338 3402 1808 3368 1428 971 985 220 1521 457 457 140 332 1503 1539 2095 1891 269 5223 226 1528 190 428 5061 410 1587 1149 1934 2275 1337 1828 275 181 85 499 29 585 808 751 401 635 461 181 164 274 36 401 255 38 60 76 16 6 35 79 46 1 39 11 2 8 2 4 14 3 1 1 1 1 1 2 1 3 1 1 1 1 2 1 1 9948\\n\", \"4981 51\\n5364 2166 223 742 350 1309 15 229 4100 3988 227 1719 9 125 787 427 141 842 171 2519 32 2554 2253 721 775 88 720 9 397 513 100 291 111 32 238 42 152 108 5 58 96 53 7 19 11 2 5 5 6 2 4966\\n\", \"541 31\\n607 204 308 298 398 213 1182 58 162 46 64 12 38 91 29 2 4 12 19 3 7 9 3 6 1 1 2 1 3 1 529\\n\", \"100 100\\n6 129 61 6 87 104 45 28 3 35 2 14 1 37 2 4 24 4 3 1 6 4 2 1 1 3 1 2 2 9 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 1 2 1 1 1 1 1 1 1 1 1 1 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 1 1 1 1 1 1 1 22\\n\", \"1 4\\n2 2 2 1\\n\", \"1 3\\n2 2 2\\n\", \"2 5\\n8 2 2 2 2\\n\", \"1 4\\n1 1 2 2\\n\", \"1 3\\n2 2 3\\n\", \"1 3\\n4 2 2\\n\", \"1 4\\n2 1 2 2\\n\", \"1 3\\n3 2 2\\n\", \"2 8\\n2 2 2 2 2 2 1 1\\n\", \"2 6\\n2 2 2 2 2 2\\n\", \"1 4\\n1 2 2 2\\n\", \"1 4\\n1 1 1 1\\n\", \"2 7\\n2 2 2 2 2 2 2\\n\", \"2 8\\n1 1 1 1 1 1 1 1\\n\", \"3 7\\n12 2 2 2 2 2 2\\n\", \"2 6\\n4 1 3 1 1 3\\n\", \"1 3\\n2 2 4\\n\", \"5 15\\n2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"2 8\\n2 2 2 2 1 1 1 1\\n\", \"1 2\\n6 2\\n\", \"4 13\\n2 2 2 2 2 2 2 2 2 2 2 2 4\\n\", \"2 7\\n1 1 1 4 2 2 2\\n\", \"3 8\\n8 2 2 2 2 2 2 2\\n\", \"2 8\\n1 1 1 1 2 2 2 2\\n\", \"2 8\\n2 2 2 2 1 1 2 2\\n\", \"1 4\\n2 2 1 1\\n\", \"3 9\\n2 2 2 2 2 2 2 2 2\\n\", \"2 6\\n2 2 2 2 2 5\\n\", \"1 1\\n6\\n\", \"2 1\\n16\\n\", \"1 1\\n2\\n\", \"2 8\\n2 2 2 2 2 2 2 1\\n\", \"4 16\\n1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"2 7\\n4 1 1 1 1 2 2\\n\", \"2 6\\n2 2 2 5 2 2\\n\", \"3 1\\n22\\n\", \"2 8\\n2 2 2 2 1 1 1 3\\n\", \"3 12\\n2 1 2 2 2 1 2 2 2 1 2 2\\n\", \"1 4\\n2 2 3 1\\n\", \"2 6\\n5 2 2 2 2 2\\n\", \"20 100\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\n\", \"1 3\\n2 2 1\\n\", \"1 2\\n3 3\\n\", \"2 6\\n2 3 2 2 3 2\\n\", \"2 8\\n2 2 1 1 2 2 2 2\\n\", \"2 6\\n3 3 2 2 2 2\\n\", \"3 12\\n2 2 2 2 2 2 2 2 2 1 1 1\\n\", \"3 10\\n2 2 2 2 2 2 2 2 2 3\\n\"], \"outputs\": [\"YES\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\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\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\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\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\"]}", "source": "primeintellect"}
|
Daenerys Targaryen has an army consisting of k groups of soldiers, the i-th group contains a_{i} soldiers. She wants to bring her army to the other side of the sea to get the Iron Throne. She has recently bought an airplane to carry her army through the sea. The airplane has n rows, each of them has 8 seats. We call two seats neighbor, if they are in the same row and in seats {1, 2}, {3, 4}, {4, 5}, {5, 6} or {7, 8}.
[Image] A row in the airplane
Daenerys Targaryen wants to place her army in the plane so that there are no two soldiers from different groups sitting on neighboring seats.
Your task is to determine if there is a possible arranging of her army in the airplane such that the condition above is satisfied.
-----Input-----
The first line contains two integers n and k (1 ≤ n ≤ 10000, 1 ≤ k ≤ 100) — the number of rows and the number of groups of soldiers, respectively.
The second line contains k integers a_1, a_2, a_3, ..., a_{k} (1 ≤ a_{i} ≤ 10000), where a_{i} denotes the number of soldiers in the i-th group.
It is guaranteed that a_1 + a_2 + ... + a_{k} ≤ 8·n.
-----Output-----
If we can place the soldiers in the airplane print "YES" (without quotes). Otherwise print "NO" (without quotes).
You can choose the case (lower or upper) for each letter arbitrary.
-----Examples-----
Input
2 2
5 8
Output
YES
Input
1 2
7 1
Output
NO
Input
1 2
4 4
Output
YES
Input
1 4
2 2 1 2
Output
YES
-----Note-----
In the first sample, Daenerys can place the soldiers like in the figure below:
[Image]
In the second sample, there is no way to place the soldiers in the plane since the second group soldier will always have a seat neighboring to someone from the first group.
In the third example Daenerys can place the first group on seats (1, 2, 7, 8), and the second group an all the remaining seats.
In the fourth example she can place the first two groups on seats (1, 2) and (7, 8), the third group on seats (3), and the fourth group on seats (5, 6).
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 2\\n0 1 0\\n\", \"5 1\\n1 1 1 0 0\\n\", \"6 4\\n1 0 0 1 1 0\\n\", \"3 2\\n1 1 1\\n\", \"5 2\\n1 1 1 0 0\\n\", \"6 4\\n0 0 1 1 1 1\\n\", \"100 1000000000\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"7 723\\n1 0 1 1 0 0 1\\n\", \"6 1000000000\\n1 1 1 1 1 1\\n\", \"20 100\\n0 1 1 1 0 0 1 1 1 1 1 1 1 0 0 1 1 1 1 0\\n\", \"10 10\\n1 0 1 0 1 0 1 0 1 0\\n\", \"100 1000000000\\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\\n\", \"2 1\\n0 1\\n\", \"6 10101010\\n0 0 0 1 1 1\\n\", \"2 1\\n1 0\\n\", \"62 424941031\\n1 0 1 0 1 1 1 0 0 0 0 0 0 1 0 1 0 1 0 0 0 0 1 1 0 0 0 1 0 1 1 0 1 1 0 0 1 0 0 0 0 0 1 0 0 1 0 1 1 0 1 1 0 1 0 1 1 1 1 0 0 1\\n\", \"95 205\\n1 1 0 0 1 1 1 1 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 1 0 1 0 0 0 1 0 0 0 1 0 0 1 0 1 0 1 0 1 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 1 1 0 1 0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 1 1 0 1 1 1 0 1 0 0 1 1 1 1\\n\", \"2 1\\n1 1\\n\", \"2 1\\n0 0\\n\", \"6 50550505\\n1 1 1 1 1 0\\n\", \"69 708701895\\n1 1 1 0 1 0 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 0 1 0 0 1 0 0 1 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 1 1 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 1 0 1 1 0 1\\n\", \"93 208758396\\n0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 0 1 0 0 1 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0\\n\", \"74 418\\n1 1 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 1 1 0 0 0 0 1 0 1 1 0 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 0 0 0 1 1 0 1 1 0 1 1 1 0\\n\", \"45 841192216\\n0 1 1 0 0 1 1 1 1 1 1 1 0 0 1 0 0 0 0 0 0 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0 1 0 1 1 1 0 0 0 0\\n\", \"52 568367085\\n1 1 1 0 1 1 0 0 1 0 1 1 0 0 1 0 1 0 0 1 1 1 1 0 0 1 1 1 1 1 0 1 1 0 1 1 0 0 0 0 1 1 1 0 0 0 0 1 1 1 1 0\\n\", \"71 1207\\n0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 1 0 0 0 1 1 0 0 0 1 0 1 1 1 0 0 1 1 1 1 1 0 1 0 0 1 0 0 1 1 1 0 1 1 0 0 1 0 1 1 1 0 1 0 0 0 1 0\\n\", \"59 34723\\n0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"39 67\\n1 0 1 0 1 1 0 0 1 1 1 1 0 1 1 1 0 0 1 0 1 0 0 0 0 0 1 0 1 1 1 0 0 1 1 1 1 0 1\\n\", \"14 77644065\\n0 0 0 0 0 1 1 1 1 0 0 0 1 0\\n\", \"8 4074\\n1 1 1 0 1 1 0 1\\n\", \"41 885543234\\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 1 0 0 0 0 0 0\\n\", \"15 2\\n0 1 0 0 0 1 0 0 0 1 0 0 1 0 0\\n\", \"4 2\\n1 1 0 0\\n\", \"98 207942770\\n0 0 0 0 0 0 0 0 1 1 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 1 1 1 1 1 1 0 0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0 0 1 1 1 1 1 1 1 1 0 1 0 0 1 0 0 0 0 1 1 0 1 0 1 1 0 0 0 0 1 0 1 0 1 1 1 0 0 1 0 1 1 1 0 1\\n\", \"12 3\\n0 0 0 1 1 0 0 1 1 0 0 0\\n\", \"15 780\\n0 1 0 1 1 1 1 1 0 0 0 0 1 0 1\\n\", \"26 44790\\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\\n\", \"88 51\\n0 1 0 0 1 1 1 0 1 1 0 1 0 0 1 1 0 1 1 0 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 0 0 1 1 1 1 0 1 0 1 1 1 0 0 0 0 1 1 1 0 1 0 1 0 0 1 0 0 1 0 0 0 1 1 0 1 0 1 0 1 0 1 0 0 1 1 0 0 0 0 0 1 1\\n\", \"23 23\\n0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 1 1\\n\", \"2 170421784\\n0 0\\n\", \"50 230\\n0 1 0 0 1 0 0 1 0 0 0 0 0 1 0 1 0 0 0 0 1 1 0 1 1 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 1 0 0\\n\", \"8 758298525\\n0 1 1 1 0 1 1 1\\n\", \"4 16935781\\n0 0 0 0\\n\", \"23 505\\n1 0 1 0 1 0 0 1 0 0 0 0 0 1 1 1 1 1 0 1 1 1 1\\n\", \"28 298139068\\n1 1 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 0 0 1 0 1 1 1 0\\n\", \"25 705\\n1 0 1 0 0 0 1 0 0 1 0 0 1 0 0 0 1 0 1 1 0 1 1 0 0\\n\", \"54 505289730\\n0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0 0 0 1 1 1 0 1 1 0 0 0 0 1 0 1 1 0 1 0 0 0 0 1 0 1 1 1\\n\", \"55 625625\\n0 1 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 1 1 0 1 0 0 1 0 0 1 0 1 1 0 1 1 0 1 1 1 0 1 0 1 1 1 0 0 0 1 1 0\\n\", \"5 1000000000\\n0 0 0 1 1\\n\", \"64 575757\\n0 0 0 0 0 1 0 0 1 1 0 0 1 0 1 1 0 0 0 1 0 1 0 1 0 1 1 1 0 1 0 0 0 0 0 0 1 0 1 1 1 0 1 1 1 0 1 1 0 1 1 1 0 1 1 0 0 0 0 1 0 1 1 1\\n\", \"2 461613425\\n0 1\\n\", \"91 445454545\\n0 1 1 1 0 0 1 1 0 1 1 0 0 0 0 1 1 0 0 0 0 1 0 1 1 0 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 0 1 0 1 0 0 1 1 1 0 0 0 1 0 0 0 0 1 1 1 0 0 1 1 0 1 1 0 0 0 1 0 1 1 1 0 0 1 0 1 0 0 1 1 1 1 1 1 0 0\\n\", \"64 355856085\\n1 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1\\n\", \"93 915259084\\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 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"5 9122\\n0 1 1 1 1\\n\", \"92 1000000000\\n0 0 1 1 0 1 1 1 0 0 1 1 1 0 1 1 1 0 0 0 0 0 1 1 1 1 0 1 1 0 0 1 1 1 1 0 0 1 1 0 1 1 1 1 1 0 1 1 0 0 1 0 1 0 1 0 0 0 1 0 1 0 1 0 1 1 0 0 1 1 0 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 1 1 1\\n\", \"38 6281\\n1 0 1 0 1 0 0 0 1 0 1 1 0 1 0 1 0 0 1 1 0 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 1 0\\n\", \"90 405601721\\n0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"16 1000000000\\n0 0 0 0 0 1 0 0 0 1 0 1 1 1 1 1\\n\", \"9 690557376\\n1 0 0 0 1 1 0 1 0\\n\", \"8 772864\\n0 0 0 0 1 0 0 0\\n\", \"91 761851245\\n0 1 0 1 1 1 0 0 1 1 0 1 0 1 1 1 0 1 0 0 1 0 1 0 1 1 0 1 0 1 0 0 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 0 1 0 0 0 1 1 0 1 1 1 0 0 1 0 0 0 1 0 1 0 1 0 1 0 0 0 0 0 0 1 1 1 0 1 0 1 0 0 0 0 1 1\\n\", \"14 804858334\\n1 1 1 1 1 1 1 1 1 1 1 1 1 0\\n\", \"67 47245433\\n0 1 0 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 1 1 0 1 0 0 0 1 0 0 0 1 1 1 0 1 1 0 0 1 1 0 1 0 0 1 0 0 0 1 1 0 0 1 0 1 1 1 1 1 1 1 0 1 0 0\\n\", \"31 1000\\n0 0 0 0 0 0 0 1 1 0 1 1 0 0 1 1 1 1 1 0 0 0 1 0 0 0 0 0 0 1 0\\n\", \"11 11111111\\n0 0 0 0 1 1 0 1 0 0 0\\n\", \"89 1000000000\\n1 1 0 0 1 1 1 0 0 1 1 0 1 0 1 1 1 1 1 1 0 0 0 1 0 1 1 0 0 0 0 1 0 0 1 0 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 0 1 0 1 0 1 1 0 0 1 1 0 1 0 0 0 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1\\n\", \"47 36889\\n0 0 0 0 1 1 0 0 0 1 0 0 1 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 1 0 1 0 1 0 0 1 0 0 1 0 0 0 0 1 1 0 0\\n\", \"13 1\\n1 1 1 1 1 1 1 0 1 0 1 1 1\\n\", \"69 1000000000\\n0 1 1 1 1 1 0 0 0 0 0 0 0 1 1 0 0 1 1 0 0 1 1 0 0 0 0 0 1 0 1 0 1 1 0 0 0 0 1 0 1 1 1 0 0 0 1 1 0 0 1 0 0 1 0 0 1 1 0 0 1 0 0 0 0 0 0 1 0\\n\", \"26 458\\n1 0 0 1 1 1 0 1 1 0 1 0 0 0 0 1 1 1 0 1 0 0 1 1 0 1\\n\", \"4 9545372\\n0 1 1 1\\n\", \"22 1065\\n0 1 0 0 0 1 0 0 1 1 1 0 1 0 1 0 0 1 0 0 0 0\\n\", \"52 816466148\\n0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1 1 1 1 1 1 1 0 1 0 1 1 1 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\", \"88 99999999\\n1 1 0 0 1 0 0 0 1 0 0 1 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 1 0 0 0 1 1 1 1 0 0 1 0 1 0 0 0 0 0 0 1 1 1 0 0 1 0 0 1 1 1 0 0 1 1 1 0 0 1 1 1 1 1 1 1 1 0 0 1 1 0 1 0 0 1 0 1 1 0 0 0 0\\n\", \"77 1000000000\\n1 1 1 1 0 1 1 1 0 0 1 1 1 0 1 1 1 1 1 0 0 1 1 0 1 1 1 0 1 1 1 0 1 0 0 0 1 1 0 1 1 1 1 1 0 1 1 1 1 0 0 1 1 0 1 0 0 1 1 0 0 0 1 0 1 1 0 1 0 0 0 0 1 1 0 1 1\\n\", \"77 690082102\\n0 0 1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0 0 1 1 0 1 0 1 1 0 0 1 0 1 0 1 0 0 1 1 1 1 0 0 0 0 0 1 0 0 0 1 0 1 0 1 0 1 1 0 1 0 0 0 0 0 1 1 0 1 0 0 1 1 1 0 0 1 0 1\\n\"], \"outputs\": [\"333333336\", \"0\", \"968493834\", \"1\", \"280000002\", \"163140742\", \"1\", \"943432053\", \"1\", \"95756105\", \"335596758\", \"1\", \"0\", \"335257169\", \"1\", \"207127441\", \"563696530\", \"1\", \"1\", \"975985364\", \"203682599\", \"238422110\", \"729393563\", \"899894444\", \"833347856\", \"21677943\", \"750975962\", \"398238624\", \"499901229\", \"436122735\", \"126904105\", \"0\", \"111111112\", \"357313797\", \"764212377\", \"672620496\", \"1\", \"122959231\", \"109883453\", \"1\", \"755817224\", \"97561468\", \"1\", \"749682909\", \"46089768\", \"541107651\", \"499152797\", \"566050219\", \"400007841\", \"46693839\", \"0\", \"946149403\", \"972843467\", \"731072361\", \"907236024\", \"758448092\", \"623069108\", \"140653691\", \"205157554\", \"33956123\", \"240938600\", \"351133152\", \"673910319\", \"6751531\", \"376636619\", \"900322483\", \"649450374\", \"882504914\", \"0\", \"154218920\", \"686869628\", \"368007311\", \"134992006\", \"892754580\", \"944706678\", \"436064901\", \"79316649\"]}", "source": "primeintellect"}
|
A girl named Sonya is studying in the scientific lyceum of the Kingdom of Kremland. The teacher of computer science (Sonya's favorite subject!) invented a task for her.
Given an array $a$ of length $n$, consisting only of the numbers $0$ and $1$, and the number $k$. Exactly $k$ times the following happens: Two numbers $i$ and $j$ are chosen equiprobable such that ($1 \leq i < j \leq n$). The numbers in the $i$ and $j$ positions are swapped.
Sonya's task is to find the probability that after all the operations are completed, the $a$ array will be sorted in non-decreasing order. She turned to you for help. Help Sonya solve this problem.
It can be shown that the desired probability is either $0$ or it can be represented as $\dfrac{P}{Q}$, where $P$ and $Q$ are coprime integers and $Q \not\equiv 0~\pmod {10^9+7}$.
-----Input-----
The first line contains two integers $n$ and $k$ ($2 \leq n \leq 100, 1 \leq k \leq 10^9$) — the length of the array $a$ and the number of operations.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 1$) — the description of the array $a$.
-----Output-----
If the desired probability is $0$, print $0$, otherwise print the value $P \cdot Q^{-1}$ $\pmod {10^9+7}$, where $P$ and $Q$ are defined above.
-----Examples-----
Input
3 2
0 1 0
Output
333333336
Input
5 1
1 1 1 0 0
Output
0
Input
6 4
1 0 0 1 1 0
Output
968493834
-----Note-----
In the first example, all possible variants of the final array $a$, after applying exactly two operations: $(0, 1, 0)$, $(0, 0, 1)$, $(1, 0, 0)$, $(1, 0, 0)$, $(0, 1, 0)$, $(0, 0, 1)$, $(0, 0, 1)$, $(1, 0, 0)$, $(0, 1, 0)$. Therefore, the answer is $\dfrac{3}{9}=\dfrac{1}{3}$.
In the second example, the array will not be sorted in non-decreasing order after one operation, therefore the answer is $0$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6 3\\n\", \"8 5\\n\", \"22 4\\n\", \"4 3\\n\", \"57 27\\n\", \"61 3\\n\", \"5 4\\n\", \"10 6\\n\", \"20 10\\n\", \"30 5\\n\", \"25 24\\n\", \"25 3\\n\", \"12 7\\n\", \"18 6\\n\", \"100000 3\\n\", \"100000 9999\\n\", \"9999 3\\n\", \"5323 32\\n\", \"6666 66\\n\", \"38578 32201\\n\", \"49449 5291\\n\", \"65310 32879\\n\", \"41183 4453\\n\", \"49127 9714\\n\", \"19684 12784\\n\", \"15332 5489\\n\", \"33904 32701\\n\", \"9258 2966\\n\", \"21648 11231\\n\", \"90952 47239\\n\", \"49298 23199\\n\", \"33643 24915\\n\", \"40651 5137\\n\", \"52991 15644\\n\", \"97075 62157\\n\", \"82767 53725\\n\", \"58915 26212\\n\", \"86516 16353\\n\", \"14746 7504\\n\", \"20404 7529\\n\", \"52614 8572\\n\", \"50561 50123\\n\", \"37509 7908\\n\", \"36575 23933\\n\", \"75842 8002\\n\", \"47357 2692\\n\", \"23214 4255\\n\", \"9474 46\\n\", \"79874 76143\\n\", \"63784 31333\\n\", \"70689 29493\\n\", \"43575 4086\\n\", \"87099 7410\\n\", \"75749 55910\\n\", \"87827 20996\\n\", \"31162 4580\\n\", \"63175 33696\\n\", \"15108 10033\\n\", \"82991 29195\\n\", \"48258 12837\\n\", \"59859 33779\\n\", \"93698 23890\\n\", \"42724 379\\n\", \"70434 39286\\n\", \"69826 18300\\n\", \"57825 17636\\n\", \"64898 2076\\n\", \"76375 67152\\n\", \"30698 3778\\n\", \"100 3\\n\", \"41 3\\n\", \"28 4\\n\", \"2487 19\\n\", \"100000 25000\\n\", \"10000 3\\n\", \"16 3\\n\"], \"outputs\": [\"4\\n\", \"3\\n\", \"6\\n\", \"3\\n\", \"4\\n\", \"9\\n\", \"3\\n\", \"3\\n\", \"4\\n\", \"6\\n\", \"3\\n\", \"7\\n\", \"3\\n\", \"5\\n\", \"25\\n\", \"7\\n\", \"20\\n\", \"13\\n\", \"12\\n\", \"3\\n\", \"7\\n\", \"3\\n\", \"7\\n\", \"6\\n\", \"3\\n\", \"4\\n\", \"3\\n\", \"5\\n\", \"3\\n\", \"3\\n\", \"4\\n\", \"3\\n\", \"6\\n\", \"5\\n\", \"3\\n\", \"3\\n\", \"4\\n\", \"6\\n\", \"3\\n\", \"4\\n\", \"6\\n\", \"3\\n\", \"5\\n\", \"3\\n\", \"7\\n\", \"8\\n\", \"6\\n\", \"13\\n\", \"3\\n\", \"4\\n\", \"4\\n\", \"7\\n\", \"7\\n\", \"3\\n\", \"5\\n\", \"6\\n\", \"3\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"3\\n\", \"5\\n\", \"12\\n\", \"3\\n\", \"5\\n\", \"5\\n\", \"9\\n\", \"3\\n\", \"7\\n\", \"10\\n\", \"8\\n\", \"7\\n\", \"12\\n\", \"5\\n\", \"20\\n\", \"6\\n\"]}", "source": "primeintellect"}
|
Memory is now interested in the de-evolution of objects, specifically triangles. He starts with an equilateral triangle of side length x, and he wishes to perform operations to obtain an equilateral triangle of side length y.
In a single second, he can modify the length of a single side of the current triangle such that it remains a non-degenerate triangle (triangle of positive area). At any moment of time, the length of each side should be integer.
What is the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y?
-----Input-----
The first and only line contains two integers x and y (3 ≤ y < x ≤ 100 000) — the starting and ending equilateral triangle side lengths respectively.
-----Output-----
Print a single integer — the minimum number of seconds required for Memory to obtain the equilateral triangle of side length y if he starts with the equilateral triangle of side length x.
-----Examples-----
Input
6 3
Output
4
Input
8 5
Output
3
Input
22 4
Output
6
-----Note-----
In the first sample test, Memory starts with an equilateral triangle of side length 6 and wants one of side length 3. Denote a triangle with sides a, b, and c as (a, b, c). Then, Memory can do $(6,6,6) \rightarrow(6,6,3) \rightarrow(6,4,3) \rightarrow(3,4,3) \rightarrow(3,3,3)$.
In the second sample test, Memory can do $(8,8,8) \rightarrow(8,8,5) \rightarrow(8,5,5) \rightarrow(5,5,5)$.
In the third sample test, Memory can do: $(22,22,22) \rightarrow(7,22,22) \rightarrow(7,22,16) \rightarrow(7,10,16) \rightarrow(7,10,4) \rightarrow$
$(7,4,4) \rightarrow(4,4,4)$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1 2\\n3 4\\n\", \"1 0\\n0 1\\n\", \"1000000000 0\\n0 1000000000\\n\", \"8205 9482\\n11 -63\\n\", \"0 0\\n0 0\\n\", \"1000000000 -1000000000\\n1000000000 1000000000\\n\", \"1000000000 1000000000\\n1000000000 -1000000000\\n\", \"-1 -1\\n1 0\\n\", \"5 2\\n-15 -6\\n\", \"2 -5\\n-3 2\\n\", \"-5 -2\\n-1 -3\\n\", \"-5 8\\n1 6\\n\", \"1 3\\n3 2\\n\", \"-42 63\\n77 -32\\n\", \"91 -7\\n-21 91\\n\", \"-67 -77\\n-56 -75\\n\", \"-26 53\\n-48 -89\\n\", \"97 -934\\n-707 184\\n\", \"689 412\\n-794 -421\\n\", \"-718 -387\\n972 972\\n\", \"-126 -376\\n75 367\\n\", \"-7 -3674\\n845 5737\\n\", \"-9912 755\\n-8220 6419\\n\", \"-3928 5185\\n4331 6665\\n\", \"2056 9614\\n-5171 8965\\n\", \"41642 63236\\n-59604 20357\\n\", \"-38387 -93294\\n-52918 -51288\\n\", \"92812 73253\\n-46231 11374\\n\", \"12784 -94506\\n26149 85264\\n\", \"955162 -709099\\n-743655 578837\\n\", \"160382 -103968\\n301943 -156088\\n\", \"-634398 -468280\\n447621 78431\\n\", \"-398622 -832591\\n-506781 -656493\\n\", \"-2665612 -7693032\\n-2861368 -6201836\\n\", \"1762462 700391\\n-7134185 5042962\\n\", \"6190536 5693104\\n-8006293 -3712238\\n\", \"553632 5653328\\n-7246622 9164341\\n\", \"43469186 94408326\\n78066381 -19616812\\n\", \"25683826 49101909\\n88380777 46573745\\n\", \"-87068851 98762810\\n3727856 -87235696\\n\", \"95145788 53456393\\n42406028 83987544\\n\", \"876432079 -414820618\\n-816514132 -914565422\\n\", \"-240038673 376842703\\n-241080203 410087456\\n\", \"938457872 -536526676\\n867891897 -855194260\\n\", \"116954418 255136645\\n-851641472 174491320\\n\", \"1 1\\n1 5\\n\", \"1 5\\n1 1\\n\", \"5 1\\n1 1\\n\", \"1 1\\n5 1\\n\", \"-1000000000 -1000000000\\n1000000000 1000000000\\n\", \"-1000000000 -1000000000\\n999999999 999999999\\n\", \"536870912 88\\n536870912 22528\\n\", \"268435456 268435456\\n22512 22528\\n\", \"-1 1\\n1 1\\n\", \"-1000 -999\\n-1 0\\n\", \"-801658422 -738703776\\n910442649 -920729415\\n\", \"-203893419 -777818\\n295920256 -474540430\\n\", \"448944609 529185527\\n946362390 958011342\\n\", \"348741875 -606207234\\n-279810821 -14278204\\n\", \"-202195424 182466434\\n-722509868 -838173079\\n\", \"-48 9\\n17 -67\\n\", \"12 180\\n79 47\\n\", \"-131 -87\\n-66 -109\\n\", \"171 17\\n9 93\\n\", \"221 20\\n-22 -200\\n\", \"372 -352\\n-160 -423\\n\", \"480 37\\n-3 -459\\n\", \"-535 -395\\n-264 513\\n\", \"-498 -685\\n-532 526\\n\", \"-16 450\\n-848 27\\n\", \"-621967643 610314360\\n-660274542 -772630232\\n\", \"222416863 97256131\\n897661932 -426944193\\n\", \"67861199 302935298\\n883117733 559626116\\n\", \"1000000000 1\\n1000000000 2\\n\", \"-2 1\\n1 -2\\n\", \"1000000000 999999995\\n99999999 -199992543\\n\"], \"outputs\": [\"0.2000000000\\n\", \"0.5000000000\\n\", \"500000000.0000000000\\n\", \"35.0198432832\\n\", \"0.0000000000\\n\", \"1000000000.0000000000\\n\", \"1000000000.0000000000\\n\", \"0.3333333333\\n\", \"0.0000000000\\n\", \"0.9166666667\\n\", \"1.1818181818\\n\", \"2.1111111111\\n\", \"0.7777777778\\n\", \"16.3878504673\\n\", \"38.7333333333\\n\", \"2.5927272727\\n\", \"29.6219512195\\n\", \"334.2819979188\\n\", \"16.0012953368\\n\", \"105.5204985241\\n\", \"19.1122881356\\n\", \"298.5843320666\\n\", \"2268.9886983324\\n\", \"3969.3426099731\\n\", \"3141.2387756983\\n\", \"32033.4760659150\\n\", \"12582.8868737997\\n\", \"22109.0927374802\\n\", \"18439.1869417765\\n\", \"8557.1487662354\\n\", \"8802.4244934460\\n\", \"98147.3248125840\\n\", \"66924.0413186624\\n\", \"282203.1726406262\\n\", \"1048758.9114990780\\n\", \"957535.4624752104\\n\", \"2140390.1895580233\\n\", \"41883387.4306073852\\n\", \"14987456.1603828062\\n\", \"26110777.7289122988\\n\", \"20815549.6776987243\\n\", \"520028295.4718751899\\n\", \"5983627.7655281517\\n\", \"105349963.0995401485\\n\", \"204147910.8375163887\\n\", \"0.5000000000\\n\", \"0.5000000000\\n\", \"0.5000000000\\n\", \"0.5000000000\\n\", \"0.0000000000\\n\", \"0.0000000000\\n\", \"11219.7636804586\\n\", \"7.9993289080\\n\", \"1.0000000000\\n\", \"0.4995000000\\n\", \"744753719.5468964978\\n\", \"99618123.5339717944\\n\", \"24529803.2444389601\\n\", \"143060520.9047362779\\n\", \"190651913.7089770083\\n\", \"21.7234042553\\n\", \"42.9433962264\\n\", \"21.7226463104\\n\", \"54.3103448276\\n\", \"94.5140388769\\n\", \"216.4903748734\\n\", \"224.9325842697\\n\", \"321.2340966921\\n\", \"503.1068273092\\n\", \"284.2416107383\\n\", \"611623765.8647500770\\n\", \"125718637.9005708302\\n\", \"126575973.2879779836\\n\", \"0.4999999993\\n\", \"0.5000000000\\n\", \"142854098.7306812546\\n\"]}", "source": "primeintellect"}
|
The determinant of a matrix 2 × 2 is defined as follows:$\operatorname{det} \left(\begin{array}{ll}{a} & {b} \\{c} & {d} \end{array} \right) = a d - b c$
A matrix is called degenerate if its determinant is equal to zero.
The norm ||A|| of a matrix A is defined as a maximum of absolute values of its elements.
You are given a matrix $A = \left(\begin{array}{ll}{a} & {b} \\{c} & {d} \end{array} \right)$. Consider any degenerate matrix B such that norm ||A - B|| is minimum possible. Determine ||A - B||.
-----Input-----
The first line contains two integers a and b (|a|, |b| ≤ 10^9), the elements of the first row of matrix A.
The second line contains two integers c and d (|c|, |d| ≤ 10^9) the elements of the second row of matrix A.
-----Output-----
Output a single real number, the minimum possible value of ||A - B||. Your answer is considered to be correct if its absolute or relative error does not exceed 10^{ - 9}.
-----Examples-----
Input
1 2
3 4
Output
0.2000000000
Input
1 0
0 1
Output
0.5000000000
-----Note-----
In the first sample matrix B is $\left(\begin{array}{ll}{1.2} & {1.8} \\{2.8} & {4.2} \end{array} \right)$
In the second sample matrix B is $\left(\begin{array}{ll}{0.5} & {0.5} \\{0.5} & {0.5} \end{array} \right)$
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 3\\n4 3 5\\n\", \"3 4\\n5 3 4\\n\", \"3 7\\n1 2 3\\n\", \"1 1\\n1\\n\", \"1 2\\n1\\n\", \"5 10\\n10 10 10 10 10\\n\", \"1 1000000000\\n1000000000\\n\", \"1 1000000000000\\n42\\n\", \"3 2\\n1 1 5\\n\", \"2 1\\n1 100\\n\", \"3 1\\n5 10 15\\n\", \"2 1\\n1 1000\\n\", \"3 3\\n2 4 4\\n\", \"10 1\\n1 2 3 4 5 6 7 8 9 10\\n\", \"3 6\\n1 99 99\\n\", \"4 1\\n100 1 100 100\\n\", \"5 2\\n4 6 8 10 14\\n\", \"4 6\\n1 2 3 10\\n\", \"5 2\\n4 6 8 10 19\\n\", \"4 1\\n5 3 1 1\\n\", \"4 2\\n2 3 4 5\\n\", \"3 10\\n1 9 9\\n\", \"3 7\\n1 5 12\\n\", \"2 1\\n1 1000000000\\n\", \"5 1\\n100 100 100 100 1\\n\", \"2 1\\n100 10000\\n\", \"5 1\\n5 5 5 5 1\\n\", \"2 500\\n1 1000\\n\", \"2 1\\n1 10000000\\n\", \"2 50\\n1 100\\n\", \"2 1\\n100 1\\n\", \"5 1\\n1 1 1 1 1000\\n\", \"3 3\\n4 4 92\\n\", \"2 30\\n1 100\\n\", \"2 94\\n1 99\\n\", \"6 1\\n2 2 3 6 6 6\\n\", \"2 3\\n1 10\\n\", \"3 3\\n100 4 4\\n\", \"3 10\\n100 100 1\\n\", \"2 1\\n1000000000 999999999\\n\", \"3 3\\n1 3 5\\n\", \"2 5\\n1 10\\n\", \"15 56\\n38 47 84 28 67 40 15 24 64 37 68 30 74 41 62\\n\", \"5 5\\n1 100 100 100 100\\n\", \"2 1\\n1 10\\n\", \"3 4\\n1 2 2\\n\", \"2 2\\n900000000 2\\n\", \"4 1\\n1 5 5 5\\n\", \"3 7\\n1 5 10\\n\", \"4 2\\n5 7 8 9\\n\", \"5 3\\n1 2 3 4 5\\n\", \"3 3\\n100 2 3\\n\", \"2 5\\n1 100\\n\", \"2 5000\\n1 1000000000\\n\", \"1 1000000000000\\n1000000000\\n\", \"2 1\\n2 4\\n\", \"3 3\\n1 2 10\\n\", \"2 2\\n5 1\\n\", \"2 5000\\n1 100000000\\n\", \"3 1\\n1 4 5\\n\", \"2 50\\n1 500\\n\", \"2 5\\n1 8\\n\", \"3 100\\n1 100 100\\n\", \"3 3\\n4 6 7\\n\", \"2 1\\n2 5\\n\", \"2 4\\n8 1000\\n\", \"2 1000000000\\n99999999 1000000000\\n\", \"3 3\\n23 123 123\\n\", \"3 1\\n5 6 3\\n\", \"5 1\\n1 10 10 10 10\\n\", \"3 5\\n1 1 10\\n\", \"3 1\\n1 1 5\\n\", \"3 5\\n1 2 3\\n\", \"4 4\\n1000000000 1000000000 1000000000 1000000000\\n\", \"3 100\\n1 55 55\\n\", \"2 1\\n1 7\\n\"], \"outputs\": [\"3\\n\", \"2\\n\", \"-1\\n\", \"0\\n\", \"-1\\n\", \"8\\n\", \"0\\n\", \"-1\\n\", \"1\\n\", \"1\\n\", \"5\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"4\\n\", \"1\\n\", \"4\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"100\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"4\\n\", \"1\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"4\\n\", \"1\\n\", \"999999999\\n\", \"1\\n\", \"1\\n\", \"15\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"5\\n\", \"1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"-1\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"4\\n\", \"2\\n\", \"8\\n\", \"49999999\\n\", \"23\\n\", \"3\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"0\\n\", \"999999999\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
The Fair Nut likes kvass very much. On his birthday parents presented him $n$ kegs of kvass. There are $v_i$ liters of kvass in the $i$-th keg. Each keg has a lever. You can pour your glass by exactly $1$ liter pulling this lever. The Fair Nut likes this drink very much, so he wants to pour his glass by $s$ liters of kvass. But he wants to do it, so kvass level in the least keg is as much as possible.
Help him find out how much kvass can be in the least keg or define it's not possible to pour his glass by $s$ liters of kvass.
-----Input-----
The first line contains two integers $n$ and $s$ ($1 \le n \le 10^3$, $1 \le s \le 10^{12}$) — the number of kegs and glass volume.
The second line contains $n$ integers $v_1, v_2, \ldots, v_n$ ($1 \le v_i \le 10^9$) — the volume of $i$-th keg.
-----Output-----
If the Fair Nut cannot pour his glass by $s$ liters of kvass, print $-1$. Otherwise, print a single integer — how much kvass in the least keg can be.
-----Examples-----
Input
3 3
4 3 5
Output
3
Input
3 4
5 3 4
Output
2
Input
3 7
1 2 3
Output
-1
-----Note-----
In the first example, the answer is $3$, the Fair Nut can take $1$ liter from the first keg and $2$ liters from the third keg. There are $3$ liters of kvass in each keg.
In the second example, the answer is $2$, the Fair Nut can take $3$ liters from the first keg and $1$ liter from the second keg.
In the third example, the Fair Nut can't pour his cup by $7$ liters, so the answer is $-1$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.125
|
{"tests": "{\"inputs\": [\"5\\nDDRRR\\n\", \"6\\nDDRRRR\\n\", \"1\\nD\\n\", \"1\\nR\\n\", \"2\\nDR\\n\", \"3\\nRDD\\n\", \"3\\nDRD\\n\", \"4\\nDRRD\\n\", \"4\\nDRRR\\n\", \"4\\nRDRD\\n\", \"5\\nDRDRR\\n\", \"4\\nRRRR\\n\", \"5\\nRDDRD\\n\", \"5\\nDDRRD\\n\", \"5\\nDRRRD\\n\", \"5\\nDDDDD\\n\", \"6\\nDRRDDR\\n\", \"7\\nRDRDRDD\\n\", \"7\\nRDRDDRD\\n\", \"7\\nRRRDDDD\\n\", \"8\\nRRRDDDDD\\n\", \"9\\nRRRDDDDDR\\n\", \"9\\nRRDDDRRDD\\n\", \"9\\nRRDDDRDRD\\n\", \"10\\nDDRRRDRRDD\\n\", \"11\\nDRDRRDDRDDR\\n\", \"12\\nDRDRDRDRRDRD\\n\", \"13\\nDRDDDDRRRRDDR\\n\", \"14\\nDDRDRRDRDRDDDD\\n\", \"15\\nDDRRRDDRDRRRDRD\\n\", \"50\\nDDDRDRDDDDRRRRDDDDRRRDRRRDDDRRRRDRDDDRRDRRDDDRDDDD\\n\", \"50\\nDRDDDDDDDRDRDDRRRDRDRDRDDDRRDRRDRDRRDDDRDDRDRDRDDR\\n\", \"100\\nRDRRDRDDDDRDRRDDRDRRDDRRDDRRRDRRRDDDRDDRDDRRDRDRRRDRDRRRDRRDDDRDDRRRDRDRRRDDRDRDDDDDDDRDRRDDDDDDRRDD\\n\", \"100\\nRRDRRDDDDDDDRDRRRDRDRDDDRDDDRDDRDRRDRRRDRRDRRRRRRRDRRRRRRDDDRRDDRRRDRRRDDRRDRRDDDDDRRDRDDRDDRRRDRRDD\\n\", \"6\\nRDDRDR\\n\", \"6\\nDRRDRD\\n\", \"8\\nDDDRRRRR\\n\", \"7\\nRRRDDDD\\n\", \"7\\nRDDRRDD\\n\", \"9\\nRDDDRRDRR\\n\", \"5\\nRDRDD\\n\", \"5\\nRRDDD\\n\", \"8\\nRDDRDRRD\\n\", \"10\\nDRRRDDRDRD\\n\", \"7\\nDRRDDRR\\n\", \"12\\nRDDDRRDRRDDR\\n\", \"7\\nRDRDDDR\\n\", \"7\\nDDRRRDR\\n\", \"10\\nDRRDRDRDRD\\n\", \"21\\nDDDDRRRRRDRDRDRDRDRDR\\n\", \"11\\nRDDDDDRRRRR\\n\", \"10\\nRDDDRRRDDR\\n\", \"4\\nRDDR\\n\", \"7\\nRDRDDRD\\n\", \"8\\nRDDDRRRD\\n\", \"16\\nDRRDRDRDRDDRDRDR\\n\", \"8\\nDRRDRDRD\\n\", \"6\\nRDDDRR\\n\", \"10\\nDDRRRRRDDD\\n\", \"7\\nDDRRRRD\\n\", \"12\\nRDDRDRDRRDRD\\n\", \"9\\nDDRRRDRDR\\n\", \"20\\nRDDRDRDRDRRDRDRDRDDR\\n\", \"7\\nRRDDDRD\\n\", \"12\\nDRRRRRRDDDDD\\n\", \"12\\nRDRDDRDRDRDR\\n\", \"6\\nDDDDDD\\n\", \"10\\nRRRDDRDDDD\\n\", \"40\\nRDDDRDDDRDRRDRDRRRRRDRDRDRDRRDRDRDRRDDDD\\n\", \"50\\nRRDDDRRDRRRDDRDDDDDRDDRRRRRRDRDDRDDDRDRRDDRDDDRDRD\\n\", \"5\\nRDRDR\\n\", \"9\\nDRRDRDDRR\\n\", \"6\\nDRRRDD\\n\", \"10\\nDDDDRRRRRR\\n\", \"9\\nRRDDDDRRD\\n\"], \"outputs\": [\"D\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"D\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"R\\n\", \"R\\n\", \"R\\n\", \"D\\n\", \"D\\n\"]}", "source": "primeintellect"}
|
There are n employees in Alternative Cake Manufacturing (ACM). They are now voting on some very important question and the leading world media are trying to predict the outcome of the vote.
Each of the employees belongs to one of two fractions: depublicans or remocrats, and these two fractions have opposite opinions on what should be the outcome of the vote. The voting procedure is rather complicated: Each of n employees makes a statement. They make statements one by one starting from employees 1 and finishing with employee n. If at the moment when it's time for the i-th employee to make a statement he no longer has the right to vote, he just skips his turn (and no longer takes part in this voting). When employee makes a statement, he can do nothing or declare that one of the other employees no longer has a right to vote. It's allowed to deny from voting people who already made the statement or people who are only waiting to do so. If someone is denied from voting he no longer participates in the voting till the very end. When all employees are done with their statements, the procedure repeats: again, each employees starting from 1 and finishing with n who are still eligible to vote make their statements. The process repeats until there is only one employee eligible to vote remaining and he determines the outcome of the whole voting. Of course, he votes for the decision suitable for his fraction.
You know the order employees are going to vote and that they behave optimal (and they also know the order and who belongs to which fraction). Predict the outcome of the vote.
-----Input-----
The first line of the input contains a single integer n (1 ≤ n ≤ 200 000) — the number of employees.
The next line contains n characters. The i-th character is 'D' if the i-th employee is from depublicans fraction or 'R' if he is from remocrats.
-----Output-----
Print 'D' if the outcome of the vote will be suitable for depublicans and 'R' if remocrats will win.
-----Examples-----
Input
5
DDRRR
Output
D
Input
6
DDRRRR
Output
R
-----Note-----
Consider one of the voting scenarios for the first sample: Employee 1 denies employee 5 to vote. Employee 2 denies employee 3 to vote. Employee 3 has no right to vote and skips his turn (he was denied by employee 2). Employee 4 denies employee 2 to vote. Employee 5 has no right to vote and skips his turn (he was denied by employee 1). Employee 1 denies employee 4. Only employee 1 now has the right to vote so the voting ends with the victory of depublicans.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7 5 3\\n\", \"1000000000 1 2019\\n\", \"100 100000 1\\n\", \"6 4 5\\n\", \"172165 93846 84\\n\", \"9978 99 98615\\n\", \"9909 95875 20\\n\", \"42651129 26190 16875\\n\", \"5 8253 91700\\n\", \"14712 8142 9912\\n\", \"98898 1040 98615\\n\", \"79674 62280 77850\\n\", \"78139 77688 1161\\n\", \"110518 69352 81284\\n\", \"881706694 5710 56529\\n\", \"863 99250 420\\n\", \"9112063 50688 2640\\n\", \"236009692 89900 300\\n\", \"16145755 64220 70642\\n\", \"997932 23910 14346\\n\", \"9907037 55440 88480\\n\", \"9695 9 85014\\n\", \"99548 73888 32\\n\", \"9742365 6750 90375\\n\", \"95544 17793 8856\\n\", \"2756 31707 63414\\n\", \"936989 17028 92708\\n\", \"9650984 18601 2090\\n\", \"26 92701 7\\n\", \"9980 78765 356\\n\", \"10348323 355 83425\\n\", \"952549276 31416 33000\\n\", \"992869 410 9880\\n\", \"96033 98622 100\\n\", \"3 998 99486\\n\", \"10652698 87345 1116\\n\", \"303857 1990 4\\n\", \"395013 59544 180\\n\", \"1183 532 73416\\n\", \"25 75060 2502\\n\", \"4987696 29388 29865\\n\", \"2531607 75419 14230\\n\", \"4015 56658 19\\n\", \"49277 166 8051\\n\", \"9984950 40800 1152\\n\", \"1710 11868 202\\n\", \"96974 1 99004\\n\", \"995676200 30 99370\\n\", \"983 97020 105\\n\", \"9331043 5355 81159\\n\", \"99005952 94024 10220\\n\", \"16965 51653 70\\n\", \"997674659 8874 35496\\n\", \"1647861 97967 10\\n\", \"7526 35 7525\\n\", \"68565 68564 1\\n\", \"58200 198 58050\\n\", \"14332 13672 1976\\n\", \"7957 18 7956\\n\", \"70343 66336 6910\\n\", \"101407 95200 6448\\n\", \"57986 4760 56440\\n\", \"87728 689 87236\\n\", \"79903 75251 7234\\n\", \"107132 20930 92956\\n\", \"97009 97008 129\\n\", \"96538 95880 900\\n\", \"7845 4410 7350\\n\", \"79873 13 79872\\n\", \"99573 99474 186\\n\", \"112104 86760 69327\\n\", \"76065 44280 39150\\n\", \"58423 58422 9737\\n\", \"22432 19298 5536\\n\"], \"outputs\": [\"19\\n\", \"500000001500000001\\n\", \"101\\n\", \"10\\n\", \"1735345812\\n\", \"507929\\n\", \"9910\\n\", \"6737492081840\\n\", \"6\\n\", \"21284\\n\", \"4761309\\n\", \"97070\\n\", \"108424\\n\", \"151686\\n\", \"680741853146475\\n\", \"864\\n\", \"78628667728\\n\", \"278502953469621\\n\", \"20303198570\\n\", \"104545151\\n\", \"87620910296\\n\", \"5227761\\n\", \"69626827\\n\", \"126544822305\\n\", \"157445948\\n\", \"2757\\n\", \"229896864\\n\", \"222830431513\\n\", \"27\\n\", \"9981\\n\", \"150833075049\\n\", \"1718466614644254\\n\", \"49284898280\\n\", \"96034\\n\", \"4\\n\", \"6304015267729\\n\", \"23081582946\\n\", \"2117961170\\n\", \"1956\\n\", \"26\\n\", \"4145604588400\\n\", \"2250674901\\n\", \"4016\\n\", \"14453806\\n\", \"519262873734\\n\", \"1711\\n\", \"4702123800\\n\", \"49568555030448651\\n\", \"984\\n\", \"14510155272753\\n\", \"2397840434982\\n\", \"16966\\n\", \"56083140668646\\n\", \"1352925986505\\n\", \"813132\\n\", \"205695\\n\", \"8583036\\n\", \"18960\\n\", \"1763140\\n\", \"110424\\n\", \"377984\\n\", \"395386\\n\", \"5657822\\n\", \"150249\\n\", \"353953\\n\", \"98514\\n\", \"243807\\n\", \"11282\\n\", \"245419010\\n\", \"153074\\n\", \"178619\\n\", \"305610\\n\", \"58436\\n\", \"36753\\n\"]}", "source": "primeintellect"}
|
A frog is initially at position $0$ on the number line. The frog has two positive integers $a$ and $b$. From a position $k$, it can either jump to position $k+a$ or $k-b$.
Let $f(x)$ be the number of distinct integers the frog can reach if it never jumps on an integer outside the interval $[0, x]$. The frog doesn't need to visit all these integers in one trip, that is, an integer is counted if the frog can somehow reach it if it starts from $0$.
Given an integer $m$, find $\sum_{i=0}^{m} f(i)$. That is, find the sum of all $f(i)$ for $i$ from $0$ to $m$.
-----Input-----
The first line contains three integers $m, a, b$ ($1 \leq m \leq 10^9, 1 \leq a,b \leq 10^5$).
-----Output-----
Print a single integer, the desired sum.
-----Examples-----
Input
7 5 3
Output
19
Input
1000000000 1 2019
Output
500000001500000001
Input
100 100000 1
Output
101
Input
6 4 5
Output
10
-----Note-----
In the first example, we must find $f(0)+f(1)+\ldots+f(7)$. We have $f(0) = 1, f(1) = 1, f(2) = 1, f(3) = 1, f(4) = 1, f(5) = 3, f(6) = 3, f(7) = 8$. The sum of these values is $19$.
In the second example, we have $f(i) = i+1$, so we want to find $\sum_{i=0}^{10^9} i+1$.
In the third example, the frog can't make any jumps in any case.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n1 2 -3\\n\", \"8\\n9 -12 3 4 -4 -10 7 3\\n\", \"1\\n0\\n\", \"4\\n1 2 3 -5\\n\", \"6\\n0 0 0 0 0 0\\n\", \"7\\n0 0 0 0 3 -3 0\\n\", \"5\\n0 0 -4 0 0\\n\", \"100\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -38 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100\\n0 0 -17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 17 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"3\\n1 -3 3\\n\", \"3\\n1 0 -1\\n\", \"3\\n3 0 0\\n\", \"3\\n0 0 0\\n\", \"3\\n-3 3 0\\n\", \"4\\n3 -2 -1 3\\n\", \"4\\n-1 0 1 0\\n\", \"4\\n0 0 0 3\\n\", \"4\\n0 0 0 0\\n\", \"4\\n3 0 -3 0\\n\", \"5\\n-3 2 2 0 -2\\n\", \"5\\n0 -1 2 0 -1\\n\", \"5\\n0 2 0 0 0\\n\", \"5\\n0 0 0 0 0\\n\", \"5\\n0 0 0 0 0\\n\", \"20\\n101 89 -166 -148 -38 -135 -138 193 14 -134 -185 -171 -52 -191 195 39 -148 200 51 -73\\n\", \"20\\n-118 -5 101 7 9 144 55 -55 -9 -126 -71 -71 189 -64 -187 123 0 -48 -12 138\\n\", \"20\\n-161 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"20\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"20\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 -137 0 0 0 0 137\\n\", \"40\\n64 -94 -386 -78 35 -233 33 82 -5 -200 368 -259 124 353 390 -305 -247 -133 379 44 133 -146 151 -217 -16 53 -157 186 -203 -8 117 -71 272 -290 -97 133 52 113 -280 -176\\n\", \"40\\n120 -96 -216 131 231 -80 -166 -102 16 227 -120 105 43 -83 -53 229 24 190 -268 119 230 348 -33 19 0 -187 -349 -25 80 -38 -30 138 -104 337 -98 0 1 -66 -243 -231\\n\", \"40\\n0 0 0 0 0 0 324 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"40\\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\\n\", \"40\\n0 0 0 0 0 308 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -308 0 0 0 0 0 0 0\\n\", \"60\\n-288 -213 -213 -23 496 489 137 -301 -219 -296 -577 269 -153 -52 -505 -138 -377 500 -256 405 588 274 -115 375 -93 117 -360 -160 429 -339 502 310 502 572 -41 -26 152 -203 562 -525 -179 -67 424 62 -329 -127 352 -474 417 -30 518 326 200 -598 471 107 339 107 -9 -244\\n\", \"60\\n112 141 -146 -389 175 399 -59 327 -41 397 263 -422 157 0 471 -2 -381 -438 99 368 173 9 -171 118 24 111 120 70 11 317 -71 -574 -139 0 -477 -211 -116 -367 16 568 -75 -430 75 -179 -21 156 291 -422 441 -224 -8 -337 -104 381 60 -138 257 91 103 -359\\n\", \"60\\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 -238 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"60\\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\\n\", \"60\\n0 0 0 0 0 0 0 0 0 -98 0 0 0 0 0 0 0 0 98 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"80\\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 668 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"80\\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\\n\", \"80\\n0 0 0 0 0 0 0 0 0 0 0 0 -137 137 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100\\n0 0 697 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"100\\n0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 -475 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 475 0 0 0 0\\n\", \"4\\n0 0 3 -3\\n\", \"4\\n1 0 0 0\\n\", \"4\\n3 3 3 3\\n\", \"2\\n0 1\\n\", \"4\\n0 -1 1 0\\n\", \"1\\n1\\n\", \"5\\n0 0 1 0 0\\n\", \"4\\n0 0 1 0\\n\", \"10\\n1 2 0 0 3 -3 0 0 -3 0\\n\", \"3\\n0 -1 0\\n\", \"2\\n1 0\\n\", \"5\\n3 -3 0 0 0\\n\", \"3\\n0 1 0\\n\", \"4\\n0 0 0 1\\n\", \"4\\n1 -1 1 -1\\n\", \"1\\n-1\\n\", \"2\\n1 1\\n\", \"2\\n1 -1\\n\", \"2\\n0 0\\n\", \"2\\n0 -1\\n\", \"2\\n-1 1\\n\", \"2\\n-1 0\\n\", \"2\\n-1 -1\\n\", \"3\\n5 -5 5\\n\", \"5\\n1 0 -1 0 1\\n\", \"6\\n0 0 0 3 0 0\\n\", \"3\\n1 -1 1\\n\"], \"outputs\": [\"YES\\n3\\n1 1\\n2 2\\n3 3\\n\", \"YES\\n8\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n\", \"NO\\n\", \"YES\\n4\\n1 1\\n2 2\\n3 3\\n4 4\\n\", \"NO\\n\", \"YES\\n2\\n1 5\\n6 7\\n\", \"YES\\n1\\n1 5\\n\", \"YES\\n1\\n1 100\\n\", \"NO\\n\", \"YES\\n2\\n1 34\\n35 100\\n\", \"YES\\n3\\n1 1\\n2 2\\n3 3\\n\", \"YES\\n2\\n1 2\\n3 3\\n\", \"YES\\n1\\n1 3\\n\", \"NO\\n\", \"YES\\n2\\n1 1\\n2 3\\n\", \"YES\\n4\\n1 1\\n2 2\\n3 3\\n4 4\\n\", \"YES\\n2\\n1 2\\n3 4\\n\", \"YES\\n1\\n1 4\\n\", \"NO\\n\", \"YES\\n2\\n1 2\\n3 4\\n\", \"YES\\n4\\n1 1\\n2 2\\n3 4\\n5 5\\n\", \"YES\\n3\\n1 2\\n3 4\\n5 5\\n\", \"YES\\n1\\n1 5\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n20\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n9 9\\n10 10\\n11 11\\n12 12\\n13 13\\n14 14\\n15 15\\n16 16\\n17 17\\n18 18\\n19 19\\n20 20\\n\", \"YES\\n19\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n9 9\\n10 10\\n11 11\\n12 12\\n13 13\\n14 14\\n15 15\\n16 17\\n18 18\\n19 19\\n20 20\\n\", \"YES\\n1\\n1 20\\n\", \"NO\\n\", \"YES\\n2\\n1 19\\n20 20\\n\", \"YES\\n40\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n9 9\\n10 10\\n11 11\\n12 12\\n13 13\\n14 14\\n15 15\\n16 16\\n17 17\\n18 18\\n19 19\\n20 20\\n21 21\\n22 22\\n23 23\\n24 24\\n25 25\\n26 26\\n27 27\\n28 28\\n29 29\\n30 30\\n31 31\\n32 32\\n33 33\\n34 34\\n35 35\\n36 36\\n37 37\\n38 38\\n39 39\\n40 40\\n\", \"YES\\n38\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n9 9\\n10 10\\n11 11\\n12 12\\n13 13\\n14 14\\n15 15\\n16 16\\n17 17\\n18 18\\n19 19\\n20 20\\n21 21\\n22 22\\n23 23\\n24 25\\n26 26\\n27 27\\n28 28\\n29 29\\n30 30\\n31 31\\n32 32\\n33 33\\n34 34\\n35 36\\n37 37\\n38 38\\n39 39\\n40 40\\n\", \"YES\\n1\\n1 40\\n\", \"NO\\n\", \"YES\\n2\\n1 32\\n33 40\\n\", \"YES\\n60\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n9 9\\n10 10\\n11 11\\n12 12\\n13 13\\n14 14\\n15 15\\n16 16\\n17 17\\n18 18\\n19 19\\n20 20\\n21 21\\n22 22\\n23 23\\n24 24\\n25 25\\n26 26\\n27 27\\n28 28\\n29 29\\n30 30\\n31 31\\n32 32\\n33 33\\n34 34\\n35 35\\n36 36\\n37 37\\n38 38\\n39 39\\n40 40\\n41 41\\n42 42\\n43 43\\n44 44\\n45 45\\n46 46\\n47 47\\n48 48\\n49 49\\n50 50\\n51 51\\n52 52\\n53 53\\n54 54\\n55 55\\n56 56\\n57 57\\n58 58\\n59 59\\n60 60\\n\", \"YES\\n58\\n1 1\\n2 2\\n3 3\\n4 4\\n5 5\\n6 6\\n7 7\\n8 8\\n9 9\\n10 10\\n11 11\\n12 12\\n13 14\\n15 15\\n16 16\\n17 17\\n18 18\\n19 19\\n20 20\\n21 21\\n22 22\\n23 23\\n24 24\\n25 25\\n26 26\\n27 27\\n28 28\\n29 29\\n30 30\\n31 31\\n32 32\\n33 34\\n35 35\\n36 36\\n37 37\\n38 38\\n39 39\\n40 40\\n41 41\\n42 42\\n43 43\\n44 44\\n45 45\\n46 46\\n47 47\\n48 48\\n49 49\\n50 50\\n51 51\\n52 52\\n53 53\\n54 54\\n55 55\\n56 56\\n57 57\\n58 58\\n59 59\\n60 60\\n\", \"YES\\n1\\n1 60\\n\", \"NO\\n\", \"YES\\n2\\n1 18\\n19 60\\n\", \"YES\\n1\\n1 80\\n\", \"NO\\n\", \"YES\\n2\\n1 13\\n14 80\\n\", \"YES\\n1\\n1 100\\n\", \"NO\\n\", \"YES\\n2\\n1 95\\n96 100\\n\", \"YES\\n2\\n1 3\\n4 4\\n\", \"YES\\n1\\n1 4\\n\", \"YES\\n4\\n1 1\\n2 2\\n3 3\\n4 4\\n\", \"YES\\n1\\n1 2\\n\", \"YES\\n2\\n1 2\\n3 4\\n\", \"YES\\n1\\n1 1\\n\", \"YES\\n1\\n1 5\\n\", \"YES\\n1\\n1 4\\n\", \"YES\\n5\\n1 1\\n2 4\\n5 5\\n6 8\\n9 10\\n\", \"YES\\n1\\n1 3\\n\", \"YES\\n1\\n1 2\\n\", \"YES\\n2\\n1 1\\n2 5\\n\", \"YES\\n1\\n1 3\\n\", \"YES\\n1\\n1 4\\n\", \"YES\\n4\\n1 1\\n2 2\\n3 3\\n4 4\\n\", \"YES\\n1\\n1 1\\n\", \"YES\\n2\\n1 1\\n2 2\\n\", \"YES\\n2\\n1 1\\n2 2\\n\", \"NO\\n\", \"YES\\n1\\n1 2\\n\", \"YES\\n2\\n1 1\\n2 2\\n\", \"YES\\n1\\n1 2\\n\", \"YES\\n2\\n1 1\\n2 2\\n\", \"YES\\n3\\n1 1\\n2 2\\n3 3\\n\", \"YES\\n3\\n1 2\\n3 4\\n5 5\\n\", \"YES\\n1\\n1 6\\n\", \"YES\\n3\\n1 1\\n2 2\\n3 3\\n\"]}", "source": "primeintellect"}
|
One spring day on his way to university Lesha found an array A. Lesha likes to split arrays into several parts. This time Lesha decided to split the array A into several, possibly one, new arrays so that the sum of elements in each of the new arrays is not zero. One more condition is that if we place the new arrays one after another they will form the old array A.
Lesha is tired now so he asked you to split the array. Help Lesha!
-----Input-----
The first line contains single integer n (1 ≤ n ≤ 100) — the number of elements in the array A.
The next line contains n integers a_1, a_2, ..., a_{n} ( - 10^3 ≤ a_{i} ≤ 10^3) — the elements of the array A.
-----Output-----
If it is not possible to split the array A and satisfy all the constraints, print single line containing "NO" (without quotes).
Otherwise in the first line print "YES" (without quotes). In the next line print single integer k — the number of new arrays. In each of the next k lines print two integers l_{i} and r_{i} which denote the subarray A[l_{i}... r_{i}] of the initial array A being the i-th new array. Integers l_{i}, r_{i} should satisfy the following conditions: l_1 = 1 r_{k} = n r_{i} + 1 = l_{i} + 1 for each 1 ≤ i < k.
If there are multiple answers, print any of them.
-----Examples-----
Input
3
1 2 -3
Output
YES
2
1 2
3 3
Input
8
9 -12 3 4 -4 -10 7 3
Output
YES
2
1 2
3 8
Input
1
0
Output
NO
Input
4
1 2 3 -5
Output
YES
4
1 1
2 2
3 3
4 4
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3454\\n\", \"10\\n\", \"111111\\n\", \"8996988892\\n\", \"5555555555\\n\", \"1\\n\", \"8147522776919916277306861346922924221557534659480258977017038624458370459299847590937757625791239188\\n\", \"8\\n\", \"14\\n\", \"2363\\n\", \"3554\\n\", \"312\\n\", \"7674\\n\", \"126\\n\", \"344\\n\", \"976\\n\", \"3144\\n\", \"1492\\n\", \"1000\\n\", \"303\\n\", \"111111111111111111111171111111111111111111111111111112\\n\", \"3111111111111111111111411111111111111111111141111111441\\n\", \"7486897358699809313898215064443112428113331907121460549315254356705507612143346801724124391167293733\\n\", \"1787075866\\n\", \"836501278190105055089734832290981\\n\", \"1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\\n\", \"2222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222\\n\", \"3333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333\\n\", \"1000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"5555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555\\n\", \"66666666666666666666666666666666666666666666666666666666666666666666666666666\\n\", \"88888888888888888888888888888888888888888888888888888888888888888888888888888888\\n\", \"9999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999\\n\", \"353\\n\", \"39\\n\", \"3697519\\n\", \"6673177113\\n\", \"6666351371557713735\\n\", \"17943911115335733153157373517\\n\", \"619715515939999957957971971757533319177373\\n\", \"4655797151375799393395377959959573533195153397997597195199777159133\\n\", \"5531399953495399131957773999751571911139197159755793777773799119333593915333593153173775755771193715\\n\", \"1319571733331774579193199551977735199771153997797535591739153377377111795579371959933533573517995559\\n\", \"3313393139519343957311771319713797711159791515393917539133957799131393735795317131513557337319131993\\n\", \"526\\n\", \"513\\n\", \"674\\n\", \"8353\\n\", \"3957\\n\", \"4426155776626276881222352363321488266188669874572115686737742545442766138617391954346963915982759371\\n\", \"9592419524227735697379444145348135927975358347769514686865768941989693174565893724972575152874281772\\n\", \"94552498866729239313265973246288189853135485783461\\n\", \"647934465937812\\n\", \"1327917795375366484539554526312125336\\n\", \"295971811535848297878828225646878276486982655866912496735794542\\n\", \"7217495392264549817889283233368819844137671271383133997418139697797385729777632527678136\\n\", \"11111111111111111111112111111111\\n\", \"262626262626262626262626262626262626\\n\", \"1000000000000000000000000000000000000\\n\", \"9969929446\\n\", \"43523522125549722432232256557771715456345544922144\\n\", \"9344661521956564755454992376342544254667536539463277572111263273131199437332443253296774957\\n\", \"1946374341357914632311595531429723377642197432217137651552992479954116463332543456759911377223599715\\n\", \"461259\\n\", \"461592\\n\", \"46159237\\n\", \"42367\\n\", \"42376\\n\", \"42376159\\n\", \"444444444444444444444444444444666666666666666666666666666666222222222222222222222222222222\\n\", \"0\\n\", \"33332\\n\", \"6499999999\\n\"], \"outputs\": [\"YES\\n344\\n\", \"YES\\n0\\n\", \"NO\\n\", \"YES\\n8\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n32\\n\", \"YES\\n64\\n\", \"YES\\n16\\n\", \"YES\\n344\\n\", \"YES\\n96\\n\", \"YES\\n344\\n\", \"YES\\n192\\n\", \"YES\\n0\\n\", \"YES\\n0\\n\", \"YES\\n72\\n\", \"YES\\n344\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n0\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n8\\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\\n56\\n\", \"NO\\n\", \"YES\\n64\\n\", \"YES\\n8\\n\", \"NO\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n8\\n\", \"YES\\n112\\n\", \"NO\\n\", \"YES\\n0\\n\", \"YES\\n96\\n\", \"YES\\n32\\n\", \"YES\\n96\\n\", \"YES\\n16\\n\", \"NO\\n\", \"YES\\n152\\n\", \"YES\\n152\\n\", \"NO\\n\", \"YES\\n376\\n\", \"YES\\n376\\n\", \"NO\\n\", \"YES\\n0\\n\", \"YES\\n32\\n\", \"YES\\n64\\n\"]}", "source": "primeintellect"}
|
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn't contain leading zeroes.
Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at all) so that the result contains at least one digit, forms a non-negative integer, doesn't have leading zeroes and is divisible by 8. After the removing, it is forbidden to rearrange the digits.
If a solution exists, you should print it.
-----Input-----
The single line of the input contains a non-negative integer n. The representation of number n doesn't contain any leading zeroes and its length doesn't exceed 100 digits.
-----Output-----
Print "NO" (without quotes), if there is no such way to remove some digits from number n.
Otherwise, print "YES" in the first line and the resulting number after removing digits from number n in the second line. The printed number must be divisible by 8.
If there are multiple possible answers, you may print any of them.
-----Examples-----
Input
3454
Output
YES
344
Input
10
Output
YES
0
Input
111111
Output
NO
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0.375
|
{"tests": "{\"inputs\": [\"00\\n00\\n\", \"00X00X0XXX0\\n0XXX0X00X00\\n\", \"0X0X0\\n0X0X0\\n\", \"0XXX0\\n00000\\n\", \"0\\n0\\n\", \"0\\nX\\n\", \"X\\n0\\n\", \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\n\", \"0000X0XX000X0XXXX0X0XXXX000X0X0XX000XXX0X00XX00XX00X0000XX0XX00X0X00X0X00X0XX000XX00XXXXXXXXXXXXXXX0\\nX00XX0XX00XXXX00XXXX00XX0000000000XXX0X00XX0XX00XXX00X00X0XX0000X00XXXXXXX00X00000XXX00XXX00XXX0X0XX\\n\", \"X\\nX\\n\", \"X0\\n00\\n\", \"0X\\n00\\n\", \"00\\nX0\\n\", \"00\\n0X\\n\", \"XX\\nXX\\n\", \"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"00000\\n00000\\n\", \"00000000\\nXXXXXXXX\\n\", \"X00X0XXXX0\\nX0XXX0XX00\\n\", \"00000XX0000000000000\\n0X00000XX0000X00X000\\n\", \"XXX00XXX0XXX0X0XXXXX\\nXXX00XXX0XXX0X0XXXXX\\n\", \"000X00000X00000X00000000000000\\n000X00000X00000X00000000000000\\n\", \"00X0X00000X0X0X00X0X0XXX0000X0\\n0000000X00X000X000000000X00000\\n\", \"000000000000000000000000000000000000000000\\n00X000X00X00X0000X0XX000000000X000X0000000\\n\", \"X0XXX00XX00X0XXXXXXXX0X0X0XX0X0X0XXXXX00X0XXXX00XX000XX0X000XX000XX\\n0000000000000000000000000000000000000000000000000000000000000000000\\n\", \"0000000000000000000000000000X00000000000000XX0X00000X0000000000000000000000000000000000000\\n0000000000000000000000000X0000000000000000000000000000000000000000000000000000000000000000\\n\", \"0000000000000000000000000000000000000X000000000000000000000X0X00000000000000000000000000000\\n000000000000000000000000000X0X0000000000000000000000000000000000000000000000000000000000000\\n\", \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\nX0X00000000000000000000000000X000000000X0000X00X000000XX000000X0X00000000X000X000000X0000X00\\n\", \"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\n\", \"XXXXXXXXXXXXXXXXXXXXXXX0XXX000XXXX0XXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXX0X0XXXXXXXXXXXXXXXXXX\\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"00000XX0000000000000000000000000000000000000000000X0000000X0000000000000X0000000000000000X00000\\n00000XX0000000000000000000000000000000000000000000X0000000X0000000000000X0000000000000000X00000\\n\", \"000000000000000X0000000000000000000000000XX0000000000000000X00000000000000000000000X000000000000\\n000000000000000X0000000000000000000000000XX0000000000000000X00000000000000000000000X000000000000\\n\", \"000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n0000000000000000000X000X0000000000X00000000X00000000000000000000000000000000000000000000000000000000\\n\", \"000000000000000000X00X000000000000000000000000000000000000000X00000000X0000000X0000000000000000000X0\\n000000000000000000X00X000000000000000000000000000000000000000X00000000X0000000X0000000000000000000X0\\n\", \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX0XXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXX\\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XX0XXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXX\\n\", \"XXXXXXXXXXX0X00XXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXX00XXXXXXXXX0X0XXX0XX\\nXXXXXXXXXXX0X00XXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXX00XXXXXXXXX0X0XXX0XX\\n\", \"0X0X0\\nX0X0X\\n\", \"X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0\\n0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X\\n\", \"X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0\\n0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X\\n\", \"X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X\\n0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0\\n\", \"0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X\\nX0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0X0\\n\", \"00000000000000X0000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX00XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\n\", \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX00\\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0\\n\", \"00XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\nX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\n\", \"XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX0XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\nXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX00XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX\\n\", \"0000000000000000000000000000000000000000000000000000000000X0000000000000000000000000000000000000X000\\n0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000XX\\n000000000000000000000000000000000X00000000000000000X000000000000000000000000000000000000000000000000\\n\", \"0000X00X000000X0000X00X00X0000000000X0000000X000X00000X0X000XXX00000000XX0XX000000000000X00000000000\\n000000000XX000000X00000X00X00X00000000000000000X0X000XX0000000000000X0X00X0000X0000X000000X0000000XX\\n\", \"0000000000000000000000000000000000X0000000000000000000000000000000000000000000000000000000000000000\\n000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\\n\", \"00000000000000000000000000X000000000000000000000000000000000000000000X00000X0000X000000000000000000\\n000X0000000000X000000000000000000000X0000000000X0X0000000000000000000X00000000000000000000000000000\\n\", \"000X00XX0XX0X00X0XX0XXXX00XXX0X00000000XXX0XXXXXXX0X00X00XX00X0XXX00000XXXX0XX00X00XXX00X0X0XXXX000\\nXXXXX000X0XXX000XXXXX0XX0000XX0XXX0XXX000XXX00XXXXX00X00XX0000X0XX0XX0XX000X0XX00X00XX00XX00X00XX0X\\n\", \"X0X0XXXX0XXXXXXXXXX00XXXXXXXXXXXXXXXXXX0XXXXX0XX0X00X0XXXXXXX0X0XXXXXXXXX0X0X0XX0XX0000XXXX00XXX0XX\\nXX0XXXXXXX0X0X00XXXX0X000X0XXXXXX0XXX0X0XXXX0XXXXXXXXXXXXXX00XX00XXX0XXXXXXXXXX00XXXX0XXXX0XXXXXXXX\\n\", \"000\\n000\\n\", \"000000000000000000000\\n000000000000000000000\\n\", \"00000000000000000000000000000000000000\\n00000000000000000000000000000000000000\\n\", \"0000\\n00X0\\n\", \"000\\n00X\\n\", \"X000\\nX000\\n\", \"X0000X000XX00000000000000000000XX000X0000X00X0X00XX000000000000X0000X0X0XX00\\n00X00XX00000000X0000000X000X000X0X0X00X000X0X0X0000X0000000X000XX000XX000X00\\n\", \"0X00\\n0000\\n\", \"0X0\\n000\\n\", \"000000\\n000000\\n\", \"X00X0\\n00000\\n\", \"000\\n0X0\\n\", \"X000\\n00X0\\n\", \"X0000\\n00000\\n\", \"X000X\\nX000X\\n\", \"X0000X\\n00000X\\n\", \"000000000000\\n000000000000\\n\", \"00000\\n0000X\\n\"], \"outputs\": [\"1\", \"4\", \"0\", \"2\", \"0\", \"0\", \"0\", \"0\", \"18\", \"0\", \"1\", \"1\", \"1\", \"1\", \"0\", \"66\", \"3\", \"0\", \"2\", \"10\", \"1\", \"17\", \"12\", \"23\", \"24\", \"57\", \"58\", \"55\", \"2\", \"7\", \"56\", \"59\", \"64\", \"65\", \"60\", \"0\", \"2\", \"0\", \"0\", \"0\", \"0\", \"0\", \"66\", \"1\", \"1\", \"1\", \"0\", \"66\", \"65\", \"49\", \"65\", \"62\", \"16\", \"4\", \"2\", \"14\", \"25\", \"2\", \"1\", \"2\", \"33\", \"2\", \"1\", \"4\", \"2\", \"1\", \"2\", \"3\", \"2\", \"3\", \"8\", \"3\"]}", "source": "primeintellect"}
|
Bishwock is a chess figure that consists of three squares resembling an "L-bar". This figure can be rotated by 90, 180 and 270 degrees so it can have four possible states:
XX XX .X X.
X. .X XX XX
Bishwocks don't attack any squares and can even occupy on the adjacent squares as long as they don't occupy the same square.
Vasya has a board with $2\times n$ squares onto which he wants to put some bishwocks. To his dismay, several squares on this board are already occupied by pawns and Vasya can't put bishwocks there. However, pawns also don't attack bishwocks and they can occupy adjacent squares peacefully.
Knowing the positions of pawns on the board, help Vasya to determine the maximum amount of bishwocks he can put onto the board so that they wouldn't occupy the same squares and wouldn't occupy squares with pawns.
-----Input-----
The input contains two nonempty strings that describe Vasya's board. Those strings contain only symbols "0" (zero) that denote the empty squares and symbols "X" (uppercase English letter) that denote the squares occupied by pawns. Strings are nonempty and are of the same length that does not exceed $100$.
-----Output-----
Output a single integer — the maximum amount of bishwocks that can be placed onto the given board.
-----Examples-----
Input
00
00
Output
1
Input
00X00X0XXX0
0XXX0X00X00
Output
4
Input
0X0X0
0X0X0
Output
0
Input
0XXX0
00000
Output
2
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"6 9 2 4\\n\", \"6 10 2 4\\n\", \"6 5 4 3\\n\", \"2 2 1 1\\n\", \"10 4 6 10\\n\", \"3 1 1 1\\n\", \"2 1 1 1\\n\", \"1000000 51923215 2302 10000\\n\", \"10 11 3 2\\n\", \"20 50 10 25\\n\", \"10 10 5 20\\n\", \"15 65 5 50\\n\", \"10 19 1 5\\n\", \"10 19 9 5\\n\", \"23 46 12 2\\n\", \"23 46 12 3\\n\", \"20 20 19 1\\n\", \"20 23 17 2\\n\", \"20 18 9 2\\n\", \"100 70 50 1\\n\", \"100 70 70 2\\n\", \"140 480 1 40\\n\", \"140 480 139 40\\n\", \"1000000 1000000000 1 1000\\n\", \"1000000 1000000000 999999 1000\\n\", \"1000000 159842934 2376 1000\\n\", \"2 1000000000 1 1000\\n\", \"100000 1000000 50000 1000\\n\", \"1000000 1000000 500000 1000\\n\", \"1000000 1000000 500000 10000\\n\", \"1000000 2500000 500000 9999\\n\", \"1000000 1500000 500000 9999\\n\", \"1000000 1500000 500000 10000\\n\", \"1000000 1 1 1\\n\", \"2 1000000000 1 1\\n\", \"1000000 1000000000 1 1\\n\", \"1000000 1 999999 1\\n\", \"1000000 1000000000 999999 1\\n\", \"2 1 1 10000\\n\", \"1000000 1 1 10000\\n\", \"1000000 1000000000 1 10000\\n\", \"1000000 1 999999 10000\\n\", \"2 1000000000 1 10000\\n\", \"1000000 1000000000 999999 10000\\n\", \"10000 78393 3000 9999\\n\", \"1000000 8839233 302200 9999\\n\", \"900005 3333333 210000 9999\\n\", \"999999 39486793 138762 9282\\n\", \"1000000 8739233 400000 9999\\n\", \"1000000 500000 500000 1\\n\", \"1000000 70000000 333333 9999\\n\", \"6 7 4 2\\n\", \"3 1 2 1\\n\", \"10 8 8 2\\n\", \"150 100 1 1\\n\", \"6 4 4 2\\n\", \"10 10 9 2\\n\", \"10 5 6 1\\n\", \"3 3 2 2\\n\", \"4 4 3 2\\n\", \"10 4 7 1\\n\", \"100 5 97 1\\n\", \"7 11 6 2\\n\", \"100 50 99 1\\n\", \"5 3 4 1\\n\", \"51 81 36 38\\n\", \"10 8 6 2\\n\", \"10 8 7 2\\n\", \"10 11 6 2\\n\", \"5 4 4 2\\n\", \"6 5 5 2\\n\", \"100 159 80 2\\n\"], \"outputs\": [\"4\\n\", \"2\\n\", \"-1\\n\", \"0\\n\", \"-1\\n\", \"-1\\n\", \"1\\n\", \"199\\n\", \"-1\\n\", \"11\\n\", \"20\\n\", \"12\\n\", \"3\\n\", \"3\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"-1\\n\", \"1\\n\", \"2\\n\", \"19\\n\", \"18\\n\", \"0\\n\", \"0\\n\", \"6\\n\", \"0\\n\", \"100\\n\", \"1000\\n\", \"10000\\n\", \"4998\\n\", \"9997\\n\", \"9998\\n\", \"-1\\n\", \"0\\n\", \"0\\n\", \"-1\\n\", \"0\\n\", \"-1\\n\", \"-1\\n\", \"10\\n\", \"-1\\n\", \"0\\n\", \"10\\n\", \"1428\\n\", \"1249\\n\", \"3332\\n\", \"244\\n\", \"1249\\n\", \"1\\n\", \"142\\n\", \"2\\n\", \"-1\\n\", \"2\\n\", \"-1\\n\", \"2\\n\", \"2\\n\", \"-1\\n\", \"2\\n\", \"2\\n\", \"-1\\n\", \"-1\\n\", \"1\\n\", \"-1\\n\", \"-1\\n\", \"36\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"1\\n\"]}", "source": "primeintellect"}
|
A bus moves along the coordinate line Ox from the point x = 0 to the point x = a. After starting from the point x = 0, it reaches the point x = a, immediately turns back and then moves to the point x = 0. After returning to the point x = 0 it immediately goes back to the point x = a and so on. Thus, the bus moves from x = 0 to x = a and back. Moving from the point x = 0 to x = a or from the point x = a to x = 0 is called a bus journey. In total, the bus must make k journeys.
The petrol tank of the bus can hold b liters of gasoline. To pass a single unit of distance the bus needs to spend exactly one liter of gasoline. The bus starts its first journey with a full petrol tank.
There is a gas station in point x = f. This point is between points x = 0 and x = a. There are no other gas stations on the bus route. While passing by a gas station in either direction the bus can stop and completely refuel its tank. Thus, after stopping to refuel the tank will contain b liters of gasoline.
What is the minimum number of times the bus needs to refuel at the point x = f to make k journeys? The first journey starts in the point x = 0.
-----Input-----
The first line contains four integers a, b, f, k (0 < f < a ≤ 10^6, 1 ≤ b ≤ 10^9, 1 ≤ k ≤ 10^4) — the endpoint of the first bus journey, the capacity of the fuel tank of the bus, the point where the gas station is located, and the required number of journeys.
-----Output-----
Print the minimum number of times the bus needs to refuel to make k journeys. If it is impossible for the bus to make k journeys, print -1.
-----Examples-----
Input
6 9 2 4
Output
4
Input
6 10 2 4
Output
2
Input
6 5 4 3
Output
-1
-----Note-----
In the first example the bus needs to refuel during each journey.
In the second example the bus can pass 10 units of distance without refueling. So the bus makes the whole first journey, passes 4 units of the distance of the second journey and arrives at the point with the gas station. Then it can refuel its tank, finish the second journey and pass 2 units of distance from the third journey. In this case, it will again arrive at the point with the gas station. Further, he can refill the tank up to 10 liters to finish the third journey and ride all the way of the fourth journey. At the end of the journey the tank will be empty.
In the third example the bus can not make all 3 journeys because if it refuels during the second journey, the tanks will contain only 5 liters of gasoline, but the bus needs to pass 8 units of distance until next refueling.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3 10 1 3\\n3 4 7\\n\", \"2 9 2 3\\n6 4\\n\", \"10 100 2 8\\n93 35 24 87 39 46 86 37 73 33\\n\", \"10 1000000000 8905990 20319560\\n233244997 997992814 242452779 497363176 572234096 126615858 886769539 662035052 989086824 716655858\\n\", \"100 1000 1 4\\n228 420 360 642 442 551 940 343 24 83 928 110 663 548 704 461 942 799 283 746 371 204 435 209 986 489 918 526 496 321 233 643 208 717 806 18 291 431 521 631 3 450 711 602 401 60 680 930 625 891 161 279 510 529 546 338 473 925 446 786 384 952 260 649 865 916 789 71 103 997 484 89 408 129 953 670 568 55 287 511 369 225 950 539 652 567 730 499 687 90 779 848 801 606 82 853 967 776 951 329\\n\", \"100 600 1 4\\n9 536 518 59 229 377 72 203 81 309 304 321 55 439 287 505 3 410 582 351 440 568 584 259 22 415 348 147 404 277 477 323 537 75 548 324 338 198 145 182 271 496 256 329 592 132 291 222 115 587 54 158 154 103 356 15 36 76 402 27 223 551 267 527 51 34 417 573 479 398 425 71 485 20 262 566 467 131 524 352 330 541 146 53 322 436 366 86 88 272 96 456 388 319 149 470 129 162 353 346\\n\", \"1 2 1 5\\n1\\n\", \"1 3 1 2\\n2\\n\", \"1 5 1 2\\n2\\n\", \"1 1000000000 1000000000 2\\n999999999\\n\", \"1 100 1 1\\n4\\n\", \"1 1000000000 1 1000000000\\n2\\n\", \"3 12000 2000 3000\\n3000 9002 7001\\n\", \"4 30000 5000 6000\\n6000 16000 15000 21001\\n\", \"3 12000 2000 245\\n3000 9003 7001\\n\", \"4 30000 5000 1654\\n6000 16000 14999 21002\\n\", \"4 10000 500 500\\n700 600 1099 2000\\n\", \"3 20000 4000 3502\\n5000 8500 15000\\n\", \"4 10000 500 500\\n700 601 1099 2000\\n\", \"3 20000 4000 3502\\n5000 8501 15000\\n\", \"1 10 1 2\\n9\\n\", \"1 10 2 9\\n5\\n\", \"1 9 6 4\\n4\\n\", \"1 10 7 4\\n5\\n\", \"2 14 8 8\\n5 9\\n\", \"2 23 12 8\\n8 16\\n\", \"2 14 4 2\\n2 7\\n\", \"3 21 6 2\\n7 11 16\\n\", \"3 29 3 4\\n7 16 19\\n\", \"3 24 2 6\\n6 12 17\\n\", \"4 31 12 9\\n7 13 21 28\\n\", \"4 10 1 7\\n2 4 6 8\\n\", \"4 36 8 4\\n4 13 19 27\\n\", \"5 25 10 2\\n6 12 13 15 22\\n\", \"5 19 7 10\\n3 7 9 12 16\\n\", \"5 28 6 8\\n3 9 15 21 25\\n\", \"6 35 12 4\\n7 12 17 21 24 28\\n\", \"6 22 5 7\\n4 6 10 13 15 18\\n\", \"6 55 3 5\\n10 18 24 34 39 45\\n\", \"7 51 6 1\\n8 17 18 23 27 33 42\\n\", \"7 36 11 4\\n6 11 17 19 22 24 30\\n\", \"7 28 10 2\\n5 10 14 19 21 23 27\\n\", \"8 46 4 5\\n3 6 15 21 24 26 36 42\\n\", \"8 51 2 1\\n6 14 20 26 29 35 40 48\\n\", \"8 56 2 9\\n7 11 20 28 34 39 40 48\\n\", \"9 57 2 2\\n5 11 15 21 24 30 36 43 50\\n\", \"9 82 14 4\\n10 18 28 38 46 55 64 74 79\\n\", \"9 40 6 3\\n5 10 14 18 22 27 30 31 36\\n\", \"10 44 6 2\\n4 8 13 19 23 29 32 33 37 41\\n\", \"10 42 1 3\\n1 6 10 15 17 22 24 29 33 38\\n\", \"10 82 2 5\\n9 17 27 37 44 51 57 62 67 72\\n\", \"11 69 4 9\\n7 14 20 26 29 35 40 46 52 58 64\\n\", \"11 65 1 7\\n7 11 14 21 24 30 37 44 50 56 59\\n\", \"11 77 10 10\\n7 14 17 24 29 34 38 47 56 64 69\\n\", \"12 78 3 1\\n4 11 19 22 30 38 43 51 56 59 67 73\\n\", \"12 89 14 9\\n6 11 18 24 33 37 45 51 60 69 71 80\\n\", \"12 13 6 7\\n1 2 3 4 5 6 7 8 9 10 11 12\\n\", \"13 91 1 3\\n5 12 17 22 29 36 43 49 57 64 70 74 84\\n\", \"13 87 5 6\\n7 10 18 24 31 40 41 48 54 63 69 78 81\\n\", \"13 46 2 4\\n1 4 9 13 15 19 21 23 25 30 35 37 42\\n\", \"14 93 1 1\\n8 15 19 21 28 36 44 51 56 63 67 74 79 85\\n\", \"14 62 11 4\\n5 10 15 18 22 26 31 34 39 42 44 47 52 57\\n\", \"14 109 10 1\\n8 15 25 29 38 48 57 65 70 79 81 89 94 100\\n\", \"15 97 4 4\\n3 7 13 23 29 35 39 45 49 50 60 68 72 81 87\\n\", \"15 77 4 8\\n7 14 16 20 26 33 36 43 44 48 52 59 61 66 70\\n\", \"15 56 1 5\\n5 10 15 20 21 25 29 31 34 37 38 41 43 47 52\\n\", \"2 1000000000 1 3\\n5 8\\n\", \"2 1000000000 1 2\\n5 8\\n\", \"2 1000000000 1 4\\n5 8\\n\", \"2 1000000000 2 4\\n5 8\\n\", \"2 1000000000 2 5\\n5 8\\n\"], \"outputs\": [\"RUN 2\\nJUMP 3\\nRUN 1\\nJUMP 2\\nRUN 2\\n\", \"IMPOSSIBLE\\n\", \"RUN 23\\nJUMP 2\\nRUN 7\\nJUMP 8\\nRUN 5\\nJUMP 2\\nRUN 25\\nJUMP 2\\nRUN 11\\nJUMP 3\\nRUN 4\\nJUMP 2\\nRUN 6\\n\", \"RUN 126615857\\nJUMP 2\\nRUN 106629137\\nJUMP 2\\nRUN 9207780\\nJUMP 2\\nRUN 254910395\\nJUMP 2\\nRUN 74870918\\nJUMP 2\\nRUN 89800954\\nJUMP 2\\nRUN 54620804\\nJUMP 2\\nRUN 170113679\\nJUMP 2\\nRUN 102317283\\nJUMP 8905992\\nRUN 2007185\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 1\\nJUMP 2\\n\", \"RUN 1\\nJUMP 2\\nRUN 2\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 1\\nJUMP 2\\nRUN 999999997\\n\", \"RUN 2999\\nJUMP 2\\nRUN 3999\\nJUMP 2003\\nRUN 2997\\n\", \"IMPOSSIBLE\\n\", \"RUN 2999\\nJUMP 2\\nRUN 3999\\nJUMP 2\\nRUN 2000\\nJUMP 2\\nRUN 2996\\n\", \"RUN 5999\\nJUMP 2\\nRUN 8997\\nJUMP 1003\\nRUN 5000\\nJUMP 2\\nRUN 8997\\n\", \"IMPOSSIBLE\\n\", \"RUN 4999\\nJUMP 3502\\nRUN 6498\\nJUMP 2\\nRUN 4999\\n\", \"RUN 600\\nJUMP 500\\nRUN 899\\nJUMP 2\\nRUN 7999\\n\", \"IMPOSSIBLE\\n\", \"RUN 8\\nJUMP 2\\n\", \"RUN 4\\nJUMP 2\\nRUN 4\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 5\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 6\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 9\\nJUMP 2\\nRUN 6\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 8\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 9\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 6\\nJUMP 2\\nRUN 2\\nJUMP 2\\nRUN 7\\nJUMP 2\\nRUN 6\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 3\\nJUMP 3\\nRUN 6\\nJUMP 2\\nRUN 7\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 8\\nJUMP 2\\nRUN 6\\nJUMP 2\\nRUN 8\\nJUMP 2\\nRUN 8\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 9\\n\", \"RUN 6\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 4\\nJUMP 5\\nRUN 4\\nJUMP 7\\nRUN 4\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 4\\n\", \"RUN 6\\nJUMP 2\\nRUN 2\\nJUMP 2\\nRUN 1\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 1\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 1\\nJUMP 2\\nRUN 5\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 4\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 6\\nJUMP 2\\nRUN 5\\nJUMP 2\\nRUN 4\\nJUMP 2\\nRUN 2\\nJUMP 2\\nRUN 8\\nJUMP 2\\nRUN 6\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"IMPOSSIBLE\\n\", \"RUN 4\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 3\\nJUMP 3\\nRUN 2\\nJUMP 2\\nRUN 2\\nJUMP 4\\nRUN 1\\nJUMP 2\\nRUN 1\\nJUMP 3\\nRUN 1\\nJUMP 4\\nRUN 2\\nJUMP 2\\nRUN 3\\nJUMP 2\\nRUN 3\\n\", \"RUN 4\\nJUMP 2\\nRUN 1\\nJUMP 2\\nRUN 999999991\\n\", \"RUN 4\\nJUMP 2\\nRUN 1\\nJUMP 2\\nRUN 999999991\\n\", \"RUN 4\\nJUMP 2\\nRUN 1\\nJUMP 2\\nRUN 999999991\\n\", \"IMPOSSIBLE\\n\", \"RUN 4\\nJUMP 5\\nRUN 999999991\\n\"]}", "source": "primeintellect"}
|
A sportsman starts from point x_{start} = 0 and runs to point with coordinate x_{finish} = m (on a straight line). Also, the sportsman can jump — to jump, he should first take a run of length of not less than s meters (in this case for these s meters his path should have no obstacles), and after that he can jump over a length of not more than d meters. Running and jumping is permitted only in the direction from left to right. He can start andfinish a jump only at the points with integer coordinates in which there are no obstacles. To overcome some obstacle, it is necessary to land at a point which is strictly to the right of this obstacle.
On the way of an athlete are n obstacles at coordinates x_1, x_2, ..., x_{n}. He cannot go over the obstacles, he can only jump over them. Your task is to determine whether the athlete will be able to get to the finish point.
-----Input-----
The first line of the input containsd four integers n, m, s and d (1 ≤ n ≤ 200 000, 2 ≤ m ≤ 10^9, 1 ≤ s, d ≤ 10^9) — the number of obstacles on the runner's way, the coordinate of the finishing point, the length of running before the jump and the maximum length of the jump, correspondingly.
The second line contains a sequence of n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ m - 1) — the coordinates of the obstacles. It is guaranteed that the starting and finishing point have no obstacles, also no point can have more than one obstacle, The coordinates of the obstacles are given in an arbitrary order.
-----Output-----
If the runner cannot reach the finishing point, print in the first line of the output "IMPOSSIBLE" (without the quotes).
If the athlete can get from start to finish, print any way to do this in the following format: print a line of form "RUN X>" (where "X" should be a positive integer), if the athlete should run for "X" more meters; print a line of form "JUMP Y" (where "Y" should be a positive integer), if the sportsman starts a jump and should remain in air for "Y" more meters.
All commands "RUN" and "JUMP" should strictly alternate, starting with "RUN", besides, they should be printed chronologically. It is not allowed to jump over the finishing point but it is allowed to land there after a jump. The athlete should stop as soon as he reaches finish.
-----Examples-----
Input
3 10 1 3
3 4 7
Output
RUN 2
JUMP 3
RUN 1
JUMP 2
RUN 2
Input
2 9 2 3
6 4
Output
IMPOSSIBLE
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"7 2\\n\", \"5 1\\n\", \"10 0\\n\", \"10 1\\n\", \"10 10\\n\", \"11 10\\n\", \"100 2\\n\", \"100 200\\n\", \"1000 1000\\n\", \"1000 31\\n\", \"1 0\\n\", \"2 0\\n\", \"3 0\\n\", \"4 0\\n\", \"5 0\\n\", \"15 0\\n\", \"153 0\\n\", \"1 1\\n\", \"2 1\\n\", \"3 1\\n\", \"4 1\\n\", \"5 1\\n\", \"15 1\\n\", \"153 1\\n\", \"1 2\\n\", \"2 2\\n\", \"3 2\\n\", \"4 2\\n\", \"5 2\\n\", \"15 2\\n\", \"153 2\\n\", \"1 3\\n\", \"2 3\\n\", \"3 3\\n\", \"4 3\\n\", \"5 3\\n\", \"15 3\\n\", \"153 3\\n\", \"1 4\\n\", \"2 4\\n\", \"3 4\\n\", \"4 4\\n\", \"5 4\\n\", \"15 4\\n\", \"153 4\\n\", \"1000 4\\n\", \"1 5\\n\", \"2 5\\n\", \"3 5\\n\", \"4 5\\n\", \"5 5\\n\", \"15 5\\n\", \"153 5\\n\", \"1000 5\\n\", \"3 1\\n\", \"5 2\\n\", \"1 4\\n\", \"1 1\\n\", \"1 6\\n\", \"8 3\\n\", \"1 2\\n\", \"5 3\\n\", \"7 3\\n\", \"39 4\\n\", \"4 2\\n\", \"20 4\\n\", \"6 4\\n\", \"1 3\\n\", \"1 0\\n\", \"11 2\\n\"], \"outputs\": [\"2\\n1 6 \\n\", \"2\\n1 4 \\n\", \"10\\n1 2 3 4 5 6 7 8 9 10 \\n\", \"4\\n1 4 7 10 \\n\", \"1\\n10\\n\", \"1\\n11\\n\", \"20\\n3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 83 88 93 98 \\n\", \"1\\n100\\n\", \"1\\n1000\\n\", \"16\\n28 91 154 217 280 343 406 469 532 595 658 721 784 847 910 973 \\n\", \"1\\n1\\n\", \"2\\n1 2 \\n\", \"3\\n1 2 3 \\n\", \"4\\n1 2 3 4 \\n\", \"5\\n1 2 3 4 5 \\n\", \"15\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 \\n\", \"153\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 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 \\n\", \"1\\n1\\n\", \"1\\n2\\n\", \"1\\n2\\n\", \"2\\n1 4 \\n\", \"2\\n1 4 \\n\", \"5\\n2 5 8 11 14 \\n\", \"51\\n2 5 8 11 14 17 20 23 26 29 32 35 38 41 44 47 50 53 56 59 62 65 68 71 74 77 80 83 86 89 92 95 98 101 104 107 110 113 116 119 122 125 128 131 134 137 140 143 146 149 152 \\n\", \"1\\n1\\n\", \"1\\n2\\n\", \"1\\n3\\n\", \"1\\n3\\n\", \"1\\n3\\n\", \"3\\n3 8 13 \\n\", \"31\\n2 7 12 17 22 27 32 37 42 47 52 57 62 67 72 77 82 87 92 97 102 107 112 117 122 127 132 137 142 147 152 \\n\", \"1\\n1\\n\", \"1\\n2\\n\", \"1\\n3\\n\", \"1\\n4\\n\", \"1\\n4\\n\", \"3\\n1 8 15 \\n\", \"22\\n3 10 17 24 31 38 45 52 59 66 73 80 87 94 101 108 115 122 129 136 143 150 \\n\", \"1\\n1\\n\", \"1\\n2\\n\", \"1\\n3\\n\", \"1\\n4\\n\", \"1\\n5\\n\", \"2\\n3 12 \\n\", \"17\\n5 14 23 32 41 50 59 68 77 86 95 104 113 122 131 140 149 \\n\", \"112\\n1 10 19 28 37 46 55 64 73 82 91 100 109 118 127 136 145 154 163 172 181 190 199 208 217 226 235 244 253 262 271 280 289 298 307 316 325 334 343 352 361 370 379 388 397 406 415 424 433 442 451 460 469 478 487 496 505 514 523 532 541 550 559 568 577 586 595 604 613 622 631 640 649 658 667 676 685 694 703 712 721 730 739 748 757 766 775 784 793 802 811 820 829 838 847 856 865 874 883 892 901 910 919 928 937 946 955 964 973 982 991 1000 \\n\", \"1\\n1\\n\", \"1\\n2\\n\", \"1\\n3\\n\", \"1\\n4\\n\", \"1\\n5\\n\", \"2\\n2 13 \\n\", \"14\\n5 16 27 38 49 60 71 82 93 104 115 126 137 148 \\n\", \"91\\n5 16 27 38 49 60 71 82 93 104 115 126 137 148 159 170 181 192 203 214 225 236 247 258 269 280 291 302 313 324 335 346 357 368 379 390 401 412 423 434 445 456 467 478 489 500 511 522 533 544 555 566 577 588 599 610 621 632 643 654 665 676 687 698 709 720 731 742 753 764 775 786 797 808 819 830 841 852 863 874 885 896 907 918 929 940 951 962 973 984 995 \\n\", \"1\\n2\\n\", \"1\\n3\\n\", \"1\\n1\\n\", \"1\\n1\\n\", \"1\\n1\\n\", \"2\\n1 8 \\n\", \"1\\n1\\n\", \"1\\n4\\n\", \"1\\n4\\n\", \"5\\n2 11 20 29 38 \\n\", \"1\\n3\\n\", \"3\\n1 10 19 \\n\", \"1\\n5\\n\", \"1\\n1\\n\", \"1\\n1\\n\", \"3\\n1 6 11 \\n\"]}", "source": "primeintellect"}
|
Long story short, shashlik is Miroslav's favorite food. Shashlik is prepared on several skewers simultaneously. There are two states for each skewer: initial and turned over.
This time Miroslav laid out $n$ skewers parallel to each other, and enumerated them with consecutive integers from $1$ to $n$ in order from left to right. For better cooking, he puts them quite close to each other, so when he turns skewer number $i$, it leads to turning $k$ closest skewers from each side of the skewer $i$, that is, skewers number $i - k$, $i - k + 1$, ..., $i - 1$, $i + 1$, ..., $i + k - 1$, $i + k$ (if they exist).
For example, let $n = 6$ and $k = 1$. When Miroslav turns skewer number $3$, then skewers with numbers $2$, $3$, and $4$ will come up turned over. If after that he turns skewer number $1$, then skewers number $1$, $3$, and $4$ will be turned over, while skewer number $2$ will be in the initial position (because it is turned again).
As we said before, the art of cooking requires perfect timing, so Miroslav wants to turn over all $n$ skewers with the minimal possible number of actions. For example, for the above example $n = 6$ and $k = 1$, two turnings are sufficient: he can turn over skewers number $2$ and $5$.
Help Miroslav turn over all $n$ skewers.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \leq n \leq 1000$, $0 \leq k \leq 1000$) — the number of skewers and the number of skewers from each side that are turned in one step.
-----Output-----
The first line should contain integer $l$ — the minimum number of actions needed by Miroslav to turn over all $n$ skewers. After than print $l$ integers from $1$ to $n$ denoting the number of the skewer that is to be turned over at the corresponding step.
-----Examples-----
Input
7 2
Output
2
1 6
Input
5 1
Output
2
1 4
-----Note-----
In the first example the first operation turns over skewers $1$, $2$ and $3$, the second operation turns over skewers $4$, $5$, $6$ and $7$.
In the second example it is also correct to turn over skewers $2$ and $5$, but turning skewers $2$ and $4$, or $1$ and $5$ are incorrect solutions because the skewer $3$ is in the initial state after these operations.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"2\\n\", \"3\\n\", \"6\\n\", \"10\\n\", \"64\\n\", \"1227\\n\", \"49152\\n\", \"1000000\\n\", \"524288\\n\", \"786431\\n\", \"999999\\n\", \"217292\\n\", \"16339\\n\", \"4\\n\", \"5\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"50\\n\", \"87\\n\", \"71\\n\", \"73\\n\", \"89\\n\", \"40\\n\", \"42\\n\", \"847\\n\", \"676\\n\", \"639\\n\", \"957\\n\", \"156\\n\", \"479\\n\", \"586\\n\", \"683\\n\", \"3541\\n\", \"6264\\n\", \"4140\\n\", \"8969\\n\", \"3080\\n\", \"7127\\n\", \"3116\\n\", \"86214\\n\", \"28211\\n\", \"62544\\n\", \"96262\\n\", \"21504\\n\", \"603070\\n\", \"261873\\n\", \"582911\\n\", \"789700\\n\", \"838757\\n\", \"546330\\n\", \"774942\\n\", \"629462\\n\", \"131156\\n\", \"874465\\n\", \"200945\\n\", \"919645\\n\", \"215283\\n\", \"955654\\n\", \"437675\\n\", \"175863\\n\", \"126395\\n\", \"406138\\n\", \"425221\\n\", \"460829\\n\", \"211425\\n\", \"662327\\n\", \"798412\\n\", \"163259\\n\", \"786432\\n\"], \"outputs\": [\"1\", \"4\", \"120\", \"15120\", \"676169815\", \"9412302\", \"468540828\", \"943169120\", \"948408574\", \"973886300\", \"88378773\", \"936105571\", \"166382218\", \"2\", \"6\", \"600\", \"240\", \"1440\", \"938830187\", \"247668980\", \"744016814\", \"405863164\", \"222320695\", \"193507326\", \"270627256\", \"206774372\", \"491267527\", \"32577133\", \"885557037\", \"980176938\", \"784626857\", \"77973950\", \"951224867\", \"358246424\", \"136451422\", \"371936240\", \"651607899\", \"806160386\", \"515942917\", \"390594722\", \"17417160\", \"5179894\", \"554785078\", \"882337958\", \"299254647\", \"15758000\", \"965169285\", \"825030283\", \"501403228\", \"220750034\", \"784174655\", \"979976656\", \"20530480\", \"751299482\", \"417880003\", \"712409910\", \"465123203\", \"197619154\", \"416395816\", \"305205122\", \"442215433\", \"374976337\", \"648609649\", \"973943578\", \"66014534\", \"501705216\", \"118190038\", \"47586814\", \"581955590\", \"755978297\"]}", "source": "primeintellect"}
|
Let's define a function $f(p)$ on a permutation $p$ as follows. Let $g_i$ be the greatest common divisor (GCD) of elements $p_1$, $p_2$, ..., $p_i$ (in other words, it is the GCD of the prefix of length $i$). Then $f(p)$ is the number of distinct elements among $g_1$, $g_2$, ..., $g_n$.
Let $f_{max}(n)$ be the maximum value of $f(p)$ among all permutations $p$ of integers $1$, $2$, ..., $n$.
Given an integers $n$, count the number of permutations $p$ of integers $1$, $2$, ..., $n$, such that $f(p)$ is equal to $f_{max}(n)$. Since the answer may be large, print the remainder of its division by $1000\,000\,007 = 10^9 + 7$.
-----Input-----
The only line contains the integer $n$ ($2 \le n \le 10^6$) — the length of the permutations.
-----Output-----
The only line should contain your answer modulo $10^9+7$.
-----Examples-----
Input
2
Output
1
Input
3
Output
4
Input
6
Output
120
-----Note-----
Consider the second example: these are the permutations of length $3$: $[1,2,3]$, $f(p)=1$. $[1,3,2]$, $f(p)=1$. $[2,1,3]$, $f(p)=2$. $[2,3,1]$, $f(p)=2$. $[3,1,2]$, $f(p)=2$. $[3,2,1]$, $f(p)=2$.
The maximum value $f_{max}(3) = 2$, and there are $4$ permutations $p$ such that $f(p)=2$.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"3\\n141 592 653\\n\", \"5\\n10 21 10 21 10\\n\", \"1\\n100000\\n\", \"50\\n100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000 100000\\n\", \"2\\n1 100000\\n\", \"17\\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\\n\", \"15\\n3026 3027 4599 4854 7086 29504 38709 40467 40663 58674 61008 70794 77517 85547 87320\\n\", \"30\\n2351 14876 66138 87327 29940 73204 19925 50198 13441 54751 1383 92120 90236 13525 3920 16669 80637 94428 54890 71321 77670 57080 82145 39778 69967 38722 46902 82127 1142 21792\\n\", \"1\\n59139\\n\", \"2\\n9859 48096\\n\", \"3\\n25987 64237 88891\\n\", \"4\\n9411 13081 2149 19907\\n\", \"5\\n25539 29221 6895 82089 18673\\n\", \"6\\n76259 10770 87448 3054 67926 81667\\n\", \"7\\n92387 35422 24898 32532 92988 84636 99872\\n\", \"8\\n8515 51563 5451 94713 9537 30709 63343 41819\\n\", \"9\\n91939 407 10197 24191 58791 9486 68030 25807 11\\n\", \"10\\n30518 96518 74071 59971 50121 4862 43967 73607 19138 90754\\n\", \"11\\n46646 21171 78816 89449 99375 50934 15950 90299 18702 62232 12657\\n\", \"12\\n30070 37311 92074 18927 91732 29711 12126 41583 52857 99118 73097 33928\\n\", \"13\\n13494 86155 96820 72596 40986 99976 16813 25571 87013 3301 832 26376 83769\\n\", \"14\\n96918 67704 10077 34778 90239 11457 80284 42263 53872 74779 93976 53416 83860 74518\\n\", \"15\\n13046 83844 14823 64255 15301 90234 84972 93547 88028 11665 54415 13159 83950 951 42336\\n\", \"16\\n29174 32688 95377 26437 64554 60498 56955 10239 22183 15847 47559 40199 92552 70488 4147 73082\\n\", \"17\\n79894 24637 8634 80107 81104 39275 53130 94227 56339 87326 7999 75751 92642 96921 74470 20999 69688\\n\", \"18\\n96022 73481 13380 42288 6166 85348 25113 78215 23198 24212 44246 35494 92733 66459 44793 68916 82818 3967\\n\", \"19\\n79446 55030 93934 39062 88123 88317 21289 62203 57354 28394 37390 95238 92823 92892 39308 16833 54733 51525 58759\\n\", \"20\\n5440 88704 61481 72140 15810 58854 43034 5150 80684 61360 50516 54301 78790 43678 46138 79893 89899 60260 2881 66499\\n\", \"21\\n21569 37548 74739 25809 65063 37631 71913 89138 47543 65542 10956 14045 78880 70111 73357 27810 70326 40523 899 6547 87440\\n\", \"22\\n72289 86393 79484 55287 14317 83704 11192 73126 81699 2429 4100 41085 87482 72352 10976 75727 42240 79569 31621 3492 51189 25936\\n\", \"23\\n88417 11045 92742 84765 6675 86673 40072 57114 15854 6611 40347 76636 87572 66082 38195 56348 89962 59831 29640 43541 14937 73713 52755\\n\", \"24\\n71841 27185 73295 46946 55928 65450 12055 73806 82714 78089 787 36380 87663 68323 75814 4265 94581 31581 51850 40486 11390 21491 27560 22678\\n\", \"25\\n87969 76030 78041 616 13694 11522 84038 25090 16869 14975 61226 96124 20457 62052 70329 76374 42303 11844 15276 37430 99330 77781 35069 64358 45168\\n\", \"26\\n71393 24874 91299 30093 62947 14491 80214 41782 51025 19158 21666 23163 20547 64293 40653 24291 46922 92106 13294 77479 63079 25559 42579 62933 24433 39507\\n\", \"27\\n54817 73719 96044 92275 12201 60564 84901 25770 17884 90636 14810 82907 20637 58023 10976 72208 94644 63856 11312 74424 26828 40632 58600 37316 38290 82420 48297\\n\", \"28\\n70945 22563 76598 21753 4558 39341 48372 77054 52039 27522 75249 18459 96536 60264 5491 20125 42367 44118 42034 38665 47472 88410 66109 78995 52147 68436 9814 71112\\n\", \"29\\n54369 14511 14048 83934 53812 75014 20356 17938 86195 31704 68393 78202 96626 86697 75814 746 46985 15868 40052 11417 11221 44700 40915 53378 98708 78644 4035 20164 37165\\n\", \"30\\n4555 13594 57403 75796 14203 12847 66292 60885 9525 40478 57327 69970 15297 37483 39540 31102 14855 412 84174 57684 65591 19837 80431 18385 3107 87740 15433 24854 73472 88205\\n\", \"31\\n20683 29734 37957 37978 63456 58920 70980 44873 76385 44661 17767 97009 15387 63916 77159 79019 86770 4866 14897 63141 86236 67614 87940 60064 16964 97948 9654 49714 30888 88075 63792\\n\", \"32\\n71403 78578 75406 67455 12710 37697 67155 28861 10540 48843 10911 56753 15477 33453 4378 26936 34492 19720 12915 27382 49984 91200 95449 34448 63525 83964 3875 98767 77905 63753 83018 58084\\n\", \"33\\n87531 27423 55960 53829 37771 40665 39138 12849 77399 53025 71350 83793 48271 59887 41997 74854 14919 24175 43637 24327 13733 38978 2959 319 10086 26876 65393 56332 68025 63623 93732 68354 83938\\n\", \"34\\n70955 19371 60706 50603 54321 86738 11122 29541 11555 57207 31790 19344 24170 29424 36512 22771 86833 4437 41655 64376 34378 19459 86276 74702 23943 69789 59614 48489 49634 63494 12958 11328 69333 1736\\n\", \"35\\n54379 920 41259 12784 3574 98219 40001 80825 45710 61390 24933 79088 24260 23153 6835 94880 67260 76187 39673 28616 98126 10341 26489 49085 37800 55805 86539 97542 39754 30660 32184 64703 11625 77872 63584\\n\", \"36\\n37803 17060 78709 42262 28636 68484 79280 97517 12570 98276 52669 6128 57054 58098 68646 75501 39174 56449 3099 1369 94579 58119 1295 90764 51657 66013 48056 55107 54066 30530 75602 74973 21212 21304 22589 4895\\n\", \"37\\n53932 65904 91967 4443 77890 47261 8160 81505 46725 69754 21621 65871 24440 51828 71673 23418 86896 4008 1117 65610 82519 5897 8804 65148 98218 76221 42277 79968 68379 30401 62125 61052 96207 64737 24698 99495 70720\\n\", \"38\\n70060 14749 72520 58113 2951 26037 80143 32789 80881 73936 82060 92911 24531 78261 9292 71335 91515 8462 31839 62555 46268 29482 92121 31019 12075 94942 36498 96317 58499 30271 81351 71322 81602 8169 26807 69903 38154 20539\\n\", \"39\\n20780 30889 9970 87591 19501 96302 76318 49481 47740 10823 42500 61167 57325 47798 36511 19252 39237 23316 29857 2603 10016 9964 99630 5402 82828 5150 98015 53882 72811 97437 57473 57400 91189 84305 85811 64503 40179 50614 52044\\n\", \"40\\n3670 5779 20621 87964 12595 34136 98063 92429 38366 43789 88330 52934 19100 22776 43342 82312 74404 64756 73980 14278 21283 85101 63339 70409 63034 14245 33606 58571 84927 14931 25355 15452 46072 4671 5838 69121 18243 87783 29748 84047\\n\", \"41\\n87094 21920 58071 41634 29145 45616 94239 76417 5226 47971 48770 79974 19190 25017 37857 30229 11726 12314 71998 54327 85032 8687 46656 12088 9595 24454 27827 7624 66535 14801 44581 25723 55659 48103 75242 39529 52973 17858 16985 41454 44182\\n\", \"42\\n70518 70764 38625 3816 78399 48585 66222 60405 72085 52153 85018 39717 51984 51451 8180 78146 59448 16768 2720 51272 48780 56464 21461 86471 23452 10470 22048 65189 56655 90480 31103 11801 73758 91536 10055 34129 20407 47933 4223 98861 84475 52291\\n\", \"43\\n86646 19609 43370 33293 3460 94658 95101 44393 6241 56335 78161 66757 52074 53692 2695 58767 31363 64326 738 15513 69425 4242 28971 60855 37309 53382 16269 57346 70968 90350 74522 22072 83345 67672 69060 4537 55137 78008 91461 32075 33280 70405 71607\\n\", \"44\\n70070 68453 23924 95475 52714 73435 34380 61085 40396 60518 38601 26501 52165 47421 73018 6684 79085 68781 31460 88265 33173 52020 44992 2534 8062 96295 77786 39103 85280 24812 93748 75446 92932 11105 71169 66433 89866 75379 11402 22186 73572 31624 70092 10734\\n\", \"45\\n53494 93105 37182 24953 1967 43700 39068 12369 7256 64700 31744 62052 84959 49662 34829 78793 51000 16339 29478 52506 96922 75606 52501 1109 21919 6503 72007 63964 75400 24682 45678 18420 67928 87241 73278 69545 24596 29646 65936 55401 89673 49738 35873 45189 3622\\n\", \"46\\n36918 9246 74631 78622 94325 22476 35243 96357 41411 68882 92184 21796 28153 43392 37856 26710 64130 20793 60200 16747 84862 23383 60010 42788 68480 92519 66229 56121 57009 24553 89096 4499 53323 30673 75386 31442 92030 59721 53173 45511 29966 67853 77462 12347 61811 81517\\n\", \"47\\n53046 58090 55185 8100 43578 1253 7226 13049 75567 73065 19920 48836 28243 45633 75475 74628 11853 68351 90922 89500 81315 71161 34816 49875 82337 2727 27746 37878 79833 24423 75618 82065 95614 82618 34391 1850 94056 57092 73115 70214 46067 29071 75947 46802 95807 42600 11211\\n\", \"48\\n69174 6934 59931 70281 68640 47326 3402 64333 42426 77247 13063 8579 61038 39362 2694 22545 83767 15909 88940 86445 45063 27451 18133 91555 28898 45640 21967 62738 61441 24293 19036 68144 5201 26050 69204 29154 85681 19871 60352 36133 86359 47186 74432 5448 53996 27876 58022 80559\\n\", \"49\\n19894 55779 73188 99759 17893 50295 8089 81025 76582 81429 73503 35619 61128 41603 40313 3166 31490 87660 19662 59197 8812 75229 25642 65938 42755 31656 16188 87599 51562 91460 38262 11118 90596 69482 71313 66858 87707 17242 14886 93539 35164 32596 83317 72606 12185 21664 80642 72099 7525\\n\", \"50\\n70081 97965 40736 24325 2476 20832 54026 23972 91400 47099 95141 27386 79799 49285 4039 818 23552 72203 55273 38168 52783 50365 89351 30945 47154 8047 27586 49184 20573 8953 38849 36466 45479 89848 82827 71475 74283 87115 92590 28903 97800 74550 74140 82514 10849 6786 67881 63456 53022 25051\\n\", \"4\\n10 3 2 1\\n\", \"6\\n5245 1414 21632 12159 31783 7412\\n\", \"46\\n1666 17339 9205 20040 30266 12751 11329 7951 9000 14465 11771 7600 19480 15993 19453 7470 1361 7922 27747 17347 4727 11280 403 16338 6064 11124 25723 18717 26118 271 9242 16952 26381 31795 28226 3646 27589 31472 30108 28354 25281 22429 30956 32264 14729 21685\\n\", \"3\\n100 90 80\\n\", \"5\\n10 9 8 7 6\\n\", \"4\\n100 40 50 10\\n\", \"6\\n5 4 3 2 1 1\\n\", \"33\\n30274 12228 26670 31244 5457 2643 27275 4380 30954 23407 8387 6669 25229 31591 27518 30261 25670 20962 31316 8992 8324 26216 10812 28467 15401 23077 10311 24975 14046 12010 11406 22841 7593\\n\", \"3\\n4 2 1\\n\", \"3\\n10 5 5\\n\", \"6\\n6 5 4 3 2 1\\n\", \"4\\n5 2 7 3\\n\"], \"outputs\": [\"653 733\\n\", \"31 41\\n\", \"0 100000\\n\", \"2500000 2500000\\n\", \"1 100000\\n\", \"65535 65536\\n\", \"306375 306420\\n\", \"724302 724303\\n\", \"0 59139\\n\", \"9859 48096\\n\", \"88891 90224\\n\", \"19907 24641\\n\", \"80328 82089\\n\", \"158428 168696\\n\", \"192724 270011\\n\", \"138409 167241\\n\", \"102429 186430\\n\", \"252317 291210\\n\", \"288850 297381\\n\", \"296580 315954\\n\", \"325890 327812\\n\", \"414474 453667\\n\", \"362168 392358\\n\", \"370791 371188\\n\", \"492038 551105\\n\", \"436157 470692\\n\", \"538648 614005\\n\", \"506639 558873\\n\", \"506467 510922\\n\", \"513496 572193\\n\", \"602650 616877\\n\", \"560664 601494\\n\", \"586407 637558\\n\", \"569885 599895\\n\", \"716531 728460\\n\", \"669482 697066\\n\", \"678299 683312\\n\", \"620095 620382\\n\", \"825663 838784\\n\", \"770578 774459\\n\", \"741185 823963\\n\", \"693927 744637\\n\", \"823487 862568\\n\", \"872694 876851\\n\", \"989044 1011845\\n\", \"977736 1012543\\n\", \"954593 973021\\n\", \"909877 959523\\n\", \"799467 864856\\n\", \"1012190 1036128\\n\", \"1039942 1109548\\n\", \"1141992 1210184\\n\", \"1052557 1068976\\n\", \"1199490 1212346\\n\", \"1214201 1233568\\n\", \"1096672 1115247\\n\", \"1233007 1259909\\n\", \"1251581 1255820\\n\", \"4 12\\n\", \"38442 41203\\n\", \"379808 392222\\n\", \"90 180\\n\", \"16 24\\n\", \"50 150\\n\", \"7 9\\n\", \"299163 327443\\n\", \"2 5\\n\", \"5 15\\n\", \"9 12\\n\", \"7 10\\n\"]}", "source": "primeintellect"}
|
You may have heard of the pie rule before. It states that if two people wish to fairly share a slice of pie, one person should cut the slice in half, and the other person should choose who gets which slice. Alice and Bob have many slices of pie, and rather than cutting the slices in half, each individual slice will be eaten by just one person.
The way Alice and Bob decide who eats each slice is as follows. First, the order in which the pies are to be handed out is decided. There is a special token called the "decider" token, initially held by Bob. Until all the pie is handed out, whoever has the decider token will give the next slice of pie to one of the participants, and the decider token to the other participant. They continue until no slices of pie are left.
All of the slices are of excellent quality, so each participant obviously wants to maximize the total amount of pie they get to eat. Assuming both players make their decisions optimally, how much pie will each participant receive?
-----Input-----
Input will begin with an integer N (1 ≤ N ≤ 50), the number of slices of pie.
Following this is a line with N integers indicating the sizes of the slices (each between 1 and 100000, inclusive), in the order in which they must be handed out.
-----Output-----
Print two integers. First, the sum of the sizes of slices eaten by Alice, then the sum of the sizes of the slices eaten by Bob, assuming both players make their decisions optimally.
-----Examples-----
Input
3
141 592 653
Output
653 733
Input
5
10 21 10 21 10
Output
31 41
-----Note-----
In the first example, Bob takes the size 141 slice for himself and gives the decider token to Alice. Then Alice gives the size 592 slice to Bob and keeps the decider token for herself, so that she can then give the size 653 slice to herself.
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
{"tests": "{\"inputs\": [\"1 1\\n\", \"0 10\\n\", \"10 10\\n\", \"100 100\\n\", \"10 100\\n\", \"20 1000\\n\", \"1000 20\\n\", \"100 10\\n\", \"2 2\\n\", \"3 3\\n\", \"2 15\\n\", \"15 2\\n\", \"1000 1000\\n\", \"1000 999\\n\", \"999 1000\\n\", \"987 567\\n\", \"555 555\\n\", \"555 1\\n\", \"1 4\\n\", \"955 956\\n\", \"4 0\\n\", \"0 3\\n\", \"3 0\\n\", \"2 3\\n\", \"3 2\\n\", \"3 4\\n\", \"4 3\\n\", \"3 5\\n\", \"5 3\\n\", \"3 6\\n\", \"6 3\\n\", \"4 4\\n\", \"4 5\\n\", \"5 4\\n\", \"4 6\\n\", \"6 4\\n\", \"4 7\\n\", \"7 4\\n\", \"3 100\\n\", \"100 3\\n\", \"4 100\\n\", \"100 4\\n\", \"30 1000\\n\", \"1000 30\\n\", \"1000 40\\n\", \"40 1000\\n\", \"2 10\\n\", \"9 3\\n\", \"2 1000\\n\", \"100 2\\n\", \"3 1\\n\", \"2 100\\n\", \"3 7\\n\", \"2 50\\n\", \"1 5\\n\", \"3 1000\\n\", \"5 2\\n\", \"10 0\\n\", \"20 0\\n\", \"1000 3\\n\", \"1000 500\\n\", \"2 5\\n\", \"2 1\\n\", \"1000 2\\n\", \"6 5\\n\", \"2 4\\n\", \"20 10\\n\", \"10 1\\n\"], \"outputs\": [\"1 1\\n0 0\\n1 0\\n0 1\\n\", \"0 1\\n0 10\\n0 0\\n0 9\\n\", \"10 9\\n0 0\\n10 10\\n1 0\\n\", \"0 1\\n100 100\\n0 0\\n99 100\\n\", \"9 100\\n0 0\\n10 100\\n1 0\\n\", \"1 0\\n20 1000\\n0 0\\n19 1000\\n\", \"0 1\\n1000 20\\n0 0\\n1000 19\\n\", \"100 9\\n0 0\\n100 10\\n0 1\\n\", \"2 2\\n0 0\\n2 0\\n0 2\\n\", \"3 3\\n0 0\\n3 0\\n0 3\\n\", \"0 0\\n2 15\\n2 0\\n0 15\\n\", \"0 0\\n15 2\\n0 2\\n15 0\\n\", \"0 1\\n1000 1000\\n0 0\\n999 1000\\n\", \"0 1\\n1000 999\\n0 0\\n1000 998\\n\", \"1 0\\n999 1000\\n0 0\\n998 1000\\n\", \"987 566\\n0 0\\n987 567\\n0 1\\n\", \"555 554\\n0 0\\n555 555\\n1 0\\n\", \"555 1\\n0 0\\n555 0\\n0 1\\n\", \"1 4\\n0 0\\n0 4\\n1 0\\n\", \"1 0\\n955 956\\n0 0\\n954 956\\n\", \"1 0\\n4 0\\n0 0\\n3 0\\n\", \"0 1\\n0 3\\n0 0\\n0 2\\n\", \"1 0\\n3 0\\n0 0\\n2 0\\n\", \"0 0\\n2 3\\n2 0\\n0 3\\n\", \"0 0\\n3 2\\n0 2\\n3 0\\n\", \"0 0\\n3 4\\n3 0\\n0 4\\n\", \"0 0\\n4 3\\n0 3\\n4 0\\n\", \"0 0\\n3 5\\n3 0\\n0 5\\n\", \"0 0\\n5 3\\n0 3\\n5 0\\n\", \"0 0\\n3 6\\n3 0\\n0 6\\n\", \"0 0\\n6 3\\n0 3\\n6 0\\n\", \"0 1\\n4 4\\n0 0\\n3 4\\n\", \"1 0\\n4 5\\n0 0\\n3 5\\n\", \"0 1\\n5 4\\n0 0\\n5 3\\n\", \"1 0\\n4 6\\n0 0\\n3 6\\n\", \"0 1\\n6 4\\n0 0\\n6 3\\n\", \"1 0\\n4 7\\n0 0\\n3 7\\n\", \"0 1\\n7 4\\n0 0\\n7 3\\n\", \"3 100\\n0 0\\n0 100\\n3 0\\n\", \"100 3\\n0 0\\n100 0\\n0 3\\n\", \"3 100\\n0 0\\n4 100\\n1 0\\n\", \"100 3\\n0 0\\n100 4\\n0 1\\n\", \"1 0\\n30 1000\\n0 0\\n29 1000\\n\", \"0 1\\n1000 30\\n0 0\\n1000 29\\n\", \"0 1\\n1000 40\\n0 0\\n1000 39\\n\", \"1 0\\n40 1000\\n0 0\\n39 1000\\n\", \"2 10\\n0 0\\n0 10\\n2 0\\n\", \"0 0\\n9 3\\n0 3\\n9 0\\n\", \"2 1000\\n0 0\\n0 1000\\n2 0\\n\", \"100 2\\n0 0\\n100 0\\n0 2\\n\", \"0 0\\n3 1\\n0 1\\n3 0\\n\", \"2 100\\n0 0\\n0 100\\n2 0\\n\", \"0 0\\n3 7\\n3 0\\n0 7\\n\", \"0 0\\n2 50\\n2 0\\n0 50\\n\", \"1 5\\n0 0\\n0 5\\n1 0\\n\", \"0 0\\n3 1000\\n3 0\\n0 1000\\n\", \"0 0\\n5 2\\n0 2\\n5 0\\n\", \"1 0\\n10 0\\n0 0\\n9 0\\n\", \"1 0\\n20 0\\n0 0\\n19 0\\n\", \"0 0\\n1000 3\\n0 3\\n1000 0\\n\", \"1000 499\\n0 0\\n1000 500\\n0 1\\n\", \"0 0\\n2 5\\n2 0\\n0 5\\n\", \"0 0\\n2 1\\n0 1\\n2 0\\n\", \"1000 2\\n0 0\\n1000 0\\n0 2\\n\", \"0 1\\n6 5\\n0 0\\n6 4\\n\", \"0 0\\n2 4\\n2 0\\n0 4\\n\", \"20 9\\n0 0\\n20 10\\n0 1\\n\", \"10 1\\n0 0\\n10 0\\n0 1\\n\"]}", "source": "primeintellect"}
|
You are given a rectangular grid of lattice points from (0, 0) to (n, m) inclusive. You have to choose exactly 4 different points to build a polyline possibly with self-intersections and self-touching. This polyline should be as long as possible.
A polyline defined by points p_1, p_2, p_3, p_4 consists of the line segments p_1 p_2, p_2 p_3, p_3 p_4, and its length is the sum of the lengths of the individual line segments.
-----Input-----
The only line of the input contains two integers n and m (0 ≤ n, m ≤ 1000). It is guaranteed that grid contains at least 4 different points.
-----Output-----
Print 4 lines with two integers per line separated by space — coordinates of points p_1, p_2, p_3, p_4 in order which represent the longest possible polyline.
Judge program compares your answer and jury's answer with 10^{ - 6} precision.
-----Examples-----
Input
1 1
Output
1 1
0 0
1 0
0 1
Input
0 10
Output
0 1
0 10
0 0
0 9
Read the inputs from stdin solve the problem and write the answer to stdout (do not directly test on the sample inputs). Enclose your code within ```python delimiters.
| 0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.