#include <bits/stdc++.h>
using namespace std;
const int MAX = 2e5 + 5;
long long numbers[MAX];
long long frq[MAX];
long long dp[MAX];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> numbers[i];
    frq[numbers[i]]++;
  }
  dp[0] = 0;
  dp[1] = frq[1];
  for (int i = 2; i < MAX; ++i) {
    dp[i] = max(i * frq[i] + dp[i - 2], dp[i - 1]);
  }
  cout << dp[MAX - 1] << endl;
}
