#include <bits/stdc++.h>
using namespace std;
inline void solve() {
  long long n, freq[100005LL] = {0};
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long temp;
    cin >> temp;
    freq[temp]++;
  }
  long long dp[100005LL][2];
  dp[0][0] = 0;
  dp[0][1] = 0;
  for (long long i = 1; i < 100005LL; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = dp[i - 1][0] + freq[i] * i;
  }
  cout << max(dp[100005LL - 1][0], dp[100005LL - 1][1]);
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  ;
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
