#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int sz = 1e5 + 10;
ll ar[sz];
ll dp[sz];
int main() {
  int n, mx;
  while (cin >> n) {
    mx = 0;
    memset(ar, 0, sizeof ar);
    memset(dp, 0, sizeof dp);
    for (int i = 0; i < n; i++) {
      int x;
      cin >> x;
      ar[x]++;
      mx = max(mx, x);
    }
    for (int i = 0; i <= mx; i++) {
      dp[i] = max({dp[i], (i >= 1 ? dp[i - 1] : 0),
                   (i >= 2 ? dp[i - 2] : 0) + ar[i] * i});
    }
    cout << dp[mx] << "\n";
  }
  return 0;
}
