#include <bits/stdc++.h>
using namespace std;
long long bucket[100005];
long long dp[100005];
int main() {
  int n;
  memset(bucket, 0, sizeof bucket);
  memset(dp, 0, sizeof dp);
  scanf("%d", &n);
  vector<int> A(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &A[i]);
    bucket[A[i]]++;
  }
  dp[0] = 0;
  dp[1] = bucket[1];
  for (long long i = 2; i < 100001; i++) {
    dp[i] = max(dp[i - 2] + bucket[i] * i, dp[i - 1]);
  }
  cout << dp[100000] << endl;
  return 0;
}
