#include <bits/stdc++.h>
using namespace std;
std::map<long long, long long>::iterator lessthan(map<long long, long long> &mp,
                                                  long long k) {
  std::map<long long, long long>::iterator it = mp.lower_bound(k);
  if (it != mp.begin()) {
    return --it;
  }
  return mp.end();
}
long long factorial(long long n) {
  if (n == 1 || n == 0) return 1;
  return n * factorial(n - 1);
}
struct Matrix {
  vector<vector<long long> > mat;
  int n_rows, n_cols;
  Matrix(vector<vector<long long> > values)
      : mat(values), n_rows(values.size()), n_cols(values[0].size()) {}
  static Matrix identity_matrix(int n) {
    vector<vector<long long> > values(n, vector<long long>(n, 0));
    for (int i = 0; i < n; i++) values[i][i] = 1;
    return values;
  }
  Matrix operator*(const Matrix &other) const {
    int n = n_rows, m = other.n_cols;
    vector<vector<long long> > result(n_rows, vector<long long>(m, 0));
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        for (int k = 0; k < n_cols; k++) {
          result[i][j] =
              (result[i][j] + mat[i][k] * 1ll * other.mat[k][j]) % 1000000007;
        }
      }
    return Matrix(result);
  }
  inline bool is_square() const { return n_rows == n_cols; }
};
Matrix fast_exponentiation(Matrix m, long long power) {
  Matrix result = Matrix::identity_matrix(m.n_rows);
  while (power) {
    if (power & 1) result = result * m;
    m = m * m;
    power >>= 1;
  }
  return result;
}
vector<long long> dp;
long long help(long long freq[], long long ind, long long n) {
  if (ind >= n) return 0;
  if (dp[ind] != -1) return dp[ind];
  return dp[ind] = max(help(freq, ind + 2, n) + freq[ind] * ind,
                       help(freq, ind + 1, n));
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n;
  cin >> n;
  long long arr[n];
  long long mz = 0;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    mz = max(mz, arr[i]);
  }
  long long freq[mz + 1];
  memset(freq, 0, sizeof(freq));
  for (long long i = 0; i < n; i++) {
    freq[arr[i]]++;
  }
  dp.resize(mz + 5, -1);
  cout << help(freq, 1, mz + 1);
  return 0;
}
