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