#include <bits/stdc++.h>
using namespace std;
long long d[100005], a[100005];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  d[1] = a[1];
  for (int i = 2; i <= 100000; i++) d[i] = max(d[i - 1], d[i - 2] + a[i] * i);
  cout << d[100000] << endl;
  return 0;
}
