#include <bits/stdc++.h>
using namespace std;
long long arr[123456] = {0}, mem[123456], n, x;
long long f(int i) {
  if (i > 100000) return 0;
  if (mem[i] != -1) return mem[i];
  return mem[i] = max(arr[i] * i + f(i + 2), f(i + 1));
}
int main() {
  memset(mem, -1, sizeof mem);
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    arr[x]++;
  }
  cout << f(1) << endl;
  return 0;
}
