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