#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int n;
  cin >> n;
  map<int, long long> mp;
  int x;
  for (int i = 0; i < n; i++) {
    cin >> x;
    mp[x]++;
  }
  if (mp.size() == 1) {
    cout << (long long)(x) * (long long)(mp[x]);
    return 0;
  } else {
    int size = mp.size();
    long long dp[size][2];
    int arr[size], j = 0;
    for (auto i : mp) {
      arr[j] = i.first;
      j++;
    }
    dp[0][0] = 0;
    dp[0][1] = arr[0] * mp[arr[0]];
    for (int i = 1; i < size; i++) {
      dp[i][0] = max(dp[i - 1][0], dp[i - 1][1]);
      dp[i][1] = mp[arr[i]] * arr[i];
      if (arr[i - 1] == arr[i] - 1)
        dp[i][1] += dp[i - 1][0];
      else
        dp[i][1] += max(dp[i - 1][0], dp[i - 1][1]);
    }
    cout << max(dp[size - 1][0], dp[size - 1][1]);
  }
}
