PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000391. Kho báu GCD (GCD Treasury)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Kho báu GCD (GCD Treasury)

GCD Treasury

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn coin piles; pile ii initially has aia_i coins. A pirate holds a positive integer xx. At each step, choose a nonempty pile with g=gcd⁡(ai,x)>1g=\gcd(a_i,x)>1, remove exactly gg coins from that pile and replace xx by gg. The process stops when no eligible pile remains.

You may choose the piles in any order and revisit the same pile. Find the maximum total number of coins removed.

Input

The first line contains n,xn,x. The second contains a1,…,ana_1,\ldots,a_n. PHOJ uses one case per file instead of the original Codeforces multi-case wrapper.

Output

Print the maximum total number of removed coins.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le20, 1≤x,ai≤301\le x,a_i\le30.

  • Subtask 2 (30 points): 1≤n≤5 0001\le n\le5\,000, 1≤x,ai≤10 0001\le x,a_i\le10\,000.

  • Subtask 3 (50 points): 1≤n,x,ai≤300 0001\le n,x,a_i\le300\,000.

Examples

Example 1

Input

3 4
2 3 4

Output

6

Explanation

Take 44 coins from the last pile, leaving x=4x=4, then 22 from the first pile, leaving x=2x=2. The remaining pile contains 33 coins but gcd⁡(3,2)=1\gcd(3,2)=1, so the total is 66.

Example 2

Input

4 2
2 2 2 2

Output

8

Explanation

Every pile is divisible by 22 and may be emptied. Each step keeps x=2x=2; four piles contribute eight coins.