#include <bits/stdc++.h>
using namespace std;
long long t[100010] = {0};
long long f[100010] = {0};
int b = 4;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int mx = 0;
  int n, a;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    a += b;
    mx = max(mx, a);
    t[a]++;
  }
  for (int i = b; i < mx + 2; i++) {
    f[i] = max(f[i - 1], f[i - 2] + t[i - 1] * (i - b - 1));
  }
  cout << f[mx + 1];
  return 0;
}
