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