#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  map<long long, long long> m;
  set<long long> s;
  for (long long i = 0, x; i < n; i++) {
    cin >> x;
    m[x]++;
    s.insert(x);
  }
  vector<long long> v(s.begin(), s.end());
  pair<long long, long long> dp[m.size()];
  dp[0].first = v[0] * m[v[0]];
  dp[0].second = 0;
  for (long long i = 1; i < m.size(); i++) {
    if (v[i - 1] == v[i] - 1) {
      dp[i].first = dp[i - 1].second + v[i] * m[v[i]];
      dp[i].second = max(dp[i - 1].first, dp[i - 1].second);
    } else {
      dp[i].first = max(dp[i - 1].first, dp[i - 1].second) + v[i] * m[v[i]];
      dp[i].second = max(dp[i - 1].first, dp[i - 1].second);
    }
  }
  cout << max(dp[m.size() - 1].first, dp[m.size() - 1].second) << '\n';
  return 0;
}
