#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int n, i, dp[100005] = {0}, ma = -1, h[100005] = {0}, a[100002];
  cin >> n;
  for (i = 0; i < n; i++) cin >> a[i];
  sort(a, a + n);
  for (i = 0; i < n; i++) {
    h[a[i]]++;
    ma = max(a[i], ma);
  }
  dp[0] = 0;
  dp[1] = h[1];
  for (i = 2; i < ma + 1; i++) {
    dp[i] = max(dp[i - 1], h[i] * i + dp[i - 2]);
  }
  cout << dp[ma] << endl;
}
