#include <bits/stdc++.h>
long long dp[(int)1e5 + 10] = {0};
int cnt[(int)1e5 + 10] = {0};
int n;
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  int m = 0;
  for (long long i = 1; i <= n; i++) {
    int x;
    cin >> x;
    ++cnt[x];
    m = max(m, x);
  }
  dp[1] = cnt[1];
  for (long long i = 2; i <= m; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + (i)*1ll * cnt[i]);
  }
  cout << dp[m] << "\n";
}
