#include <bits/stdc++.h>
using namespace std;
const int INF = (int)1e9;
const int SIZE = 100005;
map<long long, long long> mp;
long long cnt[SIZE];
long long dp[SIZE];
int main() {
  ios_base::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mp[v[i]]++;
  }
  map<long long, long long>::iterator it = mp.begin();
  int last;
  for (; it != mp.end(); it++) {
    cnt[it->first] = it->second;
    last = it->first;
  }
  dp[1] = cnt[1];
  for (int i = 2; i <= last; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  cout << dp[last] << endl;
  return 0;
}
