#include <bits/stdc++.h>
using namespace std;
long long int num[110000];
long long int dp[110000][3];
int main() {
  int n;
  scanf("%d", &n);
  memset(num, 0, sizeof(num));
  memset(dp, 0, sizeof(dp));
  int maxn = -1;
  for (int i = 1; i <= n; i++) {
    int a;
    scanf("%I64d", &a);
    num[a]++;
    maxn = max(a, maxn);
  }
  for (int i = 1; i <= 110000; i++) {
    dp[i][1] = num[i] * i + dp[i - 1][0];
    dp[i][0] = max(dp[i - 1][1], dp[i - 1][0]);
  }
  printf("%I64d\n", max(dp[maxn][0], dp[maxn][1]));
  return 0;
}
