#include <bits/stdc++.h>
long long dp[100001][2];
long long a[100001];
int main() {
  int n;
  scanf("%d", &n);
  long long max = -1;
  long long min = (int)1e5 + 5;
  int tmp;
  for (int i = 0; i < n; i++) {
    scanf("%d", &tmp);
    if (tmp > max) max = tmp;
    if (tmp < min) min = tmp;
    a[tmp] += tmp;
  }
  dp[min][0] = a[min];
  dp[min][1] = 0;
  for (int i = min + 1; i <= max; i++) {
    dp[i][0] = dp[i - 1][1] + a[i];
    dp[i][1] = std::max(dp[i - 1][0], dp[i - 1][1]);
  }
  printf("%I64d\n", std::max(dp[max][0], dp[max][1]));
  return 0;
}
