#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int count[100005];
  memset(count, 0, sizeof(count));
  bool done[100005];
  memset(done, false, sizeof(done));
  long long int dp[100005][2];
  vector<long long int> arr;
  long long int n, x;
  cin >> n;
  for (long long int i = 0; i < n; i++) {
    cin >> x;
    if (!done[x]) {
      arr.push_back(x);
      done[x] = true;
    }
    count[x]++;
  }
  sort(arr.begin(), arr.end());
  n = arr.size();
  for (long long int i = 0; i <= arr[n - 1]; i++) {
    if (i == 0) {
      dp[i][0] = 0;
      dp[i][1] = 0;
    } else if (i == 1) {
      dp[i][0] = 1ll * i * count[i];
      dp[i][1] = 0;
    }
    dp[i][0] =
        max(dp[i - 1][1], max(dp[i - 2][0], dp[i - 2][1])) + 1ll * i * count[i];
    dp[i][1] = dp[i - 1][0];
  }
  long long int res = max(dp[arr[n - 1]][0], dp[arr[n - 1]][1]);
  cout << res << endl;
  return 0;
}
