#include <bits/stdc++.h>
using namespace std;
vector<unsigned long long> dp(100005);
int main() {
  long int n;
  cin >> n;
  dp[0] = 0;
  unordered_map<long int, unsigned long long> ump;
  long int maxi = INT_MIN;
  for (int i = 0; i < n; i++) {
    long int a;
    cin >> a;
    maxi = max(maxi, a);
    ump[a]++;
  }
  for (unsigned long long i = 1; i < 100005; i++) {
    if (i == 1)
      dp[i] = max(dp[i - 1], ump[i] * i);
    else
      dp[i] = max(dp[i - 1], dp[i - 2] + ump[i] * i);
  }
  cout << dp[maxi] << endl;
}
