#include <bits/stdc++.h>
using namespace std;
int counts[100004] = {0};
long long int dp[100004];
int main() {
  int n, d;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &d);
    counts[d]++;
  }
  for (int i = 100000; i >= 1; i--) {
    dp[i] = max(1LL * counts[i] * i + dp[i + 2], dp[i + 1]);
  }
  printf("%lld\n", dp[1]);
}
