#include <bits/stdc++.h>
using namespace std;
bool deb = false;
const int N = 100011;
long long int n;
long long int a[N], dp[N][2];
int main() {
  long long int t;
  scanf("%lld", &n);
  for (int i = 1; i < n + 1; ++i) {
    scanf("%lld", &t);
    a[t]++;
  }
  for (int i = 1; i < N - 2; ++i) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = dp[i - 1][0] + i * a[i];
  }
  printf("%lld\n", max(dp[N - 3][0], dp[N - 3][1]));
  return 0;
}
