#include <bits/stdc++.h>
const int MAX_N = 100001;
long long int dp[100001], c[100001];
int main() {
  int n, x;
  scanf("%d", &n);
  while (n--) {
    scanf("%d", &x);
    c[x]++;
  }
  dp[0] = 0;
  dp[1] = c[1];
  for (int i = 2; i < MAX_N; i++) {
    dp[i] =
        (dp[i - 1] > (dp[i - 2] + i * c[i])) ? dp[i - 1] : dp[i - 2] + i * c[i];
  }
  printf("%lld", dp[MAX_N - 1]);
  return 0;
}
