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

#QHD0000012. Chán nản (Boredom)

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Chán nản (Boredom)

Boredom

Source: Codeforces

Problem Statement

You are given a sequence of nn positive integers a1,a2,…,ana_1,a_2,\ldots,a_n. You may perform the following move repeatedly, stopping whenever you choose or when the sequence becomes empty:

Choose one element with value xx, earn xx points and delete that chosen element. At the same time, delete every remaining element whose value equals x−1x-1 or x+1x+1. Other elements equal to xx remain and may be selected later.

Find the maximum total score achievable.

Input

The first line contains nn, the number of initial elements.

The second line contains nn integers a1,a2,…,ana_1,a_2,\ldots,a_n.

Output

Print one integer: the maximum total score.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤ai≤1051\le a_i\le 10^5 (1≤i≤n1\le i\le n).
  • Subtask 2 (30 points): 1≤n≤10001\le n\le 1000; 1≤ai≤1051\le a_i\le 10^5 (1≤i≤n1\le i\le n).
  • Subtask 3 (50 points): 1≤n≤1051\le n\le 10^5; 1≤ai≤1051\le a_i\le 10^5 (1≤i≤n1\le i\le n).

Examples

Input

2
1 2

Output

2

Explanation

Taking 11 removes 22 and earns only 11 point. Taking 22 removes 11 and earns 22 points, so the optimal total is 22.