#include <bits/stdc++.h>
using namespace std;
int T;
int N, M;
long long freq[100005];
long long memo[100005];
long long dp(int pos) {
  if (pos >= 100001) return 0;
  if (memo[pos] != -1) return memo[pos];
  long long optimal = max(dp(pos + 1), dp(pos + 2) + freq[pos] * pos);
  memo[pos] = optimal;
  return optimal;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  memset(freq, 0, sizeof(freq));
  cin >> N;
  for (int i = (int)0; i <= (int)N - 1; i++) {
    int v;
    cin >> v;
    freq[v]++;
  }
  memset(memo, -1, sizeof(memo));
  for (int i = (int)100000; i >= (int)1; i--) {
    dp(i);
  }
  cout << dp(1) << endl;
  return 0;
}
