#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T gcd(T a, T b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <class T>
inline T ncr(T n, T r) {
  return n * (n - 1) / r;
}
long long int dp[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long int n, a;
  cin >> n;
  for (long long int i = 1; i <= n; i++) {
    cin >> a;
    dp[a]++;
  }
  for (long long int i = 2; i <= 100005; i++)
    dp[i] = max(dp[i - 1], dp[i - 2] + dp[i] * i);
  cout << dp[100005] << "\n";
  return 0;
}
