#include <bits/stdc++.h>
using namespace std;
int x, n, a[100010];
long long ans, f[100010][2], inf = 10000000000000000LL;
void read(int &x) {
  char ch = getchar();
  int mark = 1;
  for (; ch != '-' && (ch < '0' || ch > '9'); ch = getchar())
    ;
  if (ch == '-') mark = -1, ch = getchar();
  for (x = 0; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - 48;
  x *= mark;
}
int main() {
  read(n);
  for (int i = 1; i <= n; i++) {
    read(x);
    a[x]++;
  }
  for (int i = 1; i <= 100000;)
    if (a[i]) {
      int j = i;
      for (; j <= 100000 && a[j]; j++)
        ;
      f[i - 1][0] = 0;
      f[i - 1][1] = -inf;
      for (int k = i; k < j; k++) {
        f[k][0] = max(f[k - 1][0], f[k - 1][1]);
        f[k][1] = f[k - 1][0] + (long long)a[k] * k;
      }
      ans += max(f[j - 1][0], f[j - 1][1]);
      i = j;
    } else
      i++;
  printf("%I64d\n", ans);
  return 0;
}
