#include <bits/stdc++.h>
using namespace std;
long long a[200000] = {0}, b[200];
map<long int, int> ma;
int main() {
  long long i, j, tc, x = 0, n, k, ans = 0, p, m, s;
  cin >> k;
  for (long long i = 0; i < k; i++) {
    cin >> n;
    a[n] += n;
  }
  for (i = 2; i <= 100000; i++) {
    a[i] = max(a[i - 1], a[i] + a[i - 2]);
  }
  cout << a[100000] << endl;
  return 0;
}
