#include <bits/stdc++.h>
using namespace std;
long long f[100005];
long long num[100005];
int main() {
  int n, tmp;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    num[tmp]++;
  }
  f[1] = num[1];
  for (long long i = 2; i <= 100000; i++)
    f[i] = max(f[i - 1], f[i - 2] + num[i] * i);
  printf("%I64d\n", f[100000]);
  return 0;
}
