#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n;
  cin >> n;
  vector<long long> arr(n);
  for (int i = 0; i < n; i++) cin >> arr[i];
  long long maxi = *max_element(arr.begin(), arr.end());
  long long dp[maxi + 1];
  map<long long, long long> mp;
  for (auto x : arr) mp[x]++;
  dp[0] = 0;
  dp[1] = mp[1];
  for (int i = 2; i <= maxi; i++) dp[i] = max(dp[i - 1], mp[i] * i + dp[i - 2]);
  cout << dp[maxi] << "\n";
}
