#QHD0000012. Nhàm chán (Boredom)

Nhàm chán (Boredom)

Boredom

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

Given an array aa, in one move choose a remaining value xx, gain xx points, and delete all remaining elements equal to x−1x-1 and x+1x+1. Continue as desired and maximize total score.

Input

Line 1 contains nn. Line 2 contains a1,…,ana_1,\ldots,a_n.

Output

Print the maximum score.

Subtasks

  • Subtask 1 — 20 points: n <= 20; a_i <= 30.
  • Subtask 2 — 30 points: n <= 5000; a_i <= 5000.
  • Subtask 3 — 50 points: 1 <= n <= 100000; 1 <= a_i <= 100000.

Examples

Input

3
1 2 3

Output

4

Explanation

Choosing values 1 and 3 yields 1+3=41+3=4, better than choosing 2 for 2 points.