#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n;
  vector<long long> a(n), cnt(1e5 + 5, 0);
  for (auto& i : a) {
    cin >> i;
    cnt[i]++;
  }
  vector<long long> dp(1e5 + 5, 0);
  long long mx = 0;
  dp[1] = cnt[1];
  for (int i = 2; i <= 1e5; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + i * cnt[i]);
    mx = max(mx, dp[i]);
  }
  cout << mx << '\n';
  return 0;
}
