#include <bits/stdc++.h>
using namespace std;
void _SSGJ_() {
  long long n;
  cin >> n;
  map<long long, long long> mp;
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    mp[a]++;
  }
  long long dp[100001];
  dp[0] = 0;
  dp[1] = mp[1];
  for (long long i = 2; i < 100001; i++)
    dp[i] = max(dp[i - 1], dp[i - 2] + mp[i] * i);
  cout << dp[100000] << "\n";
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  _SSGJ_();
  return 0;
}
