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