#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f, MOD = 1e9 + 7;
int main() {
  int n;
  cin >> n;
  long long int a[100005];
  memset(a, 0, sizeof(a));
  int max_num = 0;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    a[x]++;
    max_num = max(max_num, x);
  }
  long long int dp[100005];
  dp[0] = 0;
  dp[1] = a[1];
  for (int i = 2; i <= max_num; i++) {
    dp[i] = max(a[i] * i + dp[i - 2], dp[i - 1]);
  }
  cout << dp[max_num] << '\n';
  return 0;
}
