//codeforces.com/problemset/problem/455/A 
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;
/*
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class T> using ordered_set =tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
// ordered_set.find_by_order(k) returns the iterator to kth element
// ordered_set.order_of_key(k) returns the number of elements strictly less than k 

(FOR ORDERED MULTISET "UPPER_BOUND" AND "LOWER_BOUND" ARE REVERSED)
template<class T> using ordered_multiset =tree<T, null_type, less_equal<T>, rb_tree_tag,tree_order_statistics_node_update>;
// ordered_set.find_by_order(k) returns the iterator to kth element
// ordered_set.order_of_key(k) returns the number of elements strictly less than k 
*/
#ifdef LOCALIO
    #define dbg(...) cerr<< __VA_ARGS__;
    #define dbgl(...) cerr<< __VA_ARGS__<<nl;
#else
    #define dbg(...) ;
    #define dbgl(...) ;
#endif
#define fastio ios_base::sync_with_stdio(0); cin.tie(0);
#define all(x) x.begin(),x.end()
#define nl '\n'
#define mp(x,y) make_pair(x,y)
#define ff first
#define ss second
#define pb(x) push_back(x)
#define sz(x) (int)x.size()
#define szl(x) (long long)x.size()

// const int mod = 998244353;
const int mod = 1e9+7;



void solve()
{
    int n; cin>>n;
    int arr[n]; for(auto &i:arr) cin>>i;

    int freq[100001] = {0};

    for(auto i:arr) freq[i]++;

    ll dp[100001][2];

    dp[1][0] = 0;
    dp[1][1] = freq[1];

    for(int i=2; i<=100000; ++i)
    {
        dp[i][1] = dp[i-1][0] + 1LL*i*freq[i];

        dp[i][0] = max(dp[i-1][1],dp[i-1][0]);
    }

    cout<<max(dp[100000][1],dp[100000][0])<<nl;

}

signed main() {
    fastio;
    #ifdef LOCALIO
        freopen("error.txt", "w", stderr);
    #endif
    int t=1;
    // cin>>t;
    while(t--)
    {
        solve();
    }
}