#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
long long c[N], f[N];
int main() {
  long long n;
  cin >> n;
  long long Max = -1;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    c[x]++;
    Max = max(x, Max);
  }
  f[0] = 0, f[1] = c[1];
  for (int i = 2; i <= Max; i++) {
    f[i] = max(f[i - 1], f[i - 2] + c[i] * i);
  }
  cout << f[Max] << endl;
}
