#include <bits/stdc++.h>
using namespace std;
int constexpr max_n = 1e5 + 10;
long long int a[max_n], dp[max_n], n, b;
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) cin >> b, a[b]++;
  for (int i = 1; i < max_n; i++) dp[i] = max(dp[i - 1], dp[i - 2] + i * a[i]);
  cout << dp[max_n - 1];
}
