#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 5;
long long n;
long long cnt[MAX];
long long high = 0;
long long dp[MAX];
long long solve(long long i) {
  if (i > high) return 0;
  if (dp[i] != -1) return dp[i];
  long long ans = 0;
  long long a = i * cnt[i] + solve(i + 2);
  long long b = solve(i + 1);
  ans = max(a, b);
  dp[i] = ans;
  return ans;
}
int main() {
  cin >> n;
  memset(cnt, 0, sizeof cnt);
  memset(dp, -1, sizeof dp);
  for (long long i = 0; i < n; i++) {
    long long a;
    cin >> a;
    cnt[a]++;
    high = max(high, a);
  }
  cout << solve(1);
  return 0;
}
