//C++新手最易上手的方法 一看就懂!
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, m;cin >> n;m = n;
ll dp1, dp2;set<int>ad;
map<int, int>cnt;
while (n--) {
int x;cin >> x;
ad.insert(x);
cnt[x]++;
}
vector<int>a(ad.begin(), ad.end());
dp2 = a[0] * cnt[a[0]];dp1 = 0;
int k = a.size();
for (int i = 1; i < k; i++) {
if (a[i] == a[i - 1] + 1) {
ll li = dp2;
dp2 = max(dp1 + a[i] * cnt[a[i]], dp2);
dp1 = li;
} else {
dp1 = dp2;
dp2 += a[i] * cnt[a[i]];
}
}
cout << dp2;
}

京公网安备 11010502036488号