#include <bits/stdc++.h>
using namespace std;
long long arr[100001];
long long memo[100002];
long long solve(int k) {
  if (k == 1) {
    return memo[k] = arr[k];
  }
  if (k == 2) {
    return memo[k] = max(arr[k], arr[k - 1]);
  }
  if (memo[k] != -1) return memo[k];
  if (k > 2) {
    return memo[k] = max(arr[k] + solve(k - 2), solve(k - 1));
  }
}
int main() {
  memset(memo, -1, sizeof(memo));
  int g;
  cin >> g;
  int maxi = 0;
  for (int i = 0; i < g; i++) {
    int h;
    cin >> h;
    if (h > maxi) maxi = h;
    arr[h] += h;
  }
  cout << solve(maxi) << endl;
}
