#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
long long n, a[N], fr[N], dp[N];
int main() {
  cin.tie(0);
  cin.sync_with_stdio(0);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    fr[a[i]]++;
  }
  dp[0] = 0;
  dp[1] = fr[1];
  for (int idx = 2; idx <= 100000; idx++) {
    dp[idx] = max(dp[idx - 1], dp[idx - 2] + fr[idx] * idx);
  }
  cout << dp[100000] << "\n";
  return 0;
}
