#include <bits/stdc++.h>
using namespace std;
const int OO = INT_MAX;
using namespace std;
const int N = 1e5 + 100;
int n;
long long a[N];
long long cnt[N];
long long dp[N];
long long solve(long long idx) {
  if (idx == 0) return 0;
  if (idx == 1) return cnt[1];
  if (dp[idx] != -1) return dp[idx];
  return dp[idx] = max(solve(idx - 1), solve(idx - 2) + idx * cnt[idx]);
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  memset(dp, -1, sizeof(dp));
  cin >> n;
  long long mm = 0;
  for (int i = 0; i < (int)(n); ++i) {
    cin >> a[i];
    cnt[a[i]]++;
    mm = max(mm, a[i]);
  }
  cout << solve(mm);
  return 0;
}
