#include <bits/stdc++.h>
using namespace std;
long long int a, number[100001], answer[100001], m;
int n;
int main() {
  cin >> n;
  for (int q = 0; q < n; q++) {
    cin >> a;
    number[a]++;
    if (a >= m) m = a;
  }
  answer[1] = number[1];
  for (int w = 1; w <= m; w++) {
    answer[w] = max(answer[w - 1], w * number[w] + answer[w - 2]);
  }
  cout << answer[m];
}
