#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
const double pii = 2 * pi;
const double eps = 1e-6;
const double inf = 1e15;
long long int freq[100005], dp[100005];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int n, x;
  cin >> n;
  long long int m = 0;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    freq[x]++;
    m = max(m, x);
  }
  dp[0] = 0;
  dp[1] = freq[1];
  for (long long int i = 2; i <= m; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + i * freq[i]);
  }
  cout << dp[m] << "\n";
  cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n";
  return 0;
}
