#include <bits/stdc++.h>
using namespace std;
int n;
int a[100010], b[100010];
long long dp[100010], s[100010];
int res;
int main() {
  for (int i = 0; i < 100010; i++) s[i] = 0LL;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &a[i]);
    s[a[i]]++;
  }
  sort(a, a + n);
  int e = -1;
  for (int i = 0; i < n; i++) {
    if (i == 0 || a[i] != b[e]) {
      e++;
      b[e] = a[i];
    }
  }
  memset(dp, 0, sizeof(dp));
  dp[0] = b[0] * s[b[0]];
  dp[1] = b[1] * s[b[1]];
  if (b[1] != b[0] + 1)
    dp[1] += dp[0];
  else
    dp[1] = max(dp[1], dp[0]);
  for (int i = 2; i <= e; i++) {
    if (b[i] == b[i - 1] + 1) {
      dp[i] = max(dp[i - 2] + 1LL * b[i] * s[b[i]], dp[i - 1]);
    } else {
      dp[i] = max(dp[i - 2] + 1LL * b[i] * s[b[i]],
                  dp[i - 1] + 1LL * b[i] * s[b[i]]);
    }
  }
  printf("%I64d\n", dp[e]);
  return 0;
}
