#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
long long int a[maxn], dp[maxn];
int main() {
  int n;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int x;
    cin >> x;
    a[x] += x;
  }
  dp[1] = a[1];
  for (int i = 2; i <= maxn; i++) dp[i] = max(dp[i - 1], dp[i - 2] + a[i]);
  cout << dp[maxn - 1] << endl;
}
