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