#include <bits/stdc++.h>
using namespace std;
long long dp[100010][2], s[100010];
long long fmax(long long a, long long b) {
  if (a > b)
    return a;
  else
    return b;
}
int main() {
  int n, m = 0, num[100010];
  memset(s, 0, sizeof(s));
  scanf("%d", &n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &num[i]);
    s[num[i]] += num[i];
    if (m < num[i]) m = num[i];
  }
  dp[1][0] = 0;
  dp[1][1] = s[1];
  for (int i = 2; i <= m; i++) {
    dp[i][0] = fmax(dp[i - 1][1], dp[i - 1][0]);
    dp[i][1] = dp[i - 1][0] + s[i];
  }
  printf("%I64d\n", fmax(dp[m][0], dp[m][1]));
}
