#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, a;
  long long max1 = 0, max2 = 0;
  ;
  long long* arr = new long long[100001];
  for (int i = 0; i < 100001; i++) {
    arr[i] = 0;
  }
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a;
    arr[a]++;
  }
  vector<long long> sums;
  for (int i = 0; i < 100001; i++) {
    if (i > 0 && arr[i] != 0) {
      if (arr[i - 1] != 0) {
        sums.push_back(max1 + i * arr[i]);
      } else {
        if (max1 > max2) {
          sums.push_back(max1 + i * arr[i]);
        } else {
          sums.push_back(max2 + i * arr[i]);
        }
      }
      max1 = max1 > max2 ? max1 : max2;
      max2 = sums[sums.size() - 1];
    }
  }
  long long max = 0;
  for (auto i : sums) {
    if (i > max) {
      max = i;
    }
  }
  cout << max;
}
