You have probably encountered the notion of a "digital root": for a number, you take the sum of its digits, then the sum of the digits of the obtained number, and so on, until only one digit remains. Today, the author of the problem suggests moving to a new level — the "digital MEGAROOT".
Let $$$S(x)$$$ for a digit string $$$x$$$ be the sum of all digits contained in $$$x$$$.
Let $$$N_0$$$ be the starting number, written without leading zeros as a string of $$$K$$$ digits. For every pair of integers $$$L$$$, $$$R$$$ $$$(1 \le L \le R \le K)$$$, consider the substring of digits of the number $$$N_0$$$ from position $$$L$$$ to position $$$R$$$ inclusive and compute $$$S$$$ of that substring (that is, the sum of the digits in it). The number $$$N_1$$$ is defined as the sum of the values $$$S(N_0[L..R])$$$ over all pairs $$$(L, R)$$$, $$$1 \le L \le R \le K$$$.
Then the process is repeated: from $$$N_1$$$, by the same rule (all substrings of its digits are considered and their digit sums are added), $$$N_2$$$ is built; from $$$N_2$$$, $$$N_3$$$ is built; and so on — an infinite sequence of numbers $$$N_0, N_1, N_2, N_3, \ldots$$$ is obtained.
The digital MEGAROOT of the number $$$N_0$$$ is the minimum number among the entire infinite sequence $$$N_0, N_1, N_2, \ldots$$$. It can be shown that for any starting number $$$N_0$$$, this value is finite.
However, something is still missing... The author will perform $$$Q$$$ update queries on the number $$$N$$$ (which always remains a string of $$$K$$$ digits without leading zeros). Each query changes exactly one digit of the number $$$N$$$ at a given position; all changes are preserved and affect all subsequent queries.
You need to output the digital MEGAROOT of the initial number $$$N$$$, as well as the digital MEGAROOT after each of the $$$Q$$$ update queries.
The first line contains one integer $$$K$$$ $$$(1 \le K \le 2 \cdot 10^5)$$$ — the number of digits in the number $$$N$$$.
The second line contains $$$K$$$ digits forming the initial number $$$N$$$ (without leading zeros).
The third line contains one integer $$$Q$$$ $$$(1 \le Q \le 2 \cdot 10^5)$$$ — the number of update queries.
The fourth line contains $$$Q$$$ integers $$$P_1, P_2, \ldots, P_Q$$$ $$$(1 \le P_i \le K)$$$ — the positions of the digit changed in the $$$i$$$-th query.
The fifth line contains $$$Q$$$ integers $$$D_1, D_2, \ldots, D_Q$$$ $$$(0 \le D_i \le 9)$$$ — the new value of the digit in the $$$i$$$-th query: in the $$$i$$$-th query, the digit at position $$$P_i$$$ is replaced by $$$D_i$$$.
It is guaranteed that if $$$P_i = 1$$$, then $$$D_i \ge 1$$$ (that is, the number $$$N$$$ never gets a leading zero).
Print $$$Q + 1$$$ integers $$$R_0, R_1, \ldots, R_Q$$$ $$$(0 \le R_i \le 10^{18})$$$ in one line separated by spaces: $$$R_0$$$ is the digital MEGAROOT of the number $$$N$$$ before any queries, and $$$R_i$$$ for $$$i \ge 1$$$ is the digital MEGAROOT of the number $$$N$$$ after applying the first $$$i$$$ update queries.
It is guaranteed that the answer always exists and is unique; there is no need to output any special value in case of no answer.
51497441 2 1 43 7 7 0
6 18 8 4 18
In the first example, $$$K = 5$$$, $$$N_0 = 14974$$$. Let us compute its digital MEGAROOT:
The digital MEGAROOT is the minimum among $$$14974, 194, 51, 12, 6, 6, 6, \ldots$$$, that is, $$$6$$$. This value is output as $$$R_0$$$.
Next, let us see how the number $$$N$$$ changes after the update queries (the changes accumulate):
The final answers are $$$6, 18, 8, 4, 18$$$.
| Name |
|---|


