#include <bits/stdc++.h>
using namespace std;
long long a[100005], dp[100005];
int main() {
  long long n, m = 0;
  scanf("%lld", &n);
  for (long long i = 0; i < n; i++) {
    long long x;
    scanf("%lld", &x);
    m = m > x ? m : x;
    a[x] += x;
  }
  long long max = 0;
  for (long long i = 1; i <= m; i++) {
    dp[i] = a[i] + (dp[i - 2] > dp[i - 3] ? dp[i - 2] : dp[i - 3]);
    if (dp[i] > max) {
      max = dp[i];
    }
  }
  printf("%lld", max);
  return 0;
}
