Game With Numbers

아직 제출이 없습니다시간 제한1초메모리 제한1024 MB

문제

Two players are playing a game. They are given an array a_1,a_2,,a_na\_1 , a\_2 , \dots , a\_n as well as an array b_1,b_2,,b_mb\_1 , b\_2 , \dots , b\_m.

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

  • remove all elements from the array aa that are divisible by b_ib\_i,
  • remove all elements from the array aa that are not divisible by b_ib\_i.

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

입력

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

The second line contains nn integers a_1,a_2,,a_na\_1 , a\_2 , \dots , a\_n (41014a_i41014-4 ⋅ 10^{14} ≤ a\_i ≤ 4 ⋅ 10^{14}) - the elements of the array aa.

The third line contains mm integers b_1,b_2,,b_mb\_1 , b\_2 , \dots , b\_m (1b_i410141 ≤ b\_i ≤ 4 ⋅ 10^{14}) - the elements of the array bb.

출력

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

힌트

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

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