#include <bits/stdc++.h>
using namespace std;
long long int mp[100000];
int main() {
  int n, a[100000], N = 100000;
  unsigned long long int dp[N];
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    mp[a[i] - 1]++;
  }
  dp[N - 1] = mp[N - 1] * N;
  dp[N - 2] = mp[N - 2] * (N - 1);
  dp[N - 3] = mp[N - 3] * (N - 2) + dp[N - 1];
  for (int i = N - 4; i >= 0; i--) {
    dp[i] = mp[i] * (i + 1) + max(dp[i + 2], dp[i + 3]);
  }
  cout << *max_element(dp, dp + N);
  return 0;
}
