#include <bits/stdc++.h>
using namespace std;
long long dp[100010];
int freq[100010];
int main() {
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    freq[a[i]]++;
  }
  dp[1] = freq[1];
  for (int i = 2; i <= 100002; i++)
    dp[i] = max(dp[i - 1], dp[i - 2] + (freq[i] * (long long)i));
  cout << dp[100002];
  return 0;
}
