Balanced Diet

Given proportional target fractions and a balanced eating history, find how many more candies can be added with every prefix staying balanced, or report forever.

Hard8GreedyMathPrefix sumNumber theoryNo attempts yetTime limit2sMemory limit512 MB

Problem

Every day Danny buys one candy at the candy store and eats it. The store sells mm kinds of candy, numbered from 1 to mm. Danny thinks a balanced diet matters, so he applies the same idea to his candy buying. For each kind ii he has fixed a target fraction fif_i, a real number with 0<fi10 < f_i \le 1. He wants the share of kind ii among all the candies he has eaten to stay close to fif_i.

Write sis_i for the number of candies of kind ii that Danny has eaten, and let n=i=1msin = \sum_{i=1}^{m} s_i. The candies eaten so far are balanced when

nfi1<si<nfi+1n f_i - 1 < s_i < n f_i + 1

holds for every ii.

Danny has been buying and eating candy for a while, and the whole time the candies eaten have been balanced. He now wonders how many more he can buy. Given the target fractions fif_i and the order in which he has eaten so far, find how many more candies Danny can buy and eat so that the candies eaten are balanced at every moment.

Input

The input has three lines. The first line has two integers mm (1m1051 \le m \le 10^5), the number of kinds of candy, and kk (0k1050 \le k \le 10^5), the number of candies Danny has already eaten.

The second line has mm positive integers a1,,ama_1, \dots, a_m. These numbers are proportional to f1,,fmf_1, \dots, f_m, that is, fi=aij=1majf_i = \frac{a_i}{\sum_{j=1}^{m} a_j}. The sum of all aja_j is at most 10510^5.

The third line has kk integers b1,,bkb_1, \dots, b_k (1bim1 \le b_i \le m), where bib_i is the kind of candy Danny bought and ate on day ii. Every prefix of this sequence, including the whole sequence, is balanced.

Output

Print the largest number of extra candies Danny can buy and eat while the candies eaten stay balanced at every moment. If there is no upper bound on that number, print forever.