#include <bits/stdc++.h>
using namespace std;
void sprint(string s) {
  for (int i = 0; i < (int)s.size(); ++i) printf("%c", s[i]);
  printf("\n");
}
long long a[100010], dp[100010];
int main() {
  int n;
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  dp[2] = a[1];
  for (int i = 3; i < 100004; ++i) {
    dp[i] = max(dp[i - 3], dp[i - 2]) + a[i - 1] * ((long long)(i - 1));
  }
  cout << max(dp[100001], dp[100000]) << endl;
  return 0;
}
