#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  unsigned long long int n, max_ele = 0;
  cin >> n;
  vector<unsigned long long int> a(n + 1);
  unordered_map<unsigned long long int, unsigned long long int> freq;
  for (unsigned long long int i = 1; i <= n; i++) {
    cin >> a[i];
    max_ele = max(max_ele, a[i]);
    freq[a[i]]++;
  }
  unsigned long long int dp[max_ele + 1];
  memset(dp, 0, sizeof dp);
  dp[1] = freq[1];
  for (unsigned long long int i = 2; i <= max_ele; i++) {
    dp[i] = max(dp[i - 2] + i * freq[i], dp[i - 1]);
  }
  cout << dp[max_ele];
  return 0;
}
