#include <bits/stdc++.h>
using namespace std;
int cnt[100005] = {0};
long long a[100005] = {0};
int main() {
  int n;
  cin >> n;
  int z;
  for (int i = 1; i <= n; i++) {
    cin >> z;
    cnt[z]++;
  }
  a[0] = 0, a[1] = cnt[1];
  for (int i = 2; i <= 100002; i++) {
    a[i] = max(a[i - 1], a[i - 2] + 1ll * i * cnt[i]);
  }
  cout << a[100002];
}
