#include <bits/stdc++.h>
long long int ciel(double a) {
  long long int ret = a;
  if (a - ret > 0.0000000001) ret++;
  return ret;
}
long long int gcd(long long int a, long long int b) {
  if (a < b) return gcd(b, a);
  if (a % b == 0) return b;
  return gcd(b, a % b);
}
double fgcd(double a, double b) {
  if (fabs(a) < fabs(b)) return fgcd(b, a);
  if (fabs(b) < 0.0001) return a;
  return fgcd(b, fmod(a, b));
}
bool db_db_cmp(double a, double b) {
  return (a + 0.0000000001 > b && a - 0.0000000001 < b);
}
long long int fact[100005];
void generate_factorials() {
  fact[0] = fact[1] = 1;
  for (int i = 2; i <= 100005 - 1; i++)
    fact[i] = ((fact[i - 1] * i) % 1000000007);
}
long long int pow(long long int n, long long int p) {
  if (p == 0) return 1;
  if (n <= 1) return n;
  long long int res = 1;
  while (p) {
    if (p & 1) res = res * n;
    n = n * n;
    p /= 2;
  }
  return res;
}
long long int mod_pow(long long int n, long long int p) {
  if (p == 0) return 1;
  if (n <= 1) return n;
  long long int res = 1;
  while (p) {
    if (p & 1) res = ((res * n) % 1000000007);
    n = ((n * n) % 1000000007);
    p /= 2;
  }
  return res;
}
long long int get_inverse(long long int n) {
  return mod_pow(n, 1000000007 - 2);
}
long long int get_nCr(long long int n, long long int r) {
  return ((fact[n] * get_inverse(((fact[r] * fact[n - r]) % 1000000007))) %
          1000000007);
}
using namespace std;
void preprocess() {}
long long int ar[100005];
long long int dp[100005];
void init() {
  for (int i = 0; i <= 100005 - 1; i++) ar[i] = dp[i] = 0;
}
void solve(int test_case) {
  init();
  long long int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long int a;
    cin >> a;
    ar[a] += a;
  }
  dp[0] = 0;
  dp[1] = ar[1];
  dp[2] = ar[2];
  long long int ans = max(dp[1], dp[2]);
  for (int i = 3; i <= 100000; i++) {
    dp[i] = max(dp[i - 2], dp[i - 3]) + ar[i];
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
}
int main() {
  preprocess();
  int t = 1;
  for (int i = 1; i <= t; i++) {
    solve(i);
  }
  return 0;
}
