#include <bits/stdc++.h>
using namespace std;
long long int dp[200005];
int main() {
  long long int n;
  cin >> n;
  vector<long long int> v(n);
  map<long long int, long long int> m;
  for (int i = 0; i < (n); i++) {
    cin >> v[i];
    m[v[i]]++;
  }
  sort(v.begin(), v.end());
  auto it = unique(v.begin(), v.end());
  v.resize(distance(v.begin(), it));
  sort(v.begin(), v.end());
  dp[0] = 0;
  dp[1] = v[0] * m[v[0]];
  for (int i = 1; i < v.size(); ++i) {
    if (v[i - 1] + 1 == v[i])
      dp[i + 1] = max(dp[i], dp[i - 1] + v[i] * m[v[i]]);
    else
      dp[i + 1] = max(dp[i], dp[i - 1]) + v[i] * m[v[i]];
  }
  cout << dp[v.size()];
  return 0;
}
