#include <bits/stdc++.h>
using namespace std;
int n;
int arr[100011] = {0};
long long int dp[100011];
int cnt[100011] = {0};
int main() {
  cin >> n;
  set<int> st;
  vector<int> a;
  memset(cnt, 0, sizeof(cnt));
  for (int i = 1; i <= n; i++) {
    cin >> arr[i];
  }
  sort(arr + 1, arr + n + 1);
  for (int i = 0; i < n; i++) {
    cnt[arr[i + 1]]++;
  }
  dp[0] = 0;
  dp[1] = cnt[1] * 1;
  for (long long int i = 2; i <= 100000; i++) {
    dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i);
  }
  cout << dp[100000];
}
