#include <bits/stdc++.h>
using namespace std;
int foo(int n) {}
int main() {
  int n;
  cin >> n;
  vector<long long> a(100010, 0);
  long long l3 = 0, l2 = 0, l1 = 0;
  for (int i = 0; i < n; ++i) {
    int t;
    cin >> t;
    a[t] += 1;
  }
  for (int i = 0; i <= 100010; ++i) {
    long long t = a[i] * i;
    long long m;
    if (t + l2 > t + l3)
      m = t + l2;
    else
      m = t + l3;
    l3 = l2;
    l2 = l1;
    l1 = m;
  }
  if (l1 > l2)
    cout << l1;
  else
    cout << l2;
  return 0;
}
