#include <bits/stdc++.h>
using namespace std;
long long dp[100005];
long long counter[100005] = {0};
int main() {
  int n, x;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> x;
    counter[x]++;
  }
  dp[0] = 0;
  dp[1] = counter[1];
  for (int i = 2; i < 100005; ++i) {
    dp[i] = max((i * counter[i]) + dp[i - 2], dp[i - 1]);
  }
  cout << dp[100004] << endl;
  return 0;
}
