#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#pragma GCC target("sse4")
using namespace std;
template <class T>
bool ckmin(T& a, const T& b) {
  return b < a ? a = b, 1 : 0;
}
template <class T>
bool ckmax(T& a, const T& b) {
  return a < b ? a = b, 1 : 0;
}
const int MOD = 1000000007;
const char nl = '\n';
const int MX = 100001;
long long dp[MX];
long long cnt[MX];
void precalc() {
  for (int i = 2; i < (MX); i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  memset(dp, -1, sizeof(dp));
  memset(cnt, 0, sizeof(cnt));
  long long mx = 0;
  for (int i = 0; i < (n); i++) {
    cin >> arr[i];
    mx = max(mx, arr[i]);
    cnt[arr[i]]++;
  }
  dp[0] = 0;
  dp[1] = cnt[1];
  precalc();
  cout << dp[mx] << nl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  solve();
  return 0;
}
