#include <bits/stdc++.h>
using namespace std;
long long dp[100001];
long long n;
long long cnt[100001];
long long solve(long long cur) {
  if (cur > 100001) return 0;
  long long &ret = dp[cur];
  if (ret != -1) return ret;
  return ret = max(solve(cur + 1), solve(cur + 2) + cur * cnt[cur]);
}
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long a;
    cin >> a;
    cnt[a]++;
  }
  memset(dp, -1, sizeof dp);
  cout << solve(0) << endl;
  return 0;
}
