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