#include <bits/stdc++.h>
using namespace std;
int c[100005];
long long int dp[100005];
vector<pair<int, int> > v;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, x;
  cin >> n;
  for (long long int i = 0; i < n; i++) cin >> x, c[x]++;
  for (int i = 1; i < 100005; i++)
    if (c[i]) v.push_back({i, c[i]});
  int m = v.size();
  for (int i = 0; i < m; i++) {
    int x = i - 1;
    if (x >= 0 and v[x].first + 1 == v[i].first) x--;
    if (x == -1)
      dp[i] = (long long int)v[i].first * v[i].second;
    else
      dp[i] = dp[x] + (long long int)v[i].first * v[i].second;
    if (i != 0) dp[i] = max(dp[i], dp[i - 1]);
  }
  cout << dp[m - 1];
  return 0;
}
