#include <bits/stdc++.h>
using namespace std;
long long dp[100001][2];
int main() {
  int n;
  cin >> n;
  map<int, int> m;
  int k;
  for (int i = 0; i < n; i++) {
    cin >> k;
    m[k]++;
  }
  vector<pair<int, long long>> v;
  v.push_back({0, 0});
  for (auto i : m) {
    v.push_back({i.first, 1LL * i.first * i.second});
  }
  int l = v.size();
  long long ans = 0;
  for (int i = 1; i < l; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = max(dp[i - 1][0],
                   (v[i].first - v[i - 1].first) > 1 ? dp[i - 1][1] : 0) +
               v[i].second;
    ans = max(dp[i][0], dp[i][1]);
  }
  cout << ans;
}
