#include <bits/stdc++.h>
using namespace std;
unsigned long long cnts[100009];
unsigned long long dp[100009];
int main() {
  std::ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int max_x = 0;
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    cnts[x]++;
    max_x = std::max(x, max_x);
  }
  dp[1] = cnts[1];
  for (int i = 2; i <= max_x; ++i) {
    dp[i] = std::max(dp[i - 1], dp[i - 2] + cnts[i] * i);
  }
  cout << dp[max_x] << endl;
  return 0;
}
