#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, tmp;
  long long sums[(int)1e5 + 1];
  long long dp[(int)1e5 + 1];
  long long sum = 0;
  memset(sums, 0, sizeof(sums));
  memset(dp, 0, sizeof(dp));
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> tmp;
    sums[tmp] += tmp;
  }
  dp[1] = sums[1];
  dp[2] = sums[2];
  for (int i = 3; i <= 1e5; i++) {
    dp[i] = sums[i] + max(dp[i - 2], dp[i - 3]);
  }
  for (int i = 1; i <= 1e5; i++) {
    sum = max(sum, dp[i]);
  }
  cout << sum;
  return 0;
}
