#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  vector<unsigned long long> totals(100001, 0);
  vector<unsigned long long> memo(100001, 0);
  unsigned long long len, maxA = 0;
  cin >> len;
  for (int i = 0; i < len; ++i) {
    unsigned long long a;
    cin >> a;
    maxA = max(maxA, a);
    totals[a]++;
  }
  memo[0] = 0;
  memo[1] = totals[1];
  for (int i = 2; i <= maxA; ++i) {
    memo[i] = totals[i] * i + memo[i - 2];
    memo[i] = max(memo[i], memo[i - 1]);
  }
  cout << memo[maxA] << endl;
  return 0;
}
