#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
int a[N];
long long dp[N];
int max(int a, int b) { return a > b ? a : b; }
int main() {
  cin >> n;
  int idmx = 0;
  int idmi = N;
  memset(a, 0, sizeof(a));
  memset(dp, 0, sizeof(dp));
  for (int i = 0; i < n; i++) {
    int t;
    scanf("%d", &t);
    a[t]++;
    if (t > idmx) idmx = t;
    if (t < idmi) idmi = t;
  }
  if (idmi == 1) {
    dp[idmi] = (long long)a[1];
    idmi++;
  }
  for (int i = idmi; i <= idmx; i++)
    dp[i] = max(dp[i - 1], (long long)(dp[i - 2] + (long long)i * a[i]));
  cout << dp[idmx] << endl;
  return 0;
}
