CF455A.Boredom

传统题 时间 2000 ms 内存 256 MiB 9 尝试 10 已通过 9 标签

Boredom

Statement

You are given a sequence of positive integers. You may perform any number of moves. In one move, choose one remaining element with value xx, gain xx points, and erase that chosen element together with every element whose value is x1x-1 or x+1x+1. Other elements equal to xx are not erased, so they may be chosen later.

You may stop at any time. Find the maximum total number of points you can obtain.

Input

The first line contains one integer nn (1n1000001 \le n \le 100000), the length of the sequence.

The second line contains nn integers a1,a2,,ana_1,a_2,\ldots,a_n (1ai1000001 \le a_i \le 100000).

Output

Print one integer: the maximum total number of points obtainable.

Samples

Sample 1

Input:

2
1 2

Output:

2

Sample 2

Input:

3
1 2 3

Output:

4

Sample 3

Input:

9
1 2 3 1 2 2 3 2 2

Output:

10

在线编程 IDE

建议全屏模式获得最佳体验