#include <bits/stdc++.h>
using namespace std;
const int mx = 10e5 + 100;
long long int n, dp[mx], pd[mx];
int main() {
  cin >> n;
  long long int an1 = 0, an2 = mx;
  for (int i = 0; i < n; ++i) {
    long long int a;
    cin >> a;
    pd[a]++;
    an1 = max(a, an1);
    an2 = min(a, an2);
  }
  for (int i = an2; i <= an1; ++i) {
    dp[i] = dp[max(0, i - 2)] + (pd[i] * i);
    dp[i] = max(dp[i], dp[i - 1]);
  }
  long long int ans = 0;
  for (int i = an2; i <= an1; ++i) ans = max(ans, dp[i]);
  cout << ans << endl;
}
