#include <bits/stdc++.h>
using namespace std;
long long int m[100002], dp[100002];
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  for (long long int i = 0; i < n; i++) cin >> a[i];
  for (long long int i = 0; i < n; i++) m[a[i]]++;
  dp[0] = 0;
  dp[1] = m[1];
  for (long long int i = 2; i <= 100002; i++) {
    m[i] *= i;
    dp[i] = max(dp[i - 2] + m[i], dp[i - 1]);
  }
  cout << dp[100002];
}
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
