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