#include <bits/stdc++.h>
using namespace std;
const int mx = 1e5 + 5;
long long dp[mx];
long long cnt[mx];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    cnt[x]++;
  }
  dp[1] = cnt[1];
  for (long long i = 2; i < mx; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  cout << dp[mx - 1];
  cerr << "\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
  return 0;
}
