#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int a[maxn], b[maxn];
long long dp[maxn];
int main() {
  int n;
  int maxn = 0;
  long long ans;
  while (cin >> n) {
    memset(b, 0, sizeof(b));
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      b[a[i]]++;
      maxn = max(maxn, a[i]);
    }
    dp[1] = b[1];
    dp[0] = 0;
    for (int i = 2; i <= maxn; i++)
      dp[i] = max(dp[i - 1], dp[i - 2] + (long long)i * b[i]);
    ans = 0;
    for (int i = 1; i <= maxn; i++) ans = max(ans, dp[i]);
    cout << ans << endl;
  }
  return 0;
}
