#include <bits/stdc++.h>
using namespace std;
int *b, a;
int main() {
  int n;
  cin >> n;
  b = new int[100001];
  unsigned long long int dp[100001];
  for (int i = 0; i < 100001; i++) b[i] = 0, dp[i] = 0;
  for (int i = 0; i < n; i++) cin >> a, b[a]++;
  dp[0] = 0;
  dp[1] = b[1];
  int last = -1;
  for (unsigned long long int i = 2; i <= 100000; i++)
    dp[i] = max(dp[i - 1], i * b[i] + dp[i - 2]);
  cout << dp[100000] << "\n";
  return 0;
}
