#include <bits/stdc++.h>
using namespace std;
long long rec(long long max1, long long taken[], long long mark[],
              long long count[]) {
  int i;
  long long ans[100010] = {0};
  if (mark[1] == 1) {
    ans[1] = count[1];
  }
  for (i = 2; i <= max1; i++) {
    if (mark[i] == 0) {
      ans[i] = ans[i - 1];
    } else
      ans[i] = max(ans[i - 1], ans[i - 2] + count[i] * i);
  }
  return ans[max1];
}
int main() {
  int n;
  cin >> n;
  int i;
  long long a[100010];
  long long max = -1;
  long long mark1[100100] = {0};
  long long mark2[100100] = {0};
  long long count[100100] = {0};
  long long taken1[100010] = {0};
  long long taken2[100010] = {0};
  for (i = 0; i < n; i++) {
    cin >> a[i];
    mark1[a[i]] = 1;
    mark2[a[i]] = 1;
    count[a[i]]++;
    if (a[i] > max) {
      max = a[i];
    }
  }
  long long s1 = 0;
  long long s2 = 0;
  int j;
  s1 = rec(max, taken1, mark1, count);
  cout << s1 << endl;
  return 0;
}
