#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int n; if (!(cin >> n)) return 0;
    vector<long long> weight(100001);
    for (int i = 0, x; i < n; ++i) { cin >> x; weight[x] += x; }
    long long two = 0, one = 0;
    for (int v = 1; v <= 100000; ++v) {
        long long now = max(one, two + weight[v]);
        two = one; one = now;
    }
    cout << one << '\n';
}
