#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
long long A[100005];
map<long long, long long> mp;
int main() {
  long long n, a, i;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a;
    mp[a] += a;
  }
  A[1] = mp[1];
  A[0] = 0;
  for (i = 2; i <= 100000; i++) {
    A[i] = max(A[i - 1], A[i - 2] + mp[i]);
  }
  cout << A[100000] << endl;
  return 0;
}
