#include <bits/stdc++.h>
using namespace std;
double gcd(double a, double b) { return a < 0.01 ? b : gcd(fmod(b, a), a); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int n;
  cin >> n;
  long long int c[100001] = {}, x;
  for (long long i = 0; i < int(n); i++) cin >> x, c[x]++;
  long long int f[100001] = {};
  f[1] = c[1];
  for (int i = 2; i <= 100000; i++) {
    f[i] = max(f[i - 1], f[i - 2] + c[i] * i);
  }
  cout << f[100000];
  return 0;
}
