What can be better than a whopper? Only a double whopper! And what about a $$$k$$$-whopper? Bob wants to eat like a pig, but Alice wants to stop him!
A reform was made in "Burger King", and now there are $$$n$$$ cash desks there, numbered from $$$0$$$ to $$$n - 1$$$. For each cash desk, two numbers are given: $$$a_i$$$ and $$$k_i$$$ — the change in the number of patties in the whopper after visiting this cash desk, and its importance, respectively. The value $$$a_i$$$ can be negative, then the number of patties decreases.
All visitors start at cash desk $$$n - 1$$$ and then move between cash desks until they reach cash desk $$$0$$$. While at cash desk with number $$$i$$$ ($$$0 \lt i \lt n$$$), one can move either to cash desk $$$i - 1$$$, or choose a number $$$b$$$ ($$$1 \lt b \le k_i$$$) and move to cash desk $$$\lfloor i / b \rfloor$$$.
Before visiting cash desk $$$n-1$$$, Bob's whopper contains $$$10^{100}$$$ patties (did you think we were bluffing in the first paragraph?). When visiting cash desk with number $$$i$$$, exactly $$$a_i$$$ patties are added to the whopper, and it is impossible not to take them. Alice and Bob make moves alternately, and Alice moves first. Alice wants to minimize the final number of patties, while Bob wants to maximize it. On their move, Alice or Bob chooses the next cash desk to move to.
Determine how many patties will be in the whopper if both players play optimally.
The first line contains one integer $$$n$$$ ($$$2 \le n \le 200\,000$$$) — the number of cash desks in "Burger King".
The second line contains $$$n$$$ integers $$$a_i$$$ ($$$-10^9 \le a_i \le 10^9$$$) — the changes in the number of patties at the cash desks.
The third line contains $$$n$$$ integers $$$k_i$$$ ($$$2 \le k_i \le n$$$) — the importance values of the cash desks.
Let the whopper contain $$$10^{100}+x$$$ patties after optimal play by Alice and Bob. Then you need to print the single integer $$$x$$$.
The tests for this problem consist of seven groups. Points for each group are given only if all tests of this group and all tests of some previous groups are passed. Please note that passing the sample tests is not required for some groups. The final score for each group is equal to the maximum score obtained for this group over all submissions.
| Subtask | Points | $$$n$$$ | Additionally | Required subtasks |
| 1 | 10 | $$$n \le 10$$$ | — | S |
| 2 | 15 | $$$n \le 20$$$ | $$$k_i = 2$$$ | — |
| 3 | 15 | — | $$$a_i \ge 0$$$ | — |
| 4 | 15 | $$$n \le 1\,000$$$ | — | S, 1, 2 |
| 5 | 20 | $$$n \le 60\,000$$$ | — | S, 1, 2, 4 |
| 6 | 10 | $$$n \le 100\,000$$$ | — | S, 1, 2, 4, 5 |
| 7 | 15 | — | — | S, 1–6 |
51 -1 2 3 -12 2 3 4 3
-1
50 -5 2 1 -55 2 2 2 2
-8