#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, i;
  scanf("%I64d", &t);
  long long int a[100011] = {0}, cnt[100011] = {0};
  long long int dp[100011] = {0};
  long long int max1 = 0;
  for (int i = 0; i < t; ++i) {
    scanf("%I64d", &a[i]);
    cnt[a[i]]++;
    if (a[i] > max1) {
      max1 = a[i];
    }
  }
  dp[0] = 0;
  dp[1] = cnt[1];
  for (i = 2; i <= max1; ++i) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  printf("%I64d\n", dp[i - 1]);
  return 0;
}
