#include <bits/stdc++.h>
using namespace std;
long long DP[1000000];
long long counter[1000000];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    counter[x]++;
  }
  DP[0] = 0;
  DP[1] = counter[1];
  for (int i = 0; i < 1000000; i++) {
    DP[i] = max(DP[i - 1], DP[i - 2] + counter[i] * i);
  }
  cout << DP[1000000 - 1];
}
