#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  vector<long long> cnt(1e5 + 2, 0), dp(1e5 + 2, 0);
  while (n--) {
    long long x;
    cin >> x;
    cnt[x]++;
  }
  dp[1] = cnt[1];
  for (int i = 2; i < 1e5 + 2; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  cout << dp[1e5 + 1] << endl;
}
