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