#include <bits/stdc++.h>
long long a[100000 + 10] = {0};
long long dp[100000 + 10];
int main() {
  int n, x;
  scanf("%d", &n);
  int maxn = -1;
  while (n--) {
    scanf("%d", &x);
    a[x]++;
    if (x > maxn) maxn = x;
  }
  for (int i = 1; i <= maxn; i++) {
    dp[i] = dp[i - 1];
    if (a[i] == 0) continue;
    long long temp;
    if (i == 1)
      temp = i * a[i];
    else
      temp = dp[i - 2] + a[i] * i;
    if (temp > dp[i]) {
      dp[i] = temp;
    }
  }
  printf("%lld\n", dp[maxn]);
  return 0;
}
