#include <bits/stdc++.h>
using namespace std;
long long s[100000 + 9], n, f1[100000 + 9], f2[100000 + 9];
int main() {
  memset(s, 0, sizeof(s));
  scanf("%I64d", &n);
  long long res = 0;
  for (long long i = 1; i <= n; ++i) {
    long long x;
    scanf("%I64d", &x);
    ++s[x];
  }
  memset(f1, 0, sizeof(f1));
  memset(f2, 0, sizeof(f2));
  for (long long i = 1; i <= 100000; ++i) {
    f1[i] = f2[i - 1] + s[i] * i;
    if (i > 1) f1[i] = max(f1[i], f1[i - 2] + s[i] * i);
    f2[i] = max(f1[i - 1], f2[i - 1]);
  }
  printf("%I64d\n", max(f1[100000], f2[100000]));
  return 0;
}
