#include <bits/stdc++.h>
using namespace std;
int n;
long long cnt[1000000];
long long ans1[1000000];
long long ans2[1000000];
int main() {
  ios_base::sync_with_stdio(false);
  memset(cnt, 0, sizeof(cnt));
  memset(ans1, 0, sizeof(ans1));
  memset(ans2, 0, sizeof(ans2));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    int a;
    cin >> a;
    cnt[a]++;
  }
  ans1[1] = cnt[1];
  ans2[1] = 0;
  ans1[2] = 2 * cnt[2];
  ans2[2] = cnt[1];
  for (int i = 3; i <= 100000; i++) {
    ans1[i] = cnt[i] * i + max(ans1[i - 2], ans2[i - 2]);
    ans2[i] = max(ans1[i - 1], ans2[i - 1]);
  }
  cout << max(ans1[100000], ans2[100000]);
  return 0;
}
