#include <bits/stdc++.h>
using namespace std;
const int maxn = 100005;
int n, cnt[maxn];
long long dp[maxn];
int main() {
  while (~scanf("%d", &n)) {
    int tmp, top = 0;
    memset(cnt, 0, sizeof cnt);
    for (int i = 0; i < n; ++i) {
      scanf("%d", &tmp);
      top = max(top, tmp);
      cnt[tmp]++;
    }
    dp[0] = 0;
    dp[1] = cnt[1];
    for (int i = 2; i <= top; ++i)
      dp[i] = max(dp[i - 1], dp[i - 2] + (long long)i * (long long)cnt[i]);
    printf("%I64d\n", dp[top]);
  }
  return 0;
}
