#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long int> compte((int)1e5 + 1, 0);
  for (int c = 0; c < n; c++) {
    long long int z;
    cin >> z;
    compte[z] += z;
  }
  for (int c = 0; c < compte.size(); c++) {
    compte[c] = max((c - 1 > 0 ? compte[c - 1] : 0LL),
                    (c - 2 > 0 ? compte[c - 2] : 0LL) + compte[c]);
  }
  cout << compte[(int)1e5] << endl;
}
