#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int n, mx = -1;
  cin >> n;
  vector<int> v(n);
  vector<int> freq(100001);
  vector<unsigned long long int> dp(100001);
  for (int i = 0; i < n; i++) {
    cin >> v[i];
    mx = max(v[i], mx);
    freq[v[i]]++;
  }
  dp[0] = 0;
  dp[1] = freq[1];
  dp[2] = max(freq[1], 2 * freq[2]);
  for (int i = 3; i <= mx; i++) {
    dp[i] = (unsigned long long int)i * freq[i] + max(dp[i - 2], dp[i - 3]);
  }
  cout << (unsigned long long int)max(dp[mx], dp[mx - 1]) << endl;
  return 0;
}
