#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
long long DP[N][2];
int n;
int a[N];
int freq[N];
long long solve(int num, bool state) {
  if (num < 1) return 0;
  if (DP[num][state] != -1) return DP[num][state];
  long long ans2 = 0;
  ans2 = solve(num - 2, 0);
  ans2 += 1ll * freq[num] * num;
  if (!state) {
    long long ans3 = solve(num - 1, 1);
    if (ans3 > ans2) ans2 = ans3;
  }
  DP[num][state] = ans2;
  return ans2;
}
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, 0));
}
