#include <bits/stdc++.h>
using namespace std;
long long int n, t, a[100010], dp[100010];
int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> t;
    a[t]++;
  }
  dp[1] = a[1];
  dp[2] = max(a[1], a[2] * 2);
  dp[3] = max(a[1] + a[3] * 3, a[2] * 2);
  for (long long i = 4; i < 100001; i++)
    dp[i] = max(dp[i - 2] + a[i] * i, dp[i - 3] + a[i - 1] * (i - 1));
  cout << dp[100000] << endl;
  return 0;
}
