#include <bits/stdc++.h>
using namespace std;
const int maxn = (int)1e5 + 10;
long long data[maxn], cnt[maxn], dp[maxn][2], A[maxn];
int main() {
  int n;
  while (cin >> n) {
    memset(cnt, 0, sizeof(cnt));
    int cur = 0;
    for (int i = 0; i < n; ++i) {
      cin >> data[i];
      if (!cnt[data[i]]) {
        A[++cur] = data[i];
      }
      ++cnt[data[i]];
    }
    sort(A + 1, A + cur + 1);
    dp[0][1] = dp[0][0] = 0;
    for (int i = 1; i <= cur; ++i) {
      if (A[i - 1] == A[i] - 1) {
        dp[i][1] = dp[i - 1][0] + cnt[A[i]] * A[i];
      } else {
        dp[i][1] = max(dp[i - 1][0], dp[i - 1][1]) + cnt[A[i]] * A[i];
      }
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    }
    long long ans = max(dp[cur][0], dp[cur][1]);
    cout << ans << endl;
  }
}
