시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB73233.333%

문제

Two players are playing a game. They are given an array $a_1 , a_2 , \dots , a_n$ as well as an array $b_1 , b_2 , \dots , b_m$.

The game consists of m rounds. Players are participating in rounds alternatively. During the $i$-th round (for $i$ from $1$ to $m$) the corresponding player (first player, if $i$ is odd, and second if $i$ is even) has to do exactly one of the following:

  • remove all elements from the array $a$ that are divisible by $b_i$,
  • remove all elements from the array $a$ that are not divisible by $b_i$.

The first player wants to minimize the sum of the remaining elements in the array $a$ after all $m$ rounds, and the second wants to maximize it. Find the sum of the remaining elements in the array $a$ after all $m$ rounds if both players are playing optimally.

입력

The first line contains two integers $n$, $m$ ($1 ≤ n ≤ 2 ⋅ 10^4$, $1 ≤ m ≤ 2 ⋅ 10^5$) - the length of the array $a$ and the number of rounds in the game.

The second line contains $n$ integers $a_1 , a_2 , \dots , a_n$ ($-4 ⋅ 10^{14} ≤ a_i ≤ 4 ⋅ 10^{14}$) - the elements of the array $a$.

The third line contains $m$ integers $b_1 , b_2 , \dots , b_m$ ($1 ≤ b_i ≤ 4 ⋅ 10^{14}$) - the elements of the array $b$.

출력

Output a single integer - the sum of the remaining elements of the array $a$ after all $m$ rounds if both players are playing optimally.

서브태스크

번호배점제한
13

$m = 1$

26

$b_{i+1} = b_{i}$ ($1 ≤ i < m$), i.e. all elements of the array $b$ are the same

315

$b_{i+1} \bmod b_i = 0$ ($1 ≤ i < m$)

49

$1 ≤ m ≤ 7$

511

$1 ≤ m ≤ 20$

615

$1 ≤ m ≤ 100$

718

$1 ≤ a_i , b_i ≤ 10^9$

811

$m \bmod 2 = 0$, $b_{2i-1} = b_{2i}$ ($1 ≤ i ≤ \frac{m}{2}$)

912

No additional constraints

예제 입력 1

6 2
2 2 5 2 2 7
2 5

예제 출력 1

7

예제 입력 2

5 1
-5000111000 -5000222000 -15 5 2
5

예제 출력 2

-10000333010

노트

In the first sample, one possible flow of the game is the following:

  • Round 1: first player removes from $a$ all elements divisible by $2$. $a$ becomes $(5, 7)$.
  • Round 2: second player removes from $a$ all elements divisible by $5$. $a$ becomes $(7)$. If he had removed from $a$ all elements not divisible by $5$, $a$ would become $(5)$, which has a smaller sum of elements and therefore is not desirable for the second player.

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.