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