#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
long long int a[N], book[N], dp[N];
int main() {
  int n, mx = -1;
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    book[a[i]]++;
    mx = max((int)a[i], mx);
  }
  dp[1] = book[1];
  for (int i = 2; i <= mx; i++) {
    if (i >= 2)
      dp[i] = max(dp[i - 1], dp[i - 2] + book[i] * i);
    else
      dp[i] = dp[i - 1];
  }
  cout << dp[mx];
  return 0;
}
