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