#include <bits/stdc++.h>
using namespace std;
pair<long long, long long> arr[100005];
long long ans, start, mem[100005];
long long solve(int indx) {
  if (indx - start == 1) return max(arr[start].second, arr[indx].second);
  if (indx == start) return arr[start].second;
  if (indx < start) return 0;
  if (mem[indx] != -1) return mem[indx];
  long long tmp = max(arr[indx].second + solve(indx - 2),
                      arr[indx - 1].second + solve(indx - 3));
  return mem[indx] = tmp;
}
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int tmp;
    cin >> tmp;
    arr[tmp].first = tmp;
    arr[tmp].second += tmp;
  }
  sort(arr, arr + 100005);
  int indx = 100004;
  for (int i = 100003; i > 0; i--) {
    if (arr[i].first == 0) {
      start = i + 1;
      memset(mem, -1, sizeof mem);
      ans += solve(indx);
      break;
    }
    if (arr[i].first + 1 != arr[i + 1].first) {
      memset(mem, -1, sizeof mem);
      start = i + 1;
      ans += solve(indx);
      indx = i;
    }
  }
  cout << ans;
  return 0;
}
