#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimization("O3")
#pragma GCC optimization("unroll-loops")
string inttostr(long long int n) {
  std::stringstream ss;
  ss << n;
  string out = ss.str();
  return out;
}
long long int stringtoint(string s) {
  istringstream iss(s);
  long long int n;
  iss >> n;
  return n;
}
template <typename T>
T gcd(T a, T b) {
  if (a < 0) return gcd(-a, b);
  if (b < 0) return gcd(a, -b);
  return (b == 0) ? a : gcd(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  if (a < 0) return lcm(-a, b);
  if (b < 0) return lcm(a, -b);
  return a * (b / gcd(a, b));
}
long long int sum = 0;
long long int dp[1000005];
long long int n;
map<long long int, long long int> cnt;
long long int arr[1000005];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> arr[i];
    cnt[arr[i]]++;
  }
  dp[1] = cnt[1];
  for (int i = 2; i <= 1e5; ++i) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  return cout << dp[100000] << '\n', 0;
}
