#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
long long n, a, dp[MAX], cant[MAX];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) cin >> a, cant[a]++;
  for (long long i = 1; i < MAX; i++) {
    dp[i] = max(dp[i - 1], cant[i]);
    if (i >= 2) dp[i] = max(dp[i], dp[i - 2] + cant[i] * i);
  }
  cout << dp[MAX - 1] << "\n";
}
