#include <bits/stdc++.h>
using namespace std;
int a[100001];
long long sol[100001];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  sort(a, a + n);
  vector<pair<int, long long> > v;
  long long curr = a[0];
  for (int i = 1; i < n; ++i) {
    if (a[i] != a[i - 1]) {
      v.push_back(make_pair(a[i - 1], curr));
      curr = a[i];
    } else {
      curr += a[i];
    }
  }
  if (curr != 0) {
    v.push_back(make_pair(a[n - 1], curr));
  }
  int size = v.size();
  sol[0] = 0;
  sol[1] = v[0].second;
  for (int i = 2; i <= size; ++i) {
    if (v[i - 1].first == v[i - 2].first + 1) {
      sol[i] = max(sol[i - 2] + v[i - 1].second, sol[i - 1]);
    } else {
      sol[i] = sol[i - 1] + v[i - 1].second;
    }
  }
  cout << sol[size] << endl;
}
