#include <bits/stdc++.h>
using namespace std;
long long n, i, a[150001], b[150001], x;
int main() {
  cin >> n;
  for (i = 0; i < n; i++) {
    cin >> x;
    a[x] += x;
  }
  b[1] = a[1];
  b[2] = max(a[1], a[2]);
  for (i = 3; i <= 150000; i++) {
    b[i] = max(b[i - 1], b[i - 2] + a[i]);
  }
  cout << b[150000];
  return 0;
}
