#include <bits/stdc++.h>
using namespace std;
int n, a[100005] = {0}, b[100005] = {0};
long long f[100005] = {0}, ans = 0;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[a[i]]++;
  }
  f[1] = b[1];
  f[2] = b[2] * 2;
  ans = max(f[1], f[2]);
  for (int i = 3; i <= 100000; i++) {
    f[i] = max(f[i - 2], f[i - 3]) + 1LL * b[i] * i;
    ans = max(ans, f[i]);
  }
  cout << ans << endl;
  return 0;
}
