#include <bits/stdc++.h>
using namespace std;
const int M = 100005;
long long dp[M], a[M];
int main() {
  int n, i, x;
  while (~scanf("%d", &n)) {
    memset(dp, 0, sizeof(dp));
    memset(a, 0, sizeof(a));
    for (i = 0; i < n; i++) {
      scanf("%d", &x);
      a[x]++;
    }
    dp[1] = a[1];
    dp[2] = max(a[1], a[2] * 2);
    for (i = 3; i <= 100000; i++) {
      dp[i] = dp[i - 2] + a[i] * i;
      if (dp[i - 1] > dp[i]) dp[i] = dp[i - 1];
    }
    printf("%I64d\n", dp[100000]);
  }
  return 0;
}
