#include <bits/stdc++.h>
using namespace std;
int n, a, c[111111], mv;
long long f[111111];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    c[a]++;
    mv = max(mv, a);
  }
  f[1] = c[1];
  for (int i = 2; i <= mv; i++) {
    f[i] = max(f[i - 1], f[i - 2] + (long long)c[i] * i);
  }
  cout << f[mv] << endl;
  return 0;
}
