#include <bits/stdc++.h>
using namespace std;
long long n, mx = -1, arr[100005], mp[100005], dp[100000];
int main() {
  cin >> n;
  for (long long i = 0; i < n; i++) {
    cin >> arr[i];
    mp[arr[i]]++;
    mx = max(mx, arr[i]);
  }
  dp[0] = 0;
  dp[1] = mp[1];
  for (long long i = 2; i <= mx; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + mp[i] * i);
  }
  cout << dp[mx] << endl;
  return 0;
}
