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