#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int n;
  cin >> n;
  long long int as[100001];
  for (int i = 0; i <= 100000; ++i) as[i] = 0;
  for (int i = 0; i < n; ++i) {
    int a;
    cin >> a;
    as[a]++;
  }
  long long int f_np = 0, f_npp = 0;
  for (int i = 100000; 0 <= i; --i) {
    long long int f_n = max(f_np, as[i] * i + f_npp);
    f_npp = f_np;
    f_np = f_n;
  }
  cout << f_np << endl;
  return 0;
}
