#include <bits/stdc++.h>
using namespace std;
bool isV(char ch) {
  return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
void tc() {
  int n, m, x;
  cin >> n;
  vector<unsigned long long int> cnt(100001);
  int mx = INT_MIN;
  int mi = INT_MAX;
  for (int i = 0; i < n; i++) {
    cin >> x;
    cnt[x]++;
    mx = max(mx, x);
    mi = min(mi, x);
  }
  vector<unsigned long long int> dp(100001);
  dp[mi] = (1LL * cnt[mi] * mi);
  for (int i = mi + 1; i <= mx; i++) {
    unsigned long long int c = dp[i - 2] + cnt[i] * i;
    dp[i] = max(dp[i - 1], c);
  }
  cout << dp[mx];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  tc();
  return 0;
}
