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