#include <bits/stdc++.h>
using namespace std;
unsigned long long n, ai;
vector<long long> m;
vector<long long> a;
vector<long long> a2;
int main() {
  cin >> n;
  long long d[n][2];
  m.resize(1);
  a.resize(n);
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long s = 0;
  m[0] = 1;
  for (long long i = 1; i < n; i++) {
    if (a[i] == a[i - 1]) {
      m[m.size() - 1]++;
    } else {
      m.resize(m.size() + 1);
      m[m.size() - 1] = 1;
      a2.push_back(a[i - 1]);
    }
  }
  a2.push_back(a.back());
  d[0][0] = 0;
  d[0][1] = a2[0] * m[0];
  for (long long i = 1; i < a2.size(); i++) {
    d[i][0] = max(d[i - 1][0], d[i - 1][1]);
    d[i][1] = d[i - 1][0];
    if (i > 2) d[i][1] = max(d[i][1], d[i - 3][1]);
    if (a2[i] - 1 > a2[i - 1]) d[i][1] = max(d[i][1], d[i - 1][1]);
    d[i][1] += m[i] * a2[i];
  }
  cout << max(d[a2.size() - 1][1], d[a2.size() - 1][0]);
}
