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