#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int a[N];
long long dp[N];
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    a[x]++;
  }
  long long ans = 0;
  dp[N - 1] = dp[N - 2] = 0;
  for (int i = N - 3; i >= 1; --i) {
    dp[i] = max(dp[i + 1], dp[i + 2] + 1LL * a[i] * i);
    ans = max(ans, dp[i]);
  }
  cout << ans << endl;
  return 0;
}
