#include <bits/stdc++.h>
using namespace std;
const int maxN = 1e5 + 10;
int ad[maxN];
int main() {
  long long n, ma = 0, x, y, z;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    if (x > ma) {
      ma = x;
    }
    ad[x]++;
  }
  x = 0;
  y = ad[1];
  for (long long i = 2; i <= ma; i++) {
    z = max(ad[i] * i + x, y);
    x = y;
    y = z;
  }
  cout << y;
}
