#include <bits/stdc++.h>
using namespace std;
template <typename T>
T gcd(T a, T b) {
  if (!b) return a;
  return gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return a * b / gcd(a, b);
}
long long dp[100002];
long long fre[100002];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i += 1) {
    long long temp;
    cin >> temp;
    fre[temp]++;
  }
  for (int i = 0; i < 100002; i += 1) {
    fre[i] *= i;
  }
  dp[0] = 0;
  dp[1] = fre[1];
  for (int i = 2; i <= 100000; i++) {
    dp[i] = (dp[i - 1] >= dp[i - 2] + fre[i] ? dp[i - 1] : dp[i - 2] + fre[i]);
  }
  cout << dp[100000] << endl;
  return 0;
}
