#include <bits/stdc++.h>
using namespace std;
const int size = 1e5;
map<int, long long> mp;
long long dp[size + 10];
int main() {
  int n, x, num;
  cin >> n;
  num = -1;
  for (int i = 1; i <= n; ++i) {
    cin >> x;
    ++mp[x];
    num = max(x, num);
  }
  memset(dp, 0, sizeof(dp));
  for (int i = 1; i <= num; ++i) {
    dp[i] = max(dp[i - 1], mp[i] * i + dp[i - 2]);
  }
  cout << dp[num] << endl;
  return 0;
}
