#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int GCD(int x, int y) {
  if (x % y == 0)
    return y;
  else
    return (GCD(y, x % y));
}
long long int cnt[100005];
long long int dp[100005];
long long int solve(long long int val) {
  if (val < 0) return 0LL;
  if (dp[val] != -1) return dp[val];
  long long int ret, i, j;
  ret = val * cnt[val] + solve(val - 2);
  ret = max(ret, solve(val - 1));
  return dp[val] = ret;
}
int main() {
  long long int n, i, j, x, y = 0;
  memset(dp, -1, sizeof dp);
  scanf("%I64d", &n);
  for (i = 0; i < n; i++) {
    scanf("%I64d", &x);
    cnt[x]++;
    y = max(y, x);
  }
  long long int ans = solve(y);
  printf("%I64d\n", ans);
  return 0;
}
