#include <bits/stdc++.h>
using namespace std;
int a[100001];
long long dp[100001];
map<int, int> mp;
int main() {
  ios_base::sync_with_stdio(0);
  int n;
  cin >> n;
  for (int i = 1; i <= n; ++i) {
    cin >> a[i];
    mp[a[i]]++;
  }
  if (mp[a[n]] == n) {
    cout << n * 1ll * a[n];
    return 0;
  }
  dp[1] = mp[1];
  dp[0] = 0;
  for (int i = 2; i <= n; ++i) {
    dp[i] = max(dp[i - 1], dp[i - 2] + (mp[i] * 1ll * i));
  }
  cout << dp[n];
}
