#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const long long int MOD = 1e9 + 7;
const long long int N_MAX = 100100;
void solve() {
  long long int n;
  cin >> n;
  long long int a[n];
  long long int count[N_MAX];
  long long int maxi = -1;
  memset(count, 0, sizeof(count));
  for (long long int i = 0; i < (n); ++i) {
    cin >> a[i];
    count[a[i]]++;
    if (a[i] > maxi) maxi = a[i];
  }
  long long int dp[maxi + 1];
  memset(dp, 0, sizeof(dp));
  for (long long int i = 0; i < (maxi + 1); ++i) {
    if (i == 0)
      dp[i] = 0;
    else if (i == 1)
      dp[i] = count[i] * i;
    else
      dp[i] = max(dp[i - 1], dp[i - 2] + count[i] * i);
  }
  cout << dp[maxi] << endl;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int test = 1;
  while (test--) {
    solve();
  }
  return 0;
}
