#include <bits/stdc++.h>
using namespace std;
long long f[100010], dp[100010];
int main() {
  int n, x, ma = -1;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    f[x] += x;
    ma = max(ma, x);
  }
  dp[0] = f[0];
  dp[1] = f[1];
  dp[2] = max(dp[1], f[2]);
  for (int i = 3; i <= ma; ++i) {
    if (f[i]) {
      if (!f[i - 1]) {
        dp[i] = dp[i - 1] + f[i];
      } else {
        if (f[i - 2]) {
          dp[i] = dp[i - 3] + f[i - 1];
        } else {
          dp[i] = dp[i - 1];
        }
        dp[i] = max(dp[i - 2] + f[i], dp[i]);
      }
    } else
      dp[i] = dp[i - 1];
  }
  cout << dp[ma] << endl;
  return 0;
}
