#include <bits/stdc++.h>
using namespace std;
long long total[100002];
int main() {
  long long n, i, x, max_val = -1e+9;
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    total[x] += x;
    max_val = max(max_val, x);
  }
  long long points;
  for (i = 2; i <= max_val; i++) {
    total[i] = max(total[i - 1], total[i - 2] + total[i]);
  }
  points = total[max_val];
  cout << points;
}
