#include <bits/stdc++.h>
using namespace std;
map<long long, long long> m;
vector<long long> v;
long long dp[100010];
long long solve(long long i) {
  if (i >= v.size()) return 0;
  if (dp[i] != -1) return dp[i];
  long long choice1 = 0, choice2 = 0;
  if (v[i + 1] - v[i] > 1) {
    choice1 = solve(i + 1) + v[i] * m[v[i]];
  } else {
    choice1 = solve(i + 1);
    choice2 = solve(i + 2) + v[i] * m[v[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;
    if (m[x] == 0) v.push_back(x);
    m[x]++;
  }
  sort(v.begin(), v.end());
  v.push_back(0);
  cout << solve(0);
}
