#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, a[100005], temp;
  for (i = 0; i <= 100005; i++) a[i] = 0;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> temp;
    a[temp] += temp;
  }
  long long int inc = a[1], ex = 0, excl_new;
  for (i = 2; i <= 100005; i++) {
    excl_new = (inc > ex) ? inc : ex;
    inc = ex + a[i];
    ex = excl_new;
  }
  cout << ((inc > ex) ? inc : ex) << endl;
  return 0;
}
