#include <bits/stdc++.h>
using namespace std;
long long cnt[int(1e5 + 5)];
long long dp[int(1e5 + 5)];
int main() {
  int n;
  cin >> n;
  memset(cnt, 0, sizeof cnt);
  for (int i = 0; i < n; ++i) {
    int k;
    cin >> k;
    ++cnt[k];
  }
  long long ans = -1;
  dp[1] = cnt[1];
  for (int i = 2; i < int(1e5 + 5); ++i) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  for (int i = 0; i < int(1e5 + 5); ++i) ans = max(ans, dp[i]);
  cout << ans << "\n";
  return 0;
}
