#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long arr[N];
long long dp[N];
long long solve(int x) {
  if (x > 1e5) return 0;
  if (dp[x] != -1) return dp[x];
  long long ans = -1;
  if (arr[x]) ans = solve(x + 2) + arr[x] * x;
  return dp[x] = max(ans, solve(x + 1));
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  memset(dp, -1, sizeof dp);
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    arr[x]++;
  }
  cout << solve(1);
  return 0;
}
