#include <bits/stdc++.h>
using namespace std;
void scanint(int &x) {
  register int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
void scanlong(long long int &x) {
  register long long int c = getchar();
  x = 0;
  int neg = 0;
  for (; ((c < 48 || c > 57) && c != '-'); c = getchar())
    ;
  if (c == '-') {
    neg = 1;
    c = getchar();
  }
  for (; c > 47 && c < 58; c = getchar()) {
    x = (x << 1) + (x << 3) + c - 48;
  }
  if (neg) x = -x;
}
long long int dp[100000 + 5];
long long int a[100000 + 5] = {0};
long long int func(int i) {
  if (dp[i] != -1) return dp[i];
  return dp[i] = max(a[i] * i + func(i + 2), func(i + 1));
}
int main() {
  int t = 1;
  while (t--) {
    memset(dp, -1, sizeof(dp));
    long long int sum = 0;
    int n;
    scanint(n);
    int b;
    for (int i = 0; i < n; ++i) {
      scanint(b);
      a[b]++;
    }
    cout << func(0);
  }
  return 0;
}
