#include <bits/stdc++.h>

typedef long long ll;
using namespace std;

int deleteAndEarn(vector<int> &nums)
{
    int sum = 0;
    map<int, int> quantity;
    for (int n : nums)
    {
        sum += n;
        quantity[n]++;
    }

    int maxSum = INT_MIN;
    for (const auto &pair : quantity)
    {
        int currentSum = sum, n = pair.first;
        if (quantity.count(n - 1))
            currentSum -= quantity[n - 1] * (n - 1);
        if (quantity.count(n + 1))
            currentSum -= quantity[n + 1] * (n + 1);
        maxSum = max(maxSum, currentSum);
    }
    return maxSum;
}
int main()
{
    int n;
    cin >> n;
    vector<int> nums(n);
    for (int i = 0; i < n; i++)
        cin >> nums[i];
    cout << deleteAndEarn(nums) << endl;
    return 0;
}