#include <bits/stdc++.h>
using namespace std;
long long a[1000 * 100 + 10];
long long val[1000 * 100 + 10];
long long dp[1000 * 100 + 10][2];
int main() {
  long long n;
  cin >> n;
  long long maxA = 0;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    val[a[i]]++;
    maxA = max(maxA, a[i]);
  }
  dp[0][0] = 0;
  dp[0][1] = 0;
  for (long long i = 1; i <= maxA; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1] + (val[i] * i));
    dp[i][1] = dp[i - 1][0];
  }
  cout << dp[maxA][0] << endl;
  return 0;
}
