#include <bits/stdc++.h>
using namespace std;
inline long long re() {
  long long x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + (ch ^ 48);
    ch = getchar();
  }
  return x * f;
}
long long a[100100];
long long dp[100100];
long long dfs(int p) {
  if (p > 100000) return 0;
  long long maxx = 0;
  if (dp[p] != -1) return dp[p];
  maxx = max(maxx, dfs(p + 2) + p * a[p]);
  maxx = max(maxx, dfs(p + 3) + p * a[p]);
  return dp[p] = maxx;
}
int main() {
  int n;
  memset(dp, -1, sizeof(dp));
  cin >> n;
  for (int i = 1; i <= n; i++) {
    long long x;
    x = re();
    a[x]++;
  }
  long long maxx = 0;
  maxx = max(dfs(1), dfs(2));
  cout << maxx << endl;
}
