#include <bits/stdc++.h>
using namespace std;
long long L[100005], a[100005], b[100005];
long long n, m;
long long solve(long long u) {
  if (u == 0) 0;
  if (u == 1) return b[u];
  if (L[u] == -1) L[u] = max(solve(u - 1), solve(u - 2) + b[u] * u);
  return L[u];
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 1; i <= n; i++) {
    cin >> a[i];
    m = max(m, a[i]);
    b[a[i]]++;
  }
  memset(L, -1, sizeof(L));
  cout << solve(m);
}
