#include <bits/stdc++.h>
using namespace std;
long long int b[100002], cont[100002], n;
long long int maxm = 0;
void dp(long long int i) {
  if (i > maxm) return;
  long long int one = b[i - 1];
  long long int two = (b[i - 2] + (cont[i] * i));
  b[i] = one > two ? one : two;
  dp(i + 1);
}
int main() {
  long long int i, a;
  scanf("%I64d", &n);
  for (i = 1; i <= n; i++) {
    scanf("%I64d", &a);
    cont[a]++;
    if (maxm < a) maxm = a;
  }
  b[0] = 0;
  b[1] = cont[1];
  dp(2);
  printf("%I64d", b[maxm]);
}
