info
large_stringlengths
120
50k
question
large_stringlengths
504
10.4k
avg@8_qwen3_4b_instruct_2507
float64
0
0.88
{"tests": "{\"inputs\": [\"4 5 3\\n3 5 1 2\\n\", \"10 10 1\\n10 5 7 4 6 3 2 1 9 8\\n\", \"1 4 3\\n3\\n\", \"2 5 2\\n5 3\\n\", \"3 6 4\\n3 1 4\\n\", \"4 100 44\\n90 96 41 35\\n\", \"5 200 33\\n116 168 48 180 164\\n\", \"10 20 19\\n9 15 11 18 20 5 16 12 3 17\\n\", \"20 1000 344\\n133 431 634 493 866 325 757 21 291 908 503 958 477 247 531 935 928 369 282 747\\n\", \"40 200 123\\n45 28 23 141 185 69 72 36 131 54 160 152 157 40 123 194 86 7 24 26 107 9 84 184 149 59 92 137 15 71 176 122 119 134 129 80 94 101 18 178\\n\", \"100 300 32\\n60 255 143 42 98 120 3 96 225 18 38 17 146 299 240 250 137 117 70 296 258 279 103 244 109 80 12 285 231 248 49 237 199 283 65 138 275 79 227 40 10 89 270 44 165 177 150 132 108 97 9 269 187 71 139 101 112 263 105 14 20 281 228 171 82 30 39 193 265 212 106 236 272 129 33 271 84 194 203 297 232 15 152 147 52 21 216 241 168 205 85 62 160 73 192 217 54 284 276 53\\n\", \"2 1000000000 1000000000\\n1 1000000000\\n\", \"2 1000000000 999999999\\n1 1000000000\\n\", \"2 1000000000 999999998\\n1 1000000000\\n\", \"2 3 3\\n1 3\\n\", \"2 4 3\\n1 4\\n\", \"2 5 3\\n1 5\\n\", \"3 5 3\\n1 4 5\\n\"], \"outputs\": [\"3\\n3 1 1 2 \\n\", \"2\\n2 1 1 2 2 1 2 1 1 2 \\n\", \"1\\n1 \\n\", \"2\\n2 1 \\n\", \"3\\n2 1 3 \\n\", \"2\\n1 2 2 1 \\n\", \"3\\n1 2 1 3 1 \\n\", \"10\\n3 6 4 9 10 2 7 5 1 8 \\n\", \"10\\n2 7 3 2 2 6 4 1 5 5 9 8 8 3 10 7 6 1 4 1 \\n\", \"28\\n11 8 5 3 11 14 16 9 1 12 7 5 6 10 26 12 19 1 6 7 23 2 18 10 4 13 20 28 3 15 8 25 24 2 27 17 21 22 4 9 \\n\", \"15\\n8 10 9 2 9 4 1 7 2 8 1 7 2 4 1 9 7 3 11 2 2 13 11 13 15 3 4 15 8 7 4 11 5 9 10 1 1 2 3 14 3 6 6 3 5 7 3 6 14 8 2 5 2 1 8 10 2 3 1 5 9 7 4 1 4 11 13 4 4 7 12 6 11 5 12 8 13 8 6 3 5 6 11 10 5 10 9 12 6 1 5 9 4 12 3 10 7 14 12 6 \\n\", \"2\\n1 2 \\n\", \"2\\n1 2 \\n\", \"1\\n1 1 \\n\", \"2\\n1 2 \\n\", \"2\\n1 2 \\n\", \"1\\n1 1 \\n\", \"2\\n1 2 1 \\n\"]}", "source": "primeintellect"}
Recently Monocarp got a job. His working day lasts exactly $m$ minutes. During work, Monocarp wants to drink coffee at certain moments: there are $n$ minutes $a_1, a_2, \dots, a_n$, when he is able and willing to take a coffee break (for the sake of simplicity let's consider that each coffee break lasts exactly one minute). However, Monocarp's boss doesn't like when Monocarp takes his coffee breaks too often. So for the given coffee break that is going to be on minute $a_i$, Monocarp must choose the day in which he will drink coffee during the said minute, so that every day at least $d$ minutes pass between any two coffee breaks. Monocarp also wants to take these $n$ coffee breaks in a minimum possible number of working days (he doesn't count days when he is not at work, and he doesn't take coffee breaks on such days). Take into account that more than $d$ minutes pass between the end of any working day and the start of the following working day. For each of the $n$ given minutes determine the day, during which Monocarp should take a coffee break in this minute. You have to minimize the number of days spent. -----Input----- The first line contains three integers $n$, $m$, $d$ $(1 \le n \le 2\cdot10^{5}, n \le m \le 10^{9}, 1 \le d \le m)$ — the number of coffee breaks Monocarp wants to have, the length of each working day, and the minimum number of minutes between any two consecutive coffee breaks. The second line contains $n$ distinct integers $a_1, a_2, \dots, a_n$ $(1 \le a_i \le m)$, where $a_i$ is some minute when Monocarp wants to have a coffee break. -----Output----- In the first line, write the minimum number of days required to make a coffee break in each of the $n$ given minutes. In the second line, print $n$ space separated integers. The $i$-th of integers should be the index of the day during which Monocarp should have a coffee break at minute $a_i$. Days are numbered from $1$. If there are multiple optimal solutions, you may print any of them. -----Examples----- Input 4 5 3 3 5 1 2 Output 3 3 1 1 2 Input 10 10 1 10 5 7 4 6 3 2 1 9 8 Output 2 2 1 1 2 2 1 2 1 1 2 -----Note----- In the first example, Monocarp can take two coffee breaks during the first day (during minutes $1$ and $5$, $3$ minutes will pass between these breaks). One break during the second day (at minute $2$), and one break during the third day (at minute $3$). In the second example, Monocarp can determine the day of the break as follows: if the minute when he wants to take a break is odd, then this break is on the first day, if it is even, then this break is on the second day. 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\\n1 2 1 5\\n\", \"4 1\\n1 2 3 4\\n\", \"50 1\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50\\n\", \"10 1\\n1 2 3 4 5 6 7 8 9 10\\n\", \"50 5\\n232 6 11 16 21 26 31 36 41 46 665 56 61 66 71 76 602 86 91 712 101 106 111 116 121 126 131 136 141 146 151 156 161 166 755 176 181 186 191 196 201 206 211 216 221 226 231 236 241 246\\n\", \"10 99\\n1 100 199 298 397 496 364 694 793 676\\n\", \"1 99\\n1\\n\", \"2 99\\n1 100\\n\", \"3 99\\n1 100 199\\n\", \"4 99\\n1 100 199 298\\n\", \"3 99\\n295 566 992\\n\", \"2 99\\n307 854\\n\", \"7 1\\n1 1 2 3 4 5 6\\n\", \"5 1\\n1 1 2 3 4\\n\", \"4 2\\n1 1 3 5\\n\", \"4 1\\n1 1 2 3\\n\", \"5 1\\n1 1 1 2 3\\n\", \"3 1\\n1 1 2\\n\"], \"outputs\": [\"2\\n+ 3 2\\n- 4 1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"5\\n- 1 231\\n- 11 614\\n- 17 521\\n- 20 616\\n- 35 584\\n\", \"2\\n+ 7 231\\n+ 10 216\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"2\\n- 2 172\\n- 3 499\\n\", \"1\\n- 2 448\\n\", \"6\\n+ 2 1\\n+ 3 1\\n+ 4 1\\n+ 5 1\\n+ 6 1\\n+ 7 1\\n\", \"4\\n+ 2 1\\n+ 3 1\\n+ 4 1\\n+ 5 1\\n\", \"3\\n+ 2 2\\n+ 3 2\\n+ 4 2\\n\", \"3\\n+ 2 1\\n+ 3 1\\n+ 4 1\\n\", \"4\\n+ 2 1\\n+ 3 2\\n+ 4 2\\n+ 5 2\\n\", \"2\\n+ 2 1\\n+ 3 1\\n\"]}", "source": "primeintellect"}
The Queen of England has n trees growing in a row in her garden. At that, the i-th (1 ≤ i ≤ n) tree from the left has height a_{i} meters. Today the Queen decided to update the scenery of her garden. She wants the trees' heights to meet the condition: for all i (1 ≤ i < n), a_{i} + 1 - a_{i} = k, where k is the number the Queen chose. Unfortunately, the royal gardener is not a machine and he cannot fulfill the desire of the Queen instantly! In one minute, the gardener can either decrease the height of a tree to any positive integer height or increase the height of a tree to any positive integer height. How should the royal gardener act to fulfill a whim of Her Majesty in the minimum number of minutes? -----Input----- The first line contains two space-separated integers: n, k (1 ≤ n, k ≤ 1000). The second line contains n space-separated integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 1000) — the heights of the trees in the row. -----Output----- In the first line print a single integer p — the minimum number of minutes the gardener needs. In the next p lines print the description of his actions. If the gardener needs to increase the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, then print in the corresponding line "+ j x". If the gardener needs to decrease the height of the j-th (1 ≤ j ≤ n) tree from the left by x (x ≥ 1) meters, print on the corresponding line "- j x". If there are multiple ways to make a row of trees beautiful in the minimum number of actions, you are allowed to print any of them. -----Examples----- Input 4 1 1 2 1 5 Output 2 + 3 2 - 4 1 Input 4 1 1 2 3 4 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\": [\"4 4\\n1 2\\n1 3\\n4 2\\n4 3\\n\", \"3 3\\n1 2\\n2 3\\n3 1\\n\", \"3 0\\n\", \"6 3\\n1 2\\n4 3\\n6 5\\n\", \"100000 0\\n\", \"5 4\\n1 2\\n1 3\\n1 4\\n1 5\\n\", \"6 3\\n1 2\\n2 3\\n4 5\\n\", \"5 5\\n1 2\\n2 3\\n3 4\\n4 5\\n5 1\\n\", \"59139 0\\n\", \"9859 0\\n\", \"25987 0\\n\", \"9411 0\\n\", \"25539 0\\n\", \"59139 1\\n10301 5892\\n\", \"9859 1\\n1721 9478\\n\", \"76259 0\\n\", \"92387 0\\n\", \"6 4\\n1 2\\n2 3\\n3 1\\n4 5\\n\"], \"outputs\": [\"1 2\\n\", \"0 1\\n\", \"3 1\\n\", \"2 12\\n\", \"3 166661666700000\\n\", \"1 6\\n\", \"1 1\\n\", \"0 1\\n\", \"3 34470584559489\\n\", \"3 159667007809\\n\", \"3 2924603876545\\n\", \"3 138872935265\\n\", \"3 2775935665889\\n\", \"2 59137\\n\", \"2 9857\\n\", \"3 73910302948209\\n\", \"3 131421748719345\\n\", \"0 1\\n\"]}", "source": "primeintellect"}
After Vitaly was expelled from the university, he became interested in the graph theory. Vitaly especially liked the cycles of an odd length in which each vertex occurs at most once. Vitaly was wondering how to solve the following problem. You are given an undirected graph consisting of n vertices and m edges, not necessarily connected, without parallel edges and loops. You need to find t — the minimum number of edges that must be added to the given graph in order to form a simple cycle of an odd length, consisting of more than one vertex. Moreover, he must find w — the number of ways to add t edges in order to form a cycle of an odd length (consisting of more than one vertex). It is prohibited to add loops or parallel edges. Two ways to add edges to the graph are considered equal if they have the same sets of added edges. Since Vitaly does not study at the university, he asked you to help him with this task. -----Input----- The first line of the input contains two integers n and m ($3 \leq n \leq 10^{5}, 0 \leq m \leq \operatorname{min}(\frac{n(n - 1)}{2}, 10^{5})$ — the number of vertices in the graph and the number of edges in the graph. Next m lines contain the descriptions of the edges of the graph, one edge per line. Each edge is given by a pair of integers a_{i}, b_{i} (1 ≤ a_{i}, b_{i} ≤ n) — the vertices that are connected by the i-th edge. All numbers in the lines are separated by a single space. It is guaranteed that the given graph doesn't contain any loops and parallel edges. The graph isn't necessarily connected. -----Output----- Print in the first line of the output two space-separated integers t and w — the minimum number of edges that should be added to the graph to form a simple cycle of an odd length consisting of more than one vertex where each vertex occurs at most once, and the number of ways to do this. -----Examples----- Input 4 4 1 2 1 3 4 2 4 3 Output 1 2 Input 3 3 1 2 2 3 3 1 Output 0 1 Input 3 0 Output 3 1 -----Note----- The simple cycle is a cycle that doesn't contain any vertex twice. 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\\n\", \"2 4\\n\", \"20 10\\n\", \"1000 1000\\n\", \"1 1000\\n\", \"1000 122\\n\", \"1 2\\n\", \"1 1\\n\", \"2 1\\n\", \"15 22\\n\", \"2 3\\n\", \"2 5\\n\", \"432 333\\n\", \"17 23\\n\", \"843 134\\n\", \"912 584\\n\", \"88 88\\n\", \"3 16\\n\"], \"outputs\": [\"16\\n\", \"64\\n\", \"75497471\\n\", \"708964705\\n\", \"46452554\\n\", \"712990290\\n\", \"8\\n\", \"4\\n\", \"8\\n\", \"679477111\\n\", \"32\\n\", \"128\\n\", \"726933080\\n\", \"444595123\\n\", \"230806096\\n\", \"626052968\\n\", \"412395273\\n\", \"524288\\n\"]}", "source": "primeintellect"}
Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below. [Image] The dimension of this tile is perfect for this kitchen, as he will need exactly $w \times h$ tiles without any scraps. That is, the width of the kitchen is $w$ tiles, and the height is $h$ tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black. [Image] The picture on the left shows one valid tiling of a $3 \times 2$ kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by $998244353$ (a prime number). -----Input----- The only line contains two space separated integers $w$, $h$ ($1 \leq w,h \leq 1\,000$) — the width and height of the kitchen, measured in tiles. -----Output----- Output a single integer $n$ — the remainder of the number of tilings when divided by $998244353$. -----Examples----- Input 2 2 Output 16 Input 2 4 Output 64 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.75
{"tests": "{\"inputs\": [\"5\\n1 0 1\\n20 1 0\\n300 0 1\\n4000 0 0\\n50000 1 0\\n1 2\\n2 3\\n2 4\\n1 5\\n\", \"5\\n10000 0 1\\n2000 1 0\\n300 0 1\\n40 0 0\\n1 1 0\\n1 2\\n2 3\\n2 4\\n1 5\\n\", \"2\\n109 0 1\\n205 0 1\\n1 2\\n\", \"8\\n82 0 0\\n3 1 1\\n53 0 0\\n5 0 0\\n81 0 1\\n56 1 0\\n99 1 0\\n87 0 1\\n5 7\\n2 8\\n4 7\\n4 1\\n3 2\\n2 5\\n8 6\\n\", \"10\\n64 0 0\\n10 0 0\\n17 0 1\\n90 1 1\\n97 1 1\\n19 1 0\\n26 1 1\\n95 1 1\\n46 0 0\\n86 0 0\\n5 4\\n7 1\\n9 5\\n6 8\\n1 6\\n7 5\\n8 10\\n3 7\\n3 2\\n\", \"1\\n98 1 1\\n\", \"5\\n17 1 1\\n64 0 0\\n41 1 1\\n100 0 0\\n37 1 1\\n5 4\\n3 5\\n3 1\\n5 2\\n\", \"9\\n71 1 1\\n59 0 0\\n87 0 0\\n9 0 1\\n39 1 1\\n3 1 1\\n72 0 0\\n96 1 0\\n100 1 1\\n1 4\\n3 7\\n9 5\\n1 8\\n3 2\\n6 8\\n4 5\\n3 5\\n\", \"7\\n28 0 1\\n56 1 0\\n40 1 0\\n34 1 0\\n12 0 0\\n27 0 1\\n15 0 1\\n4 6\\n4 7\\n6 1\\n5 3\\n3 2\\n4 5\\n\", \"7\\n62 1 1\\n72 1 1\\n95 1 1\\n59 0 0\\n52 1 1\\n99 0 1\\n1 1 0\\n4 3\\n1 6\\n5 3\\n2 6\\n7 4\\n2 5\\n\", \"10\\n92 0 1\\n19 1 0\\n46 1 0\\n53 1 0\\n13 1 0\\n63 0 1\\n3 0 1\\n67 1 0\\n20 0 1\\n82 0 1\\n6 5\\n9 1\\n3 7\\n10 4\\n4 8\\n2 8\\n5 2\\n3 8\\n9 10\\n\", \"7\\n87 1 0\\n69 0 0\\n61 0 0\\n88 0 1\\n46 0 1\\n39 1 0\\n91 1 1\\n6 4\\n5 6\\n2 7\\n2 4\\n3 7\\n6 1\\n\", \"1\\n35 0 0\\n\", \"3\\n57 1 0\\n6 0 1\\n76 1 1\\n1 3\\n3 2\\n\", \"7\\n43 0 1\\n41 1 0\\n53 1 0\\n52 1 0\\n35 0 1\\n36 0 0\\n96 0 1\\n6 4\\n5 7\\n2 1\\n6 2\\n5 3\\n6 3\\n\", \"3\\n82 0 0\\n2 1 1\\n88 0 0\\n3 1\\n3 2\\n\", \"7\\n3 1 0\\n5 0 1\\n16 0 1\\n64 0 1\\n37 1 0\\n97 1 1\\n36 1 0\\n7 1\\n1 4\\n4 5\\n2 4\\n4 6\\n1 3\\n\", \"5\\n67 0 0\\n96 1 0\\n40 0 1\\n59 0 0\\n17 0 0\\n4 5\\n1 4\\n5 2\\n5 3\\n\"], \"outputs\": [\"4\", \"24000\", \"-1\", \"16\", \"128\", \"0\", \"0\", \"142\", \"164\", \"124\", \"330\", \"252\", \"0\", \"114\", \"230\", \"0\", \"18\", \"34\"]}", "source": "primeintellect"}
Ashish has a tree consisting of $n$ nodes numbered $1$ to $n$ rooted at node $1$. The $i$-th node in the tree has a cost $a_i$, and binary digit $b_i$ is written in it. He wants to have binary digit $c_i$ written in the $i$-th node in the end. To achieve this, he can perform the following operation any number of times: Select any $k$ nodes from the subtree of any node $u$, and shuffle the digits in these nodes as he wishes, incurring a cost of $k \cdot a_u$. Here, he can choose $k$ ranging from $1$ to the size of the subtree of $u$. He wants to perform the operations in such a way that every node finally has the digit corresponding to its target. Help him find the minimum total cost he needs to spend so that after all the operations, every node $u$ has digit $c_u$ written in it, or determine that it is impossible. -----Input----- First line contains a single integer $n$ $(1 \le n \le 2 \cdot 10^5)$ denoting the number of nodes in the tree. $i$-th line of the next $n$ lines contains 3 space-separated integers $a_i$, $b_i$, $c_i$ $(1 \leq a_i \leq 10^9, 0 \leq b_i, c_i \leq 1)$  — the cost of the $i$-th node, its initial digit and its goal digit. Each of the next $n - 1$ lines contain two integers $u$, $v$ $(1 \leq u, v \leq n, \text{ } u \ne v)$, meaning that there is an edge between nodes $u$ and $v$ in the tree. -----Output----- Print the minimum total cost to make every node reach its target digit, and $-1$ if it is impossible. -----Examples----- Input 5 1 0 1 20 1 0 300 0 1 4000 0 0 50000 1 0 1 2 2 3 2 4 1 5 Output 4 Input 5 10000 0 1 2000 1 0 300 0 1 40 0 0 1 1 0 1 2 2 3 2 4 1 5 Output 24000 Input 2 109 0 1 205 0 1 1 2 Output -1 -----Note----- The tree corresponding to samples $1$ and $2$ are: [Image] In sample $1$, we can choose node $1$ and $k = 4$ for a cost of $4 \cdot 1$ = $4$ and select nodes ${1, 2, 3, 5}$, shuffle their digits and get the desired digits in every node. In sample $2$, we can choose node $1$ and $k = 2$ for a cost of $10000 \cdot 2$, select nodes ${1, 5}$ and exchange their digits, and similarly, choose node $2$ and $k = 2$ for a cost of $2000 \cdot 2$, select nodes ${2, 3}$ and exchange their digits to get the desired digits in every node. In sample $3$, it is impossible to get the desired digits, because there is no node with digit $1$ initially. 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 8\\nBBBBBBBB\\nBBBBBBBB\\nBBBBBBBB\\nWWWWWWWW\\nWWWWWWWW\\nWWWWWWWW\\n\", \"3 3\\nWBW\\nBWW\\nWWW\\n\", \"3 6\\nWWBBWW\\nWWBBWW\\nWWBBWW\\n\", \"4 4\\nBBBB\\nBBBB\\nBBBB\\nBBBW\\n\", \"10 9\\nBWWWBWWBB\\nBBWWBWBBW\\nBBWBWBWBB\\nBWBWBBBBB\\nBBWBWBWBW\\nBWWBWWBBW\\nWBWWWBWWW\\nWBBWBWBWW\\nBBWWBWWBB\\nBBWWBWWBW\\n\", \"4 1\\nW\\nW\\nB\\nB\\n\", \"2 10\\nBBWBWWBWBB\\nBBBBBBBBBW\\n\", \"100 1\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nW\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\nB\\n\", \"1 100\\nWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWWBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\\n\", \"4 5\\nBWWBB\\nBWBBW\\nWBWWW\\nWBWWB\\n\", \"2 9\\nWBBBWBBBW\\nBWWBBBBBB\\n\", \"6 6\\nBBWWWB\\nWBBBWB\\nBBBBBW\\nWWWWWW\\nBBBBBW\\nBWWBBB\\n\", \"1 1\\nW\\n\", \"1 1\\nB\\n\", \"1 8\\nWWBWWWWW\\n\", \"2 8\\nBBBBBBBB\\nBBBBBBBB\\n\", \"1 52\\nBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB\\n\", \"11 8\\nWWWWWWWW\\nWWWWWWWW\\nWWWWWWWW\\nWWWWWWWW\\nWWWWWWWW\\nWWWBWWWW\\nWWWWWWWW\\nWBWWWWWW\\nWWWWWWWW\\nWWWWWWWW\\nWWWWWWWW\\n\"], \"outputs\": [\"2\\n\", \"4\\n\", \"3\\n\", \"4\\n\", \"61\\n\", \"2\\n\", \"10\\n\", \"2\\n\", \"2\\n\", \"13\\n\", \"9\\n\", \"16\\n\", \"1\\n\", \"1\\n\", \"3\\n\", \"1\\n\", \"1\\n\", \"9\\n\"]}", "source": "primeintellect"}
The first algorithm for detecting a face on the image working in realtime was developed by Paul Viola and Michael Jones in 2001. A part of the algorithm is a procedure that computes Haar features. As part of this task, we consider a simplified model of this concept. Let's consider a rectangular image that is represented with a table of size n × m. The table elements are integers that specify the brightness of each pixel in the image. A feature also is a rectangular table of size n × m. Each cell of a feature is painted black or white. To calculate the value of the given feature at the given image, you must perform the following steps. First the table of the feature is put over the table of the image (without rotations or reflections), thus each pixel is entirely covered with either black or white cell. The value of a feature in the image is the value of W - B, where W is the total brightness of the pixels in the image, covered with white feature cells, and B is the total brightness of the pixels covered with black feature cells. Some examples of the most popular Haar features are given below. [Image] Your task is to determine the number of operations that are required to calculate the feature by using the so-called prefix rectangles. A prefix rectangle is any rectangle on the image, the upper left corner of which coincides with the upper left corner of the image. You have a variable value, whose value is initially zero. In one operation you can count the sum of pixel values ​​at any prefix rectangle, multiply it by any integer and add to variable value. You are given a feature. It is necessary to calculate the minimum number of operations required to calculate the values of this attribute at an arbitrary image. For a better understanding of the statement, read the explanation of the first sample. -----Input----- The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 100) — the number of rows and columns in the feature. Next n lines contain the description of the feature. Each line consists of m characters, the j-th character of the i-th line equals to "W", if this element of the feature is white and "B" if it is black. -----Output----- Print a single number — the minimum number of operations that you need to make to calculate the value of the feature. -----Examples----- Input 6 8 BBBBBBBB BBBBBBBB BBBBBBBB WWWWWWWW WWWWWWWW WWWWWWWW Output 2 Input 3 3 WBW BWW WWW Output 4 Input 3 6 WWBBWW WWBBWW WWBBWW Output 3 Input 4 4 BBBB BBBB BBBB BBBW Output 4 -----Note----- The first sample corresponds to feature B, the one shown in the picture. The value of this feature in an image of size 6 × 8 equals to the difference of the total brightness of the pixels in the lower and upper half of the image. To calculate its value, perform the following two operations: add the sum of pixels in the prefix rectangle with the lower right corner in the 6-th row and 8-th column with coefficient 1 to the variable value (the rectangle is indicated by a red frame); $\left. \begin{array}{|r|r|r|r|r|r|r|r|} \hline 1 & {1} & {1} & {1} & {1} & {1} & {1} & {1} \\ \hline 1 & {1} & {1} & {1} & {1} & {1} & {1} & {1} \\ \hline 1 & {1} & {1} & {1} & {1} & {1} & {1} & {1} \\ \hline 1 & {1} & {1} & {1} & {1} & {1} & {1} & {1} \\ \hline 1 & {1} & {1} & {1} & {1} & {1} & {1} & {1} \\ \hline 1 & {1} & {1} & {1} & {1} & {1} & {1} & {1} \\ \hline \end{array} \right.$ add the number of pixels in the prefix rectangle with the lower right corner in the 3-rd row and 8-th column with coefficient - 2 and variable value. [Image] Thus, all the pixels in the lower three rows of the image will be included with factor 1, and all pixels in the upper three rows of the image will be included with factor 1 - 2 = - 1, as required. 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 10\\n5 5\\n7 6\\n\", \"4 5 2\\n8 1 1 2\\n6 3 7 5 2\\n\", \"1 1 2\\n1\\n2\\n\", \"4 1 1\\n3 2 3 2\\n3\\n\", \"1 4 1\\n3\\n2 4 5 5\\n\", \"3 3 3\\n1 1 2\\n3 5 6\\n\", \"4 5 6\\n5 1 7 2\\n8 7 3 9 8\\n\", \"4 8 10\\n2 1 2 2\\n10 12 10 8 7 9 10 9\\n\", \"8 4 18\\n9 4 2 2 7 5 1 1\\n11 12 8 9\\n\", \"6 6 2\\n6 1 5 3 10 1\\n11 4 7 8 11 7\\n\", \"10 10 7\\n6 7 15 1 3 1 14 6 7 4\\n15 3 13 17 11 19 20 14 8 17\\n\", \"14 14 22\\n23 1 3 16 23 1 7 5 18 7 3 6 17 8\\n22 14 22 18 12 11 7 24 20 27 10 22 16 7\\n\", \"10 20 36\\n12 4 7 18 4 4 2 7 4 10\\n9 18 7 7 30 19 26 27 16 20 30 25 23 17 5 30 22 7 13 6\\n\", \"20 10 31\\n17 27 2 6 11 12 5 3 12 4 2 10 4 8 2 10 7 9 12 1\\n24 11 18 10 30 16 20 18 24 24\\n\", \"40 40 61\\n28 59 8 27 45 67 33 32 61 3 42 2 3 37 8 8 10 61 1 5 65 28 34 27 8 35 45 49 31 49 13 23 23 53 20 48 14 74 16 6\\n69 56 34 66 42 73 45 49 29 70 67 77 73 26 78 11 50 69 64 72 78 66 66 29 80 40 50 75 68 47 78 63 41 70 52 52 69 22 69 66\\n\", \"10 10 0\\n1000 1000 1000 1000 1000 1000 1000 1000 1000 1000\\n1001 1001 1001 1001 1001 1001 1001 1001 1001 1001\\n\", \"9 8 0\\n1 2 3 4 5 6 7 8 9\\n2 3 4 5 6 7 8 9\\n\", \"9 8 0\\n1 2 3 4 5 6 7 8 9\\n1 2 3 4 5 6 7 8\\n\"], \"outputs\": [\"2 3\\n\", \"3 8\\n\", \"1 0\\n\", \"1 2\\n\", \"1 1\\n\", \"1 0\\n\", \"3 12\\n\", \"1 0\\n\", \"4 22\\n\", \"3 16\\n\", \"5 42\\n\", \"10 115\\n\", \"10 69\\n\", \"7 86\\n\", \"22 939\\n\", \"0 0\\n\", \"8 44\\n\", \"8 36\\n\"]}", "source": "primeintellect"}
A group of n schoolboys decided to ride bikes. As nobody of them has a bike, the boys need to rent them. The renting site offered them m bikes. The renting price is different for different bikes, renting the j-th bike costs p_{j} rubles. In total, the boys' shared budget is a rubles. Besides, each of them has his own personal money, the i-th boy has b_{i} personal rubles. The shared budget can be spent on any schoolchildren arbitrarily, but each boy's personal money can be spent on renting only this boy's bike. Each boy can rent at most one bike, one cannot give his bike to somebody else. What maximum number of schoolboys will be able to ride bikes? What minimum sum of personal money will they have to spend in total to let as many schoolchildren ride bikes as possible? -----Input----- The first line of the input contains three integers n, m and a (1 ≤ n, m ≤ 10^5; 0 ≤ a ≤ 10^9). The second line contains the sequence of integers b_1, b_2, ..., b_{n} (1 ≤ b_{i} ≤ 10^4), where b_{i} is the amount of the i-th boy's personal money. The third line contains the sequence of integers p_1, p_2, ..., p_{m} (1 ≤ p_{j} ≤ 10^9), where p_{j} is the price for renting the j-th bike. -----Output----- Print two integers r and s, where r is the maximum number of schoolboys that can rent a bike and s is the minimum total personal money needed to rent r bikes. If the schoolchildren cannot rent any bikes, then r = s = 0. -----Examples----- Input 2 2 10 5 5 7 6 Output 2 3 Input 4 5 2 8 1 1 2 6 3 7 5 2 Output 3 8 -----Note----- In the first sample both schoolchildren can rent a bike. For instance, they can split the shared budget in half (5 rubles each). In this case one of them will have to pay 1 ruble from the personal money and the other one will have to pay 2 rubles from the personal money. In total, they spend 3 rubles of their personal money. This way of distribution of money minimizes the amount of spent personal money. 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\\n1 3\\n\", \"34 7\\n10 28\\n10 19\\n10 13\\n24 10\\n10 29\\n20 10\\n10 26\\n\", \"84 3\\n39 19\\n55 73\\n42 43\\n\", \"84 0\\n\", \"34 7\\n11 32\\n33 29\\n17 16\\n15 5\\n13 25\\n8 19\\n20 4\\n\", \"43 21\\n38 19\\n43 8\\n40 31\\n3 14\\n24 21\\n12 17\\n1 9\\n5 27\\n25 37\\n11 6\\n13 26\\n16 22\\n10 32\\n36 7\\n30 29\\n42 35\\n20 33\\n4 23\\n18 15\\n41 34\\n2 28\\n\", \"34 7\\n22 4\\n5 25\\n15 7\\n5 9\\n27 7\\n34 21\\n3 13\\n\", \"50 7\\n19 37\\n30 32\\n43 20\\n48 14\\n30 29\\n18 36\\n9 46\\n\", \"41 12\\n41 12\\n29 13\\n3 37\\n2 20\\n4 24\\n27 6\\n39 20\\n28 41\\n30 1\\n35 9\\n5 39\\n12 31\\n\", \"26 2\\n22 1\\n14 10\\n\", \"7 3\\n4 7\\n4 6\\n6 5\\n\", \"50 24\\n18 36\\n11 18\\n22 18\\n18 47\\n18 10\\n45 18\\n18 29\\n13 18\\n8 18\\n18 30\\n26 18\\n18 6\\n5 18\\n18 7\\n46 18\\n50 18\\n18 3\\n18 32\\n4 18\\n18 24\\n18 19\\n23 18\\n35 18\\n31 18\\n\", \"7 3\\n3 4\\n7 3\\n3 2\\n\", \"1 0\\n\", \"2 0\\n\", \"4 1\\n1 2\\n\", \"3 1\\n1 2\\n\", \"5 1\\n1 5\\n\"], \"outputs\": [\"3\\n1 2\\n4 2\\n2 3\\n\", \"33\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n\", \"83\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n1 35\\n1 36\\n1 37\\n1 38\\n1 39\\n1 40\\n1 41\\n1 42\\n1 43\\n1 44\\n1 45\\n1 46\\n1 47\\n1 48\\n1 49\\n1 50\\n1 51\\n1 52\\n1 53\\n1 54\\n1 55\\n1 56\\n1 57\\n1 58\\n1 59\\n1 60\\n1 61\\n1 62\\n1 63\\n1 64\\n1 65\\n1 66\\n1 67\\n1 68\\n1 69\\n1 70\\n1 71\\n1 72\\n1 73\\n1 74\\n1 75\\n1 76\\n1 77\\n1 78\\n1 79\\n1 80\\n1 81\\n1 82\\n1 83\\n1 84\\n\", \"83\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n1 35\\n1 36\\n1 37\\n1 38\\n1 39\\n1 40\\n1 41\\n1 42\\n1 43\\n1 44\\n1 45\\n1 46\\n1 47\\n1 48\\n1 49\\n1 50\\n1 51\\n1 52\\n1 53\\n1 54\\n1 55\\n1 56\\n1 57\\n1 58\\n1 59\\n1 60\\n1 61\\n1 62\\n1 63\\n1 64\\n1 65\\n1 66\\n1 67\\n1 68\\n1 69\\n1 70\\n1 71\\n1 72\\n1 73\\n1 74\\n1 75\\n1 76\\n1 77\\n1 78\\n1 79\\n1 80\\n1 81\\n1 82\\n1 83\\n1 84\\n\", \"33\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n\", \"42\\n39 1\\n39 2\\n39 3\\n39 4\\n39 5\\n39 6\\n39 7\\n39 8\\n39 9\\n39 10\\n39 11\\n39 12\\n39 13\\n39 14\\n39 15\\n39 16\\n39 17\\n39 18\\n39 19\\n39 20\\n39 21\\n39 22\\n39 23\\n39 24\\n39 25\\n39 26\\n39 27\\n39 28\\n39 29\\n39 30\\n39 31\\n39 32\\n39 33\\n39 34\\n39 35\\n39 36\\n39 37\\n39 38\\n39 40\\n39 41\\n39 42\\n39 43\\n\", \"33\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n\", \"49\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n1 35\\n1 36\\n1 37\\n1 38\\n1 39\\n1 40\\n1 41\\n1 42\\n1 43\\n1 44\\n1 45\\n1 46\\n1 47\\n1 48\\n1 49\\n1 50\\n\", \"40\\n7 1\\n7 2\\n7 3\\n7 4\\n7 5\\n7 6\\n7 8\\n7 9\\n7 10\\n7 11\\n7 12\\n7 13\\n7 14\\n7 15\\n7 16\\n7 17\\n7 18\\n7 19\\n7 20\\n7 21\\n7 22\\n7 23\\n7 24\\n7 25\\n7 26\\n7 27\\n7 28\\n7 29\\n7 30\\n7 31\\n7 32\\n7 33\\n7 34\\n7 35\\n7 36\\n7 37\\n7 38\\n7 39\\n7 40\\n7 41\\n\", \"25\\n2 1\\n2 3\\n2 4\\n2 5\\n2 6\\n2 7\\n2 8\\n2 9\\n2 10\\n2 11\\n2 12\\n2 13\\n2 14\\n2 15\\n2 16\\n2 17\\n2 18\\n2 19\\n2 20\\n2 21\\n2 22\\n2 23\\n2 24\\n2 25\\n2 26\\n\", \"6\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n\", \"49\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n1 10\\n1 11\\n1 12\\n1 13\\n1 14\\n1 15\\n1 16\\n1 17\\n1 18\\n1 19\\n1 20\\n1 21\\n1 22\\n1 23\\n1 24\\n1 25\\n1 26\\n1 27\\n1 28\\n1 29\\n1 30\\n1 31\\n1 32\\n1 33\\n1 34\\n1 35\\n1 36\\n1 37\\n1 38\\n1 39\\n1 40\\n1 41\\n1 42\\n1 43\\n1 44\\n1 45\\n1 46\\n1 47\\n1 48\\n1 49\\n1 50\\n\", \"6\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n\", \"0\\n\", \"1\\n1 2\\n\", \"3\\n3 1\\n3 2\\n3 4\\n\", \"2\\n3 1\\n3 2\\n\", \"4\\n2 1\\n2 3\\n2 4\\n2 5\\n\"]}", "source": "primeintellect"}
A country has n cities. Initially, there is no road in the country. One day, the king decides to construct some roads connecting pairs of cities. Roads can be traversed either way. He wants those roads to be constructed in such a way that it is possible to go from each city to any other city by traversing at most two roads. You are also given m pairs of cities — roads cannot be constructed between these pairs of cities. Your task is to construct the minimum number of roads that still satisfy the above conditions. The constraints will guarantee that this is always possible. -----Input----- The first line consists of two integers n and m $(1 \leq n \leq 10^{3}, 0 \leq m < \frac{n}{2})$. Then m lines follow, each consisting of two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}), which means that it is not possible to construct a road connecting cities a_{i} and b_{i}. Consider the cities are numbered from 1 to n. It is guaranteed that every pair of cities will appear at most once in the input. -----Output----- You should print an integer s: the minimum number of roads that should be constructed, in the first line. Then s lines should follow, each consisting of two integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}), which means that a road should be constructed between cities a_{i} and b_{i}. If there are several solutions, you may print any of them. -----Examples----- Input 4 1 1 3 Output 3 1 2 4 2 2 3 -----Note----- This is one possible solution of the example: [Image] These are examples of wrong solutions: [Image] The above solution is wrong because it doesn't use the minimum number of edges (4 vs 3). In addition, it also tries to construct a road between cities 1 and 3, while the input specifies that it is not allowed to construct a road between the pair. [Image] The above solution is wrong because you need to traverse at least 3 roads to go from city 1 to city 3, whereas in your country it must be possible to go from any city to another by traversing at most 2 roads. [Image] Finally, the above solution is wrong because it must be possible to go from any city to another, whereas it is not possible in this country to go from city 1 to 3, 2 to 3, and 4 to 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\": [\"9\\n88 22 83 14 95 91 98 53 11\\n3 24\\n7 -8\\n1 67\\n1 64\\n9 65\\n5 12\\n6 -80\\n3 8\\n\", \"6\\n53 82 15 77 71 23\\n5 -77\\n6 -73\\n2 0\\n1 26\\n4 -92\\n\", \"10\\n99 60 68 46 51 11 96 41 48 99\\n4 50\\n6 -97\\n3 -92\\n7 1\\n9 99\\n2 79\\n1 -15\\n8 -68\\n5 -84\\n\", \"8\\n53 41 22 22 34 95 56 24\\n3 -20\\n7 -56\\n5 -3\\n3 22\\n1 37\\n6 -34\\n2 32\\n\", \"8\\n2 19 83 95 9 87 15 6\\n6 16\\n7 98\\n5 32\\n7 90\\n8 37\\n2 -34\\n1 -83\\n\", \"6\\n60 89 33 64 92 75\\n4 50\\n1 32\\n5 21\\n3 77\\n1 86\\n\", \"4\\n14 66 86 37\\n3 -9\\n1 93\\n2 -57\\n\", \"9\\n59 48 48 14 51 51 86 53 58\\n1 -47\\n5 10\\n8 -6\\n9 46\\n2 -69\\n8 -79\\n9 92\\n6 12\\n\", \"3\\n17 26 6\\n1 -41\\n2 -66\\n\", \"7\\n63 3 67 55 14 19 96\\n4 35\\n1 -23\\n3 -66\\n2 80\\n3 80\\n2 -42\\n\", \"5\\n91 61 4 61 35\\n5 75\\n2 13\\n2 -15\\n1 90\\n\", \"19\\n40 99 20 54 5 31 67 73 10 46 70 68 80 74 7 58 75 25 13\\n13 -28\\n12 -33\\n9 -62\\n12 34\\n15 70\\n5 -22\\n7 83\\n2 -24\\n6 -64\\n17 62\\n14 -28\\n1 -83\\n4 34\\n8 -24\\n11 19\\n6 31\\n7 -8\\n16 90\\n\", \"39\\n98 80 74 31 81 15 23 52 54 86 56 9 95 91 29 20 97 78 62 65 17 95 12 39 77 17 60 78 76 51 36 56 74 66 43 23 17 9 13\\n15 21\\n34 -35\\n28 80\\n13 -15\\n29 -34\\n38 -8\\n18 10\\n18 19\\n27 54\\n7 42\\n16 49\\n12 90\\n39 33\\n20 53\\n2 91\\n33 59\\n29 -93\\n36 29\\n26 50\\n5 -12\\n33 -6\\n17 -60\\n27 7\\n17 85\\n31 63\\n26 80\\n1 -99\\n4 -40\\n10 -39\\n11 36\\n21 22\\n16 -15\\n14 -25\\n25 30\\n33 97\\n38 26\\n8 -78\\n10 -7\\n\", \"19\\n51 5 39 54 26 71 97 99 73 16 31 9 52 38 89 87 55 12 3\\n18 -94\\n19 -48\\n2 -61\\n10 72\\n1 -82\\n13 4\\n19 -40\\n16 -96\\n6 -16\\n19 -40\\n13 44\\n11 38\\n15 -7\\n6 8\\n18 -32\\n8 -75\\n3 58\\n10 -15\\n\", \"39\\n100 83 92 26 10 63 56 85 12 64 25 50 75 51 11 41 78 53 52 96 63 12 48 88 57 57 25 52 69 45 4 97 5 87 58 15 72 59 100\\n35 -60\\n33 -39\\n1 65\\n11 -65\\n34 -63\\n38 84\\n4 76\\n22 -9\\n6 -91\\n23 -65\\n18 7\\n2 -17\\n29 -15\\n19 26\\n29 23\\n14 -12\\n30 -72\\n9 14\\n12 -1\\n27 -21\\n32 -67\\n7 -3\\n26 -18\\n12 -45\\n33 75\\n14 -86\\n34 -46\\n24 -44\\n27 -29\\n22 -39\\n17 -73\\n36 -72\\n18 -76\\n27 -65\\n8 65\\n24 -15\\n35 79\\n27 61\\n\", \"2\\n83 33\\n1 67\\n\", \"6\\n538779323 241071283 506741761 673531032 208769045 334127496\\n1 -532301622\\n5 -912729787\\n6 -854756762\\n4 -627791911\\n2 -289935846\\n\", \"10\\n909382626 193846090 573881879 291637627 123338066 411896152 123287948 171497812 135534629 568762298\\n9 -257478179\\n4 -502075958\\n2 -243790121\\n2 -927464462\\n8 -89981403\\n1 -792322781\\n10 -326468006\\n7 -261940740\\n4 -565652087\\n\"], \"outputs\": [\"5\\n\", \"0\\n\", \"7\\n\", \"1\\n\", \"5\\n\", \"4\\n\", \"3\\n\", \"5\\n\", \"0\\n\", \"4\\n\", \"4\\n\", \"11\\n\", \"37\\n\", \"7\\n\", \"38\\n\", \"1\\n\", \"0\\n\", \"0\\n\"]}", "source": "primeintellect"}
Alyona decided to go on a diet and went to the forest to get some apples. There she unexpectedly found a magic rooted tree with root in the vertex 1, every vertex and every edge of which has a number written on. The girl noticed that some of the tree's vertices are sad, so she decided to play with them. Let's call vertex v sad if there is a vertex u in subtree of vertex v such that dist(v, u) > a_{u}, where a_{u} is the number written on vertex u, dist(v, u) is the sum of the numbers written on the edges on the path from v to u. Leaves of a tree are vertices connected to a single vertex by a single edge, but the root of a tree is a leaf if and only if the tree consists of a single vertex — root. Thus Alyona decided to remove some of tree leaves until there will be no any sad vertex left in the tree. What is the minimum number of leaves Alyona needs to remove? -----Input----- In the first line of the input integer n (1 ≤ n ≤ 10^5) is given — the number of vertices in the tree. In the second line the sequence of n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9) is given, where a_{i} is the number written on vertex i. The next n - 1 lines describe tree edges: i^{th} of them consists of two integers p_{i} and c_{i} (1 ≤ p_{i} ≤ n, - 10^9 ≤ c_{i} ≤ 10^9), meaning that there is an edge connecting vertices i + 1 and p_{i} with number c_{i} written on it. -----Output----- Print the only integer — the minimum number of leaves Alyona needs to remove such that there will be no any sad vertex left in the tree. -----Example----- Input 9 88 22 83 14 95 91 98 53 11 3 24 7 -8 1 67 1 64 9 65 5 12 6 -80 3 8 Output 5 -----Note----- The following image represents possible process of removing leaves from the tree: [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 2 2\\n\", \"3 2 1\\n\", \"7 2 3\\n\", \"9 2 3\\n\", \"2 1 1000\\n\", \"1000 2 8\\n\", \"513 2 9\\n\", \"82 3 4\\n\", \"244 3 5\\n\", \"1000 999 1\\n\", \"1 1 1\\n\", \"1 1 2\\n\", \"2 1 1\\n\", \"1 2 1\\n\", \"5 3 2\\n\", \"1 1000000000 1\\n\", \"27 3 3\\n\", \"1 1 10\\n\"], \"outputs\": [\"1 1 2 \\n1 2 1 \\n\", \"-1\\n\", \"1 1 1 1 2 2 2 \\n1 1 2 2 1 1 2 \\n1 2 1 2 1 2 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 1 1 2 2 \\n1 2 3 1 2 \\n\", \"1 \\n\", \"1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3 3 \\n1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 1 1 1 2 2 2 3 3 3 \\n1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 1 2 3 \\n\", \"1 \\n1 \\n1 \\n1 \\n1 \\n1 \\n1 \\n1 \\n1 \\n1 \\n\"]}", "source": "primeintellect"}
Recently Pashmak has been employed in a transportation company. The company has k buses and has a contract with a school which has n students. The school planned to take the students to d different places for d days (each day in one place). Each day the company provides all the buses for the trip. Pashmak has to arrange the students in the buses. He wants to arrange the students in a way that no two students become close friends. In his ridiculous idea, two students will become close friends if and only if they are in the same buses for all d days. Please help Pashmak with his weird idea. Assume that each bus has an unlimited capacity. -----Input----- The first line of input contains three space-separated integers n, k, d (1 ≤ n, d ≤ 1000; 1 ≤ k ≤ 10^9). -----Output----- If there is no valid arrangement just print -1. Otherwise print d lines, in each of them print n integers. The j-th integer of the i-th line shows which bus the j-th student has to take on the i-th day. You can assume that the buses are numbered from 1 to k. -----Examples----- Input 3 2 2 Output 1 1 2 1 2 1 Input 3 2 1 Output -1 -----Note----- Note that two students become close friends only if they share a bus each day. But the bus they share can differ from day to day. 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 2 3\\n4 3 2\\n3 1 3\\n1 2\\n2 3\\n\", \"5\\n3 4 2 1 2\\n4 2 1 5 4\\n5 3 2 1 1\\n1 2\\n3 2\\n4 3\\n5 3\\n\", \"5\\n3 4 2 1 2\\n4 2 1 5 4\\n5 3 2 1 1\\n1 2\\n3 2\\n4 3\\n5 4\\n\", \"4\\n4 7 3 2\\n2 3 7 2\\n1 1 2 1\\n4 3\\n1 2\\n3 2\\n\", \"7\\n1 8 3 2 6 3 2\\n2 6 6 5 4 1 9\\n6 4 7 1 5 5 2\\n2 6\\n1 6\\n6 4\\n3 4\\n2 5\\n7 1\\n\", \"4\\n55 70 35 4\\n90 10 100 6\\n58 87 24 21\\n3 4\\n1 2\\n3 2\\n\", \"5\\n17 51 38 4 38\\n21 75 13 82 43\\n62 32 84 72 29\\n1 4\\n4 3\\n2 5\\n3 2\\n\", \"10\\n100 26 100 22 4 32 29 23 41 26\\n54 20 97 84 12 13 45 73 91 41\\n25 53 52 33 97 80 100 7 31 36\\n5 4\\n10 7\\n3 9\\n8 2\\n3 1\\n1 2\\n6 10\\n8 5\\n4 6\\n\", \"15\\n10 34 69 39 82 49 57 22 50 25 82 37 33 62 69\\n35 14 68 31 26 8 33 98 33 95 19 22 89 18 67\\n80 24 10 5 26 85 69 21 29 38 89 24 78 68 88\\n13 1\\n6 12\\n8 4\\n11 9\\n14 11\\n15 5\\n3 15\\n1 10\\n13 9\\n7 12\\n14 6\\n3 2\\n2 7\\n4 5\\n\", \"14\\n91 43 4 87 52 50 48 57 96 79 91 64 44 22\\n69 11 42 26 61 87 4 50 19 46 52 71 27 83\\n2 1 16 76 21 5 66 40 54 4 44 5 47 55\\n1 10\\n2 10\\n4 12\\n11 3\\n7 2\\n5 6\\n12 1\\n13 8\\n3 6\\n4 14\\n8 9\\n2 13\\n11 7\\n\", \"8\\n69 44 1 96 69 29 8 74\\n89 77 25 99 2 32 41 40\\n38 6 18 33 43 25 63 12\\n1 4\\n3 1\\n8 5\\n1 6\\n6 2\\n2 7\\n7 5\\n\", \"10\\n26 100 22 4 32 29 23 41 26 54\\n20 97 84 12 13 45 73 91 41 25\\n53 52 33 97 80 100 7 31 36 99\\n8 2\\n3 1\\n10 4\\n8 5\\n1 2\\n6 10\\n10 7\\n5 4\\n3 9\\n\", \"15\\n34 69 39 82 49 57 22 50 25 82 37 33 62 69 35\\n14 68 31 26 8 33 98 33 95 19 22 89 18 67 80\\n24 10 5 26 85 69 21 29 38 89 24 78 68 88 65\\n5 2\\n13 1\\n2 7\\n6 12\\n14 6\\n8 4\\n14 11\\n13 9\\n15 3\\n7 12\\n1 10\\n5 4\\n15 5\\n11 9\\n\", \"7\\n2 3 1 6 4 2 3\\n3 1 7 4 3 3 3\\n4 6 2 2 6 3 2\\n4 2\\n7 5\\n7 1\\n2 7\\n6 2\\n3 4\\n\", \"5\\n3 5 2 7 8\\n1 7 2 8 8\\n3 3 6 7 3\\n2 3\\n2 5\\n2 1\\n4 5\\n\", \"6\\n3 3 1 3 2 3\\n1 3 1 4 5 3\\n3 1 6 3 4 4\\n5 4\\n6 3\\n1 5\\n2 5\\n2 6\\n\", \"5\\n3 5 3 4 1\\n3 4 5 4 5\\n1 1 1 4 4\\n1 3\\n4 1\\n4 2\\n5 2\\n\", \"4\\n2 3 5 2\\n4 5 5 6\\n4 2 4 3\\n4 3\\n1 4\\n2 3\\n\"], \"outputs\": [\"6\\n1 3 2 \\n\", \"-1\\n\", \"9\\n1 3 2 1 3 \\n\", \"8\\n2 3 1 2 \\n\", \"-1\\n\", \"93\\n1 2 3 1 \\n\", \"149\\n3 3 2 1 1 \\n\", \"364\\n2 1 3 1 2 3 1 3 1 2 \\n\", \"620\\n2 3 2 2 3 3 1 1 3 3 2 2 1 1 1 \\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"10\\n1 3 3 2 1 \\n\", \"13\\n1 1 2 3 \\n\"]}", "source": "primeintellect"}
You are given a tree consisting of $n$ vertices. A tree is an undirected connected acyclic graph. [Image] Example of a tree. You have to paint each vertex into one of three colors. For each vertex, you know the cost of painting it in every color. You have to paint the vertices so that any path consisting of exactly three distinct vertices does not contain any vertices with equal colors. In other words, let's consider all triples $(x, y, z)$ such that $x \neq y, y \neq z, x \neq z$, $x$ is connected by an edge with $y$, and $y$ is connected by an edge with $z$. The colours of $x$, $y$ and $z$ should be pairwise distinct. Let's call a painting which meets this condition good. You have to calculate the minimum cost of a good painting and find one of the optimal paintings. If there is no good painting, report about it. -----Input----- The first line contains one integer $n$ $(3 \le n \le 100\,000)$ — the number of vertices. The second line contains a sequence of integers $c_{1, 1}, c_{1, 2}, \dots, c_{1, n}$ $(1 \le c_{1, i} \le 10^{9})$, where $c_{1, i}$ is the cost of painting the $i$-th vertex into the first color. The third line contains a sequence of integers $c_{2, 1}, c_{2, 2}, \dots, c_{2, n}$ $(1 \le c_{2, i} \le 10^{9})$, where $c_{2, i}$ is the cost of painting the $i$-th vertex into the second color. The fourth line contains a sequence of integers $c_{3, 1}, c_{3, 2}, \dots, c_{3, n}$ $(1 \le c_{3, i} \le 10^{9})$, where $c_{3, i}$ is the cost of painting the $i$-th vertex into the third color. Then $(n - 1)$ lines follow, each containing two integers $u_j$ and $v_j$ $(1 \le u_j, v_j \le n, u_j \neq v_j)$ — the numbers of vertices connected by the $j$-th undirected edge. It is guaranteed that these edges denote a tree. -----Output----- If there is no good painting, print $-1$. Otherwise, print the minimum cost of a good painting in the first line. In the second line print $n$ integers $b_1, b_2, \dots, b_n$ $(1 \le b_i \le 3)$, where the $i$-th integer should denote the color of the $i$-th vertex. If there are multiple good paintings with minimum cost, print any of them. -----Examples----- Input 3 3 2 3 4 3 2 3 1 3 1 2 2 3 Output 6 1 3 2 Input 5 3 4 2 1 2 4 2 1 5 4 5 3 2 1 1 1 2 3 2 4 3 5 3 Output -1 Input 5 3 4 2 1 2 4 2 1 5 4 5 3 2 1 1 1 2 3 2 4 3 5 4 Output 9 1 3 2 1 3 -----Note----- All vertices should be painted in different colors in the first example. The optimal way to do it is to paint the first vertex into color $1$, the second vertex — into color $3$, and the third vertex — into color $2$. The cost of this painting is $3 + 2 + 1 = 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\": [\"4 2\\n1 100\\n40 70\\n120 130\\n125 180\\n\", \"3 2\\n1 12\\n15 20\\n25 30\\n\", \"5 2\\n1 10\\n5 15\\n14 50\\n30 70\\n99 100\\n\", \"7 6\\n-8 6\\n7 9\\n-10 -5\\n-6 10\\n-7 -3\\n5 8\\n4 10\\n\", \"9 6\\n-7 -3\\n-3 10\\n-6 1\\n-1 8\\n-9 4\\n-7 -6\\n-5 -3\\n-10 -2\\n3 4\\n\", \"7 7\\n9 10\\n-5 3\\n-6 2\\n1 6\\n-9 6\\n-10 7\\n-7 -5\\n\", \"23 2\\n-629722518 -626148345\\n739975524 825702590\\n-360913153 -208398929\\n76588954 101603025\\n-723230356 -650106339\\n-117490984 -101920679\\n-39187628 -2520915\\n717852164 720343632\\n-611281114 -579708833\\n-141791522 -122348148\\n605078929 699430996\\n-873386085 -820238799\\n-922404067 -873522961\\n7572046 13337057\\n975081176 977171682\\n901338407 964254238\\n325388219 346712972\\n505189756 516497863\\n-425326983 -422098946\\n520670681 522544433\\n-410872616 -367919621\\n359488350 447471156\\n-566203447 -488202136\\n\", \"24 21\\n240694945 246896662\\n240694930 246896647\\n240695065 246896782\\n240695050 246896767\\n240695080 246896797\\n240694960 246896677\\n240694975 246896692\\n240694825 246896542\\n240694900 246896617\\n240694915 246896632\\n240694885 246896602\\n240694855 246896572\\n240694870 246896587\\n240694795 246896512\\n240695095 246896812\\n240695125 246896842\\n240695005 246896722\\n240694990 246896707\\n240695140 246896857\\n240695020 246896737\\n240695035 246896752\\n240694840 246896557\\n240694810 246896527\\n240695110 246896827\\n\", \"1 1\\n2 2\\n\", \"1 1\\n-1000000000 1000000000\\n\", \"2 1\\n-1000000000 -1000000000\\n1000000000 1000000000\\n\", \"7 3\\n3 3\\n-6 -1\\n6 7\\n2 8\\n3 10\\n-8 0\\n-3 10\\n\", \"5 4\\n4 7\\n-4 2\\n-7 -7\\n-5 -2\\n-8 -8\\n\", \"7 7\\n0 7\\n9 9\\n-10 -7\\n5 8\\n-10 4\\n-7 0\\n-3 5\\n\", \"9 2\\n5 10\\n-10 -10\\n0 10\\n-6 3\\n-8 7\\n6 10\\n-8 1\\n5 7\\n2 2\\n\", \"9 5\\n-2 1\\n-6 9\\n-7 -2\\n5 7\\n-10 -7\\n-9 -2\\n1 4\\n-1 10\\n4 8\\n\", \"54 7\\n-98 -39\\n14 60\\n-23 -5\\n58 75\\n14 16\\n-40 20\\n-6 10\\n11 60\\n-47 54\\n-71 -17\\n-48 -25\\n-87 -46\\n-10 99\\n-97 -88\\n-14 94\\n-25 29\\n-96 -92\\n68 75\\n-75 2\\n12 84\\n-47 3\\n-88 49\\n-37 88\\n-61 -25\\n36 67\\n30 54\\n12 31\\n-71 60\\n-18 -15\\n-61 -47\\n-51 -41\\n-67 51\\n26 37\\n18 94\\n-67 52\\n-16 56\\n-5 26\\n27 57\\n36 91\\n-61 61\\n71 86\\n27 73\\n-57 -39\\n54 71\\n-16 14\\n-97 81\\n-32 49\\n-18 50\\n-63 93\\n51 70\\n8 66\\n43 45\\n-2 99\\n11 98\\n\", \"52 18\\n-50 54\\n35 65\\n67 82\\n-87 -10\\n-39 4\\n-55 -18\\n-27 90\\n-42 73\\n18 43\\n70 85\\n-85 -22\\n-1 60\\n-89 23\\n-78 -75\\n-14 69\\n-69 50\\n-93 74\\n-10 45\\n-81 -72\\n-24 86\\n-89 100\\n25 70\\n-65 -61\\n-45 100\\n-49 -23\\n-74 -59\\n-81 -15\\n-58 47\\n-65 -58\\n-47 16\\n-22 91\\n-85 19\\n-81 77\\n79 87\\n-31 88\\n26 32\\n11 90\\n7 46\\n64 83\\n-51 -20\\n-76 44\\n-22 75\\n45 84\\n-98 46\\n-20 78\\n-88 -47\\n-41 65\\n2 93\\n-66 69\\n-73 94\\n-85 -44\\n-65 -23\\n\"], \"outputs\": [\"31\\n1 2 \\n\", \"0\\n1 2 \\n\", \"21\\n3 4 \\n\", \"0\\n1 2 3 4 5 6 \\n\", \"1\\n1 2 3 5 7 8 \\n\", \"0\\n1 2 3 4 5 6 7 \\n\", \"0\\n1 2 \\n\", \"6201418\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 17 18 20 21 22 23 \\n\", \"1\\n1 \\n\", \"2000000001\\n1 \\n\", \"1\\n1 \\n\", \"6\\n4 5 7 \\n\", \"0\\n1 2 3 4 \\n\", \"0\\n1 2 3 4 5 6 7 \\n\", \"10\\n5 7 \\n\", \"0\\n1 2 3 4 5 \\n\", \"111\\n22 28 32 35 40 46 49 \\n\", \"67\\n1 7 8 16 17 20 21 24 28 31 33 35 41 42 44 47 49 50 \\n\"]}", "source": "primeintellect"}
All our characters have hobbies. The same is true for Fedor. He enjoys shopping in the neighboring supermarket. The goods in the supermarket have unique integer ids. Also, for every integer there is a product with id equal to this integer. Fedor has n discount coupons, the i-th of them can be used with products with ids ranging from l_{i} to r_{i}, inclusive. Today Fedor wants to take exactly k coupons with him. Fedor wants to choose the k coupons in such a way that the number of such products x that all coupons can be used with this product x is as large as possible (for better understanding, see examples). Fedor wants to save his time as well, so he asks you to choose coupons for him. Help Fedor! -----Input----- The first line contains two integers n and k (1 ≤ k ≤ n ≤ 3·10^5) — the number of coupons Fedor has, and the number of coupons he wants to choose. Each of the next n lines contains two integers l_{i} and r_{i} ( - 10^9 ≤ l_{i} ≤ r_{i} ≤ 10^9) — the description of the i-th coupon. The coupons can be equal. -----Output----- In the first line print single integer — the maximum number of products with which all the chosen coupons can be used. The products with which at least one coupon cannot be used shouldn't be counted. In the second line print k distinct integers p_1, p_2, ..., p_{k} (1 ≤ p_{i} ≤ n) — the ids of the coupons which Fedor should choose. If there are multiple answers, print any of them. -----Examples----- Input 4 2 1 100 40 70 120 130 125 180 Output 31 1 2 Input 3 2 1 12 15 20 25 30 Output 0 1 2 Input 5 2 1 10 5 15 14 50 30 70 99 100 Output 21 3 4 -----Note----- In the first example if we take the first two coupons then all the products with ids in range [40, 70] can be bought with both coupons. There are 31 products in total. In the second example, no product can be bought with two coupons, that is why the answer is 0. Fedor can choose any two coupons in this example. 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\\nDI\\n\", \"2 2\\nMA\\nID\\n\", \"5 5\\nDIMAD\\nDIMAI\\nDIMAM\\nDDMAA\\nAAMID\\n\", \"1 1\\nI\\n\", \"5 5\\nDIMAD\\nADDDI\\nMDDDM\\nIDDDA\\nDAMID\\n\", \"5 5\\nAAAAA\\nAAAAA\\nAAAAA\\nAAAAA\\nAAAAA\\n\", \"1 1\\nD\\n\", \"1 4\\nDIMA\\n\", \"4 1\\nD\\nI\\nM\\nA\\n\", \"2 2\\nDI\\nAM\\n\", \"2 2\\nDI\\nMA\\n\", \"5 5\\nDIADD\\nDMADD\\nDDDID\\nAMMMD\\nMIDAD\\n\", \"10 10\\nDIDDIMDIDD\\nDMDDAADIDD\\nDADDDDDMDD\\nDDDDDDDADD\\nDIDDDDIDDD\\nDMDDDDMDDD\\nDADDDDADID\\nDDIMDDDDMD\\nDDAADDIAAD\\nDDDDDDMADD\\n\", \"14 34\\nDDDDDDDDDDDDIMADDDDDDDDDDDDDDDIMAD\\nDDDDDDIMADDDDDDDDDDDDDDDDDDDDDIMAD\\nDDDDDDDDDDDDDIDDDDDDDDDDDIDIMIDIMA\\nDDDDDDIMDDDDDDDDDDDDDIDDDDDDDDDDDD\\nDDDDDDDDDDDDDDDDDMADDDDDDDDDDDDDMD\\nDDDDDDIMIDDDDDDDDDDDDIMIDIMIDDDIDD\\nDDDDDDDDDDDDDDDDDMIMDDDDIMDDIMADIM\\nDDDDDDDDDDDADIMADIDDDDDDIDIMADADDD\\nDDDDDDDDIDDDDDDDDDDDDDDDDMADIMDDAM\\nDMDDDDDDDDDDDDIMADIMDDDDDMADDDMIDI\\nDDDDDDDDIMDDDDDDDDDDIDIMADIDDDDMAD\\nDDDIDDDDDDDDDDMIDIMADADADIMADIMAAD\\nDDDADDDDDDDDDIMIMADIDDMDMAMIDMDDDM\\nDIDIDDDDDDIIAAMMAIMIDADAAAMDIDDDID\\n\", \"9 6\\nDIMADD\\nIDDDDD\\nMDDDDD\\nADDDDD\\nDIMADD\\nIDDDDD\\nMDDDDD\\nADDDDD\\nDDDDDD\\n\", \"1 1\\nM\\n\", \"1 1\\nA\\n\", \"1 4\\nIMAD\\n\"], \"outputs\": [\"Poor Dima!\\n\", \"Poor Inna!\\n\", \"4\\n\", \"Poor Dima!\\n\", \"Poor Inna!\\n\", \"Poor Dima!\\n\", \"Poor Dima!\\n\", \"1\\n\", \"1\\n\", \"Poor Inna!\\n\", \"Poor Dima!\\n\", \"3\\n\", \"4\\n\", \"Poor Inna!\\n\", \"2\\n\", \"Poor Dima!\\n\", \"Poor Dima!\\n\", \"Poor Dima!\\n\"]}", "source": "primeintellect"}
Inna and Dima bought a table of size n × m in the shop. Each cell of the table contains a single letter: "D", "I", "M", "A". Inna loves Dima, so she wants to go through his name as many times as possible as she moves through the table. For that, Inna acts as follows: initially, Inna chooses some cell of the table where letter "D" is written; then Inna can move to some side-adjacent table cell that contains letter "I"; then from this cell she can go to one of the side-adjacent table cells that contains the written letter "M"; then she can go to a side-adjacent cell that contains letter "A". Then Inna assumes that she has gone through her sweetheart's name; Inna's next move can be going to one of the side-adjacent table cells that contains letter "D" and then walk on through name DIMA in the similar manner. Inna never skips a letter. So, from the letter "D" she always goes to the letter "I", from the letter "I" she always goes the to letter "M", from the letter "M" she always goes to the letter "A", and from the letter "A" she always goes to the letter "D". Depending on the choice of the initial table cell, Inna can go through name DIMA either an infinite number of times or some positive finite number of times or she can't go through his name once. Help Inna find out what maximum number of times she can go through name DIMA. -----Input----- The first line of the input contains two integers n and m (1 ≤ n, m ≤ 10^3). Then follow n lines that describe Inna and Dima's table. Each line contains m characters. Each character is one of the following four characters: "D", "I", "M", "A". Note that it is not guaranteed that the table contains at least one letter "D". -----Output----- If Inna cannot go through name DIMA once, print on a single line "Poor Dima!" without the quotes. If there is the infinite number of names DIMA Inna can go through, print "Poor Inna!" without the quotes. Otherwise print a single integer — the maximum number of times Inna can go through name DIMA. -----Examples----- Input 1 2 DI Output Poor Dima! Input 2 2 MA ID Output Poor Inna! Input 5 5 DIMAD DIMAI DIMAM DDMAA AAMID Output 4 -----Note----- Notes to the samples: In the first test sample, Inna cannot go through name DIMA a single time. In the second test sample, Inna can go through the infinite number of words DIMA. For that, she should move in the clockwise direction starting from the lower right corner. In the third test sample the best strategy is to start from the cell in the upper left corner of the table. Starting from this cell, Inna can go through name DIMA four times. 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\", \"10\\n\", \"1000000\\n\", \"1\\n\", \"17\\n\", \"3\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"103\\n\", \"11\\n\", \"152\\n\", \"987654\\n\", \"123452\\n\", \"78266\\n\", \"4\\n\"], \"outputs\": [\"8\\n\", \"19210869\\n\", \"739718215\\n\", \"1\\n\", \"466150679\\n\", \"141\\n\", \"177560\\n\", \"9307164\\n\", \"622090000\\n\", \"111008220\\n\", \"462523094\\n\", \"506663771\\n\", \"85147825\\n\", \"472559655\\n\", \"801594140\\n\", \"37092478\\n\", \"379770260\\n\", \"4360\\n\"]}", "source": "primeintellect"}
Let $n$ be an integer. Consider all permutations on integers $1$ to $n$ in lexicographic order, and concatenate them into one big sequence $P$. For example, if $n = 3$, then $P = [1, 2, 3, 1, 3, 2, 2, 1, 3, 2, 3, 1, 3, 1, 2, 3, 2, 1]$. The length of this sequence is $n \cdot n!$. Let $1 \leq i \leq j \leq n \cdot n!$ be a pair of indices. We call the sequence $(P_i, P_{i+1}, \dots, P_{j-1}, P_j)$ a subarray of $P$. You are given $n$. Find the number of distinct subarrays of $P$. Since this number may be large, output it modulo $998244353$ (a prime number). -----Input----- The only line contains one integer $n$ ($1 \leq n \leq 10^6$), as described in the problem statement. -----Output----- Output a single integer — the number of distinct subarrays, modulo $998244353$. -----Examples----- Input 2 Output 8 Input 10 Output 19210869 -----Note----- In the first example, the sequence $P = [1, 2, 2, 1]$. It has eight distinct subarrays: $[1]$, $[2]$, $[1, 2]$, $[2, 1]$, $[2, 2]$, $[1, 2, 2]$, $[2, 2, 1]$ and $[1, 2, 2, 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\\n\", \"3\\n\", \"6\\n\", \"10\\n\", \"67\\n\", \"159\\n\", \"2\\n\", \"5\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"89\\n\", \"38\\n\", \"34\\n\", \"93\\n\", \"41\\n\", \"72\\n\", \"179\\n\"], \"outputs\": [\"1 2 1 \", \"2 1\", \"1 2 1 3 2 \", \"1 2 1 3 2 4 1 2 3 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 4 14 5 3 9 15 2 4 3 7 6 16 2 5 4 8 10 17 3 18 11 4 1 6 5 19 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 4 14 5 3 9 15 2 4 3 7 6 16 2 5 4 8 10 17 3 18 11 4 1 6 5 19 7 9 4 20 2 21 12 3 8 5 6 22 3 2 13 23 4 7 14 10 5 24 3 6 9 11 15 8 2 25 4 5 3 26 7 27 6 4 16 28 2 29 5 12 4 30 8 9 10 6 17 7 3 5 18 13 11 3 4 31 1 14 6 32 5 8 19 3 7 33 9 34 4 15 20 6 2 10 21 4 12 35 3 36 8 7 5 11 6 37 22 16 \", \"1 \", \"1 2 1 3 \", \"1 2 1 3 2 4 \", \"1 2 1 3 2 4 1 \", \"1 2 1 3 2 4 1 2 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 4 14 5 3 9 15 2 4 3 7 6 16 2 5 4 8 10 17 3 18 11 4 1 6 5 19 7 9 4 20 2 21 12 3 8 5 6 22 3 2 13 23 4 7 14 10 5 24 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 4 14 5 3 9 15 2 4 3 7 6 16 2 5 4 8 10 17 3 18 11 4 1 6 5 19 7 9 4 20 2 21 12 3 8 5 6 22 3 2 13 23 4 7 14 10 5 24 3 6 9 11 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 4 14 5 3 9 15 2 4 3 7 6 16 2 5 4 8 10 17 3 18 11 4 1 6 5 19 7 9 4 20 2 \", \"1 2 1 3 2 4 1 2 3 5 2 6 4 3 1 7 2 8 3 4 5 9 2 3 6 2 4 10 3 11 1 5 7 4 2 12 8 6 3 13 4 14 5 3 9 15 2 4 3 7 6 16 2 5 4 8 10 17 3 18 11 4 1 6 5 19 7 9 4 20 2 21 12 3 8 5 6 22 3 2 13 23 4 7 14 10 5 24 3 6 9 11 15 8 2 25 4 5 3 26 7 27 6 4 16 28 2 29 5 12 4 30 8 9 10 6 17 7 3 5 18 13 11 3 4 31 1 14 6 32 5 8 19 3 7 33 9 34 4 15 20 6 2 10 21 4 12 35 3 36 8 7 5 11 6 37 22 16 3 9 2 38 13 5 23 39 4 6 7 8 14 40 10 4 5 17 24 41 \"]}", "source": "primeintellect"}
You're given an integer $n$. For every integer $i$ from $2$ to $n$, assign a positive integer $a_i$ such that the following conditions hold: For any pair of integers $(i,j)$, if $i$ and $j$ are coprime, $a_i \neq a_j$. The maximal value of all $a_i$ should be minimized (that is, as small as possible). A pair of integers is called coprime if their greatest common divisor is $1$. -----Input----- The only line contains the integer $n$ ($2 \le n \le 10^5$). -----Output----- Print $n-1$ integers, $a_2$, $a_3$, $\ldots$, $a_n$ ($1 \leq a_i \leq n$). If there are multiple solutions, print any of them. -----Examples----- Input 4 Output 1 2 1 Input 3 Output 2 1 -----Note----- In the first example, notice that $3$ and $4$ are coprime, so $a_3 \neq a_4$. Also, notice that $a=[1,2,3]$ satisfies the first condition, but it's not a correct answer because its maximal value is $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\\ngarage for sa-le\\n\", \"4\\nEdu-ca-tion-al Ro-unds are so fun\\n\", \"1\\nj\\n\", \"10\\nb\\n\", \"1\\nQGVsfZevMD\\n\", \"1\\nqUOYCytbKgoGRgaqhjrohVRxKTKjjOUPPnEjiXJWlvpCyqiRzbnpyNqDylWverSTrcgZpEoDKhJCrOOvsuXHzkPtbXeKCKMwUTVk\\n\", \"100000\\nBGRHXGrqgjMxCBCdQTCpQyHNMkraTRxhyZBztkxXNFEKnCNjHWeCWmmrRjiczJAdfQqdQfnuupPqzRhEKnpuTCsVPNVTIMiuiQUJ\\n\", \"1\\nrHPBSGKzxoSLerxkDVxJG PfUqVrdSdOgJBySsRHYryfLKOvIcU\\n\", \"2\\nWDJDSbGZbGLcDB-GuDJxmjHEeruCdJNdr wnEbYVxUZbgfjEHlHx\\n\", \"2\\nZeqxDLfPrSzHmZMjwSIoGeEdkWWmyvMqYkaXDzOeoFYRwFGamjYbjKYCIyMgjYoxhKnAQHmGAhkwIoySySumVOYmMDBYXDYkmwErqCrjZWkSisPtNczKRofaLOaJhgUbVOtZqjoJYpCILTmGkVpzCiYETFdgnTbTIVCqAoCZqRhJvWrBZjaMqicyLwZNRMfOFxjxDfNatDFmpmOyOQyGdiTvnprfkWGiaFdrwFVYKOrviRXdhYTdIfEjfzhb HrReddDwSntvOGtnNQFjoOnNDdAejrmNXxDmUdWTKTynngKTnHVSOiZZhggAbXaksqKyxuhhjisYDfzPLtTcKBZJCcuGLjhdZcgbrYQtqPnLoMmCKgusOmkLbBKGnKAEvgeLVmzwaYjvcyCZfngSJBlZwDimHsCctSkAhgqakEvXembgLVLbPfcQsmgxTCgCvSNliSyroTYpRmJGCwQlfcKXoptvkrYijULaUKWeVoaFTBFQvinGXGRj\\n\", \"2\\nWjrWBWqKIeSndDHeiVmfChQNsoUiRQHVplnIWkwBtxAJhOdTigAAzKtbNEqcgvbWHOopfCNgWHfwXyzSCfNqGMLnmlIdKQonLsmGSJlPBcYfHNJJDGlKNnOGtrWUhaTWuilHWMUlFEzbJYbeAWvgnSOOOPLxX-eJEKRsKqSnMjrPbFDprCqgbTfwAnPjFapVKiTjCcWEzhahwPRHScfcLnUixnxckQJzuHzshyBFKPwVGzHeJWniiRKynDFQdaazmTZtDGnFVTmTUZCRCpUHFmUHAVtEdweCImRztqrkQInyCsnMnYBbjjAdKZjXzyPGS TUZjnPyjnjyRCxfKkvpNicAzGqKQgiRreJIMVZPuKyFptrqhgIeWwpZFYetHqvZKUIscYuQttIRNuklmgqRYhbCWPgXpEygxYWMggVbQbiWNNBFMxRoPIRxcBLhayOizbixIRgaXczSibmlTnnYsnlltfDDwPolEIsjPilMiQQjUGeEyAWES\\n\", \"10\\nIBgDZeAHSUFhJxcZkQKqaTZT gqErHjXUahQpfDTcZZW nhLsPIrfflZWnwiQEWpt dcTGNMjzkuWNIVXrshBowdQ ugLvpovZZVWryM\\n\", \"10\\nlELWTeKqHCohtEOB PLhjMMwfpFlcnfft nWGsnztStldkrbGkJZz EtSrgwffzJSspzWpoMXGK-jmbVygQC BoIwaGSYKRsgmxBVwkoa\\n\", \"100000\\nBvbikpOjCTXWr-zqGzpEGswptPksN IsJVeilKfqoiicTMcmZeduDs KtZKEFZQztKq ynKDcPxbVfOKrjxAfQvKIIR HlsgVUeeGvfSc\\n\", \"10\\nTQEKPQiFXCqY iugCuECYdemF RqdrrpurDgeYK-fLJIgvtgWkPHma-kqoGdxPXvloehNNire JShAkvoJxjDMEoHiOp nHgyCAQMfiQSz\\n\", \"4\\na-aa\\n\", \"6\\na aa-aaa-aa a-aaa-a\\n\", \"4\\nasd asd asd asdf\\n\"], \"outputs\": [\"7\\n\", \"10\\n\", \"1\\n\", \"1\\n\", \"10\\n\", \"100\\n\", \"100\\n\", \"51\\n\", \"34\\n\", \"253\\n\", \"322\\n\", \"25\\n\", \"22\\n\", \"25\\n\", \"19\\n\", \"2\\n\", \"5\\n\", \"4\\n\"]}", "source": "primeintellect"}
The main city magazine offers its readers an opportunity to publish their ads. The format of the ad should be like this: There are space-separated non-empty words of lowercase and uppercase Latin letters. There are hyphen characters '-' in some words, their positions set word wrapping points. Word can include more than one hyphen. It is guaranteed that there are no adjacent spaces and no adjacent hyphens. No hyphen is adjacent to space. There are no spaces and no hyphens before the first word and after the last word. When the word is wrapped, the part of the word before hyphen and the hyphen itself stay on current line and the next part of the word is put on the next line. You can also put line break between two words, in that case the space stays on current line. Check notes for better understanding. The ad can occupy no more that k lines and should have minimal width. The width of the ad is the maximal length of string (letters, spaces and hyphens are counted) in it. You should write a program that will find minimal width of the ad. -----Input----- The first line contains number k (1 ≤ k ≤ 10^5). The second line contains the text of the ad — non-empty space-separated words of lowercase and uppercase Latin letters and hyphens. Total length of the ad don't exceed 10^6 characters. -----Output----- Output minimal width of the ad. -----Examples----- Input 4 garage for sa-le Output 7 Input 4 Edu-ca-tion-al Ro-unds are so fun Output 10 -----Note----- Here all spaces are replaced with dots. In the first example one of possible results after all word wraps looks like this: garage. for. sa- le The second example: Edu-ca- tion-al. Ro-unds. are.so.fun 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\": [\"0000000101\\n3\\n\", \"1000000000\\n2\\n\", \"1000000000\\n1\\n\", \"1001100000\\n11\\n\", \"0100000001\\n10\\n\", \"0110110000\\n12\\n\", \"0111100111\\n32\\n\", \"0000001100\\n52\\n\", \"0000000000\\n1\\n\", \"0000000001\\n1\\n\", \"0000010000\\n2\\n\", \"1100000000\\n3\\n\", \"1110010000\\n1000\\n\", \"1101000001\\n1000\\n\", \"1110000000\\n4\\n\", \"1011000000\\n6\\n\", \"1000000011\\n18\\n\", \"0000000101\\n4\\n\"], \"outputs\": [\"YES\\n8 10 8\\n\", \"NO\\n\", \"YES\\n1\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n5 6 5 6 5 6 5 6 5 3 6 5\\n\", \"YES\\n9 10 9 10 9 10 9 10 9 10 9 10 9 10 9 10 9 8 10 9 10 9 10 9 10 9 10 9 10 9 8 10\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n10\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n2 3 2 3\\n\", \"YES\\n3 4 3 4 3 4\\n\", \"YES\\n9 10 9 10 9 10 9 10 9 10 9 10 9 10 9 10 9 10\\n\", \"YES\\n8 10 8 10\\n\"]}", "source": "primeintellect"}
Xenia has a set of weights and pan scales. Each weight has an integer weight from 1 to 10 kilos. Xenia is going to play with scales and weights a little. For this, she puts weights on the scalepans, one by one. The first weight goes on the left scalepan, the second weight goes on the right scalepan, the third one goes on the left scalepan, the fourth one goes on the right scalepan and so on. Xenia wants to put the total of m weights on the scalepans. Simply putting weights on the scales is not interesting, so Xenia has set some rules. First, she does not put on the scales two consecutive weights of the same weight. That is, the weight that goes i-th should be different from the (i + 1)-th weight for any i (1 ≤ i < m). Second, every time Xenia puts a weight on some scalepan, she wants this scalepan to outweigh the other one. That is, the sum of the weights on the corresponding scalepan must be strictly greater than the sum on the other pan. You are given all types of weights available for Xenia. You can assume that the girl has an infinite number of weights of each specified type. Your task is to help Xenia lay m weights on ​​the scales or to say that it can't be done. -----Input----- The first line contains a string consisting of exactly ten zeroes and ones: the i-th (i ≥ 1) character in the line equals "1" if Xenia has i kilo weights, otherwise the character equals "0". The second line contains integer m (1 ≤ m ≤ 1000). -----Output----- In the first line print "YES", if there is a way to put m weights on the scales by all rules. Otherwise, print in the first line "NO". If you can put m weights on the scales, then print in the next line m integers — the weights' weights in the order you put them on the scales. If there are multiple solutions, you can print any of them. -----Examples----- Input 0000000101 3 Output YES 8 10 8 Input 1000000000 2 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
{"tests": "{\"inputs\": [\"3\\n2 4 3\\n\", \"5\\n1 2 3 4 4\\n\", \"3\\n13 8 5\\n\", \"4\\n1 10 100 1000\\n\", \"3\\n1 1000000000 999999999\\n\", \"35\\n5856 4937422 170055 7988916 88598426 20915252 3051495 1885928 720361 2233 12926337 842 231953689 24812 33 260 33841588 54756839 15334 275154 40145 982571591 375308952 551 607262640 228 64956 292 143355264 1392 9479 3624 1165568 445208 105100\\n\", \"27\\n496869708 6536632 139291 53540 27689600 72492314 189787341 364332 953704 2496779 10576485 307082368 85752 44802715 21328 10886 1543076 10000 17113116 32213 117295028 444 589373 803952075 10443 225042 4039854\\n\", \"4\\n100 21 52 49\\n\", \"3\\n4 10 5\\n\", \"4\\n3 11 15 1\\n\", \"4\\n4 2 2 3\\n\", \"5\\n2 5 1 2 3\\n\", \"20\\n81068139 119396832 83838155 1000000000 159840370 103235333 5918577 125483356 178466846 136582489 44105349 274856214 1669196 97691244 38933329 67086034 67211704 59593309 135002571 70170536\\n\", \"43\\n4182 3 6766 701408734 14930353 2585 39088170 1598 10947 988 28658 3524579 611 196419 378 22 14 267914297 90 17712 433494438 24157818 9227466 121394 832041 63245987 165580142 46369 2 514230 6 35 4 234 9 317812 145 102334156 75026 1346270 5702888 56 2178310\\n\", \"38\\n302 346604864 11937715 19315628 790 115 3344 97062 42 188 50568969 907423313 214213587 560818450 1278 254110 4559802 22914 31253342 59988 10 7377914 33 132391278 489 5410 2067 8753 14162 2818113 411158 37075 81822310 74 1076424 1741690 665267 157049\\n\", \"5\\n2 2 2 2 2\\n\", \"4\\n1 2 99 100\\n\", \"3\\n1 1 1\\n\"], \"outputs\": [\"YES\\n4 2 3 \", \"YES\\n4 3 1 2 4 \", \"NO\", \"NO\", \"NO\", \"YES\\n982571591 375308952 143355264 54756839 20915252 7988916 3051495 1165568 445208 170055 64956 24812 9479 3624 1392 551 260 33 228 292 842 2233 5856 15334 40145 105100 275154 720361 1885928 4937422 12926337 33841588 88598426 231953689 607262640 \", \"YES\\n803952075 307082368 117295028 44802715 17113116 6536632 2496779 953704 364332 139291 53540 21328 10443 444 10000 10886 32213 85752 225042 589373 1543076 4039854 10576485 27689600 72492314 189787341 496869708 \", \"YES\\n100 49 21 52 \", \"NO\", \"NO\", \"YES\\n4 2 2 3 \", \"NO\", \"NO\", \"YES\\n701408734 267914297 102334156 39088170 14930353 5702888 2178310 832041 317812 121394 46369 17712 6766 2585 988 378 145 56 22 9 4 2 3 6 14 35 90 234 611 1598 4182 10947 28658 75026 196419 514230 1346270 3524579 9227466 24157818 63245987 165580142 433494438 \", \"YES\\n907423313 346604864 132391278 50568969 19315628 7377914 2818113 1076424 411158 157049 59988 22914 8753 3344 1278 489 188 74 33 10 42 115 302 790 2067 5410 14162 37075 97062 254110 665267 1741690 4559802 11937715 31253342 81822310 214213587 560818450 \", \"YES\\n2 2 2 2 2 \", \"YES\\n100 2 1 99 \", \"YES\\n1 1 1 \"]}", "source": "primeintellect"}
You are given $n$ numbers $a_1, a_2, \ldots, a_n$. Is it possible to arrange them in a circle in such a way that every number is strictly less than the sum of its neighbors? For example, for the array $[1, 4, 5, 6, 7, 8]$, the arrangement on the left is valid, while arrangement on the right is not, as $5\ge 4 + 1$ and $8> 1 + 6$. [Image] -----Input----- The first line contains a single integer $n$ ($3\le n \le 10^5$) — the number of numbers. The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \le 10^9$) — the numbers. The given numbers are not necessarily distinct (i.e. duplicates are allowed). -----Output----- If there is no solution, output "NO" in the first line. If there is a solution, output "YES" in the first line. In the second line output $n$ numbers — elements of the array in the order they will stay in the circle. The first and the last element you output are considered neighbors in the circle. If there are multiple solutions, output any of them. You can print the circle starting with any element. -----Examples----- Input 3 2 4 3 Output YES 4 2 3 Input 5 1 2 3 4 4 Output YES 4 4 2 1 3 Input 3 13 8 5 Output NO Input 4 1 10 100 1000 Output NO -----Note----- One of the possible arrangements is shown in the first example: $4< 2 + 3$; $2 < 4 + 3$; $3< 4 + 2$. One of the possible arrangements is shown in the second example. No matter how we arrange $13, 8, 5$ in a circle in the third example, $13$ will have $8$ and $5$ as neighbors, but $13\ge 8 + 5$. There is no solution in the fourth example. 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 2 2 2 2\\n\", \"3\\n1 1 1\\n\", \"3\\n3 3 3\\n\", \"1\\n1\\n\", \"1\\n963837006\\n\", \"5\\n1 3 3 5 3\\n\", \"100\\n5 5 2 4 5 4 4 4 4 2 5 3 4 2 4 4 1 1 5 3 2 2 1 3 3 2 5 3 4 5 1 3 5 4 4 4 3 1 4 4 3 4 5 2 5 4 2 1 2 2 3 5 5 5 1 4 5 3 1 4 2 2 5 1 5 3 4 1 5 1 2 2 3 5 1 3 2 4 2 4 2 2 4 1 3 5 2 2 2 3 3 4 3 2 2 5 5 4 2 5\\n\", \"100\\n1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 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 2 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 1 1 1\\n\", \"3\\n1 2 2\\n\", \"3\\n2 1 1\\n\", \"4\\n1 1 1 6\\n\", \"6\\n1 1 1 1 1 6\\n\", \"6\\n1 1 1 1 1 3\\n\", \"10\\n98 22 20 91 71 58 15 71 1 3\\n\", \"6\\n1 1 1 1 1 10\\n\", \"57\\n28 57 82 64 59 54 23 13 19 67 77 46 100 73 59 21 72 81 53 73 92 86 14 100 9 17 77 96 46 41 24 29 60 100 89 47 8 25 24 64 3 32 14 53 80 70 87 1 99 77 41 60 8 95 2 1 78\\n\", \"10\\n1 1 1 1 1 1 1 1 8 8\\n\"], \"outputs\": [\"3\\n\", \"0\\n\", \"3\\n\", \"0\\n\", \"321279002\\n\", \"5\\n\", \"106\\n\", \"6\\n\", \"1\\n\", \"0\\n\", \"3\\n\", \"3\\n\", \"1\\n\", \"149\\n\", \"5\\n\", \"990\\n\", \"8\\n\"]}", "source": "primeintellect"}
Pavel has several sticks with lengths equal to powers of two. He has $a_0$ sticks of length $2^0 = 1$, $a_1$ sticks of length $2^1 = 2$, ..., $a_{n-1}$ sticks of length $2^{n-1}$. Pavel wants to make the maximum possible number of triangles using these sticks. The triangles should have strictly positive area, each stick can be used in at most one triangle. It is forbidden to break sticks, and each triangle should consist of exactly three sticks. Find the maximum possible number of triangles. -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 300\,000$) — the number of different lengths of sticks. The second line contains $n$ integers $a_0$, $a_1$, ..., $a_{n-1}$ ($1 \leq a_i \leq 10^9$), where $a_i$ is the number of sticks with the length equal to $2^i$. -----Output----- Print a single integer — the maximum possible number of non-degenerate triangles that Pavel can make. -----Examples----- Input 5 1 2 2 2 2 Output 3 Input 3 1 1 1 Output 0 Input 3 3 3 3 Output 3 -----Note----- In the first example, Pavel can, for example, make this set of triangles (the lengths of the sides of the triangles are listed): $(2^0, 2^4, 2^4)$, $(2^1, 2^3, 2^3)$, $(2^1, 2^2, 2^2)$. In the second example, Pavel cannot make a single triangle. In the third example, Pavel can, for example, create this set of triangles (the lengths of the sides of the triangles are listed): $(2^0, 2^0, 2^0)$, $(2^1, 2^1, 2^1)$, $(2^2, 2^2, 2^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\": [\"5\\n1 2 2 1 2\\n\", \"8\\n1 2 2 1 2 1 1 2\\n\", \"1\\n2\\n\", \"1\\n1\\n\", \"2\\n2 2\\n\", \"2\\n1 2\\n\", \"2\\n1 1\\n\", \"10\\n2 2 2 2 2 2 1 2 1 1\\n\", \"10\\n2 1 1 2 1 2 1 2 2 1\\n\", \"10\\n1 1 1 1 1 1 1 1 1 1\\n\", \"10\\n1 1 1 1 2 1 1 1 1 1\\n\", \"10\\n2 1 2 2 2 2 2 2 2 2\\n\", \"10\\n2 2 2 2 2 2 2 2 2 2\\n\", \"10\\n1 1 1 1 1 2 1 1 2 1\\n\", \"9\\n1 1 1 2 2 1 1 1 1\\n\", \"100\\n2 2 2 2 1 1 2 2 1 2 2 1 1 2 2 2 2 2 2 1 1 2 2 2 2 1 2 1 1 2 2 1 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 1 2 2 2 2\\n\", \"200\\n1 2 1 1 2 2 1 1 1 1 1 1 2 1 2 2 2 2 2 1 2 2 1 1 2 2 2 2 2 1 2 1 1 2 2 2 1 2 2 2 1 1 2 2 2 1 2 2 1 2 1 2 2 1 2 2 2 2 2 1 2 2 1 2 1 1 2 2 2 2 2 2 2 1 2 2 2 1 1 2 2 2 2 1 1 2 2 1 1 1 2 2 1 1 2 2 1 1 2 2 2 1 2 2 2 1 2 1 2 2 2 2 2 2 2 1 1 1 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 1 2 1 2 1 1 1 2 2 2 1 2 1 2 2 1 2 2 1 2 1 2 1 1 2 2 1 2 2 1 2 1 1 2 1 1 2 2 2 2 1 2 1 1 1 1 1 1 1 1 2 1 2 1 1 2 1 2 1 2 2 1 2 1 1 1 2\\n\"], \"outputs\": [\"120\\n\", \"16800\\n\", \"1\\n\", \"1\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"2419200\\n\", \"786240\\n\", \"9496\\n\", \"26200\\n\", \"3628800\\n\", \"3628800\\n\", \"68760\\n\", \"16704\\n\", \"834603967\\n\", \"83780780\\n\"]}", "source": "primeintellect"}
Smart Beaver decided to be not only smart, but also a healthy beaver! And so he began to attend physical education classes at school X. In this school, physical education has a very creative teacher. One of his favorite warm-up exercises is throwing balls. Students line up. Each one gets a single ball in the beginning. The balls are numbered from 1 to n (by the demand of the inventory commission). [Image] Figure 1. The initial position for n = 5. After receiving the balls the students perform the warm-up exercise. The exercise takes place in a few throws. For each throw the teacher chooses any two arbitrary different students who will participate in it. The selected students throw their balls to each other. Thus, after each throw the students remain in their positions, and the two balls are swapped. [Image] Figure 2. The example of a throw. In this case there was a throw between the students, who were holding the 2-nd and the 4-th balls. Since the warm-up has many exercises, each of them can only continue for little time. Therefore, for each student we know the maximum number of throws he can participate in. For this lessons maximum number of throws will be 1 or 2. Note that after all phases of the considered exercise any ball can end up with any student. Smart Beaver decided to formalize it and introduced the concept of the "ball order". The ball order is a sequence of n numbers that correspond to the order of balls in the line. The first number will match the number of the ball of the first from the left student in the line, the second number will match the ball of the second student, and so on. For example, in figure 2 the order of the balls was (1, 2, 3, 4, 5), and after the throw it was (1, 4, 3, 2, 5). Smart beaver knows the number of students and for each student he knows the maximum number of throws in which he can participate. And now he is wondering: what is the number of distinct ways of ball orders by the end of the exercise. -----Input----- The first line contains a single number n — the number of students in the line and the number of balls. The next line contains exactly n space-separated integers. Each number corresponds to a student in the line (the i-th number corresponds to the i-th from the left student in the line) and shows the number of throws he can participate in. The input limits for scoring 30 points are (subproblem D1): 1 ≤ n ≤ 10. The input limits for scoring 70 points are (subproblems D1+D2): 1 ≤ n ≤ 500. The input limits for scoring 100 points are (subproblems D1+D2+D3): 1 ≤ n ≤ 1000000. -----Output----- The output should contain a single integer — the number of variants of ball orders after the warm up exercise is complete. As the number can be rather large, print it modulo 1000000007 (10^9 + 7). -----Examples----- Input 5 1 2 2 1 2 Output 120 Input 8 1 2 2 1 2 1 1 2 Output 16800 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\\n10\\nG\\n\", \"2\\n10 10\\nWL\\n\", \"2\\n1 2\\nWL\\n\", \"3\\n10 10 10\\nGLW\\n\", \"2\\n2 10\\nGL\\n\", \"1\\n10\\nW\\n\", \"1\\n9\\nW\\n\", \"1\\n9\\nG\\n\", \"2\\n10 10\\nGL\\n\", \"3\\n10 10 50\\nWGL\\n\", \"3\\n10 9 10\\nGLW\\n\", \"2\\n100 100\\nWG\\n\", \"2\\n100 100\\nGW\\n\", \"2\\n1 1000000000000\\nGW\\n\", \"4\\n1 1 1 1\\nWGWL\\n\", \"10\\n324839129156 133475576222 987711341463 185514358673 88712073883 243757012712 950854402304 21947060440 598567289966 674328002732\\nGLLLLLLLLW\\n\", \"5\\n2 2 1 1 1\\nWGLLW\\n\"], \"outputs\": [\"30\\n\", \"40\\n\", \"8\\n\", \"80\\n\", \"60\\n\", \"20\\n\", \"18\\n\", \"27\\n\", \"60\\n\", \"220\\n\", \"77\\n\", \"400\\n\", \"500\\n\", \"2000000000003\\n\", \"8\\n\", \"20611890699442\\n\", \"16\\n\"]}", "source": "primeintellect"}
Bob is a duck. He wants to get to Alice's nest, so that those two can duck! [Image] Duck is the ultimate animal! (Image courtesy of See Bang) The journey can be represented as a straight line, consisting of $n$ segments. Bob is located to the left of the first segment, while Alice's nest is on the right of the last segment. Each segment has a length in meters, and also terrain type: grass, water or lava. Bob has three movement types: swimming, walking and flying. He can switch between them or change his direction at any point in time (even when he is located at a non-integer coordinate), and doing so doesn't require any extra time. Bob can swim only on the water, walk only on the grass and fly over any terrain. Flying one meter takes $1$ second, swimming one meter takes $3$ seconds, and finally walking one meter takes $5$ seconds. Bob has a finite amount of energy, called stamina. Swimming and walking is relaxing for him, so he gains $1$ stamina for every meter he walks or swims. On the other hand, flying is quite tiring, and he spends $1$ stamina for every meter flown. Staying in place does not influence his stamina at all. Of course, his stamina can never become negative. Initially, his stamina is zero. What is the shortest possible time in which he can reach Alice's nest? -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of segments of terrain. The second line contains $n$ integers $l_1, l_2, \dots, l_n$ ($1 \leq l_i \leq 10^{12}$). The $l_i$ represents the length of the $i$-th terrain segment in meters. The third line contains a string $s$ consisting of $n$ characters "G", "W", "L", representing Grass, Water and Lava, respectively. It is guaranteed that the first segment is not Lava. -----Output----- Output a single integer $t$ — the minimum time Bob needs to reach Alice. -----Examples----- Input 1 10 G Output 30 Input 2 10 10 WL Output 40 Input 2 1 2 WL Output 8 Input 3 10 10 10 GLW Output 80 -----Note----- In the first sample, Bob first walks $5$ meters in $25$ seconds. Then he flies the remaining $5$ meters in $5$ seconds. In the second sample, Bob first swims $10$ meters in $30$ seconds. Then he flies over the patch of lava for $10$ seconds. In the third sample, the water pond is much smaller. Bob first swims over the water pond, taking him $3$ seconds. However, he cannot fly over the lava just yet, as he only has one stamina while he needs two. So he swims back for half a meter, and then half a meter forward, taking him $3$ seconds in total. Now he has $2$ stamina, so he can spend $2$ seconds flying over the lava. In the fourth sample, he walks for $50$ seconds, flies for $10$ seconds, swims for $15$ seconds, and finally flies for $5$ 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\": [\"9 2\\n6 19 3 4 4 2 6 7 8\\n\", \"1 1\\n7\\n\", \"2 1\\n135072 38422\\n\", \"2 2\\n51200 19970\\n\", \"37 13\\n164823 8992 21818 77521 130870 83201 174985 168799 9565 84443 105083 54131 130813 42829 98759 60103 198520 125068 59611 45609 124003 106143 54167 179002 103755 152802 146640 38512 91309 6660 131534 32533 67324 27272 49166 129157 41630\\n\", \"3 1\\n134186 63312 172492\\n\", \"3 2\\n50314 12156 18453\\n\", \"3 3\\n101035 128296 199007\\n\", \"4 1\\n133301 55497 1118 165948\\n\", \"4 2\\n16725 4342 181671 28129\\n\", \"4 3\\n100149 153186 186417 57607\\n\", \"4 4\\n16277 102030 166971 119789\\n\", \"5 1\\n132416 80387 164336 78116 99081\\n\", \"5 2\\n15840 196527 169082 107594 191438\\n\", \"5 3\\n99264 145372 149635 193968 140692\\n\", \"5 4\\n15392 61512 162893 23445 65753\\n\", \"5 5\\n98816 43061 167639 85627 15007\\n\"], \"outputs\": [\"2 5 11 18 30 43 62 83 121\\n\", \"7\\n\", \"38422 211916\\n\", \"19970 71170\\n\", \"6660 15652 25217 47035 74307 106840 145352 186982 229811 275420 324586 378717 432884 499155 568250 645139 744478 854951 971927 1101748 1242137 1388721 1539413 1694722 1872856 2052091 2247519 2447427 2655186 2886059 3143172 3412950 3707594 4016782 4338351 4668045 5021874\\n\", \"63312 260810 630800\\n\", \"12156 30609 93079\\n\", \"101035 229331 428338\\n\", \"1118 57733 247649 603513\\n\", \"4342 21067 53538 251934\\n\", \"57607 157756 310942 554966\\n\", \"16277 118307 238096 405067\\n\", \"78116 236619 494203 884203 1438539\\n\", \"15840 123434 308356 607388 988837\\n\", \"99264 239956 385328 634227 968887\\n\", \"15392 38837 100349 166102 344387\\n\", \"15007 58068 143695 242511 410150\\n\"]}", "source": "primeintellect"}
Tsumugi brought $n$ delicious sweets to the Light Music Club. They are numbered from $1$ to $n$, where the $i$-th sweet has a sugar concentration described by an integer $a_i$. Yui loves sweets, but she can eat at most $m$ sweets each day for health reasons. Days are $1$-indexed (numbered $1, 2, 3, \ldots$). Eating the sweet $i$ at the $d$-th day will cause a sugar penalty of $(d \cdot a_i)$, as sweets become more sugary with time. A sweet can be eaten at most once. The total sugar penalty will be the sum of the individual penalties of each sweet eaten. Suppose that Yui chooses exactly $k$ sweets, and eats them in any order she wants. What is the minimum total sugar penalty she can get? Since Yui is an undecided girl, she wants you to answer this question for every value of $k$ between $1$ and $n$. -----Input----- The first line contains two integers $n$ and $m$ ($1 \le m \le n \le 200\ 000$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 200\ 000$). -----Output----- You have to output $n$ integers $x_1, x_2, \ldots, x_n$ on a single line, separed by spaces, where $x_k$ is the minimum total sugar penalty Yui can get if she eats exactly $k$ sweets. -----Examples----- Input 9 2 6 19 3 4 4 2 6 7 8 Output 2 5 11 18 30 43 62 83 121 Input 1 1 7 Output 7 -----Note----- Let's analyze the answer for $k = 5$ in the first example. Here is one of the possible ways to eat $5$ sweets that minimize total sugar penalty: Day $1$: sweets $1$ and $4$ Day $2$: sweets $5$ and $3$ Day $3$ : sweet $6$ Total penalty is $1 \cdot a_1 + 1 \cdot a_4 + 2 \cdot a_5 + 2 \cdot a_3 + 3 \cdot a_6 = 6 + 4 + 8 + 6 + 6 = 30$. We can prove that it's the minimum total sugar penalty Yui can achieve if she eats $5$ sweets, hence $x_5 = 30$. 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\", \"4\\n\", \"1\\n\", \"3\\n\", \"5\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"15\\n\", \"16\\n\", \"17\\n\", \"33\\n\", \"79\\n\", \"27\\n\", \"55\\n\"], \"outputs\": [\"2\\n1 1\\n2 1\", \"3\\n1 1\\n2 1\\n3 1\\n3 2\", \"1\\n1 1\", \"2\\n1 1\\n2 1\\n2 2\", \"3\\n1 1\\n2 1\\n3 1\\n3 2\\n3 3\", \"4\\n1 1\\n2 1\\n3 1\\n4 1\\n4 2\\n4 3\", \"4\\n1 1\\n2 1\\n3 1\\n4 1\\n4 2\\n4 3\\n4 4\", \"5\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n5 2\\n5 3\\n5 4\", \"5\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n5 2\\n5 3\\n5 4\\n5 5\", \"6\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n6 2\\n6 3\\n6 4\\n6 5\", \"8\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n8 2\\n8 3\\n8 4\\n8 5\\n8 6\\n8 7\\n8 8\", \"9\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n9 2\\n9 3\\n9 4\\n9 5\\n9 6\\n9 7\\n9 8\", \"9\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n9 2\\n9 3\\n9 4\\n9 5\\n9 6\\n9 7\\n9 8\\n9 9\", \"17\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n10 1\\n11 1\\n12 1\\n13 1\\n14 1\\n15 1\\n16 1\\n17 1\\n17 2\\n17 3\\n17 4\\n17 5\\n17 6\\n17 7\\n17 8\\n17 9\\n17 10\\n17 11\\n17 12\\n17 13\\n17 14\\n17 15\\n17 16\\n17 17\", \"40\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n10 1\\n11 1\\n12 1\\n13 1\\n14 1\\n15 1\\n16 1\\n17 1\\n18 1\\n19 1\\n20 1\\n21 1\\n22 1\\n23 1\\n24 1\\n25 1\\n26 1\\n27 1\\n28 1\\n29 1\\n30 1\\n31 1\\n32 1\\n33 1\\n34 1\\n35 1\\n36 1\\n37 1\\n38 1\\n39 1\\n40 1\\n40 2\\n40 3\\n40 4\\n40 5\\n40 6\\n40 7\\n40 8\\n40 9\\n40 10\\n40 11\\n40 12\\n40 13\\n40 14\\n40 15\\n40 16\\n40 17\\n40 18\\n40 19\\n40 20\\n40 21\\n40 22\\n40 23\\n40 24\\n40 25\\n40 26\\n40 27\\n40 28\\n40 29\\n40 30\\n40 31\\n40 32\\n40 33\\n40 34\\n40 35\\n40 36\\n40 37\\n40 38\\n40 39\\n40 40\", \"14\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n10 1\\n11 1\\n12 1\\n13 1\\n14 1\\n14 2\\n14 3\\n14 4\\n14 5\\n14 6\\n14 7\\n14 8\\n14 9\\n14 10\\n14 11\\n14 12\\n14 13\\n14 14\", \"28\\n1 1\\n2 1\\n3 1\\n4 1\\n5 1\\n6 1\\n7 1\\n8 1\\n9 1\\n10 1\\n11 1\\n12 1\\n13 1\\n14 1\\n15 1\\n16 1\\n17 1\\n18 1\\n19 1\\n20 1\\n21 1\\n22 1\\n23 1\\n24 1\\n25 1\\n26 1\\n27 1\\n28 1\\n28 2\\n28 3\\n28 4\\n28 5\\n28 6\\n28 7\\n28 8\\n28 9\\n28 10\\n28 11\\n28 12\\n28 13\\n28 14\\n28 15\\n28 16\\n28 17\\n28 18\\n28 19\\n28 20\\n28 21\\n28 22\\n28 23\\n28 24\\n28 25\\n28 26\\n28 27\\n28 28\"]}", "source": "primeintellect"}
Nauuo is a girl who loves playing chess. One day she invented a game by herself which needs $n$ chess pieces to play on a $m\times m$ chessboard. The rows and columns are numbered from $1$ to $m$. We denote a cell on the intersection of the $r$-th row and $c$-th column as $(r,c)$. The game's goal is to place $n$ chess pieces numbered from $1$ to $n$ on the chessboard, the $i$-th piece lies on $(r_i,\,c_i)$, while the following rule is satisfied: for all pairs of pieces $i$ and $j$, $|r_i-r_j|+|c_i-c_j|\ge|i-j|$. Here $|x|$ means the absolute value of $x$. However, Nauuo discovered that sometimes she couldn't find a solution because the chessboard was too small. She wants to find the smallest chessboard on which she can put $n$ pieces according to the rules. She also wonders how to place the pieces on such a chessboard. Can you help her? -----Input----- The only line contains a single integer $n$ ($1\le n\le 1000$) — the number of chess pieces for the game. -----Output----- The first line contains a single integer — the minimum value of $m$, where $m$ is the length of sides of the suitable chessboard. The $i$-th of the next $n$ lines contains two integers $r_i$ and $c_i$ ($1\le r_i,c_i\le m$) — the coordinates of the $i$-th chess piece. If there are multiple answers, print any. -----Examples----- Input 2 Output 2 1 1 1 2 Input 4 Output 3 1 1 1 3 3 1 3 3 -----Note----- In the first example, you can't place the two pieces on a $1\times1$ chessboard without breaking the rule. But you can place two pieces on a $2\times2$ chessboard like this: [Image] In the second example, you can't place four pieces on a $2\times2$ chessboard without breaking the rule. For example, if you place the pieces like this: [Image] then $|r_1-r_3|+|c_1-c_3|=|1-2|+|1-1|=1$, $|1-3|=2$, $1<2$; and $|r_1-r_4|+|c_1-c_4|=|1-2|+|1-2|=2$, $|1-4|=3$, $2<3$. It doesn't satisfy the rule. However, on a $3\times3$ chessboard, you can place four pieces like this: [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\": [\"5\\noxxxx\\nx...x\\nx...x\\nx...x\\nxxxxo\\n\", \"6\\n.x.x..\\nx.x.x.\\n.xo..x\\nx..ox.\\n.x.x.x\\n..x.x.\\n\", \"3\\no.x\\noxx\\no.x\\n\", \"1\\no\\n\", \"2\\nox\\n.o\\n\", \"5\\n.xxo.\\n..oxo\\nx.oxo\\no..xo\\noooox\\n\", \"8\\n..xox.xo\\n..xxx.xx\\n........\\n........\\n........\\n........\\n........\\n........\\n\", \"8\\n..x.xxx.\\nx.x.xxxx\\nxxxxxxox\\nxxoxxxxx\\n.xxxx.x.\\nx.xxx.x.\\n..x..xx.\\n.xx...x.\\n\", \"8\\noxxxxxxx\\nxoxxxoxx\\nxx...x..\\nxx...x..\\nxx...x..\\nxx...x..\\noxxxxxxx\\nxx...x..\\n\", \"8\\nx.......\\n.x.....x\\nx.x...x.\\nxx.x.x..\\nxxx.x..x\\n.xxx.xxx\\n..oxxxx.\\n.x.xoo.o\\n\", \"8\\n........\\n........\\n........\\n..xxxx..\\n.xx..xx.\\n..xoox..\\noxx..xx.\\n..xxox..\\n\", \"8\\n....o...\\n..o.x...\\n..x..o..\\n.....oo.\\n.....xx.\\n........\\n.o...o..\\n.x...x.o\\n\", \"8\\n.o....o.\\n.....x..\\n.....o..\\n..x.....\\n..o...x.\\n...x..o.\\n...oxx..\\n....oo..\\n\", \"10\\n...o.xxx.x\\n..ooxxxxxx\\n.x..x.x...\\nx.xxx..ox.\\nxx.xoo.xxx\\n.......xxx\\n.x.x.xx...\\nxo..xo..xx\\n....x....o\\n.ox.xxx..x\\n\", \"10\\no....o....\\n..........\\nx.........\\n...o......\\n..o.......\\no..oo....x\\n..........\\nx....x....\\n.o........\\n.....oo...\\n\", \"20\\nxxxxxx.xxxxxxxxxxxxx\\n.xx.x.x.xx.xxxxxxxxx\\nxxxxxx.xx.xx.xxx.xxx\\nxx.xxxoxxx..xxxxxxxx\\nxoxx.x..xx.xx.xo.xox\\n.xxxxxxxxx.xxxxxxxxx\\no.xxxxxoxxx..xx.oxox\\nxxx.xxxx....xxx.xx.x\\nxxxxxxo.xoxxoxxxxxxx\\n.x..xx.xxxx...xx..xx\\nxxxxxxxxxxxx..xxxxxx\\nxxx.x.xxxxxxxx..xxxx\\nxxxxxxx.xxoxxxx.xxx.\\nx.x.xx.xxx.xxxxxxxx.\\no.xxxx.xx.oxxxxx..xx\\nx.oxxxxxx.x.xx.xx.x.\\n.xoxx.xxxx..xx...x.x\\nxxxx.x.xxxxxoxxxoxxx\\noxx.xxxxx.xxxxxxxxx.\\nxxxxxxoxxxxxx.xxxxxx\\n\", \"20\\n.xooxo.oxx.xo..xxox.\\nox.oo.xoox.xxo.xx.x.\\noo..o.o.xoo.oox....o\\nooo.ooxox.ooxox..oox\\n.o.xx.x.ox.xo.xxoox.\\nxooo.oo.xox.o.o.xxxo\\noxxoox...oo.oox.xo.x\\no.oxoxxx.oo.xooo..o.\\no..xoxox.xo.xoooxo.x\\n.oxoxxoo..o.xxoxxo..\\nooxxooooox.o.x.x.ox.\\noxxxx.oooooox.oxxxo.\\nxoo...xoxoo.xx.x.oo.\\noo..xxxox.xo.xxoxoox\\nxxxoo..oo...ox.xo.o.\\no..ooxoxo..xoo.xxxxo\\no....oo..x.ox..oo.xo\\n.x.xox.xo.o.oo.oxo.o\\nooxoxoxxxox.x..xx.x.\\n.xooxx..xo.xxoo.oo..\\n\"], \"outputs\": [\"YES\\nxxxxxxxxx\\nx...xxxxx\\nx...xxxxx\\nx...xxxxx\\nxxxxoxxxx\\nxxxxx...x\\nxxxxx...x\\nxxxxx...x\\nxxxxxxxxx\\n\", \"YES\\nxxxxxxxxxxx\\nxxxxxxxxxxx\\nxx.x.x..xxx\\nxxx.x.x..xx\\nxx.x...x.xx\\nxxx..o..xxx\\nxx.x...x.xx\\nxx..x.x.xxx\\nxxx..x.x.xx\\nxxxxxxxxxxx\\nxxxxxxxxxxx\\n\", \"NO\\n\", \"YES\\no\\n\", \"YES\\nxxx\\n.ox\\nx.x\\n\", \"NO\\n\", \"YES\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\n..xx..xox.xxxxx\\n..xx..xxx.xxxxx\\n............xxx\\n............xxx\\n............xxx\\n............xxx\\n............xxx\\n............xxx\\n\", \"YES\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxx..x.xxx.xx\\nx..x.x.x.xxxxxx\\nxx.x.xxxxxxxxxx\\nxxxxxxxoxxxxxxx\\nxxxxx.xxxx.x.xx\\nx.xxxx.x.x.x.xx\\nxx.xx..x..xx.xx\\nx..x..xx...x.xx\\nx.xx...x.xxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\n\", \"YES\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxx...x..\\nxxxxxxxxx...x..\\nxxxxxxxxx...x..\\nxxxxxxxxx...x..\\nxxxxxxxoxxxxxxx\\nxxxx...x.......\\nxxxx...x.......\\nxxxx...x.......\\nxxxx...x.......\\nxxxxxxxxx...x..\\nxxxx...x...x..x\\nxxxxxxxxx...x..\\n\", \"YES\\nx..........xxxx\\n.x...........xx\\nx.x.........xxx\\nxx.x.......x.xx\\nxxx.x.....x..xx\\n.x...x...x..xxx\\n......x.x..xxxx\\n.x.....o..xx.xx\\nxxxxx.x.xxx.xxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\n\", \"YES\\nxxx........xxxx\\nxxx............\\nxxx............\\nxxx............\\nxxx.........x..\\nxxx...x.x...xx.\\nxxx..x...x..x..\\nxxx...xox...xx.\\nxxxxxx...x..x..\\nxxx...xxx...xxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\nxxxxxxxxxxxxxxx\\n\", \"YES\\n....x...xxxxxxx\\n..........x...x\\n..........x...x\\n...........x..x\\n...........xx.x\\n...........xx.x\\n..............x\\n.......o......x\\nx......x.....xx\\nx..........x.xx\\nx..........x.xx\\nx............xx\\nxx...........xx\\nxxx.x.......xxx\\nxxx.x...x.xxxxx\\n\", \"YES\\nxx.........xxxx\\nxx..........xxx\\nx...........xxx\\nx............xx\\nx............xx\\nx............xx\\nx......x.....xx\\nx......o......x\\nx.............x\\nx.............x\\nx.............x\\nx...........x.x\\nx...........x.x\\nx...xx...xxx..x\\nx....x....xx..x\\n\", \"YES\\nxxxxxxxx...x.xxx.xx\\n...x.xxx..xxxxxxxxx\\n..xx...x......x...x\\n.x....x...xxx..xx.x\\nx.xx..............x\\nxx.x...........xx.x\\n.......x.x.x.x....x\\n.x..............xxx\\nxx................x\\n....x....o..xx...xx\\n.xx..............xx\\nxx........x......xx\\nxx.x.x........x.xxx\\nxxxx..........xxxxx\\nxx...............xx\\nxx.xx..x...x....xxx\\nxxxxxx..........xxx\\nxxxxxx..........xxx\\nxxxxxx.xx.xxx..xxxx\\n\", \"YES\\nxxxx..........xxxxx\\nxxx...............x\\nxxxx..............x\\nxxx...............x\\nxxx................\\nxxxx...............\\nxxx................\\nxxxx...............\\nxxx................\\nxxx......o.........\\nxxxx...............\\nxxxxx..............\\nxxxx...............\\nxxxx...............\\nxxxxx.............x\\nxxxx...............\\nxxxxx....x....x....\\nxxxx.x.............\\nxxxx..........xx...\\n\", \"NO\\n\", \"NO\\n\"]}", "source": "primeintellect"}
Igor has been into chess for a long time and now he is sick of the game by the ordinary rules. He is going to think of new rules of the game and become world famous. Igor's chessboard is a square of size n × n cells. Igor decided that simple rules guarantee success, that's why his game will have only one type of pieces. Besides, all pieces in his game are of the same color. The possible moves of a piece are described by a set of shift vectors. The next passage contains a formal description of available moves. Let the rows of the board be numbered from top to bottom and the columns be numbered from left to right from 1 to n. Let's assign to each square a pair of integers (x, y) — the number of the corresponding column and row. Each of the possible moves of the piece is defined by a pair of integers (dx, dy); using this move, the piece moves from the field (x, y) to the field (x + dx, y + dy). You can perform the move if the cell (x + dx, y + dy) is within the boundaries of the board and doesn't contain another piece. Pieces that stand on the cells other than (x, y) and (x + dx, y + dy) are not important when considering the possibility of making the given move (for example, like when a knight moves in usual chess). Igor offers you to find out what moves his chess piece can make. He placed several pieces on the board and for each unoccupied square he told you whether it is attacked by any present piece (i.e. whether some of the pieces on the field can move to that cell). Restore a possible set of shift vectors of the piece, or else determine that Igor has made a mistake and such situation is impossible for any set of shift vectors. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 50). The next n lines contain n characters each describing the position offered by Igor. The j-th character of the i-th string can have the following values: o — in this case the field (i, j) is occupied by a piece and the field may or may not be attacked by some other piece; x — in this case field (i, j) is attacked by some piece; . — in this case field (i, j) isn't attacked by any piece. It is guaranteed that there is at least one piece on the board. -----Output----- If there is a valid set of moves, in the first line print a single word 'YES' (without the quotes). Next, print the description of the set of moves of a piece in the form of a (2n - 1) × (2n - 1) board, the center of the board has a piece and symbols 'x' mark cells that are attacked by it, in a format similar to the input. See examples of the output for a full understanding of the format. If there are several possible answers, print any of them. If a valid set of moves does not exist, print a single word 'NO'. -----Examples----- Input 5 oxxxx x...x x...x x...x xxxxo Output YES ....x.... ....x.... ....x.... ....x.... xxxxoxxxx ....x.... ....x.... ....x.... ....x.... Input 6 .x.x.. x.x.x. .xo..x x..ox. .x.x.x ..x.x. Output YES ........... ........... ........... ....x.x.... ...x...x... .....o..... ...x...x... ....x.x.... ........... ........... ........... Input 3 o.x oxx o.x Output NO -----Note----- In the first sample test the piece is a usual chess rook, and in the second sample test the piece is a usual chess knight. 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\\n\", \"2\\n\", \"3\\n\", \"5\\n\", \"17\\n\", \"6\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\", \"13\\n\", \"14\\n\", \"16\\n\", \"23\\n\"], \"outputs\": [\"16\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n\", \"7\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n\", \"10\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n\", \"13\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n\", \"19\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n\", \"55\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n12 13\\n13 12\\n13 13\\n13 14\\n14 13\\n14 14\\n14 15\\n15 14\\n15 15\\n15 16\\n16 15\\n16 16\\n16 17\\n17 16\\n17 17\\n17 18\\n18 17\\n18 18\\n\", \"22\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n\", \"25\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n\", \"28\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n\", \"31\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n\", \"34\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n\", \"37\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n\", \"40\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n12 13\\n13 12\\n13 13\\n\", \"43\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n12 13\\n13 12\\n13 13\\n13 14\\n14 13\\n14 14\\n\", \"46\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n12 13\\n13 12\\n13 13\\n13 14\\n14 13\\n14 14\\n14 15\\n15 14\\n15 15\\n\", \"52\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n12 13\\n13 12\\n13 13\\n13 14\\n14 13\\n14 14\\n14 15\\n15 14\\n15 15\\n15 16\\n16 15\\n16 16\\n16 17\\n17 16\\n17 17\\n\", \"73\\n0 0\\n0 1\\n1 0\\n1 1\\n1 2\\n2 1\\n2 2\\n2 3\\n3 2\\n3 3\\n3 4\\n4 3\\n4 4\\n4 5\\n5 4\\n5 5\\n5 6\\n6 5\\n6 6\\n6 7\\n7 6\\n7 7\\n7 8\\n8 7\\n8 8\\n8 9\\n9 8\\n9 9\\n9 10\\n10 9\\n10 10\\n10 11\\n11 10\\n11 11\\n11 12\\n12 11\\n12 12\\n12 13\\n13 12\\n13 13\\n13 14\\n14 13\\n14 14\\n14 15\\n15 14\\n15 15\\n15 16\\n16 15\\n16 16\\n16 17\\n17 16\\n17 17\\n17 18\\n18 17\\n18 18\\n18 19\\n19 18\\n19 19\\n19 20\\n20 19\\n20 20\\n20 21\\n21 20\\n21 21\\n21 22\\n22 21\\n22 22\\n22 23\\n23 22\\n23 23\\n23 24\\n24 23\\n24 24\\n\"]}", "source": "primeintellect"}
Leo Jr. draws pictures in his notebook with checkered sheets (that is, each sheet has a regular square grid printed on it). We can assume that the sheets are infinitely large in any direction. To draw a picture, Leo Jr. colors some of the cells on a sheet gray. He considers the resulting picture beautiful if the following conditions are satisfied: The picture is connected, that is, it is possible to get from any gray cell to any other by following a chain of gray cells, with each pair of adjacent cells in the path being neighbours (that is, sharing a side). Each gray cell has an even number of gray neighbours. There are exactly $n$ gray cells with all gray neighbours. The number of other gray cells can be arbitrary (but reasonable, so that they can all be listed). Leo Jr. is now struggling to draw a beautiful picture with a particular choice of $n$. Help him, and provide any example of a beautiful picture. To output cell coordinates in your answer, assume that the sheet is provided with a Cartesian coordinate system such that one of the cells is chosen to be the origin $(0, 0)$, axes $0x$ and $0y$ are orthogonal and parallel to grid lines, and a unit step along any axis in any direction takes you to a neighbouring cell. -----Input----- The only line contains a single integer $n$ ($1 \leq n \leq 500$) — the number of gray cells with all gray neighbours in a beautiful picture. -----Output----- In the first line, print a single integer $k$ — the number of gray cells in your picture. For technical reasons, $k$ should not exceed $5 \cdot 10^5$. Each of the following $k$ lines should contain two integers — coordinates of a gray cell in your picture. All listed cells should be distinct, and the picture should satisdfy all the properties listed above. All coordinates should not exceed $10^9$ by absolute value. One can show that there exists an answer satisfying all requirements with a small enough $k$. -----Example----- Input 4 Output 12 1 0 2 0 0 1 1 1 2 1 3 1 0 2 1 2 2 2 3 2 1 3 2 3 -----Note----- The answer for the sample is pictured below: [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\": [\"7 3\\n1 2 3 4 3 2 6\\n6 3 1 4 2 2 3\\n\", \"4 4\\n0 1 2 3\\n0 1 2 3\\n\", \"5 3\\n1 2 3 4 0\\n4 1 2 14 3\\n\", \"1 1\\n0\\n10000\\n\", \"1 2\\n0\\n10000\\n\", \"1 10000000000\\n0\\n10000\\n\", \"2 3\\n0 0\\n4 7\\n\", \"2 3\\n0 1\\n4 7\\n\", \"2 3\\n1 0\\n4 7\\n\", \"2 3\\n1 1\\n4 7\\n\", \"3 10\\n0 1 2\\n9240 5331 6721\\n\", \"4 10\\n2 1 2 1\\n960 2596 3752 8303\\n\", \"5 10\\n0 2 2 0 2\\n8473 9299 7399 4396 7275\\n\", \"6 10\\n0 3 3 5 3 5\\n4845 6494 579 5025 2998 4787\\n\", \"7 10\\n4 6 4 6 4 2 0\\n5590 6764 2775 3854 4798 348 3954\\n\", \"8 10\\n7 5 0 0 2 3 6 3\\n2948 525 5789 4809 3961 6111 5209 8128\\n\", \"20 10\\n13 10 5 6 18 5 12 13 15 1 10 3 9 16 7 9 7 11 9 13\\n2634 7980 171 3503 6601 9378 4618 8243 9343 1979 4172 7441 9722 9863 6041 4790 1737 7586 6461 228\\n\"], \"outputs\": [\"10 1\\n8 1\\n7 1\\n10 2\\n8 2\\n7 1\\n9 3\\n\", \"0 0\\n4 1\\n8 2\\n12 3\\n\", \"7 1\\n17 1\\n19 2\\n21 3\\n8 1\\n\", \"10000 10000\\n\", \"20000 10000\\n\", \"100000000000000 10000\\n\", \"12 4\\n15 4\\n\", \"12 4\\n21 7\\n\", \"15 4\\n18 4\\n\", \"18 4\\n21 7\\n\", \"92400 9240\\n53310 5331\\n67210 6721\\n\", \"34728 960\\n25960 2596\\n37520 3752\\n31667 2596\\n\", \"84730 8473\\n75890 7399\\n73990 7399\\n80653 4396\\n73866 7275\\n\", \"48450 4845\\n49815 4787\\n43900 579\\n48108 4787\\n46319 2998\\n47870 4787\\n\", \"48772 4798\\n49894 3954\\n45957 2775\\n46984 3854\\n47980 4798\\n41507 348\\n47928 3954\\n\", \"50603 2948\\n46163 525\\n53444 2948\\n52464 2948\\n52596 2948\\n53766 2948\\n52090 5209\\n55783 2948\\n\", \"62163 1737\\n45528 4172\\n84573 171\\n48662 1979\\n48053 1979\\n93780 9378\\n49331 1979\\n67772 1737\\n49124 1979\\n43335 1979\\n41720 4172\\n51931 1979\\n48885 1979\\n69392 1737\\n65570 1737\\n43953 1979\\n61266 1737\\n55345 1979\\n45624 1979\\n59757 228\\n\"]}", "source": "primeintellect"}
You are given a functional graph. It is a directed graph, in which from each vertex goes exactly one arc. The vertices are numerated from 0 to n - 1. Graph is given as the array f_0, f_1, ..., f_{n} - 1, where f_{i} — the number of vertex to which goes the only arc from the vertex i. Besides you are given array with weights of the arcs w_0, w_1, ..., w_{n} - 1, where w_{i} — the arc weight from i to f_{i}. [Image] The graph from the first sample test. Also you are given the integer k (the length of the path) and you need to find for each vertex two numbers s_{i} and m_{i}, where: s_{i} — the sum of the weights of all arcs of the path with length equals to k which starts from the vertex i; m_{i} — the minimal weight from all arcs on the path with length k which starts from the vertex i. The length of the path is the number of arcs on this path. -----Input----- The first line contains two integers n, k (1 ≤ n ≤ 10^5, 1 ≤ k ≤ 10^10). The second line contains the sequence f_0, f_1, ..., f_{n} - 1 (0 ≤ f_{i} < n) and the third — the sequence w_0, w_1, ..., w_{n} - 1 (0 ≤ w_{i} ≤ 10^8). -----Output----- Print n lines, the pair of integers s_{i}, m_{i} in each line. -----Examples----- Input 7 3 1 2 3 4 3 2 6 6 3 1 4 2 2 3 Output 10 1 8 1 7 1 10 2 8 2 7 1 9 3 Input 4 4 0 1 2 3 0 1 2 3 Output 0 0 4 1 8 2 12 3 Input 5 3 1 2 3 4 0 4 1 2 14 3 Output 7 1 17 1 19 2 21 3 8 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\": [\"3\\n1 1 2\\n2 3 1\\n6 4 1\\n\", \"3\\n1 5 2\\n1 1 1\\n1 2 3\\n\", \"1\\n1\\n\", \"4\\n1 1 1 1\\n1 11 1 2\\n2 5 1 4\\n3 9 4 1\\n\", \"4\\n1 1 1 1\\n1 7 1 1\\n1 3 1 2\\n2 6 3 1\\n\", \"4\\n1 1 1 1\\n1 12 1 2\\n4 4 1 3\\n5 10 6 1\\n\", \"4\\n1 1 1 1\\n1 13 1 2\\n4 5 1 3\\n5 11 6 1\\n\", \"4\\n1 1 1 1\\n1 13 1 2\\n4 5 1 3\\n7 11 6 1\\n\", \"4\\n1 1 1 1\\n1 14 1 6\\n4 5 1 5\\n3 8 2 1\\n\", \"10\\n3 2 6 5 1 2 1 1 2 1\\n1 2 2 3 1 4 1 1 1 1\\n1 1 3 1 2 2 2 1 1 1\\n1 3 1 2 1 2 1 1 1 1\\n12 1 4 3 3 1 1 1 2 1\\n8 1 1 1 1 3 6 5 1 3\\n1 1 1 2 4 1 3 2 1 1\\n1 1 1 1 1 1 1 2 1 1\\n1 2 1 1 1 1 1 1 1 1\\n2 1 1 1 1 1 1 1 1 2\\n\", \"4\\n1 2 3 5\\n1 1 1 1\\n1 1 1 1\\n1 1 1 1\\n\", \"1\\n2\\n\", \"3\\n1 1 4\\n1 1 2\\n1 1 2\\n\", \"1\\n5\\n\", \"3\\n1 2 1\\n2 2 3\\n1 3 1\\n\", \"3\\n2 1 1\\n2 1 1\\n2 1 1\\n\", \"1\\n60000\\n\"], \"outputs\": [\"Yes\\n\", \"No\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"Yes\\n\", \"No\\n\", \"Yes\\n\", \"Yes\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\", \"No\\n\"]}", "source": "primeintellect"}
Okabe needs to renovate the Future Gadget Laboratory after he tried doing some crazy experiments! The lab is represented as an n by n square grid of integers. A good lab is defined as a lab in which every number not equal to 1 can be expressed as the sum of a number in the same row and a number in the same column. In other words, for every x, y such that 1 ≤ x, y ≤ n and a_{x}, y ≠ 1, there should exist two indices s and t so that a_{x}, y = a_{x}, s + a_{t}, y, where a_{i}, j denotes the integer in i-th row and j-th column. Help Okabe determine whether a given lab is good! -----Input----- The first line of input contains the integer n (1 ≤ n ≤ 50) — the size of the lab. The next n lines contain n space-separated integers denoting a row of the grid. The j-th integer in the i-th row is a_{i}, j (1 ≤ a_{i}, j ≤ 10^5). -----Output----- Print "Yes" if the given lab is good and "No" otherwise. You can output each letter in upper or lower case. -----Examples----- Input 3 1 1 2 2 3 1 6 4 1 Output Yes Input 3 1 5 2 1 1 1 1 2 3 Output No -----Note----- In the first sample test, the 6 in the bottom left corner is valid because it is the sum of the 2 above it and the 4 on the right. The same holds for every number not equal to 1 in this table, so the answer is "Yes". In the second sample test, the 5 cannot be formed as the sum of an integer in the same row and an integer in the same column. Thus the answer is "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.75
{"tests": "{\"inputs\": [\"2 1\\nRL\\n\", \"2 1\\nLR\\n\", \"4 2\\nRLRL\\n\", \"3 2\\nRRL\\n\", \"3 2\\nLRL\\n\", \"250 2188894\\nLRLLLRRLRLRRLLRRRRRRRRRLRRLLRLLRLRLRLRRLLLRRLLLRLRRRRRRRLLLRRRRRLLLLRLRRRLRRRLLLLLLLLRRLRRLLRRRLLLRLLRRRLLRRLRLRLLLRLRRLLRRRRLRRLRLLLLRLRRLLLLLRRLRLRRRLLLRRLLLRRRLLRLRRRLRRRRRLRRLRRLLLRLRRRLLLRLLRRRLLRRLLRLLLLRRRRRLLRRLRLRRRLLRRRRRLRLLRRRRLLLRRRLRRLR\\n\", \"258 7719\\nRLLLRRLRRRRRLRLLLLLRRLRRRRRLLLRLRLLLLLRLLLRRRRRLLLRRLRLRLRLLRRLLRLRLLLLLLLLLLLRRLLLLRLLLLLRLLRLLRRRLLRLLLLLLRLRRRRLRLLRLRLRRLLRLRLRLLLRRLRLLLLLLLLLRRRLLRRLRRLLLLLLLLRRRLLLRRRLLRLLLLRLRLRLRLLRRLLLLRLRRRLLRRLRLRLLLRRRRRRLRRRLLLRRRLRLRLLRLLRLRLLRLRLLLRLRRLRRRRL\\n\", \"476 252\\nRRLLLRRRLLLLLRLRRLLRLLLRLRRLRRLLRLRLRRLLRRRRLLLRRRLLLLRLRLRRRLRLLRRRLRLRRLLRRLLLRLLRLRLLLRLRRLLLRLLLRLLRRRLRLRLLRLLLLLLRLRLRRRRLLRLRRRLRLLRRRLRRRRLRRRLRLLRLRRRLLRRLLRLLRLLRLRLRLRRLLLRLLLLLRLRRRRRLRLRLRLLLLRRLRRLLRLRLRLLRLLRLLRRLRLRLLRLRLRLRLRRLLLRLRRLLRLLRLLRLRLRLLRRLLRLLRLLLLLRLLLLRLLRLLLLLLLLLLLLLLRLRRRLRLLRRLLLRLLLLRRRRRRRRLRLRRLLRRLLLLRLLRLLRLRRLLRLLRRRLRLRRLRLRRRLRRLRRRRRRLLLLRLRRLLRRLLRRRLRRRRRLRRLLRRLRLRLLRLRLLLLLRLRLLRLLLRRRLLLLRRRLLRLRRLLLLRLLLLLRLRRRRRLRRLRRRRRL\\n\", \"127 67\\nLLLRRRLRLRLLRRRLRLLLLRRLRRLRLRLRRLLRLLRRLRLRLLLRRLRLLLRRRRRRLLLRLLLLRRLLRRRRRLRRRLRRLLRRRRRLLLRLLLLRRRRLLRLRLRRRLLLRRRRLRRRLLRL\\n\", \"189 106\\nRLRRRLLRRRRRRRRRLLLRLRLRRRRLLRRLRRRRRLLRLLLRRLRRRRLLRLRRRLLRRLLRRLLLRRLLLRLRRLRLRLLRRLLLLRRRLLRRLRLLLRLLLLLLRRLLLRLRRRRLRLLLLRRLLLRLRLLLLRLRLRRRLRRRRLLLLLRRRLRRRRRLLRRLLRRLLRLRLLLLRRLRLLRRR\\n\", \"308 2805095\\nRRRRRLLLRRLLLLRRLLRRLRLRLRRLLLRLLRRLLLLRLRRLRRLLLLLLLLRLRLRLRLLLRLRLRLLRLLRLRRRLRLRLRLRLLRLLLRRLRLRRRRRLRRRLRRRRLRRRRRRRLLRRRRLRRLLRLLLLRLRRRRRRRLRRLRRLRRRRLLLLRLRLLLRRLRLLLRLLLLRLRLRLRLLLLLLLLRLRRRRRRRRRLLRLLRRRRLLLRLLRLRLRLLRLRRRLLLLLLRRRRLLLLLRRLLLRLLRLRRRRLRRRLRRRRLLLLRLLLLLLLLRLLRRRLLRRRRRLRRLRLRLRLLRL\\n\", \"175 67888\\nLRRRRRLLLLLRRLRLLLRRRRLRRLRRLRRRRLRLRRRRRRRRRLRLRRRLLRRRRLRLLRRRLLLLRRRRRLRRRRRRLLRLLRLLLRLLRLLLLLLRLLRRRRLLRRLLRRRLRLRLRRRRRRLRLRRRLLLLRLRRLLRRRRLLRRRLLLRLLLLLRLRLLRLRRLRLLRL\\n\", \"209 54\\nLRLRRLLRLRRRRRLLLLRLLRRLRLLLRLRRLLRLLLLLRRRRLLRRRRLLRLLRRLRRLLRRLLRLRRRLLRLLLLLRLLRRLLLRRLRLRLLLLRRLRRRLLLLRRRLLRLLRRLLRLRLRLRLRLRLLRRLLLLRLRLRLLRLLRLLRRRLLRLRRRLLLLRLLLRLRLLRRLRRLRRLLLLLLLLLLRRRRRLRRLLRRLLRRL\\n\", \"258 71\\nRRRRLLRLLRRLLLLLRRRLRRRRRRLRLLRLRLLLRRLLLLRLLLRRLLRRLRRRLLLRRRLRLRRRRRRLLRLRRRRLLRRLRRRLLLRRRRLRRRLRLRLLRRLRRRLLLLLLLRRLRRLLLRRLLLLLLRRRLLRLRLRLLLRLLRLRRRLRRLLLLLLRRRRLRLRRRLRLRLLLRLRLRRRLRLLRRLLRLLRLLLLRLRRLLLRRLLLLLLRLLRRRRRRRRRRRRRRLLLLRRRRRLRRLLLRLLLRLRR\\n\", \"347 152\\nRRRLRRRLLRRRLRRLRRRRLRRRRLLRLRLRRLRRRLRLRRRLLLRLLLRLLLLLRLRLLRRRLRLLRRRRLRLRLLLLLRRRLRRLRLLRRLRRLRRLLLRRRLLRLRLLRRRLRRRLLRLRLLLRRLLRLLLRRRRRLRLLRRRLRRLRLLRRLRRRLRRRLLLLLLLRLLLLLRRLRRLRRRLRRRRLLRRRLRRRLRRRRLRRLRLLLRLLLLLRRLLRRRRLLRLLRRLRLRRLRLRRRLLRLLRLRLLLRLRLRLLRRRLLRRLRLRRLRRRLRLRLLLLRRRLRLRLLLRLRRRLRRLLRRLLLRLRLLLRRLLLLRLLLRRLLRLRRRLLLLRRLRRL\\n\", \"488 2493006\\nRRRRRRRRRLRRRRRLLRLLRRRLRRLRLRRRLLRLLLLRRLRLLLRLRRLLRRRRRRLLRLRLRRLRLRLRRRRLRRRRLLRLRRRLRLRRLRRLLLLLRRLRRLLLLLRRRLLRRLRRLLLLRRRRRLRLRRRLRRRLLRRLRRRLLRLRLRRRRLLLRLLLLRRLLLLRRRLLRLLRRRRLRRLRRLRLRLLLRLLRRLLRLRRRRRRLLLLLLLLRRRLRRLRLLLRLRLRLLRLRRRRLRLRRLRRRLRRRLRRRLRRLLLRLLLLRLLRRRLRRRRRRLLRRRLRLRLLRLRLRRRRRRLRRRLLLRLLLRLLLLRLRRLLRLRLRLLRLLRLLRRLRLLLRLLLLRLLRLRRLLLRRLRLLRRRLRLRRLLRLLRRRLLRLLRRLRRLRRLLRRLLRLRRLRLLRLRRLLLLLRLLRLRRRRLRRLRRLRLLLLRRRLLLLLLLLLLLLRRLLRLLLRLLRLLRLRLRLLRRRLLRRRRLR\\n\", \"444 368721\\nLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRR\\n\"], \"outputs\": [\"1 1 \\n\", \"-1\", \"2 1 3 \\n1 2\\n\", \"1 2 \\n1 1\\n\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\", \"-1\"]}", "source": "primeintellect"}
There are $n$ children, who study at the school №41. It is well-known that they are good mathematicians. Once at a break, they arranged a challenge for themselves. All children arranged in a row and turned heads either to the left or to the right. Children can do the following: in one second several pairs of neighboring children who are looking at each other can simultaneously turn the head in the opposite direction. For instance, the one who was looking at the right neighbor turns left and vice versa for the second child. Moreover, every second at least one pair of neighboring children performs such action. They are going to finish when there is no pair of neighboring children who are looking at each other. You are given the number $n$, the initial arrangement of children and the number $k$. You have to find a way for the children to act if they want to finish the process in exactly $k$ seconds. More formally, for each of the $k$ moves, you need to output the numbers of the children who turn left during this move. For instance, for the configuration shown below and $k = 2$ children can do the following steps: [Image] At the beginning, two pairs make move: $(1, 2)$ and $(3, 4)$. After that, we receive the following configuration: [Image] At the second move pair $(2, 3)$ makes the move. The final configuration is reached. Good job. [Image] It is guaranteed that if the solution exists, it takes not more than $n^2$ "headturns". -----Input----- The first line of input contains two integers $n$ and $k$ ($2 \le n \le 3000$, $1 \le k \le 3000000$)  — the number of children and required number of moves. The next line contains a string of length $n$ and consists only of characters L and R, where L means that the child looks to the left and R means that the child looks to the right. -----Output----- If there is no solution, print a single line with number $-1$. Otherwise, output $k$ lines. Each line has to start with a number $n_i$ ($1\le n_i \le \frac{n}{2}$)  — the number of pairs of children, who turn at this move. After that print $n_i$ distinct integers  — the numbers of the children who will turn left during this move. After performing all "headturns", there can't be a pair of two neighboring children looking at each other. If there are many solutions, print any of them. -----Examples----- Input 2 1 RL Output 1 1 Input 2 1 LR Output -1 Input 4 2 RLRL Output 2 1 3 1 2 -----Note----- The first sample contains a pair of children who look at each other. After one move, they can finish the process. In the second sample, children can't make any move. As a result, they can't end in $k>0$ moves. The third configuration is described in the statement. 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\\n1 2 1\\n3 2 1\\n1 3 3\\n\", \"4 5 2\\n4 1 8\\n2 4 1\\n2 1 3\\n3 4 9\\n3 1 5\\n\", \"5 5 4\\n1 2 999999999\\n2 3 999999999\\n3 4 999999999\\n1 5 999999999\\n5 4 999999999\\n\", \"4 5 0\\n4 1 8\\n2 4 1\\n2 1 3\\n3 4 9\\n3 1 5\\n\", \"4 3 3\\n1 2 1000000000\\n2 3 1000000000\\n3 4 1000000000\\n\", \"6 6 4\\n1 2 947932848\\n2 3 932847264\\n3 4 994392894\\n1 5 943982748\\n5 4 983472874\\n5 6 236174687\\n\", \"5 5 4\\n1 2 947932848\\n2 3 932847264\\n3 4 994392894\\n1 5 943982748\\n5 4 983472874\\n\", \"4 4 0\\n1 2 1\\n2 3 1\\n3 4 1\\n1 4 2\\n\", \"6 6 5\\n1 2 1000000000\\n2 3 1000000000\\n3 4 1000000000\\n3 5 1\\n4 6 1\\n5 6 2\\n\", \"7 7 4\\n1 2 1000000000\\n2 3 1000000000\\n3 7 1\\n7 5 1\\n3 4 1000000000\\n4 5 1000000000\\n4 6 1\\n\", \"9 9 7\\n1 2 1000000000\\n7 9 1000000000\\n9 4 1000000000\\n2 6 1000000000\\n2 3 1000000000\\n3 7 1000000000\\n6 8 1000000000\\n8 4 1000000000\\n4 5 1000000000\\n\", \"6 6 4\\n1 2 999999999\\n2 3 999999999\\n3 4 999999999\\n4 5 1\\n1 6 1000000000\\n5 6 1000000000\\n\", \"6 6 4\\n1 2 999999998\\n2 3 999999998\\n3 4 999999998\\n4 5 1\\n1 6 999999999\\n5 6 1000000000\\n\", \"6 5 5\\n1 2 1000000000\\n2 3 1000000000\\n3 4 1000000000\\n4 5 1000000000\\n5 6 1000000000\\n\", \"10 10 4\\n1 2 1000000000\\n2 3 1\\n3 4 1000000000\\n4 5 1000000000\\n5 6 1000000000\\n6 7 1000000000\\n7 8 1\\n8 9 1000000000\\n9 10 1000000000\\n8 10 1\\n\", \"7 7 6\\n1 2 1000000000\\n2 3 1000000000\\n3 4 1000000000\\n4 5 1000000000\\n5 6 1000000000\\n6 7 1000000000\\n7 1 1000000000\\n\", \"7 8 6\\n1 2 1000000000\\n2 3 1000000000\\n3 4 1000000000\\n3 5 50000000\\n4 5 50000000\\n6 4 50000000\\n7 6 1\\n7 3 1000000000\\n\"], \"outputs\": [\"2\\n1 2 \", \"2\\n3 2 \", \"4\\n1 4 2 5 \", \"0\\n\", \"3\\n1 2 3 \", \"4\\n4 1 6 2 \", \"4\\n4 1 2 5 \", \"0\\n\", \"5\\n1 2 4 6 5 \", \"4\\n1 2 3 4 \", \"7\\n1 5 4 6 7 8 2 \", \"4\\n1 5 2 6 \", \"4\\n1 5 2 6 \", \"5\\n1 2 3 4 5 \", \"4\\n1 2 3 4 \", \"6\\n1 7 2 6 3 5 \", \"6\\n1 2 4 5 6 7 \"]}", "source": "primeintellect"}
You are given an undirected connected weighted graph consisting of $n$ vertices and $m$ edges. Let's denote the length of the shortest path from vertex $1$ to vertex $i$ as $d_i$. You have to erase some edges of the graph so that at most $k$ edges remain. Let's call a vertex $i$ good if there still exists a path from $1$ to $i$ with length $d_i$ after erasing the edges. Your goal is to erase the edges in such a way that the number of good vertices is maximized. -----Input----- The first line contains three integers $n$, $m$ and $k$ ($2 \le n \le 3 \cdot 10^5$, $1 \le m \le 3 \cdot 10^5$, $n - 1 \le m$, $0 \le k \le m$) — the number of vertices and edges in the graph, and the maximum number of edges that can be retained in the graph, respectively. Then $m$ lines follow, each containing three integers $x$, $y$, $w$ ($1 \le x, y \le n$, $x \ne y$, $1 \le w \le 10^9$), denoting an edge connecting vertices $x$ and $y$ and having weight $w$. The given graph is connected (any vertex can be reached from any other vertex) and simple (there are no self-loops, and for each unordered pair of vertices there exists at most one edge connecting these vertices). -----Output----- In the first line print $e$ — the number of edges that should remain in the graph ($0 \le e \le k$). In the second line print $e$ distinct integers from $1$ to $m$ — the indices of edges that should remain in the graph. Edges are numbered in the same order they are given in the input. The number of good vertices should be as large as possible. -----Examples----- Input 3 3 2 1 2 1 3 2 1 1 3 3 Output 2 1 2 Input 4 5 2 4 1 8 2 4 1 2 1 3 3 4 9 3 1 5 Output 2 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\": [\"4\\n5 5 7 2\\n\", \"3\\n1 2 3\\n\", \"3\\n3 1 10\\n\", \"1\\n0\\n\", \"1\\n7\\n\", \"2\\n3 4\\n\", \"10\\n2 1 0 0 0 2 2 1 1 0\\n\", \"10\\n5 3 2 0 6 5 4 1 6 2\\n\", \"10\\n63366411 57391809 217887804 43036621 397716019 878676084 451005539 537039674 935482853 474757099\\n\", \"100\\n3 2 1 3 2 3 1 2 0 0 1 2 1 3 2 0 2 0 2 3 1 1 1 0 1 0 3 2 2 0 0 1 0 1 3 3 1 2 2 2 3 0 2 1 3 0 2 1 0 0 1 2 2 3 1 3 2 2 2 0 0 1 0 1 0 2 3 2 2 1 0 2 0 2 0 3 3 3 1 1 3 1 1 1 1 0 0 1 0 0 2 3 1 2 1 3 0 3 0 0\\n\", \"100\\n7 4 5 5 3 0 1 3 4 2 5 0 1 5 5 7 2 4 4 6 7 7 3 6 6 2 0 0 2 7 7 2 6 1 5 7 4 1 0 7 0 7 1 5 7 5 3 4 2 2 0 0 6 3 6 3 7 7 2 5 3 7 3 0 0 1 6 1 5 3 7 6 3 7 4 3 5 7 7 4 7 4 7 2 2 5 5 4 4 4 3 3 0 3 4 3 1 7 1 6\\n\", \"100\\n116 15 100 97 10 72 118 57 127 14 8 99 78 74 3 22 21 34 36 64 125 102 103 78 4 55 79 17 114 45 34 103 90 7 2 124 107 58 122 69 91 4 110 14 87 66 3 8 123 88 91 73 47 40 115 46 2 55 86 124 26 5 104 107 91 88 108 107 86 14 48 68 26 86 126 92 33 77 53 88 80 114 14 66 19 17 60 62 17 28 41 62 109 15 85 94 31 95 89 117\\n\", \"100\\n1065 362 1002 1071 502 252 1401 1824 887 1803 1572 1571 502 1408 1699 1750 1785 1507 1616 1458 372 323 939 1208 1639 1517 1145 319 935 1507 1094 156 1062 39 1884 1470 646 917 1699 631 39 789 1030 1589 1700 17 495 32 506 574 1458 206 1091 211 279 1617 1624 1183 572 1496 1014 2007 139 1820 1662 1546 1695 1215 40 1555 686 193 1346 385 919 1812 685 291 151 277 1612 1783 1028 447 1782 549 60 704 2032 1427 1498 271 1530 625 1446 867 1826 1128 644 1280\\n\", \"69\\n380 150 5 157 175 306 237 3 232 356 148 397 259 176 318 310 362 185 211 413 231 254 97 35 284 67 146 350 351 156 288 380 57 306 341 375 309 30 239 261 168 45 180 78 268 324 342 85 66 77 318 130 83 360 409 122 79 371 363 234 233 160 9 387 177 302 4 330 266\\n\", \"20\\n6336516 45164 67114498 71304212 7486060 68191796 72498272 70428676 73572450 71318068 71469694 5386788 74459206 4234844 68299902 70263402 69240440 70434322 68299868 70391846\\n\", \"20\\n1081344 1081344 0 32768 0 1081344 1048576 0 0 32768 1048576 32768 1048576 1081344 1081344 1048576 0 1048576 1048576 1081344\\n\", \"1\\n23424\\n\"], \"outputs\": [\"2\\n\", \"-1\\n\", \"3\\n\", \"-1\\n\", \"1\\n\", \"2\\n\", \"2\\n\", \"3\\n\", \"10\\n\", \"2\\n\", \"3\\n\", \"7\\n\", \"11\\n\", \"9\\n\", \"16\\n\", \"2\\n\", \"1\\n\"]}", "source": "primeintellect"}
You are given an array $a_1, a_2, \dots, a_n$ of integer numbers. Your task is to divide the array into the maximum number of segments in such a way that: each element is contained in exactly one segment; each segment contains at least one element; there doesn't exist a non-empty subset of segments such that bitwise XOR of the numbers from them is equal to $0$. Print the maximum number of segments the array can be divided into. Print -1 if no suitable division exists. -----Input----- The first line contains a single integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the size of the array. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($0 \le a_i \le 10^9$). -----Output----- Print the maximum number of segments the array can be divided into while following the given constraints. Print -1 if no suitable division exists. -----Examples----- Input 4 5 5 7 2 Output 2 Input 3 1 2 3 Output -1 Input 3 3 1 10 Output 3 -----Note----- In the first example $2$ is the maximum number. If you divide the array into $\{[5], [5, 7, 2]\}$, the XOR value of the subset of only the second segment is $5 \oplus 7 \oplus 2 = 0$. $\{[5, 5], [7, 2]\}$ has the value of the subset of only the first segment being $5 \oplus 5 = 0$. However, $\{[5, 5, 7], [2]\}$ will lead to subsets $\{[5, 5, 7]\}$ of XOR $7$, $\{[2]\}$ of XOR $2$ and $\{[5, 5, 7], [2]\}$ of XOR $5 \oplus 5 \oplus 7 \oplus 2 = 5$. Let's take a look at some division on $3$ segments — $\{[5], [5, 7], [2]\}$. It will produce subsets: $\{[5]\}$, XOR $5$; $\{[5, 7]\}$, XOR $2$; $\{[5], [5, 7]\}$, XOR $7$; $\{[2]\}$, XOR $2$; $\{[5], [2]\}$, XOR $7$; $\{[5, 7], [2]\}$, XOR $0$; $\{[5], [5, 7], [2]\}$, XOR $5$; As you can see, subset $\{[5, 7], [2]\}$ has its XOR equal to $0$, which is unacceptable. You can check that for other divisions of size $3$ or $4$, non-empty subset with $0$ XOR always exists. The second example has no suitable divisions. The third example array can be divided into $\{[3], [1], [10]\}$. No subset of these segments has its XOR equal to $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\": [\"4\\n\", \"5\\n\", \"1000000\\n\", \"999999\\n\", \"524288\\n\", \"524287\\n\", \"890123\\n\", \"2\\n\", \"3\\n\", \"7\\n\", \"6\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"887726\\n\", \"314159\\n\", \"10239\\n\", \"997263\\n\", \"233557\\n\", \"1000\\n\", \"102\\n\", \"777777\\n\"], \"outputs\": [\"8 10\\n1 2 0\\n2 3 0\\n3 4 0\\n1 5 0\\n2 6 0\\n3 7 0\\n4 8 0\\n5 6 1\\n6 7 1\\n7 8 1\\n\", \"5 7\\n1 2 0\\n2 3 1\\n3 4 0\\n4 5 0\\n2 4 0\\n1 3 3\\n3 5 1\\n\", \"1000000\\n\", \"999999\\n\", \"524288\\n\", \"524287\\n\", \"890123\\n\", \"2\\n\", \"3\\n\", \"7\\n\", \"6\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"887726\\n\", \"314159\\n\", \"10239\\n\", \"997263\\n\", \"233557\\n\", \"1000\\n\", \"102\\n\", \"777777\\n\"]}", "source": "primeintellect"}
You are given an integer L. Construct a directed graph that satisfies the conditions below. The graph may contain multiple edges between the same pair of vertices. It can be proved that such a graph always exists. - The number of vertices, N, is at most 20. The vertices are given ID numbers from 1 to N. - The number of edges, M, is at most 60. Each edge has an integer length between 0 and 10^6 (inclusive). - Every edge is directed from the vertex with the smaller ID to the vertex with the larger ID. That is, 1,2,...,N is one possible topological order of the vertices. - There are exactly L different paths from Vertex 1 to Vertex N. The lengths of these paths are all different, and they are integers between 0 and L-1. Here, the length of a path is the sum of the lengths of the edges contained in that path, and two paths are considered different when the sets of the edges contained in those paths are different. -----Constraints----- - 2 \leq L \leq 10^6 - L is an integer. -----Input----- Input is given from Standard Input in the following format: L -----Output----- In the first line, print N and M, the number of the vertices and edges in your graph. In the i-th of the following M lines, print three integers u_i,v_i and w_i, representing the starting vertex, the ending vertex and the length of the i-th edge. If there are multiple solutions, any of them will be accepted. -----Sample Input----- 4 -----Sample Output----- 8 10 1 2 0 2 3 0 3 4 0 1 5 0 2 6 0 3 7 0 4 8 0 5 6 1 6 7 1 7 8 1 In the graph represented by the sample output, there are four paths from Vertex 1 to N=8: - 1 → 2 → 3 → 4 → 8 with length 0 - 1 → 2 → 3 → 7 → 8 with length 1 - 1 → 2 → 6 → 7 → 8 with length 2 - 1 → 5 → 6 → 7 → 8 with length 3 There are other possible solutions. 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\\n92 31\\n0 7\\n31 0\\n7 141\\n\", \"2\\n0 1\\n2 0\\n\", \"3\\n0 2\\n1 3\\n2 0\\n\", \"4\\n101 0\\n0 102\\n102 100\\n103 101\\n\", \"5\\n0 1\\n1 4\\n4 0\\n3 2\\n5 3\\n\", \"6\\n10001 0\\n0 10005\\n10003 10001\\n10002 10000\\n10005 10002\\n10004 10003\\n\", \"3\\n0 743259\\n72866 70294\\n743259 0\\n\", \"4\\n263750 0\\n513707 263750\\n0 718595\\n718595 148112\\n\", \"5\\n645873 145459\\n638930 82975\\n0 645873\\n82975 389665\\n145459 0\\n\", \"6\\n341637 51795\\n0 809471\\n51795 0\\n244669 341637\\n852537 508622\\n809471 852537\\n\", \"7\\n111283 0\\n496010 510417\\n423431 921854\\n510417 111283\\n0 496010\\n758535 423431\\n921854 59208\\n\", \"8\\n611412 115521\\n114290 712424\\n115521 242491\\n242491 0\\n0 114290\\n712424 282922\\n282922 589147\\n359823 611412\\n\", \"9\\n308992 348750\\n0 6496\\n487447 676506\\n874677 985199\\n260782 487447\\n985199 260782\\n348750 0\\n570981 308992\\n6496 570981\\n\", \"10\\n419946 201769\\n245945 0\\n842799 113073\\n836998 245945\\n0 794376\\n692107 836998\\n113073 904403\\n904403 987165\\n201769 692107\\n794376 842799\\n\", \"10\\n189071 852255\\n227133 652124\\n329720 4848\\n652124 329720\\n0 72517\\n943168 0\\n72517 544697\\n4848 943168\\n538963 189071\\n544697 538963\\n\", \"2\\n0 300000\\n1000000 0\\n\"], \"outputs\": [\"92 7 31 141 \\n\", \"2 1 \\n\", \"1 2 3 \\n\", \"103 102 101 100 \\n\", \"5 1 3 4 2 \\n\", \"10004 10005 10003 10002 10001 10000 \\n\", \"72866 743259 70294 \\n\", \"513707 718595 263750 148112 \\n\", \"638930 645873 82975 145459 389665 \\n\", \"244669 809471 341637 852537 51795 508622 \\n\", \"758535 496010 423431 510417 921854 111283 59208 \\n\", \"359823 114290 611412 712424 115521 282922 242491 589147 \\n\", \"874677 6496 985199 570981 260782 308992 487447 348750 676506 \\n\", \"419946 794376 201769 842799 692107 113073 836998 904403 245945 987165 \\n\", \"227133 72517 652124 544697 329720 538963 4848 189071 943168 852255 \\n\", \"1000000 300000 \\n\"]}", "source": "primeintellect"}
During the lunch break all n Berland State University students lined up in the food court. However, it turned out that the food court, too, has a lunch break and it temporarily stopped working. Standing in a queue that isn't being served is so boring! So, each of the students wrote down the number of the student ID of the student that stands in line directly in front of him, and the student that stands in line directly behind him. If no one stands before or after a student (that is, he is the first one or the last one), then he writes down number 0 instead (in Berland State University student IDs are numerated from 1). After that, all the students went about their business. When they returned, they found out that restoring the queue is not such an easy task. Help the students to restore the state of the queue by the numbers of the student ID's of their neighbors in the queue. -----Input----- The first line contains integer n (2 ≤ n ≤ 2·10^5) — the number of students in the queue. Then n lines follow, i-th line contains the pair of integers a_{i}, b_{i} (0 ≤ a_{i}, b_{i} ≤ 10^6), where a_{i} is the ID number of a person in front of a student and b_{i} is the ID number of a person behind a student. The lines are given in the arbitrary order. Value 0 is given instead of a neighbor's ID number if the neighbor doesn't exist. The ID numbers of all students are distinct. It is guaranteed that the records correspond too the queue where all the students stand in some order. -----Output----- Print a sequence of n integers x_1, x_2, ..., x_{n} — the sequence of ID numbers of all the students in the order they go in the queue from the first student to the last one. -----Examples----- Input 4 92 31 0 7 31 0 7 141 Output 92 7 31 141 -----Note----- The picture illustrates the queue for the first sample. [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\\n1 1\\n\", \"3\\n3 4 2\\n\", \"1\\n1\\n\", \"1\\n1000000000\\n\", \"3\\n1 2 3\\n\", \"2\\n2 3\\n\", \"5\\n1 4 2 1 1\\n\", \"15\\n2 72 77 69 62 73 58 9 4 95 97 14 41 79 34\\n\", \"1\\n1\\n\", \"10\\n529280935 122195401 684409084 743180136 724768643 211207376 167236398 696535490 425348743 1\\n\", \"8\\n1 870540358 821874877 223725489 367257956 1 105870869 267059674\\n\", \"5\\n483078839 692549116 1 458438081 1\\n\", \"6\\n1 1 423308752 1 1 1\\n\", \"7\\n150616203 306436158 391126478 164096410 558820207 878798937 310121836\\n\", \"50\\n1 3083990 976356336 922018335 1 170272482 1 547248035 1 1 1 1 1 928379588 1 1 1 270052499 315045369 1 1 556091215 1 655608230 424079072 1 1 185387009 77360256 1 1 942696777 228860271 1 487787709 1 437229749 167886535 1 1 904578415 319694007 1 313704390 1 1 957736320 771147030 458205965 497342117\\n\", \"96\\n1 1 1 1 1 1 1 943302667 1 1 1 1 1 1 1 1 422145309 1 1 848134211 1 1 1 1 182511245 1 1 1 1 826044915 1 1 1 1 778749310 1 1 1 1 1 1 1 1 1 1 1 1 1 274149110 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 291019191 1 1 1 1 1 1 1 1 1 1 1 532064146 1 1 1 1 1 1 772234680 1 1 1 1 1 1 1\\n\"], \"outputs\": [\"0\\n\", \"13\\n\", \"0\\n\", \"999999999\\n\", \"4\\n\", \"4\\n\", \"5\\n\", \"944598823\\n\", \"0\\n\", \"391882076\\n\", \"945207649\\n\", \"723940136\\n\", \"423308751\\n\", \"650844459\\n\", \"768215804\\n\", \"870354739\\n\"]}", "source": "primeintellect"}
Long ago, Vasily built a good fence at his country house. Vasily calls a fence good, if it is a series of n consecutively fastened vertical boards of centimeter width, the height of each in centimeters is a positive integer. The house owner remembers that the height of the i-th board to the left is h_{i}. Today Vasily decided to change the design of the fence he had built, by cutting his top connected part so that the fence remained good. The cut part should consist of only the upper parts of the boards, while the adjacent parts must be interconnected (share a non-zero length before cutting out of the fence). You, as Vasily's curious neighbor, will count the number of possible ways to cut exactly one part as is described above. Two ways to cut a part are called distinct, if for the remaining fences there is such i, that the height of the i-th boards vary. As Vasily's fence can be very high and long, get the remainder after dividing the required number of ways by 1 000 000 007 (10^9 + 7). -----Input----- The first line contains integer n (1 ≤ n ≤ 1 000 000) — the number of boards in Vasily's fence. The second line contains n space-separated numbers h_1, h_2, ..., h_{n} (1 ≤ h_{i} ≤ 10^9), where h_{i} equals the height of the i-th board to the left. -----Output----- Print the remainder after dividing r by 1 000 000 007, where r is the number of ways to cut exactly one connected part so that the part consisted of the upper parts of the boards and the remaining fence was good. -----Examples----- Input 2 1 1 Output 0 Input 3 3 4 2 Output 13 -----Note----- From the fence from the first example it is impossible to cut exactly one piece so as the remaining fence was good. All the possible variants of the resulting fence from the second sample look as follows (the grey shows the cut out part): [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\": [\"6\\n\", \"3\\n\", \"1\\n\", \"2\\n\", \"4\\n\", \"5\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"13\\n\", \"16\\n\", \"25\\n\", \"29\\n\", \"120\\n\", \"128\\n\"], \"outputs\": [\"6\\n5 3 1 6 4 2 \", \"2\\n1 3\", \"1\\n1 \", \"1\\n1\", \"4\\n3 1 4 2 \", \"5\\n5 3 1 4 2 \", \"7\\n7 5 3 1 6 4 2 \", \"8\\n7 5 3 1 8 6 4 2 \", \"9\\n9 7 5 3 1 8 6 4 2 \", \"10\\n9 7 5 3 1 10 8 6 4 2 \", \"13\\n13 11 9 7 5 3 1 12 10 8 6 4 2 \", \"16\\n15 13 11 9 7 5 3 1 16 14 12 10 8 6 4 2 \", \"25\\n25 23 21 19 17 15 13 11 9 7 5 3 1 24 22 20 18 16 14 12 10 8 6 4 2 \", \"29\\n29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 28 26 24 22 20 18 16 14 12 10 8 6 4 2 \", \"120\\n119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 \", \"128\\n127 125 123 121 119 117 115 113 111 109 107 105 103 101 99 97 95 93 91 89 87 85 83 81 79 77 75 73 71 69 67 65 63 61 59 57 55 53 51 49 47 45 43 41 39 37 35 33 31 29 27 25 23 21 19 17 15 13 11 9 7 5 3 1 128 126 124 122 120 118 116 114 112 110 108 106 104 102 100 98 96 94 92 90 88 86 84 82 80 78 76 74 72 70 68 66 64 62 60 58 56 54 52 50 48 46 44 42 40 38 36 34 32 30 28 26 24 22 20 18 16 14 12 10 8 6 4 2 \"]}", "source": "primeintellect"}
An exam for n students will take place in a long and narrow room, so the students will sit in a line in some order. The teacher suspects that students with adjacent numbers (i and i + 1) always studied side by side and became friends and if they take an exam sitting next to each other, they will help each other for sure. Your task is to choose the maximum number of students and make such an arrangement of students in the room that no two students with adjacent numbers sit side by side. -----Input----- A single line contains integer n (1 ≤ n ≤ 5000) — the number of students at an exam. -----Output----- In the first line print integer k — the maximum number of students who can be seated so that no two students with adjacent numbers sit next to each other. In the second line print k distinct integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ n), where a_{i} is the number of the student on the i-th position. The students on adjacent positions mustn't have adjacent numbers. Formally, the following should be true: |a_{i} - a_{i} + 1| ≠ 1 for all i from 1 to k - 1. If there are several possible answers, output any of them. -----Examples----- Input 6 Output 6 1 5 3 6 2 4 Input 3 Output 2 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 3\\n0 1 0 1\\n0 1\\n1 2\\n2 3\\n\", \"4 3\\n1 1 1 0\\n0 1\\n0 2\\n3 0\\n\", \"10 39\\n0 1 0 1 0 1 1 0 1 1\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n2 3\\n2 4\\n2 5\\n2 6\\n2 7\\n2 8\\n2 9\\n3 4\\n3 6\\n3 7\\n3 8\\n3 9\\n4 5\\n4 6\\n4 7\\n4 9\\n5 6\\n5 7\\n5 8\\n5 9\\n6 8\\n6 9\\n7 8\\n7 9\\n8 9\\n\", \"10 16\\n0 1 1 0 0 1 1 0 0 1\\n0 2\\n0 3\\n1 2\\n1 3\\n2 4\\n2 5\\n3 4\\n3 5\\n4 6\\n4 7\\n5 6\\n5 7\\n6 8\\n6 9\\n7 8\\n7 9\\n\", \"1 0\\n0\\n\", \"1 0\\n1\\n\", \"2 1\\n0 1\\n0 1\\n\", \"2 1\\n1 0\\n0 1\\n\", \"10 19\\n0 0 0 0 0 0 0 0 1 1\\n0 1\\n0 3\\n0 4\\n1 2\\n1 3\\n1 4\\n1 5\\n1 7\\n1 8\\n1 9\\n2 3\\n2 4\\n3 4\\n3 5\\n4 6\\n4 8\\n5 7\\n6 7\\n7 9\\n\", \"10 29\\n0 1 1 1 1 1 1 0 1 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 8\\n1 2\\n1 3\\n1 4\\n1 7\\n1 8\\n1 9\\n2 3\\n2 5\\n2 7\\n2 8\\n2 9\\n3 4\\n3 9\\n4 5\\n4 8\\n5 6\\n5 7\\n6 7\\n6 8\\n6 9\\n7 8\\n8 9\\n\", \"10 9\\n1 1 1 0 1 1 0 1 0 1\\n0 1\\n0 4\\n0 5\\n1 2\\n1 3\\n2 9\\n3 6\\n6 7\\n7 8\\n\", \"10 14\\n1 1 0 0 1 0 1 0 1 1\\n0 1\\n0 2\\n0 4\\n0 9\\n1 3\\n2 5\\n3 4\\n3 6\\n3 8\\n4 9\\n5 6\\n6 7\\n7 8\\n7 9\\n\", \"10 19\\n0 1 0 1 1 1 1 1 1 1\\n0 1\\n0 2\\n0 3\\n0 4\\n0 8\\n0 9\\n1 4\\n1 8\\n2 3\\n2 4\\n2 5\\n2 6\\n2 7\\n2 8\\n2 9\\n3 6\\n4 5\\n4 7\\n5 8\\n\", \"10 24\\n0 1 0 0 0 1 0 0 0 1\\n0 1\\n0 2\\n0 3\\n0 4\\n0 6\\n0 9\\n1 3\\n1 4\\n1 7\\n1 9\\n2 4\\n2 5\\n2 7\\n2 8\\n3 4\\n3 6\\n4 5\\n4 6\\n5 6\\n5 7\\n6 7\\n6 9\\n7 8\\n8 9\\n\", \"10 29\\n0 1 1 1 0 1 0 1 1 1\\n0 1\\n0 2\\n0 4\\n0 7\\n0 8\\n1 2\\n1 4\\n1 5\\n1 7\\n1 8\\n1 9\\n2 3\\n2 4\\n2 5\\n2 6\\n2 7\\n2 8\\n3 5\\n3 6\\n3 7\\n4 5\\n4 6\\n4 9\\n5 7\\n5 8\\n6 8\\n7 8\\n7 9\\n8 9\\n\", \"10 39\\n1 1 1 1 1 1 1 1 1 1\\n0 1\\n0 2\\n0 3\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n1 8\\n1 9\\n2 3\\n2 4\\n2 5\\n2 6\\n2 7\\n2 8\\n2 9\\n3 4\\n3 5\\n3 7\\n3 8\\n3 9\\n4 5\\n4 6\\n5 6\\n5 7\\n5 8\\n5 9\\n6 7\\n6 8\\n7 8\\n7 9\\n8 9\\n\"], \"outputs\": [\"2\\n\", \"1\\n\", \"4\\n\", \"3\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"2\\n\", \"2\\n\", \"3\\n\", \"1\\n\", \"3\\n\", \"2\\n\", \"1\\n\"]}", "source": "primeintellect"}
You are given a program you want to execute as a set of tasks organized in a dependency graph. The dependency graph is a directed acyclic graph: each task can depend on results of one or several other tasks, and there are no directed circular dependencies between tasks. A task can only be executed if all tasks it depends on have already completed. Some of the tasks in the graph can only be executed on a coprocessor, and the rest can only be executed on the main processor. In one coprocessor call you can send it a set of tasks which can only be executed on it. For each task of the set, all tasks on which it depends must be either already completed or be included in the set. The main processor starts the program execution and gets the results of tasks executed on the coprocessor automatically. Find the minimal number of coprocessor calls which are necessary to execute the given program. -----Input----- The first line contains two space-separated integers N (1 ≤ N ≤ 10^5) — the total number of tasks given, and M (0 ≤ M ≤ 10^5) — the total number of dependencies between tasks. The next line contains N space-separated integers $E_{i} \in \{0,1 \}$. If E_{i} = 0, task i can only be executed on the main processor, otherwise it can only be executed on the coprocessor. The next M lines describe the dependencies between tasks. Each line contains two space-separated integers T_1 and T_2 and means that task T_1 depends on task T_2 (T_1 ≠ T_2). Tasks are indexed from 0 to N - 1. All M pairs (T_1, T_2) are distinct. It is guaranteed that there are no circular dependencies between tasks. -----Output----- Output one line containing an integer — the minimal number of coprocessor calls necessary to execute the program. -----Examples----- Input 4 3 0 1 0 1 0 1 1 2 2 3 Output 2 Input 4 3 1 1 1 0 0 1 0 2 3 0 Output 1 -----Note----- In the first test, tasks 1 and 3 can only be executed on the coprocessor. The dependency graph is linear, so the tasks must be executed in order 3 -> 2 -> 1 -> 0. You have to call coprocessor twice: first you call it for task 3, then you execute task 2 on the main processor, then you call it for for task 1, and finally you execute task 0 on the main processor. In the second test, tasks 0, 1 and 2 can only be executed on the coprocessor. Tasks 1 and 2 have no dependencies, and task 0 depends on tasks 1 and 2, so all three tasks 0, 1 and 2 can be sent in one coprocessor call. After that task 3 is executed on the main processor. 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\\n4 1\\n\", \"3 1\\n2\\n\", \"5 5\\n25 24 23 22 21\\n\", \"1 30\\n8 22 13 25 10 30 12 27 6 4 7 2 20 16 26 14 15 17 23 3 24 9 5 11 29 1 19 28 21 18\\n\", \"30 1\\n29\\n\", \"1 1\\n1\\n\", \"2 1\\n1\\n\", \"1 2\\n2 1\\n\", \"1 3\\n2 3 1\\n\", \"2 3\\n3 2 1\\n\", \"3 3\\n6 7 8\\n\", \"3 1\\n3\\n\", \"3 2\\n5 4\\n\", \"27 3\\n12 77 80\\n\", \"7 1\\n5\\n\", \"6 1\\n5\\n\"], \"outputs\": [\"2 4 \\n1 3 \\n\", \"3 2 1 \\n\", \"2 3 1 25 4 \\n7 6 8 5 24 \\n10 12 9 23 11 \\n13 15 14 16 22 \\n19 21 20 17 18 \\n\", \"8 \\n22 \\n13 \\n25 \\n10 \\n30 \\n12 \\n27 \\n6 \\n4 \\n7 \\n2 \\n20 \\n16 \\n26 \\n14 \\n15 \\n17 \\n23 \\n3 \\n24 \\n9 \\n5 \\n11 \\n29 \\n1 \\n19 \\n28 \\n21 \\n18 \\n\", \"8 20 17 12 5 26 13 2 19 22 28 16 10 4 6 11 3 25 1 27 15 9 30 24 21 18 14 23 29 7 \\n\", \"1 \\n\", \"2 1 \\n\", \"2 \\n1 \\n\", \"2 \\n3 \\n1 \\n\", \"4 3 \\n2 5 \\n1 6 \\n\", \"2 6 1 \\n7 4 3 \\n5 9 8 \\n\", \"2 3 1 \\n\", \"2 5 1 \\n4 6 3 \\n\", \"8 21 18 13 5 27 14 2 20 23 12 17 10 4 6 11 3 26 1 24 16 9 7 25 22 19 15 \\n43 32 46 48 51 37 41 49 77 30 40 28 34 38 44 35 31 45 52 50 47 29 36 53 42 39 33 \\n62 61 78 63 81 55 70 79 67 73 58 69 59 64 80 54 56 57 68 72 65 60 71 66 74 75 76 \\n\", \"2 3 1 5 6 7 4 \\n\", \"2 3 1 5 6 4 \\n\"]}", "source": "primeintellect"}
One day Ms Swan bought an orange in a shop. The orange consisted of n·k segments, numbered with integers from 1 to n·k. There were k children waiting for Ms Swan at home. The children have recently learned about the orange and they decided to divide it between them. For that each child took a piece of paper and wrote the number of the segment that he would like to get: the i-th (1 ≤ i ≤ k) child wrote the number a_{i} (1 ≤ a_{i} ≤ n·k). All numbers a_{i} accidentally turned out to be different. Now the children wonder, how to divide the orange so as to meet these conditions: each child gets exactly n orange segments; the i-th child gets the segment with number a_{i} for sure; no segment goes to two children simultaneously. Help the children, divide the orange and fulfill the requirements, described above. -----Input----- The first line contains two integers n, k (1 ≤ n, k ≤ 30). The second line contains k space-separated integers a_1, a_2, ..., a_{k} (1 ≤ a_{i} ≤ n·k), where a_{i} is the number of the orange segment that the i-th child would like to get. It is guaranteed that all numbers a_{i} are distinct. -----Output----- Print exactly n·k distinct integers. The first n integers represent the indexes of the segments the first child will get, the second n integers represent the indexes of the segments the second child will get, and so on. Separate the printed numbers with whitespaces. You can print a child's segment indexes in any order. It is guaranteed that the answer always exists. If there are multiple correct answers, print any of them. -----Examples----- Input 2 2 4 1 Output 2 4 1 3 Input 3 1 2 Output 3 2 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 3\\n-1 -1\\n\", \"5 2\\n1 -1 -1 1 2\\n\", \"5 3\\n1 -1 -1 1 2\\n\", \"4 200000\\n-1 -1 12345 -1\\n\", \"9 3\\n-1 -1 -1 -1 1 2 3 -1 -1\\n\", \"10 5\\n4 -1 -1 1 -1 -1 -1 2 -1 -1\\n\", \"10 8\\n-1 3 5 2 4 -1 -1 1 -1 -1\\n\", \"10 11\\n-1 11 -1 -1 -1 -1 10 -1 -1 -1\\n\", \"10 14\\n-1 9 11 11 -1 -1 -1 -1 -1 -1\\n\", \"10 2\\n-1 -1 -1 -1 -1 -1 -1 1 1 -1\\n\", \"10 5\\n1 -1 -1 -1 5 -1 1 -1 -1 -1\\n\", \"10 8\\n4 8 -1 -1 -1 2 -1 4 -1 -1\\n\", \"10 11\\n11 8 -1 8 -1 3 -1 -1 3 -1\\n\", \"10 14\\n-1 -1 6 -1 -1 -1 9 -1 -1 -1\\n\", \"10 2\\n-1 -1 -1 2 2 1 -1 -1 -1 -1\\n\", \"2 3\\n3 3\\n\"], \"outputs\": [\"9\\n\", \"0\\n\", \"2\\n\", \"735945883\\n\", \"64\\n\", \"12288\\n\", \"14406\\n\", \"100000000\\n\", \"62748517\\n\", \"1\\n\", \"15360\\n\", \"100842\\n\", \"0\\n\", \"810903912\\n\", \"1\\n\", \"1\\n\"]}", "source": "primeintellect"}
Let's denote that some array $b$ is bad if it contains a subarray $b_l, b_{l+1}, \dots, b_{r}$ of odd length more than $1$ ($l < r$ and $r - l + 1$ is odd) such that $\forall i \in \{0, 1, \dots, r - l\}$ $b_{l + i} = b_{r - i}$. If an array is not bad, it is good. Now you are given an array $a_1, a_2, \dots, a_n$. Some elements are replaced by $-1$. Calculate the number of good arrays you can obtain by replacing each $-1$ with some integer from $1$ to $k$. Since the answer can be large, print it modulo $998244353$. -----Input----- The first line contains two integers $n$ and $k$ ($2 \le n, k \le 2 \cdot 10^5$) — the length of array $a$ and the size of "alphabet", i. e., the upper bound on the numbers you may use to replace $-1$. The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($a_i = -1$ or $1 \le a_i \le k$) — the array $a$. -----Output----- Print one integer — the number of good arrays you can get, modulo $998244353$. -----Examples----- Input 2 3 -1 -1 Output 9 Input 5 2 1 -1 -1 1 2 Output 0 Input 5 3 1 -1 -1 1 2 Output 2 Input 4 200000 -1 -1 12345 -1 Output 735945883 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 6\\nXXXXXX\\nXXXXXX\\nXXXXXX\\n\", \"10 10\\n.XXXXXX...\\n.XXXXXX...\\n.XXXXXX...\\n.XXXXXX...\\n.XXXXXXXX.\\n...XXXXXX.\\n...XXXXXX.\\n...XXXXXX.\\n...XXXXXX.\\n..........\\n\", \"4 5\\nX....\\n..XXX\\n..XXX\\n..XXX\\n\", \"1 1\\nX\\n\", \"10 12\\n...X..X..XX.\\n.....X......\\n..X.........\\n...X..XX...X\\n.......X.X..\\n....X...X.X.\\n..........X.\\n......XXX...\\n......X..X..\\n..X....XX..X\\n\", \"13 12\\n............\\n...XXX..XXXX\\n.XXXXXX.XXXX\\n.XXXXXX.XXXX\\n.XXXXXXXXXXX\\n.XXXXXXXXXXX\\n.XXX..XXXXXX\\nXXXXXXXX....\\nXXXXXXXXXX..\\nXXXXXXXXXXX.\\n.....XXXXXXX\\n.....XXXXXXX\\n.....XXXXXXX\\n\", \"15 14\\n..............\\n..XXXXXXXX....\\n..XXXXXXXXXXXX\\n..XXXXXXXXXXXX\\nXXXXXXXXXXXXXX\\nXXXXXXXXXXXXXX\\nXXXXXXXXXXXXXX\\nXXXXXXXXXXXXX.\\nXXXXXXXXXXXXX.\\n..XXXXXXXXX...\\n.XXXXXXXXXXX..\\n.XXXXXXXXXXX..\\n.XXXXXXXXXXX..\\n.XXXXXXXXXXX..\\n.XXXXXXXXXXX..\\n\", \"17 17\\n.................\\n.....XXXXXXXXX...\\n.....XXXXXXXXXXX.\\n.....XXXXXXXXXXXX\\n..XXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n.XXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXX\\n.....XXXXXXXXXXXX\\n.....XXXXXXXXX...\\n.....XXXXXXXXX...\\n\", \"20 20\\n....................\\n....................\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXXX\\n..XXXXXXXXXXXXXXXXX.\\n..XXXXXXXXXXXXXXXXX.\\n..XXXXXXXXXXXXXXXXX.\\n..XXXXXXXXXXXXXXXXX.\\n\", \"7 7\\nXXXXXXX\\nXXXXXXX\\nXXXXXXX\\nXX...XX\\nXXXXXXX\\nXXXXXXX\\nXXXXXXX\\n\", \"7 5\\n..XXX\\n..XXX\\n..XXX\\n.XXX.\\nXXX..\\nXXX..\\nXXX..\\n\", \"3 8\\nXXX..XXX\\nXXXXXXXX\\nXXXXXXXX\\n\", \"7 11\\nXXX.XXX.XXX\\nXXX.XXX.XXX\\nXXX.XXX.XXX\\n.XXXXXXXXX.\\n..XXX.XXX..\\n..XXX.XXX..\\n..XXX.XXX..\\n\", \"5 5\\n..XXX\\n..XXX\\nXXXXX\\nXXXX.\\nXXX..\\n\", \"8 7\\n.XXX...\\n.XXX...\\n.XXX...\\n..XXX..\\n...XXX.\\n....XXX\\n....XXX\\n....XXX\\n\", \"4 11\\n.XXX.XXX...\\n.XXXXXXX...\\n.XXXXXXX...\\n.XXX.XXX...\\n\"], \"outputs\": [\"1\\n......\\n.XXXX.\\n......\\n\", \"2\\n..........\\n..........\\n...XX.....\\n..........\\n..........\\n..........\\n.....XX...\\n..........\\n..........\\n..........\\n\", \"0\\nX....\\n..XXX\\n..XXX\\n..XXX\\n\", \"0\\nX\\n\", \"0\\n...X..X..XX.\\n.....X......\\n..X.........\\n...X..XX...X\\n.......X.X..\\n....X...X.X.\\n..........X.\\n......XXX...\\n......X..X..\\n..X....XX..X\\n\", \"1\\n............\\n............\\n....X....XX.\\n..XXXX...XX.\\n..XXXX...XX.\\n..X....XXXX.\\n..X.........\\n..X.........\\n.XXXXXX.....\\n......XXX...\\n......XXXX..\\n......XXXXX.\\n............\\n\", \"2\\n..............\\n..............\\n..............\\n....XXXX......\\n....XXXXXXXX..\\n....XXXXXXX...\\n..XXXXXXXXX...\\n....XXXXX.....\\n....XXXXX.....\\n....XXXXX.....\\n....XXXXX.....\\n....XXXXX.....\\n...XXXXXXX....\\n..............\\n..............\\n\", \"3\\n.................\\n.................\\n.................\\n.................\\n........XXX......\\n........XXXXX....\\n........XXXXXX...\\n.....XXXXXXXXX...\\n....XXXXXXXXXX...\\n.....XXXXXXXXX...\\n.....XXXXXXXXX...\\n........XXXXXX...\\n........XXX......\\n........XXX......\\n.................\\n.................\\n.................\\n\", \"6\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n........XXXXXX......\\n........XXXXXX......\\n........XXXXX.......\\n........XXXXX.......\\n........XXXXX.......\\n........XXXXX.......\\n....................\\n....................\\n....................\\n....................\\n....................\\n....................\\n\", \"0\\nXXXXXXX\\nXXXXXXX\\nXXXXXXX\\nXX...XX\\nXXXXXXX\\nXXXXXXX\\nXXXXXXX\\n\", \"0\\n..XXX\\n..XXX\\n..XXX\\n.XXX.\\nXXX..\\nXXX..\\nXXX..\\n\", \"0\\nXXX..XXX\\nXXXXXXXX\\nXXXXXXXX\\n\", \"0\\nXXX.XXX.XXX\\nXXX.XXX.XXX\\nXXX.XXX.XXX\\n.XXXXXXXXX.\\n..XXX.XXX..\\n..XXX.XXX..\\n..XXX.XXX..\\n\", \"0\\n..XXX\\n..XXX\\nXXXXX\\nXXXX.\\nXXX..\\n\", \"0\\n.XXX...\\n.XXX...\\n.XXX...\\n..XXX..\\n...XXX.\\n....XXX\\n....XXX\\n....XXX\\n\", \"0\\n.XXX.XXX...\\n.XXXXXXX...\\n.XXXXXXX...\\n.XXX.XXX...\\n\"]}", "source": "primeintellect"}
The Berland Forest can be represented as an infinite cell plane. Every cell contains a tree. That is, contained before the recent events. A destructive fire raged through the Forest, and several trees were damaged by it. Precisely speaking, you have a $n \times m$ rectangle map which represents the damaged part of the Forest. The damaged trees were marked as "X" while the remaining ones were marked as ".". You are sure that all burnt trees are shown on the map. All the trees outside the map are undamaged. The firemen quickly extinguished the fire, and now they are investigating the cause of it. The main version is that there was an arson: at some moment of time (let's consider it as $0$) some trees were set on fire. At the beginning of minute $0$, only the trees that were set on fire initially were burning. At the end of each minute, the fire spread from every burning tree to each of $8$ neighboring trees. At the beginning of minute $T$, the fire was extinguished. The firemen want to find the arsonists as quickly as possible. The problem is, they know neither the value of $T$ (how long the fire has been raging) nor the coordinates of the trees that were initially set on fire. They want you to find the maximum value of $T$ (to know how far could the arsonists escape) and a possible set of trees that could be initially set on fire. Note that you'd like to maximize value $T$ but the set of trees can be arbitrary. -----Input----- The first line contains two integer $n$ and $m$ ($1 \le n, m \le 10^6$, $1 \le n \cdot m \le 10^6$) — the sizes of the map. Next $n$ lines contain the map. The $i$-th line corresponds to the $i$-th row of the map and contains $m$-character string. The $j$-th character of the $i$-th string is "X" if the corresponding tree is burnt and "." otherwise. It's guaranteed that the map contains at least one "X". -----Output----- In the first line print the single integer $T$ — the maximum time the Forest was on fire. In the next $n$ lines print the certificate: the map ($n \times m$ rectangle) where the trees that were set on fire are marked as "X" and all other trees are marked as ".". -----Examples----- Input 3 6 XXXXXX XXXXXX XXXXXX Output 1 ...... .X.XX. ...... Input 10 10 .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXX... .XXXXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. ...XXXXXX. .......... Output 2 .......... .......... ...XX..... .......... .......... .......... .....XX... .......... .......... .......... Input 4 5 X.... ..XXX ..XXX ..XXX Output 0 X.... ..XXX ..XXX ..XXX 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\": [\"aaaaa\\naa\\n\", \"axbaxxb\\nab\\n\", \"aabb\\nab\\n\", \"aaaaaaaaaaaaaaa\\na\\n\", \"aaaaaaaaaaa\\nb\\n\", \"ababababababababa\\naba\\n\", \"axxbaxxbaxxb\\nab\\n\", \"axaxxbaxabxbaxxbxb\\nab\\n\", \"ababcc\\nabc\\n\", \"a\\na\\n\", \"a\\nb\\n\", \"a\\naa\\n\", \"a\\nab\\n\", \"a\\nbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb\\n\", \"a\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\n\", \"abxxxaxbxaxxxba\\naba\\n\"], \"outputs\": [\"2 2 1 1 0 0\\n\", \"0 1 1 2 1 1 0 0\\n\", \"1 1 1 0 0\\n\", \"15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0\\n\", \"0 0 0 0 0 0 0 0 0 0 0 0\\n\", \"4 4 4 4 4 4 3 3 3 2 2 2 1 1 1 0 0 0\\n\", \"0 0 1 1 2 2 3 2 2 1 1 0 0\\n\", \"1 1 2 2 3 3 3 3 3 3 3 3 3 2 2 1 1 0 0\\n\", \"1 1 1 1 0 0 0\\n\", \"1 0\\n\", \"0 0\\n\", \"0 0\\n\", \"0 0\\n\", \"0 0\\n\", \"0 0\\n\", \"0 0 1 1 1 1 2 2 2 2 1 1 1 0 0 0\\n\"]}", "source": "primeintellect"}
Dreamoon has a string s and a pattern string p. He first removes exactly x characters from s obtaining string s' as a result. Then he calculates $\operatorname{occ}(s^{\prime}, p)$ that is defined as the maximal number of non-overlapping substrings equal to p that can be found in s'. He wants to make this number as big as possible. More formally, let's define $\operatorname{ans}(x)$ as maximum value of $\operatorname{occ}(s^{\prime}, p)$ over all s' that can be obtained by removing exactly x characters from s. Dreamoon wants to know $\operatorname{ans}(x)$ for all x from 0 to |s| where |s| denotes the length of string s. -----Input----- The first line of the input contains the string s (1 ≤ |s| ≤ 2 000). The second line of the input contains the string p (1 ≤ |p| ≤ 500). Both strings will only consist of lower case English letters. -----Output----- Print |s| + 1 space-separated integers in a single line representing the $\operatorname{ans}(x)$ for all x from 0 to |s|. -----Examples----- Input aaaaa aa Output 2 2 1 1 0 0 Input axbaxxb ab Output 0 1 1 2 1 1 0 0 -----Note----- For the first sample, the corresponding optimal values of s' after removal 0 through |s| = 5 characters from s are {"aaaaa", "aaaa", "aaa", "aa", "a", ""}. For the second sample, possible corresponding optimal values of s' are {"axbaxxb", "abaxxb", "axbab", "abab", "aba", "ab", "a", ""}. 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\\n4 8 2\\n\", \"3\\n3 5 6\\n\", \"2\\n50000 100000\\n\", \"2\\n99999 99998\\n\", \"17\\n1 2 4 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\\n\", \"19\\n1 2 3 4 6 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\\n\", \"20\\n1 2 3 4 6 8 16 20 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536\\n\", \"20\\n1 2 3 4 6 8 16 32 64 128 256 512 1024 2048 4096 8192 16384 32768 65536 100000\\n\", \"7\\n7 4096 8192 16384 32768 65536 100000\\n\", \"9\\n7 4096 8192 16384 32768 65536 100000 100000 100000\\n\", \"10\\n7 4096 8192 16384 32768 65536 100000 100000 100000 100000\\n\", \"7\\n99994 99995 99996 99997 99998 99999 100000\\n\", \"16\\n100000 50000 25000 12500 6250 3125 1562 781 390 195 97 48 24 12 6 3\\n\", \"17\\n100000 99999 49999 24999 12499 6249 3124 1562 781 390 195 97 48 24 12 6 3\\n\", \"2\\n99999 100000\\n\", \"1\\n100000\\n\"], \"outputs\": [\"2\", \"5\", \"1\", \"2\", \"72\", \"90\", \"99\", \"113\", \"51\", \"108\", \"136\", \"37\", \"76\", \"87\", \"12\", \"0\"]}", "source": "primeintellect"}
Amr loves Chemistry, and specially doing experiments. He is preparing for a new interesting experiment. Amr has n different types of chemicals. Each chemical i has an initial volume of a_{i} liters. For this experiment, Amr has to mix all the chemicals together, but all the chemicals volumes must be equal first. So his task is to make all the chemicals volumes equal. To do this, Amr can do two different kind of operations. Choose some chemical i and double its current volume so the new volume will be 2a_{i} Choose some chemical i and divide its volume by two (integer division) so the new volume will be $\lfloor \frac{a_{i}}{2} \rfloor$ Suppose that each chemical is contained in a vessel of infinite volume. Now Amr wonders what is the minimum number of operations required to make all the chemicals volumes equal? -----Input----- The first line contains one number n (1 ≤ n ≤ 10^5), the number of chemicals. The second line contains n space separated integers a_{i} (1 ≤ a_{i} ≤ 10^5), representing the initial volume of the i-th chemical in liters. -----Output----- Output one integer the minimum number of operations required to make all the chemicals volumes equal. -----Examples----- Input 3 4 8 2 Output 2 Input 3 3 5 6 Output 5 -----Note----- In the first sample test, the optimal solution is to divide the second chemical volume by two, and multiply the third chemical volume by two to make all the volumes equal 4. In the second sample test, the optimal solution is to divide the first chemical volume by two, and divide the second and the third chemical volumes by two twice to make all the volumes equal 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\": [\"5 4 2 2\\n1 2 3 2 1\\n3 2 1 2 3\\n1 1\\n2 1\\n1 2\\n2 2\\n\", \"4 3 2 200\\n69 70 71 72\\n104 105 106 107\\n1 1\\n2 2\\n1 2\\n\", \"4 3 1 1000000000\\n900000 910000 940000 990000\\n990000 999000 999900 999990\\n1 87654\\n2 76543\\n1 65432\\n\", \"5 5 3 1000000\\n921 853 547 187 164\\n711 462 437 307 246\\n2 94\\n2 230\\n1 373\\n1 476\\n2 880\\n\", \"10 10 10 1000000\\n836 842 645 671 499 554 462 288 89 104\\n880 722 623 651 591 573 154 532 136 59\\n1 47\\n1 169\\n2 486\\n1 262\\n2 752\\n2 498\\n2 863\\n2 616\\n1 791\\n1 656\\n\", \"1 2 2 1000000\\n96\\n262\\n1 699\\n2 699\\n\", \"1 2 2 1000000\\n793\\n33\\n1 733\\n2 406\\n\", \"1 2 2 10000\\n82\\n996\\n2 574\\n2 217\\n\", \"1 2 2 1000000\\n778\\n62\\n2 119\\n2 220\\n\", \"1 2 2 1000000\\n963\\n25\\n2 961\\n1 327\\n\", \"10 20 20 1000000\\n809 909 795 661 635 613 534 199 188 3\\n475 585 428 379 185 177 66 104 15 38\\n2 454\\n1 863\\n2 14\\n2 104\\n1 663\\n2 885\\n1 650\\n1 967\\n2 650\\n2 483\\n2 846\\n1 283\\n1 187\\n2 533\\n2 112\\n2 938\\n2 553\\n1 816\\n1 549\\n2 657\\n\", \"10 20 19 1000000\\n650 996 972 951 904 742 638 93 339 151\\n318 565 849 579 521 965 286 189 196 307\\n2 439\\n1 333\\n2 565\\n1 602\\n2 545\\n2 596\\n2 821\\n2 929\\n1 614\\n2 647\\n2 909\\n1 8\\n2 135\\n1 301\\n1 597\\n1 632\\n1 437\\n2 448\\n2 631\\n2 969\\n\", \"10 20 18 10000\\n916 582 790 449 578 502 411 196 218 144\\n923 696 788 609 455 570 330 435 284 113\\n2 736\\n1 428\\n1 861\\n2 407\\n2 320\\n1 340\\n1 88\\n1 172\\n1 788\\n2 633\\n2 612\\n2 571\\n2 536\\n2 30\\n2 758\\n2 90\\n2 8\\n1 970\\n1 20\\n1 22\\n\", \"10 20 16 1000000\\n317 880 696 304 260 180 214 245 79 37\\n866 621 940 89 718 674 195 267 12 49\\n2 825\\n2 197\\n1 657\\n1 231\\n1 728\\n2 771\\n2 330\\n2 943\\n1 60\\n1 89\\n2 721\\n2 959\\n1 926\\n2 215\\n1 583\\n2 680\\n1 799\\n2 887\\n1 709\\n1 316\\n\", \"10 20 20 10000\\n913 860 844 775 297 263 247 71 50 6\\n971 938 890 854 643 633 427 418 190 183\\n1 556\\n2 579\\n1 315\\n2 446\\n1 327\\n1 724\\n2 12\\n1 142\\n1 627\\n1 262\\n1 681\\n1 802\\n1 886\\n1 350\\n2 383\\n1 191\\n1 717\\n1 968\\n2 588\\n1 57\\n\", \"1 93 46 46\\n1\\n1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n2 1\\n1 2\\n\"], \"outputs\": [\"3\\n1 1\\n2 3\\n\", \"-1\\n\", \"-1\\n\", \"1\\n1 1\\n2 1\\n5 1\\n\", \"9\\n1 9\\n2 9\\n4 9\\n10 9\\n9 9\\n3 9\\n6 9\\n8 9\\n5 9\\n7 9\\n\", \"1\\n1 1\\n2 1\\n\", \"1\\n1 1\\n2 1\\n\", \"-1\\n\", \"1\\n1 1\\n2 1\\n\", \"1\\n2 1\\n1 1\\n\", \"10\\n13 10\\n12 10\\n19 10\\n7 10\\n5 10\\n18 10\\n2 10\\n8 10\\n3 9\\n4 9\\n15 9\\n1 9\\n10 9\\n14 9\\n17 9\\n9 9\\n20 9\\n11 9\\n6 9\\n16 9\\n\", \"-1\\n\", \"-1\\n\", \"6\\n9 6\\n10 6\\n4 6\\n20 6\\n15 6\\n3 6\\n2 4\\n14 4\\n7 4\\n16 4\\n11 4\\n6 4\\n1 4\\n18 4\\n8 4\\n12 4\\n\", \"-1\\n\", \"1\\n2 1\\n4 1\\n6 1\\n8 1\\n10 1\\n12 1\\n14 1\\n16 1\\n18 1\\n20 1\\n22 1\\n24 1\\n26 1\\n28 1\\n30 1\\n32 1\\n34 1\\n36 1\\n38 1\\n40 1\\n42 1\\n44 1\\n46 1\\n48 1\\n50 1\\n52 1\\n54 1\\n56 1\\n58 1\\n60 1\\n62 1\\n64 1\\n66 1\\n68 1\\n70 1\\n72 1\\n74 1\\n76 1\\n78 1\\n80 1\\n82 1\\n84 1\\n86 1\\n88 1\\n90 1\\n92 1\\n\"]}", "source": "primeintellect"}
Nura wants to buy k gadgets. She has only s burles for that. She can buy each gadget for dollars or for pounds. So each gadget is selling only for some type of currency. The type of currency and the cost in that currency are not changing. Nura can buy gadgets for n days. For each day you know the exchange rates of dollar and pound, so you know the cost of conversion burles to dollars or to pounds. Each day (from 1 to n) Nura can buy some gadgets by current exchange rate. Each day she can buy any gadgets she wants, but each gadget can be bought no more than once during n days. Help Nura to find the minimum day index when she will have k gadgets. Nura always pays with burles, which are converted according to the exchange rate of the purchase day. Nura can't buy dollars or pounds, she always stores only burles. Gadgets are numbered with integers from 1 to m in order of their appearing in input. -----Input----- First line contains four integers n, m, k, s (1 ≤ n ≤ 2·10^5, 1 ≤ k ≤ m ≤ 2·10^5, 1 ≤ s ≤ 10^9) — number of days, total number and required number of gadgets, number of burles Nura has. Second line contains n integers a_{i} (1 ≤ a_{i} ≤ 10^6) — the cost of one dollar in burles on i-th day. Third line contains n integers b_{i} (1 ≤ b_{i} ≤ 10^6) — the cost of one pound in burles on i-th day. Each of the next m lines contains two integers t_{i}, c_{i} (1 ≤ t_{i} ≤ 2, 1 ≤ c_{i} ≤ 10^6) — type of the gadget and it's cost. For the gadgets of the first type cost is specified in dollars. For the gadgets of the second type cost is specified in pounds. -----Output----- If Nura can't buy k gadgets print the only line with the number -1. Otherwise the first line should contain integer d — the minimum day index, when Nura will have k gadgets. On each of the next k lines print two integers q_{i}, d_{i} — the number of gadget and the day gadget should be bought. All values q_{i} should be different, but the values d_{i} can coincide (so Nura can buy several gadgets at one day). The days are numbered from 1 to n. In case there are multiple possible solutions, print any of them. -----Examples----- Input 5 4 2 2 1 2 3 2 1 3 2 1 2 3 1 1 2 1 1 2 2 2 Output 3 1 1 2 3 Input 4 3 2 200 69 70 71 72 104 105 106 107 1 1 2 2 1 2 Output -1 Input 4 3 1 1000000000 900000 910000 940000 990000 990000 999000 999900 999990 1 87654 2 76543 1 65432 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\": [\"3\\n3 5\\n1 2\\n3 4\\n2 1000000000\\n1 1\\n999999999 999999999\\n10 3\\n5 10\\n7 8\\n\", \"1\\n200000 88635750\\n4971058 40181766\\n6012372 78925196\\n\", \"1\\n200000 598920770\\n24529366 24846325\\n35694819 90253337\\n\", \"1\\n1 1\\n1 1\\n1 1\\n\", \"1\\n4 9\\n4 10\\n5 5\\n\", \"1\\n1 1\\n3 3\\n1 1\\n\", \"1\\n3 100\\n1 1\\n1 1\\n\", \"1\\n1 100\\n1 1\\n1 1\\n\", \"1\\n1 6\\n5 9\\n5 9\\n\", \"1\\n2 10\\n1 1\\n1 1\\n\", \"1\\n1 2\\n1 2\\n1 2\\n\", \"1\\n2 10\\n1 5\\n3 3\\n\", \"1\\n11 111\\n4 4\\n4 4\\n\", \"1\\n4 52\\n3 5\\n3 5\\n\", \"1\\n10 10\\n1 1\\n1 1\\n\", \"2\\n3 5\\n1 2\\n1 2\\n3 5\\n1 1\\n1 1\\n\"], \"outputs\": [\"7\\n2000000000\\n0\\n\", \"0\\n\", \"703962247\\n\", \"2\\n\", \"9\\n\", \"3\\n\", \"200\\n\", \"200\\n\", \"4\\n\", \"20\\n\", \"2\\n\", \"12\\n\", \"222\\n\", \"88\\n\", \"20\\n\", \"4\\n10\\n\"]}", "source": "primeintellect"}
You are given two lists of segments $[al_1, ar_1], [al_2, ar_2], \dots, [al_n, ar_n]$ and $[bl_1, br_1], [bl_2, br_2], \dots, [bl_n, br_n]$. Initially, all segments $[al_i, ar_i]$ are equal to $[l_1, r_1]$ and all segments $[bl_i, br_i]$ are equal to $[l_2, r_2]$. In one step, you can choose one segment (either from the first or from the second list) and extend it by $1$. In other words, suppose you've chosen segment $[x, y]$ then you can transform it either into $[x - 1, y]$ or into $[x, y + 1]$. Let's define a total intersection $I$ as the sum of lengths of intersections of the corresponding pairs of segments, i.e. $\sum\limits_{i=1}^{n}{\text{intersection_length}([al_i, ar_i], [bl_i, br_i])}$. Empty intersection has length $0$ and length of a segment $[x, y]$ is equal to $y - x$. What is the minimum number of steps you need to make $I$ greater or equal to $k$? -----Input----- The first line contains the single integer $t$ ($1 \le t \le 1000$) — the number of test cases. The first line of each test case contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$; $1 \le k \le 10^9$) — the length of lists and the minimum required total intersection. The second line of each test case contains two integers $l_1$ and $r_1$ ($1 \le l_1 \le r_1 \le 10^9$) — the segment all $[al_i, ar_i]$ are equal to initially. The third line of each test case contains two integers $l_2$ and $r_2$ ($1 \le l_2 \le r_2 \le 10^9$) — the segment all $[bl_i, br_i]$ are equal to initially. It's guaranteed that the sum of $n$ doesn't exceed $2 \cdot 10^5$. -----Output----- Print $t$ integers — one per test case. For each test case, print the minimum number of step you need to make $I$ greater or equal to $k$. -----Example----- Input 3 3 5 1 2 3 4 2 1000000000 1 1 999999999 999999999 10 3 5 10 7 8 Output 7 2000000000 0 -----Note----- In the first test case, we can achieve total intersection $5$, for example, using next strategy: make $[al_1, ar_1]$ from $[1, 2]$ to $[1, 4]$ in $2$ steps; make $[al_2, ar_2]$ from $[1, 2]$ to $[1, 3]$ in $1$ step; make $[bl_1, br_1]$ from $[3, 4]$ to $[1, 4]$ in $2$ steps; make $[bl_2, br_2]$ from $[3, 4]$ to $[1, 4]$ in $2$ steps. In result, $I = \text{intersection_length}([al_1, ar_1], [bl_1, br_1]) + \text{intersection_length}([al_2, ar_2], [bl_2, br_2]) + \\ + \text{intersection_length}([al_3, ar_3], [bl_3, br_3]) = 3 + 2 + 0 = 5$ In the second test case, we can make $[al_1, ar_1] = [0, 1000000000]$ in $1000000000$ steps and $[bl_1, br_1] = [0, 1000000000]$ in $1000000000$ steps. In the third test case, the total intersection $I$ is already equal to $10 > 3$, so we don't need to do any steps. 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 8 0 2 8 3 4 5\\n\", \"10 10 7 0 5 8 2 11\\n\", \"10 10 0 7 5 8 2 11\\n\", \"10 10 -7 0 5 8 2 11\\n\", \"10 10 0 -7 5 8 2 11\\n\", \"10 10 7 7 5 8 2 11\\n\", \"10 10 7 -7 5 8 2 11\\n\", \"10 10 -7 7 5 8 2 11\\n\", \"10 10 -7 -7 5 8 2 11\\n\", \"669 649 952 535 380 408 58 532\\n\", \"90 798 425 372 244 996 169 253\\n\", \"403 24 708 984 850 765 344 865\\n\", \"767 238 263 303 155 351 21 686\\n\", \"380 171 865 522 392 242 71 774\\n\", \"254 578 251 809 412 966 92 984\\n\", \"870 396 187 223 444 202 222 732\\n\"], \"outputs\": [\"8.000000000000 11.000000000000\\n4.000000000000 8.000000000000\\n6.000000000000 8.000000000000\\n6.000000000000 3.000000000000\\n10.000000000000 3.000000000000\\n10.000000000000 8.000000000000\\n12.000000000000 8.000000000000\\n\", \"18.000000000000 10.000000000000\\n10.000000000000 12.500000000000\\n10.000000000000 11.000000000000\\n-1.000000000000 11.000000000000\\n-1.000000000000 9.000000000000\\n10.000000000000 9.000000000000\\n10.000000000000 7.500000000000\\n\", \"10.000000000000 18.000000000000\\n7.500000000000 10.000000000000\\n9.000000000000 10.000000000000\\n9.000000000000 -1.000000000000\\n11.000000000000 -1.000000000000\\n11.000000000000 10.000000000000\\n12.500000000000 10.000000000000\\n\", \"2.000000000000 10.000000000000\\n10.000000000000 7.500000000000\\n10.000000000000 9.000000000000\\n21.000000000000 9.000000000000\\n21.000000000000 11.000000000000\\n10.000000000000 11.000000000000\\n10.000000000000 12.500000000000\\n\", \"10.000000000000 2.000000000000\\n12.500000000000 10.000000000000\\n11.000000000000 10.000000000000\\n11.000000000000 21.000000000000\\n9.000000000000 21.000000000000\\n9.000000000000 10.000000000000\\n7.500000000000 10.000000000000\\n\", \"15.656854249492 15.656854249492\\n8.232233047034 11.767766952966\\n9.292893218813 10.707106781187\\n1.514718625761 2.928932188135\\n2.928932188135 1.514718625761\\n10.707106781187 9.292893218813\\n11.767766952966 8.232233047034\\n\", \"15.656854249492 4.343145750508\\n11.767766952966 11.767766952966\\n10.707106781187 10.707106781187\\n2.928932188135 18.485281374239\\n1.514718625761 17.071067811865\\n9.292893218813 9.292893218813\\n8.232233047034 8.232233047034\\n\", \"4.343145750508 15.656854249492\\n8.232233047034 8.232233047034\\n9.292893218813 9.292893218813\\n17.071067811865 1.514718625761\\n18.485281374239 2.928932188135\\n10.707106781187 10.707106781187\\n11.767766952966 11.767766952966\\n\", \"4.343145750508 4.343145750508\\n11.767766952966 8.232233047034\\n10.707106781187 9.292893218813\\n18.485281374239 17.071067811865\\n17.071067811865 18.485281374239\\n9.292893218813 10.707106781187\\n8.232233047034 11.767766952966\\n\", \"1024.682613875615 848.884662209511\\n575.916456324002 814.636511363644\\n654.792511754716 674.281362260767\\n191.010279936512 413.647439967974\\n219.425256427080 363.084715446440\\n683.207488245284 623.718637739233\\n762.083543675998 483.363488636356\\n\", \"839.457138593842 1453.995424839786\\n9.647146756572 889.800974807679\\n34.345769679757 861.583462059417\\n-156.028382995185 694.950086070998\\n-44.719922354699 567.783161952163\\n145.654230320243 734.416537940583\\n170.352853243428 706.199025192321\\n\", \"849.793598704384 644.967374470500\\n58.018125294167 272.218665946880\\n263.383806001404 124.455554218502\\n-241.814184690481 -577.684026065135\\n37.418203306711 -778.595134502139\\n542.616193998596 -76.455554218502\\n747.981874705833 -224.218665946880\\n\", \"997.080388094088 503.073603013340\\n708.472352611015 288.801225291430\\n759.070447773105 244.882746652387\\n309.397666483806 -273.181332171406\\n325.256770937595 -286.946825476181\\n774.929552226895 231.117253347613\\n825.527647388985 187.198774708570\\n\", \"587.195587057422 296.035949646213\\n278.731214336125 338.811301914276\\n361.657949535370 201.394393969167\\n-301.025457003657 -198.513973907563\\n-264.341356074397 -259.302761845898\\n398.342050464630 140.605606030833\\n481.268785663875 3.188698085724\\n\", \"540.249899491702 1500.614217883613\\n57.252040492729 639.042939229079\\n210.065989624590 591.630947594843\\n-81.517758925964 -348.174839566104\\n6.350261824857 -375.436734755790\\n297.934010375410 564.369052405157\\n450.747959507271 516.957060770921\\n\", \"999.794532443395 550.781715159771\\n699.893362547183 538.645476249672\\n784.946681273591 467.322738124836\\n314.602137963862 -93.569417800670\\n484.708775416679 -236.214894050342\\n955.053318726409 324.677261875164\\n1040.106637452818 253.354523750328\\n\"]}", "source": "primeintellect"}
Petya has recently started working as a programmer in the IT city company that develops computer games. Besides game mechanics implementation to create a game it is necessary to create tool programs that can be used by game designers to create game levels. Petya's first assignment is to create a tool that allows to paint different arrows on the screen. A user of this tool will choose a point on the screen, specify a vector (the arrow direction) and vary several parameters to get the required graphical effect. In the first version of the program Petya decided to limit parameters of the arrow by the following: a point with coordinates (px, py), a nonzero vector with coordinates (vx, vy), positive scalars a, b, c, d, a > c. The produced arrow should have the following properties. The arrow consists of a triangle and a rectangle. The triangle is isosceles with base of length a and altitude of length b perpendicular to the base. The rectangle sides lengths are c and d. Point (px, py) is situated in the middle of the triangle base and in the middle of side of rectangle that has length c. Area of intersection of the triangle and the rectangle is zero. The direction from (px, py) point to the triangle vertex opposite to base containing the point coincides with direction of (vx, vy) vector. Enumerate the arrow points coordinates in counter-clockwise order starting from the tip. [Image] -----Input----- The only line of the input contains eight integers px, py, vx, vy ( - 1000 ≤ px, py, vx, vy ≤ 1000, vx^2 + vy^2 > 0), a, b, c, d (1 ≤ a, b, c, d ≤ 1000, a > c). -----Output----- Output coordinates of the arrow points in counter-clockwise order. Each line should contain two coordinates, first x, then y. Relative or absolute error should not be greater than 10^{ - 9}. -----Examples----- Input 8 8 0 2 8 3 4 5 Output 8.000000000000 11.000000000000 4.000000000000 8.000000000000 6.000000000000 8.000000000000 6.000000000000 3.000000000000 10.000000000000 3.000000000000 10.000000000000 8.000000000000 12.000000000000 8.000000000000 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 1\\nAABBB\\n\", \"5 1\\nABABB\\n\", \"26 1\\nABCDEFGHIJKLMNOPQRSTUVWXYZ\\n\", \"27 1\\nABCDEFGHIJKLMNOPQRSTUVWXYZA\\n\", \"5 2\\nABACA\\n\", \"6 2\\nABCABC\\n\", \"8 3\\nABCBCDCA\\n\", \"73 2\\nDEBECECBBADAADEAABEAEEEAEBEAEBCDDBABBAEBACCBEEBBAEADEECACEDEEDABACDCDBBBD\\n\", \"44 15\\nHGJIFCGGCDGIJDHBIBGAEABCIABIGBDEADBBBAGDFDHA\\n\", \"41 19\\nTMEYYIIELFDCMBDKWWKYNRNDUPRONYROXQCLVQALP\\n\", \"377 3\\nEADADBBBBDEAABBAEBABACDBDBBCACAADBEAEACDEAABACADEEDEACACDADABBBBDDEECBDABACACBAECBADAEBDEEBDBCDAEADBCDDACACDCCEEDBCCBBCEDBECBABCDDBBDEADEDAEACDECECBEBACBCCDCDBDAECDECADBCBEDBBDAAEBCAAECCDCCDBDDEBADEEBDCAEABBDEDBBDDEAECCBDDCDEACDAECCBDDABABEAEDCDEDBAECBDEACEBCECEACDCBABCBAAEAADACADBBBBABEADBCADEBCBECCABBDDDEEBCDEBADEBDAAABBEABADEDEAEABCEEBEEDEAEBEABCEDDBACBCCADEBAAAAAEABABBCE\\n\", \"433 3\\nFZDDHMJGBZCHFUXBBPIEBBEFDWOMXXEPOMDGSMPIUZOMRZQNSJAVNATGIWPDFISKFQXJNVFXPHOZDAEZFDAHDXXQKZMGNSGKQNWGNGJGJZVVITKNFLVCPMZSDMCHBTVAWYVZLIXXIADXNYILEYNIQHKMOGMVOCWGHCWIYMPEPADSJAAKEGTUSEDWAHMNYJDIHBKHVUHLYGNGZDBULRXLSAJHPCMNWCEAAPYMHDTYWPADOTJTXTXUKLCHWKUSZRHEKQEFPVJEJJHRWCKYOIWALRTIBUMNOCRXLSIKQCJVQXEPGOHRUDJDKMUUUDORURWXJNVRVMNOUNRFKSVMTMZGOIJLXEPAMVGESOADYIGZXRBJDIWKNOWTCSROAQTBECHTOZVSQUOOJRZIBAUHMKAXDCIMDZJFMABGRNTGPUJAUNFPFWCJG\\n\", \"5 2\\nABCAB\\n\", \"5 1\\nAZAZA\\n\", \"7 2\\nABCDBCD\\n\", \"3 26\\nAAB\\n\"], \"outputs\": [\"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\"]}", "source": "primeintellect"}
[Image] It's the end of July – the time when a festive evening is held at Jelly Castle! Guests from all over the kingdom gather here to discuss new trends in the world of confectionery. Yet some of the things discussed here are not supposed to be disclosed to the general public: the information can cause discord in the kingdom of Sweetland in case it turns out to reach the wrong hands. So it's a necessity to not let any uninvited guests in. There are 26 entrances in Jelly Castle, enumerated with uppercase English letters from A to Z. Because of security measures, each guest is known to be assigned an entrance he should enter the castle through. The door of each entrance is opened right before the first guest's arrival and closed right after the arrival of the last guest that should enter the castle through this entrance. No two guests can enter the castle simultaneously. For an entrance to be protected from possible intrusion, a candy guard should be assigned to it. There are k such guards in the castle, so if there are more than k opened doors, one of them is going to be left unguarded! Notice that a guard can't leave his post until the door he is assigned to is closed. Slastyona had a suspicion that there could be uninvited guests at the evening. She knows the order in which the invited guests entered the castle, and wants you to help her check whether there was a moment when more than k doors were opened. -----Input----- Two integers are given in the first string: the number of guests n and the number of guards k (1 ≤ n ≤ 10^6, 1 ≤ k ≤ 26). In the second string, n uppercase English letters s_1s_2... s_{n} are given, where s_{i} is the entrance used by the i-th guest. -----Output----- Output «YES» if at least one door was unguarded during some time, and «NO» otherwise. You can output each letter in arbitrary case (upper or lower). -----Examples----- Input 5 1 AABBB Output NO Input 5 1 ABABB Output YES -----Note----- In the first sample case, the door A is opened right before the first guest's arrival and closed when the second guest enters the castle. The door B is opened right before the arrival of the third guest, and closed after the fifth one arrives. One guard can handle both doors, as the first one is closed before the second one is opened. In the second sample case, the door B is opened before the second guest's arrival, but the only guard can't leave the door A unattended, as there is still one more guest that should enter the castle through this door. 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.5
{"tests": "{\"inputs\": [\"5\\n4 5 3 5\\n6 7 4 6\\n\", \"3\\n2 4\\n3 2\\n\", \"8\\n2 3 1 1 2 4 3\\n3 4 4 2 5 5 4\\n\", \"2\\n1\\n1000000000\\n\", \"10\\n1 1 1 3 2 1 1 2 1\\n3 2 3 3 3 2 3 3 3\\n\", \"10\\n1 1 4 2 2 1 7 6 7\\n8 9 7 4 6 3 8 7 9\\n\", \"20\\n2 3 2 6 1 1 2 5 2 3 3 1 2 2 3 2 6 1 3\\n2 7 3 6 5 7 3 5 3 6 7 7 7 9 5 2 7 2 9\\n\", \"20\\n10 10 8 9 7 4 9 9 8 9 12 1 1 10 19 5 17 5 9\\n13 19 9 19 9 12 19 19 19 9 19 4 13 10 19 19 19 7 10\\n\", \"30\\n13 1 11 2 1 1 6 2 12 1 6 5 6 1 1 1 6 6 6 12 1 5 3 8 1 4 6 3 2\\n14 6 14 6 12 4 6 5 14 13 6 8 7 7 6 2 10 10 14 13 12 13 14 14 6 13 13 5 11\\n\", \"30\\n12 3 2 20 12 78 2 25 12 12 31 19 56 34 9 25 20 31 2 12 24 8 6 19 21 89 6 7 2\\n85 9 12 70 97 93 6 51 24 19 95 51 95 56 21 34 37 37 6 89 78 89 7 85 97 93 89 8 70\\n\", \"10\\n2 2 1 1 3 2 1 4 2\\n3 2 1 3 4 3 2 4 4\\n\", \"10\\n5 32 2 2 15 10 5 20 20\\n10 48 11 15 20 34 11 20 48\\n\", \"20\\n1 3 2 5 2 1 3 2 3 2 3 1 2 1 3 3 5 5 3\\n2 5 4 5 5 3 3 3 4 5 3 5 5 5 3 5 5 5 5\\n\", \"20\\n22 10 1 38 8 7 47 13 1 18 7 6 6 20 20 23 7 8 20\\n49 20 18 48 13 43 47 26 34 48 34 43 22 49 26 47 38 23 47\\n\", \"30\\n14 20 2 18 17 14 13 2 2 12 9 2 9 15 26 11 20 23 6 9 22 1 6 19 17 1 9 15 15\\n23 27 15 20 29 22 25 11 26 14 27 19 15 29 27 29 23 27 13 29 26 15 21 23 26 14 25 21 18\\n\", \"30\\n5 3 3 3 2 2 5 1 3 5 5 1 5 1 5 1 4 7 5 7 2 2 3 7 2 2 5 3 3\\n7 5 7 4 7 6 5 4 7 10 7 10 7 7 5 4 7 7 9 9 7 6 9 10 5 6 9 6 7\\n\"], \"outputs\": [\"3 4 6 5 7 \\n\", \"-1\\n\", \"3 4 5 2 1 4 3 2 \\n\", \"1000000000 1 \\n\", \"1 3 2 1 3 3 2 1 3 1 \\n\", \"3 1 9 7 6 2 4 7 8 1 \\n\", \"2 2 1 7 2 9 3 7 6 6 3 2 3 5 5 1 7 3 2 2 \\n\", \"17 19 19 9 9 19 5 7 9 19 8 9 10 10 19 12 4 1 13 10 \\n\", \"6 13 5 3 14 6 10 6 1 6 6 6 7 1 12 13 4 1 2 11 14 12 1 13 14 8 5 2 6 1 \\n\", \"19 51 25 34 56 95 31 37 20 70 2 6 89 93 78 24 12 89 8 7 6 2 12 19 85 12 97 21 9 3 \\n\", \"2 4 4 3 2 2 1 1 3 2 \\n\", \"34 10 5 11 2 15 20 20 48 32 \\n\", \"1 5 5 5 3 3 3 3 5 2 5 1 3 2 5 5 3 4 2 1 \\n\", \"7 38 48 18 1 34 7 43 6 22 49 20 47 47 23 8 13 26 20 10 \\n\", \"12 14 1 15 21 6 13 25 9 29 15 18 20 23 27 26 22 14 23 19 2 26 17 29 11 2 15 9 27 20 \\n\", \"10 7 3 6 2 5 5 9 7 7 4 1 7 5 9 3 7 2 6 2 7 5 5 10 1 4 3 7 5 3 \\n\"]}", "source": "primeintellect"}
A permutation of length $k$ is a sequence of $k$ integers from $1$ to $k$ containing each integer exactly once. For example, the sequence $[3, 1, 2]$ is a permutation of length $3$. When Neko was five, he thought of an array $a$ of $n$ positive integers and a permutation $p$ of length $n - 1$. Then, he performed the following: Constructed an array $b$ of length $n-1$, where $b_i = \min(a_i, a_{i+1})$. Constructed an array $c$ of length $n-1$, where $c_i = \max(a_i, a_{i+1})$. Constructed an array $b'$ of length $n-1$, where $b'_i = b_{p_i}$. Constructed an array $c'$ of length $n-1$, where $c'_i = c_{p_i}$. For example, if the array $a$ was $[3, 4, 6, 5, 7]$ and permutation $p$ was $[2, 4, 1, 3]$, then Neko would have constructed the following arrays: $b = [3, 4, 5, 5]$ $c = [4, 6, 6, 7]$ $b' = [4, 5, 3, 5]$ $c' = [6, 7, 4, 6]$ Then, he wrote two arrays $b'$ and $c'$ on a piece of paper and forgot about it. 14 years later, when he was cleaning up his room, he discovered this old piece of paper with two arrays $b'$ and $c'$ written on it. However he can't remember the array $a$ and permutation $p$ he used. In case Neko made a mistake and there is no array $a$ and permutation $p$ resulting in such $b'$ and $c'$, print -1. Otherwise, help him recover any possible array $a$. -----Input----- The first line contains an integer $n$ ($2 \leq n \leq 10^5$) — the number of elements in array $a$. The second line contains $n-1$ integers $b'_1, b'_2, \ldots, b'_{n-1}$ ($1 \leq b'_i \leq 10^9$). The third line contains $n-1$ integers $c'_1, c'_2, \ldots, c'_{n-1}$ ($1 \leq c'_i \leq 10^9$). -----Output----- If Neko made a mistake and there is no array $a$ and a permutation $p$ leading to the $b'$ and $c'$, print -1. Otherwise, print $n$ positive integers $a_i$ ($1 \le a_i \le 10^9$), denoting the elements of the array $a$. If there are multiple possible solutions, print any of them. -----Examples----- Input 5 4 5 3 5 6 7 4 6 Output 3 4 6 5 7 Input 3 2 4 3 2 Output -1 Input 8 2 3 1 1 2 4 3 3 4 4 2 5 5 4 Output 3 4 5 2 1 4 3 2 -----Note----- The first example is explained is the problem statement. In the third example, for $a = [3, 4, 5, 2, 1, 4, 3, 2]$, a possible permutation $p$ is $[7, 1, 5, 4, 3, 2, 6]$. In that case, Neko would have constructed the following arrays: $b = [3, 4, 2, 1, 1, 3, 2]$ $c = [4, 5, 5, 2, 4, 4, 3]$ $b' = [2, 3, 1, 1, 2, 4, 3]$ $c' = [3, 4, 4, 2, 5, 5, 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\": [\"3\\n\", \"5\\n\", \"13\\n\", \"1\\n\", \"2\\n\", \"4\\n\", \"6\\n\", \"15\\n\", \"16\\n\", \"7\\n\", \"8\\n\", \"9\\n\", \"10\\n\", \"11\\n\", \"12\\n\", \"14\\n\"], \"outputs\": [\"18\\n\", \"1800\\n\", \"695720788\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"150347555\\n\", \"0\\n\", \"670320\\n\", \"0\\n\", \"734832000\\n\", \"0\\n\", \"890786230\\n\", \"0\\n\", \"0\\n\"]}", "source": "primeintellect"}
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1, p_2, ..., p_{n}. Petya decided to introduce the sum operation on the set of permutations of length n. Let's assume that we are given two permutations of length n: a_1, a_2, ..., a_{n} and b_1, b_2, ..., b_{n}. Petya calls the sum of permutations a and b such permutation c of length n, where c_{i} = ((a_{i} - 1 + b_{i} - 1) mod n) + 1 (1 ≤ i ≤ n). Operation $x \text{mod} y$ means taking the remainder after dividing number x by number y. Obviously, not for all permutations a and b exists permutation c that is sum of a and b. That's why Petya got sad and asked you to do the following: given n, count the number of such pairs of permutations a and b of length n, that exists permutation c that is sum of a and b. The pair of permutations x, y (x ≠ y) and the pair of permutations y, x are considered distinct pairs. As the answer can be rather large, print the remainder after dividing it by 1000000007 (10^9 + 7). -----Input----- The single line contains integer n (1 ≤ n ≤ 16). -----Output----- In the single line print a single non-negative integer — the number of such pairs of permutations a and b, that exists permutation c that is sum of a and b, modulo 1000000007 (10^9 + 7). -----Examples----- Input 3 Output 18 Input 5 Output 1800 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\\naAbB\\n\", \"4\\naBaCaB\\n\", \"5\\nxYyXzZaZ\\n\", \"26\\naAbBcCdDeEfFgGhHiIjJkKlLmMnNoOpPqQrRsStTuUvVwWxXyY\\n\", \"26\\nzAyBxCwDvEuFtGsHrIqJpKoLnMmNlOkPjQiRhSgTfUeVdWcXbY\\n\", \"5\\naArRaRaR\\n\", \"2\\ndA\\n\", \"2\\ncB\\n\", \"10\\nhNcMeXsSlHsUwYeMcA\\n\", \"100\\nqDpInBmCrFwXpDbFgOzVvOcEmJrUcToAdEwEgTvBvBfWwRpGyEaXgDdRwVlQnYgWmWhMrHaIzPyXvGaFlRsVzHhZrOuVpXrKxFzAmWwPlFtNfPtJxVmLuHjKfYyArHrEnSwSzOvDpQhCgCqLlAcNpGhXrEeFuCmAqIkXyYtSsQwIxJzNiIuTgEbVuWrMwPrAlLyKaZ\\n\", \"2\\ndD\\n\", \"2\\ndE\\n\", \"3\\ndDdD\\n\", \"3\\ndEdD\\n\", \"3\\ndEeD\\n\", \"3\\ndEeF\\n\"], \"outputs\": [\"0\\n\", \"3\\n\", \"2\\n\", \"0\\n\", \"13\\n\", \"2\\n\", \"1\\n\", \"1\\n\", \"7\\n\", \"42\\n\", \"0\\n\", \"1\\n\", \"0\\n\", \"1\\n\", \"1\\n\", \"2\\n\"]}", "source": "primeintellect"}
After a hard day Vitaly got very hungry and he wants to eat his favorite potato pie. But it's not that simple. Vitaly is in the first room of the house with n room located in a line and numbered starting from one from left to right. You can go from the first room to the second room, from the second room to the third room and so on — you can go from the (n - 1)-th room to the n-th room. Thus, you can go to room x only from room x - 1. The potato pie is located in the n-th room and Vitaly needs to go there. Each pair of consecutive rooms has a door between them. In order to go to room x from room x - 1, you need to open the door between the rooms with the corresponding key. In total the house has several types of doors (represented by uppercase Latin letters) and several types of keys (represented by lowercase Latin letters). The key of type t can open the door of type T if and only if t and T are the same letter, written in different cases. For example, key f can open door F. Each of the first n - 1 rooms contains exactly one key of some type that Vitaly can use to get to next rooms. Once the door is open with some key, Vitaly won't get the key from the keyhole but he will immediately run into the next room. In other words, each key can open no more than one door. Vitaly realizes that he may end up in some room without the key that opens the door to the next room. Before the start his run for the potato pie Vitaly can buy any number of keys of any type that is guaranteed to get to room n. Given the plan of the house, Vitaly wants to know what is the minimum number of keys he needs to buy to surely get to the room n, which has a delicious potato pie. Write a program that will help Vitaly find out this number. -----Input----- The first line of the input contains a positive integer n (2 ≤ n ≤ 10^5) — the number of rooms in the house. The second line of the input contains string s of length 2·n - 2. Let's number the elements of the string from left to right, starting from one. The odd positions in the given string s contain lowercase Latin letters — the types of the keys that lie in the corresponding rooms. Thus, each odd position i of the given string s contains a lowercase Latin letter — the type of the key that lies in room number (i + 1) / 2. The even positions in the given string contain uppercase Latin letters — the types of doors between the rooms. Thus, each even position i of the given string s contains an uppercase letter — the type of the door that leads from room i / 2 to room i / 2 + 1. -----Output----- Print the only integer — the minimum number of keys that Vitaly needs to buy to surely get from room one to room n. -----Examples----- Input 3 aAbB Output 0 Input 4 aBaCaB Output 3 Input 5 xYyXzZaZ 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\": [\"5\\n1 2 3 1 2\\n\", \"5\\n1 -2 3 1 -2\\n\", \"2\\n0 0\\n\", \"3\\n0 -1 0\\n\", \"3\\n1 1 1\\n\", \"4\\n-1 1 1 -1\\n\", \"4\\n-1 1 -1 1\\n\", \"2\\n-1 -1\\n\", \"3\\n-1 0 -1\\n\", \"6\\n-1 3 3 5 5 -1\\n\", \"2\\n-1000000000 -1000000000\\n\", \"3\\n-1000000000 -1000000000 -1000000000\\n\", \"3\\n1000000000 1000000000 1000000000\\n\", \"10\\n-589330597 -126288833 -126288833 -834860352 -834860352 -834860352 -834860352 -21170405 -834860352 -834860352\\n\", \"20\\n-808998072 733614990 579897311 -337992089 579897311 120800519 -337992089 -803027570 733614990 -686536765 733614990 -803027570 -803027570 733614990 120800519 -803027570 -686536765 579897311 -808998072 -686536765\\n\"], \"outputs\": [\"8 1\\n1 \", \"5 2\\n2 5 \", \"0 0\\n\", \"0 1\\n2 \", \"3 0\\n\", \"2 2\\n1 4 \", \"2 2\\n1 3 \", \"-2 0\\n\", \"-2 0\\n\", \"14 0\\n\", \"-2000000000 0\\n\", \"-2000000000 1\\n3 \", \"3000000000 0\\n\", \"-252577666 8\\n1 4 5 6 7 8 9 10 \", \"4215055101 13\\n1 4 7 8 10 12 13 15 16 17 18 19 20 \"]}", "source": "primeintellect"}
— Oh my sweet Beaverette, would you fancy a walk along a wonderful woodland belt with me? — Of course, my Smart Beaver! Let us enjoy the splendid view together. How about Friday night? At this point the Smart Beaver got rushing. Everything should be perfect by Friday, so he needed to prepare the belt to the upcoming walk. He needed to cut down several trees. Let's consider the woodland belt as a sequence of trees. Each tree i is described by the esthetic appeal a_{i} — some trees are very esthetically pleasing, others are 'so-so', and some trees are positively ugly! The Smart Beaver calculated that he needed the following effects to win the Beaverette's heart: The first objective is to please the Beaverette: the sum of esthetic appeal of the remaining trees must be maximum possible; the second objective is to surprise the Beaverette: the esthetic appeal of the first and the last trees in the resulting belt must be the same; and of course, the walk should be successful: there must be at least two trees in the woodland belt left. Now help the Smart Beaver! Which trees does he need to cut down to win the Beaverette's heart? -----Input----- The first line contains a single integer n — the initial number of trees in the woodland belt, 2 ≤ n. The second line contains space-separated integers a_{i} — the esthetic appeals of each tree. All esthetic appeals do not exceed 10^9 in their absolute value. to get 30 points, you need to solve the problem with constraints: n ≤ 100 (subproblem A1); to get 100 points, you need to solve the problem with constraints: n ≤ 3·10^5 (subproblems A1+A2). -----Output----- In the first line print two integers — the total esthetic appeal of the woodland belt after the Smart Beaver's intervention and the number of the cut down trees k. In the next line print k integers — the numbers of the trees the Beaver needs to cut down. Assume that the trees are numbered from 1 to n from left to right. If there are multiple solutions, print any of them. It is guaranteed that at least two trees have equal esthetic appeal. -----Examples----- Input 5 1 2 3 1 2 Output 8 1 1 Input 5 1 -2 3 1 -2 Output 5 2 2 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\": [\"2\\n\", \"3\\n\", \"4\\n\", \"5\\n\", \"6\\n\", \"50\\n\", \"51\\n\", \"52\\n\", \"53\\n\", \"54\\n\", \"100\\n\", \"101\\n\", \"102\\n\", \"103\\n\", \"104\\n\"], \"outputs\": [\"1 \", \"1 1 \", \"1 1 2 \", \"1 1 1 2 \", \"1 1 1 2 3 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 12 13 13 14 15 15 16 17 18 19 20 21 22 23 24 25 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 12 13 13 14 15 15 16 17 17 18 19 20 21 22 23 24 25 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 12 13 13 14 15 15 16 17 17 18 19 20 21 22 23 24 25 26 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 12 13 13 14 15 15 16 17 17 18 19 20 21 22 23 24 25 26 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 12 13 13 14 15 15 16 17 17 18 19 20 21 22 23 24 25 26 27 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 11 11 12 13 13 13 13 14 15 15 16 17 17 17 18 19 19 19 20 21 21 22 23 23 24 25 25 26 27 27 28 29 29 30 31 31 32 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 11 11 12 13 13 13 13 14 15 15 16 17 17 17 18 19 19 19 20 21 21 22 23 23 24 25 25 26 27 27 28 29 29 30 31 31 32 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 11 11 12 13 13 13 13 14 15 15 16 17 17 17 18 19 19 19 20 21 21 22 23 23 24 25 25 26 27 27 28 29 29 30 31 31 32 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 11 11 12 13 13 13 13 14 15 15 16 17 17 17 18 19 19 19 20 21 21 22 23 23 24 25 25 26 27 27 28 29 29 30 31 31 32 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 \", \"1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 3 3 4 5 5 5 6 7 7 7 7 8 9 9 10 11 11 11 11 12 13 13 13 13 14 15 15 16 17 17 17 18 19 19 19 20 21 21 22 23 23 24 25 25 26 27 27 28 29 29 30 31 31 32 33 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 \"]}", "source": "primeintellect"}
Kate has a set $S$ of $n$ integers $\{1, \dots, n\} $. She thinks that imperfection of a subset $M \subseteq S$ is equal to the maximum of $gcd(a, b)$ over all pairs $(a, b)$ such that both $a$ and $b$ are in $M$ and $a \neq b$. Kate is a very neat girl and for each $k \in \{2, \dots, n\}$ she wants to find a subset that has the smallest imperfection among all subsets in $S$ of size $k$. There can be more than one subset with the smallest imperfection and the same size, but you don't need to worry about it. Kate wants to find all the subsets herself, but she needs your help to find the smallest possible imperfection for each size $k$, will name it $I_k$. Please, help Kate to find $I_2$, $I_3$, ..., $I_n$. -----Input----- The first and only line in the input consists of only one integer $n$ ($2\le n \le 5 \cdot 10^5$)  — the size of the given set $S$. -----Output----- Output contains only one line that includes $n - 1$ integers: $I_2$, $I_3$, ..., $I_n$. -----Examples----- Input 2 Output 1 Input 3 Output 1 1 -----Note----- First sample: answer is 1, because $gcd(1, 2) = 1$. Second sample: there are subsets of $S$ with sizes $2, 3$ with imperfection equal to 1. For example, $\{2,3\}$ and $\{1, 2, 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\": [\"6\\n3 1 0\\n0 3 0\\n2 2 0\\n1 0 0\\n1 3 0\\n0 1 0\\n\", \"8\\n0 1 1\\n1 0 1\\n1 1 0\\n1 1 1\\n2 2 2\\n3 2 2\\n2 3 2\\n2 2 3\\n\", \"2\\n-32839949 -68986721 41592956\\n-32839949 -31435211 41592956\\n\", \"10\\n-93796614 30297417 22968703\\n-91631822 -13274485 54175787\\n-91631822 30297417 22968703\\n-75960156 -13274485 22968703\\n-75960156 30297417 22968703\\n-91631822 -92047004 65302423\\n-91631822 30297417 -16296706\\n-75960156 88346795 54175787\\n-93796614 30297417 -16296706\\n-75960156 30297417 54175787\\n\", \"2\\n34319950 -11299623 -19866275\\n34319950 -11299623 98728529\\n\", \"2\\n62887961 73879338 -68804433\\n62887961 63665147 -68804433\\n\", \"2\\n35627406 -93449884 80249079\\n52771770 -93449884 80249079\\n\", \"4\\n-42939263 80157803 90523514\\n-42939263 94977529 90523514\\n-42939263 94977529 -3280468\\n-42939263 80157803 -3280468\\n\", \"4\\n32117556 7831842 -38931866\\n32117556 -42244261 -38931866\\n-24487444 -42244261 -38931866\\n-24487444 7831842 -38931866\\n\", \"4\\n-53055455 42895224 28613596\\n-53061404 42895224 39577025\\n-53061404 42895224 28613596\\n-53055455 42895224 39577025\\n\", \"2\\n-100000000 -100000000 -100000000\\n-100000000 -100000000 100000000\\n\", \"2\\n-100000000 100000000 -100000000\\n-100000000 -100000000 -100000000\\n\", \"2\\n100000000 -100000000 -100000000\\n-100000000 -100000000 -100000000\\n\", \"2\\n-100000000 -100000000 -100000000\\n100000000 -100000000 -100000000\\n\", \"8\\n-100000000 -100000000 -100000000\\n100000000 100000000 100000000\\n-100000000 100000000 100000000\\n-100000000 -100000000 100000000\\n100000000 100000000 -100000000\\n100000000 -100000000 -100000000\\n-100000000 100000000 -100000000\\n100000000 -100000000 100000000\\n\"], \"outputs\": [\"6 2\\n4 5\\n3 1\\n\", \"3 4\\n5 8\\n1 2\\n7 6\\n\", \"1 2\\n\", \"9 1\\n7 3\\n6 2\\n5 10\\n4 8\\n\", \"1 2\\n\", \"2 1\\n\", \"1 2\\n\", \"4 1\\n3 2\\n\", \"3 4\\n2 1\\n\", \"3 2\\n1 4\\n\", \"1 2\\n\", \"2 1\\n\", \"2 1\\n\", \"1 2\\n\", \"1 4\\n7 3\\n6 8\\n5 2\\n\"]}", "source": "primeintellect"}
This is an easier version of the problem. In this version, $n \le 2000$. There are $n$ distinct points in three-dimensional space numbered from $1$ to $n$. The $i$-th point has coordinates $(x_i, y_i, z_i)$. The number of points $n$ is even. You'd like to remove all $n$ points using a sequence of $\frac{n}{2}$ snaps. In one snap, you can remove any two points $a$ and $b$ that have not been removed yet and form a perfectly balanced pair. A pair of points $a$ and $b$ is perfectly balanced if no other point $c$ (that has not been removed yet) lies within the axis-aligned minimum bounding box of points $a$ and $b$. Formally, point $c$ lies within the axis-aligned minimum bounding box of points $a$ and $b$ if and only if $\min(x_a, x_b) \le x_c \le \max(x_a, x_b)$, $\min(y_a, y_b) \le y_c \le \max(y_a, y_b)$, and $\min(z_a, z_b) \le z_c \le \max(z_a, z_b)$. Note that the bounding box might be degenerate. Find a way to remove all points in $\frac{n}{2}$ snaps. -----Input----- The first line contains a single integer $n$ ($2 \le n \le 2000$; $n$ is even), denoting the number of points. Each of the next $n$ lines contains three integers $x_i$, $y_i$, $z_i$ ($-10^8 \le x_i, y_i, z_i \le 10^8$), denoting the coordinates of the $i$-th point. No two points coincide. -----Output----- Output $\frac{n}{2}$ pairs of integers $a_i, b_i$ ($1 \le a_i, b_i \le n$), denoting the indices of points removed on snap $i$. Every integer between $1$ and $n$, inclusive, must appear in your output exactly once. We can show that it is always possible to remove all points. If there are many solutions, output any of them. -----Examples----- Input 6 3 1 0 0 3 0 2 2 0 1 0 0 1 3 0 0 1 0 Output 3 6 5 1 2 4 Input 8 0 1 1 1 0 1 1 1 0 1 1 1 2 2 2 3 2 2 2 3 2 2 2 3 Output 4 5 1 6 2 7 3 8 -----Note----- In the first example, here is what points and their corresponding bounding boxes look like (drawn in two dimensions for simplicity, as all points lie on $z = 0$ plane). Note that order of removing matters: for example, points $5$ and $1$ don't form a perfectly balanced pair initially, but they do after point $3$ is removed. [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\\n-5 R\\n0 P\\n3 P\\n7 B\\n\", \"5\\n10 R\\n14 B\\n16 B\\n21 R\\n32 R\\n\", \"10\\n66 R\\n67 R\\n72 R\\n73 R\\n76 R\\n78 B\\n79 B\\n83 B\\n84 B\\n85 P\\n\", \"10\\n61 R\\n64 R\\n68 R\\n71 R\\n72 R\\n73 R\\n74 P\\n86 P\\n87 B\\n90 B\\n\", \"15\\n-9518 R\\n-6858 P\\n-6726 B\\n-6486 R\\n-4496 P\\n-4191 P\\n-772 B\\n-258 R\\n-194 P\\n1035 R\\n2297 P\\n4816 B\\n5779 R\\n9342 B\\n9713 B\\n\", \"6\\n-8401 R\\n-5558 P\\n-3457 P\\n-2361 R\\n6966 P\\n8140 B\\n\", \"2\\n1 R\\n2 R\\n\", \"2\\n-1000000000 B\\n1000000000 R\\n\", \"2\\n-1000000000 P\\n1000000000 P\\n\", \"2\\n-1000000000 B\\n1000000000 P\\n\", \"9\\n-105 R\\n-81 B\\n-47 P\\n-25 R\\n-23 B\\n55 P\\n57 R\\n67 B\\n76 P\\n\", \"6\\n-13 R\\n-10 P\\n-6 R\\n-1 P\\n4 R\\n10 P\\n\", \"8\\n-839 P\\n-820 P\\n-488 P\\n-334 R\\n-83 B\\n187 R\\n380 B\\n804 P\\n\", \"8\\n-12 P\\n-9 B\\n-2 R\\n-1 R\\n2 B\\n8 B\\n9 R\\n15 P\\n\", \"6\\n0 B\\n3 P\\n7 B\\n9 B\\n11 P\\n13 B\\n\"], \"outputs\": [\"12\\n\", \"24\\n\", \"26\\n\", \"29\\n\", \"25088\\n\", \"17637\\n\", \"1\\n\", \"0\\n\", \"2000000000\\n\", \"2000000000\\n\", \"272\\n\", \"32\\n\", \"2935\\n\", \"54\\n\", \"17\\n\"]}", "source": "primeintellect"}
The cities of Byteland and Berland are located on the axis $Ox$. In addition, on this axis there are also disputed cities, which belong to each of the countries in their opinion. Thus, on the line $Ox$ there are three types of cities: the cities of Byteland, the cities of Berland, disputed cities. Recently, the project BNET has been launched — a computer network of a new generation. Now the task of the both countries is to connect the cities so that the network of this country is connected. The countries agreed to connect the pairs of cities with BNET cables in such a way that: If you look at the only cities of Byteland and the disputed cities, then in the resulting set of cities, any city should be reachable from any other one by one or more cables, If you look at the only cities of Berland and the disputed cities, then in the resulting set of cities, any city should be reachable from any other one by one or more cables. Thus, it is necessary to choose a set of pairs of cities to connect by cables in such a way that both conditions are satisfied simultaneously. Cables allow bi-directional data transfer. Each cable connects exactly two distinct cities. The cost of laying a cable from one city to another is equal to the distance between them. Find the minimum total cost of laying a set of cables so that two subsets of cities (Byteland and disputed cities, Berland and disputed cities) are connected. Each city is a point on the line $Ox$. It is technically possible to connect the cities $a$ and $b$ with a cable so that the city $c$ ($a < c < b$) is not connected to this cable, where $a$, $b$ and $c$ are simultaneously coordinates of the cities $a$, $b$ and $c$. -----Input----- The first line contains a single integer $n$ ($2 \le n \le 2 \cdot 10^{5}$) — the number of cities. The following $n$ lines contains an integer $x_i$ and the letter $c_i$ ($-10^{9} \le x_i \le 10^{9}$) — the coordinate of the city and its type. If the city belongs to Byteland, $c_i$ equals to 'B'. If the city belongs to Berland, $c_i$ equals to «R». If the city is disputed, $c_i$ equals to 'P'. All cities have distinct coordinates. Guaranteed, that the cities are given in the increasing order of their coordinates. -----Output----- Print the minimal total length of such set of cables, that if we delete all Berland cities ($c_i$='R'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. Similarly, if we delete all Byteland cities ($c_i$='B'), it will be possible to find a way from any remaining city to any other remaining city, moving only by cables. -----Examples----- Input 4 -5 R 0 P 3 P 7 B Output 12 Input 5 10 R 14 B 16 B 21 R 32 R Output 24 -----Note----- In the first example, you should connect the first city with the second, the second with the third, and the third with the fourth. The total length of the cables will be $5 + 3 + 4 = 12$. In the second example there are no disputed cities, so you need to connect all the neighboring cities of Byteland and all the neighboring cities of Berland. The cities of Berland have coordinates $10, 21, 32$, so to connect them you need two cables of length $11$ and $11$. The cities of Byteland have coordinates $14$ and $16$, so to connect them you need one cable of length $2$. Thus, the total length of all cables is $11 + 11 + 2 = 24$. 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 2\\n2 3\\n3 4\\n4 5\\n5 1\\n1 3\\n2 4\\n3 5\\n4 1\\n5 2\\n\", \"6\\n5 6\\n4 3\\n5 3\\n2 4\\n6 1\\n3 1\\n6 2\\n2 5\\n1 4\\n3 6\\n1 2\\n4 5\\n\", \"5\\n3 2\\n4 2\\n4 1\\n2 1\\n2 5\\n3 1\\n4 5\\n3 5\\n4 3\\n1 5\\n\", \"7\\n4 5\\n6 2\\n4 1\\n3 1\\n3 2\\n7 5\\n2 1\\n7 6\\n6 3\\n5 2\\n6 4\\n4 7\\n1 5\\n7 3\\n\", \"10\\n6 5\\n9 10\\n4 8\\n6 1\\n7 9\\n4 3\\n3 10\\n4 10\\n7 10\\n7 1\\n6 8\\n2 3\\n1 5\\n5 7\\n2 8\\n1 2\\n5 9\\n4 9\\n2 6\\n8 3\\n\", \"14\\n13 4\\n3 9\\n6 11\\n1 13\\n7 8\\n3 2\\n14 3\\n4 1\\n10 4\\n12 11\\n1 6\\n13 7\\n10 14\\n12 5\\n12 2\\n10 7\\n1 5\\n13 10\\n6 12\\n4 5\\n2 9\\n11 2\\n8 3\\n9 8\\n8 14\\n14 7\\n6 5\\n11 9\\n\", \"20\\n5 20\\n1 15\\n3 19\\n16 20\\n6 8\\n11 14\\n17 9\\n17 8\\n16 5\\n9 18\\n3 2\\n19 13\\n8 7\\n9 6\\n12 4\\n7 1\\n17 7\\n10 20\\n10 16\\n18 17\\n2 11\\n11 12\\n4 14\\n4 5\\n9 15\\n11 13\\n3 10\\n6 15\\n12 14\\n3 16\\n18 15\\n1 8\\n19 10\\n2 19\\n13 2\\n1 6\\n20 4\\n14 5\\n13 12\\n18 7\\n\", \"8\\n2 1\\n3 1\\n2 3\\n4 2\\n6 2\\n8 2\\n3 4\\n3 6\\n3 7\\n3 8\\n4 5\\n7 4\\n6 5\\n5 8\\n6 8\\n8 7\\n\", \"25\\n17 14\\n19 1\\n24 16\\n23 13\\n20 15\\n24 23\\n18 25\\n4 1\\n18 9\\n2 17\\n14 12\\n25 2\\n13 6\\n21 9\\n19 3\\n11 18\\n10 13\\n12 19\\n3 17\\n12 1\\n10 6\\n15 1\\n18 21\\n11 21\\n23 22\\n8 11\\n11 16\\n10 23\\n2 9\\n25 7\\n15 5\\n22 24\\n13 22\\n5 10\\n5 20\\n4 15\\n5 6\\n12 4\\n3 14\\n16 22\\n8 24\\n7 17\\n25 9\\n21 8\\n8 16\\n19 14\\n3 7\\n20 6\\n20 4\\n2 7\\n\", \"5\\n2 1\\n1 3\\n1 4\\n1 5\\n3 2\\n2 4\\n2 5\\n4 3\\n3 5\\n4 5\\n\", \"6\\n1 2\\n3 1\\n4 1\\n5 1\\n2 3\\n4 2\\n2 5\\n4 3\\n3 6\\n5 4\\n4 6\\n5 6\\n\", \"7\\n2 1\\n3 1\\n5 1\\n6 1\\n7 1\\n2 3\\n2 6\\n2 7\\n3 6\\n3 7\\n4 5\\n6 4\\n7 4\\n7 5\\n\", \"9\\n1 2\\n6 1\\n1 7\\n1 8\\n1 9\\n3 2\\n2 5\\n6 2\\n7 2\\n2 9\\n3 6\\n4 5\\n7 4\\n5 7\\n8 5\\n6 7\\n8 6\\n9 6\\n\", \"10\\n1 2\\n1 3\\n1 4\\n1 5\\n2 3\\n2 4\\n2 5\\n3 4\\n3 5\\n4 5\\n6 7\\n6 8\\n6 9\\n6 10\\n7 8\\n7 9\\n7 10\\n8 9\\n8 10\\n9 10\\n\", \"6\\n4 6\\n4 3\\n5 3\\n2 4\\n6 1\\n3 1\\n6 2\\n2 5\\n1 4\\n3 6\\n1 2\\n4 5\\n\"], \"outputs\": [\"1 2 3 4 5 \", \"1 2 4 5 3 6 \", \"1 2 3 4 5 \", \"1 2 3 6 7 4 5 \", \"1 5 7 9 10 4 3 8 2 6 \", \"1 4 13 10 7 14 8 3 9 2 11 12 6 5 \", \"-1\\n\", \"-1\\n\", \"1 4 15 20 5 6 10 13 23 22 24 16 8 11 21 18 9 25 2 7 17 3 14 19 12 \", \"1 2 3 4 5 \", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\"]}", "source": "primeintellect"}
One day Vasya came up to the blackboard and wrote out n distinct integers from 1 to n in some order in a circle. Then he drew arcs to join the pairs of integers (a, b) (a ≠ b), that are either each other's immediate neighbors in the circle, or there is number c, such that a and с are immediate neighbors, and b and c are immediate neighbors. As you can easily deduce, in the end Vasya drew 2·n arcs. For example, if the numbers are written in the circle in the order 1, 2, 3, 4, 5 (in the clockwise direction), then the arcs will join pairs of integers (1, 2), (2, 3), (3, 4), (4, 5), (5, 1), (1, 3), (2, 4), (3, 5), (4, 1) and (5, 2). Much time has passed ever since, the numbers we wiped off the blackboard long ago, but recently Vasya has found a piece of paper with 2·n written pairs of integers that were joined with the arcs on the board. Vasya asks you to find the order of numbers in the circle by these pairs. -----Input----- The first line of the input contains a single integer n (5 ≤ n ≤ 10^5) that shows, how many numbers were written on the board. Next 2·n lines contain pairs of integers a_{i}, b_{i} (1 ≤ a_{i}, b_{i} ≤ n, a_{i} ≠ b_{i}) — the numbers that were connected by the arcs. It is guaranteed that no pair of integers, connected by a arc, occurs in the input more than once. The pairs of numbers and the numbers in the pairs are given in the arbitrary order. -----Output----- If Vasya made a mistake somewhere and there isn't any way to place numbers from 1 to n on the circle according to the statement, then print a single number "-1" (without the quotes). Otherwise, print any suitable sequence of n distinct integers from 1 to n. If there are multiple solutions, you are allowed to print any of them. Specifically, it doesn't matter which number you write first to describe the sequence of the order. It also doesn't matter whether you write out the numbers in the clockwise or counter-clockwise direction. -----Examples----- Input 5 1 2 2 3 3 4 4 5 5 1 1 3 2 4 3 5 4 1 5 2 Output 1 2 3 4 5 Input 6 5 6 4 3 5 3 2 4 6 1 3 1 6 2 2 5 1 4 3 6 1 2 4 5 Output 1 2 4 5 3 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\": [\"6 4 10\\n3 1 1 1 2 2\\n7\\n8\\n9\\n10\\n11\\n12\\n13\\n14\\n15\\n16\\n\", \"4 5 4\\n4 4 5 1\\n15\\n9\\n13\\n6\\n\", \"1 1 20\\n1\\n2\\n5\\n200\\n199\\n198\\n24\\n123\\n100\\n101\\n100\\n3\\n6\\n200\\n193\\n191\\n24\\n123\\n78\\n109\\n13\\n\", \"1 100 20\\n5\\n2\\n3\\n4\\n5\\n100\\n101\\n102\\n103\\n200\\n78\\n6\\n7\\n8\\n9\\n10\\n104\\n105\\n106\\n107\\n108\\n\", \"100 99 20\\n89 96 26 16 28 26 96 14 46 92 76 66 93 65 45 7 89 6 95 53 34 59 15 75 8 25 20 99 41 90 51 14 94 23 68 25 58 81 50 85 87 53 27 67 64 30 55 77 7 30 10 32 38 1 67 94 44 16 49 38 63 76 81 47 55 92 67 25 61 96 2 52 33 69 4 64 24 29 88 70 45 76 83 79 22 87 5 62 11 30 17 82 77 48 73 88 96 35 96 82\\n106\\n198\\n109\\n190\\n154\\n160\\n127\\n147\\n163\\n153\\n143\\n194\\n189\\n172\\n181\\n129\\n162\\n104\\n175\\n172\\n\", \"100 16 20\\n9 16 14 12 14 4 9 7 3 3 4 6 15 1 6 15 12 5 11 10 8 10 4 6 4 15 4 3 8 7 4 7 13 10 15 10 1 2 7 9 7 15 14 6 4 4 14 6 3 7 2 2 2 5 10 7 3 11 11 6 12 14 13 4 7 4 11 11 3 9 6 8 1 11 3 11 7 15 8 10 1 10 3 13 11 8 3 3 8 8 13 12 14 13 8 14 8 15 1 1\\n164\\n106\\n152\\n147\\n186\\n137\\n144\\n121\\n143\\n192\\n137\\n127\\n108\\n168\\n162\\n171\\n140\\n153\\n181\\n200\\n\", \"100 41 20\\n36 27 30 37 31 23 37 27 36 35 15 7 7 4 36 36 35 23 30 30 36 35 4 36 25 4 23 25 36 7 31 25 36 27 30 30 25 25 4 15 35 25 15 27 4 15 35 7 23 30 35 36 36 25 30 7 36 36 25 23 27 35 30 30 35 23 27 36 36 15 25 7 16 8 8 4 4 30 35 36 36 36 31 30 36 36 35 36 30 27 31 8 7 25 25 4 27 27 36 36\\n180\\n176\\n168\\n161\\n164\\n127\\n194\\n143\\n143\\n183\\n186\\n141\\n160\\n130\\n170\\n163\\n162\\n151\\n147\\n156\\n\", \"20 9 20\\n9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9\\n172\\n27\\n41\\n96\\n137\\n111\\n33\\n36\\n67\\n173\\n176\\n150\\n72\\n75\\n38\\n81\\n186\\n180\\n169\\n40\\n\", \"100 11 20\\n10 6 6 9 1 10 10 6 6 10 9 6 9 1 9 6 1 10 9 9 10 9 6 6 9 10 6 6 6 10 6 9 9 9 10 6 10 6 9 6 6 6 9 10 9 6 9 1 9 9 9 10 9 10 6 6 9 9 6 10 10 10 6 6 10 9 10 6 10 9 6 10 6 9 6 6 10 6 6 9 9 9 9 9 9 6 6 6 6 9 10 10 6 10 6 10 6 9 6 9\\n195\\n170\\n126\\n189\\n143\\n122\\n166\\n170\\n168\\n166\\n177\\n153\\n138\\n198\\n171\\n127\\n118\\n123\\n154\\n113\\n\", \"100 51 20\\n2 5 17 5 16 14 23 36 27 41 31 36 44 50 6 22 14 2 37 39 49 31 26 9 11 49 5 38 8 25 6 4 49 5 29 8 47 38 11 1 18 21 21 15 26 34 6 43 2 28 48 30 48 39 12 26 32 26 12 22 37 9 10 5 13 44 32 3 19 15 37 42 40 22 16 46 11 42 15 17 44 50 43 32 39 8 10 28 43 14 43 49 45 39 39 7 4 8 16 10\\n102\\n106\\n101\\n101\\n106\\n161\\n105\\n105\\n106\\n105\\n113\\n127\\n118\\n101\\n106\\n104\\n135\\n127\\n105\\n105\\n\", \"100 6 20\\n6 4 6 3 6 6 3 1 1 3 1 3 1 6 2 1 4 6 4 1 6 6 4 1 6 1 3 4 3 2 1 4 1 4 6 1 1 4 2 3 2 6 4 1 1 1 2 6 2 2 4 2 1 1 1 2 6 4 6 4 3 3 4 6 4 2 3 4 6 4 6 1 3 6 6 3 3 2 2 3 6 2 1 4 4 3 2 2 3 1 3 3 6 3 4 4 2 6 3 6\\n147\\n105\\n121\\n139\\n129\\n128\\n122\\n133\\n187\\n168\\n102\\n144\\n108\\n110\\n117\\n113\\n144\\n124\\n104\\n113\\n\", \"100 21 20\\n11 17 21 14 7 15 18 6 17 11 21 3 17 21 21 7 21 17 14 21 14 14 3 6 18 21 17 17 18 14 14 21 15 13 3 15 11 11 16 11 6 10 15 17 11 15 13 13 21 16 21 13 11 14 21 21 13 18 16 3 21 16 13 16 15 3 16 21 21 21 14 15 16 17 16 16 21 2 14 21 7 7 21 16 17 21 17 15 21 10 7 17 21 11 13 17 14 3 11 14\\n170\\n118\\n164\\n118\\n178\\n177\\n127\\n117\\n109\\n108\\n142\\n150\\n129\\n139\\n178\\n112\\n114\\n117\\n117\\n108\\n\", \"100 74 20\\n9 15 16 18 55 41 64 44 5 1 27 31 36 25 71 28 71 35 47 40 21 53 31 11 24 1 69 67 58 16 19 52 33 17 63 1 49 28 17 52 46 60 53 21 21 60 19 63 11 61 8 27 3 22 38 31 45 69 61 18 58 22 8 71 17 1 64 70 56 10 66 47 70 1 45 8 66 8 66 25 39 45 47 7 41 24 41 72 16 42 28 7 15 10 38 29 50 4 37 11\\n123\\n140\\n156\\n123\\n681178055639444431\\n402923644436772466\\n122\\n101\\n705403096072274104\\n169676975611015773\\n108\\n122\\n164\\n131\\n164\\n164\\n365209906715274474\\n122\\n111\\n122\\n\", \"100 17 20\\n8 16 4 7 12 6 1 17 6 1 2 7 16 16 12 7 17 8 12 12 1 17 16 4 16 17 2 2 6 6 17 1 2 2 6 4 6 17 16 12 17 16 17 1 12 12 4 6 8 17 1 4 16 12 17 8 1 1 6 8 4 4 12 8 12 2 16 1 16 6 2 8 12 4 2 6 4 4 2 8 2 8 1 16 16 8 1 2 6 1 17 4 2 6 12 17 12 7 16 6\\n101\\n108\\n112\\n116\\n108\\n141\\n133\\n832741425065423238\\n460535959993121846\\n433996273266058278\\n119\\n132326735886440059\\n132\\n117\\n196\\n76769211260841343\\n162\\n116\\n112\\n141\\n\", \"100 21 20\\n21 21 15 21 1 4 21 3 11 11 21 3 16 11 4 3 21 21 4 16 4 21 21 21 11 16 21 14 14 14 8 1 1 4 11 21 8 14 11 4 6 8 6 1 8 21 11 3 3 21 1 8 11 1 4 16 1 21 1 4 14 11 13 1 21 21 16 6 21 13 15 13 21 13 21 1 5 6 14 7 21 11 8 8 11 14 5 3 3 3 8 5 3 11 13 1 16 4 21 3\\n127\\n178\\n192\\n174\\n164\\n118\\n108\\n404159127218619270\\n14469197281678073\\n127\\n139\\n139\\n555738333143181764\\n906223987227162448\\n101\\n138\\n747440919795929604\\n127\\n138\\n122\\n\"], \"outputs\": [\"4\\n3\\n4\\n2\\n3\\n4\\n1\\n2\\n3\\n4\\n\", \"5\\n3\\n3\\n3\\n\", \"1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"1\\n2\\n3\\n4\\n100\\n1\\n2\\n3\\n100\\n78\\n6\\n7\\n8\\n9\\n10\\n4\\n5\\n6\\n7\\n8\\n\", \"19\\n86\\n36\\n74\\n32\\n39\\n97\\n22\\n42\\n31\\n18\\n80\\n73\\n52\\n63\\n1\\n41\\n13\\n57\\n52\\n\", \"4\\n2\\n8\\n1\\n10\\n5\\n14\\n12\\n13\\n16\\n5\\n6\\n9\\n8\\n2\\n11\\n10\\n9\\n5\\n8\\n\", \"32\\n24\\n14\\n5\\n10\\n40\\n9\\n19\\n19\\n37\\n40\\n17\\n3\\n2\\n17\\n9\\n6\\n32\\n24\\n40\\n\", \"8\\n7\\n5\\n4\\n5\\n3\\n5\\n8\\n7\\n1\\n4\\n2\\n4\\n7\\n2\\n5\\n6\\n8\\n5\\n4\\n\", \"3\\n2\\n7\\n5\\n8\\n2\\n7\\n2\\n11\\n7\\n1\\n1\\n2\\n7\\n3\\n8\\n5\\n3\\n2\\n8\\n\", \"24\\n1\\n20\\n20\\n1\\n51\\n51\\n51\\n1\\n51\\n23\\n51\\n30\\n20\\n1\\n35\\n17\\n51\\n51\\n51\\n\", \"3\\n5\\n2\\n1\\n1\\n5\\n5\\n5\\n1\\n6\\n5\\n6\\n5\\n5\\n2\\n5\\n6\\n5\\n5\\n5\\n\", \"7\\n1\\n1\\n1\\n1\\n20\\n20\\n20\\n1\\n20\\n5\\n20\\n2\\n1\\n1\\n5\\n9\\n20\\n20\\n20\\n\", \"2\\n35\\n57\\n2\\n23\\n54\\n74\\n2\\n26\\n37\\n26\\n74\\n74\\n14\\n74\\n74\\n20\\n74\\n34\\n74\\n\", \"3\\n15\\n10\\n15\\n15\\n15\\n3\\n12\\n14\\n11\\n9\\n17\\n15\\n3\\n15\\n17\\n7\\n15\\n10\\n15\\n\", \"20\\n2\\n20\\n17\\n2\\n2\\n20\\n15\\n11\\n20\\n2\\n2\\n2\\n19\\n2\\n20\\n21\\n20\\n20\\n12\\n\"]}", "source": "primeintellect"}
Misha was interested in water delivery from childhood. That's why his mother sent him to the annual Innovative Olympiad in Irrigation (IOI). Pupils from all Berland compete there demonstrating their skills in watering. It is extremely expensive to host such an olympiad, so after the first $n$ olympiads the organizers introduced the following rule of the host city selection. The host cities of the olympiads are selected in the following way. There are $m$ cities in Berland wishing to host the olympiad, they are numbered from $1$ to $m$. The host city of each next olympiad is determined as the city that hosted the olympiad the smallest number of times before. If there are several such cities, the city with the smallest index is selected among them. Misha's mother is interested where the olympiad will be held in some specific years. The only information she knows is the above selection rule and the host cities of the first $n$ olympiads. Help her and if you succeed, she will ask Misha to avoid flooding your house. -----Input----- The first line contains three integers $n$, $m$ and $q$ ($1 \leq n, m, q \leq 500\,000$) — the number of olympiads before the rule was introduced, the number of cities in Berland wishing to host the olympiad, and the number of years Misha's mother is interested in, respectively. The next line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq m$), where $a_i$ denotes the city which hosted the olympiad in the $i$-th year. Note that before the rule was introduced the host city was chosen arbitrarily. Each of the next $q$ lines contains an integer $k_i$ ($n + 1 \leq k_i \leq 10^{18}$) — the year number Misha's mother is interested in host city in. -----Output----- Print $q$ integers. The $i$-th of them should be the city the olympiad will be hosted in the year $k_i$. -----Examples----- Input 6 4 10 3 1 1 1 2 2 7 8 9 10 11 12 13 14 15 16 Output 4 3 4 2 3 4 1 2 3 4 Input 4 5 4 4 4 5 1 15 9 13 6 Output 5 3 3 3 -----Note----- In the first example Misha's mother is interested in the first $10$ years after the rule was introduced. The host cities these years are 4, 3, 4, 2, 3, 4, 1, 2, 3, 4. In the second example the host cities after the new city is introduced are 2, 3, 1, 2, 3, 5, 1, 2, 3, 4, 5, 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 999\\n400000 1 2\\n500000 1 1\\n\", \"2 1000\\n400000 500 1\\n600000 500 2\\n\", \"2 99999\\n500 1 1\\n499 10000 2\\n\", \"26 10\\n495492 7 1\\n256604 5 2\\n511773 3 2\\n590712 4 1\\n206826 7 2\\n817878 4 2\\n843915 1 1\\n349160 3 1\\n351298 4 1\\n782251 8 2\\n910928 4 1\\n662354 4 2\\n468621 2 2\\n466991 7 2\\n787303 6 2\\n221623 8 2\\n343518 6 1\\n141123 7 1\\n24725 6 1\\n896603 3 2\\n918129 8 2\\n706071 6 2\\n512369 2 2\\n600004 4 1\\n928608 9 2\\n298493 3 1\\n\", \"13 10000\\n78186 325 1\\n942344 8592 2\\n19328 6409 2\\n632454 7747 2\\n757264 8938 1\\n462681 7708 1\\n26489 2214 2\\n415801 8912 2\\n156832 48 1\\n898262 1620 2\\n936086 5125 1\\n142567 5086 1\\n207839 9409 2\\n\", \"22 30\\n739680 21 1\\n697634 24 1\\n267450 27 2\\n946750 8 2\\n268031 27 1\\n418652 11 1\\n595005 12 1\\n59519 22 2\\n332220 1 1\\n355395 2 1\\n573947 26 1\\n864962 4 1\\n659836 14 1\\n439461 22 1\\n694157 11 2\\n429431 11 2\\n304031 9 2\\n282710 4 1\\n623799 11 1\\n610188 27 2\\n596592 20 2\\n562391 18 2\\n\", \"10 100\\n945740 58 2\\n424642 85 2\\n310528 91 2\\n688743 93 1\\n355046 85 1\\n663649 84 2\\n720124 56 1\\n941616 59 2\\n412011 46 2\\n891591 30 2\\n\", \"4 100\\n884131 61 1\\n927487 23 2\\n663318 13 1\\n234657 61 1\\n\", \"20 20\\n722369 11 1\\n210389 8 2\\n743965 2 1\\n951723 17 2\\n880618 1 2\\n101303 8 2\\n174013 19 2\\n627995 19 1\\n541778 5 1\\n586095 19 1\\n324166 4 1\\n125805 12 2\\n538606 2 2\\n691777 9 2\\n127586 7 1\\n849701 9 1\\n23273 17 1\\n250794 4 1\\n64709 7 2\\n785893 9 1\\n\", \"5 786551\\n352506 2 1\\n450985 6 2\\n561643 4 2\\n5065 8 2\\n717868 3 1\\n\", \"3 96475\\n187875 5 2\\n813727 8 1\\n645383 7 2\\n\", \"2 96475\\n813727 8 1\\n645383 7 2\\n\", \"2 2\\n1 1 1\\n999999 1 2\\n\", \"2 1000000\\n1 1 1\\n999999 1 2\\n\", \"2 250001\\n499999 250000 1\\n500000 250000 2\\n\"], \"outputs\": [\"500000.000000000000000000000000000000\\n\", \"400.000000000000000000000000000000\\n\", \"99.950100000000000000088817841970\\n\", \"4120.833333333333333481363069950021\\n\", \"7.572493946731234866574095088154\\n\", \"6656.250000000000000000000000000000\\n\", \"1919.167567567567567521358284921007\\n\", \"3152.739130434782608647381607624993\\n\", \"1369.000000000000000000000000000000\\n\", \"0.635685124996669956255399003275\\n\", \"50659.571428571428569398449326399714\\n\", \"50659.571428571428569398449326399714\\n\", \"1.000000000000000000000000000000\\n\", \"0.499999999999500000001997901400\\n\", \"1.499997000005989434244513258676\\n\"]}", "source": "primeintellect"}
n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 10^6. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-negative integer coordinate, and blow it up. At this moment all people will start running with their maximum speed in the direction they are facing. Also, two strange rays will start propagating from the bomb with speed s: one to the right, and one to the left. Of course, the speed s is strictly greater than people's maximum speed. The rays are strange because if at any moment the position and the direction of movement of some ray and some person coincide, then the speed of the person immediately increases by the speed of the ray. You need to place the bomb is such a point that the minimum time moment in which there is a person that has run through point 0, and there is a person that has run through point 10^6, is as small as possible. In other words, find the minimum time moment t such that there is a point you can place the bomb to so that at time moment t some person has run through 0, and some person has run through point 10^6. -----Input----- The first line contains two integers n and s (2 ≤ n ≤ 10^5, 2 ≤ s ≤ 10^6) — the number of people and the rays' speed. The next n lines contain the description of people. The i-th of these lines contains three integers x_{i}, v_{i} and t_{i} (0 < x_{i} < 10^6, 1 ≤ v_{i} < s, 1 ≤ t_{i} ≤ 2) — the coordinate of the i-th person on the line, his maximum speed and the direction he will run to (1 is to the left, i.e. in the direction of coordinate decrease, 2 is to the right, i.e. in the direction of coordinate increase), respectively. It is guaranteed that the points 0 and 10^6 will be reached independently of the bomb's position. -----Output----- Print the minimum time needed for both points 0 and 10^6 to be reached. Your answer is considered correct if its absolute or relative error doesn't exceed 10^{ - 6}. Namely, if your answer is a, and the jury's answer is b, then your answer is accepted, if $\frac{|a - b|}{\operatorname{max}(1,|b|)} \leq 10^{-6}$. -----Examples----- Input 2 999 400000 1 2 500000 1 1 Output 500000.000000000000000000000000000000 Input 2 1000 400000 500 1 600000 500 2 Output 400.000000000000000000000000000000 -----Note----- In the first example, it is optimal to place the bomb at a point with a coordinate of 400000. Then at time 0, the speed of the first person becomes 1000 and he reaches the point 10^6 at the time 600. The bomb will not affect on the second person, and he will reach the 0 point at the time 500000. In the second example, it is optimal to place the bomb at the point 500000. The rays will catch up with both people at the time 200. At this time moment, the first is at the point with a coordinate of 300000, and the second is at the point with a coordinate of 700000. Their speed will become 1500 and at the time 400 they will simultaneously run through points 0 and 10^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\": [\"7\\n1 3 1 3 2 1 2\\n\", \"4\\n2 1 1 2\\n\", \"1\\n2\\n\", \"2\\n3 1\\n\", \"3\\n2 1 2\\n\", \"3\\n1 2 3\\n\", \"12\\n3 3 3 3 3 3 3 3 1 3 3 2\\n\", \"60\\n3 3 1 2 2 1 3 1 1 1 3 2 2 2 3 3 1 3 2 3 2 2 1 3 3 2 3 1 2 2 2 1 3 2 1 1 3 3 1 1 1 3 1 2 1 1 3 3 3 2 3 2 3 2 2 2 1 1 1 2\\n\", \"12\\n3 1 1 1 1 1 1 2 1 1 1 1\\n\", \"22\\n2 2 2 2 2 2 2 2 2 2 3 2 2 2 2 2 2 1 2 2 2 2\\n\", \"138\\n2 3 2 2 2 2 2 2 2 2 1 2 1 2 2 2 1 2 1 2 2 1 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 1 2 3 2 2 2 3 1 3 2 3 2 3 2 2 2 2 3 2 2 2 2 2 1 2 2 3 2 2 3 2 1 2 2 2 2 2 3 1 2 2 2 2 2 3 2 2 3 2 2 2 2 2 1 1 2 3 2 2 2 2 3 2 2 2 2 2 1 2 1 2 2 2 2 2 1 2 3 2 3 2 2 2 1 2 2 2 1 2 2 2 2 1 2 2 2 2 1 3\\n\", \"203\\n2 2 1 2 1 2 2 2 1 2 2 1 1 3 1 2 1 2 1 1 2 3 1 1 2 3 3 2 2 2 1 2 1 1 1 1 1 3 1 1 2 1 1 2 2 2 1 2 2 2 1 2 3 2 1 1 2 2 1 2 1 2 2 1 1 2 2 2 1 1 2 2 1 2 1 2 2 3 2 1 2 1 1 1 1 1 1 1 1 1 1 2 2 1 1 2 2 2 2 1 1 1 1 1 1 1 2 2 2 2 2 1 1 1 2 2 2 1 2 2 1 3 2 1 1 1 2 1 1 2 1 1 2 2 2 1 1 2 2 2 1 2 1 3 2 1 2 2 2 1 1 1 2 2 2 1 2 1 1 2 2 2 2 2 1 1 2 1 2 2 1 1 1 1 1 1 2 2 3 1 1 2 3 1 1 1 1 1 1 2 2 1 1 1 2 2 3 2 1 3 1 1 1\\n\", \"220\\n1 1 3 1 3 1 1 3 1 3 3 3 3 1 3 3 1 3 3 3 3 3 1 1 1 3 1 1 1 3 2 3 3 3 1 1 3 3 1 1 3 3 3 3 1 3 3 1 1 1 2 3 1 1 1 2 3 3 3 2 3 1 1 3 1 1 1 3 2 1 3 2 3 1 1 3 3 3 1 3 1 1 1 3 3 2 1 3 2 1 1 3 3 1 1 1 2 1 1 3 2 1 2 1 1 1 3 1 3 3 1 2 3 3 3 3 1 3 1 1 1 1 2 3 1 1 1 1 1 1 3 2 3 1 3 1 3 1 1 3 1 3 1 3 1 3 1 3 3 2 3 1 3 3 1 3 3 3 3 1 1 3 3 3 3 1 1 3 3 3 2 1 1 1 3 3 1 3 3 3 1 1 1 3 1 3 3 1 1 1 2 3 1 1 3 1 1 1 1 2 3 1 1 2 3 3 1 3 1 3 3 3 3 1 3 2 3 1 1 3\\n\", \"61\\n2 3 1 3 2 2 2 3 1 3 2 3 1 2 1 1 2 2 2 2 3 2 3 1 2 1 3 1 3 2 1 1 3 2 1 3 3 3 1 3 3 1 1 3 1 3 2 2 1 2 2 2 1 3 2 3 1 3 3 1 1\\n\", \"5\\n1 2 2 3 3\\n\"], \"outputs\": [\"2\\n3 5 2\\n6 7 4\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"1\\n1 2 3\\n\", \"1\\n9 12 2\\n\", \"20\\n6 60 1\\n17 44 20\\n3 5 33\\n36 21 42\\n59 14 2\\n58 26 49\\n9 29 48\\n23 19 24\\n10 30 37\\n41 54 15\\n45 31 27\\n57 55 38\\n39 12 25\\n35 34 11\\n32 52 7\\n8 50 18\\n43 4 53\\n46 56 51\\n40 22 16\\n28 13 47\\n\", \"1\\n3 8 1\\n\", \"1\\n18 2 11\\n\", \"18\\n13 91 84\\n34 90 48\\n11 39 77\\n78 129 50\\n137 68 119\\n132 122 138\\n19 12 96\\n40 7 2\\n22 88 69\\n107 73 46\\n115 15 52\\n127 106 87\\n93 92 66\\n71 112 117\\n63 124 42\\n17 70 101\\n109 121 57\\n123 25 36\\n\", \"13\\n188 72 14\\n137 4 197\\n158 76 122\\n152 142 26\\n104 119 179\\n40 63 38\\n12 1 78\\n17 30 27\\n189 60 53\\n166 190 144\\n129 7 183\\n83 41 22\\n121 81 200\\n\", \"20\\n198 89 20\\n141 56 131\\n166 204 19\\n160 132 142\\n111 112 195\\n45 216 92\\n6 31 109\\n14 150 170\\n199 60 18\\n173 123 140\\n134 69 156\\n82 191 85\\n126 200 80\\n24 97 46\\n62 86 149\\n214 101 26\\n79 171 78\\n125 72 118\\n172 103 162\\n219 51 64\\n\", \"20\\n9 55 2\\n24 34 27\\n3 5 37\\n35 17 41\\n61 11 4\\n60 19 54\\n15 20 59\\n26 14 29\\n16 22 38\\n43 50 12\\n49 25 36\\n57 51 40\\n39 6 33\\n32 30 10\\n31 48 8\\n13 47 23\\n45 1 58\\n53 52 56\\n42 18 21\\n28 7 44\\n\", \"1\\n1 3 4\\n\"]}", "source": "primeintellect"}
The School №0 of the capital of Berland has n children studying in it. All the children in this school are gifted: some of them are good at programming, some are good at maths, others are good at PE (Physical Education). Hence, for each child we know value t_{i}: t_{i} = 1, if the i-th child is good at programming, t_{i} = 2, if the i-th child is good at maths, t_{i} = 3, if the i-th child is good at PE Each child happens to be good at exactly one of these three subjects. The Team Scientific Decathlon Olympias requires teams of three students. The school teachers decided that the teams will be composed of three children that are good at different subjects. That is, each team must have one mathematician, one programmer and one sportsman. Of course, each child can be a member of no more than one team. What is the maximum number of teams that the school will be able to present at the Olympiad? How should the teams be formed for that? -----Input----- The first line contains integer n (1 ≤ n ≤ 5000) — the number of children in the school. The second line contains n integers t_1, t_2, ..., t_{n} (1 ≤ t_{i} ≤ 3), where t_{i} describes the skill of the i-th child. -----Output----- In the first line output integer w — the largest possible number of teams. Then print w lines, containing three numbers in each line. Each triple represents the indexes of the children forming the team. You can print both the teams, and the numbers in the triplets in any order. The children are numbered from 1 to n in the order of their appearance in the input. Each child must participate in no more than one team. If there are several solutions, print any of them. If no teams can be compiled, print the only line with value w equal to 0. -----Examples----- Input 7 1 3 1 3 2 1 2 Output 2 3 5 2 6 7 4 Input 4 2 1 1 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\": [\"5 7\\n2 3 5 4 1\\n\", \"10 10\\n9 1 1 1 1 1 1 1 1 1\\n\", \"5 10\\n3 1 4 2 4\\n\", \"1 1\\n1\\n\", \"2 1\\n1 1\\n\", \"10 20\\n3 2 8 6 6 9 6 10 10 5\\n\", \"100 2000\\n12 82 30 95 4 97 12 10 75 13 98 68 54 63 62 85 15 73 15 58 2 51 38 35 74 11 67 48 42 30 75 41 59 10 42 28 6 40 88 47 58 23 81 66 64 55 71 48 69 21 21 67 50 36 14 9 74 1 38 95 56 60 97 48 83 98 54 75 21 88 8 34 72 46 53 79 28 17 31 17 94 30 85 4 65 31 70 38 67 13 41 38 23 18 5 84 14 10 15 23\\n\", \"100 2000\\n31 21 8 4 15 6 3 20 22 16 47 14 35 1 21 22 15 26 19 21 17 44 7 1 15 40 45 22 2 30 46 1 20 90 56 28 24 65 43 8 9 12 38 1 47 8 13 35 20 47 12 8 24 6 16 12 23 52 33 83 6 3 11 55 20 15 53 20 6 39 7 5 44 2 27 9 26 24 35 11 50 6 46 5 35 55 42 49 38 16 3 12 38 33 61 7 22 37 8 26\\n\", \"100 2000\\n61 77 55 79 29 99 68 31 78 53 80 91 78 52 84 95 92 84 23 65 86 89 84 98 83 40 50 88 53 74 52 53 52 61 69 90 81 95 98 100 92 79 94 93 80 84 76 34 40 56 65 72 95 91 95 80 45 89 58 96 99 96 78 64 43 96 50 68 62 92 59 65 77 64 94 92 69 97 48 76 53 92 100 94 88 70 29 100 93 78 61 30 32 93 96 95 82 92 57 84\\n\", \"1 2\\n2\\n\", \"2 2\\n1 1\\n\", \"2 2\\n1 2\\n\", \"2 2\\n2 1\\n\", \"6 590\\n99 100 150 200 299 300\\n\", \"4 6\\n4 3 2 1\\n\"], \"outputs\": [\"3\\n\", \"4\\n\", \"5\\n\", \"1\\n\", \"2\\n\", \"6\\n\", \"80\\n\", \"100\\n\", \"54\\n\", \"1\\n\", \"2\\n\", \"2\\n\", \"2\\n\", \"5\\n\", \"4\\n\"]}", "source": "primeintellect"}
Alyona has recently bought a miniature fridge that can be represented as a matrix with $h$ rows and $2$ columns. Initially there is only one shelf at the bottom of the fridge, but Alyona can install arbitrary number of shelves inside the fridge between any two rows. A shelf is two cells wide, does not occupy any space but separates the inside of the fridge to the lower and upper part. [Image] An example of a fridge with $h = 7$ and two shelves. The shelves are shown in black. The picture corresponds to the first example. Alyona has $n$ bottles of milk that she wants to put in the fridge. The $i$-th bottle is $a_i$ cells tall and $1$ cell wide. She can put a bottle on some shelf if the corresponding space above the shelf is at least as tall as the bottle. She can not put a bottle on top of another bottle (if there is no shelf between them). Two bottles can not share a cell. Alyona is interested in the largest integer $k$ such that she can put bottles $1$, $2$, ..., $k$ in the fridge at the same time. Find this largest $k$. -----Input----- The first line contains two integers $n$ and $h$ ($1 \le n \le 10^3$, $1 \le h \le 10^9$) — the number of bottles and the height of the fridge. The second line contains $n$ integers $a_1$, $a_2$, ..., $a_n$ ($1 \le a_i \le h$) — the heights of the bottles. -----Output----- Print the single integer $k$ — the maximum integer such that Alyona can put the bottles $1$, $2$, ..., $k$ in the fridge at the same time. If Alyona can put all bottles in the fridge, print $n$. It is easy to see that Alyona can always put at least one bottle in the fridge. -----Examples----- Input 5 7 2 3 5 4 1 Output 3 Input 10 10 9 1 1 1 1 1 1 1 1 1 Output 4 Input 5 10 3 1 4 2 4 Output 5 -----Note----- One of optimal locations in the first example is shown on the picture in the statement. One of optimal locations in the second example is shown on the picture below. [Image] One of optimal locations in the third example is shown on the picture below. [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 4\\n>>>>\\n>>>>\\n>>>>\\n\", \"3 3\\n>>>\\n<<<\\n>>>\\n\", \"3 2\\n==\\n=<\\n==\\n\", \"1 1\\n<\\n\", \"1 1\\n=\\n\", \"3 3\\n<<<\\n<<=\\n<<=\\n\", \"3 3\\n><>\\n>><\\n><<\\n\", \"11 23\\n>><>>>>>>>><>>>>>>>>>>>\\n<<<>>>>>>>><>><><>>><>>\\n<<<>><<<><><><<><<>><>>\\n><<>>>>>>>><>><><>>><>>\\n<<<>>><<><><>><><<>><>>\\n<<<>>><<><><>><><<>><>>\\n><<>>>>>>>><>>>>>>>>>>>\\n><<>>>>>>>><>>>>>>>><>>\\n><<>>>>>>>><>>>>>>>>>>>\\n<<<<<<<<<<<<<><<<<<<<<<\\n<<<<<<<<<<<<<<<<<<<<<<<\\n\", \"3 2\\n<>\\n<=\\n>>\\n\", \"2 3\\n>>>\\n==<\\n\", \"3 3\\n===\\n===\\n===\\n\", \"3 3\\n=<>\\n>>>\\n=<=\\n\", \"3 1\\n>\\n<\\n<\\n\", \"2 2\\n<>\\n>>\\n\", \"10 24\\n<><>>>><>>><>>>>>>>><<>>\\n<><>>>><>>><>>>>>>>><<>>\\n>><>>>><>>><>>>>>>>><>>>\\n<<<><><<<<<<><<><>>><<<>\\n<<<=<=<<<<<<><<=<>==<<<>\\n>><>>>><>>><>>>>>>>><>>>\\n>>>>>>>>>>>>>>>>>>>>>>>>\\n<<<<<<<<<<<<=<<<<=<<<<<<\\n<><>>>><>>><>>>>>>>><<>>\\n<><>>>><>>><>>>>>>>><<>>\\n\"], \"outputs\": [\"Yes\\n2 2 2 \\n1 1 1 1 \\n\", \"Yes\\n3 1 3 \\n2 2 2 \\n\", \"No\\n\", \"Yes\\n1 \\n2 \\n\", \"Yes\\n1 \\n1 \\n\", \"Yes\\n1 2 2 \\n3 3 2 \\n\", \"No\\n\", \"No\\n\", \"Yes\\n2 1 4 \\n3 1 \\n\", \"Yes\\n3 1 \\n1 1 2 \\n\", \"Yes\\n1 1 1 \\n1 1 1 \\n\", \"No\\n\", \"Yes\\n3 1 1 \\n2 \\n\", \"Yes\\n2 4 \\n3 1 \\n\", \"Yes\\n6 6 8 4 3 8 10 1 6 6 \\n7 5 9 3 5 3 5 9 5 5 5 9 1 5 5 3 5 1 3 3 9 7 5 2 \\n\"]}", "source": "primeintellect"}
Mr. Apple, a gourmet, works as editor-in-chief of a gastronomic periodical. He travels around the world, tasting new delights of famous chefs from the most fashionable restaurants. Mr. Apple has his own signature method of review  — in each restaurant Mr. Apple orders two sets of dishes on two different days. All the dishes are different, because Mr. Apple doesn't like to eat the same food. For each pair of dishes from different days he remembers exactly which was better, or that they were of the same quality. After this the gourmet evaluates each dish with a positive integer. Once, during a revision of a restaurant of Celtic medieval cuisine named «Poisson», that serves chestnut soup with fir, warm soda bread, spicy lemon pie and other folk food, Mr. Apple was very pleasantly surprised the gourmet with its variety of menu, and hence ordered too much. Now he's confused about evaluating dishes. The gourmet tasted a set of $n$ dishes on the first day and a set of $m$ dishes on the second day. He made a table $a$ of size $n \times m$, in which he described his impressions. If, according to the expert, dish $i$ from the first set was better than dish $j$ from the second set, then $a_{ij}$ is equal to ">", in the opposite case $a_{ij}$ is equal to "<". Dishes also may be equally good, in this case $a_{ij}$ is "=". Now Mr. Apple wants you to help him to evaluate every dish. Since Mr. Apple is very strict, he will evaluate the dishes so that the maximal number used is as small as possible. But Mr. Apple also is very fair, so he never evaluates the dishes so that it goes against his feelings. In other words, if $a_{ij}$ is "<", then the number assigned to dish $i$ from the first set should be less than the number of dish $j$ from the second set, if $a_{ij}$ is ">", then it should be greater, and finally if $a_{ij}$ is "=", then the numbers should be the same. Help Mr. Apple to evaluate each dish from both sets so that it is consistent with his feelings, or determine that this is impossible. -----Input----- The first line contains integers $n$ and $m$ ($1 \leq n, m \leq 1000$) — the number of dishes in both days. Each of the next $n$ lines contains a string of $m$ symbols. The $j$-th symbol on $i$-th line is $a_{ij}$. All strings consist only of "<", ">" and "=". -----Output----- The first line of output should contain "Yes", if it's possible to do a correct evaluation for all the dishes, or "No" otherwise. If case an answer exist, on the second line print $n$ integers — evaluations of dishes from the first set, and on the third line print $m$ integers — evaluations of dishes from the second set. -----Examples----- Input 3 4 >>>> >>>> >>>> Output Yes 2 2 2 1 1 1 1 Input 3 3 >>> <<< >>> Output Yes 3 1 3 2 2 2 Input 3 2 == =< == Output No -----Note----- In the first sample, all dishes of the first day are better than dishes of the second day. So, the highest score will be $2$, for all dishes of the first day. In the third sample, the table is contradictory — there is no possible evaluation of the dishes that satisfies it. 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 1\\n5 4 3 5 2\\n\", \"5 3 1\\n5 4 3 5 5\\n\", \"5 3 1\\n5 4 4 5 5\\n\", \"3 2 7\\n5 4 2\\n\", \"100 1 1\\n-1 -1 -2 0 -2 -1 0 0 0 0 2 2 2 2 2 1 0 1 1 1 1 0 1 0 2 0 0 1 1 1 2 2 1 0 0 2 0 1 2 1 2 1 2 2 0 2 0 1 1 0 2 1 1 2 1 1 0 2 2 0 1 1 1 1 1 1 0 2 2 2 2 0 0 0 0 2 2 1 0 2 0 0 2 0 2 1 0 2 2 1 1 2 0 2 0 2 0 0 2 2\\n\", \"100 5 100\\n-45 -36 -55 -96 -49 8 -88 -87 -82 51 27 -33 -65 0 -1 -42 -58 -19 -11 77 -54 14 -49 -90 -35 -9 -2 -48 0 -21 44 22 37 -32 -81 64 28 85 -77 44 18 -74 -50 62 8 -74 41 -15 -91 -93 -2 57 -12 2 -2 -90 84 6 -62 -14 72 85 86 -71 -59 57 -89 -4 78 56 56 24 -15 -78 27 -30 -31 -52 -92 50 43 85 -79 -14 -96 -1 -40 -7 16 18 99 -9 27 6 -96 -36 51 68 -17 55\\n\", \"4 35529 390662471\\n7178385 -402086 21850337 -1012896\\n\", \"2 176474 610141845\\n-1063752 -6637683\\n\", \"1 157330 640126408\\n-1723747\\n\", \"100 21063 1\\n-2 -1 -1 -2 -1 -2 -1 0 0 -2 0 0 0 0 0 0 0 -1 -1 -2 2 2 0 2 2 2 2 0 1 1 2 1 2 1 0 1 2 2 0 2 0 2 1 1 2 1 0 1 1 0 1 0 0 0 0 0 0 2 1 0 2 2 0 2 0 1 1 2 1 2 2 1 1 1 1 1 0 2 2 2 2 2 2 0 0 0 0 0 2 1 0 1 0 0 2 1 0 2 0 0\\n\", \"1 2 1000000000\\n-1000000000\\n\", \"2 1 1000\\n-1000000000 1000000000\\n\", \"5 200000 1000000000\\n1 2 3 4 5\\n\", \"10 200000 1000000000\\n1 5 2 6890 321 6 8 -123 9 10\\n\", \"4 1 1\\n-2 -2 1 1\\n\"], \"outputs\": [\"5 4 3 5 -1 \\n\", \"5 4 0 5 5 \\n\", \"5 1 4 5 5 \\n\", \"5 11 -5 \\n\", \"-1 -1 -2 0 -2 -1 0 0 0 0 2 2 2 2 2 1 0 1 1 1 1 0 1 0 2 0 0 1 1 1 2 2 1 0 0 2 0 1 2 1 2 1 2 2 0 2 0 1 1 0 2 1 1 2 1 1 0 2 2 0 1 1 1 1 1 1 0 2 2 2 2 0 0 0 0 2 2 1 0 2 0 0 2 0 2 1 0 2 2 1 1 2 0 2 0 2 0 0 2 2 \\n\", \"-45 -36 -55 -96 -49 8 -88 -87 -82 51 27 -33 -65 -100 -101 -42 -58 -19 -11 77 -54 14 -49 -90 -35 -9 -102 -48 100 -21 44 22 37 -32 -81 64 28 85 -77 44 18 -74 -50 62 8 -74 41 -15 -91 -93 -2 57 -12 2 -2 -90 84 6 -62 -14 72 85 86 -71 -59 57 -89 -4 78 56 56 24 -15 -78 27 -30 -31 -52 -92 50 43 85 -79 -14 -96 -101 -40 -7 16 18 99 -9 27 6 -96 -36 51 68 -17 55 \\n\", \"3469871245807 3470254327807 3469885917759 -3469865080318 \\n\", \"53837084913513 -53837092614948 \\n\", \"-100711089494387 \\n\", \"-212 -212 -212 -212 -212 -212 -212 212 212 -212 212 212 212 212 212 212 212 -212 -212 -212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 212 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 211 \\n\", \"-3000000000 \\n\", \"-1000001000 1000000000 \\n\", \"-39999999999999 40000000000002 40000000000003 40000000000004 40000000000005 \\n\", \"20000000000001 20000000000005 20000000000002 20000000006890 20000000000321 20000000000006 20000000000008 -20000000000123 20000000000009 20000000000010 \\n\", \"-2 -2 0 1 \\n\"]}", "source": "primeintellect"}
Recently Maxim has found an array of n integers, needed by no one. He immediately come up with idea of changing it: he invented positive integer x and decided to add or subtract it from arbitrary array elements. Formally, by applying single operation Maxim chooses integer i (1 ≤ i ≤ n) and replaces the i-th element of array a_{i} either with a_{i} + x or with a_{i} - x. Please note that the operation may be applied more than once to the same position. Maxim is a curious minimalis, thus he wants to know what is the minimum value that the product of all array elements (i.e. $\prod_{i = 1}^{n} a_{i}$) can reach, if Maxim would apply no more than k operations to it. Please help him in that. -----Input----- The first line of the input contains three integers n, k and x (1 ≤ n, k ≤ 200 000, 1 ≤ x ≤ 10^9) — the number of elements in the array, the maximum number of operations and the number invented by Maxim, respectively. The second line contains n integers a_1, a_2, ..., a_{n} ($|a_{i}|\leq 10^{9}$) — the elements of the array found by Maxim. -----Output----- Print n integers b_1, b_2, ..., b_{n} in the only line — the array elements after applying no more than k operations to the array. In particular, $a_{i} \equiv b_{i} \operatorname{mod} x$ should stay true for every 1 ≤ i ≤ n, but the product of all array elements should be minimum possible. If there are multiple answers, print any of them. -----Examples----- Input 5 3 1 5 4 3 5 2 Output 5 4 3 5 -1 Input 5 3 1 5 4 3 5 5 Output 5 4 0 5 5 Input 5 3 1 5 4 4 5 5 Output 5 1 4 5 5 Input 3 2 7 5 4 2 Output 5 11 -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\": [\"10 6 100\\n17 5\\n\", \"11 6 100\\n12 5\\n\", \"25 27 91\\n10 87\\n\", \"79 4 68\\n9 65\\n\", \"9 1 20\\n4 19\\n\", \"6 6 100\\n12 5\\n\", \"9 76 78\\n86 69\\n\", \"62 21 10\\n47 2\\n\", \"4 1 2\\n10 1\\n\", \"1 1 2\\n3 1\\n\", \"14 5 2\\n99 1\\n\", \"20 1 5\\n8 4\\n\", \"12 12 19\\n83 8\\n\", \"5 12 11\\n4 2\\n\", \"34 14 18\\n74 14\\n\"], \"outputs\": [\"4\\nSTRIKE\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"2\\nSTRIKE\\nSTRIKE\\n\", \"1\\nSTRIKE\\n\", \"21\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"53\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"2\\nSTRIKE\\nSTRIKE\\n\", \"9\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"3\\nSTRIKE\\nSTRIKE\\nSTRIKE\\n\", \"16\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"5\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"26\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"17\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"11\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nSTRIKE\\nHEAL\\nSTRIKE\\nHEAL\\nSTRIKE\\nSTRIKE\\n\", \"1\\nSTRIKE\\n\", \"16\\nSTRIKE\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nHEAL\\nHEAL\\nHEAL\\nHEAL\\nSTRIKE\\nSTRIKE\\n\"]}", "source": "primeintellect"}
Vova is again playing some computer game, now an RPG. In the game Vova's character received a quest: to slay the fearsome monster called Modcrab. After two hours of playing the game Vova has tracked the monster and analyzed its tactics. The Modcrab has h_2 health points and an attack power of a_2. Knowing that, Vova has decided to buy a lot of strong healing potions and to prepare for battle. Vova's character has h_1 health points and an attack power of a_1. Also he has a large supply of healing potions, each of which increases his current amount of health points by c_1 when Vova drinks a potion. All potions are identical to each other. It is guaranteed that c_1 > a_2. The battle consists of multiple phases. In the beginning of each phase, Vova can either attack the monster (thus reducing its health by a_1) or drink a healing potion (it increases Vova's health by c_1; Vova's health can exceed h_1). Then, if the battle is not over yet, the Modcrab attacks Vova, reducing his health by a_2. The battle ends when Vova's (or Modcrab's) health drops to 0 or lower. It is possible that the battle ends in a middle of a phase after Vova's attack. Of course, Vova wants to win the fight. But also he wants to do it as fast as possible. So he wants to make up a strategy that will allow him to win the fight after the minimum possible number of phases. Help Vova to make up a strategy! You may assume that Vova never runs out of healing potions, and that he can always win. -----Input----- The first line contains three integers h_1, a_1, c_1 (1 ≤ h_1, a_1 ≤ 100, 2 ≤ c_1 ≤ 100) — Vova's health, Vova's attack power and the healing power of a potion. The second line contains two integers h_2, a_2 (1 ≤ h_2 ≤ 100, 1 ≤ a_2 < c_1) — the Modcrab's health and his attack power. -----Output----- In the first line print one integer n denoting the minimum number of phases required to win the battle. Then print n lines. i-th line must be equal to HEAL if Vova drinks a potion in i-th phase, or STRIKE if he attacks the Modcrab. The strategy must be valid: Vova's character must not be defeated before slaying the Modcrab, and the monster's health must be 0 or lower after Vova's last action. If there are multiple optimal solutions, print any of them. -----Examples----- Input 10 6 100 17 5 Output 4 STRIKE HEAL STRIKE STRIKE Input 11 6 100 12 5 Output 2 STRIKE STRIKE -----Note----- In the first example Vova's character must heal before or after his first attack. Otherwise his health will drop to zero in 2 phases while he needs 3 strikes to win. In the second example no healing needed, two strikes are enough to get monster to zero health and win with 6 health left. 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 3 2\\n**.\\n...\\n\", \"1 2 2\\n..\\n\", \"3 3 4\\n.*.\\n*.*\\n.*.\\n\", \"4 4 2\\n....\\n....\\n....\\n....\\n\", \"1 1 1\\n.\\n\", \"1 1 1\\n*\\n\", \"2 2 2\\n.*\\n*.\\n\", \"1 1 1000\\n.\\n\", \"1 1 2000\\n*\\n\", \"5 5 3\\n.....\\n.....\\n*...*\\n*....\\n.*...\\n\", \"3 3 1\\n.*.\\n.*.\\n.*.\\n\", \"2 3 1\\n**.\\n...\\n\", \"2 2 1\\n..\\n..\\n\", \"3 3 1\\n...\\n...\\n...\\n\", \"2 3 1\\n...\\n...\\n\"], \"outputs\": [\"3\\n\", \"1\\n\", \"0\\n\", \"24\\n\", \"1\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"0\\n\", \"18\\n\", \"6\\n\", \"4\\n\", \"4\\n\", \"9\\n\", \"6\\n\"]}", "source": "primeintellect"}
Suppose that you are in a campus and have to go for classes day by day. As you may see, when you hurry to a classroom, you surprisingly find that many seats there are already occupied. Today you and your friends went for class, and found out that some of the seats were occupied. The classroom contains $n$ rows of seats and there are $m$ seats in each row. Then the classroom can be represented as an $n \times m$ matrix. The character '.' represents an empty seat, while '*' means that the seat is occupied. You need to find $k$ consecutive empty seats in the same row or column and arrange those seats for you and your friends. Your task is to find the number of ways to arrange the seats. Two ways are considered different if sets of places that students occupy differs. -----Input----- The first line contains three positive integers $n,m,k$ ($1 \leq n, m, k \leq 2\,000$), where $n,m$ represent the sizes of the classroom and $k$ is the number of consecutive seats you need to find. Each of the next $n$ lines contains $m$ characters '.' or '*'. They form a matrix representing the classroom, '.' denotes an empty seat, and '*' denotes an occupied seat. -----Output----- A single number, denoting the number of ways to find $k$ empty seats in the same row or column. -----Examples----- Input 2 3 2 **. ... Output 3 Input 1 2 2 .. Output 1 Input 3 3 4 .*. *.* .*. Output 0 -----Note----- In the first sample, there are three ways to arrange those seats. You can take the following seats for your arrangement. $(1,3)$, $(2,3)$ $(2,2)$, $(2,3)$ $(2,1)$, $(2,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\": [\"4\\nabab\\naabb\\n\", \"1\\na\\nb\\n\", \"8\\nbabbaabb\\nabababaa\\n\", \"2\\nbb\\nbb\\n\", \"10\\naaaaabbbbb\\nababaaaaab\\n\", \"10\\nbbbbbbbbbb\\naaaaaaaaaa\\n\", \"6\\naaaaaa\\naabaaa\\n\", \"1\\nb\\nb\\n\", \"5\\nbaaaa\\nabaaa\\n\", \"10\\naabaaaaaab\\nbaaaaaabbb\\n\", \"100\\nbbbabbababbbbbbabbbbbbbbabbbbbbbbbbbbbbbaabbbbbbbbbbbbbabbabaababbaabbbbbbbbbbaabbbbbbaabbbbbaabbbbb\\nbabababbbbbbabaaabbbbbbbaabbbbaabbbbbbabbbbbbbbababbbbabbbbbbbbbbbabbbbbbbbabbbbbbbbbbbbbbbbabbbbaab\\n\", \"101\\nbabbbbabbbbaabbbbbbbabbbababababbbbbbbbabaababbababbaaabbababbbbbbbbbaabbbababbbbbabbbbbabbbaabbbaabb\\nbbabbbbbbabbbbbbbbbbbabbbbbbbbbbabbabbbbbbbbbbbabbababbbabbabbbbbbbbbbbbbaabbbabbbbabbabbbbababbbbbab\\n\", \"100\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\naaaaaaaaaaaaaaaaaaabaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\n\", \"10\\naaaaaaaaaa\\nbbbbbbbbbb\\n\", \"2\\nab\\nba\\n\"], \"outputs\": [\"2\\n3 3\\n3 2\\n\", \"-1\\n\", \"3\\n2 6\\n1 3\\n7 8\\n\", \"0\\n\", \"3\\n2 4\\n6 7\\n8 9\\n\", \"5\\n1 2\\n3 4\\n5 6\\n7 8\\n9 10\\n\", \"-1\\n\", \"0\\n\", \"2\\n2 2\\n2 1\\n\", \"3\\n1 8\\n9 9\\n9 3\\n\", \"16\\n7 9\\n41 42\\n56 59\\n61 62\\n64 68\\n79 80\\n87 88\\n94 95\\n2 6\\n13 15\\n17 26\\n31 32\\n39 48\\n50 55\\n76 93\\n98 99\\n\", \"20\\n2 7\\n12 13\\n21 25\\n27 29\\n31 40\\n42 43\\n45 50\\n54 55\\n58 70\\n71 77\\n83 89\\n93 98\\n3 10\\n22 33\\n36 51\\n57 74\\n79 84\\n87 92\\n99 99\\n99 100\\n\", \"-1\\n\", \"5\\n1 2\\n3 4\\n5 6\\n7 8\\n9 10\\n\", \"2\\n1 1\\n1 2\\n\"]}", "source": "primeintellect"}
Monocarp has got two strings $s$ and $t$ having equal length. Both strings consist of lowercase Latin letters "a" and "b". Monocarp wants to make these two strings $s$ and $t$ equal to each other. He can do the following operation any number of times: choose an index $pos_1$ in the string $s$, choose an index $pos_2$ in the string $t$, and swap $s_{pos_1}$ with $t_{pos_2}$. You have to determine the minimum number of operations Monocarp has to perform to make $s$ and $t$ equal, and print any optimal sequence of operations — or say that it is impossible to make these strings equal. -----Input----- The first line contains one integer $n$ $(1 \le n \le 2 \cdot 10^{5})$ — the length of $s$ and $t$. The second line contains one string $s$ consisting of $n$ characters "a" and "b". The third line contains one string $t$ consisting of $n$ characters "a" and "b". -----Output----- If it is impossible to make these strings equal, print $-1$. Otherwise, in the first line print $k$ — the minimum number of operations required to make the strings equal. In each of the next $k$ lines print two integers — the index in the string $s$ and the index in the string $t$ that should be used in the corresponding swap operation. -----Examples----- Input 4 abab aabb Output 2 3 3 3 2 Input 1 a b Output -1 Input 8 babbaabb abababaa Output 3 2 6 1 3 7 8 -----Note----- In the first example two operations are enough. For example, you can swap the third letter in $s$ with the third letter in $t$. Then $s = $ "abbb", $t = $ "aaab". Then swap the third letter in $s$ and the second letter in $t$. Then both $s$ and $t$ are equal to "abab". In the second example it's impossible to make two strings equal. 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 0\\n\", \"4 4\\n1 2 1\\n1 3 0\\n2 3 1\\n3 4 1\\n\", \"8 9\\n1 2 0\\n8 3 0\\n2 3 1\\n1 4 1\\n8 7 0\\n1 5 1\\n4 6 1\\n5 7 0\\n6 8 0\\n\", \"9 10\\n1 2 0\\n2 3 0\\n1 4 1\\n4 5 1\\n4 6 1\\n6 7 1\\n1 7 0\\n1 8 0\\n7 8 0\\n9 7 1\\n\", \"5 6\\n1 2 0\\n3 2 0\\n5 1 1\\n1 3 1\\n5 3 0\\n4 3 1\\n\", \"15 31\\n6 2 0\\n5 15 1\\n2 3 1\\n6 9 1\\n13 12 0\\n2 7 0\\n15 3 0\\n3 5 1\\n3 8 1\\n5 8 1\\n1 9 1\\n8 4 0\\n13 2 1\\n9 12 0\\n9 2 1\\n6 13 1\\n3 1 0\\n14 9 0\\n15 2 1\\n10 15 0\\n7 10 0\\n2 8 1\\n11 7 0\\n10 9 1\\n12 11 1\\n7 15 0\\n12 2 0\\n13 11 1\\n4 6 0\\n12 7 0\\n12 1 1\\n\", \"5 10\\n1 2 1\\n1 3 0\\n1 4 0\\n1 5 0\\n2 3 0\\n2 4 1\\n2 5 0\\n3 4 1\\n3 5 1\\n4 5 0\\n\", \"5 10\\n1 2 0\\n1 3 1\\n1 4 0\\n1 5 0\\n2 3 0\\n2 4 0\\n2 5 1\\n3 4 0\\n3 5 0\\n4 5 1\\n\", \"5 10\\n1 2 0\\n1 3 0\\n1 4 0\\n1 5 0\\n2 3 0\\n2 4 0\\n2 5 0\\n3 4 0\\n3 5 0\\n4 5 0\\n\", \"13 58\\n9 12 0\\n8 11 0\\n4 8 0\\n2 12 1\\n9 1 1\\n10 6 1\\n5 2 1\\n3 9 0\\n8 3 0\\n9 10 0\\n8 5 1\\n11 3 0\\n11 1 0\\n2 6 1\\n12 3 1\\n11 6 0\\n1 12 0\\n2 1 1\\n11 13 0\\n6 8 1\\n11 5 1\\n8 9 0\\n1 4 0\\n12 7 1\\n5 12 0\\n11 7 0\\n10 2 0\\n5 10 1\\n9 4 1\\n7 5 1\\n2 11 0\\n13 12 1\\n10 3 1\\n1 13 0\\n7 1 0\\n6 3 0\\n7 13 0\\n4 10 0\\n7 10 1\\n12 8 1\\n2 13 0\\n3 1 1\\n5 13 0\\n4 3 0\\n8 1 0\\n4 12 1\\n11 10 1\\n10 1 1\\n1 6 0\\n8 13 1\\n5 4 0\\n9 11 0\\n10 13 1\\n8 2 0\\n10 12 0\\n6 12 0\\n1 5 0\\n11 12 0\\n\", \"6 6\\n1 2 1\\n2 3 1\\n3 4 1\\n3 5 1\\n4 6 1\\n4 5 1\\n\", \"9 12\\n1 2 1\\n2 3 1\\n3 1 0\\n2 4 1\\n4 5 0\\n2 5 0\\n4 6 0\\n4 7 1\\n6 7 0\\n5 8 1\\n8 9 1\\n5 9 1\\n\", \"12 48\\n9 5 0\\n6 3 0\\n2 4 1\\n6 8 1\\n9 2 1\\n7 2 0\\n3 12 1\\n6 12 1\\n2 5 0\\n11 4 1\\n7 12 0\\n8 11 1\\n11 2 1\\n2 6 0\\n9 1 0\\n1 3 0\\n8 12 0\\n11 5 1\\n10 6 0\\n10 9 1\\n1 12 1\\n10 12 1\\n1 10 0\\n10 2 0\\n1 8 0\\n7 4 1\\n9 3 0\\n11 7 0\\n4 3 0\\n1 2 0\\n8 9 0\\n11 12 0\\n12 9 1\\n7 5 0\\n3 5 0\\n5 6 1\\n3 10 0\\n11 10 1\\n2 3 0\\n4 9 0\\n1 5 1\\n10 5 1\\n6 9 1\\n10 4 0\\n9 7 0\\n4 12 0\\n3 8 1\\n6 11 1\\n\", \"6 6\\n1 2 1\\n2 3 1\\n3 4 1\\n3 5 1\\n5 6 1\\n4 5 1\\n\", \"6 7\\n1 2 1\\n1 3 1\\n2 4 1\\n2 5 1\\n3 5 1\\n3 6 1\\n5 6 1\\n\"], \"outputs\": [\"1\\n1 2 1\\n\", \"3\\n1 2 0\\n1 3 1\\n2 3 0\\n\", \"3\\n2 3 0\\n1 5 0\\n6 8 1\\n\", \"5\\n1 4 0\\n4 5 0\\n4 6 0\\n6 7 0\\n1 7 1\\n\", \"2\\n1 3 0\\n4 3 0\\n\", \"18\\n5 15 0\\n2 3 0\\n6 9 0\\n15 3 1\\n3 5 0\\n3 8 0\\n5 8 0\\n1 9 0\\n13 2 0\\n9 2 0\\n6 13 0\\n3 1 1\\n15 2 0\\n2 8 0\\n10 9 0\\n12 11 0\\n13 11 0\\n12 1 0\\n\", \"5\\n1 2 0\\n1 5 1\\n2 4 0\\n3 4 0\\n3 5 0\\n\", \"4\\n1 3 0\\n1 5 1\\n2 5 0\\n4 5 0\\n\", \"1\\n1 5 1\\n\", \"25\\n2 12 0\\n9 1 0\\n10 6 0\\n5 2 0\\n8 5 0\\n2 6 0\\n12 3 0\\n2 1 0\\n6 8 0\\n11 5 0\\n12 7 0\\n5 10 0\\n9 4 0\\n7 5 0\\n13 12 0\\n10 3 0\\n1 13 1\\n7 10 0\\n12 8 0\\n3 1 0\\n4 12 0\\n11 10 0\\n10 1 0\\n8 13 0\\n10 13 0\\n\", \"2\\n3 5 0\\n4 5 0\\n\", \"6\\n2 3 0\\n2 4 0\\n2 5 1\\n4 7 0\\n5 8 0\\n8 9 0\\n\", \"20\\n2 4 0\\n6 8 0\\n9 2 0\\n3 12 0\\n6 12 0\\n11 4 0\\n8 11 0\\n11 2 0\\n11 5 0\\n10 9 0\\n10 12 0\\n7 4 0\\n12 9 0\\n5 6 0\\n11 10 0\\n1 5 0\\n10 5 0\\n6 9 0\\n3 8 0\\n6 11 0\\n\", \"2\\n3 4 0\\n4 5 0\\n\", \"5\\n1 2 0\\n2 4 0\\n2 5 0\\n3 5 0\\n5 6 0\\n\"]}", "source": "primeintellect"}
Breaking Good is a new video game which a lot of gamers want to have. There is a certain level in the game that is really difficult even for experienced gamers. Walter William, the main character of the game, wants to join a gang called Los Hermanos (The Brothers). The gang controls the whole country which consists of n cities with m bidirectional roads connecting them. There is no road is connecting a city to itself and for any two cities there is at most one road between them. The country is connected, in the other words, it is possible to reach any city from any other city using the given roads. The roads aren't all working. There are some roads which need some more work to be performed to be completely functioning. The gang is going to rob a bank! The bank is located in city 1. As usual, the hardest part is to escape to their headquarters where the police can't get them. The gang's headquarters is in city n. To gain the gang's trust, Walter is in charge of this operation, so he came up with a smart plan. First of all the path which they are going to use on their way back from city 1 to their headquarters n must be as short as possible, since it is important to finish operation as fast as possible. Then, gang has to blow up all other roads in country that don't lay on this path, in order to prevent any police reinforcements. In case of non-working road, they don't have to blow up it as it is already malfunctional. If the chosen path has some roads that doesn't work they'll have to repair those roads before the operation. Walter discovered that there was a lot of paths that satisfied the condition of being shortest possible so he decided to choose among them a path that minimizes the total number of affected roads (both roads that have to be blown up and roads to be repaired). Can you help Walter complete his task and gain the gang's trust? -----Input----- The first line of input contains two integers n, m (2 ≤ n ≤ 10^5, $0 \leq m \leq \operatorname{min}(\frac{n(n - 1)}{2}, 10^{5})$), the number of cities and number of roads respectively. In following m lines there are descriptions of roads. Each description consists of three integers x, y, z (1 ≤ x, y ≤ n, $z \in \{0,1 \}$) meaning that there is a road connecting cities number x and y. If z = 1, this road is working, otherwise it is not. -----Output----- In the first line output one integer k, the minimum possible number of roads affected by gang. In the following k lines output three integers describing roads that should be affected. Each line should contain three integers x, y, z (1 ≤ x, y ≤ n, $z \in \{0,1 \}$), cities connected by a road and the new state of a road. z = 1 indicates that the road between cities x and y should be repaired and z = 0 means that road should be blown up. You may output roads in any order. Each affected road should appear exactly once. You may output cities connected by a single road in any order. If you output a road, it's original state should be different from z. After performing all operations accroding to your plan, there should remain working only roads lying on some certain shortest past between city 1 and n. If there are multiple optimal answers output any. -----Examples----- Input 2 1 1 2 0 Output 1 1 2 1 Input 4 4 1 2 1 1 3 0 2 3 1 3 4 1 Output 3 1 2 0 1 3 1 2 3 0 Input 8 9 1 2 0 8 3 0 2 3 1 1 4 1 8 7 0 1 5 1 4 6 1 5 7 0 6 8 0 Output 3 2 3 0 1 5 0 6 8 1 -----Note----- In the first test the only path is 1 - 2 In the second test the only shortest path is 1 - 3 - 4 In the third test there are multiple shortest paths but the optimal is 1 - 4 - 6 - 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\": [\"abab\\nba\\n\", \"defineintlonglong\\nsignedmain\\n\", \"rotator\\nrotator\\n\", \"cacdcdbbbb\\nbdcaccdbbb\\n\", \"f\\np\\n\", \"baabbaaaaa\\nababa\\n\", \"cbaabccadacadbaacbadddcdabcacdbbabccbbcbbcbbaadcabadcbdcadddccbbbbdacdbcbaddacaadbcddadbabbdbbacabdd\\ncccdacdabbacbbcacdca\\n\", \"tqlrrtidhfpgevosrsya\\nysrsvgphitrrqtldfeoa\\n\", \"d\\nd\\n\", \"ebkkiajfffiiifcgheijbcdafkcdckgdakhicebfgkeiffjbkdbgjeb\\nebffigfbciadcdfdbiehgciiifakbekijfffjcakckgkhekejbkdgjb\\n\", \"acacdddadaddcbbbbdacb\\nbabbbcadddacacdaddbdc\\n\", \"dadebcabefcbaffce\\ncffbfcaddebabecae\\n\", \"babbaaababbbbabbaaaababbbaabababbaabbaababbaaabaabbabaabbaababababbaabaaabaaaaababbaabaaaaabaabbabaaababbbb\\nbbaabbbbabbbbaaaaaababbbabaaabbbbabababbbaabbbbbabaababbaabaaabaabbababababaaaaabaabbabaaabaaaaaaaaaaaaabbb\\n\", \"yz\\nzy\\n\", \"eternalalexandersookeustzeouuanisafqaqautomaton\\nnoiol\\n\"], \"outputs\": [\"12\", \"0\", \"4\", \"24\", \"0\", \"120\", \"773806867\", \"2\", \"2\", \"12\", \"64\", \"2\", \"284471294\", \"2\", \"1920\"]}", "source": "primeintellect"}
Kaavi, the mysterious fortune teller, deeply believes that one's fate is inevitable and unavoidable. Of course, she makes her living by predicting others' future. While doing divination, Kaavi believes that magic spells can provide great power for her to see the future. [Image]  Kaavi has a string $T$ of length $m$ and all the strings with the prefix $T$ are magic spells. Kaavi also has a string $S$ of length $n$ and an empty string $A$. During the divination, Kaavi needs to perform a sequence of operations. There are two different operations: Delete the first character of $S$ and add it at the front of $A$. Delete the first character of $S$ and add it at the back of $A$. Kaavi can perform no more than $n$ operations. To finish the divination, she wants to know the number of different operation sequences to make $A$ a magic spell (i.e. with the prefix $T$). As her assistant, can you help her? The answer might be huge, so Kaavi only needs to know the answer modulo $998\,244\,353$. Two operation sequences are considered different if they are different in length or there exists an $i$ that their $i$-th operation is different. A substring is a contiguous sequence of characters within a string. A prefix of a string $S$ is a substring of $S$ that occurs at the beginning of $S$. -----Input----- The first line contains a string $S$ of length $n$ ($1 \leq n \leq 3000$). The second line contains a string $T$ of length $m$ ($1 \leq m \leq n$). Both strings contain only lowercase Latin letters. -----Output----- The output contains only one integer  — the answer modulo $998\,244\,353$. -----Examples----- Input abab ba Output 12 Input defineintlonglong signedmain Output 0 Input rotator rotator Output 4 Input cacdcdbbbb bdcaccdbbb Output 24 -----Note----- The first test: $\text{baba abab bbaa baab baab}$ The red ones are the magic spells. In the first operation, Kaavi can either add the first character "a" at the front or the back of $A$, although the results are the same, they are considered as different operations. So the answer is $6\times2=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\": [\"10 15 2\\n2\\n10 13\\n\", \"8 17 3\\n4\\n3 4 5 8\\n\", \"7 14 3\\n2\\n1 2\\n\", \"30 70 10\\n3\\n30 32 35\\n\", \"21 56 7\\n5\\n1 2 3 4 5\\n\", \"10 1000000000 25\\n20\\n1 1 5 7 8 10 12 22 44 47 73 77 82 83 89 141 142 168 195 199\\n\", \"30 60 3\\n10\\n1 5 6 10 12 13 18 23 24 25\\n\", \"61 1000000000 13\\n55\\n29 72 85 94 103 123 125 144 147 153 154 184 189 192 212 234 247 265 292 296 299 304 309 365 378 379 393 401 414 417 421 427 439 441 480 500 509 515 522 539 571 582 623 630 634 635 643 649 654 679 680 686 747 748 775\\n\", \"117 120 3\\n0\\n\", \"37 3813 32\\n117\\n1 1 4 5 6 8 10 13 13 16 18 19 20 23 30 32 33 38 49 59 66 69 96 157 160 183 205 292 301 320 349 360 370 372 384 400 410 413 423 434 434 445 451 463 464 490 494 496 497 517 528 532 556 572 607 647 668 689 708 729 748 806 819 879 905 905 915 925 928 931 959 970 1133 1146 1150 1156 1172 1189 1193 1218 1228 1233 1247 1297 1383 1447 1468 1512 1539 1550 1634 1635 1702 1836 1845 1866 1880 2068 2082 2143 2146 2167 2234 2239 2277 2331 2351 2432 2478 2592 2684 2863 2885 3043 3141 3258 3426\\n\", \"100000000000 200000000000 10000000000\\n10\\n1 1 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000 110000000000\\n\", \"1 2 1\\n0\\n\", \"50 230 10\\n20\\n50 60 70 80 90 100 110 120 130 140 150 160 170 180 190 200 210 220 230 240\\n\", \"100000000000 100000000005 2\\n0\\n\", \"333 500 5\\n1\\n3000\\n\"], \"outputs\": [\"12\", \"2\", \"0\", \"60\", \"0\", \"510\", \"4\", \"360\", \"117\", \"3781\", \"109999999999\", \"1\", \"49\", \"100000000000\", \"333\"]}", "source": "primeintellect"}
Finally! Vasya have come of age and that means he can finally get a passport! To do it, he needs to visit the passport office, but it's not that simple. There's only one receptionist at the passport office and people can queue up long before it actually opens. Vasya wants to visit the passport office tomorrow. He knows that the receptionist starts working after t_{s} minutes have passed after midnight and closes after t_{f} minutes have passed after midnight (so that (t_{f} - 1) is the last minute when the receptionist is still working). The receptionist spends exactly t minutes on each person in the queue. If the receptionist would stop working within t minutes, he stops serving visitors (other than the one he already serves). Vasya also knows that exactly n visitors would come tomorrow. For each visitor Vasya knows the point of time when he would come to the passport office. Each visitor queues up and doesn't leave until he was served. If the receptionist is free when a visitor comes (in particular, if the previous visitor was just served and the queue is empty), the receptionist begins to serve the newcomer immediately. [Image] "Reception 1" For each visitor, the point of time when he would come to the passport office is positive. Vasya can come to the office at the time zero (that is, at midnight) if he needs so, but he can come to the office only at integer points of time. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and stand in the queue after the last of them. Vasya wants to come at such point of time that he will be served by the receptionist, and he would spend the minimum possible time in the queue. Help him! -----Input----- The first line contains three integers: the point of time when the receptionist begins to work t_{s}, the point of time when the receptionist stops working t_{f} and the time the receptionist spends on each visitor t. The second line contains one integer n — the amount of visitors (0 ≤ n ≤ 100 000). The third line contains positive integers in non-decreasing order — the points of time when the visitors arrive to the passport office. All times are set in minutes and do not exceed 10^12; it is guaranteed that t_{s} < t_{f}. It is also guaranteed that Vasya can arrive at the passport office at such a point of time that he would be served by the receptionist. -----Output----- Print single non-negative integer — the point of time when Vasya should arrive at the passport office. If Vasya arrives at the passport office at the same time with several other visitors, he yields to them and queues up the last. If there are many answers, you can print any of them. -----Examples----- Input 10 15 2 2 10 13 Output 12 Input 8 17 3 4 3 4 5 8 Output 2 -----Note----- In the first example the first visitor comes exactly at the point of time when the receptionist begins to work, and he is served for two minutes. At 12 minutes after the midnight the receptionist stops serving the first visitor, and if Vasya arrives at this moment, he will be served immediately, because the next visitor would only come at 13 minutes after midnight. In the second example, Vasya has to come before anyone else to be served. 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\\n\", \"10 3\\n\", \"314159265 35\\n\", \"1000000000 100\\n\", \"900000000 89\\n\", \"899999999 92\\n\", \"900000001 97\\n\", \"243551227 80\\n\", \"1 100\\n\", \"779283406 99\\n\", \"16 20\\n\", \"123454321 88\\n\", \"123454320 80\\n\", \"123454322 68\\n\", \"2 100\\n\"], \"outputs\": [\"5\\n\", \"147\\n\", \"457397712\\n\", \"926307829\\n\", \"780773257\\n\", \"409296605\\n\", \"212445492\\n\", \"644200854\\n\", \"1\\n\", \"487694749\\n\", \"222760788\\n\", \"968285458\\n\", \"160599768\\n\", \"73286229\\n\", \"470199269\\n\"]}", "source": "primeintellect"}
Find the number of sequences of length K consisting of positive integers such that the product of any two adjacent elements is at most N, modulo 10^9+7. -----Constraints----- - 1\leq N\leq 10^9 - 1 2\leq K\leq 100 (fixed at 21:33 JST) - N and K are integers. -----Input----- Input is given from Standard Input in the following format: N K -----Output----- Print the number of sequences, modulo 10^9+7. -----Sample Input----- 3 2 -----Sample Output----- 5 (1,1), (1,2), (1,3), (2,1), and (3,1) satisfy the condition. 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 4\\n\", \"12 21 10\\n\", \"3 1 8\\n\", \"100 100 1000000\\n\", \"100 100 1\\n\", \"22 75 24126\\n\", \"45 72 83481\\n\", \"47 29 44734\\n\", \"2 75 25\\n\", \"82 84 416241\\n\", \"56 32 30430\\n\", \"28 37 11105\\n\", \"39 18 23359\\n\", \"79 6 29018\\n\", \"68 68 313904\\n\"], \"outputs\": [\"45.0000000000\\n\", \"89.7834636934\\n\", \"4.2363947991\\n\", \"0.0000000000\\n\", \"89.9998854084\\n\", \"66.3790171829\\n\", \"53.8288157430\\n\", \"20.4206366709\\n\", \"89.7453537677\\n\", \"28.3216596827\\n\", \"43.2962287317\\n\", \"59.9115059975\\n\", \"7.7168423353\\n\", \"1.9580634609\\n\", \"0.1924235310\\n\"]}", "source": "primeintellect"}
Takahashi has a water bottle with the shape of a rectangular prism whose base is a square of side a~\mathrm{cm} and whose height is b~\mathrm{cm}. (The thickness of the bottle can be ignored.) We will pour x~\mathrm{cm}^3 of water into the bottle, and gradually tilt the bottle around one of the sides of the base. When will the water be spilled? More formally, find the maximum angle in which we can tilt the bottle without spilling any water. -----Constraints----- - All values in input are integers. - 1 \leq a \leq 100 - 1 \leq b \leq 100 - 1 \leq x \leq a^2b -----Input----- Input is given from Standard Input in the following format: a b x -----Output----- Print the maximum angle in which we can tilt the bottle without spilling any water, in degrees. Your output will be judged as correct when the absolute or relative error from the judge's output is at most 10^{-6}. -----Sample Input----- 2 2 4 -----Sample Output----- 45.0000000000 This bottle has a cubic shape, and it is half-full. The water gets spilled when we tilt the bottle more than 45 degrees. 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 4 5\\n\", \"1\\n1\\n\", \"1\\n1000000\\n\", \"2\\n2 999999\\n\", \"9\\n1 2 3 100 500000 500001 999901 999997 999999\\n\", \"3\\n999998 999999 1000000\\n\", \"3\\n1 2 3\\n\", \"3\\n5 345435 999996\\n\", \"6\\n1 10 100 1000 10000 1000000\\n\", \"2\\n1 1000000\\n\", \"2\\n500000 500001\\n\", \"4\\n1 2 999999 1000000\\n\", \"10\\n63649 456347 779 458642 201571 534312 583774 283450 377377 79066\\n\", \"10\\n1 100000 199999 299998 399997 499996 599995 699994 799993 899992\\n\"], \"outputs\": [\"3\\n999996 999997 1000000 \\n\", \"1\\n1000000 \\n\", \"1\\n1 \\n\", \"2\\n1 1000000 \\n\", \"9\\n4 5 6 7 999994 999995 999996 999998 1000000 \\n\", \"3\\n1 2 3 \\n\", \"3\\n999998 999999 1000000 \\n\", \"3\\n1 654566 1000000 \\n\", \"6\\n2 990001 999001 999901 999991 999999 \\n\", \"2\\n2 999999 \\n\", \"2\\n1 1000000 \\n\", \"4\\n3 4 999997 999998 \\n\", \"10\\n416227 465689 541359 543654 622624 716551 798430 920935 936352 999222 \\n\", \"10\\n100009 200008 300007 400006 500005 600004 700003 800002 900001 1000000 \\n\"]}", "source": "primeintellect"}
Little Chris is very keen on his toy blocks. His teacher, however, wants Chris to solve more problems, so he decided to play a trick on Chris. There are exactly s blocks in Chris's set, each block has a unique number from 1 to s. Chris's teacher picks a subset of blocks X and keeps it to himself. He will give them back only if Chris can pick such a non-empty subset Y from the remaining blocks, that the equality holds: $\sum_{x \in X}(x - 1) = \sum_{y \in Y}(s - y)$ "Are you kidding me?", asks Chris. For example, consider a case where s = 8 and Chris's teacher took the blocks with numbers 1, 4 and 5. One way for Chris to choose a set is to pick the blocks with numbers 3 and 6, see figure. Then the required sums would be equal: (1 - 1) + (4 - 1) + (5 - 1) = (8 - 3) + (8 - 6) = 7. $\left. \begin{array}{l l l l l l}{1} & {2} & {3} & {4} & {5} & {6} & {7} & {8} \end{array} \right.$ However, now Chris has exactly s = 10^6 blocks. Given the set X of blocks his teacher chooses, help Chris to find the required set Y! -----Input----- The first line of input contains a single integer n (1 ≤ n ≤ 5·10^5), the number of blocks in the set X. The next line contains n distinct space-separated integers x_1, x_2, ..., x_{n} (1 ≤ x_{i} ≤ 10^6), the numbers of the blocks in X. Note: since the size of the input and output could be very large, don't use slow output techniques in your language. For example, do not use input and output streams (cin, cout) in C++. -----Output----- In the first line of output print a single integer m (1 ≤ m ≤ 10^6 - n), the number of blocks in the set Y. In the next line output m distinct space-separated integers y_1, y_2, ..., y_{m} (1 ≤ y_{i} ≤ 10^6), such that the required equality holds. The sets X and Y should not intersect, i.e. x_{i} ≠ y_{j} for all i, j (1 ≤ i ≤ n; 1 ≤ j ≤ m). It is guaranteed that at least one solution always exists. If there are multiple solutions, output any of them. -----Examples----- Input 3 1 4 5 Output 2 999993 1000000 Input 1 1 Output 1 1000000 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\\n\", \"4 3\\n\", \"5 1\\n\", \"1 100000\\n\", \"96024 12472\\n\", \"21741 3575\\n\", \"58934 6404\\n\", \"89829 8298\\n\", \"5499 1023\\n\", \"247 3270\\n\", \"58413 1253\\n\", \"100000 1\\n\", \"1 1\\n\", \"100000 14047\\n\"], \"outputs\": [\"2\\n4 5\\n\", \"3\\n2 3 1\\n\", \"-1\\n\", \"1\\n99999\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"-1\\n\", \"62\\n3228 3223 3212 3243 3230 3241 3263 3227 3255 3265 3262 3239 3261 3235 3219 3236 3231 3267 3210 3233 3258 3266 3237 3232 3252 3218 3251 3222 3242 3216 3256 3238 3253 3247 3214 3259 3217 3211 3269 3215 3220 3246 3221 3225 3264 3244 3250 3257 3209 3248 3234 3268 3260 3229 3254 3270 3245 3226 3213 3240 3249 3224\\n\", \"-1\\n\", \"-1\\n\", \"1\\n1\\n\", \"-1\\n\"]}", "source": "primeintellect"}
At the children's day, the child came to Picks's house, and messed his house up. Picks was angry at him. A lot of important things were lost, in particular the favorite set of Picks. Fortunately, Picks remembers something about his set S: its elements were distinct integers from 1 to limit; the value of $\sum_{x \in S} \text{lowbit}(x)$ was equal to sum; here lowbit(x) equals 2^{k} where k is the position of the first one in the binary representation of x. For example, lowbit(10010_2) = 10_2, lowbit(10001_2) = 1_2, lowbit(10000_2) = 10000_2 (binary representation). Can you help Picks and find any set S, that satisfies all the above conditions? -----Input----- The first line contains two integers: sum, limit (1 ≤ sum, limit ≤ 10^5). -----Output----- In the first line print an integer n (1 ≤ n ≤ 10^5), denoting the size of S. Then print the elements of set S in any order. If there are multiple answers, print any of them. If it's impossible to find a suitable set, print -1. -----Examples----- Input 5 5 Output 2 4 5 Input 4 3 Output 3 2 3 1 Input 5 1 Output -1 -----Note----- In sample test 1: lowbit(4) = 4, lowbit(5) = 1, 4 + 1 = 5. In sample test 2: lowbit(1) = 1, lowbit(2) = 2, lowbit(3) = 1, 1 + 2 + 1 = 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\\ngennady\\ngalya\\nboris\\nbill\\ntoshik\\nbilbo\\ntorin\\ngendalf\\nsmaug\\ngaladriel\\n\", \"1\\na\\na\\n\", \"2\\na\\na\\na\\na\\n\", \"2\\na\\nb\\na\\na\\n\", \"2\\nb\\nb\\na\\na\\n\", \"2\\na\\nb\\na\\nb\\n\", \"10\\nbaa\\na\\nba\\naabab\\naa\\nbaab\\nbb\\nabbbb\\na\\na\\na\\nba\\nba\\nbaabbb\\nba\\na\\naabb\\nbaa\\nab\\nb\\n\", \"10\\nabaabbaaa\\nacccccaacabc\\nacbaabaaabbca\\naaccca\\ncbbba\\naaba\\nacab\\nac\\ncbac\\nca\\nbbbbc\\nbacbcbcaac\\nc\\ncba\\na\\nabba\\nbcabc\\nabcccaa\\nab\\na\\n\", \"1\\nzzzz\\nyyx\\n\", \"1\\naa\\naaa\\n\", \"1\\naaa\\naa\\n\", \"10\\nb\\nb\\na\\na\\na\\na\\nb\\nb\\na\\nb\\nb\\na\\na\\na\\nb\\nb\\nb\\na\\nb\\nb\\n\", \"10\\na\\nb\\na\\na\\nc\\na\\na\\na\\na\\na\\nb\\nc\\nc\\na\\nc\\nb\\na\\na\\na\\nc\\n\", \"10\\nw\\nr\\na\\nc\\nx\\ne\\nb\\nx\\nw\\nx\\nz\\ng\\nd\\ny\\ns\\ny\\nj\\nh\\nl\\nu\\n\"], \"outputs\": [\"11\\n4 1\\n2 5\\n1 3\\n5 2\\n3 4\\n\", \"1\\n1 1\\n\", \"2\\n1 1\\n2 2\\n\", \"1\\n1 1\\n2 2\\n\", \"0\\n1 1\\n2 2\\n\", \"2\\n1 1\\n2 2\\n\", \"17\\n4 7\\n8 9\\n2 1\\n9 6\\n6 4\\n1 8\\n3 2\\n7 10\\n10 3\\n5 5\\n\", \"10\\n1 9\\n6 5\\n4 10\\n8 6\\n7 8\\n9 4\\n10 3\\n3 2\\n2 1\\n5 7\\n\", \"0\\n1 1\\n\", \"2\\n1 1\\n\", \"2\\n1 1\\n\", \"9\\n3 2\\n4 3\\n5 4\\n6 8\\n1 1\\n2 5\\n7 6\\n8 7\\n10 9\\n9 10\\n\", \"6\\n1 4\\n3 7\\n4 8\\n6 9\\n2 1\\n5 2\\n7 6\\n8 3\\n9 5\\n10 10\\n\", \"0\\n3 3\\n7 2\\n4 8\\n6 7\\n2 9\\n1 5\\n9 10\\n5 4\\n8 6\\n10 1\\n\"]}", "source": "primeintellect"}
Teachers of one programming summer school decided to make a surprise for the students by giving them names in the style of the "Hobbit" movie. Each student must get a pseudonym maximally similar to his own name. The pseudonym must be a name of some character of the popular saga and now the teachers are busy matching pseudonyms to student names. There are n students in a summer school. Teachers chose exactly n pseudonyms for them. Each student must get exactly one pseudonym corresponding to him. Let us determine the relevance of a pseudonym b to a student with name a as the length of the largest common prefix a and b. We will represent such value as $\operatorname{lcp}(a, b)$. Then we can determine the quality of matching of the pseudonyms to students as a sum of relevances of all pseudonyms to the corresponding students. Find the matching between students and pseudonyms with the maximum quality. -----Input----- The first line contains number n (1 ≤ n ≤ 100 000) — the number of students in the summer school. Next n lines contain the name of the students. Each name is a non-empty word consisting of lowercase English letters. Some names can be repeating. The last n lines contain the given pseudonyms. Each pseudonym is a non-empty word consisting of small English letters. Some pseudonyms can be repeating. The total length of all the names and pseudonyms doesn't exceed 800 000 characters. -----Output----- In the first line print the maximum possible quality of matching pseudonyms to students. In the next n lines describe the optimal matching. Each line must have the form a b (1 ≤ a, b ≤ n), that means that the student who was number a in the input, must match to the pseudonym number b in the input. The matching should be a one-to-one correspondence, that is, each student and each pseudonym should occur exactly once in your output. If there are several optimal answers, output any. -----Examples----- Input 5 gennady galya boris bill toshik bilbo torin gendalf smaug galadriel Output 11 4 1 2 5 1 3 5 2 3 4 -----Note----- The first test from the statement the match looks as follows: bill → bilbo (lcp = 3) galya → galadriel (lcp = 3) gennady → gendalf (lcp = 3) toshik → torin (lcp = 2) boris → smaug (lcp = 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\\n1 2 3\\n\", \"4\\n2 1 3 2\\n\", \"17\\n1 45 22 39 28 23 23 100 500 778 777 778 1001 1002 1005 1003 1005\\n\", \"101\\n1 50 170 148 214 153 132 234 181 188 180 225 226 200 197 122 181 168 87 220 223 160 235 94 257 145 199 235 102 146 119 60 109 134 209 260 210 191 180 271 236 195 155 169 166 143 246 102 208 137 278 269 156 251 198 165 111 198 151 213 256 121 276 163 179 285 104 99 139 122 188 184 215 242 244 115 304 259 135 149 104 72 303 291 124 237 112 165 183 168 71 139 85 131 137 107 120 267 235 337 69\\n\", \"10\\n1 2 2 2 2 2 2 2 2 1\\n\", \"25\\n1 2 3 4 4 4 4 4 4 4 2 3 5 5 7 9 8 5 10 12 15 12 100500 800600 228228228\\n\", \"10\\n17 18 19 19 18 17 100 500 100 100\\n\", \"10\\n1 1 1 1 5 5 1 1 1 1\\n\", \"20\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\\n\", \"1\\n1\\n\", \"5\\n1 5 3 5 2\\n\", \"10\\n1 1 1 1 2 2 2 2 4 3\\n\", \"20\\n1 2 2 2 5 6 6 6 7 7 8 9 15 15 16 16 17 18 19 19\\n\", \"4\\n2 2 1 1\\n\"], \"outputs\": [\"3\\n\", \"2\\n\", \"10\\n\", \"3\\n\", \"2\\n\", \"12\\n\", \"4\\n\", \"5\\n\", \"20\\n\", \"1\\n\", \"2\\n\", \"9\\n\", \"20\\n\", \"1\\n\"]}", "source": "primeintellect"}
One day Squidward, Spongebob and Patrick decided to go to the beach. Unfortunately, the weather was bad, so the friends were unable to ride waves. However, they decided to spent their time building sand castles. At the end of the day there were n castles built by friends. Castles are numbered from 1 to n, and the height of the i-th castle is equal to h_{i}. When friends were about to leave, Squidward noticed, that castles are not ordered by their height, and this looks ugly. Now friends are going to reorder the castles in a way to obtain that condition h_{i} ≤ h_{i} + 1 holds for all i from 1 to n - 1. Squidward suggested the following process of sorting castles: Castles are split into blocks — groups of consecutive castles. Therefore the block from i to j will include castles i, i + 1, ..., j. A block may consist of a single castle. The partitioning is chosen in such a way that every castle is a part of exactly one block. Each block is sorted independently from other blocks, that is the sequence h_{i}, h_{i} + 1, ..., h_{j} becomes sorted. The partitioning should satisfy the condition that after each block is sorted, the sequence h_{i} becomes sorted too. This may always be achieved by saying that the whole sequence is a single block. Even Patrick understands that increasing the number of blocks in partitioning will ease the sorting process. Now friends ask you to count the maximum possible number of blocks in a partitioning that satisfies all the above requirements. -----Input----- The first line of the input contains a single integer n (1 ≤ n ≤ 100 000) — the number of castles Spongebob, Patrick and Squidward made from sand during the day. The next line contains n integers h_{i} (1 ≤ h_{i} ≤ 10^9). The i-th of these integers corresponds to the height of the i-th castle. -----Output----- Print the maximum possible number of blocks in a valid partitioning. -----Examples----- Input 3 1 2 3 Output 3 Input 4 2 1 3 2 Output 2 -----Note----- In the first sample the partitioning looks like that: [1][2][3]. [Image] In the second sample the partitioning is: [2, 1][3, 2] [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.25
{"tests": "{\"inputs\": [\"6\\n3 1 0\\n0 3 0\\n2 2 0\\n1 0 0\\n1 3 0\\n0 1 0\\n\", \"8\\n0 1 1\\n1 0 1\\n1 1 0\\n1 1 1\\n2 2 2\\n3 2 2\\n2 3 2\\n2 2 3\\n\", \"2\\n-32839949 -68986721 41592956\\n-32839949 -31435211 41592956\\n\", \"2\\n34319950 -11299623 -19866275\\n34319950 -11299623 98728529\\n\", \"2\\n62887961 73879338 -68804433\\n62887961 63665147 -68804433\\n\", \"2\\n35627406 -93449884 80249079\\n52771770 -93449884 80249079\\n\", \"4\\n-42939263 80157803 90523514\\n-42939263 94977529 90523514\\n-42939263 94977529 -3280468\\n-42939263 80157803 -3280468\\n\", \"4\\n32117556 7831842 -38931866\\n32117556 -42244261 -38931866\\n-24487444 -42244261 -38931866\\n-24487444 7831842 -38931866\\n\", \"4\\n-53055455 42895224 28613596\\n-53061404 42895224 39577025\\n-53061404 42895224 28613596\\n-53055455 42895224 39577025\\n\", \"2\\n-100000000 -100000000 -100000000\\n-100000000 -100000000 100000000\\n\", \"2\\n-100000000 100000000 -100000000\\n-100000000 -100000000 -100000000\\n\", \"2\\n100000000 -100000000 -100000000\\n-100000000 -100000000 -100000000\\n\", \"2\\n-100000000 -100000000 -100000000\\n100000000 -100000000 -100000000\\n\", \"8\\n-100000000 -100000000 -100000000\\n100000000 100000000 100000000\\n-100000000 100000000 100000000\\n-100000000 -100000000 100000000\\n100000000 100000000 -100000000\\n100000000 -100000000 -100000000\\n-100000000 100000000 -100000000\\n100000000 -100000000 100000000\\n\"], \"outputs\": [\"6 2\\n4 5\\n3 1\\n\", \"3 4\\n5 8\\n1 2\\n7 6\\n\", \"1 2\\n\", \"1 2\\n\", \"2 1\\n\", \"1 2\\n\", \"4 1\\n3 2\\n\", \"3 4\\n2 1\\n\", \"3 2\\n1 4\\n\", \"1 2\\n\", \"2 1\\n\", \"2 1\\n\", \"1 2\\n\", \"1 4\\n7 3\\n6 8\\n5 2\\n\"]}", "source": "primeintellect"}
This is a harder version of the problem. In this version, $n \le 50\,000$. There are $n$ distinct points in three-dimensional space numbered from $1$ to $n$. The $i$-th point has coordinates $(x_i, y_i, z_i)$. The number of points $n$ is even. You'd like to remove all $n$ points using a sequence of $\frac{n}{2}$ snaps. In one snap, you can remove any two points $a$ and $b$ that have not been removed yet and form a perfectly balanced pair. A pair of points $a$ and $b$ is perfectly balanced if no other point $c$ (that has not been removed yet) lies within the axis-aligned minimum bounding box of points $a$ and $b$. Formally, point $c$ lies within the axis-aligned minimum bounding box of points $a$ and $b$ if and only if $\min(x_a, x_b) \le x_c \le \max(x_a, x_b)$, $\min(y_a, y_b) \le y_c \le \max(y_a, y_b)$, and $\min(z_a, z_b) \le z_c \le \max(z_a, z_b)$. Note that the bounding box might be degenerate. Find a way to remove all points in $\frac{n}{2}$ snaps. -----Input----- The first line contains a single integer $n$ ($2 \le n \le 50\,000$; $n$ is even), denoting the number of points. Each of the next $n$ lines contains three integers $x_i$, $y_i$, $z_i$ ($-10^8 \le x_i, y_i, z_i \le 10^8$), denoting the coordinates of the $i$-th point. No two points coincide. -----Output----- Output $\frac{n}{2}$ pairs of integers $a_i, b_i$ ($1 \le a_i, b_i \le n$), denoting the indices of points removed on snap $i$. Every integer between $1$ and $n$, inclusive, must appear in your output exactly once. We can show that it is always possible to remove all points. If there are many solutions, output any of them. -----Examples----- Input 6 3 1 0 0 3 0 2 2 0 1 0 0 1 3 0 0 1 0 Output 3 6 5 1 2 4 Input 8 0 1 1 1 0 1 1 1 0 1 1 1 2 2 2 3 2 2 2 3 2 2 2 3 Output 4 5 1 6 2 7 3 8 -----Note----- In the first example, here is what points and their corresponding bounding boxes look like (drawn in two dimensions for simplicity, as all points lie on $z = 0$ plane). Note that order of removing matters: for example, points $5$ and $1$ don't form a perfectly balanced pair initially, but they do after point $3$ is removed. [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\\n4 0 11 6\\n\", \"1\\n13\\n\", \"5\\n315479581 954336048 124252105 880492165 179952043\\n\", \"2\\n151282707 316934479\\n\", \"5\\n809571641 29322377 935888946 833709370 2457463\\n\", \"1\\n901418150\\n\", \"2\\n512483 512483\\n\", \"10\\n268439624 335544469 2491136 151142938 168395872 536905856 17833986 35939360 617678852 13111553\\n\", \"5\\n108499762 843249791 917433490 622172778 725664656\\n\", \"100\\n8650752 65536 131072 134217728 2112 8 0 0 0 0 0 1 0 0 268435456 1024 0 18890756 0 0 0 135364608 6291464 0 0 0 0 0 32 0 16384 0 0 0 0 33554560 256 0 16 0 0 536870912 536870912 0 0 128 0 0 4096 2048 0 0 0 0 268435456 64 1 0 0 262144 524288 0 8192 0 0 0 2 2 512 131072 0 0 67108864 0 0 0 1536 0 0 1048576 0 0 4 33562624 0 16777216 32768 0 0 0 4194304 0 8392704 32 0 67108864 272 0 524288 0\\n\", \"20\\n39369225 366489160 859321608 999860258 379104801 588554056 870353472 407929704 859051016 533509480 960538409 631782433 983759332 519352617 525084936 665915192 397678857 971809857 921746720 257203785\\n\", \"4\\n433189692 522048869 125182076 157942182\\n\", \"6\\n787704054 796688644 754725914 561572949 573891604 312543334\\n\", \"14\\n219574575 219681731 685381501 409783582 795617061 245084272 244865365 67699914 412700853 515125891 354384091 542221506 770632242 705595610\\n\"], \"outputs\": [\"11 6 4 0 \", \"13 \", \"124252105 880492165 954336048 315479581 179952043 \", \"316934479 151282707 \", \"935888946 2457463 29322377 809571641 833709370 \", \"901418150 \", \"512483 512483 \", \"268439624 13111553 536905856 335544469 2491136 617678852 168395872 35939360 151142938 17833986 \", \"725664656 843249791 917433490 622172778 108499762 \", \"8650752 0 0 0 536870912 65536 0 0 0 0 0 18890756 256 4 32768 0 0 0 2112 0 64 0 0 0 8 0 0 272 16 0 0 0 1024 1048576 268435456 8392704 0 0 0 524288 524288 0 0 131072 0 1 16384 0 512 128 0 32 262144 33562624 2 4194304 0 0 67108864 0 0 16777216 0 2048 1 0 67108864 0 0 0 0 0 2 32 0 4096 0 0 0 0 0 8192 0 0 0 0 131072 6291464 33554560 0 0 135364608 1536 268435456 536870912 0 134217728 0 0 0 \", \"983759332 519352617 379104801 39369225 921746720 257203785 631782433 859051016 999860258 525084936 960538409 407929704 366489160 397678857 665915192 859321608 870353472 588554056 971809857 533509480 \", \"433189692 157942182 125182076 522048869 \", \"312543334 573891604 787704054 754725914 796688644 561572949 \", \"219574575 515125891 244865365 409783582 354384091 67699914 705595610 685381501 245084272 795617061 770632242 542221506 219681731 412700853 \"]}", "source": "primeintellect"}
Anu has created her own function $f$: $f(x, y) = (x | y) - y$ where $|$ denotes the bitwise OR operation. For example, $f(11, 6) = (11|6) - 6 = 15 - 6 = 9$. It can be proved that for any nonnegative numbers $x$ and $y$ value of $f(x, y)$ is also nonnegative. She would like to research more about this function and has created multiple problems for herself. But she isn't able to solve all of them and needs your help. Here is one of these problems. A value of an array $[a_1, a_2, \dots, a_n]$ is defined as $f(f(\dots f(f(a_1, a_2), a_3), \dots a_{n-1}), a_n)$ (see notes). You are given an array with not necessarily distinct elements. How should you reorder its elements so that the value of the array is maximal possible? -----Input----- The first line contains a single integer $n$ ($1 \le n \le 10^5$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^9$). Elements of the array are not guaranteed to be different. -----Output----- Output $n$ integers, the reordering of the array with maximum value. If there are multiple answers, print any. -----Examples----- Input 4 4 0 11 6 Output 11 6 4 0 Input 1 13 Output 13 -----Note----- In the first testcase, value of the array $[11, 6, 4, 0]$ is $f(f(f(11, 6), 4), 0) = f(f(9, 4), 0) = f(9, 0) = 9$. $[11, 4, 0, 6]$ is also a valid answer. 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\\n\", \"3 0\\n\", \"3 2\\n\", \"1 0\\n\", \"2 0\\n\", \"2 1\\n\", \"10 4\\n\", \"6 3\\n\", \"1 0\\n\", \"4 0\\n\", \"4 1\\n\", \"4 2\\n\", \"4 3\\n\", \"3 1\\n\"], \"outputs\": [\"1 5 2 4 3\\n\", \"1 2 3\\n\", \"3 2 1\\n\", \"1\\n\", \"1 2\\n\", \"2 1\\n\", \"10 9 8 7 1 2 3 4 5 6\\n\", \"6 5 4 1 2 3\\n\", \"1\\n\", \"1 2 3 4\\n\", \"4 1 2 3\\n\", \"4 3 1 2\\n\", \"4 3 2 1\\n\", \"3 1 2\\n\"]}", "source": "primeintellect"}
Permutation p is an ordered set of integers p_1, p_2, ..., p_{n}, consisting of n distinct positive integers, each of them doesn't exceed n. We'll denote the i-th element of permutation p as p_{i}. We'll call number n the size or the length of permutation p_1, p_2, ..., p_{n}. The decreasing coefficient of permutation p_1, p_2, ..., p_{n} is the number of such i (1 ≤ i < n), that p_{i} > p_{i} + 1. You have numbers n and k. Your task is to print the permutation of length n with decreasing coefficient k. -----Input----- The single line contains two space-separated integers: n, k (1 ≤ n ≤ 10^5, 0 ≤ k < n) — the permutation length and the decreasing coefficient. -----Output----- In a single line print n space-separated integers: p_1, p_2, ..., p_{n} — the permutation of length n with decreasing coefficient k. If there are several permutations that meet this condition, print any of them. It is guaranteed that the permutation with the sought parameters exists. -----Examples----- Input 5 2 Output 1 5 2 4 3 Input 3 0 Output 1 2 3 Input 3 2 Output 3 2 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\\n1 4 6\\n\", \"4\\n2 3 6 6\\n\", \"3\\n6 15 10\\n\", \"4\\n2 3 5 7\\n\", \"6\\n10 8 75 6 7 35\\n\", \"1\\n1\\n\", \"2\\n1 1\\n\", \"2\\n8 32\\n\", \"1\\n97969\\n\", \"2\\n313 313\\n\", \"2\\n97969 97969\\n\", \"8\\n6 15 35 77 143 221 34 26\\n\", \"1\\n998\\n\", \"3\\n2 2 2\\n\"], \"outputs\": [\"1\", \"2\", \"3\", \"-1\", \"3\", \"1\", \"1\", \"2\", \"1\", \"2\", \"1\", \"3\", \"-1\", \"2\"]}", "source": "primeintellect"}
You are given an array $a$ of length $n$ that has a special condition: every element in this array has at most 7 divisors. Find the length of the shortest non-empty subsequence of this array product of whose elements is a perfect square. A sequence $a$ is a subsequence of an array $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements. -----Input----- The first line contains an integer $n$ ($1 \le n \le 10^5$) — the length of $a$. The second line contains $n$ integers $a_1$, $a_2$, $\ldots$, $a_{n}$ ($1 \le a_i \le 10^6$) — the elements of the array $a$. -----Output----- Output the length of the shortest non-empty subsequence of $a$ product of whose elements is a perfect square. If there are several shortest subsequences, you can find any of them. If there's no such subsequence, print "-1". -----Examples----- Input 3 1 4 6 Output 1 Input 4 2 3 6 6 Output 2 Input 3 6 15 10 Output 3 Input 4 2 3 5 7 Output -1 -----Note----- In the first sample, you can choose a subsequence $[1]$. In the second sample, you can choose a subsequence $[6, 6]$. In the third sample, you can choose a subsequence $[6, 15, 10]$. In the fourth sample, there is no such subsequence. 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.5
{"tests": "{\"inputs\": [\"4\\n0 0 0\\n2 0 0\\n2 2 0\\n0 2 0\\n4\\n1 1 -1\\n1 1 1\\n1 3 1\\n1 3 -1\\n\", \"4\\n4 -2 0\\n4 3 0\\n-3 3 0\\n-3 -2 0\\n4\\n6 -2 0\\n3 2 2\\n-3 7 0\\n3 4 6\\n\", \"4\\n-6 6 0\\n13 9 0\\n15 -7 0\\n-5 -5 0\\n4\\n2 0 4\\n2 6 8\\n2 12 1\\n2 4 -4\\n\", \"3\\n2 16 0\\n8 -6 -8\\n8 3 8\\n4\\n-10 5 0\\n25 18 0\\n23 8 0\\n-9 0 0\\n\", \"4\\n-10 5 0\\n25 18 0\\n23 8 0\\n-9 0 0\\n5\\n7 12 -5\\n7 0 -10\\n7 3 8\\n7 10 7\\n7 6 0\\n\", \"5\\n942 -816 0\\n573 1114 0\\n-800 1000 0\\n250 500 0\\n-2012 684 0\\n4\\n1615 -150 0\\n150 1200 -900\\n-1514 1340 0\\n582 -454 1098\\n\", \"8\\n0 1000 0\\n436 1013 0\\n500 500 0\\n1000 500 0\\n1000 1000 0\\n1401 1000 0\\n1500 0 0\\n0 0 0\\n8\\n-200 1000 400\\n150 1000 400\\n125 250 -500\\n850 250 -500\\n750 1000 400\\n1200 1000 400\\n1250 0 -800\\n-250 0 -800\\n\", \"4\\n3390 -1280 0\\n1500 -200 -1000\\n-950 1200 0\\n1500 -200 1650\\n9\\n2500 900 0\\n500 1200 0\\n-600 1000 0\\n100 600 0\\n-2000 700 0\\n3500 -2500 0\\n3750 -550 0\\n2410 -720 0\\n600 -400 0\\n\", \"4\\n0 1000 -700\\n1500 1000 -700\\n1500 1000 500\\n0 1000 500\\n5\\n0 500 0\\n1500 1500 0\\n0 1500 0\\n250 1000 0\\n500 1000 0\\n\", \"9\\n1824 1717 0\\n573 1114 0\\n-850 0 0\\n0 0 0\\n949 665 0\\n3700 -1200 0\\n3639 485 0\\n2500 0 0\\n2741 578 0\\n7\\n1300 0 -1000\\n-800 0 -1000\\n-1500 0 0\\n-1087 0 1400\\n470 0 0\\n740 0 1800\\n3320 0 0\\n\", \"14\\n900 -2000 0\\n2600 -2000 0\\n2600 500 0\\n900 500 0\\n900 -1500 0\\n2200 -1500 0\\n2200 -200 0\\n1900 -300 0\\n1900 -1200 0\\n1100 -1250 0\\n1100 150 0\\n2350 150 0\\n2350 -1750 0\\n900 -1750 0\\n4\\n3100 -750 -500\\n1500 -750 -500\\n1500 -750 500\\n3100 -750 500\\n\", \"9\\n2564 865 0\\n573 1115 0\\n-600 1000 0\\n100 600 0\\n949 665 0\\n2341 -2375 0\\n3879 -561 0\\n2200 -600 0\\n2543 -250 0\\n10\\n2900 -1000 0\\n280 60 900\\n1990 -480 0\\n1710 -320 0\\n830 450 -550\\n660 280 0\\n270 260 500\\n345 460 0\\n-520 1440 -1000\\n1300 400 -1000\\n\", \"16\\n0 1000 0\\n436 1013 0\\n500 500 0\\n1000 500 0\\n1000 1000 0\\n1401 1028 0\\n1434 461 0\\n2087 442 0\\n2066 1040 0\\n2492 1031 0\\n2541 449 0\\n3069 451 0\\n3050 1071 0\\n3702 1071 0\\n3754 0 0\\n0 0 0\\n16\\n-243 700 394\\n109 700 365\\n129 700 -366\\n763 700 -366\\n725 700 397\\n1131 700 409\\n1173 700 -339\\n1910 700 -405\\n1834 700 414\\n2254 700 439\\n2323 700 -425\\n2847 700 -380\\n2849 700 477\\n3418 700 470\\n3537 700 -1057\\n-294 700 -777\\n\", \"16\\n0 1000 0\\n436 1013 0\\n509 517 0\\n1000 500 0\\n1000 1000 0\\n1401 1028 0\\n1434 461 0\\n2086 442 0\\n2079 1044 0\\n2506 1032 0\\n2549 450 0\\n3077 446 0\\n3063 1067 0\\n3715 1062 0\\n3756 -125 0\\n0 0 0\\n16\\n-243 700 394\\n109 700 365\\n129 700 -366\\n763 700 -366\\n725 700 397\\n1131 700 409\\n1173 700 -339\\n2294 700 -439\\n2238 700 513\\n2711 700 500\\n2773 700 -473\\n3374 700 -402\\n3386 700 515\\n3925 700 451\\n3880 700 -975\\n-294 700 -777\\n\"], \"outputs\": [\"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n\", \"NO\\n\"]}", "source": "primeintellect"}
Cowboy Beblop is a funny little boy who likes sitting at his computer. He somehow obtained two elastic hoops in the shape of 2D polygons, which are not necessarily convex. Since there's no gravity on his spaceship, the hoops are standing still in the air. Since the hoops are very elastic, Cowboy Beblop can stretch, rotate, translate or shorten their edges as much as he wants. For both hoops, you are given the number of their vertices, as well as the position of each vertex, defined by the X , Y and Z coordinates. The vertices are given in the order they're connected: the 1st vertex is connected to the 2nd, which is connected to the 3rd, etc., and the last vertex is connected to the first one. Two hoops are connected if it's impossible to pull them to infinity in different directions by manipulating their edges, without having their edges or vertices intersect at any point – just like when two links of a chain are connected. The polygons' edges do not intersect or overlap. To make things easier, we say that two polygons are well-connected, if the edges of one polygon cross the area of the other polygon in two different directions (from the upper and lower sides of the plane defined by that polygon) a different number of times. Cowboy Beblop is fascinated with the hoops he has obtained and he would like to know whether they are well-connected or not. Since he’s busy playing with his dog, Zwei, he’d like you to figure it out for him. He promised you some sweets if you help him! -----Input----- The first line of input contains an integer n (3 ≤ n ≤ 100 000), which denotes the number of edges of the first polygon. The next N lines each contain the integers x, y and z ( - 1 000 000 ≤ x, y, z ≤ 1 000 000) — coordinates of the vertices, in the manner mentioned above. The next line contains an integer m (3 ≤ m ≤ 100 000) , denoting the number of edges of the second polygon, followed by m lines containing the coordinates of the second polygon’s vertices. It is guaranteed that both polygons are simple (no self-intersections), and in general that the obtained polygonal lines do not intersect each other. Also, you can assume that no 3 consecutive points of a polygon lie on the same line. -----Output----- Your output should contain only one line, with the words "YES" or "NO", depending on whether the two given polygons are well-connected. -----Example----- Input 4 0 0 0 2 0 0 2 2 0 0 2 0 4 1 1 -1 1 1 1 1 3 1 1 3 -1 Output YES -----Note----- On the picture below, the two polygons are well-connected, as the edges of the vertical polygon cross the area of the horizontal one exactly once in one direction (for example, from above to below), and zero times in the other (in this case, from below to above). Note that the polygons do not have to be parallel to any of the xy-,xz-,yz- planes in general. [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 9\\n1 4 3\\n2 4\\n3 3 1\\n1 2 3\\n2 2\\n3 1 2\\n1 3 1\\n2 2\\n3 1 3\\n\", \"1 2\\n2 1\\n3 1 1\\n\", \"2 3\\n1 2 1\\n2 1\\n3 2 1\\n\", \"2 3\\n1 1 2\\n2 1\\n3 2 1\\n\", \"10 10\\n2 9\\n1 2 1\\n1 3 2\\n3 1 1\\n3 1 1\\n2 3\\n3 1 1\\n3 1 1\\n3 1 2\\n3 1 1\\n\", \"10 10\\n1 1 2\\n2 1\\n2 1\\n2 1\\n1 2 3\\n2 1\\n3 2 4\\n1 3 4\\n2 1\\n2 1\\n\", \"10 10\\n2 4\\n3 7 1\\n3 10 1\\n3 7 1\\n1 6 3\\n3 4 1\\n2 6\\n1 7 6\\n2 7\\n3 5 2\\n\", \"5 10\\n2 1\\n1 4 3\\n1 5 2\\n3 4 1\\n3 4 1\\n2 3\\n1 2 1\\n1 3 1\\n3 3 2\\n2 3\\n\", \"10 5\\n1 5 4\\n2 5\\n2 3\\n3 7 2\\n1 8 4\\n\", \"8 8\\n2 4\\n2 7\\n2 6\\n3 1 3\\n3 8 2\\n2 4\\n1 3 1\\n3 7 2\\n\", \"2 10\\n2 2\\n1 2 1\\n3 1 1\\n3 1 1\\n3 1 1\\n2 2\\n3 1 2\\n3 1 1\\n3 1 1\\n3 1 2\\n\", \"2 10\\n2 1\\n1 1 2\\n3 1 1\\n2 1\\n3 1 2\\n2 1\\n3 1 2\\n2 1\\n2 1\\n3 1 2\\n\", \"5 10\\n1 2 1\\n1 3 2\\n2 3\\n1 4 3\\n1 5 4\\n2 5\\n3 1 2\\n2 5\\n2 5\\n2 5\\n\", \"5 10\\n2 1\\n1 1 2\\n1 2 3\\n2 1\\n3 2 2\\n3 2 2\\n2 1\\n3 2 1\\n2 1\\n1 3 4\\n\"], \"outputs\": [\"YES\\nNO\\nYES\\n\", \"YES\\n\", \"NO\\n\", \"YES\\n\", \"NO\\nNO\\nNO\\nNO\\nYES\\nNO\\n\", \"YES\\n\", \"NO\\nNO\\nNO\\nYES\\nNO\\n\", \"NO\\nNO\\nYES\\n\", \"NO\\n\", \"NO\\nNO\\nYES\\n\", \"NO\\nNO\\nNO\\nYES\\nNO\\nNO\\nYES\\n\", \"YES\\nYES\\nYES\\nYES\\n\", \"YES\\n\", \"YES\\nYES\\nNO\\n\"]}", "source": "primeintellect"}
There are n employees working in company "X" (let's number them from 1 to n for convenience). Initially the employees didn't have any relationships among each other. On each of m next days one of the following events took place: either employee y became the boss of employee x (at that, employee x didn't have a boss before); or employee x gets a packet of documents and signs them; then he gives the packet to his boss. The boss signs the documents and gives them to his boss and so on (the last person to sign the documents sends them to the archive); or comes a request of type "determine whether employee x signs certain documents". Your task is to write a program that will, given the events, answer the queries of the described type. At that, it is guaranteed that throughout the whole working time the company didn't have cyclic dependencies. -----Input----- The first line contains two integers n and m (1 ≤ n, m ≤ 10^5) — the number of employees and the number of events. Each of the next m lines contains the description of one event (the events are given in the chronological order). The first number of the line determines the type of event t (1 ≤ t ≤ 3). If t = 1, then next follow two integers x and y (1 ≤ x, y ≤ n) — numbers of the company employees. It is guaranteed that employee x doesn't have the boss currently. If t = 2, then next follow integer x (1 ≤ x ≤ n) — the number of the employee who got a document packet. If t = 3, then next follow two integers x and i (1 ≤ x ≤ n; 1 ≤ i ≤ [number of packets that have already been given]) — the employee and the number of the document packet for which you need to find out information. The document packets are numbered started from 1 in the chronological order. It is guaranteed that the input has at least one query of the third type. -----Output----- For each query of the third type print "YES" if the employee signed the document package and "NO" otherwise. Print all the words without the quotes. -----Examples----- Input 4 9 1 4 3 2 4 3 3 1 1 2 3 2 2 3 1 2 1 3 1 2 2 3 1 3 Output YES NO YES 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.75
{"tests": "{\"inputs\": [\"1\\n13\\n\", \"4\\n1 2 3 4\\n\", \"16\\n978618343 473608041 799158564 800910753 461479363 520477481 780529176 678879534 118274424 720632652 639921017 582019792 143353286 537373229 944668919 758615621\\n\", \"16\\n521848329 105907607 414661942 473600423 264555612 186332345 774233687 736918178 456150336 216550357 568433949 135218174 18789799 324141005 617635501 149674864\\n\", \"16\\n612095723 222321386 616933999 386488979 943748076 902598472 681820298 449949990 359507903 613063462 437031953 902348579 697631196 99280352 60225467 969809069\\n\", \"16\\n666766712 653140033 670637874 170909587 210382562 358152171 128926299 750686139 315428350 607830667 363710774 325047228 570196776 38425426 438601514 634274054\\n\", \"1\\n6\\n\", \"1\\n8\\n\", \"1\\n9\\n\", \"4\\n7 9 6 9\\n\", \"4\\n423654797 623563697 645894116 384381709\\n\", \"4\\n437587210 297534606 891773002 56712976\\n\", \"4\\n963662765 272656295 383441522 477665112\\n\", \"4\\n791725034 812168727 528894922 479977172\\n\"], \"outputs\": [\"13\\n\", \"14\\n\", \"14440495117\\n\", \"9436107110\\n\", \"13643168169\\n\", \"10395033063\\n\", \"6\\n\", \"8\\n\", \"9\\n\", \"40\\n\", \"2723388435\\n\", \"2575380796\\n\", \"3061088459\\n\", \"3424934582\\n\"]}", "source": "primeintellect"}
Ilya is a very good-natured lion. He likes maths. Of all mathematical objects, his favourite one is matrices. Now he's faced a complicated matrix problem he needs to solve. He's got a square 2^{n} × 2^{n}-sized matrix and 4^{n} integers. You need to arrange all these numbers in the matrix (put each number in a single individual cell) so that the beauty of the resulting matrix with numbers is maximum. The beauty of a 2^{n} × 2^{n}-sized matrix is an integer, obtained by the following algorithm: Find the maximum element in the matrix. Let's denote it as m. If n = 0, then the beauty of the matrix equals m. Otherwise, a matrix can be split into 4 non-intersecting 2^{n} - 1 × 2^{n} - 1-sized submatrices, then the beauty of the matrix equals the sum of number m and other four beauties of the described submatrices. As you can see, the algorithm is recursive. Help Ilya, solve the problem and print the resulting maximum beauty of the matrix. -----Input----- The first line contains integer 4^{n} (1 ≤ 4^{n} ≤ 2·10^6). The next line contains 4^{n} integers a_{i} (1 ≤ a_{i} ≤ 10^9) — the numbers you need to arrange in the 2^{n} × 2^{n}-sized matrix. -----Output----- On a single line print the maximum value of the beauty of the described matrix. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Examples----- Input 1 13 Output 13 Input 4 1 2 3 4 Output 14 -----Note----- Consider the second sample. You need to arrange the numbers in the matrix as follows: 1 2 3 4 Then the beauty of the matrix will equal: 4 + 1 + 2 + 3 + 4 = 14. 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\\n4 3 1 6\\n\", \"5 2\\n3 2 0 2 7\\n\", \"3 3\\n2 3 1\\n\", \"10 3\\n1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000 1000000000\\n\", \"5 4\\n0 554459682 978416312 784688178 954779973\\n\", \"5 2\\n1 554459683 978416312 784688178 954779974\\n\", \"10 8\\n994538714 617271264 168716105 915909382 338220996 533154890 507276501 323171960 121635370 33140162\\n\", \"10 5\\n994538715 617271265 168716106 915909383 338220997 533154890 507276501 323171960 121635371 33140163\\n\", \"15 12\\n256121252 531930087 157210108 921323934 786210452 0 962820592 824495629 642702951 556399489 660627699 454443499 406577817 234814732 387536495\\n\", \"15 8\\n256121253 531930088 157210109 921323935 786210453 1 962820593 824495630 642702951 556399489 660627699 454443499 406577818 234814733 387536496\\n\", \"48 34\\n227460647 746912226 53993109 682685525 621533698 666833117 492590398 167395931 678377836 66509684 638633255 713194369 386921920 34175132 704550051 220688091 499436760 495071385 102952101 137372655 0 720974146 209203457 946682102 237312198 943872065 957150897 357568282 367006748 0 730509325 68523190 726721460 85037180 620964625 219537305 396613042 39840356 91947418 566463810 791505982 87036026 446282153 912204581 895882687 284561729 35994526 423462628\\n\", \"48 19\\n227460648 746912227 53993110 682685526 621533699 666833118 492590399 167395932 678377837 66509685 638633256 713194370 386921921 34175133 704550052 220688092 499436761 495071386 102952102 137372655 0 720974146 209203457 946682102 237312198 943872065 957150897 357568282 367006748 0 730509325 68523190 726721460 85037180 620964626 219537306 396613043 39840357 91947419 566463811 791505983 87036027 446282154 912204582 895882688 284561730 35994527 423462629\\n\", \"10 5\\n3 3 3 3 4 3 3 3 3 3\\n\", \"5 4\\n3 1 3 1 3\\n\"], \"outputs\": [\"3 2 5 4 \", \"2 1 4 1 6 \", \"1 2 3 \", \"0 0 10000000000 0 0 0 0 0 0 0 \", \"3 554459681 978416311 784688177 954779973 \", \"6 554459681 978416311 784688177 954779973 \", \"961398551 584131101 135575942 882769219 305080833 500014727 474136338 290031797 88495208 331401628 \", \"961398551 584131101 135575942 882769219 305080833 500014727 474136338 290031797 88495208 331401635 \", \"256121252 531930087 157210108 921323934 786210452 6 962820591 824495628 642702950 556399488 660627698 454443498 406577817 234814732 387536495 \", \"256121252 531930087 157210108 921323934 786210452 17 962820591 824495628 642702950 556399488 660627698 454443498 406577817 234814732 387536495 \", \"227460647 746912226 53993109 682685525 621533698 666833117 492590398 167395931 678377836 66509684 638633255 713194369 386921920 34175132 704550051 220688091 499436760 495071385 102952101 137372655 0 720974146 209203457 946682102 237312198 943872065 957150897 357568282 367006748 4 730509324 68523189 726721459 85037179 620964625 219537305 396613042 39840356 91947418 566463810 791505982 87036026 446282153 912204581 895882687 284561729 35994526 423462628 \", \"227460647 746912226 53993109 682685525 621533698 666833117 492590398 167395931 678377836 66509684 638633255 713194369 386921920 34175132 704550051 220688091 499436760 495071385 102952101 137372655 0 720974146 209203457 946682102 237312198 943872065 957150897 357568282 367006748 37 730509324 68523189 726721459 85037179 620964625 219537305 396613042 39840356 91947418 566463810 791505982 87036026 446282153 912204581 895882687 284561729 35994526 423462628 \", \"0 0 0 31 0 0 0 0 0 0 \", \"2 0 2 5 2 \"]}", "source": "primeintellect"}
Little Vasya had n boxes with balls in the room. The boxes stood in a row and were numbered with numbers from 1 to n from left to right. Once Vasya chose one of the boxes, let's assume that its number is i, took all balls out from it (it is guaranteed that this box originally had at least one ball), and began putting balls (one at a time) to the boxes with numbers i + 1, i + 2, i + 3 and so on. If Vasya puts a ball into the box number n, then the next ball goes to box 1, the next one goes to box 2 and so on. He did it until he had no balls left in his hands. It is possible that Vasya puts multiple balls to the same box, and it is also possible that one or more balls will go to the box number i. If i = n, Vasya puts the first ball into the box number 1, then the next ball goes to box 2 and so on. For example, let's suppose that initially Vasya had four boxes, and the first box had 3 balls, the second one had 2, the third one had 5 and the fourth one had 4 balls. Then, if i = 3, then Vasya will take all five balls out of the third box and put them in the boxes with numbers: 4, 1, 2, 3, 4. After all Vasya's actions the balls will lie in the boxes as follows: in the first box there are 4 balls, 3 in the second one, 1 in the third one and 6 in the fourth one. At this point Vasya has completely forgotten the original arrangement of the balls in the boxes, but he knows how they are arranged now, and the number x — the number of the box, where he put the last of the taken out balls. He asks you to help to find the initial arrangement of the balls in the boxes. -----Input----- The first line of the input contains two integers n and x (2 ≤ n ≤ 10^5, 1 ≤ x ≤ n), that represent the number of the boxes and the index of the box that got the last ball from Vasya, correspondingly. The second line contains n space-separated integers a_1, a_2, ..., a_{n}, where integer a_{i} (0 ≤ a_{i} ≤ 10^9, a_{x} ≠ 0) represents the number of balls in the box with index i after Vasya completes all the actions. Please, do not use the %lld specifier to read or write 64-bit integers in С++. It is preferred to use the cin, cout streams or the %I64d specifier. -----Output----- Print n integers, where the i-th one represents the number of balls in the box number i before Vasya starts acting. Separate the numbers in the output by spaces. If there are multiple correct solutions, you are allowed to print any of them. -----Examples----- Input 4 4 4 3 1 6 Output 3 2 5 4 Input 5 2 3 2 0 2 7 Output 2 1 4 1 6 Input 3 3 2 3 1 Output 1 2 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\\nrivest\\nshamir\\nadleman\\n\", \"10\\ntourist\\npetr\\nwjmzbmr\\nyeputons\\nvepifanov\\nscottwu\\noooooooooooooooo\\nsubscriber\\nrowdark\\ntankengineer\\n\", \"10\\npetr\\negor\\nendagorion\\nfeferivan\\nilovetanyaromanova\\nkostka\\ndmitriyh\\nmaratsnowbear\\nbredorjaguarturnik\\ncgyforever\\n\", \"7\\ncar\\ncare\\ncareful\\ncarefully\\nbecarefuldontforgetsomething\\notherwiseyouwillbehacked\\ngoodluck\\n\", \"2\\na\\naa\\n\", \"6\\nax\\nay\\nby\\nbz\\ncz\\ncx\\n\", \"4\\nax\\nay\\nby\\nbx\\n\", \"4\\nax\\nay\\nby\\nbz\\n\", \"1\\na\\n\", \"1\\nzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz\\n\", \"2\\naa\\na\\n\", \"5\\naaaaa\\naaaa\\naaa\\naa\\na\\n\", \"2\\nanud\\nanu\\n\", \"8\\nwa\\nwb\\nxc\\nxd\\nyb\\nyc\\nzd\\nza\\n\"], \"outputs\": [\"bcdefghijklmnopqrsatuvwxyz\\n\", \"Impossible\\n\", \"aghjlnopefikdmbcqrstuvwxyz\\n\", \"acbdefhijklmnogpqrstuvwxyz\\n\", \"abcdefghijklmnopqrstuvwxyz\\n\", \"Impossible\\n\", \"Impossible\\n\", \"abcdefghijklmnopqrstuvwxyz\\n\", \"abcdefghijklmnopqrstuvwxyz\\n\", \"abcdefghijklmnopqrstuvwxyz\\n\", \"Impossible\\n\", \"Impossible\\n\", \"Impossible\\n\", \"Impossible\\n\"]}", "source": "primeintellect"}
Fox Ciel is going to publish a paper on FOCS (Foxes Operated Computer Systems, pronounce: "Fox"). She heard a rumor: the authors list on the paper is always sorted in the lexicographical order. After checking some examples, she found out that sometimes it wasn't true. On some papers authors' names weren't sorted in lexicographical order in normal sense. But it was always true that after some modification of the order of letters in alphabet, the order of authors becomes lexicographical! She wants to know, if there exists an order of letters in Latin alphabet such that the names on the paper she is submitting are following in the lexicographical order. If so, you should find out any such order. Lexicographical order is defined in following way. When we compare s and t, first we find the leftmost position with differing characters: s_{i} ≠ t_{i}. If there is no such position (i. e. s is a prefix of t or vice versa) the shortest string is less. Otherwise, we compare characters s_{i} and t_{i} according to their order in alphabet. -----Input----- The first line contains an integer n (1 ≤ n ≤ 100): number of names. Each of the following n lines contain one string name_{i} (1 ≤ |name_{i}| ≤ 100), the i-th name. Each name contains only lowercase Latin letters. All names are different. -----Output----- If there exists such order of letters that the given names are sorted lexicographically, output any such order as a permutation of characters 'a'–'z' (i. e. first output the first letter of the modified alphabet, then the second, and so on). Otherwise output a single word "Impossible" (without quotes). -----Examples----- Input 3 rivest shamir adleman Output bcdefghijklmnopqrsatuvwxyz Input 10 tourist petr wjmzbmr yeputons vepifanov scottwu oooooooooooooooo subscriber rowdark tankengineer Output Impossible Input 10 petr egor endagorion feferivan ilovetanyaromanova kostka dmitriyh maratsnowbear bredorjaguarturnik cgyforever Output aghjlnopefikdmbcqrstuvwxyz Input 7 car care careful carefully becarefuldontforgetsomething otherwiseyouwillbehacked goodluck Output acbdefhijklmnogpqrstuvwxyz 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\\n2 0\\n0 0\\n1 0\\n1 1\\n0 1\\n0 -1 -2 1 0\\n\", \"3\\n1 0\\n0 0\\n2 0\\n0 1 2\\n\", \"9\\n0 0\\n1 0\\n2 0\\n0 1\\n1 1\\n2 1\\n1 2\\n2 2\\n0 2\\n0 0 0 -1 -1 -2 1 1 2\\n\", \"18\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n0 10\\n0 11\\n0 12\\n0 13\\n0 14\\n0 15\\n0 16\\n1 0\\n0 1 2 3 4 5 6 7 8 9 -1 10 11 12 13 14 15 16\\n\", \"1\\n0 0\\n0\\n\", \"37\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n0 10\\n0 11\\n0 12\\n0 13\\n0 14\\n0 15\\n0 16\\n0 17\\n0 18\\n0 19\\n0 20\\n0 21\\n0 22\\n0 23\\n0 24\\n0 25\\n0 26\\n0 27\\n0 28\\n0 29\\n0 30\\n0 31\\n0 32\\n0 33\\n0 34\\n0 35\\n1 0\\n0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 -1 26 27 28 29 30 31 32 33 34 35\\n\", \"31\\n0 0\\n0 1\\n0 2\\n0 3\\n1 0\\n1 1\\n2 0\\n2 1\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n11 0\\n12 0\\n13 0\\n14 0\\n15 0\\n16 0\\n17 0\\n18 0\\n19 0\\n20 0\\n21 0\\n22 0\\n23 0\\n24 0\\n25 0\\n0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 -11 -12 -13 -14 1 -15 2 -16 -17 -18 3 -19 -20 0 -21 -22 -23 -24 -25 -1\\n\", \"40\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n0 10\\n0 11\\n0 12\\n1 0\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n1 6\\n1 7\\n2 0\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n11 0\\n12 0\\n13 0\\n14 0\\n15 0\\n16 0\\n17 0\\n18 0\\n19 0\\n20 0\\n0 1 2 -1 -2 3 4 -3 5 6 7 8 0 -4 -5 1 -6 -7 -8 -9 -10 -11 9 2 -12 -13 -14 3 10 -15 11 4 -16 -17 -18 -19 5 6 12 -20\\n\", \"21\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n1 0\\n1 1\\n1 2\\n1 3\\n2 0\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n86174 -26039 -13726 25840 85990 -62633 -29634 -68400 39255 1313 77388 830 -45558 -90862 97867 46376 58592 17103 32820 27220 94751\\n\", \"31\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n1 0\\n1 1\\n1 2\\n1 3\\n1 4\\n1 5\\n2 0\\n2 1\\n2 2\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n11 0\\n12 0\\n13 0\\n14 0\\n-8 1 4 -11 0 -4 -10 3 4 -5 -9 8 7 6 2 -2 -1 9 -3 -14 2 3 -6 0 -7 -1 5 0 -13 -12 1\\n\", \"1\\n0 0\\n-9876\\n\", \"16\\n0 0\\n0 1\\n1 0\\n2 0\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n11 0\\n12 0\\n13 0\\n14 0\\n0 -1 -2 -3 -4 -5 -6 -7 -8 -9 -10 1 -11 -12 -13 -14\\n\", \"5\\n1 1\\n0 1\\n2 0\\n1 0\\n0 0\\n0 -1 -2 1 0\\n\", \"2\\n0 0\\n1 0\\n-1 0\\n\"], \"outputs\": [\"YES\\n0 0\\n1 0\\n2 0\\n0 1\\n1 1\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n1 0\\n0 10\\n0 11\\n0 12\\n0 13\\n0 14\\n0 15\\n0 16\\n\", \"YES\\n0 0\\n\", \"YES\\n0 0\\n0 1\\n0 2\\n0 3\\n0 4\\n0 5\\n0 6\\n0 7\\n0 8\\n0 9\\n0 10\\n0 11\\n0 12\\n0 13\\n0 14\\n0 15\\n0 16\\n0 17\\n0 18\\n0 19\\n0 20\\n0 21\\n0 22\\n0 23\\n0 24\\n0 25\\n1 0\\n0 26\\n0 27\\n0 28\\n0 29\\n0 30\\n0 31\\n0 32\\n0 33\\n0 34\\n0 35\\n\", \"YES\\n0 0\\n1 0\\n2 0\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n11 0\\n12 0\\n13 0\\n14 0\\n0 1\\n15 0\\n0 2\\n16 0\\n17 0\\n18 0\\n0 3\\n19 0\\n20 0\\n1 1\\n21 0\\n22 0\\n23 0\\n24 0\\n25 0\\n2 1\\n\", \"YES\\n0 0\\n0 1\\n0 2\\n1 0\\n2 0\\n0 3\\n0 4\\n3 0\\n0 5\\n0 6\\n0 7\\n0 8\\n1 1\\n4 0\\n5 0\\n1 2\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n11 0\\n0 9\\n1 3\\n12 0\\n13 0\\n14 0\\n1 4\\n0 10\\n15 0\\n0 11\\n1 5\\n16 0\\n17 0\\n18 0\\n19 0\\n1 6\\n1 7\\n0 12\\n20 0\\n\", \"NO\\n\", \"NO\\n\", \"NO\\n\", \"YES\\n0 0\\n1 0\\n2 0\\n3 0\\n4 0\\n5 0\\n6 0\\n7 0\\n8 0\\n9 0\\n10 0\\n0 1\\n11 0\\n12 0\\n13 0\\n14 0\\n\", \"YES\\n0 0\\n1 0\\n2 0\\n0 1\\n1 1\\n\", \"NO\\n\"]}", "source": "primeintellect"}
Wilbur is playing with a set of n points on the coordinate plane. All points have non-negative integer coordinates. Moreover, if some point (x, y) belongs to the set, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y also belong to this set. Now Wilbur wants to number the points in the set he has, that is assign them distinct integer numbers from 1 to n. In order to make the numbering aesthetically pleasing, Wilbur imposes the condition that if some point (x, y) gets number i, then all (x',y') from the set, such that x' ≥ x and y' ≥ y must be assigned a number not less than i. For example, for a set of four points (0, 0), (0, 1), (1, 0) and (1, 1), there are two aesthetically pleasing numberings. One is 1, 2, 3, 4 and another one is 1, 3, 2, 4. Wilbur's friend comes along and challenges Wilbur. For any point he defines it's special value as s(x, y) = y - x. Now he gives Wilbur some w_1, w_2,..., w_{n}, and asks him to find an aesthetically pleasing numbering of the points in the set, such that the point that gets number i has it's special value equal to w_{i}, that is s(x_{i}, y_{i}) = y_{i} - x_{i} = w_{i}. Now Wilbur asks you to help him with this challenge. -----Input----- The first line of the input consists of a single integer n (1 ≤ n ≤ 100 000) — the number of points in the set Wilbur is playing with. Next follow n lines with points descriptions. Each line contains two integers x and y (0 ≤ x, y ≤ 100 000), that give one point in Wilbur's set. It's guaranteed that all points are distinct. Also, it is guaranteed that if some point (x, y) is present in the input, then all points (x', y'), such that 0 ≤ x' ≤ x and 0 ≤ y' ≤ y, are also present in the input. The last line of the input contains n integers. The i-th of them is w_{i} ( - 100 000 ≤ w_{i} ≤ 100 000) — the required special value of the point that gets number i in any aesthetically pleasing numbering. -----Output----- If there exists an aesthetically pleasant numbering of points in the set, such that s(x_{i}, y_{i}) = y_{i} - x_{i} = w_{i}, then print "YES" on the first line of the output. Otherwise, print "NO". If a solution exists, proceed output with n lines. On the i-th of these lines print the point of the set that gets number i. If there are multiple solutions, print any of them. -----Examples----- Input 5 2 0 0 0 1 0 1 1 0 1 0 -1 -2 1 0 Output YES 0 0 1 0 2 0 0 1 1 1 Input 3 1 0 0 0 2 0 0 1 2 Output NO -----Note----- In the first sample, point (2, 0) gets number 3, point (0, 0) gets number one, point (1, 0) gets number 2, point (1, 1) gets number 5 and point (0, 1) gets number 4. One can easily check that this numbering is aesthetically pleasing and y_{i} - x_{i} = w_{i}. In the second sample, the special values of the points in the set are 0, - 1, and - 2 while the sequence that the friend gives to Wilbur is 0, 1, 2. Therefore, the answer does not 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
{"tests": "{\"inputs\": [\"5\\n1 2 3 2 1\\n\", \"3\\n10 6 8\\n\", \"7\\n1 2 1 2 1 2 1\\n\", \"7\\n1 2 1 2 1 3 1\\n\", \"1\\n1\\n\", \"5\\n1 1 4 2 2\\n\", \"6\\n1 3 4 3 5 4\\n\", \"100\\n82 51 81 14 37 17 78 92 64 15 8 86 89 8 87 77 66 10 15 12 100 25 92 47 21 78 20 63 13 49 41 36 41 79 16 87 87 69 3 76 80 60 100 49 70 59 72 8 38 71 45 97 71 14 76 54 81 4 59 46 39 29 92 3 49 22 53 99 59 52 74 31 92 43 42 23 44 9 82 47 7 40 12 9 3 55 37 85 46 22 84 52 98 41 21 77 63 17 62 91\\n\", \"7\\n6 2 2 6 5 7 7\\n\", \"7\\n2 4 1 2 3 1 2\\n\", \"7\\n2 1 2 1 2 2 1\\n\", \"7\\n5 2 4 2 4 1 1\\n\", \"6\\n3 2 1 7 3 7\\n\", \"6\\n4 1 2 3 2 1\\n\"], \"outputs\": [\"1 2 3 2 1 \\n\", \"10 6 6 \\n\", \"1 2 1 1 1 1 1 \\n\", \"1 1 1 1 1 3 1 \\n\", \"1 \\n\", \"1 1 4 2 2 \\n\", \"1 3 3 3 5 4 \\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 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 22 22 53 99 59 52 52 31 31 31 31 23 23 9 9 9 7 7 7 7 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 \\n\", \"2 2 2 5 5 7 7 \\n\", \"2 4 1 1 1 1 1 \\n\", \"1 1 1 1 2 2 1 \\n\", \"5 2 2 2 2 1 1 \\n\", \"1 1 1 7 3 3 \\n\", \"1 1 2 3 2 1 \\n\"]}", "source": "primeintellect"}
This is an easier version of the problem. In this version $n \le 1000$ The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlskva. All skyscrapers are built along the highway. It is known that the company has already bought $n$ plots along the highway and is preparing to build $n$ skyscrapers, one skyscraper per plot. Architects must consider several requirements when planning a skyscraper. Firstly, since the land on each plot has different properties, each skyscraper has a limit on the largest number of floors it can have. Secondly, according to the design code of the city, it is unacceptable for a skyscraper to simultaneously have higher skyscrapers both to the left and to the right of it. Formally, let's number the plots from $1$ to $n$. Then if the skyscraper on the $i$-th plot has $a_i$ floors, it must hold that $a_i$ is at most $m_i$ ($1 \le a_i \le m_i$). Also there mustn't be integers $j$ and $k$ such that $j < i < k$ and $a_j > a_i < a_k$. Plots $j$ and $k$ are not required to be adjacent to $i$. The company wants the total number of floors in the built skyscrapers to be as large as possible. Help it to choose the number of floors for each skyscraper in an optimal way, i.e. in such a way that all requirements are fulfilled, and among all such construction plans choose any plan with the maximum possible total number of floors. -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 1000$) — the number of plots. The second line contains the integers $m_1, m_2, \ldots, m_n$ ($1 \leq m_i \leq 10^9$) — the limit on the number of floors for every possible number of floors for a skyscraper on each plot. -----Output----- Print $n$ integers $a_i$ — the number of floors in the plan for each skyscraper, such that all requirements are met, and the total number of floors in all skyscrapers is the maximum possible. If there are multiple answers possible, print any of them. -----Examples----- Input 5 1 2 3 2 1 Output 1 2 3 2 1 Input 3 10 6 8 Output 10 6 6 -----Note----- In the first example, you can build all skyscrapers with the highest possible height. In the second test example, you cannot give the maximum height to all skyscrapers as this violates the design code restriction. The answer $[10, 6, 6]$ is optimal. Note that the answer of $[6, 6, 8]$ also satisfies all restrictions, but is not optimal. 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\\n2 2 1 3 4 1\\n\", \"3\\n2 2 9\\n\", \"5\\n10 100 111 1 2\\n\", \"10\\n1 2 3 4 1 2 3 4 5 6\\n\", \"50\\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\\n\", \"100\\n1 838 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 605 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 27 533 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 835 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1000 1 992\\n\", \"1\\n1\\n\", \"2\\n1 1\\n\", \"6\\n5 4 3 2 1 2\\n\", \"9\\n1 2 3 4 5 6 7 8 9\\n\", \"7\\n99 100 1 2 3 4 5\\n\", \"5\\n3 3 1 2 3\\n\", \"1\\n100\\n\", \"1\\n5\\n\"], \"outputs\": [\"3\", \"3\", \"3\", \"6\", \"50\", \"42\", \"1\", \"2\", \"2\", \"9\", \"5\", \"3\", \"1\", \"1\"]}", "source": "primeintellect"}
Kefa decided to make some money doing business on the Internet for exactly n days. He knows that on the i-th day (1 ≤ i ≤ n) he makes a_{i} money. Kefa loves progress, that's why he wants to know the length of the maximum non-decreasing subsegment in sequence a_{i}. Let us remind you that the subsegment of the sequence is its continuous fragment. A subsegment of numbers is called non-decreasing if all numbers in it follow in the non-decreasing order. Help Kefa cope with this task! -----Input----- The first line contains integer n (1 ≤ n ≤ 10^5). The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^9). -----Output----- Print a single integer — the length of the maximum non-decreasing subsegment of sequence a. -----Examples----- Input 6 2 2 1 3 4 1 Output 3 Input 3 2 2 9 Output 3 -----Note----- In the first test the maximum non-decreasing subsegment is the numbers from the third to the fifth one. In the second test the maximum non-decreasing subsegment is the numbers from the first to the third one. 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 0\\n0 1\\n1 1\\n1 0\\n\", \"6\\n5 0\\n10 0\\n12 -4\\n10 -8\\n5 -8\\n3 -4\\n\", \"19\\n449447997 711296339\\n530233434 692216537\\n535464528 613140435\\n535533467 100893188\\n530498867 -265063956\\n519107979 -271820709\\n482156929 -287792333\\n-303730271 -287970295\\n-416935204 -263348201\\n-443613873 -249980523\\n-453444829 -173903413\\n-462102798 -80789280\\n-462064673 -13220755\\n-461368561 482595837\\n-457749751 687048095\\n-448625206 709399396\\n-145117181 710688825\\n159099640 711650577\\n400454061 711503381\\n\", \"4\\n0 0\\n0 10\\n10 10\\n6 4\\n\", \"4\\n-1000000000 -1000000000\\n-999999999 -999999999\\n1000000000 999999999\\n0 -1\\n\", \"4\\n-1000000000 -1000000000\\n-1000000000 1000000000\\n1000000000 1000000000\\n1000000000 -1000000000\\n\", \"4\\n-100000 -100000\\n-99999 -99999\\n100000 99999\\n0 -100\\n\", \"4\\n-10000 -10000\\n-9999 -9999\\n10000 9999\\n0 -1000\\n\", \"5\\n0 0\\n0 10\\n10 10\\n20 0\\n10 -1\\n\", \"5\\n10 -1\\n0 0\\n0 10\\n10 10\\n20 0\\n\", \"4\\n1000000000 1000000000\\n1000000000 -1000000000\\n-1000000000 -1000000000\\n-1000000000 1000000000\\n\", \"4\\n2 0\\n0 0\\n0 14\\n8 14\\n\", \"4\\n0 0\\n1 100\\n100 0\\n1 -100\\n\", \"4\\n-1000000000 1000000000\\n1000000000 500000000\\n1000000000 -1000000000\\n-500000000 -1000000000\\n\"], \"outputs\": [\"0.3535533906\\n\", \"1.0000000000\\n\", \"24967.1394973334\\n\", \"0.7071067812\\n\", \"0.0000000000\\n\", \"707106781.1865475000\\n\", \"0.0000017678\\n\", \"0.0000176781\\n\", \"0.5000000000\\n\", \"0.5000000000\\n\", \"707106781.1865475000\\n\", \"0.8682431421\\n\", \"0.5000000000\\n\", \"530330085.8899106400\\n\"]}", "source": "primeintellect"}
You are given a convex polygon P with n distinct vertices p_1, p_2, ..., p_{n}. Vertex p_{i} has coordinates (x_{i}, y_{i}) in the 2D plane. These vertices are listed in clockwise order. You can choose a real number D and move each vertex of the polygon a distance of at most D from their original positions. Find the maximum value of D such that no matter how you move the vertices, the polygon does not intersect itself and stays convex. -----Input----- The first line has one integer n (4 ≤ n ≤ 1 000) — the number of vertices. The next n lines contain the coordinates of the vertices. Line i contains two integers x_{i} and y_{i} ( - 10^9 ≤ x_{i}, y_{i} ≤ 10^9) — the coordinates of the i-th vertex. These points are guaranteed to be given in clockwise order, and will form a strictly convex polygon (in particular, no three consecutive points lie on the same straight line). -----Output----- Print one real number D, which is the maximum real number such that no matter how you move the vertices, the polygon stays convex. Your answer will be considered correct if its absolute or relative error does not exceed 10^{ - 6}. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if $\frac{|a - b|}{\operatorname{max}(1, b)} \leq 10^{-6}$. -----Examples----- Input 4 0 0 0 1 1 1 1 0 Output 0.3535533906 Input 6 5 0 10 0 12 -4 10 -8 5 -8 3 -4 Output 1.0000000000 -----Note----- Here is a picture of the first sample [Image] Here is an example of making the polygon non-convex. [Image] This is not an optimal solution, since the maximum distance we moved one point is ≈ 0.4242640687, whereas we can make it non-convex by only moving each point a distance of at most ≈ 0.3535533906. 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\": [\"110\\n\", \"010\\n\", \"0001111\\n\", \"0111001100111011101000\\n\", \"0\\n\", \"1\\n\", \"0000000000000000\\n\", \"0100000001000001\\n\", \"0000100010001110\\n\", \"1001101000001101\\n\", \"0010000110000100\\n\", \"1111101000110110\\n\", \"1111111111111010\\n\", \"1111111111111111\\n\"], \"outputs\": [\"010\\n\", \"010\\n\", \"0000000\\n\", \"0011001100001011101000\\n\", \"0\\n\", \"0\\n\", \"0000000000000000\\n\", \"0100000001000000\\n\", \"0000100010000010\\n\", \"1001101000000100\\n\", \"0010000110000100\\n\", \"0011101000010010\\n\", \"0000000000001010\\n\", \"0000000000000000\\n\"]}", "source": "primeintellect"}
The only difference between easy and hard versions is the length of the string. You can hack this problem if you solve it. But you can hack the previous problem only if you solve both problems. Kirk has a binary string $s$ (a string which consists of zeroes and ones) of length $n$ and he is asking you to find a binary string $t$ of the same length which satisfies the following conditions: For any $l$ and $r$ ($1 \leq l \leq r \leq n$) the length of the longest non-decreasing subsequence of the substring $s_{l}s_{l+1} \ldots s_{r}$ is equal to the length of the longest non-decreasing subsequence of the substring $t_{l}t_{l+1} \ldots t_{r}$; The number of zeroes in $t$ is the maximum possible. A non-decreasing subsequence of a string $p$ is a sequence of indices $i_1, i_2, \ldots, i_k$ such that $i_1 < i_2 < \ldots < i_k$ and $p_{i_1} \leq p_{i_2} \leq \ldots \leq p_{i_k}$. The length of the subsequence is $k$. If there are multiple substrings which satisfy the conditions, output any. -----Input----- The first line contains a binary string of length not more than $10^5$. -----Output----- Output a binary string which satisfied the above conditions. If there are many such strings, output any of them. -----Examples----- Input 110 Output 010 Input 010 Output 010 Input 0001111 Output 0000000 Input 0111001100111011101000 Output 0011001100001011101000 -----Note----- In the first example: For the substrings of the length $1$ the length of the longest non-decreasing subsequnce is $1$; For $l = 1, r = 2$ the longest non-decreasing subsequnce of the substring $s_{1}s_{2}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{2}$ is $01$; For $l = 1, r = 3$ the longest non-decreasing subsequnce of the substring $s_{1}s_{3}$ is $11$ and the longest non-decreasing subsequnce of the substring $t_{1}t_{3}$ is $00$; For $l = 2, r = 3$ the longest non-decreasing subsequnce of the substring $s_{2}s_{3}$ is $1$ and the longest non-decreasing subsequnce of the substring $t_{2}t_{3}$ is $1$; The second example is similar to the first one. 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\\nabb\\ndad\\n\", \"8\\ndrpepper\\ncocacola\\n\", \"1\\nh\\np\\n\", \"2\\nxc\\nda\\n\", \"3\\nbab\\naab\\n\", \"15\\nxrezbaoiksvhuww\\ndcgcjrkafntbpbl\\n\", \"3\\nbaa\\nbba\\n\", \"10\\ndaefcecfae\\nccdaceefca\\n\", \"10\\nfdfbffedbc\\ncfcdddfbed\\n\", \"100\\nbltlukvrharrgytdxnbjailgafwdmeowqvwwsadryzquqzvfhjnpkwvgpwvohvjwzafcxqmisgyyuidvvjqljqshflzywmcccksk\\njmgilzxkrvntkvqpsemrmyrasfqrofkwjwfznctwrmegghlhbbomjlojyapmrpkowqhsvwmrccfbnictnntjevynqilptaoharqv\\n\", \"100\\npfkskdknmbxxslokqdliigxyvntsmaziljamlflwllvbhqnzpyvvzirhhhglsskiuogfoytcxjmospipybckwmkjhnfjddweyqqi\\nakvzmboxlcfwccaoknrzrhvqcdqkqnywstmxinqbkftnbjmahrvexoipikkqfjjmasnxofhklxappvufpsyujdtrpjeejhznoeai\\n\", \"3\\nwhw\\nuuh\\n\", \"242\\nrrrrrrrrrrrrrmmmmmmmmmmmmmgggggggggggggwwwwwwwwwwwwwyyyyyyyyyyyyyhhhhhhhhhhhhhoooooooooooooqqqqqqqqqqqqqjjjjjjjjjjjjjvvvvvvvvvvvvvlllllllllllllnnnnnnnnnnnnnfffffffffffffeeeeeeeeaaaaaaaaiiiiiiiiuuuuuuuuzzzzzzzzbbbbbbbbxxxxxxxxttttttttsscckppdd\\nrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfrmgwyhoqjvlnfeaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxteaiuzbxtscsckpdpd\\n\", \"1\\nw\\nl\\n\"], \"outputs\": [\"2\\nb d\\nd a\\n\", \"7\\nl e\\ne d\\nd c\\nc p\\np o\\no r\\nr a\\n\", \"1\\np h\\n\", \"2\\nc a\\nx d\\n\", \"1\\nb a\\n\", \"15\\nz c\\nc r\\nr i\\ni a\\nj h\\nh l\\nl w\\nw b\\nx d\\ng e\\no k\\nk f\\ns n\\nu p\\nv t\\n\", \"1\\nb a\\n\", \"4\\ne d\\nd c\\nc f\\nf a\\n\", \"4\\nc e\\ne f\\nf d\\nd b\\n\", \"25\\ni y\\ny p\\np d\\nd o\\no c\\nc h\\nh f\\nf e\\ne j\\nj b\\nb m\\nm l\\nl u\\nu g\\ng t\\nt q\\nq w\\nw z\\nz k\\nk r\\nr n\\nn s\\ns x\\nx v\\nv a\\n\", \"25\\no y\\ny w\\nw v\\nv e\\ne j\\nj t\\nt q\\nq m\\nm l\\nl r\\nr u\\nu i\\ni z\\nz s\\ns c\\nc b\\nb d\\nd n\\nn x\\nx f\\nf k\\nk g\\ng h\\nh p\\np a\\n\", \"2\\nw u\\nu h\\n\", \"21\\nt x\\nx b\\nb z\\nz u\\nu i\\ni e\\ne a\\ns c\\np d\\nn l\\nl v\\nv j\\nj q\\nq o\\no h\\nh y\\ny w\\nw g\\ng m\\nm r\\nr f\\n\", \"1\\nw l\\n\"]}", "source": "primeintellect"}
Valya and Tolya are an ideal pair, but they quarrel sometimes. Recently, Valya took offense at her boyfriend because he came to her in t-shirt with lettering that differs from lettering on her pullover. Now she doesn't want to see him and Tolya is seating at his room and crying at her photos all day long. This story could be very sad but fairy godmother (Tolya's grandmother) decided to help them and restore their relationship. She secretly took Tolya's t-shirt and Valya's pullover and wants to make the letterings on them same. In order to do this, for one unit of mana she can buy a spell that can change some letters on the clothes. Your task is calculate the minimum amount of mana that Tolya's grandmother should spend to rescue love of Tolya and Valya. More formally, letterings on Tolya's t-shirt and Valya's pullover are two strings with same length n consisting only of lowercase English letters. Using one unit of mana, grandmother can buy a spell of form (c_1, c_2) (where c_1 and c_2 are some lowercase English letters), which can arbitrary number of times transform a single letter c_1 to c_2 and vise-versa on both Tolya's t-shirt and Valya's pullover. You should find the minimum amount of mana that grandmother should spend to buy a set of spells that can make the letterings equal. In addition you should output the required set of spells. -----Input----- The first line contains a single integer n (1 ≤ n ≤ 10^5) — the length of the letterings. The second line contains a string with length n, consisting of lowercase English letters — the lettering on Valya's pullover. The third line contains the lettering on Tolya's t-shirt in the same format. -----Output----- In the first line output a single integer — the minimum amount of mana t required for rescuing love of Valya and Tolya. In the next t lines output pairs of space-separated lowercase English letters — spells that Tolya's grandmother should buy. Spells and letters in spells can be printed in any order. If there are many optimal answers, output any. -----Examples----- Input 3 abb dad Output 2 a d b a Input 8 drpepper cocacola Output 7 l e e d d c c p p o o r r a -----Note----- In first example it's enough to buy two spells: ('a','d') and ('b','a'). Then first letters will coincide when we will replace letter 'a' with 'd'. Second letters will coincide when we will replace 'b' with 'a'. Third letters will coincide when we will at first replace 'b' with 'a' and then 'a' with 'd'. 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\": [\"AABCCBAAB\\nABCB\\n5\\n1 3 1 2\\n2 2 2 4\\n7 9 1 1\\n3 4 2 3\\n4 5 1 3\\n\", \"AAAAAA\\nAAAAAA\\n30\\n3 4 1 2\\n3 3 4 4\\n5 6 3 4\\n3 3 2 3\\n6 6 1 5\\n2 4 4 6\\n1 6 2 5\\n6 6 3 4\\n3 5 1 4\\n4 5 3 6\\n2 3 2 4\\n3 4 4 4\\n6 6 4 6\\n3 3 2 5\\n1 5 3 3\\n4 6 1 2\\n6 6 6 6\\n3 3 3 4\\n6 6 6 6\\n5 6 4 4\\n6 6 5 5\\n2 3 1 4\\n3 6 4 5\\n3 5 6 6\\n4 5 2 6\\n5 6 6 6\\n1 4 2 5\\n4 5 2 5\\n4 5 1 3\\n2 2 4 6\\n\", \"A\\nA\\n1\\n1 1 1 1\\n\", \"CCBACACBCCCBBAAC\\nCACCAAABAACBBBBAC\\n20\\n7 7 2 15\\n3 11 14 15\\n4 9 6 12\\n10 15 13 17\\n10 16 5 14\\n14 15 12 16\\n16 16 16 16\\n3 15 9 14\\n10 12 8 12\\n15 15 9 10\\n14 15 8 15\\n7 14 17 17\\n15 15 17 17\\n15 15 5 9\\n4 14 12 17\\n13 15 8 12\\n1 4 2 2\\n6 13 17 17\\n11 14 5 11\\n15 16 2 9\\n\", \"ABAAAAAA\\nABABBAAAAAA\\n5\\n3 8 4 11\\n3 8 3 11\\n2 8 2 11\\n1 8 1 11\\n1 8 2 11\\n\", \"ABC\\nABC\\n9\\n1 1 1 1\\n1 1 2 2\\n1 1 3 3\\n2 2 1 1\\n2 2 2 2\\n2 2 3 3\\n3 3 1 1\\n3 3 2 2\\n3 3 3 3\\n\", \"A\\nBB\\n1\\n1 1 1 2\\n\", \"BBAACCBACACBCCCBBAAC\\nCACCAAABAACBBBBACABC\\n1\\n3 10 6 13\\n\", \"AAAAACAAAAAB\\nAAAAABAAAAAC\\n20\\n1 6 10 12\\n10 12 7 12\\n9 12 8 12\\n2 6 8 12\\n7 12 2 6\\n9 12 7 12\\n1 6 10 12\\n4 6 3 6\\n7 12 7 12\\n4 6 5 6\\n3 6 12 12\\n5 6 8 12\\n9 12 1 6\\n2 6 3 6\\n10 12 2 6\\n1 6 12 12\\n7 12 3 6\\n9 12 3 6\\n10 12 10 12\\n11 12 11 12\\n\", \"AAABABACACACAAACAC\\nAABCBBACABACBBCBCC\\n20\\n6 17 17 17\\n14 17 13 14\\n1 13 7 12\\n11 17 5 17\\n6 10 16 17\\n16 17 16 16\\n15 17 17 17\\n15 15 7 10\\n1 4 10 14\\n4 11 2 17\\n6 9 1 7\\n16 16 11 18\\n4 14 6 17\\n1 17 6 18\\n13 18 15 18\\n1 12 5 11\\n8 8 12 17\\n10 15 3 7\\n17 17 9 14\\n6 17 6 6\\n\", \"AAACAABB\\nCACBCCBB\\n10\\n2 2 4 5\\n4 4 3 3\\n1 4 1 8\\n5 5 2 8\\n7 7 3 4\\n6 6 2 2\\n1 7 1 1\\n6 7 7 8\\n4 6 6 8\\n8 8 6 8\\n\", \"A\\nCB\\n1\\n1 1 1 2\\n\", \"BCBBC\\nABBCB\\n5\\n2 2 2 4\\n3 4 2 4\\n1 2 2 2\\n2 3 4 5\\n5 5 2 4\\n\"], \"outputs\": [\"10011\\n\", \"111001000000000010101000001000\\n\", \"1\\n\", \"00001100101000010000\\n\", \"00111\\n\", \"100011011\\n\", \"1\\n\", \"0\\n\", \"11111111111111111111\\n\", \"00010001011111100110\\n\", \"1111010011\\n\", \"1\\n\", \"10011\\n\"]}", "source": "primeintellect"}
Alice has a string consisting of characters 'A', 'B' and 'C'. Bob can use the following transitions on any substring of our string in any order any number of times: A $\rightarrow$ BC B $\rightarrow$ AC C $\rightarrow$ AB AAA $\rightarrow$ empty string Note that a substring is one or more consecutive characters. For given queries, determine whether it is possible to obtain the target string from source. -----Input----- The first line contains a string S (1 ≤ |S| ≤ 10^5). The second line contains a string T (1 ≤ |T| ≤ 10^5), each of these strings consists only of uppercase English letters 'A', 'B' and 'C'. The third line contains the number of queries Q (1 ≤ Q ≤ 10^5). The following Q lines describe queries. The i-th of these lines contains four space separated integers a_{i}, b_{i}, c_{i}, d_{i}. These represent the i-th query: is it possible to create T[c_{i}..d_{i}] from S[a_{i}..b_{i}] by applying the above transitions finite amount of times? Here, U[x..y] is a substring of U that begins at index x (indexed from 1) and ends at index y. In particular, U[1..|U|] is the whole string U. It is guaranteed that 1 ≤ a ≤ b ≤ |S| and 1 ≤ c ≤ d ≤ |T|. -----Output----- Print a string of Q characters, where the i-th character is '1' if the answer to the i-th query is positive, and '0' otherwise. -----Example----- Input AABCCBAAB ABCB 5 1 3 1 2 2 2 2 4 7 9 1 1 3 4 2 3 4 5 1 3 Output 10011 -----Note----- In the first query we can achieve the result, for instance, by using transitions $A A B \rightarrow A A A C \rightarrow \operatorname{AAA} A B \rightarrow A B$. The third query asks for changing AAB to A — but in this case we are not able to get rid of the character '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\": [\"?aa?\\nab\\n\", \"??b?\\nza\\n\", \"abcd\\nabacaba\\n\", \"mqwstphetbfrsyxuzdww\\nrutseqtsbh\\n\", \"????????????????????\\nxwkxsxlrre\\n\", \"fzjqgrgzzzghrwgwhfjq\\nggwfrjzzqh\\n\", \"ng?\\nvu\\n\", \"???\\nb\\n\", \"??a?\\na\\n\", \"c?aa???a?cdcc??\\nabcadbaccb\\n\", \"cc?cdb?????b?cc?b?\\ncabdacd\\n\", \"ccaaa?bc?baccbccccbca?cccab??aacccbaac?bccacc?accccaccbcbbcbc\\ncbaaacccc\\n\", \"aacaacbabc?bcca?ccca\\nbc\\n\"], \"outputs\": [\"baab\\n\", \"azbz\\n\", \"abcd\\n\", \"mqwstphetbfrsyxuzdww\\n\", \"eekkllrrrrsswwxxxxxx\\n\", \"fzjqgrgzzzghrwgwhfjq\\n\", \"ngz\\n\", \"bbb\\n\", \"aaaa\\n\", \"cbaabbzazcdcczz\\n\", \"ccacdbaaaddbdcczbz\\n\", \"ccaaaabcabaccbccccbcaacccabaaaacccbaaczbccacczaccccaccbcbbcbc\\n\", \"aacaacbabcbbccabccca\\n\"]}", "source": "primeintellect"}
You are given two strings s and t consisting of small Latin letters, string s can also contain '?' characters. Suitability of string s is calculated by following metric: Any two letters can be swapped positions, these operations can be performed arbitrary number of times over any pair of positions. Among all resulting strings s, you choose the one with the largest number of non-intersecting occurrences of string t. Suitability is this number of occurrences. You should replace all '?' characters with small Latin letters in such a way that the suitability of string s is maximal. -----Input----- The first line contains string s (1 ≤ |s| ≤ 10^6). The second line contains string t (1 ≤ |t| ≤ 10^6). -----Output----- Print string s with '?' replaced with small Latin letters in such a way that suitability of that string is maximal. If there are multiple strings with maximal suitability then print any of them. -----Examples----- Input ?aa? ab Output baab Input ??b? za Output azbz Input abcd abacaba Output abcd -----Note----- In the first example string "baab" can be transformed to "abab" with swaps, this one has suitability of 2. That means that string "baab" also has suitability of 2. In the second example maximal suitability you can achieve is 1 and there are several dozens of such strings, "azbz" is just one of them. In the third example there are no '?' characters and the suitability of the string 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\": [\"2 1\\n2 2\\n2 1000\\n\", \"1 100\\n1 1\\n\", \"3 5\\n4 3\\n5 2\\n6 1\\n\", \"1 1\\n1 87\\n\", \"1 1\\n100 77\\n\", \"5 10\\n3 81\\n3 49\\n1 20\\n1 12\\n1 30\\n\", \"5 10\\n4 3\\n1 54\\n2 57\\n2 31\\n1 99\\n\", \"5 10\\n2 81\\n3 31\\n4 49\\n1 35\\n1 67\\n\", \"10 1\\n1 92\\n1 92\\n1 92\\n1 92\\n1 92\\n1 92\\n1 92\\n1 92\\n1 92\\n1 92\\n\", \"10 1\\n1 16\\n1 16\\n1 16\\n1 16\\n1 16\\n1 16\\n1 16\\n1 16\\n1 16\\n1 16\\n\", \"10 1\\n1 40\\n1 40\\n1 40\\n1 40\\n1 40\\n1 40\\n1 40\\n1 40\\n1 40\\n1 40\\n\", \"2 1\\n1 10\\n1 10\\n\", \"20 16807\\n75250 50074\\n43659 8931\\n11273 27545\\n50879 77924\\n37710 64441\\n38166 84493\\n43043 7988\\n22504 82328\\n31730 78841\\n42613 44304\\n33170 17710\\n97158 29561\\n70934 93100\\n80279 51817\\n95336 99098\\n7827 13513\\n29268 23811\\n77634 80980\\n79150 36580\\n58822 11968\\n\"], \"outputs\": [\"2.0000000000\", \"-1\\n\", \"0.5000000000\", \"-1\\n\", \"0.7777777778\", \"-1\\n\", \"-1\\n\", \"263.0000000000\", \"102.2222222222\", \"17.7777777778\", \"44.4444444444\", \"20.0000000000\", \"0.2244225704\"]}", "source": "primeintellect"}
You have n devices that you want to use simultaneously. The i-th device uses a_{i} units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·a_{i} units of power. The i-th device currently has b_{i} units of power stored. All devices can store an arbitrary amount of power. You have a single charger that can plug to any single device. The charger will add p units of power per second to a device. This charging is continuous. That is, if you plug in a device for λ seconds, it will gain λ·p units of power. You can switch which device is charging at any arbitrary unit of time (including real numbers), and the time it takes to switch is negligible. You are wondering, what is the maximum amount of time you can use the devices until one of them hits 0 units of power. If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. -----Input----- The first line contains two integers, n and p (1 ≤ n ≤ 100 000, 1 ≤ p ≤ 10^9) — the number of devices and the power of the charger. This is followed by n lines which contain two integers each. Line i contains the integers a_{i} and b_{i} (1 ≤ a_{i}, b_{i} ≤ 100 000) — the power of the device and the amount of power stored in the device in the beginning. -----Output----- If you can use the devices indefinitely, print -1. Otherwise, print the maximum amount of time before any one device hits 0 power. Your answer will be considered correct if its absolute or relative error does not exceed 10^{ - 4}. Namely, let's assume that your answer is a and the answer of the jury is b. The checker program will consider your answer correct if $\frac{|a - b|}{\operatorname{max}(1, b)} \leq 10^{-4}$. -----Examples----- Input 2 1 2 2 2 1000 Output 2.0000000000 Input 1 100 1 1 Output -1 Input 3 5 4 3 5 2 6 1 Output 0.5000000000 -----Note----- In sample test 1, you can charge the first device for the entire time until it hits zero power. The second device has enough power to last this time without being charged. In sample test 2, you can use the device indefinitely. In sample test 3, we can charge the third device for 2 / 5 of a second, then switch to charge the second device for a 1 / 10 of a second. 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\\n1 2 3\\n\", \"10 100000\\n1 2 3 4 5 6 7 8 9 10\\n\", \"2 100\\n1 2\\n\", \"10 100000\\n1 1 2 2 3 3 4 4 5 5\\n\", \"5 100000\\n1 1 1 1 1\\n\", \"1 0\\n1\\n\", \"2 1\\n1 1\\n\", \"2 1\\n2 2\\n\", \"86 95031\\n1 1 2 1 1 2 1 1 1 1 2 2 2 1 1 1 2 2 1 2 1 1 1 2 1 1 1 1 1 2 2 1 1 1 2 1 1 2 2 1 1 1 2 2 2 2 1 1 1 2 2 2 2 2 1 1 2 1 2 1 2 2 1 2 2 1 1 2 1 1 1 1 1 2 1 2 2 1 1 1 1 2 2 2 2 1\\n\", \"97 78153\\n2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 2 2 1 2 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2\\n\", \"39 93585\\n2 2 2 2 2 2 3 2 2 2 2 2 2 2 2 3 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2\\n\", \"73 80734\\n2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 1 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 2 3 2 2 2 2 2 2 2 3 2 2 2 2 2 2 2\\n\", \"41 26406\\n3 3 2 3 3 2 1 3 3 2 2 2 2 2 3 3 2 3 2 2 3 3 3 2 2 2 2 2 2 3 3 2 1 3 2 3 3 2 3 3 3\\n\"], \"outputs\": [\"8\\n\", \"334171350\\n\", \"252403355\\n\", \"475936186\\n\", \"943217271\\n\", \"1\\n\", \"3\\n\", \"1\\n\", \"1000000006\\n\", \"0\\n\", \"1000000006\\n\", \"1000000006\\n\", \"0\\n\"]}", "source": "primeintellect"}
When Darth Vader gets bored, he sits down on the sofa, closes his eyes and thinks of an infinite rooted tree where each node has exactly n sons, at that for each node, the distance between it an its i-th left child equals to d_{i}. The Sith Lord loves counting the number of nodes in the tree that are at a distance at most x from the root. The distance is the sum of the lengths of edges on the path between nodes. But he has got used to this activity and even grew bored of it. 'Why does he do that, then?' — you may ask. It's just that he feels superior knowing that only he can solve this problem. Do you want to challenge Darth Vader himself? Count the required number of nodes. As the answer can be rather large, find it modulo 10^9 + 7. -----Input----- The first line contains two space-separated integers n and x (1 ≤ n ≤ 10^5, 0 ≤ x ≤ 10^9) — the number of children of each node and the distance from the root within the range of which you need to count the nodes. The next line contains n space-separated integers d_{i} (1 ≤ d_{i} ≤ 100) — the length of the edge that connects each node with its i-th child. -----Output----- Print a single number — the number of vertexes in the tree at distance from the root equal to at most x. -----Examples----- Input 3 3 1 2 3 Output 8 -----Note----- Pictures to the sample (the yellow color marks the nodes the distance to which is at most three) [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\": [\"5\\n1 2 3 4 5\\n\", \"6\\n1 1 2 2 3 3\\n\", \"47\\n3 4 5 3 1 4 4 3 4 6 1 5 1 3 5 3 6 5 1 4 3 2 6 5 3 1 4 6 4 6 2 1 1 1 4 3 6 1 6 6 3 5 1 4 6 4 4\\n\", \"13\\n8 23 26 8 15 13 35 36 28 8 4 33 6\\n\", \"17\\n15 29 28 23 20 12 9 30 4 13 1 25 11 20 6 23 10\\n\", \"31\\n189 73 300 133 414 23 150 301 252 21 274 272 316 291 339 356 201 267 257 43 10 25 16 211 59 2 181 54 344 337 201\\n\", \"85\\n319 554 696 281 275 544 356 313 296 308 848 668 135 705 231 735 882 622 796 435 621 523 709 247 169 152 395 758 447 595 550 819 188 664 589 907 3 619 771 810 669 471 425 870 737 329 83 549 425 138 870 775 451 818 735 169 162 419 903 803 852 75 297 687 310 714 419 652 164 667 245 906 133 643 881 322 681 704 479 278 114 324 42 475 396\\n\", \"102\\n1830 2653 1293 4285 4679 3563 3668 4499 3507 2666 3507 1120 466 290 4280 60 4135 1120 289 1752 2101 2699 653 2811 3885 4018 4097 3142 2932 561 193 3662 3017 3487 3158 2876 3396 2806 3440 4503 1728 362 2194 2743 2946 596 1892 4785 3661 2971 3487 17 3616 2710 1189 613 915 3891 2654 554 3506 1938 2783 2537 4791 1098 930 1000 1007 942 3871 2547 1798 4610 1613 774 1347 1460 2752 3158 4540 4720 2639 887 1999 2046 1199 1889 426 1888 4317 649 1660 336 4728 2422 2771 3536 1683 3786 2711 308\\n\", \"1\\n1\\n\", \"2\\n1 1\\n\", \"3\\n1 2 3\\n\", \"3\\n2 1 2\\n\", \"2\\n1 2\\n\"], \"outputs\": [\"5\\n5 4 3 2 1\\n\", \"5\\n1 2 3 2 1\\n\", \"11\\n1 2 3 4 5 6 5 4 3 2 1\\n\", \"12\\n8 36 35 33 28 26 23 15 13 8 6 4\\n\", \"17\\n20 23 30 29 28 25 23 20 15 13 12 11 10 9 6 4 1\\n\", \"31\\n201 414 356 344 339 337 316 301 300 291 274 272 267 257 252 211 201 189 181 150 133 73 59 54 43 25 23 21 16 10 2\\n\", \"85\\n169 419 425 735 870 907 906 903 882 881 870 852 848 819 818 810 803 796 775 771 758 737 735 714 709 705 704 696 687 681 669 668 667 664 652 643 622 621 619 595 589 554 550 549 544 523 479 475 471 451 447 435 425 419 396 395 356 329 324 322 319 313 310 308 297 296 281 278 275 247 245 231 188 169 164 162 152 138 135 133 114 83 75 42 3\\n\", \"102\\n1120 3158 3487 3507 4791 4785 4728 4720 4679 4610 4540 4503 4499 4317 4285 4280 4135 4097 4018 3891 3885 3871 3786 3668 3662 3661 3616 3563 3536 3507 3506 3487 3440 3396 3158 3142 3017 2971 2946 2932 2876 2811 2806 2783 2771 2752 2743 2711 2710 2699 2666 2654 2653 2639 2547 2537 2422 2194 2101 2046 1999 1938 1892 1889 1888 1830 1798 1752 1728 1683 1660 1613 1460 1347 1293 1199 1189 1120 1098 1007 1000 942 930 915 887 774 653 649 613 596 561 554 466 426 362 336 308 290 289 193 60 17\\n\", \"1\\n1\\n\", \"1\\n1\\n\", \"3\\n3 2 1\\n\", \"2\\n2 1\\n\", \"2\\n2 1\\n\"]}", "source": "primeintellect"}
Sereja loves integer sequences very much. He especially likes stairs. Sequence a_1, a_2, ..., a_{|}a| (|a| is the length of the sequence) is stairs if there is such index i (1 ≤ i ≤ |a|), that the following condition is met: a_1 < a_2 < ... < a_{i} - 1 < a_{i} > a_{i} + 1 > ... > a_{|}a| - 1 > a_{|}a|. For example, sequences [1, 2, 3, 2] and [4, 2] are stairs and sequence [3, 1, 2] isn't. Sereja has m cards with numbers. He wants to put some cards on the table in a row to get a stair sequence. What maximum number of cards can he put on the table? -----Input----- The first line contains integer m (1 ≤ m ≤ 10^5) — the number of Sereja's cards. The second line contains m integers b_{i} (1 ≤ b_{i} ≤ 5000) — the numbers on the Sereja's cards. -----Output----- In the first line print the number of cards you can put on the table. In the second line print the resulting stairs. -----Examples----- Input 5 1 2 3 4 5 Output 5 5 4 3 2 1 Input 6 1 1 2 2 3 3 Output 5 1 2 3 2 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\\nc=aa#bb\\nd12=c\\nres=c^d12\\ntmp=aa$c\\n\", \"2\\nmax=aaaa$bbbb\\nmin=bbbb^aaaa\\n\", \"6\\nres=res\\nb=a\\nc=b\\nd=c\\nres=d\\nres=res\\n\", \"4\\nc=a\\na=b\\nb=c\\nres=a&b\\n\", \"1\\nres=res\\n\", \"6\\na=b\\nb=c\\nc=a\\nres=res&a\\nres=res#b\\nres=res^c\\n\", \"3\\na=res\\nres=x^y\\nres=a\\n\", \"9\\nc=a$b\\ne=c#c\\nf=c$c\\nh=a$b\\nx=h$h\\ny=h#h\\nz=x^y\\ng=f^e\\nres=z&g\\n\", \"3\\nd=a$b\\nres=d^c\\nddd=c#b\\n\", \"5\\nres=a\\nb=c&d\\ne=res&a\\nx=y\\nres=c$x\\n\", \"9\\nc111=a&b\\nd=b^a\\ne=c111#d\\nd=d\\nf=f\\nf=c111$d\\ng=e$f\\nh=e#f\\nres=g^h\\n\", \"7\\na=b&c\\nw=r#e\\nx=b^c\\nz=a&b\\nt=w^x\\nz=x&b\\nres=x$w\\n\", \"2\\np1=p2^p2\\nres=p1^p0\\n\"], \"outputs\": [\"2\\naaaa=aa#bb\\nres=aaaa^aaaa\\n\", \"0\", \"1\\nres=a\\n\", \"1\\nres=b&a\\n\", \"0\\n\", \"3\\naaaa=res&b\\naaab=aaaa#c\\nres=aaab^b\\n\", \"0\\n\", \"5\\naaaa=a$b\\naaab=aaaa$aaaa\\naaac=aaaa#aaaa\\naaad=aaab^aaac\\nres=aaad&aaad\\n\", \"2\\naaaa=a$b\\nres=aaaa^c\\n\", \"1\\nres=c$y\\n\", \"7\\naaaa=a&b\\naaab=b^a\\naaac=aaaa#aaab\\naaad=aaaa$aaab\\naaae=aaac$aaad\\naaaf=aaac#aaad\\nres=aaae^aaaf\\n\", \"3\\naaaa=b^c\\naaab=r#e\\nres=aaaa$aaab\\n\", \"2\\naaaa=p2^p2\\nres=aaaa^p0\\n\"]}", "source": "primeintellect"}
Let's analyze a program written on some strange programming language. The variables in this language have names consisting of $1$ to $4$ characters, and each character is a lowercase or an uppercase Latin letter, or a digit. There is an extra constraint that the first character should not be a digit. There are four types of operations in the program, each denoted by one of the characters: $, ^, # or &. Each line of the program has one of the following formats: <lvalue>=<rvalue>, where <lvalue> and <rvalue> are valid variable names; <lvalue>=<arg1><op><arg2>, where <lvalue>, <arg1> and <arg2> are valid variable names, and <op> is an operation character. The program is executed line-by-line, and the result of execution is stored in a variable having the name res. If res is never assigned in the program, then the result will be equal to the value of res before running the program. Two programs are called equivalent if no matter which operations do characters $, ^, # and & denote (but, obviously, performing the same operation on the same arguments gives the same result) and which values do variables have before execution of program, the value of res after running the first program is equal to the value of res after running the second program (the programs are executed independently). You are given a program consisting of $n$ lines. Your task is to write a program consisting of minimum possible number of lines that is equivalent to the program you are given. -----Input----- The first line contains one integer $n$ ($1 \le n \le 1000$) — the number of lines in the program. Then $n$ lines follow — the program itself. Each line corresponds to the format described in the statement and has no extra whitespaces. -----Output----- In the first line print $k$ — the minimum number of lines in the equivalent program. Then print $k$ lines without any whitespaces — an equivalent program having exactly $k$ lines, in the same format it is described in the statement. -----Examples----- Input 4 c=aa#bb d12=c res=c^d12 tmp=aa$c Output 2 aaaa=aa#bb res=aaaa^aaaa Input 2 max=aaaa$bbbb min=bbbb^aaaa 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\\n1 2\\n1 3\\n\", \"6\\n1 2\\n1 3\\n2 4\\n2 5\\n5 6\\n\", \"7\\n3 2\\n5 7\\n4 2\\n7 6\\n6 3\\n1 6\\n\", \"7\\n5 6\\n2 6\\n6 4\\n6 1\\n6 3\\n6 7\\n\", \"7\\n2 1\\n4 7\\n2 3\\n6 4\\n7 3\\n1 5\\n\", \"7\\n6 4\\n3 7\\n3 5\\n1 3\\n4 2\\n7 4\\n\", \"4\\n2 3\\n2 4\\n2 1\\n\", \"5\\n1 3\\n4 3\\n2 5\\n3 2\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"6\\n1 2\\n2 3\\n3 4\\n3 5\\n3 6\\n\", \"13\\n1 4\\n2 4\\n3 4\\n4 5\\n5 11\\n11 12\\n12 13\\n13 6\\n6 7\\n7 8\\n7 9\\n7 10\\n\", \"11\\n2 3\\n3 4\\n4 7\\n7 8\\n1 3\\n3 5\\n4 10\\n4 11\\n6 7\\n7 9\\n\"], \"outputs\": [\"0\\n1\\n\", \"0\\n3\\n1\\n2\\n4\\n\", \"3\\n4\\n5\\n0\\n1\\n2\\n\", \"0\\n1\\n2\\n3\\n4\\n5\\n\", \"2\\n0\\n3\\n4\\n1\\n5\\n\", \"0\\n3\\n4\\n5\\n1\\n2\\n\", \"0\\n1\\n2\\n\", \"0\\n1\\n3\\n2\\n\", \"0\\n\", \"0\\n\", \"4\\n0\\n1\\n2\\n3\\n\", \"4\\n5\\n6\\n7\\n8\\n9\\n10\\n11\\n0\\n1\\n2\\n3\\n\", \"4\\n5\\n0\\n1\\n6\\n7\\n8\\n9\\n2\\n3\\n\"]}", "source": "primeintellect"}
You are given a tree consisting of $n$ nodes. You want to write some labels on the tree's edges such that the following conditions hold: Every label is an integer between $0$ and $n-2$ inclusive. All the written labels are distinct. The largest value among $MEX(u,v)$ over all pairs of nodes $(u,v)$ is as small as possible. Here, $MEX(u,v)$ denotes the smallest non-negative integer that isn't written on any edge on the unique simple path from node $u$ to node $v$. -----Input----- The first line contains the integer $n$ ($2 \le n \le 10^5$) — the number of nodes in the tree. Each of the next $n-1$ lines contains two space-separated integers $u$ and $v$ ($1 \le u,v \le n$) that mean there's an edge between nodes $u$ and $v$. It's guaranteed that the given graph is a tree. -----Output----- Output $n-1$ integers. The $i^{th}$ of them will be the number written on the $i^{th}$ edge (in the input order). -----Examples----- Input 3 1 2 1 3 Output 0 1 Input 6 1 2 1 3 2 4 2 5 5 6 Output 0 3 2 4 1 -----Note----- The tree from the second sample: [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\": [\"8\\n1 2 7 3 4 8 5 6\\n\", \"6\\n25 1 2 3 14 36\\n\", \"20\\n1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11\\n\", \"7\\n1 2 5 7 3 4 6\\n\", \"1\\n1000000000\\n\", \"1\\n1\\n\", \"2\\n1 2\\n\", \"2\\n2 1\\n\", \"22\\n22 1 20 2 19 3 18 4 17 5 16 6 15 7 14 8 13 9 12 10 11 21\\n\", \"63\\n32 48 31 56 30 47 29 60 28 46 27 55 26 45 25 62 24 44 23 54 22 43 21 59 20 42 19 53 18 41 17 63 16 40 15 52 14 39 13 58 12 38 11 51 10 37 9 61 8 36 7 50 6 35 5 57 4 34 3 49 2 33 1\\n\", \"127\\n64 96 63 112 62 95 61 120 60 94 59 111 58 93 57 124 56 92 55 110 54 91 53 119 52 90 51 109 50 89 49 126 48 88 47 108 46 87 45 118 44 86 43 107 42 85 41 123 40 84 39 106 38 83 37 117 36 82 35 105 34 81 33 127 32 80 31 104 30 79 29 116 28 78 27 103 26 77 25 122 24 76 23 102 22 75 21 115 20 74 19 101 18 73 17 125 16 72 15 100 14 71 13 114 12 70 11 99 10 69 9 121 8 68 7 98 6 67 5 113 4 66 3 97 2 65 1\\n\", \"100\\n1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 100 99 98 97 96 95 94 93 92 91 90 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 73 72 71 70 69 68 67 66 65 64 63 62 61\\n\", \"10\\n1 2 3 10 9 8 4 5 6 7\\n\"], \"outputs\": [\"7\", \"2\", \"11\", \"5\", \"1000000001\", \"2\", \"2\", \"2\", \"11\", \"33\", \"65\", \"61\", \"7\"]}", "source": "primeintellect"}
For long time scientists study the behavior of sharks. Sharks, as many other species, alternate short movements in a certain location and long movements between locations. Max is a young biologist. For $n$ days he watched a specific shark, and now he knows the distance the shark traveled in each of the days. All the distances are distinct. Max wants to know now how many locations the shark visited. He assumed there is such an integer $k$ that if the shark in some day traveled the distance strictly less than $k$, then it didn't change the location; otherwise, if in one day the shark traveled the distance greater than or equal to $k$; then it was changing a location in that day. Note that it is possible that the shark changed a location for several consecutive days, in each of them the shark traveled the distance at least $k$. The shark never returned to the same location after it has moved from it. Thus, in the sequence of $n$ days we can find consecutive nonempty segments when the shark traveled the distance less than $k$ in each of the days: each such segment corresponds to one location. Max wants to choose such $k$ that the lengths of all such segments are equal. Find such integer $k$, that the number of locations is as large as possible. If there are several such $k$, print the smallest one. -----Input----- The first line contains a single integer $n$ ($1 \leq n \leq 10^5$) — the number of days. The second line contains $n$ distinct positive integers $a_1, a_2, \ldots, a_n$ ($1 \leq a_i \leq 10^9$) — the distance traveled in each of the day. -----Output----- Print a single integer $k$, such that the shark was in each location the same number of days, the number of locations is maximum possible satisfying the first condition, $k$ is smallest possible satisfying the first and second conditions. -----Examples----- Input 8 1 2 7 3 4 8 5 6 Output 7 Input 6 25 1 2 3 14 36 Output 2 -----Note----- In the first example the shark travels inside a location on days $1$ and $2$ (first location), then on $4$-th and $5$-th days (second location), then on $7$-th and $8$-th days (third location). There are three locations in total. In the second example the shark only moves inside a location on the $2$-nd day, so there is only one location. 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\": [\"3\\n2\\n1234\\n0600\\n2\\n1337\\n1337\\n4\\n3139\\n3139\\n3139\\n3139\\n\", \"3\\n10\\n0000\\n0000\\n0000\\n0000\\n0000\\n0000\\n0000\\n0000\\n0000\\n0000\\n1\\n1234\\n7\\n1234\\n4567\\n8901\\n2345\\n6789\\n0123\\n4567\\n\", \"4\\n4\\n3139\\n3138\\n3138\\n3137\\n4\\n3138\\n3148\\n3148\\n3158\\n4\\n3138\\n3238\\n3238\\n3338\\n4\\n3138\\n4138\\n4138\\n5138\\n\", \"1\\n3\\n0000\\n0000\\n0001\\n\", \"14\\n3\\n0000\\n0000\\n0001\\n3\\n0000\\n0001\\n0000\\n3\\n0001\\n0000\\n0000\\n3\\n0000\\n0000\\n1000\\n3\\n0000\\n1000\\n0000\\n3\\n1000\\n0000\\n0000\\n3\\n0000\\n0001\\n0001\\n3\\n0001\\n0000\\n0001\\n3\\n0001\\n0001\\n0000\\n3\\n0000\\n1000\\n1000\\n3\\n1000\\n0000\\n1000\\n3\\n1000\\n1000\\n0000\\n4\\n0000\\n0001\\n0001\\n0002\\n4\\n0000\\n1000\\n1000\\n2000\\n\", \"1\\n3\\n0990\\n0990\\n0991\\n\", \"1\\n3\\n1234\\n1234\\n1034\\n\", \"1\\n3\\n1111\\n1111\\n1112\\n\", \"3\\n3\\n0000\\n0000\\n0001\\n4\\n0000\\n0000\\n0001\\n0002\\n4\\n0000\\n0000\\n0001\\n0003\\n\", \"1\\n3\\n1234\\n1234\\n1230\\n\", \"1\\n3\\n0000\\n0000\\n0009\\n\", \"1\\n4\\n0000\\n0000\\n0000\\n0001\\n\", \"1\\n3\\n1000\\n1000\\n9000\\n\"], \"outputs\": [\"0\\n1234\\n0600\\n1\\n1337\\n0337\\n3\\n3139\\n0139\\n1139\\n2139\\n\", \"9\\n0000\\n1000\\n2000\\n3000\\n4000\\n5000\\n6000\\n7000\\n8000\\n9000\\n0\\n1234\\n1\\n1234\\n4567\\n8901\\n2345\\n6789\\n0123\\n0567\\n\", \"1\\n3139\\n3138\\n0138\\n3137\\n1\\n3138\\n3148\\n0148\\n3158\\n1\\n3138\\n3238\\n0238\\n3338\\n1\\n3138\\n4138\\n0138\\n5138\\n\", \"1\\n0000\\n1000\\n0001\\n\", \"1\\n0000\\n1000\\n0001\\n1\\n0000\\n0001\\n1000\\n1\\n0001\\n0000\\n1000\\n1\\n0000\\n2000\\n1000\\n1\\n0000\\n1000\\n2000\\n1\\n1000\\n0000\\n2000\\n1\\n0000\\n0001\\n1001\\n1\\n0001\\n0000\\n1001\\n1\\n0001\\n1001\\n0000\\n1\\n0000\\n1000\\n2000\\n1\\n1000\\n0000\\n2000\\n1\\n1000\\n2000\\n0000\\n1\\n0000\\n0001\\n1001\\n0002\\n1\\n0000\\n1000\\n3000\\n2000\\n\", \"1\\n0990\\n1990\\n0991\\n\", \"1\\n1234\\n0234\\n1034\\n\", \"1\\n1111\\n0111\\n1112\\n\", \"1\\n0000\\n1000\\n0001\\n1\\n0000\\n1000\\n0001\\n0002\\n1\\n0000\\n1000\\n0001\\n0003\\n\", \"1\\n1234\\n0234\\n1230\\n\", \"1\\n0000\\n1000\\n0009\\n\", \"2\\n0000\\n1000\\n2000\\n0001\\n\", \"1\\n1000\\n0000\\n9000\\n\"]}", "source": "primeintellect"}
A PIN code is a string that consists of exactly $4$ digits. Examples of possible PIN codes: 7013, 0000 and 0990. Please note that the PIN code can begin with any digit, even with 0. Polycarp has $n$ ($2 \le n \le 10$) bank cards, the PIN code of the $i$-th card is $p_i$. Polycarp has recently read a recommendation that it is better to set different PIN codes on different cards. Thus he wants to change the minimal number of digits in the PIN codes of his cards so that all $n$ codes would become different. Formally, in one step, Polycarp picks $i$-th card ($1 \le i \le n$), then in its PIN code $p_i$ selects one position (from $1$ to $4$), and changes the digit in this position to any other. He needs to change the minimum number of digits so that all PIN codes become different. Polycarp quickly solved this problem. Can you solve it? -----Input----- The first line contains integer $t$ ($1 \le t \le 100$) — the number of test cases in the input. Then test cases follow. The first line of each of $t$ test sets contains a single integer $n$ ($2 \le n \le 10$) — the number of Polycarp's bank cards. The next $n$ lines contain the PIN codes $p_1, p_2, \dots, p_n$ — one per line. The length of each of them is $4$. All PIN codes consist of digits only. -----Output----- Print the answers to $t$ test sets. The answer to each set should consist of a $n + 1$ lines In the first line print $k$ — the least number of changes to make all PIN codes different. In the next $n$ lines output the changed PIN codes in the order corresponding to their appearance in the input. If there are several optimal answers, print any of them. -----Example----- Input 3 2 1234 0600 2 1337 1337 4 3139 3139 3139 3139 Output 0 1234 0600 1 1337 1237 3 3139 3138 3939 6139 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\": [\"16\\nfun while return var { } ( ) , ; > = + ++ - --\\n9\\nfun fib(num) { # compute fibs\\n var return_value = 1, prev = 0, temp;\\n while (num > 0) {\\n temp = return_value; return_value = return_value + prev;\\n prev = temp;\\n num--;\\n }\\n return return_value;\\n}\\n\", \"10\\n( ) + ++ : -> >> >>: b c)\\n2\\n($val1++ + +4 kb) >> :out\\nb-> + 10 >>: t # using >>: \\n\", \"0\\n\\n2\\none two three four five seven\\none two three four five seven\\n\", \"3\\n1 8 21\\n2\\n0 1 1 2 3 5 8 13 21\\n0 1 1 2 3 5 8 13 21\\n\", \"4\\n+ ++ +++ ++++\\n2\\n+ ++ +++ ++++ ++ + +++ ++++ + ++++ ++ +\\n+ ++ +++ ++++ ++ + +++ ++++ + ++++ ++ +\\n\", \"2\\nz 05c\\n2\\n01 x 02 y 03 z 05 xx 06 yy 07 zz 08 xxx 09 yyy 10 zzzz \\n11 x 12 y 13 z 15 xx 16 yy 17 zz 18 xxx 19 yyy 20 zzzz # ^^^ trailing spaces!\\n\", \"7\\n! + = ( ) fun foo+bar\\n7\\n# Such comments!\\n# Much nothing!\\nfoo! bar+# but...\\n# Here's more foo bar\\nfoo+bar!\\nfun(foo)=bar\\n# how's that? that was sneaky!\\n\", \"10\\n+ - * / ^ a+ b- c* 1/ 01^\\n5\\nx + y + z + 1 + 01 + 001\\nx - y - z - 1 - 01 - 001\\nx * y * z * 1 * 01 * 001\\nx / y / z / 1 / 01 / 001\\nx ^ y ^ z ^ 1 ^ 01 ^ 001\\n\", \"8\\n< > << >> in out fun in>>out\\n6\\n# let's rock\\nin>>out in >> out inout>>outin bin>>out # yay!\\nfun>>in>>out funin>>out out>>in <in> > <out>\\nin> >> >>> >>>> >>>>>out\\n# what's going on here?\\n<> <> <> <> <fun> <funfun> <not so fun>\\n\", \"2\\n! 123!!456\\n4\\n1112233334447777778888999000001111 222233444455566677778889991 # quite a long!\\n123!!456789 # ho-ho! what a catch!\\n123!!456abc # a variant of that\\n0123!!456789 # that is not going to work\\n\", \"4\\n+ = +=+ =+=\\n1\\n+ = + =\\n\", \"3\\n+ = =+=\\n1\\n+ = + =\\n\", \"6\\n+=-; =- + = - ;\\n1\\n+ = - ;\\n\"], \"outputs\": [\"fun a(b){var c=1,d=0,e;while(b>0){e=c;c=c+d;d=e;b--;}return c;}\\n\", \"(a+++ +4c )>> :d b->+10>>:e\\n\", \"a b c d e f a b c d e f\\n\", \"0 1 1 2 3 5 8 13 21 0 1 1 2 3 5 8 13 21\\n\", \"+ ++ +++ ++++++ + +++ +++++ ++++++ + + ++ +++ ++++++ + +++ +++++ ++++++ +\\n\", \"01a 02b 03z 05 c 06d 07e 08f 09g 10h 11a 12b 13z 15c 16d 17e 18f 19g 20h\\n\", \"a!b+foo+bar!fun(a)=b\\n\", \"a +b+c+1+01+001a-b -c-1-01-001a*b*c *1*01*001a/b/c/1 /01/001a^b^c^1^01 ^001\\n\", \"in>>outin>> out a>>b c>>out fun>>in>>outd>>out out>>in<in> ><out>in> >>>>> >>>>>>>>>out<><><><><fun><e><f g fun>\\n\", \"1112233334447777778888999000001111 222233444455566677778889991 123!!456789 123!!456a 0123!!456789\\n\", \"+= +=\\n\", \"+=+ =\\n\", \"+= -;\\n\"]}", "source": "primeintellect"}
International Coding Procedures Company (ICPC) writes all its code in Jedi Script (JS) programming language. JS does not get compiled, but is delivered for execution in its source form. Sources contain comments, extra whitespace (including trailing and leading spaces), and other non-essential features that make them quite large but do not contribute to the semantics of the code, so the process of minification is performed on source files before their delivery to execution to compress sources while preserving their semantics. You are hired by ICPC to write JS minifier for ICPC. Fortunately, ICPC adheres to very strict programming practices and their JS sources are quite restricted in grammar. They work only on integer algorithms and do not use floating point numbers and strings. Every JS source contains a sequence of lines. Each line contains zero or more tokens that can be separated by spaces. On each line, a part of the line that starts with a hash character ('#' code 35), including the hash character itself, is treated as a comment and is ignored up to the end of the line. Each line is parsed into a sequence of tokens from left to right by repeatedly skipping spaces and finding the longest possible token starting at the current parsing position, thus transforming the source code into a sequence of tokens. All the possible tokens are listed below: A reserved token is any kind of operator, separator, literal, reserved word, or a name of a library function that should be preserved during the minification process. Reserved tokens are fixed strings of non-space ASCII characters that do not contain the hash character ('#' code 35). All reserved tokens are given as an input to the minification process. A number token consists of a sequence of digits, where a digit is a character from zero ('0') to nine ('9') inclusive. A word token consists of a sequence of characters from the following set: lowercase letters, uppercase letters, digits, underscore ('_' code 95), and dollar sign ('$' code 36). A word does not start with a digit. Note, that during parsing the longest sequence of characters that satisfies either a number or a word definition, but that appears in the list of reserved tokens, is considered to be a reserved token instead. During the minification process words are renamed in a systematic fashion using the following algorithm: Take a list of words that consist only of lowercase letters ordered first by their length, then lexicographically: "a", "b", ..., "z", "aa", "ab", ..., excluding reserved tokens, since they are not considered to be words. This is the target word list. Rename the first word encountered in the input token sequence to the first word in the target word list and all further occurrences of the same word in the input token sequence, too. Rename the second new word encountered in the input token sequence to the second word in the target word list, and so on. The goal of the minification process is to convert the given source to the shortest possible line (counting spaces) that still parses to the same sequence of tokens with the correspondingly renamed words using these JS parsing rules. -----Input----- The first line of the input contains a single integer $n$ ($0 \le n \le 40$) — the number of reserved tokens. The second line of the input contains the list of reserved tokens separated by spaces without repetitions in the list. Each reserved token is at least one and at most 20 characters long and contains only characters with ASCII codes from 33 (exclamation mark) to 126 (tilde) inclusive, with exception of a hash character ('#' code 35). The third line of the input contains a single integer $m$ ($1 \le m \le 40$) — the number of lines in the input source code. Next $m$ lines contain the input source, each source line is at most 80 characters long (counting leading and trailing spaces). Each line contains only characters with ASCII codes from 32 (space) to 126 (tilde) inclusive. The source code is valid and fully parses into a sequence of tokens. -----Output----- Write to the output a single line that is the result of the minification process on the input source code. The output source line shall parse to the same sequence of tokens as the input source with the correspondingly renamed words and shall contain the minimum possible number of spaces needed for that. If there are multiple ways to insert the minimum possible number of spaces into the output, use any way. -----Examples----- Input 16 fun while return var { } ( ) , ; > = + ++ - -- 9 fun fib(num) { # compute fibs var return_value = 1, prev = 0, temp; while (num > 0) { temp = return_value; return_value = return_value + prev; prev = temp; num--; } return return_value; } Output fun a(b){var c=1,d=0,e;while(b>0){e=c;c=c+d;d=e;b--;}return c;} Input 10 ( ) + ++ : -> >> >>: b c) 2 ($val1++ + +4 kb) >> :out b-> + 10 >>: t # using >>: Output (a+++ +4c )>> :d b->+10>>:e 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\\n1 7 3 5\\n\", \"5 5\\n1 10 100 1000 10000\\n\", \"2 2\\n52233 12247\\n\", \"3 2\\n4 4 4\\n\", \"10 3\\n10000 20000 30000 40000 50000 60000 70000 80000 90000 100000\\n\", \"6 4\\n36874 16401 3128 2000 1343 1260\\n\", \"12 7\\n15809 57514 78998 84734 87276 90593 95915 97387 98583 99971 99991 99997\\n\", \"52 52\\n19752 66708 73109 84463 95683 96876 98503 98812 99766 99778 99913 99975 99977 99997 99997 99997 99998 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\", \"5 3\\n96497 62751 76014 23191 16861\\n\", \"14 12\\n681 14683 40716 67845 32350 92400 5755 68869 24772 1955 56419 89403 87360 90186\\n\", \"5 3\\n100 100 100 100 100\\n\", \"100 51\\n245 196 57 35 8 4 2 1 1 1 1 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 0 0 0 0 0\\n\", \"4 3\\n1279 80972 85162 86681\\n\"], \"outputs\": [\"8\", \"9\", \"39986\", \"0\", \"2000000\", \"9470\", \"451011\", \"0\", \"167237\", \"78278\", \"0\", \"0\", \"12937\"]}", "source": "primeintellect"}
Let's call beauty of an array $b_1, b_2, \ldots, b_n$ ($n > 1$)  — $\min\limits_{1 \leq i < j \leq n} |b_i - b_j|$. You're given an array $a_1, a_2, \ldots a_n$ and a number $k$. Calculate the sum of beauty over all subsequences of the array of length exactly $k$. As this number can be very large, output it modulo $998244353$. A sequence $a$ is a subsequence of an array $b$ if $a$ can be obtained from $b$ by deletion of several (possibly, zero or all) elements. -----Input----- The first line contains integers $n, k$ ($2 \le k \le n \le 1000$). The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($0 \le a_i \le 10^5$). -----Output----- Output one integer — the sum of beauty over all subsequences of the array of length exactly $k$. As this number can be very large, output it modulo $998244353$. -----Examples----- Input 4 3 1 7 3 5 Output 8 Input 5 5 1 10 100 1000 10000 Output 9 -----Note----- In the first example, there are $4$ subsequences of length $3$ — $[1, 7, 3]$, $[1, 3, 5]$, $[7, 3, 5]$, $[1, 7, 5]$, each of which has beauty $2$, so answer is $8$. In the second example, there is only one subsequence of length $5$ — the whole array, which has the beauty equal to $|10-1| = 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
{"tests": "{\"inputs\": [\"7 3\\n1 5 16 18 7 2 10\\nbaaaaca\\n\", \"5 5\\n2 4 1 3 1000\\naaaaa\\n\", \"5 4\\n2 4 1 3 1000\\naaaaa\\n\", \"8 1\\n10 15 2 1 4 8 15 16\\nqqwweerr\\n\", \"6 3\\n14 18 9 19 2 15\\ncccccc\\n\", \"2 1\\n10 10\\nqq\\n\", \"1 1\\n10\\nz\\n\", \"1 1\\n1\\na\\n\", \"1 1\\n1000000000\\nz\\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 53 1 1 1 1 1 1 1 1 1 1 1 1 1 1\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\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 53 1 1 1 1 1 1 1 1 1 1 1 1 1\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\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 53 53 1 1 1 1 1 1 1 1 1 1 1 1\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\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 53 53 53 1 1 1 1 1 1 1 1 1 1 1\\naaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa\\n\"], \"outputs\": [\"54\\n\", \"1010\\n\", \"1009\\n\", \"41\\n\", \"52\\n\", \"10\\n\", \"10\\n\", \"1\\n\", \"1000000000\\n\", \"53\\n\", \"53\\n\", \"53\\n\", \"53\\n\"]}", "source": "primeintellect"}
You are playing a new famous fighting game: Kortal Mombat XII. You have to perform a brutality on your opponent's character. You are playing the game on the new generation console so your gamepad have $26$ buttons. Each button has a single lowercase Latin letter from 'a' to 'z' written on it. All the letters on buttons are pairwise distinct. You are given a sequence of hits, the $i$-th hit deals $a_i$ units of damage to the opponent's character. To perform the $i$-th hit you have to press the button $s_i$ on your gamepad. Hits are numbered from $1$ to $n$. You know that if you press some button more than $k$ times in a row then it'll break. You cherish your gamepad and don't want to break any of its buttons. To perform a brutality you have to land some of the hits of the given sequence. You are allowed to skip any of them, however changing the initial order of the sequence is prohibited. The total damage dealt is the sum of $a_i$ over all $i$ for the hits which weren't skipped. Note that if you skip the hit then the counter of consecutive presses the button won't reset. Your task is to skip some hits to deal the maximum possible total damage to the opponent's character and not break your gamepad buttons. -----Input----- The first line of the input contains two integers $n$ and $k$ ($1 \le k \le n \le 2 \cdot 10^5$) — the number of hits and the maximum number of times you can push the same button in a row. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the damage of the $i$-th hit. The third line of the input contains the string $s$ consisting of exactly $n$ lowercase Latin letters — the sequence of hits (each character is the letter on the button you need to press to perform the corresponding hit). -----Output----- Print one integer $dmg$ — the maximum possible damage to the opponent's character you can deal without breaking your gamepad buttons. -----Examples----- Input 7 3 1 5 16 18 7 2 10 baaaaca Output 54 Input 5 5 2 4 1 3 1000 aaaaa Output 1010 Input 5 4 2 4 1 3 1000 aaaaa Output 1009 Input 8 1 10 15 2 1 4 8 15 16 qqwweerr Output 41 Input 6 3 14 18 9 19 2 15 cccccc Output 52 Input 2 1 10 10 qq Output 10 -----Note----- In the first example you can choose hits with numbers $[1, 3, 4, 5, 6, 7]$ with the total damage $1 + 16 + 18 + 7 + 2 + 10 = 54$. In the second example you can choose all hits so the total damage is $2 + 4 + 1 + 3 + 1000 = 1010$. In the third example you can choose all hits expect the third one so the total damage is $2 + 4 + 3 + 1000 = 1009$. In the fourth example you can choose hits with numbers $[2, 3, 6, 8]$. Only this way you can reach the maximum total damage $15 + 2 + 8 + 16 = 41$. In the fifth example you can choose only hits with numbers $[2, 4, 6]$ with the total damage $18 + 19 + 15 = 52$. In the sixth example you can change either first hit or the second hit (it does not matter) with the total damage $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.5
{"tests": "{\"inputs\": [\"3\\n12 3 45\\n\", \"2\\n123 456\\n\", \"20\\n80 9 55 1 98 29 81 10 96 100 70 87 86 12 58 82 10 22 59 13\\n\", \"100\\n3615 1436 2205 5695 9684 7621 391 1579 557 420 1756 5265 247 5494 3509 6089 2931 7372 4939 8030 2901 1150 5389 7168 6213 2723 4301 7250 3857 9178 4723 1932 1161 1412 8200 5226 1474 3495 9533 8555 6372 1517 8034 6547 1148 9651 2399 3065 9675 3418 7758 3226 9844 4234 510 7652 162 8010 8162 2732 2112 4041 3392 6344 671 4120 4659 7718 8660 7102 9098 6195 6999 9411 6710 2261 4388 7125 3808 978 398 9286 1280 7382 1095 8203 5687 9281 3722 8159 470 5735 4210 3694 2197 5422 816 7546 9965 2963\\n\", \"20\\n4 53 9 79 47 2 64 98 51 82 14 30 77 41 69 4 37 85 81 62\\n\", \"1\\n123767132\\n\", \"100\\n463 6421 2912 1546 3999 5175 4357 2259 7380 6081 1148 7857 3532 4168 5643 8819 2568 6681 975 9216 4590 5217 6215 7422 6631 1651 39 4268 8290 2022 3175 8281 1552 980 9314 234 934 5133 6712 1880 2766 5042 5004 5455 6038 6010 6022 1553 4015 4544 3985 4033 223 7682 6302 2121 4832 3956 9872 8340 5327 6763 2063 6708 4733 8339 2933 8477 7857 6074 1299 5768 3029 7138 8653 9121 6901 6803 5306 9098 6803 2902 9941 3926 3269 5739 3823 7278 3413 5796 4346 9968 3024 3416 7311 9307 4840 2545 2041 5300\\n\", \"20\\n28 98 66 48 1 74 39 86 11 68 57 82 71 78 96 21 51 35 3 11\\n\", \"20\\n56 42 16 26 62 47 23 74 70 47 97 26 65 12 15 38 78 97 21 52\\n\", \"20\\n76 86 70 7 16 24 10 62 26 29 40 65 55 49 34 55 92 47 43 100\\n\", \"100\\n7039 7577 5463 7876 8938 6398 2374 5567 521 1898 8004 5009 6146 7735 8024 4006 4845 9123 2957 2271 6649 7439 5602 1551 70 1443 8522 2111 8170 2152 3949 714 6557 7548 309 9826 3500 866 9474 1769 3961 6927 6519 1001 7849 8030 1914 7309 7589 6077 3576 4981 5642 8862 3406 4886 5945 4631 4017 536 5815 8850 2727 918 2702 6974 5148 3841 3259 2940 6750 8686 2718 1922 5586 3395 3549 6220 6653 782 9952 7446 2907 2206 7926 2579 4555 1928 5663 9273 7408 2851 5713 8355 1106 812 5732 6398 3099 2579\\n\", \"100\\n6591 1074 3466 3728 549 5440 533 3543 1536 2967 1587 304 6326 6410 8670 6736 4482 8431 1697 9264 8338 2995 3725 1805 488 4563 4261 6025 2602 1892 9297 4359 1139 7117 1423 4834 5663 7912 1245 9287 3059 8964 785 2614 4226 7093 5537 7285 1929 4499 9803 7277 212 2311 9198 9355 6422 577 9919 4656 1734 85 4102 3986 956 7000 4910 1897 6648 9208 3144 2850 6044 3842 232 256 653 90 3959 1606 550 9846 1567 8750 2804 7411 9986 7221 1163 9615 1284 7084 7631 1181 6220 505 9756 8692 7879 4916\\n\", \"100\\n15 7214 8212 3205 5610 4217 5220 235 5691 7149 2027 7344 6416 139 481 4653 4909 8693 9715 6209 2087 6580 1234 6189 7049 580 8482 886 19 1763 5819 4630 9238 549 6236 7946 4585 5283 1187 2501 9159 4375 2374 7068 8223 8177 9645 8825 2547 5669 8725 6329 601 1131 9390 9293 8013 7198 5774 2460 3949 2190 3437 1264 2988 8366 5399 8021 1247 2342 3501 1149 9059 6354 9108 8686 9813 673 6804 7218 7400 8006 9002 3574 9635 3275 1958 9867 8912 9241 5518 1497 4943 1650 937 5895 8865 7544 6821 340\\n\"], \"outputs\": [\"12330\", \"1115598\", \"2248760\", \"674832474\", \"1675580\", \"116407724\", \"495837625\", \"1899280\", \"1934680\", \"2178920\", \"906817803\", \"167137718\", \"666837072\"]}", "source": "primeintellect"}
This problem differs from the previous one only in the absence of the constraint on the equal length of all numbers $a_1, a_2, \dots, a_n$. A team of SIS students is going to make a trip on a submarine. Their target is an ancient treasure in a sunken ship lying on the bottom of the Great Rybinsk sea. Unfortunately, the students don't know the coordinates of the ship, so they asked Meshanya (who is a hereditary mage) to help them. He agreed to help them, but only if they solve his problem. Let's denote a function that alternates digits of two numbers $f(a_1 a_2 \dots a_{p - 1} a_p, b_1 b_2 \dots b_{q - 1} b_q)$, where $a_1 \dots a_p$ and $b_1 \dots b_q$ are digits of two integers written in the decimal notation without leading zeros. In other words, the function $f(x, y)$ alternately shuffles the digits of the numbers $x$ and $y$ by writing them from the lowest digits to the older ones, starting with the number $y$. The result of the function is also built from right to left (that is, from the lower digits to the older ones). If the digits of one of the arguments have ended, then the remaining digits of the other argument are written out. Familiarize with examples and formal definitions of the function below. For example: $$f(1111, 2222) = 12121212$$ $$f(7777, 888) = 7787878$$ $$f(33, 44444) = 4443434$$ $$f(555, 6) = 5556$$ $$f(111, 2222) = 2121212$$ Formally, if $p \ge q$ then $f(a_1 \dots a_p, b_1 \dots b_q) = a_1 a_2 \dots a_{p - q + 1} b_1 a_{p - q + 2} b_2 \dots a_{p - 1} b_{q - 1} a_p b_q$; if $p < q$ then $f(a_1 \dots a_p, b_1 \dots b_q) = b_1 b_2 \dots b_{q - p} a_1 b_{q - p + 1} a_2 \dots a_{p - 1} b_{q - 1} a_p b_q$. Mishanya gives you an array consisting of $n$ integers $a_i$, your task is to help students to calculate $\sum_{i = 1}^{n}\sum_{j = 1}^{n} f(a_i, a_j)$ modulo $998\,244\,353$. -----Input----- The first line of the input contains a single integer $n$ ($1 \le n \le 100\,000$) — the number of elements in the array. The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the elements of the array. -----Output----- Print the answer modulo $998\,244\,353$. -----Examples----- Input 3 12 3 45 Output 12330 Input 2 123 456 Output 1115598 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\": [\"15 2\\n4\\nUURL\\n8\\nLRLLLLLLLL\\n\", \"1 1\\n1\\nL\\n\", \"1 1\\n1\\nR\\n\", \"1 1\\n1\\nU\\n\", \"1 10\\n1\\nURLRLULUR\\n1\\nLRRRURULULL\\n1\\nLURURRUUUU\\n1\\nRRULLLRRUL\\n1\\nUULLUURL\\n1\\nRLRRULUL\\n1\\nLURRLRUULRR\\n1\\nLULLULUUUL\\n1\\nURULLULL\\n1\\nLRRLRUUUURRLRRL\\n\", \"3 10\\n2\\nRUUUULULULUU\\n1\\nULLLURLU\\n3\\nLLURLULU\\n2\\nRRLURLURLLR\\n3\\nLRURURLRLLL\\n3\\nLRLULRRUURURRL\\n1\\nRULLR\\n2\\nLRULLURUL\\n3\\nRLL\\n1\\nULRUULURLULLLLLLRLL\\n\", \"7 10\\n3\\nLLULULLLR\\n4\\nLUUURLLLUURRU\\n1\\nULURR\\n6\\nLURLLLLRLR\\n2\\nULULURU\\n7\\nRRUUUURLRLR\\n7\\nUUURRULRRLUL\\n7\\nULLLRUULULR\\n6\\nUURRLL\\n6\\nRULUUULLRLLLUULL\\n\", \"15 10\\n1\\nURUUUR\\n15\\nRRLLURRRURL\\n1\\nUURRLUR\\n13\\nLRUULUURLRRRL\\n6\\nLULUURULUURL\\n15\\nUULL\\n8\\nULLLULRLRUU\\n8\\nULRUULRUURLLRL\\n5\\nLLUULRLURRRULLR\\n10\\nLUULLRU\\n\", \"31 10\\n12\\nRRRRRRULUURR\\n9\\nLUUURULLLLU\\n24\\nLLRRLURLLU\\n25\\nLLUUURL\\n14\\nRRRRRRULU\\n11\\nLRLUULRUULR\\n10\\nULULU\\n30\\nLLRLLLLRULRLL\\n1\\nRRULRLRLLLRULR\\n20\\nULLULLRR\\n\", \"4503599627370495 1\\n2251799813685248\\nLLLLLLLL\\n\", \"4503599627370495 1\\n2251799813685248\\nLLLLLL\\n\", \"576460752303423487 1\\n1125899906842624\\nR\\n\", \"1125899906842623 1\\n1\\nUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUULLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRLULLLLLLLLLLLLLLLLUUUULRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRRUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU\\n\"], \"outputs\": [\"10\\n5\\n\", \"1\\n\", \"1\\n\", \"1\\n\", \"1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n1\\n\", \"2\\n2\\n2\\n3\\n3\\n3\\n1\\n1\\n3\\n1\\n\", \"1\\n6\\n3\\n7\\n4\\n5\\n5\\n3\\n7\\n1\\n\", \"12\\n15\\n7\\n11\\n10\\n9\\n4\\n9\\n1\\n10\\n\", \"15\\n2\\n18\\n26\\n14\\n11\\n12\\n29\\n1\\n17\\n\", \"8796093022208\\n\", \"35184372088832\\n\", \"1688849860263936\\n\", \"2147483648\\n\"]}", "source": "primeintellect"}
T is a complete binary tree consisting of n vertices. It means that exactly one vertex is a root, and each vertex is either a leaf (and doesn't have children) or an inner node (and has exactly two children). All leaves of a complete binary tree have the same depth (distance from the root). So n is a number such that n + 1 is a power of 2. In the picture you can see a complete binary tree with n = 15. [Image] Vertices are numbered from 1 to n in a special recursive way: we recursively assign numbers to all vertices from the left subtree (if current vertex is not a leaf), then assign a number to the current vertex, and then recursively assign numbers to all vertices from the right subtree (if it exists). In the picture vertices are numbered exactly using this algorithm. It is clear that for each size of a complete binary tree exists exactly one way to give numbers to all vertices. This way of numbering is called symmetric. You have to write a program that for given n answers q queries to the tree. Each query consists of an integer number u_{i} (1 ≤ u_{i} ≤ n) and a string s_{i}, where u_{i} is the number of vertex, and s_{i} represents the path starting from this vertex. String s_{i} doesn't contain any characters other than 'L', 'R' and 'U', which mean traverse to the left child, to the right child and to the parent, respectively. Characters from s_{i} have to be processed from left to right, considering that u_{i} is the vertex where the path starts. If it's impossible to process a character (for example, to go to the left child of a leaf), then you have to skip it. The answer is the number of vertex where the path represented by s_{i} ends. For example, if u_{i} = 4 and s_{i} = «UURL», then the answer is 10. -----Input----- The first line contains two integer numbers n and q (1 ≤ n ≤ 10^18, q ≥ 1). n is such that n + 1 is a power of 2. The next 2q lines represent queries; each query consists of two consecutive lines. The first of these two lines contains u_{i} (1 ≤ u_{i} ≤ n), the second contains non-empty string s_{i}. s_{i} doesn't contain any characters other than 'L', 'R' and 'U'. It is guaranteed that the sum of lengths of s_{i} (for each i such that 1 ≤ i ≤ q) doesn't exceed 10^5. -----Output----- Print q numbers, i-th number must be the answer to the i-th query. -----Example----- Input 15 2 4 UURL 8 LRLLLLLLLL Output 10 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\\n1 2 1 3 6\\n\", \"5\\n3 2 5 4 10\\n\", \"4\\n1 1 1 1\\n\", \"1\\n1000000000\\n\", \"2\\n921 921\\n\", \"2\\n1000000000 1\\n\", \"11\\n3 10 20 13 18 12 6 5 19 10 8\\n\", \"19\\n3 1 16 11 12 10 3 13 12 9 1 9 8 4 19 16 19 3 3\\n\", \"4\\n11 6 1 16\\n\", \"19\\n10 10 8 11 6 1 6 13 8 20 8 14 9 18 18 7 5 20 6\\n\", \"12\\n6 20 12 12 1 8 15 19 5 19 5 16\\n\", \"2\\n6 16\\n\", \"8\\n10 4 7 6 14 4 2 2\\n\"], \"outputs\": [\"10\", \"20\", \"1\", \"1000000000\", \"1841\", \"1\", \"36\", \"6\", \"17\", \"21\", \"31\", \"22\", \"3\"]}", "source": "primeintellect"}
You went to the store, selling $n$ types of chocolates. There are $a_i$ chocolates of type $i$ in stock. You have unlimited amount of cash (so you are not restricted by any prices) and want to buy as many chocolates as possible. However if you buy $x_i$ chocolates of type $i$ (clearly, $0 \le x_i \le a_i$), then for all $1 \le j < i$ at least one of the following must hold: $x_j = 0$ (you bought zero chocolates of type $j$) $x_j < x_i$ (you bought less chocolates of type $j$ than of type $i$) For example, the array $x = [0, 0, 1, 2, 10]$ satisfies the requirement above (assuming that all $a_i \ge x_i$), while arrays $x = [0, 1, 0]$, $x = [5, 5]$ and $x = [3, 2]$ don't. Calculate the maximum number of chocolates you can buy. -----Input----- The first line contains an integer $n$ ($1 \le n \le 2 \cdot 10^5$), denoting the number of types of chocolate. The next line contains $n$ integers $a_i$ ($1 \le a_i \le 10^9$), denoting the number of chocolates of each type. -----Output----- Print the maximum number of chocolates you can buy. -----Examples----- Input 5 1 2 1 3 6 Output 10 Input 5 3 2 5 4 10 Output 20 Input 4 1 1 1 1 Output 1 -----Note----- In the first example, it is optimal to buy: $0 + 0 + 1 + 3 + 6$ chocolates. In the second example, it is optimal to buy: $1 + 2 + 3 + 4 + 10$ chocolates. In the third example, it is optimal to buy: $0 + 0 + 0 + 1$ chocolates. 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