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

#GL0000135. Topforces phản công (Topforces Strikes Back)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Topforces phản công (Topforces Strikes Back)

Topforces Strikes Back

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn problems with positive attractiveness values aia_i. Select between one and three problems so that, for every pair of selected values, neither value divides the other. Maximize the sum of their attractiveness. Equal values from different positions cannot be chosen together because they divide each other.

Input

The first line contains nn; the next contains nn integers aia_i.

Output

Print the maximum total attractiveness of a valid selection.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 2≤ai≤1 0002\le a_i\le 1\,000.
  • Subtask 2 (30 points): 1≤n≤1 0001\le n\le 1\,000; 2≤ai≤30 0002\le a_i\le 30\,000.
  • Subtask 3 (50 points): 1≤n≤200 0001\le n\le 200\,000; 2≤ai≤200 0002\le a_i\le 200\,000.

Examples

Input

4
10 6 30 15

Output

31

Explanation

Choosing 10, 6 and 15 gives sum 31, and none divides another. Choosing 30 excludes each of those values and yields only 30, so 31 is optimal.