#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, x, mx = 0, arr[100009] = {};
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> x;
    arr[x]++;
    mx = max(mx, x);
  }
  for (int i = mx; i >= 1; i--) {
    arr[i] = arr[i] * i + max(arr[i + 2], arr[i + 3]);
  }
  cout << max(arr[1], arr[2]) << endl;
  return 0;
}
