#include <bits/stdc++.h>
using namespace std;
const int MAXn = 100 * 1000 + 5;
int n;
long long ar[MAXn], dp[MAXn];
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> ar[i];
  sort(ar, ar + n);
  long long ans = 0;
  for (int j = 0, i = 2; j < n; ++i) {
    int nj = j + 1;
    while (nj < n && ar[nj] == ar[j]) ++nj;
    dp[i] = (j && ar[j] == ar[j - 1] + 1)
                ? max(dp[i - 1], dp[i - 2] + (nj - j) * ar[j])
                : dp[i - 1] + (nj - j) * ar[j];
    ans = max(ans, dp[i]);
    j = nj;
  }
  cout << ans << endl;
  return 0;
}
