#include <bits/stdc++.h>
using namespace std;
deque<long long> p;
deque<long long> q;
int main() {
  unsigned long long n, i, a[100005], dp[100005], x, ma = 0;
  cin >> n;
  for (i = 0; i <= n; i++) a[i] = 0;
  for (i = 0; i < n; i++) {
    cin >> x;
    ma = max(ma, x);
    a[x]++;
  }
  dp[0] = 0;
  dp[1] = a[1];
  for (i = 2; i <= ma; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + a[i] * i);
  }
  cout << dp[ma];
  return 0;
}
