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