#include <bits/stdc++.h>
typedef long long LL;
using namespace std;
const int M = 1000000007;
const int N = 100001;
LL cnt[N];
LL dp[N];
LL ma[N];
int main() {
  ios_base::sync_with_stdio(0);
  cout.precision(15);
  cout.setf(ios::fixed);
  LL n, i, j, m;
  cin >> n;
  for (i = 0; i < N; i++) {
    dp[i] = 0;
    ma[i] = 0;
  }
  for (i = 0; i < n; i++) {
    cin >> m;
    cnt[m] += m;
  }
  dp[0] = 0;
  ma[0] = 0;
  dp[1] = cnt[1];
  ma[1] = cnt[1];
  for (i = 2; i < N; i++) {
    dp[i] = ma[i - 2] + cnt[i];
    ma[i] = max(ma[i - 1], dp[i]);
  }
  cout << ma[N - 1] << '\n';
}
