#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long DP[N];
int n;
int a[N];
int freq[N];
long long solve(int num) {
  if (num < 1) return 0;
  if (DP[num] != -1) return DP[num];
  return DP[num] =
             max((long long)num * freq[num] + solve(num - 2), solve(num - 1));
}
int main() {
  memset(DP, -1, sizeof DP);
  scanf("%d", &n);
  int mx = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", a + i);
    ++freq[a[i]];
    if (a[i] > mx) mx = a[i];
  }
  printf("%lld\n", solve(mx));
}
