#include <bits/stdc++.h>
using namespace std;
const int MAXN = 111111;
int n;
int f[MAXN + 111];
int t;
long long dp[MAXN + 111];
long long solve(int u) {
  if (u > MAXN) return 0;
  if (dp[u] != -1) return dp[u];
  return dp[u] = max(solve(u - 1), 1LL * f[u] * u + solve(u - 2));
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  while (n--) {
    cin >> t;
    f[t]++;
  }
  dp[0] = 0LL;
  dp[1] = 1LL * f[1];
  for (int i = 2; i <= MAXN; i++) {
    solve(i);
  }
  cout << dp[MAXN] << endl;
}
