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