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