#include <bits/stdc++.h>
using namespace std;
long long n, d[100001];
unordered_map<long long, long long> num;
int D = 1;
int main() {
  cin >> n;
  for (long long i = 1; i <= n; ++i) {
    long long x;
    cin >> x;
    if (num.find(x) != num.end())
      num[x]++;
    else
      num[x] = 1;
  }
  d[0] = 0;
  d[1] = num[1];
  for (long long i = 2; i <= 100000; ++i) {
    d[i] = max(num[i] * i + d[i - 2], d[i - 1]);
  }
  cout << d[100000] << '\n';
  return 0;
}
