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