#include <bits/stdc++.h>
long long int s = 0, m[100001], d = 0, n, r, t;
int main(void) {
  scanf("%lld", &n);
  while (n--) {
    scanf("%lld", &r);
    m[r] += r;
  }
  for (int i = 0; i < 100001; i++) {
    t = s;
    s = s > d + m[i] ? s : d + m[i];
    d = t;
  }
  printf("%lld", s);
}
