#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int mN = 1e5;
int n;
vector<long long> dp(mN + 1);
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  unordered_map<long long, long long> arr;
  for (int i = 0, x; i < n; ++i) {
    cin >> x;
    arr[x]++;
  }
  dp[0] = 0;
  for (long long i = 1; i <= mN; ++i) {
    dp[i] = (arr[i] * i) + ((i - 2 >= 0) ? dp[i - 2] : 0);
    if (dp[i - 1] > dp[i]) dp[i] = dp[i - 1];
  }
  cout << dp[mN] << "\n";
}
