#include <bits/stdc++.h>
using namespace std;
int f[100001];
int main() {
  long long n, i, nr, m = 0, a, b;
  cin >> n;
  while (n--) {
    cin >> nr;
    f[nr]++;
    if (nr > m) m = nr;
  }
  a = 0;
  b = f[1];
  for (i = 2; i <= m; i++) {
    if (b > a + f[i] * i)
      nr = b;
    else
      nr = a + f[i] * i;
    a = b;
    b = nr;
  }
  cout << b;
  return 0;
}
