#include <bits/stdc++.h>
using namespace std;
long long i, j, k, l, m, n, br[100009], a, b, z = 0, ans = 0, num = 0, sum = 0,
                                              cnt = 0;
long long ar[100009], cr[100009];
int main() {
  scanf("%lld", &n);
  for (i = 1; i <= n; i++) {
    scanf("%lld", &a);
    ar[a] = ar[a] + a;
  }
  for (i = 3; i <= 100000; i++) {
    ar[i] = max(ar[i - 2] + ar[i], ar[i - 3] + ar[i]);
  }
  k = ar[i];
  ans = max(ar[100000], ar[99999]);
  printf("%lld\n", ans);
  return 0;
}
