#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, maxi = 0;
  cin >> n;
  long long arr[n];
  map<long long, long long> m;
  for (int i = 0; i < n; i++) {
    cin >> arr[i];
    m[arr[i]]++;
  }
  map<long long, long long>::iterator it;
  vector<long long> dp, num;
  for (it = m.begin(); it != m.end(); it++) {
    if (num.size() == 0) {
      dp.push_back(it->first * it->second);
      num.push_back(it->first);
    } else {
      if (it->first == num[num.size() - 1] + 1) {
        long long temp = 0;
        if (num.size() > 1) temp = dp[dp.size() - 2];
        long long prev = dp[dp.size() - 1];
        dp.push_back(max(prev, it->first * it->second + temp));
        num.push_back(it->first);
      } else {
        long long temp = dp[dp.size() - 1];
        dp.push_back(it->first * it->second + temp);
        num.push_back(it->first);
      }
    }
    if (dp[dp.size() - 1] > maxi) maxi = dp[dp.size() - 1];
  }
  cout << maxi;
  return 0;
}
