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