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