#include <bits/stdc++.h>
using namespace std;
int abs(int x) {
  if (x < 0) return -x;
  return x;
}
int addmod(int v1, int v2) {
  int v3 = v1 + v2;
  if (v3 >= 1000000007) v3 -= 1000000007;
  return v3;
}
int cc[100];
long long dp[100005][2];
vector<pair<int, int> > v;
long long solve(int pos, bool flag) {
  if (pos == v.size()) return 0;
  if (dp[pos][flag] != -1) return dp[pos][flag];
  long long ans = 0;
  ans = solve(pos + 1, 0);
  if (flag) {
    if (v[pos - 1].first - 1 != v[pos].first) {
      ans =
          max((long long)v[pos].second * v[pos].first + solve(pos + 1, 1), ans);
    }
  } else {
    ans = max((long long)v[pos].second * v[pos].first + solve(pos + 1, 1), ans);
  }
  return dp[pos][flag] = ans;
}
int main() {
  int n;
  scanf("%d", &n);
  int a[n];
  for (int i = (0); i < (n); i++) {
    scanf("%d", &a[i]);
  }
  sort(a, a + n);
  int last = a[n - 1];
  int c = 1;
  for (int i = (n - 1) - 1; i >= (0); --i) {
    if (a[i] == last)
      c++;
    else {
      v.push_back(pair<int, int>(last, c));
      c = 1;
      last = a[i];
    }
  }
  v.push_back(pair<int, int>(last, c));
  long long ans = 0;
  memset(dp, -1, sizeof(dp));
  cout << (solve(0, 0)), cout << (endl);
  return 0;
}
