#include <bits/stdc++.h>
long long N = 100000;
using namespace std;
signed main() {
  long long n;
  cin >> n;
  vector<long long> v(n), fr(N + 5);
  for (long long i = 0; i < n; i++) {
    cin >> v[i];
    fr[v[i]]++;
  }
  vector<long long> dp(N + 5);
  dp[1] = fr[1];
  for (long long i = 2; i <= N; i++) {
    dp[i] = max(dp[i - 2] + fr[i] * i, dp[i - 1]);
  }
  cout << dp[N];
}
