#include <bits/stdc++.h>
using namespace std;
long long n, x, dp[100001], coun[100001];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> n;
  while (n-- && cin >> x) coun[x]++;
  dp[1] = coun[1];
  for (long long i = 2; i < 100001; i++)
    dp[i] = max(dp[i - 2] + coun[i] * i, dp[i - 1]);
  cout << dp[100000] << endl;
  return 0;
}
