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