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

#GL0000227. Tối đa tổng sức mạnh các thẻ đồ họa (Video Cards)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Tối đa tổng sức mạnh các thẻ đồ họa (Video Cards)

Video Cards

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A shop sells nn video cards of powers a1,…,ana_1,\ldots,a_n. Buy any non-empty selection and choose one leading card with unchanged power vv. Every secondary card may have its power decreased to a positive integer no larger than its original power and divisible by vv. Maximize the total power of the chosen compatible cards; cards may be left unbought.

Input

First line contains nn; second line has aia_i.

Output

Print the maximum total power.

Subtasks

  • Subtask 1 (20 points): 1≤n≤50, 1≤ai≤1001\le n\le 50,\ 1\le a_i\le 100.

  • Subtask 2 (30 points): 1≤n≤5000, 1≤ai≤50001\le n\le 5000,\ 1\le a_i\le 5000.

  • Subtask 3 (50 points): 1≤n≤200000, 1≤ai≤2000001\le n\le 200000,\ 1\le a_i\le 200000.

Examples

Example 1

Input

4
3 2 15 9

Output

27

Explanation

Choose the card of power 3 as the leader and the cards of powers 15 and 9 as secondary cards. Their total is 27.

Example 2

Input

4
8 2 2 7

Output

18

Explanation

Choose a card of power 2 as the leader and reduce power 7 to power 6. The total is 8+2+2+6=18.