#include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  solve();
  return 0;
}
void solve() {
  long long n, ele;
  cin >> n;
  vector<long long> count(100002);
  while (n--) {
    cin >> ele;
    count[ele]++;
  }
  for (int i = 2; i <= 100000; i++) {
    count[i] = max(count[i - 1], count[i - 2] + (i * count[i]));
  }
  cout << count[100000] << endl;
}
