#include <bits/stdc++.h>
using namespace std;
static const long long MAX = 100000;
long long cnt[MAX + 1];
int main(void) {
  long long n;
  cin >> n;
  long long x;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    cnt[x]++;
  }
  long long f[MAX];
  f[0] = 0;
  f[1] = cnt[1];
  for (long long i = 2; i <= MAX; i++) {
    f[i] = max(f[i - 1], f[i - 2] + cnt[i] * i);
  }
  cout << f[MAX] << endl;
  return 0;
}
