#include <bits/stdc++.h>
using namespace std;
void solve(long long int T) {
  long long int n;
  cin >> n;
  long long int freq[100005];
  memset(freq, 0, sizeof(freq));
  while (n--) {
    long long int x;
    cin >> x;
    freq[x]++;
  }
  long long int dp[100005];
  dp[0] = 0;
  dp[1] = freq[1];
  for (long long int i = 2; i < 100005; i++) {
    long long int ans = freq[i] * i;
    dp[i] = max(ans + dp[i - 2], dp[i - 1]);
  }
  cout << dp[100000] << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  for (long long int t = 1; t <= T; t++) {
    solve(t);
  }
  cerr << "time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs" << endl;
  return 0;
}
