#include <bits/stdc++.h>
using namespace std;
bool Check(int N, int pos) { return (bool)(N & (1 << pos)); }
int Set(int N, int pos) { return N = N | (1 << pos); }
int fx[] = {+0, +0, +1, -1, -1, +1, -1, +1};
int fy[] = {-1, +1, +0, +0, +1, +1, -1, -1};
int hr[] = {-2, -2, -1, +1, +2, +2, -1, +1};
int hc[] = {+1, -1, +2, +2, -1, +1, -2, -2};
int dx[] = {+1, -1, +0, +0};
int dy[] = {+0, +0, +1, -1};
const int MAXN = (int)1e5 + 9;
long long frq[MAXN], dp[MAXN][2];
int main() {
  long long i, j, k, l, m, n, p, q, x, y, u, v, r, tc, t;
  cin >> n;
  for (int i = 1; i <= (int)n; i++) {
    cin >> m;
    frq[m]++;
  }
  dp[0][0] = dp[0][1] = 0;
  for (int i = 1; i <= (int)MAXN - 1; i++) {
    dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
    dp[i][1] = dp[i - 1][0] + frq[i] * i;
  }
  cout << max(dp[MAXN - 1][0], dp[MAXN - 1][1]) << endl;
  return 0;
}
