#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e9 + 7;
const double pi =
    3.14159265358979323846264338327950288419716939937510582097494459;
const double EPS = 1e-10;
const int N = 1e5 + 3;
const int oo = 1e9 + 7;
const long long OO = 1e18;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int arr[N];
long long dp[N];
long long solve(int i) {
  if (i > N) return 0;
  if (~dp[i]) return dp[i];
  return dp[i] = max(solve(i + 1), solve(i + 2) + arr[i] * 1LL * i);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    arr[x]++;
  }
  memset(dp, -1, sizeof(dp));
  cout << solve(1) << endl;
}
