#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  cin >> n;
  vector<int> cnt(100001);
  vector<long long> d(100001);
  for (int i = 0; i < n; ++i) {
    cin >> a;
    ++cnt[a];
  }
  d[1] = cnt[1];
  for (int i = 2; i <= 100000; ++i)
    d[i] = max(d[i - 1], d[i - 2] + i * 1ll * cnt[i]);
  cout << d[100000];
  return 0;
}
