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