#include <bits/stdc++.h>
using namespace std;
inline long long int inp() {
  long long int n = 0, s = 1;
  char c = getchar();
  while (c < '0') {
    if (c == '-') s = -1;
    c = getchar();
  }
  while (c <= '9' && c >= '0') n = (n << 3) + (n << 1) + c - '0', c = getchar();
  return n * s;
}
long long int n, arr[100007], dp[100007];
int main() {
  n = inp();
  memset(arr, 0, sizeof(arr));
  for (int i = 0; i < n; ++i) arr[inp()]++;
  dp[100007 - 1] = arr[100007 - 1] * (100007 - 1L);
  dp[100007 - 2] = (dp[100007 - 1] > arr[100007 - 2] * (100007 - 2L)
                        ? dp[100007 - 1]
                        : arr[100007 - 2] * (100007 - 2L));
  for (long long int i = 100007 - 2; i > 0; --i)
    dp[i] = (dp[i + 1] > arr[i] * i + dp[i + 2] ? dp[i + 1]
                                                : arr[i] * i + dp[i + 2]);
  printf("%lld\n", dp[1]);
  return 0;
}
