#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long n;
  cin >> n;
  unsigned long long arr[200000];
  unsigned long long hash[200000] = {0};
  unsigned long long dp[200000] = {0};
  for (unsigned long long i = 0; i <= n; i++) {
    cin >> arr[i];
    hash[arr[i]]++;
  }
  dp[0] = 0;
  dp[1] = hash[1];
  for (unsigned long long i = 2; i < 200000; i++) {
    dp[i] = max(dp[i - 2] + hash[i] * i, dp[i - 1]);
  }
  cout << dp[200000 - 1];
}
