#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  long long f[100001] = {0};
  set<long long> s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    long long x;
    cin >> x;
    f[x]++;
    s.insert(x);
  }
  int l = 0, i = 1;
  long long dp[100001][2];
  dp[0][0] = dp[0][1] = 0;
  for (auto c : s) {
    if (c == l + 1)
      dp[i][1] = dp[i - 1][0] + c * f[c];
    else
      dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + c * f[c];
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    l = c;
    i++;
  }
  int k = s.size();
  long long ans = max(dp[k][0], dp[k][1]);
  cout << ans;
  return 0;
}
