#include <bits/stdc++.h>
using namespace std;
int main() {
  long n;
  scanf("%ld", &n);
  long long a[n];
  long long s = -1;
  long long dp[100001] = {0};
  for (long i = 0; i < n; i++) {
    cin >> a[i];
    dp[a[i]]++;
    if (a[i] > s) s = a[i];
  }
  long long f[s + 1];
  f[0] = 0;
  f[1] = dp[1];
  for (long i = 2; i <= s; i++) {
    f[i] = max(f[i - 1], f[i - 2] + dp[i] * i);
  }
  cout << f[s];
  return 0;
}
