#include <bits/stdc++.h>
using namespace std;
int num[100010];
long long val[100010];
long long mx[100010];
long long d[100010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  map<int, int> mp;
  num[0] = -1;
  val[0] = mx[0] = 0;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    mp[x]++;
  }
  int m = 0;
  for (auto& p : mp) {
    m++;
    num[m] = p.first;
    val[m] = 1LL * p.first * p.second;
  }
  for (int i = 1; i <= m; i++) {
    if (num[i - 1] + 1 != num[i]) {
      d[i] = val[i] + mx[i - 1];
    } else {
      d[i] = val[i] + mx[i - 2];
    }
    mx[i] = max(mx[i - 1], d[i]);
  }
  cout << mx[m] << '\n';
  return 0;
}
