#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long arr[N], dp[N], n;
long long go(int indx) {
  if (indx == n) return 0;
  long long &ret = dp[indx];
  if (~ret) return ret;
  long long sum = arr[indx], j = indx + 1;
  while (j != n && arr[j] == arr[indx]) sum += arr[j++];
  ret = go(j);
  while (j != n && arr[j] - arr[indx] == 1) j++;
  return ret = max(ret, sum + go(j));
}
int main() {
  memset(dp, -1, sizeof dp);
  cin >> n;
  for (int i = 0; i < n; cin >> arr[i++])
    ;
  sort(arr, arr + n);
  cout << go(0);
  return 0;
}
