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