#include <bits/stdc++.h>
using namespace std;
void sb() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
int main() {
  int n;
  cin >> n;
  vector<long long> freq((int)1e5 + 2, 0);
  for (int i = 0; i < n; i++) {
    int a;
    cin >> a;
    freq[a]++;
  }
  int ans = 0;
  vector<long long> dp((int)1e5 + 2, 0);
  dp[1] = freq[1] * 1;
  for (int i = 2; i <= (int)1e5; i++) {
    dp[i] = max(dp[i - 2] + freq[i] * i, dp[i - 1]);
  }
  cout << dp[(int)1e5] << endl;
}
