#QHD0000012. Nhàm chán (Boredom)
Nhàm chán (Boredom)
Boredom
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given an array , in one move choose a remaining value , gain points, and delete all remaining elements equal to and . Continue as desired and maximize total score.
Input
Line 1 contains . Line 2 contains .
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 , better than choosing 2 for 2 points.