#include <bits/stdc++.h>
using namespace std;
void SMF() {
  long long n, y;
  vector<long long> mp(100001);
  cin >> n;
  for (y = 0; y < n; y++) {
    long long t;
    cin >> t;
    mp[t] += t;
  }
  for (y = 2; y <= 100001; y++) mp[y] = max(mp[y - 1], mp[y] + mp[y - 2]);
  cout << mp[y - 1] << "\n";
}
int main() {
  long long CT = 1;
  while (CT--) SMF();
  return 0;
}
