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