#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
long long cnt[N], ans[N] = {};
int main() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  long long int maxi = 0;
  for (long long int i = 0; i < N; i++) {
    if (i >= 2)
      ans[i] += max(ans[i - 1], ans[i - 2] + cnt[i] * i);
    else
      ans[i] = i * cnt[i];
    maxi = max(maxi, ans[i]);
  }
  cout << maxi << endl;
  return 0;
}
