#include <bits/stdc++.h>
using namespace std;
long long a[100010] = {0};
long long dp[100010] = {0};
int main() {
  int n;
  cin >> n;
  int maxx = 0;
  for (int i = 0; i < n; i++) {
    int k;
    cin >> k;
    if (maxx < k) maxx = k;
    a[k]++;
  }
  dp[1] = a[1];
  dp[2] = max(a[1], 2 * a[2]);
  for (int i = 3; i <= maxx; i++) {
    long long tmp = dp[i - 2] + i * a[i];
    dp[i] = max(tmp, dp[i - 1]);
  }
  long long ans = 0;
  for (int i = 1; i <= maxx; i++) ans = max(ans, dp[i]);
  cout << ans;
  return 0;
}
