ICPC 2016 · Problem A · Balanced Diet

40th ICPC · Phuket, Thailand

Statement

Time limit: 2 seconds

Every day, Danny buys one sweet from the candy store and eats it. The store has mm types of sweets, numbered from 11 to mm. Danny knows that a balanced diet is important and is applying this concept to his sweet purchasing. To each sweet type ii, he has assigned a target fraction, which is a real number fif_{i} (0<fi10 < fi \le 1). He wants the fraction of sweets of type ii among all sweets he has eaten to be roughly equal to fif_{i}. To be more precise, let sis_{i} denote the number of sweets of type ii that Danny has eaten, and let n=Pmn= P^{m} i=1sii=1 s^{i}. We say the set of sweets is balanced if for every ii we have nfi1<si<nfi+1.nfi- 1< si < nfi+ 1.

Danny has been buying and eating sweets for a while and during this entire time the set of sweets has been balanced. He is now wondering how many more sweets he can buy while still fulfilling this condition. Given the target fractions fif_{i} and the sequence of sweets he has eaten so far, determine how many more sweets he can buy and eat so that at any time the set of sweets is balanced.

Input

The input consists of three lines. The first line contains two integers mm (1m1051 \le m \le 10^{5}), which is the number of types of sweets, and kk (0k1050 \le k \le 10^{5}), which is the number of sweets Danny has already eaten.

The second line contains mm positive integers a1,...,ama_{1}, . . . , a_{m}. These numbers are proportional to f1,...,fmf_{1}, . . . , f_{m}, that is, fi=fi = aia_{i} PmP_{m} j=1ajj=1 a^{j} . It is guaranteed that the sum of all aja_{j} is no larger than 10510^{5}.

The third line contains kk integers b1,...,bkb_{1}, . . . , b_{k} (1bim1 \le bi \le m), where each bib_{i} denotes the type of sweet Danny bought and ate on the iith day. It is guaranteed that every prefix of this sequence (including the whole sequence) is balanced.

Output

Display the maximum number of additional sweets that Danny can buy and eat while keeping his diet continuously balanced. If there is no upper limit on the number of sweets, display the word forever.

Sample Input 1

6 5
2 1 6 3 5 3
1 2 5 3 5

Sample Output 1

1

Sample Input 2

6 4
2 1 6 3 5 3
1 2 5 3

Sample Output 2

forever

ACM-ICPC World Finals 2016 Problem A: Balanced Diet

No official solution in the source collection.