#include <bits/stdc++.h>
using namespace std;
long long a[100010], dp[100010], cnt[100010], p[100010];
int main() {
  long long n, i, l = 1;
  cin >> n;
  for (i = 1; i <= n; i++) {
    cin >> a[i];
    cnt[a[i]]++;
  }
  sort(a + 1, a + n + 1);
  for (i = 1; i <= n; i++) {
    if (a[i] == a[i - 1]) continue;
    p[l++] = a[i];
  }
  for (i = 1; i < l; i++) {
    if (p[i] - 1 == p[i - 1])
      dp[i] = max(dp[i - 1], dp[i - 2] + p[i] * cnt[p[i]]);
    else
      dp[i] = dp[i - 1] + p[i] * cnt[p[i]];
  }
  cout << dp[l - 1] << endl;
  return 0;
}
