Alex doesn't like boredom. That's why whenever he gets bored, he comes up with games. One long winter evening he came up with a game and decided to play it.

Given a sequence a consisting of n integers. The player can make several steps. In a single step he can choose an element of the sequence (let's denote it a_{k}) and delete it, at that all elements equal to a_{k} + 1 and a_{k} - 1 also must be deleted from the sequence. That step brings a_{k} points to the player. 

Alex is a perfectionist, so he decided to get as many points as possible. Help him.


-----Input-----

The first line contains integer n (1 ≤ n ≤ 10^5) that shows how many numbers are in Alex's sequence. 

The second line contains n integers a_1, a_2, ..., a_{n} (1 ≤ a_{i} ≤ 10^5).


-----Output-----

Print a single integer — the maximum number of points that Alex can earn.


-----Examples-----
Input
2
1 2

Output
2

Input
3
1 2 3

Output
4

Input
9
1 2 1 3 2 2 2 2 3

Output
10



-----Note-----

Consider the third test example. At first step we need to choose any element equal to 2. After that step our sequence looks like this [2, 2, 2, 2]. Then we do 4 steps, on each step we choose any element equals to 2. In total we earn 10 points.

Difficulty: competition

Starter code:

Solutions:
"""
Codeforces Contest 260 Div 1 Problem A

Author  : chaotic_iak
Language: Python 3.3.4
"""

def main():
    n, = read()
    ar = read()
    a = [0] * 100001
    for i in ar: a[i] += 1

    dp = [0] * 100001
    dp[1] = a[1]
    for i in range(2, 100001):
        dp[i] = max(a[i] * i + dp[i-2], dp[i-1])
    print(dp[-1])

################################### NON-SOLUTION STUFF BELOW

def read(mode=2):
    # 0: String
    # 1: List of strings
    # 2: List of integers
    inputs = input().strip()
    if mode == 0: return inputs
    if mode == 1: return inputs.split()
    if mode == 2: return map(int, inputs.split())

def write(s="\n"):
    if isinstance(s, list): s = " ".join(map(str, s))
    s = str(s)
    print(s, end="")

main()

3

import sys

def compress(l):
    x = l[0]
    cnt = 1
    c = []
    for i in range(1, len(l)):
        if l[i] == x:
            cnt += 1
        else:
            c.append((x, cnt))
            x = l[i]
            cnt = 1
    c.append((x, cnt))
    return c

def __starting_point():
    n = int(sys.stdin.readline())
    a = [int(x) for x in sys.stdin.readline().split()]
    a.sort()
    a = compress(a)
    dp = [0, a[0][0] * a[0][1]]
    for i in range(1, len(a)):
        x, c = a[i]
        px = a[i-1][0]
        dp.append(max(dp[-1], x*c + (dp[-1] if x > px + 1 else dp[-2])))
    print(max(dp))

__starting_point()

n = int(input())
a = list(map(int, input().split()))
MAX = 100001
d = [0] * MAX
c = [0] * MAX
for i in a:
    c[i] +=1
d[1] = c[1]
for i in range(2, MAX):
    d[i] = max(d[i - 2] + i * c[i], d[i - 1])
print(d[-1])


n=int(input())
maxnum=100500
numbers=[0]*maxnum
points=[0]*maxnum
inputArray=list(map(int,input().split()))
for i in range(n):
    numbers[inputArray[i]]+=1
for i in range(maxnum):
    points[i]=numbers[i]*i

for i in range(maxnum-3,0,-1):
    points[i]=max(points[i+1], points[i]+points[i+2])

print (points[1])

N = 100005
x = [0] * N
input()
for i in map(int, input().split(' ')):
    x[i] += 1
for i in range(2, N):
    x[i] = max(x[i - 1], x[i] * i + x[i - 2])
print(x[N - 1])


N = 100005
x = [0] * N
input()
for i in map(int, input().split(' ')):
    x[i] += 1
for i in range(2, N):
    x[i] = max(x[i - 1], x[i] * i + x[i - 2])
print(x[N - 1])

import sys

def findmax2(nums, n):
    inter = {}
    inter[0] = 0
    inter[1] = nums.get(1, 0)
    for i in range(2, n + 1):
        inter[i] = max(inter[i-2] + nums.get(i, 0), inter[i-1])

    return inter[n]
    
count = int(sys.stdin.readline())
nums = list(map(int, sys.stdin.readline().split()))

pnums = {}



for n in nums:
    pnums[n] = pnums.get(n, 0) + n



print(findmax2(pnums, max(nums)))

N=100001
a=[0]*N
input()
for i in map(int,input().split(' ')):
    a[i]+=i
dp=[0]*N
for i in range(1,N):
    if i==1:
        dp[i]=a[i]
    else:
        dp[i]=max(dp[i-1],dp[i-2]+a[i])
print(dp[N-1])


n = int(input())
t = list(map(int, input().split()))
s = [0] * 100001
for i in t: s[i] += 1
a = b = 0
for i in range(100001): a, b = max(a, b), a + s[i] * i
print(max(a, b))

input()
s = [0] * 100002
for i in map(int, input().split()): s[i] += i
a = b = 0
for d in s: a, b = max(a, b), a + d
print(a)

import math
a=[0]*100005
dp=[0]*100005
x=int(input(""))
y=input("").split(' ')
y=[int(z) for z in y]
for g in range (len(y)):
    a[y[g]]+=1
for g in range (100000,0,-1):
    if (dp[g+1]>dp[g+2]+g*a[g]):
        dp[g]=dp[g+1]
    else:
        dp[g]=dp[g+2]+g*a[g]
print(dp[1])


from collections import Counter

n = int(input())
nums = list(map(int, input().split()))

num_counter = Counter(nums)
tab = [0, num_counter[1]]
for a in range(2, 100001):
    tab.append(max(
        tab[-1],
        tab[-2] + num_counter[a] * a
    ))
print(tab[100000])


a=[0 for i in range(100010)]
f=[0 for i in range(100010)]
ans=0
n=int(input())
L=input().split()
for i in range(n):
	a[int(L[i])]+=1
for i in range(1,100001):
	f[i]=f[i-2]+i*a[i]
	ans=max(ans,f[i])
	f[i]=max(f[i],f[i-1])
print(ans)
return


from collections import Counter


def main():
    n = int(input())
    a = Counter(list(map(int, input().split())))

    res = [0] * len(a)
    _i = 0
    for j, (i, cnt) in enumerate(sorted(list(a.items()), reverse=True)):
        if i == _i - 1:
            res[j] = max(res[j-1], res[j-2] + i * a[i])
        else:
            res[j] = res[j-1] + i * a[i]
        _i = i

    print(res[-1])


def __starting_point():
    main()


__starting_point()

aints = int(input())
nums = list(map(int, input().split(' ')))
compute = [0] * 100001
for i in nums:
    compute[i] += 1
    
answer = [0, compute[1]] + [-1] * (100000)

for i in range(2, 100001):
    answer[i] = max(compute[i]*i+answer[i-2], answer[i-1])
print(answer[-2])

n = int(input())
f = [0] * 100002
t = list(map(int, input().split()))
for i in t : 
    f[i] += i
a = 0
b = 0
for i in f: 
    tmp = a
    a = max(a, b)
    b = tmp + i
print(a)

def main():
    input()
    aa = list(map(int, input().split()))
    n = max(aa) + 1
    cnt = [0] * n
    for x in aa:
        cnt[x] += 1
    a, b = 0, cnt[1]
    for i in range(2, n):
        a, b = b, max(b, a + cnt[i] * i)
    print(b)

def __starting_point():
    main()
__starting_point()

def main():
    input()
    aa = list(map(int, input().split()))
    n = max(aa) + 1
    cnt = [0] * n
    for x in aa:
        cnt[x] += x
    a = b = 0
    for x in cnt:
        a, b = b, max(b, a + x)
    print(b)


def __starting_point():
    main()
__starting_point()

#input

n=int(input())

a=[int(x) for x in input().split()]



#variables

x=[0]*100001
dp=[0]


#main

for i in range(n):

	x[a[i]]+=1
dp.append(x[1])
for i in range(2,100001):
	dp.append(max(dp[-1],dp[-2]+x[i]*i))



#output
print(dp[-1])

n = int(input())
a = list(map(int, input().split()))

counts = [0] * 100001
mx = 0
for x in a:
	counts[x] += 1
	mx = max(x, mx)

f = [0, counts[1]]
for i in range(2, mx + 1):
	f.append(max(f[i - 1], i * counts[i] + f[i - 2]))
print(f[mx])


n = int(input())
counts = [0] * 100002
for a in map(int, input().split()):
	counts[a] += 1

f2, f1 = 0, counts[1] # f[i-2], f[i-1]
for i in range(2, 100002):
	f2, f1 = f1, max(f1, i * counts[i] + f2)
print(f1)


N=100005
lis=[0]*N
dp=[0]*N
input()
for i in map(int,input().split(' ')):
    lis[i]+=1
dp[1]=lis[1]
for i in range(2,N):
    dp[i]=max(dp[i-1],dp[i-2]+i*lis[i])
print(dp[N-1])



from collections import Counter

n = int(input())

sequence = list(map(int, input().split()))

numset = list(set(sequence))

k = len(numset)

numset.sort()

cnt = Counter(sequence)

f = [0] * (k + 1)

f[1] = cnt[numset[0]] * numset[0]
f[0] = 0

for i in range(2, k + 1):
    if numset[i - 1] - numset[i - 2] == 1:
        f[i] = max(f[i - 1], f[i - 2] + cnt[numset[i - 1]] * numset[i - 1])
    else:
        f[i] = numset[i - 1] * cnt[numset[i - 1]] + f[i - 1]

print(f[k])

'''
import timeit

s = """
k = list(set(a))
cnt = Counter(a)
print cnt
"""

setup = """
from random import randint
n = 100000
a = [randint(1,n) for i in range(n)]
from collections import Counter

"""


print(timeit.timeit(stmt=s, number=1, setup=setup))
'''

from collections import Counter

n = int(input())

sequence = list(map(int, input().split()))

numset = list(set(sequence))

k = len(numset)

numset.sort()

cnt = Counter(sequence)

f = [0] * (k + 1)

f[1] = cnt[numset[0]] * numset[0]
f[0] = 0

for i in range(2, k + 1):
    if numset[i - 1] - numset[i - 2] == 1:
        f[i] = max(f[i - 1], f[i - 2] + cnt[numset[i - 1]] * numset[i - 1])
    else:
        f[i] = numset[i - 1] * cnt[numset[i - 1]] + f[i - 1]

print(f[k])

'''
import timeit

s = """
k = list(set(a))
cnt = Counter(a)
print cnt
"""

setup = """
from random import randint
n = 100000
a = [randint(1,n) for i in range(n)]
from collections import Counter

"""


print(timeit.timeit(stmt=s, number=1, setup=setup))
'''

import sys

k = [0] * 100001
n = int(sys.stdin.readline())
st = [int(x) for x in (sys.stdin.readline()).split()]

for i in st:
    k[i] += 1
    
x = 0
y = 0

j = 100000
while(j > 0):
    if(j % 2 != 0):
        x = max(x + k[j] * j, y)
    else:
        y = max(y + k[j] * j, x)
    j -= 1
        
print(max(x, y))