#include <iostream>
using namespace std;

int main() {
    int n;
    cin >> n;
    int x[10001] = {0},y[10001] = {0};
    int arr[10001] = { 0 };
    for (int i = 0; i < n; i++) {
        int x = 0;
        cin >> x;
        arr[x] += x;
    }

    for(int j=1;j<10001;j++)
    {
        x[j] = arr[j] + y[j-1];
        y[j] = max(x[j-1],y[j-1]);
    }

    cout<<(x[10000]>y[10000] ? x[10000] : y[10000])<<endl;
    

    return 0;
}