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