#include <bits/stdc++.h>
using namespace std;
const long long N = 1e5 + 5;
long long n;
long long a[N], dp[N], cnt[N];
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  dp[0] = 0;
  dp[1] = cnt[1];
  for (long long i = 2; i <= 1e5 + 2; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  cout << dp[*max_element(a, a + n)] << "\n";
  return 0;
}
