#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n;
  cin >> n;
  set<int> pom;
  multiset<int> ile;
  int tab[n];
  for (int i = 0; i < n; i++) {
    cin >> tab[i];
    ile.insert(tab[i]);
    pom.insert(tab[i]);
  }
  vector<vector<long long>> a;
  for (auto x : pom) {
    long long p = ile.count(x);
    a.push_back({x, 1LL * p * x});
  }
  int len = a.size();
  vector<long long> dp(len, 0);
  dp[len - 1] = a[len - 1][1];
  if (len == 1)
    cout << a[0][1];
  else {
    if (a[len - 2][0] + 1 == a[len - 1][0])
      dp[len - 2] = max(a[len - 2][1], a[len - 1][1]);
    else
      dp[len - 2] = a[len - 2][1] + a[len - 1][1];
    for (int i = len - 3; i >= 0; i--) {
      if (a[i][0] + 1 == a[i + 1][0]) {
        dp[i] = max(dp[i + 1], a[i][1] + dp[i + 2]);
      } else
        dp[i] = a[i][1] + dp[i + 1];
    }
    cout << dp[0];
  }
}
