#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long freq[100000 + 1] = {};
  long long maxi = INT_MIN, x;
  for (long long i = 0; i < n; i++) {
    cin >> x;
    freq[x]++;
    maxi = max(maxi, x);
  }
  long long dp[100000 + 1] = {0};
  dp[1] = freq[1];
  for (long long i = 2; i <= maxi; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + i * freq[i]);
  }
  cout << dp[maxi] << endl;
  return 0;
}
