#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
long long dp[100020];
long long solve(long long i) {
  if (i > 100000) return 0;
  if (dp[i] != -1) return dp[i];
  long long choice1 = 0, choice2 = 0;
  choice1 = solve(i + 1);
  choice2 = solve(i + 2) + (i * m[i]);
  return dp[i] = max(choice1, choice2);
}
signed main() {
  memset(dp, -1, sizeof dp);
  long long n;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    m[x]++;
  }
  cout << solve(1);
}
