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