#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> dp(100005, 0);
vector<long long> cnt(100005, 0);
void run_case() {
  for (int i = 0; i < 100005; i++) {
    dp[i] = 0;
    cnt[i] = 0;
  }
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    cnt[x]++;
  }
  n = 100005;
  dp[1] = 1ll * cnt[1];
  for (long long i = 2; i < n; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + 1ll * cnt[i] * i);
  }
  cout << dp[n - 1] << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long tc = 1;
  for (long long i = 1; i <= tc; i++) run_case();
  return 0;
}
