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: MEDIUM
Tags: Dynamic programming
Skill types: Dynamic programming

Starter code:

Solutions:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = list()
cur = a[0]
k = 1
for i in range(1, n):
	if a[i - 1] == a[i]:
		k += 1
	else:
		b.append((cur, k))
		cur = a[i]
		k = 1
b.append((cur, k))
n1 = len(b)
dp = [0] * n1
dp[0] = b[0][0] * b[0][1]
maxx = b[0][0] * b[0][1]
for i in range(1, n1):
	if b[i - 1][0] + 1 == b[i][0]:
		if i != 1:
			dp[i] = max(b[i][0] * b[i][1] + dp[i - 2], dp[i - 1])
		else:
			dp[i] = max(b[i][0] * b[i][1], dp[i - 1])
	else:
		dp[i] = dp[i - 1] + b[i][0] * b[i][1]
print(max(dp))


from typing import Counter
n = int(input())
l = list(map(int, input().split()))

def solve(l):
	c = Counter(l)
	points = [0] * (max(l) + 1)
	for i in sorted(list(set(l))):
		points[i] = i * c[i]

	def robber(points):
		if not points:
			return 0
		if len(points) == 1:
			return points[0]
		if len(points) == 2:
			return max(points[0], points[1])
		n = len(points)
		dp = [0] * n
		dp[0] = points[0]
		dp[1] = max(points[0], points[1])
		for i in range(2, len(points)):
			dp[i] = max(dp[i - 1], points[i] + dp[i - 2])
		return dp[-1]
	return robber(points)
print(solve(l))


t = 1
while t > 0:
	t -= 1
	n = int(input())
	l = list(map(int, input().split()))
	a = [0] * 100005
	ans = [0] * 100005
	for i in l:
		a[i] += 1
	ans[0] = 0
	ans[1] = a[1]
	for i in range(2, 100001):
		ans[i] = max(ans[i - 1], ans[i - 2] + i * a[i])
	print(ans[100000])


n = int(input())
line = str(input()).split()
line = [int(it) for it in line]
line.sort()
link = dict()
count = 1
pp = line[0]
for i in range(1, 100000 + 1):
	link.update({i: 0})
for i in range(1, n):
	if pp == line[i]:
		count += 1
	else:
		link.update({pp: count})
		pp = line[i]
		count = 1
link.update({pp: count})
dp = [0] * (100000 + 1)
dp[1] = link[1]
for i in range(2, 100000 + 1):
	dp[i] = max(dp[i - 2] + i * link[i], dp[i - 1])
print(dp[100000])


input()
a = sorted([int(a_i) for a_i in input().split()])
n = len(a)
count = {}
for number in a:
	if number not in count:
		count[number] = 1
	else:
		count[number] += 1
c_list = list(count.items())
f = []
for (i, (first, second)) in enumerate(c_list):
	pr = i - 1
	while pr >= 0 and c_list[pr][0] + 1 == c_list[i][0]:
		pr -= 1
	if pr == -1:
		f.append(c_list[i][0] * c_list[i][1])
	else:
		f.append(c_list[i][0] * c_list[i][1] + f[pr])
	if i != 0:
		f[i] = max(f[i], f[i - 1])
print(f[-1])


from collections import Counter
answer = {0: 0}
n = int(input())
count = Counter(list(map(int, input().split())))
for i in range(1, 100001):
	if not count.get(i):
		count[i] = 0
	answer[i] = 0
answer[1] = count[1]
for (k, v) in sorted(list(count.items()))[1:]:
	answer[k] = max([answer[k - 1], answer[k - 2] + k * v])
print(answer[100000])


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])


n = int(input())
l = 100002
nums = [int(i) for i in input().split()]
sums = [0 for i in range(l)]
res = [0 for i in range(l)]
for e in nums:
	sums[e] += e
res[1] = sums[1]
res[2] = sums[2]
if res[2] < res[1]:
	res[2] = res[1]
for i in range(3, l):
	res[i] = sums[i] + res[i - 2]
	if res[i] < res[i - 1]:
		res[i] = res[i - 1]
print(max(res))


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])


from collections import Counter
in_n = input()
in_nums = input()
n = int(in_n)
nums_counter = Counter([int(x) for x in in_nums.split()])

def getMaxScore(keys):
	saved = [0]
	cur_key_chain = []
	last_num = None
	for key in keys:
		cur_key_chain.append(key)
		if last_num is not None and last_num + 1 == key:
			saved.append(max(key * nums_counter[key] + saved[len(saved) - 2], saved[len(saved) - 1]))
		else:
			saved.append(key * nums_counter[key] + saved[len(saved) - 1])
		last_num = key
	return saved[len(saved) - 1]
print(getMaxScore(sorted(list(nums_counter.keys()))))


def rr():
	return input().rstrip()

def rri():
	return int(rr())

def rrl():
	return list(map(int, rr().split()))

def rrt():
	return tuple(map(int, rr().split()))
from collections import defaultdict

def mus(d=0):
	return defaultdict(defaultdict(d))

def ms(x, y, d=0):
	return [[0] * y for i in range(x)]

def ar(x, d=0):
	return [d] * x

def ppm(m, n=0, x=0, y=0):
	print('\n'.join(('\t'.join((str(m[j][i]) for j in range(y or n))) for i in range(x or n))))

def ppa(a, n):
	print('\t'.join(map(str, a[0:n])))

def ppl(a=0, x=[1]):
	x[0] = a or x[0] + 1
	print('-' + '- -' * 14 + '-# ' + str(x[0] - 2) + ' #-' + '- -' * 14 + '-')

def yn(x):
	return 'YES' if x else 'NO'
from itertools import accumulate
from itertools import groupby

def grp(x):
	return ((i, sum((1 for _ in g))) for (i, g) in groupby(x))
import math

def rnar():
	return (*rrl(), rrl())

def read():
	return rnar()

def solve(n, arr):
	arr.sort()
	x = list(grp(arr))
	am = ar(10 ** 5 + 1)
	for (i, num) in x:
		am[i] = num
	dp = ar(10 ** 5 + 1)
	dp[0] = 0
	dp[1] = am[1]
	for i in range(2, 10 ** 5 + 1):
		dp[i] = max(dp[i - 1], dp[i - 2] + am[i] * i)
	ans = dp[-1]
	return ans
test_count = 1
for _ in range(test_count):
	input_data = read()
	result = solve(*input_data)
	print(result)


def func(nums):
	if nums == []:
		return 0
	arr = [0 for i in range(100001)]
	dp = [0 for i in range(100001)]
	for i in nums:
		arr[i] += 1
	ans = 0
	if arr[1] != 0:
		dp[1] = arr[1]
		ans = arr[1]
	for i in range(2, max(nums) + 1):
		if arr[i] != 0:
			if arr[i - 1] == 0:
				dp[i] = max(dp[i - 1], dp[i - 2]) + arr[i] * i
			else:
				dp[i] = max(dp[i - 1], arr[i] * i + dp[i - 2])
		else:
			dp[i] = dp[i - 1]
		ans = max(dp[i], ans)
	return ans
n = int(input())
nums = [int(i) for i in input().split()]
print(func(nums))


n = int(input())
ns = input().split()
for i in range(len(ns)):
	ns[i] = int(ns[i])
n = max(ns)
cnt = [0] * (n + 1)
for i in range(len(ns)):
	cnt[ns[i]] = cnt[ns[i]] + 1
f = [0] * (n + 1)
f[1] = cnt[1]
for i in range(2, n + 1):
	f[i] = max([f[i - 1], f[i - 2] + cnt[i] * i])
print(f[n])


n = int(input().strip())
l = [0] * 100002
for x in input().split():
	l[int(x)] += int(x)
max = l[1]
for i in range(2, len(l)):
	if l[i - 2] + l[i] > max:
		max = l[i - 2] + l[i]
	l[i] = max
print(max)


import sys
from math import *
import threading
from heapq import *
from itertools import count
from pprint import pprint
from collections import defaultdict
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(300000)
mod = 10 ** 9 + 7
inf = 10 ** 15
decision = ['NO', 'YES']
yes = 'YES'
no = 'NO'
import os
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def npr(n, r):
	return factorial(n) % mod // (factorial(n - r) % mod) if n >= r else 0

def ncr(n, r):
	return factorial(n) % mod // (factorial(r) % mod * (factorial(n - r) % mod)) if n >= r else 0

def lower_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] >= num:
			answer = middle
			end = middle - 1
		else:
			start = middle + 1
	return answer

def upper_bound(li, num):
	answer = -1
	start = 0
	end = len(li) - 1
	while start <= end:
		middle = (end + start) // 2
		if li[middle] <= num:
			answer = middle
			start = middle + 1
		else:
			end = middle - 1
	return answer

def abs(x):
	return x if x >= 0 else -x

def binary_search(li, val):
	ans = -1
	lb = 0
	ub = len(li) - 1
	while lb <= ub:
		mid = (lb + ub) // 2
		if li[mid] > val:
			ub = mid - 1
		elif val > li[mid]:
			lb = mid + 1
		else:
			ans = mid
			break
	return ans

def kadane(x):
	sum_so_far = 0
	current_sum = 0
	for i in x:
		current_sum += i
		if current_sum < 0:
			current_sum = 0
		else:
			sum_so_far = max(sum_so_far, current_sum)
	return sum_so_far

def pref(li):
	pref_sum = [0]
	for i in li:
		pref_sum.append(pref_sum[-1] + i)
	return pref_sum

def SieveOfEratosthenes(n):
	prime = [{1, i} for i in range(n + 1)]
	p = 2
	while p <= n:
		for i in range(p * 2, n + 1, p):
			prime[i].add(p)
		p += 1
	return prime

def primefactors(n):
	factors = []
	while n % 2 == 0:
		factors.append(2)
		n //= 2
	for i in range(3, int(sqrt(n)) + 1, 2):
		while n % i == 0:
			factors.append(i)
			n //= i
	if n > 2:
		factors.append(n)
	return factors

def prod(li):
	ans = 1
	for i in li:
		ans *= i
	return ans

def sumk(a, b):
	print('called for', a, b)
	ans = a * (a + 1) // 2
	ans -= b * (b + 1) // 2
	return ans

def sumi(n):
	ans = 0
	if len(n) > 1:
		for x in n:
			ans += int(x)
		return ans
	else:
		return int(n)

def checkwin(x, a):
	if a[0][0] == a[1][1] == a[2][2] == x:
		return 1
	if a[0][2] == a[1][1] == a[2][0] == x:
		return 1
	if len(set(a[0])) == 1 and a[0][0] == x or (len(set(a[1])) == 1 and a[1][0] == x) or (len(set(a[2])) == 1 and a[2][0] == x):
		return 1
	if len(set(a[0][:])) == 1 and a[0][0] == x or (len(set(a[1][:])) == 1 and a[0][1] == x) or (len(set(a[2][:])) == 1 and a[0][0] == x):
		return 1
	return 0
karmanya = 1
while karmanya != 0:
	karmanya -= 1
	n = int(input())
	a = list(map(int, input().split()))
	cnt = defaultdict(int)
	for i in a:
		cnt[i] += 1
	n = max(a) + 5
	dp = [0] * n
	for i in range(n - 3, -1, -1):
		dp[i] = max(cnt[i] * i + dp[i + 2], dp[i + 1])
	print(dp[0])


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


n = int(input())
a = list(map(lambda x: int(x), input().split()))
cont = [0 for i in range(100001)]
dp = [0 for i in range(100001)]
for num in a:
	cont[num] += 1
dp[0] = 0
dp[1] = cont[1]
for i in range(2, 100001):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * cont[i])
print(dp[100000])


n = int(input())
a = [int(x) for x in input().split()]
d = {}
maxi = max(a)
for num in a:
	d[num] = d.get(num, 0) + 1
r = [0] * (maxi + 1)
r[0] = 0
r[1] = d.get(1, 0)
for i in range(2, maxi + 1):
	r[i] = max(r[i - 1], r[i - 2] + d.get(i, 0) * i)
print(r[maxi])


n = int(input())
a = [0] * 1000000
x = t = 0
for i in map(int, input().split()):
	a[i] += i
for j in a:
	(x, t) = (max(x, j + t), x)
print(x)


input()
a = [0] * 100001
for i in map(int, input().split()):
	x = int(i)
	a[x] += x
m = n = 0
for i in a:
	(m, n) = (n, max(i + m, n))
print(n)


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)


a = []
b = []
f = []
n = input()
s = input().split()
a = list(s)
for i in range(len(a)):
	a[i] = int(a[i])
for i in range(0, int(max(a)) + 2):
	b.append(0)
	f.append(0)
for i in range(len(a)):
	b[int(a[i])] += 1
for i in range(len(b)):
	b[i] = i * b[i]
f[1] = b[1]
for i in range(2, len(b) - 1):
	f[i] = max(f[i - 2] + b[i], f[i - 1])
print(f[-2])


from collections import Counter as C
n = int(input())
l = [*map(int, input().split())]
c = [(0, 0)] + sorted(C(l).items())
dp = {}
for i in range(1, len(c)):
	dp[i] = max(dp.get(i - 1, 0) + (0 if c[i - 1][0] + 1 == c[i][0] else c[i][0] * c[i][1]), dp.get(i - 2, 0) + c[i][1] * c[i][0])
print(dp[len(c) - 1])


n = int(input())
a = [int(i) for i in input().split()]
numcount = dp = [0] * (max(a) + 1)
for i in a:
	numcount[i] += 1
dp[1] = numcount[1]
for j in range(2, max(a) + 1):
	dp[j] = max(dp[j - 1], dp[j - 2] + numcount[j] * j)
print(max(dp))


n = int(input())
MAXN = 101101
a = [0] * MAXN
b = [0] * MAXN
a = list(map(int, input().split()))
for i in range(n):
	b[a[i]] += 1
for i in range(MAXN):
	b[i] = b[i] * i
for i in range(MAXN - 3, 0, -1):
	b[i] = max(b[i + 1], b[i] + b[i + 2])
print(b[1])


n = int(input())
a = list(map(int, input().split()))
a.sort()
N = 100001
b = [0] * (n + 3)
c = [0] * (n + 3)
l = 2
i = 0
while i < n:
	d = 0
	j = i
	while j < n and a[i] == a[j]:
		d += a[j]
		j += 1
	b[l] = a[i]
	if abs(b[l] - b[l - 1]) > 1:
		c[l] = d + c[l - 1]
	else:
		c[l] = max(c[l - 1], c[l - 2] + d)
	l += 1
	i = j
print(c[l - 1])


n = int(input())
c = [0 for i in range(100001)]
for m in map(int, input().split()):
	c[m] += 1
dp = [0 for i in range(100001)]
for i in range(1, 100001):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * c[i])
print(dp[100000])


n = int(input())
I = [int(x) for x in input().split()]
I.sort()
O = []
i = 0
j = 0
start = True
while i < n:
	while I[i] == I[j]:
		i += 1
		if i == n:
			break
	if start:
		O.append(I[j] * (i - j))
		start = False
	elif I[j] - I[j - 1] > 1:
		O.append(O[len(O) - 1] + I[j] * (i - j))
	elif len(O) < 2:
		O.append(max(I[j] * (i - j), O[len(O) - 1]))
	else:
		O.append(max(O[len(O) - 2] + I[j] * (i - j), O[len(O) - 1]))
	j = i
print(O[len(O) - 1])


import sys
import math
import collections
import bisect
from collections import deque as queue

def get_ints():
	return map(int, sys.stdin.readline().strip().split())

def get_list():
	return list(map(int, sys.stdin.readline().strip().split()))

def get_string():
	return sys.stdin.readline().strip()
for t in range(1):
	n = int(input())
	arr = get_list()
	counter = collections.Counter(arr)
	ans = [0]
	if 1 in counter:
		ans.append(counter[1])
	else:
		ans.append(0)
	for i in range(2, 10 ** 5 + 1):
		val = 0
		if i in counter:
			val = i * counter[i]
		to_ap = max(ans[i - 1], ans[i - 2] + val)
		ans.append(to_ap)
	print(ans[-1])


n = int(input())
data = list(map(int, input().split()))
M = max(data)
count = [0] * (M + 1)
for i in data:
	count[i] += 1
dp = [0] * (M + 1)
dp[1] = count[1]
for i in range(2, M + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + count[i] * i)
print(dp[M])


from functools import lru_cache
from sys import stdin, stdout
import sys
from math import *
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
dp = [0] * 100001
for i in range(n):
	dp[ar[i]] += 1
dp[2] = dp[2] * 2
for i in range(3, len(dp)):
	if i - 2 == 1:
		dp[i] = dp[i - 2] + i * dp[i]
	else:
		dp[i] = max(dp[i - 2], dp[i - 3]) + dp[i] * i
print(max(dp))


from collections import Counter
n = int(input())
arr = list(map(int, input().split()))
m = Counter(arr)
dp = [0 for i in range(10 ** 5 + 1)]
dp[0] = 0
dp[1] = m[1]
for i in range(2, 10 ** 5 + 1):
	dp[i] = max(dp[i - 2] + i * m[i], dp[i - 1])
print(dp[10 ** 5])


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


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


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()


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))


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])


input()
v = [0] * 2 ** 17
for i in input().split():
	v[int(i)] += 1
for i in range(2, 2 ** 17):
	v[i] = max(v[i - 1], v[i - 2] + v[i] * i)
print(v[-1])


n = int(input())
a = [int(x) for x in input().split()]
l = [0] * (10 ** 5 + 1)
ma = 0
for i in a:
	l[i] += 1
	ma = max(ma, i)
f = [0] * (ma + 1)
f[0] = 0
f[1] = l[1]
for i in range(2, ma + 1):
	f[i] = max(f[i - 1], f[i - 2] + l[i] * i)
print(f[ma])


n = int(input())
lst = [int(i) for i in input().split()]
ti = [0] * 100002
for k in lst:
	ti[k] += k
a = 0
b = 0
for k in ti:
	(a, b) = (max(a, b), a + k)
print(a)


n = int(input())
a = [int(i) for i in input().split()]
c = dict()
s = 0
for i in a:
	c[i] = c.get(i, 0) + i
for i in range(2, max(a) + 1):
	c[i] = max(c.get(i - 1, 0), c.get(i - 2, 0) + c.get(i, 0))
print(c[max(a)])


n = int(input())
l = list(map(int, input().split()))
m = max(l)
dp = [-1] * (m + 1)
dp[0] = 0
count = [0] * (m + 1)
for i in l:
	count[i] += 1
dp[1] = count[1]
for i in range(2, m + 1):
	dp[i] = max(dp[i - 2] + count[i] * i, dp[i - 1])
print(dp[m])


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()


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


from collections import defaultdict
n = int(input())
N = 100010
arr = [int(i) for i in input().split()]
Dict = defaultdict(int)
for i in arr:
	Dict[i] += 1
dp = [0] * N
for i in range(1, N):
	if i - 2 < 0:
		dp[i] = i * Dict[i]
	else:
		dp[i] = i * Dict[i] + dp[i - 2]
	dp[i] = max(dp[i], dp[i - 1])
print(dp[-1])


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))


def solve():
	n = int(input())
	l = map(int, input().split())
	counter = [0] * 100005
	for i in l:
		counter[i] += 1
	dp = [[0, 0] for _ in range(100005)]
	for i in range(1, 100005):
		dp[i][0] = max(dp[i - 1])
		dp[i][1] = dp[i - 1][0] + i * counter[i]
	print(max(dp[100004]))
solve()


n = int(input())
l = [int(i) for i in input().split()]
s = [0] * (max(l) + 1)
for j in range(len(l)):
	s[l[j]] += 1
f = [0] * len(s)
f[1] = s[1]
for j in range(2, len(s)):
	a = f[j - 1]
	b = f[j - 2] + j * s[j]
	f[j] = max(a, b)
print(f[len(s) - 1])


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


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


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])


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])

def read(mode=2):
	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()


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


n = int(input())
l = list(map(int, input().split()))
d = [0] * 100005
for i in l:
	d[i] += 1
dp = [0] * 100005
dp[1] = d[1]
for i in range(2, 100005):
	dp[i] = max(dp[i - 1], dp[i - 2] + d[i] * i)
print(dp[max(l)])


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])


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


n = int(input())
arr = list(map(int, input().split()))
mx = max(arr)
dp = [0] * (mx + 1)
from collections import Counter
cnt = Counter(arr)
dp[1] = cnt[1]
for i in range(2, mx + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * cnt[i])
print(dp[mx])


n = int(input())
a = list(map(int, input().split(' ')))
cnt = [0] * (max(a) + 1)
for i in a:
	cnt[i] += 1
dp = [0] * (max(a) + 1)
dp[0] = 0
for i in range(1, max(a) + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i)
print(dp[max(a)])


n = int(input())
arr = list(map(int, input().split()))
count = [0 for i in range(0, 100001)]
for x in arr:
	count[x] += 1
f = [0 for i in range(0, 100001)]
for i in range(1, 100001):
	f[i] = i * count[i]
	if i - 2 >= 0:
		f[i] += f[i - 2]
	if f[i - 1] > f[i]:
		f[i] = f[i - 1]
print(f[100000])


from sys import stdin
_input = stdin.readline
(_max, _int, _range) = (max, int, range)
from collections import Counter

def solution():
	n = _int(_input())
	arr = Counter([_int(i) for i in _input().split()])
	m = _max(arr)
	z = [0] * (m + 1)
	for i in _range(1, m + 1):
		if i > 2:
			z[i] = _max(arr[i] * i + z[i - 2], z[i - 1])
		else:
			z[i] = _max(arr[i] * i, z[i - 1])
	print(z[-1])
solution()


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


import queue
n = int(input())

def dp(n, countArr, arrDP):
	if arrDP[n] != -1:
		return arrDP[n]
	arrDP[n] = max(dp(n - 1, countArr, arrDP), dp(n - 2, countArr, arrDP) + countArr[n] * n)
	return arrDP[n]
arr = list(map(int, input().split()))
countArr = [0] * 100001
maxNum = 0
for i in range(len(arr)):
	maxNum = max(maxNum, arr[i])
	countArr[arr[i]] += 1
maxArr = [-1] * 100001
maxArr[0] = 0
maxArr[1] = countArr[1]
for i in range(maxNum + 1):
	result = dp(i, countArr, maxArr)
print(result)


n = int(input())
arr = [int(x) for x in input().split()]
d = [0 for i in range(100001)]
for x in arr:
	d[x] = d[x] + 1
dp = [0 for _ in range(100001)]
dp[1] = d[1]
for i in range(2, 100001):
	dp[i] = max(i * d[i] + dp[i - 2], dp[i - 1])
print(dp[-1])


n = int(input())
p = [int(i) for i in input().split()]
p.sort()
p.append(0)
w = []
s = 1
for i in range(n):
	if p[i + 1] == p[i]:
		s += 1
	else:
		w.append([p[i], s * p[i]])
		s = 1
w.append([0, 0])
c = [w[0]]
num = 0
for i in range(len(w) - 1):
	if w[i + 1][0] == w[i][0] + 1:
		c.append(w[i + 1])
	else:
		l = len(c)
		if l > 3:
			c[2][1] += c[0][1]
			for j in range(3, l):
				c[j][1] = c[j][1] + max(c[j - 2][1], c[j - 3][1])
			num += max(c[l - 2][1], c[l - 1][1])
		elif l == 1:
			num += c[0][1]
		elif l == 2:
			num += max(c[0][1], c[1][1])
		elif l == 3:
			num += max(c[0][1] + c[2][1], c[1][1])
		c = [w[i + 1]]
print(num)


n = int(input())
line = list(map(int, input().split()))
n = max(line)
m = [[0, 0, 0] for i in range(n)]
for i in range(len(line)):
	m[line[i] - 1][0] += 1
m[0][1] = m[0][0]
for i in range(1, n):
	m[i][1] = m[i - 1][2] + m[i][0] * (i + 1)
	m[i][2] = max(m[i - 1][1], m[i - 1][2])
print(max(m[n - 1][2], m[n - 1][1]))


n = list(map(int, input().strip().split()))
l = list(map(int, input().strip().split()))
dp = {}
cnt = {}
maxVal = 0
for i in l:
	if maxVal < i:
		maxVal = i
	if i not in cnt:
		cnt[i] = 1
	else:
		cnt[i] += 1
dp[0] = 0
if 1 in cnt:
	dp[1] = 1 * cnt[1]
else:
	dp[1] = 0
for i in range(2, maxVal + 1):
	if i not in cnt:
		cnt[i] = 0
	dp[i] = max(dp[i - 1], dp[i - 2] + i * cnt[i])
print(dp[maxVal])


input()
seq = [int(i) for i in input().split()]
max_n = max(seq)
ans = [0] * (max_n + 1)
count = [0] * (max_n + 1)
for n in seq:
	count[n] += 1
ans[1] = count[1]
for i in range(2, max_n + 1):
	ans[i] = max(ans[i - 2] + i * count[i], ans[i - 1])
print(ans[-1])


N = int(input())
A = list(map(int, input().split()))
dic = {}
for i in A:
	if i in dic:
		dic[i] += 1
	else:
		dic[i] = 1
dp = [0 for i in range(100001)]
dp[1] = dic.get(1, 0)
for i in range(2, max(A) + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + dic.get(i, 0) * i)
print(dp[max(A)])


n = int(input())
arr = input().split()
arr = list(arr)
m = [0] * 100000
ans = [0] * 100000
for i in range(n):
	m[int(arr[i]) - 1] += int(arr[i])
(ans[0], ans[1], ans[2]) = (m[0], m[1], m[2] + m[0])
for i in range(3, len(ans)):
	ans[i] = max(ans[i - 2], ans[i - 3]) + m[i]
print(max(ans[99998], ans[99999]))


def boredom(x):
	n = len(x) + 1
	l = (3 + n) * [0]
	le = 3
	x = [0] + x
	for i in range(1, n):
		i = int(i)
		l[le] = x[i] + l[le - 2] if x[i] + l[le - 2] > x[i - 1] + l[le - 3] else x[i - 1] + l[le - 3]
		le += 1
	return l[le - 1]
input()
array = list(map(int, input().split(' ')))
l = (max(array) + 1) * [0]
for i in array:
	l[i] += i
l += [0]
result = 0
array_aux = []
for i in range(min(array), len(l)):
	if l[i] > 0:
		array_aux += [l[i]]
	else:
		result += boredom(array_aux)
		array_aux = []
print(result)


n = int(input())
d = [0] * 100000
for x in map(int, input().split()):
	d[x - 1] += x
a = b = 0
for i in d:
	(a, b) = (max(a, i + b), a)
print(a)


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
from collections import Counter

def solve():
	n = inp()
	count = Counter(inlt())
	keys = list(count.keys())
	res = {0: 0, 1: count.get(1, 0)}
	for k in range(2, max(keys) + 1):
		res[k] = max(res.get(k - 1, 0), res.get(k - 2, 0) + count.get(k, 0) * k)
	print(res[max(keys)])

def main():
	t = 1
	for i in range(t):
		solve()
BUFSIZE = 8192

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	return input().strip()

def invr():
	return map(int, input().split())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		to = f(*args, **kwargs)
		if stack:
			return to
		else:
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						return to
					to = stack[-1].send(to)
	return wrappedfunc

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
a = [int(i) for i in input().split()]
max_value = max(a)
cnt = (max_value + 1) * [0]
for i in range(n):
	cnt[a[i]] += 1
f = (max_value + 1) * [0]
f[0] = 0
f[1] = cnt[1]
for i in range(2, max_value + 1):
	if f[i - 1] > f[i - 2] + cnt[i] * i:
		f[i] = f[i - 1]
	else:
		f[i] = f[i - 2] + cnt[i] * i
print(f[max_value])


n = int(input())
a = [int(x) for x in input().split()]
set1 = sorted(list(set(a)))
max1 = set1[-1]
num = [0] * (max1 + 1)
for i in a:
	num[i] += 1
f = [0] * (max1 + 1)
f[1] = num[1]
j = 1
for i in set1:
	if i >= 2:
		if i > j + 1:
			f[j:i] = [f[j]] * (i - j)
		f[i] = max(f[i - 1], f[i - 2] + i * num[i])
		j = i
print(f[max1])


n = int(input())
x = list(map(int, input().split()))
y = [0] * 100001
for i in x:
	y[i] += 1
dp = [0] * 100001
dp[1] = x.count(1)
for i in range(2, len(dp)):
	a = dp[i - 2] + i * y[i]
	b = dp[i - 1]
	dp[i] = max(a, b)
print(dp[-1])


from collections import Counter
input()
c = Counter(map(int, input().split()))
max_ = max(c)
max_points = {1: c[1], 2: max(c[1], 2 * c[2])}
for i in range(3, max_ + 1):
	max_points[i] = max(max_points[i - 2] + i * c[i], max_points[i - 1])
print(max_points[max_])


n = int(input())
count = [0 for x in range(100001)]
dp = [0 for x in range(100001)]
for i in input().split():
	count[int(i)] += int(i)
for (index, i) in enumerate(count):
	if index > 1:
		dp[index] = max(dp[index - 2] + i, dp[index - 1])
	else:
		dp[index] = i
print(dp[-1])


import os
import sys
if os.path.exists('C:\\Users\\User\\codeforces'):
	f = iter(open('A.txt').readlines())

	def input():
		return next(f).strip()
else:
	input = lambda : sys.stdin.readline().strip()
fprint = lambda *args: print(*args, flush=True)
n = int(input())
a = list(map(int, input().split()))
N = 10 ** 5 + 1
x = [0] * N
for i in a:
	x[i] += 1
y = [0] * N
for i in range(1, N):
	if i >= 2:
		y[i] = max(y[i - 1], y[i - 2] + x[i] * i)
	else:
		y[i] = x[i] * i
print(max(y))


from collections import Counter

def dp(arr):
	mat = [0] * (max(arr) + 1)
	dic = Counter(arr)
	if 1 in dic:
		mat[1] = dic[1]
	for i in range(2, len(mat)):
		k = 0
		if i in dic:
			k = dic[i]
		mat[i] = max(mat[i - 2] + i * k, mat[i - 1])
	return mat[-1]
n = int(input())
arr = list(map(int, input().split()))
print(dp(arr))


n = int(input())
size = int(10 ** 5)
(arr, dp) = ([0] * (size + 1), [0] * (size + 1))
temp = [int(i) for i in input().split()]
for i in temp:
	arr[i] += 1
(dp[1], dp[2]) = (arr[1], max(arr[1], 2 * arr[2]))
for i in range(3, size + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * arr[i])
print(dp[size])


import sys
from math import *

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())
n = mint()
a = [0] * 100001
d = [0] * 100001
for i in mints():
	a[i] += 1
d[1] = a[1]
for i in range(2, 100001):
	d[i] = max(d[i - 1], d[i - 2] + a[i] * i)
print(d[100000])


n = int(input())
numbers = list(map(int, input().split()))
maxN = 0
arr = [0] * 100001
for n in numbers:
	arr[n] += 1
	maxN = max(maxN, n)
for i in range(2, maxN + 1):
	arr[i] = max(arr[i - 1], arr[i] * i + arr[i - 2])
print(arr[maxN])


n = int(input())
seq = input().split()
for i in range(n):
	seq[i] = int(seq[i])
a = min(seq)
b = max(seq)
num = [0] * (b - a + 2)
for i in range(n):
	num[seq[i] - a] += 1
for i in range(b - a + 1):
	num[i] = num[i] * (i + a)
check = [num[0], max(num[0], num[1])]
for i in range(b - a - 1):
	check += [max(check[len(check) - 1], check[len(check) - 2] + num[len(check)])]
print(check[-1])


N = int(input())
count = dict()
count[1] = 0
for i in input().split():
	n = int(i)
	if not count.get(n):
		count[n] = 0
	count[n] += 1
keys = count.keys()
dp = [0] * (max(keys) + 1)
dp[1] = count[1]
for i in range(2, max(keys) + 1):
	if not count.get(i):
		dp[i] = dp[i - 1]
		continue
	dp[i] = max(dp[i - 1], dp[i - 2] + count[i] * i)
print(dp[-1])


n = int(input())
a = [int(num) for num in input().split()]
a.sort()
ma = a[n - 1]
mi = a[0]
dp = [0 for i in range(ma + 1)]
count = [0 for i in range(ma + 1)]
for item in a:
	count[item] += 1
dp[0] = 0
dp[mi] = count[mi] * mi
for i in range(mi + 1, ma + 1):
	dp[i] = max(count[i] * i + dp[i - 2], dp[i - 1])
print(dp[ma])


import math
import itertools
gh = lambda : map(int, input().split())
N = 2 * 100000.0 + 5
N = int(N)

def main():
	input()
	d = [0] * N
	for i in gh():
		d[i] += i
	a = b = 0
	for i in d:
		(a, b) = (max(a, i + b), a)
	print(a)
main()


from collections import Counter, defaultdict

def solution(A):
	amax = max(A)
	C = dict(Counter(A))
	if len(C) == 1:
		return C[amax] * amax
	F0 = 0
	F1 = C[1] if 1 in C else 0
	F = 0
	a = 2
	while a <= amax:
		ca = C[a] if a in C else 0
		F = max(F1, F0 + ca * a)
		F0 = F1
		F1 = F
		a += 1
	return F
is_test = False
if is_test:
	print('Start tests..')
	assert solution([1]) == 1
	assert solution([1, 1]) == 2
	assert solution([1, 2]) == 2
	assert solution([1, 2, 3]) == 4
	assert solution([1, 2, 1, 3, 2, 2, 2, 2, 3]) == 10
	assert solution([1, 2, 1, 3, 2, 2, 2, 2, 3, 4, 4]) == 18
	assert solution([6, 6, 8, 9, 7, 9, 6, 9, 5, 7, 7, 4, 5, 3, 9, 1, 10, 3, 4, 5, 8, 9, 6, 5, 6, 4, 10, 9, 1, 4, 1, 7, 1, 4, 9, 10, 8, 2, 9, 9, 10, 5, 8, 9, 5, 6, 8, 7, 2, 8, 7, 6, 2, 6, 10, 8, 6, 2, 5, 5, 3, 2, 8, 8, 5, 3, 6, 2, 1, 4, 7, 2, 7, 3, 7, 4, 10, 10, 7, 5, 4, 7, 5, 10, 7, 1, 1, 10, 7, 7, 7, 2, 3, 4, 2, 8, 4, 7, 4, 4]) == 296
	print('passed!')
n = input()
A = list(map(int, input().split(' ')))
print(solution(A))


n = int(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
import sys
input = sys.stdin.readline
from collections import Counter, defaultdict, deque

def f(n, a):
	M = max(a)
	count = [0 for i in range(M + 1)]
	for i in range(n):
		count[a[i]] += 1
	dp = [0 for i in range(M + 1)]
	dp[0] = 0
	dp[1] = count[1]
	for i in range(2, M + 1):
		dp[i] = max(dp[i - 1], dp[i - 2] + count[i] * i)
	return dp[-1]
t = 1
result = []
for i in range(t):
	n = int(input())
	a = list(map(int, input().split()))
	result.append(f(n, a))
for i in range(t):
	print(result[i])


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())
a = list(map(int, input().split()))
dp = [0] * 100001
co = [0] * 100001
for i in a:
	co[i] += 1
dp[1] = co[1]
r = dp[1]
for i in range(2, 100001):
	if co[i] > 0:
		r = max(dp[i - 1], dp[i - 2] + i * co[i])
	dp[i] = r
print(r)


n = int(input())
k = [int(i) for i in input().split()]
maxi = max(k)
count = (maxi + 1) * [0]
for j in range(n):
	count[k[j]] += 1
f = (maxi + 1) * [0]
f[0] = 0
f[1] = count[1] * 1
for p in range(2, maxi + 1):
	if f[p - 1] > p * count[p] + f[p - 2]:
		f[p] = f[p - 1]
	else:
		f[p] = p * count[p] + f[p - 2]
print(f[maxi])


n = int(input())
sequence = [int(k) for k in input().split()]
minimum = min(sequence)
maximum = max(sequence)
numbers = (maximum + 1) * [0]
dp = (maximum + 1) * [0]
for i in sequence:
	numbers[i] += 1
dp[0] = [0, 0]
dp[1] = [0, numbers[1]]
for i in range(2, maximum + 1):
	dp[i] = [max(dp[i - 1][0], dp[i - 1][1]), dp[i - 1][0] + i * numbers[i]]
highest = max(dp[maximum][0], dp[maximum][1])
print(highest)


n = int(input())
a = [int(x) for x in input().split()]
max1 = max(a)
num = [0] * (max1 + 1)
for i in a:
	num[i] += 1
f = [0] * (max1 + 1)
f[1] = num[1]
for i in range(2, max1 + 1):
	f[i] = max(f[i - 1], f[i - 2] + i * num[i])
print(f[max1])


import sys
sys.setrecursionlimit(100000)
n = int(input())
a = list(map(lambda x: int(x), input().split()))
hashmap = {}
for i in a:
	if i not in hashmap:
		hashmap[i] = 0
	hashmap[i] += 1
dp = [0 for i in range(0, max(a) + 1)]
for i in range(1, max(a) + 1):
	if i in hashmap:
		dp[i] = max(dp[i - 1], dp[i - 2] + hashmap[i] * i)
	else:
		dp[i] = max(dp[i - 1], dp[i - 2])
print(dp[max(a)])


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()


a = int(input())
b = input().split(' ')
l = [int(i) for i in b]
largest = 0
total = 0
maxpoints = 0
mp = 0
for i in l:
	if i > largest:
		largest = i
	total = total + i
freq = [None] * 200000
for i in range(len(freq)):
	freq[i] = 0
for i in l:
	freq[i] = freq[i] + 1
dp = [None] * 200000
for i in range(len(dp)):
	dp[i] = 0
dp[0] = 0
dp[1] = freq[1]
for i in range(2, len(dp)):
	dp[i] = max(dp[i - 1], freq[i] * i + dp[i - 2])
print(dp[len(dp) - 1])


n = int(input())
inp_list = list(map(int, input().split()))
m = max(inp_list)
num_l = [0] * (1 + m)
ans_l = [[0, 0], [0, 0]]
for x in inp_list:
	num_l[x] += x
for i in range(1, 1 + m):
	ans_l.append([num_l[i] + max(ans_l[-2]), max(ans_l[-1])])
print(max(ans_l[-1]))


n = int(input())
ctr = [0] * 100002
maxVal = 0
for i in [int(x) for x in input().split()]:
	ctr[i] += 1
	if i > maxVal:
		maxVal = i
checker = [0] * (maxVal + 1)
checker[1] = ctr[1]
for i in range(2, maxVal + 1):
	checker[i] = max(i * ctr[i] + checker[i - 2], checker[i - 1])
print(checker[maxVal])


n = int(input())
a = map(int, input().split())
cnt = [0] * 100001
for x in a:
	cnt[x] += 1
f = [0] * 100001
f[1] = cnt[1]
for i in range(2, 100001):
	f[i] = max(f[i - 1], f[i - 2] + i * cnt[i])
print(f[100000])


from collections import defaultdict
n = int(input())
l = list(map(int, input().split()))
d = {}
d = defaultdict(int)
maxi = -99
for i in l:
	d[i] += 1
	maxi = max(i, maxi)
dp = [0] * 100001
dp[1] = d[1]
for i in range(2, 100000 + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + d[i] * i)
print(max(dp))


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


leng = int(input())
lst = list(map(int, input().split()))
c = [0] * 100001
Max = lst[0]
for i in range(leng):
	c[lst[i]] += 1
	if lst[i] > Max:
		Max = lst[i]
dp = [0] * (Max + 1)
dp[1] = c[1]
for i in range(2, Max + 1):
	dp[i] = max(i * c[i] + dp[i - 2], dp[i - 1])
print(dp[Max])


n = int(input())
A = map(int, input().split())
dec = [0] * 10 ** 5
for el in A:
	dec[el - 1] += 1
d = [0] * 10 ** 5
d[0] = dec[0]
d[1] = max(dec[0], dec[1] * 2)
for i in range(2, len(dec)):
	d[i] = max(d[i - 1], d[i - 2] + dec[i] * (i + 1))
print(d[-1])


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	d[a[i]] = d.get(a[i], 0) + a[i]
b = [0] * (10 ** 5 + 5)
b[1] = d.get(1, 0)
res = 0
for i in range(2, 10 ** 5 + 5):
	b[i] = max(b[i], b[i - 2] + d.get(i, 0), b[i - 1])
	res = max(res, b[i])
print(res)


n = int(input())
a = list(map(int, input().split()))
ma = max(a)
dp = [0] * (ma + 4)
for i in a:
	dp[i] += i
for i in range(ma, 0, -1):
	dp[i] = dp[i] + max(dp[i + 2], dp[i + 3])
print(max(dp[1], dp[2]))


while True:
	try:
		n = int(input())
		line = [int(i) for i in input().split()]
		l = 100001 * [0]
		for i in line:
			l[i] += i
		x = max(line)
		dp = [0] * len(l)
		dp[1] = l[1]
		for i in range(2, len(l)):
			dp[i] = max(dp[i - 2] + l[i], dp[i - 1])
		print(dp[len(l) - 1])
	except EOFError:
		break


from sys import stdin as si
from collections import Counter as C

class Solution(object):

	def toing(self, M):
		M = sorted(M)
		D = C(M)
		A = []
		for (k, v) in D.items():
			st = bool(k - 1 in D)
			A.append((k, st, v * k))
		del D
		self.d = {}
		return self.bazinga(0, len(A), A)[1]

	def get_i(self, y, D):
		if D[1]:
			return y - 2
		else:
			return y - 1

	def bazinga(self, i, x, A):
		if i == x:
			return (i - 1, 0)
		out = None
		if i == x - 1:
			if A[i][2] >= A[i - 1][2]:
				out = (self.get_i(i, A[i]), A[i][2])
			else:
				out = (self.get_i(i, A[i]) - 1, A[i - 1][2])
			self.d[i] = out
		else:
			(itm, current_max) = self.bazinga(i + 1, x, A)
			if itm in self.d:
				return self.d[itm]
			if itm < 0:
				out = (itm, current_max)
			elif itm == 0:
				out = (0, A[0][2] + current_max)
			elif A[itm][2] >= A[itm - 1][2]:
				out = (self.get_i(itm, A[itm]), A[itm][2] + current_max)
			else:
				out = (self.get_i(itm, A[itm]) - 1, A[itm - 1][2] + current_max)
			self.d[itm] = out
			i = itm
		return self.d[i]

	def toing1(self, A):
		d = [0] * 100001
		for x in A:
			d[x] += x
		a = b = 0
		for i in d:
			(a, b) = (max(a, i + b), a)
		return a
x = si.readline().strip()
y = map(int, si.readline().strip().split())
S = Solution()
print(S.toing1(y))


n = int(input())
a = [int(x) for x in input().split()]
mx = max(a)
c = [0] * (mx + 1)
for i in a:
	c[i] += 1
for i in range(2, mx + 1):
	c[i] = max(c[i - 1], c[i - 2] + c[i] * i)
print(c[mx])


n = int(input())
a = [int(x) for x in input().split()]
cnt = [0] * (10 ** 5 + 1)
for x in a:
	cnt[x] += 1
dp = [[0] * (10 ** 5 + 1) for _ in range(2)]
for i in range(1, 10 ** 5 + 1):
	dp[0][i] = max(dp[0][i - 1], dp[1][i - 1])
	dp[1][i] = dp[0][i - 1] + cnt[i] * i
print(max(dp[0][i], dp[1][i]))


n = int(input())
a = [int(x) for x in input().split()]
x = [0] * 100001
dp = [0]
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))
print(dp[-1])


from sys import stdin

def get_freq(arr):
	freq = [0] * (10 ** 5 + 1)
	for i in arr:
		freq[i] += 1
	return freq
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
freq = get_freq(arr)
dp = [0] * (10 ** 5 + 1)
dp[0] = 0
dp[1] = freq[1]
for i in range(2, 10 ** 5 + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * freq[i])
print(dp[-1])


from sys import stdin, stdout
import heapq
import cProfile
from collections import Counter, defaultdict, deque
from functools import reduce
import math

def get_int():
	return int(stdin.readline().strip())

def get_tuple():
	return map(int, stdin.readline().split())

def get_list():
	return list(map(int, stdin.readline().split()))

def sub(st):
	r = 0
	for (i, val) in enumerate(st):
		if val == '1':
			r = i
	return r

def solve():
	n = get_int()
	ls = get_list()
	freq_dic = Counter(ls)
	n = max(ls)
	dp = [0, freq_dic[1]] + [0] * (n - 1)
	for i in range(2, n + 1):
		dp[i] = max(dp[i - 1], dp[i - 2] + freq_dic[i] * i)
	print(dp[-1])

def main():
	solve()
TestCases = False
if TestCases:
	for i in range(get_int()):
		main()
else:
	main()


L = []
for i in range(100001):
	L.append(0)
n = int(input())
I = list(map(int, input().split()))
for i in range(n):
	L[I[i]] += 1
dp = {}
dp = {0: 0, 1: L[1]}
for i in range(2, 100001):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * L[i])
print(dp[100000])


n = int(input())
input_int_array = [int(x) for x in input().split()]
arr = [0] * 100001
max1 = 0
for el in input_int_array:
	arr[el] += 1
	if max1 < el:
		max1 = el
dp = [0] * (max1 + 1)
dp[0] = 0
dp[1] = arr[1]
for i in range(2, max1 + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + arr[i] * i)
print(dp[max1])


LIMIT = 100010

def frequency(arr):
	freq = [0] * LIMIT
	for i in arr:
		freq[i] += 1
	return freq

def solution(arr):
	freq = frequency(arr)
	dp = [0] * LIMIT
	dp[1] = freq[1]
	for i in range(2, LIMIT):
		dp[i] = max(dp[i - 1], dp[i - 2] + freq[i] * i)
	return dp[-1]
n = int(input())
arr = list(map(int, input().split()))
print(solution(arr))


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


n = int(input())
dp = [0] * 100010
for x in list(map(int, input().split())):
	dp[x] += x
for i in range(2, 100002):
	dp[i] = max(dp[i - 1], dp[i] + dp[i - 2])
print(dp[100001])


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
n = int(input())
arr = list(map(int, input().split()))
count = defaultdict(int)
for i in arr:
	count[i] += 1
dp = [0] * (10 ** 5 + 11)
dp[0] = 0
dp[1] = count[1]
for i in range(2, 10 ** 5 + 11):
	dp[i] = max(dp[i - 1], dp[i - 2] + count[i] * i)
print(max(dp))


from collections import *
n = int(input())
l = [*map(int, input().split())]
arr = [0] * (10 ** 5 + 1)
dic = Counter(l)
arr[1] = dic.get(1, 0)
for i in range(2, 10 ** 5 + 1):
	arr[i] = max(arr[i - 1], arr[i - 2] + dic.get(i, 0) * i)
print(arr[-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])


input()
l = list(map(int, input().split()))
n = max(l) + 1
cnt = [0] * n
for i in l:
	cnt[i] += 1
(z, x) = (0, cnt[1])
for i in range(2, n):
	(z, x) = (x, max(x, z + cnt[i] * i))
print(x)


def boredom(arr):
	cnt = [0] * (max(arr) + 10)
	for i in arr:
		cnt[i] += 1
	dp = [0] * (max(arr) + 5)
	arr = sorted(arr)
	curr = 0
	prev = 0
	for i in range(len(dp)):
		if i >= 2:
			dp[i] = max(dp[i - 2] + cnt[i] * i, dp[i - 1])
		else:
			dp[i] = arr.count(i) * i
	return max(dp)
a = input()
lst = list(map(int, input().strip().split()))
print(boredom(lst))


n = int(input())
ls = list(map(int, input().split()))
mem = {}
for i in ls:
	if i not in mem:
		mem[i] = 1
	else:
		mem[i] += 1
values = {}
lst = sorted(list(mem.keys()))
l = len(lst)
for i in lst:
	values[i] = i * mem[i]
dp = [[0, 0] for _ in range(l)]
dp[0] = [values[lst[0]], 0]
prev = lst[0]
for i in range(1, l):
	if lst[i] == prev + 1:
		dp[i] = [values[lst[i]] + dp[i - 1][1], max(dp[i - 1])]
	else:
		dp[i] = [values[lst[i]] + max(dp[i - 1]), max(dp[i - 1])]
	prev = lst[i]
print(max(dp[l - 1]))


def backtrack(score, hashmap, list1):
	global res
	if dp[score][sum(hashmap)] == 1:
		return score
	else:
		dp[score][sum(hashmap)] = 1
		print(score)
	if sum(hashmap) == 0:
		if score >= res:
			res = score
		return score
	for a in range(0, len(hashmap)):
		if hashmap[a] != 0:
			orig = a
			orig_l = hashmap[a - 1]
			orig_r = hashmap[a + 1]
			hashmap[a] -= 1
			hashmap[a - 1] = 0
			hashmap[a + 1] = 0
			score += orig
			backtrack(score, hashmap, list1)
			hashmap[a] += 1
			hashmap[a - 1] = orig_l
			hashmap[a + 1] = orig_r
			score -= orig
arg = int(input())
list1 = list(map(int, input().strip().split()))
hashmap = [0 for a in range(0, 10 ** 5 + 2)]
for a in range(0, arg):
	hashmap[list1[a]] += 1
res = 0
dp = [0, hashmap[1]]
for a in range(2, 10 ** 5 + 1):
	dp.append(max(dp[a - 1], hashmap[a] * a + dp[a - 2]))
print(dp[10 ** 5])


n = int(input())
l = input().split()
g = [0] * 100000
for i in l:
	g[int(i) - 1] += 1
(x, y) = (0, 0)
for i in range(100000):
	(x, y) = (max((i + 1) * g[i] + y, x), x)
print(x)


n = int(input())
l = list(map(int, input().split()))
m = 10 ** 5 + 2
freq = [0] * m
for i in l:
	freq[i] += 1
dp = [0] * m
dp[1] = freq[1]
dp[2] = freq[2] * 2
for i in range(3, m):
	dp[i] = max(dp[i - 3], dp[i - 2]) + freq[i] * i
print(max(dp))


n = int(input())
counts = [0] * 100002
for a in map(int, input().split()):
	counts[a] += 1
(f2, f1) = (0, counts[1])
for i in range(2, 100002):
	(f2, f1) = (f1, max(f1, i * counts[i] + f2))
print(f1)


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


for u in range(1):
	n = int(input())
	x = [int(w) for w in input().split()]
	count = [0] * (max(x) + 1)
	for i in range(n):
		count[x[i]] += 1
	ans = [0] * (max(x) + 1)
	ans[0] = 0
	if count[1]:
		ans[1] = count[1]
	for i in range(2, len(ans)):
		ans[i] = max(ans[i - 1], ans[i - 2] + count[i] * i)
	print(ans[-1])


n = int(input())
dp = [0] * 100001
arr = [0] * 100001
l = list(map(int, input().split()))
for i in range(n):
	arr[l[i]] += l[i]
dp[0] = arr[0]
dp[1] = arr[1]
for i in range(2, 100001):
	if arr[i] + dp[i - 2] > dp[i - 1]:
		dp[i] = arr[i] + dp[i - 2]
	else:
		dp[i] = dp[i - 1]
print(int(dp[100000]))


n = int(input())
line = input()
a = line.split()
num = []
ans = []
for i in range(10 ** 5 + 1):
	num.append(0)
	ans.append(0)
for i in range(n):
	a[i] = int(a[i])
	num[a[i]] += 1
a.sort()
m = a[n - 1]
ans[1] = num[1]
for i in range(2, m + 1):
	ans[i] = max(ans[i - 1], ans[i - 2] + num[i] * i)
print(ans[m])


n = int(input())
l = [0] * (10 ** 5 + 1)
dp = [0] * (10 ** 5 + 1)
a = list(map(int, input().split()))
for i in a:
	l[i] += 1
dp[1] = l[1]
for i in range(2, 10 ** 5 + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + i * l[i])
print(dp[10 ** 5])


input()
l = list(map(int, input().split()))
freq = [0] * 100005
for i in range(len(l)):
	freq[l[i]] += 1
scoreDP = dict()
scoreDP[0] = 0
scoreDP[1] = freq[1]
for i in range(2, 100001):
	scoreDP[i] = max(freq[i] * i + scoreDP[i - 2], scoreDP[i - 1])
print(scoreDP[10 ** 5])


n = int(input())
a = list(map(int, input().split()))
massiv = [0] * 10 ** 5
for i in range(n):
	massiv[a[i] - 1] += 1
dp = [0] * 10 ** 5
dp[0] = massiv[0]
dp[1] = massiv[1] * 2
maxx = dp[0]
for i in range(2, len(dp)):
	dp[i] = massiv[i] * (i + 1) + maxx
	if dp[i - 1] > maxx:
		maxx = dp[i - 1]
print(max(dp))


n = int(input())
a = list(map(int, input().split()))
dp = [0] * (max(a) + 1)
if len(a) == 1:
	print(a[0])
else:
	for i in a:
		dp[i] += 1
	f = [0, dp[0]]
	for u in range(1, len(dp)):
		f.append(max(f[-1], f[-2] + dp[u] * u))
	print(f[-1])


n = int(input())
w = [0] * (10 ** 5 + 2)
dp = [0] * (10 ** 5 + 2)
a = [int(x) for x in input().split()]
for r in a:
	w[r] += r
dp[0] = 0
dp[1] = w[1]
for t in range(2, len(dp)):
	dp[t] = max(dp[t - 1], dp[t - 2] + w[t])
print(max(dp))


import sys
input = sys.stdin.readline
ins = lambda : input().rstrip()
ini = lambda : int(input().rstrip())
inm = lambda : map(int, input().rstrip().split())
inl = lambda : list(map(int, input().split()))
out = lambda x, s='\n': print(s.join(map(str, x)))
n = ini()
a = inl()
m = max(a) + 1
count = [0] * m
for i in a:
	count[i] += i
ans = [0] * m
for i in range(1, m):
	ans[i] = count[i]
	if i - 2 >= 0:
		ans[i] += ans[i - 2]
	ans[i] = max(ans[i], ans[i - 1])
print(ans[m - 1])


n = int(input())
a = [0] * 100005
for k in map(int, input().split()):
	a[k] += 1
d = [0] + [a[1]] + [0] * 100003
for i in range(100001):
	d[i + 1] = max(d[i + 1], d[i])
	d[i + 2] = max(d[i + 2], d[i] + a[i + 2] * (i + 2))
print(max(d))


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2
from bisect import bisect_right, bisect_left
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def factorial(n):
	if n == 0:
		return 1
	return n * factorial(n - 1)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)
MOD = 1000000007
PMOD = 998244353
N = 10 ** 5
T = 1
for _ in range(T):
	n = int(stdin.readline())
	a = list(map(int, stdin.readline().rstrip().split()))
	c = [0] * N
	for i in a:
		c[i - 1] += 1
	dp = [0] * (N + 1)
	dp[1] = c[0]
	for i in range(2, N + 1):
		dp[i] = max(dp[i - 1], c[i - 1] * i + dp[i - 2])
	print(dp[-1])


from collections import Counter
n = int(input())
a = map(int, input().split())
count = Counter(a)
b = sorted(count.items())
best = [0] * (len(b) + 1)
best[1] = b[0][0] * b[0][1]
for i in range(2, len(b) + 1):
	j = i - 1 if b[i - 2][0] + 1 < b[i - 1][0] else i - 2
	best[i] = max(best[i - 1], best[j] + b[i - 1][0] * b[i - 1][1])
print(best[len(b)])


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

def boredom():
	worths = {}
	for a in A:
		if a not in worths:
			worths[a] = a
		else:
			worths[a] += a
	values = [(val, worths[val]) for val in worths]
	values.sort(key=lambda val: val[0])
	B = [0 for _ in range(len(values))]
	B[0] = values[0][1]
	for i in range(1, len(values)):
		if values[i][0] > values[i - 1][0] + 1:
			B[i] = values[i][1] + B[i - 1]
		else:
			B[i] = max(B[i - 1], values[i][1] + B[i - 2])
	print(B[len(values) - 1])
boredom()


from collections import defaultdict
_ = input('')
nums = list(map(int, input('').split(' ')))
dp = defaultdict(int)
for i in nums:
	dp[i] += i
dp[0] = 0
for i in range(2, max(nums) + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + dp[i])
print(dp[max(nums)])


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)))


input()
p = [0] * 100002
s = input().split()
for k in s:
	p[int(k)] += 1
for i in range(1, 100002):
	p[i] = max(p[i - 1], p[i - 2] + i * p[i])
print(p[-1])


import sys
n = int(sys.stdin.readline())
a = list(map(int, sys.stdin.readline().split(' ')))
M = max(a)
c = [0] * (M + 1)
for x in a:
	c[x] += 1

def solve():
	s = [0, c[1]]
	for i in range(2, M + 1):
		s.append(max(s[i - 1], s[i - 2] + c[i] * i))
	return s[-1]
print(solve())


__author__ = 'myduomilia'
n = int(input())
arr = list(map(int, input().split()))
a = [0 for i in range(100001)]
b = [0 for i in range(100001)]
for val in arr:
	a[val] += 1
(b[0], b[1]) = (a[0], a[1])
for i in range(2, 100001):
	b[i] = max(b[i - 1], b[i - 2] + a[i] * i)
print(b[100000])


n = int(input())
nums = list(map(int, input().split(' ')))
d = {}
for i in range(n):
	if nums[i] not in d:
		d[nums[i]] = 1
	else:
		d[nums[i]] = d[nums[i]] + 1
uniq = list(d.keys())
uniq = sorted(uniq)
dp = [0] * (len(uniq) + 1)
dp[0] = 0
for i in range(0, len(uniq)):
	if i == 0:
		dp[i] = d[uniq[i]] * uniq[i]
	elif uniq[i] - 1 == uniq[i - 1]:
		if i - 2 >= 0:
			dp[i] = max(dp[i - 2] + d[uniq[i]] * uniq[i], dp[i - 1])
		else:
			dp[i] = max(d[uniq[i]] * uniq[i], dp[i - 1])
	else:
		dp[i] = dp[i - 1] + d[uniq[i]] * uniq[i]
print(max(dp))
res = []


input()
z = [0] * (10 ** 5 + 1)
for i in map(int, input().split()):
	z[i] += i
a = b = 0
for i in z:
	(a, b) = (max(a, i + b), a)
print(a)


from collections import Counter
n = input()
a = list(map(int, input().split()))
memset = dict(Counter(a))
dp = [0] * 100001
if 1 not in memset:
	dp[1] = 0
else:
	dp[1] = memset[1] * 1
for i in range(2, len(dp)):
	if i not in memset:
		dp[i] = dp[i - 1]
		continue
	dp[i] = max(dp[i - 1], dp[i - 2] + i * memset[i])
print(dp[-1])


n = int(input())
a = list(map(int, input().split()))
dp = [0] * (10 ** 5 + 1)
for num in a:
	dp[num] += num
(a, b) = (0, 0)
for i in dp:
	(a, b) = (max(a, b + i), a)
print(a)


n = int(input())
if n == 0:
	print(0)
	pass
items = [int(s) for s in input().split()]
counts = dict()
max_item = 0
for item in items:
	counts[item] = counts.get(item, 0) + 1
	if item > max_item:
		max_item = item
dp = [0] * (max_item + 1)
dp[1] = counts.get(1, 0)
for i in range(2, max_item + 1):
	dp[i] = max(counts.get(i, 0) * i + dp[i - 2], dp[i - 1])
print(dp[max_item])


n = int(input())
l = list(map(int, input().split()))
dp = [0] * (10 ** 5 + 1)
dp[1] = 1
hash = {}
for i in range(1, 10 ** 5 + 1):
	hash[i] = 0
for i in range(n):
	hash[l[i]] += 1
ba = set(l)
seti = {}
z = sum(l)
for i in range(1, 10 ** 5 + 1):
	max1 = hash[i] * i + dp[i - 2]
	max2 = dp[i - 1]
	dp[i] = max(max1, max2)
print(dp[10 ** 5])


n = int(input())
a = list(map(int, input().split()))
m = max(a)
occs = [0] * (m + 1)
for i in a:
	occs[i] += 1
f0 = [0] * (m + 1)
f1 = [0] * (m + 1)
for i in range(1, len(occs)):
	if i >= 2:
		f0[i] = max(f1[i - 1], f1[i - 2])
	else:
		f0[i] = f1[i - 1]
	f1[i] = f0[i - 1] + i * occs[i]
print(max(f0[m], f1[m]))


n = int(input())
N = int(100000.0) + 5
freq = {}
dp = {}
for i in range(N + 1):
	dp[i] = 0
	freq[i] = 0
for i in input().strip().split():
	freq[int(i)] += 1
dp[0] = 0
dp[1] = freq[1]
for i in range(2, N + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + freq[i] * i)
print(dp[N])


a = int(input())
b = list(map(int, input().split()))
c = [0] * 100015
for i in range(a):
	c[b[i]] += b[i]
d = 0
e = 0
f = 0
i = 1
g = 0
while i < 100005:
	if not g:
		e += c[i]
		f += c[i + 1]
		if e >= f:
			d += e
			e = 0
			f = 0
			i += 2
		else:
			e += c[i + 2]
			if f >= e:
				d += f
				e = 0
				f = 0
				i += 3
				g = 0
			else:
				f += c[i + 3]
				if e >= f:
					d += e
					e = 0
					f = 0
					g = 0
				else:
					g = 1
				i += 4
	else:
		e += c[i]
		if f >= e:
			d += f
			e = 0
			f = 0
			i += 1
			g = 0
		else:
			f += c[i + 1]
			if e >= f:
				d += e
				e = 0
				f = 0
				g = 0
			else:
				g = 1
			i += 2
print(d + max(e, f))


n = int(input())
lst = list(map(int, input().split()))
(d, a, length) = ({}, [], 0)
for (i, x) in enumerate(lst):
	if d.get(x) == None:
		d[x] = 0
		a.append(x)
		length += 1
	d[x] += 1
a.sort()
(res, k) = ([a[0] * d[a[0]]], 1)
result = 0
for i in range(1, length):
	x = a[i] * d[a[i]]
	if a[i] - a[i - 1] == 1:
		if k == 1:
			res.append(x)
		elif k == 2:
			res.append(res[0] + x)
		else:
			res.append(max(res[k - 2], res[k - 3]) + x)
	else:
		if k == 1:
			result += res[0]
		else:
			result += max(res[k - 1], res[k - 2])
		(res, k) = ([x], 0)
	k += 1
if k == 1:
	result += res[0]
else:
	result += max(res[k - 1], res[k - 2])
print(result)


import sys, os.path
from collections import defaultdict
if os.path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
n = int(input())
d = defaultdict(int)
a = list(map(int, input().split()))
for i in a:
	d[i] += 1
ans = [0, d[1]]
for i in range(2, max(a) + 1):
	ans.append(max(ans[i - 2] + d[i] * i, ans[i - 1]))
print(ans[-1])


input()
l = list(map(int, input().split()))
ans = [0] * (max(l) + 2)
for i in l:
	ans[i] += i
pre = now = 0
for j in ans:
	(pre, now) = (max(pre, now), pre + j)
print(pre)


num = int(input())
n = [0] * 100001
for i in map(int, input().split()):
	n[i] += i
(first, second) = (0, 0)
for i in n:
	(first, second) = (max(first, i + second), first)
print(first)


n = int(input())
arr = list(map(int, input().split(' ')))
d = {}
count = 0
for i in range(n):
	if arr[i] in d:
		d[arr[i]] += 1
	else:
		d[arr[i]] = 1
		count += 1
aux = []
for key in d:
	aux.append(key)
aux.sort()
dp = [0 for i in range(count + 1)]
if count == 1:
	print(n * arr[0])
else:
	dp[1] = aux[0] * d[aux[0]]
	dp[2] = aux[1] * d[aux[1]]
	if aux[1] != aux[0] + 1:
		dp[2] += aux[0] * d[aux[0]]
	for i in range(3, count + 1):
		dp[i] = max(dp[i - 2] + aux[i - 1] * d[aux[i - 1]], dp[i - 3] + aux[i - 1] * d[aux[i - 1]])
		if aux[i - 2] + 1 != aux[i - 1]:
			dp[i] = max(dp[i], dp[i - 1] + aux[i - 1] * d[aux[i - 1]])
	print(max(dp[count], dp[count - 1]))


def Main():
	n = int(input())
	arr = list(map(int, input().split()))
	arr.sort()
	pp = dict()
	for i in range(n):
		val = pp.get(arr[i], 0)
		pp[arr[i]] = val + 1
	ans = 0
	a = [0] * (arr[n - 1] + 1)
	for key in range(1, len(a)):
		val = pp.get(key, 0)
		a[key] = a[key - 2] + key * val
		if a[key] < a[key - 1]:
			a[key] = a[key - 1]
		if a[key] > ans:
			ans = a[key]
	print(ans)
Main()


n = int(input())
lis = list(map(int, input().split()))
has = [0] * 100100
for i in lis:
	has[i] += 1
dp = [0] * 100100
c = 0
dp[1] = has[1]
for i in range(2, 100002):
	dp[i] = max(dp[i - 2] + has[i] * i, dp[i - 1])
print(max(dp))


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())
l = list(map(int, input().split()))
b = l.copy()
b.sort()
min1 = min(l)
max1 = max(l)
l1 = [0] * (max1 + 1)
i = 0
count1 = 1
while i < len(b) - 1:
	if b[i] == b[i + 1]:
		count1 = count1 + 1
	else:
		l1[b[i]] = count1
		count1 = 1
	i = i + 1
l1[b[i]] = count1
dp = [0] * (max1 + 1)
if max1 == 0:
	dp[0] = 0
	print(0)
elif max1 == 1:
	dp[1] = 1 * l1[1]
	print(dp[1])
else:
	dp[0] = 0
	dp[1] = 1 * l1[1]
	i = 2
	for i in range(2, len(dp)):
		dp[i] = max(dp[i - 1], dp[i - 2] + i * l1[i])
	print(dp[len(dp) - 1])


def solve(L):
	d = {}
	for i in L:
		if i not in d:
			d[i] = 1
		else:
			d[i] += 1
	f = []
	for i in d:
		f.append((i, i * d[i]))
	f.sort(key=lambda x: x[0])
	dp = [0, f[0][1]]
	for i in range(1, len(f)):
		if f[i][0] > f[i - 1][0] + 1:
			dp.append(f[i][1] + dp[i])
		else:
			dp.append(max(f[i][1] + dp[i - 1], dp[i]))
	return dp[-1]
N = int(input())
L = list(map(int, input().split(' ')))
print(solve(L))


n = int(input())
l = sorted(list(map(int, input().split())))
cnt = [0] + [0] * int(100000.0)
for i in l[:n + 1]:
	cnt[i] += 1
dp = [0] + [0] * int(100000.0)
dp[1] = cnt[1]
for i in range(2, int(100000.0) + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + cnt[i] * i)
print(dp[-1])


n = int(input())
numbers = list(map(int, input().split()))
cnt = [0] * 1000010
for i in numbers:
	cnt[i] += 1
dp = [0] * 100010
dp[1] = cnt[1] * 1
for i in range(2, max(numbers) + 1):
	dp[i] = max(dp[i - 2] + cnt[i] * i, dp[i - 1])
print(dp[max(numbers)])


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


import sys
import math
from collections import defaultdict, Counter
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
dp = [0] * (10 ** 5 + 2)
for j in range(1, 10 ** 5 + 1):
	dp[j] = dp[j - 1]
	if c.get(j) != None:
		dp[j] = max(dp[j], c[j] * j + dp[j - 2])
print(dp[10 ** 5])


from collections import Counter
entrada = int(input())
entrada2 = list(map(int, input().split()))
f = Counter(entrada2)
memo = {0: 0, 1: f[1]}
maior = max(entrada2)
for i in range(2, maior + 1):
	memo[i] = max(memo[i - 1], memo[i - 2] + f[i] * i)
print(memo[maior])


from collections import defaultdict
n = int(input())
a = [int(x) for x in input().split()]
mx = max(a)
dp = [0] * (mx + 1)
for i in range(n):
	dp[a[i]] += 1
ans = [0, dp[1]]
for i in range(2, mx + 1):
	res = max(ans[-1], ans[-2] + i * dp[i])
	ans += [res]
print(ans[-1])


n = int(input())
num = list(map(int, input().split()))
ans = 0
if n == 1:
	ans = num[0]
elif n == 2:
	if abs(num[0] - num[1]) == 1:
		ans = max(num)
	else:
		ans = sum(num)
else:
	c = max(num) + 1
	d = max(min(num), 2)
	b = [0] * 100001
	for i in num:
		b[i] += i
	b[0] = 0
	b[1] = num.count(1)
	for i in range(d, c):
		b[i] = max(b[i - 2] + b[i], b[i - 1])
	ans = b[c - 1]
print(ans)


n = int(input())
l = [int(i) for i in input().split()]
l.sort()
arr = []
arr_count = 0
a = 0
for i in l:
	if i > a:
		lis = []
		lis.append(i)
		arr.append(lis)
		a = i
	else:
		lis.append(i)
arr_count += sum(arr[0])
lst = []
arr.append([0])
for i in range(1, len(arr)):
	if arr[i][0] == arr[i - 1][0] + 1:
		if lst == []:
			l2 = []
			arr_count -= sum(arr[i - 1])
			lst.append(sum(arr[i - 1]))
			l2.append(sum(arr[i - 1]))
		lst.append(sum(arr[i]))
		if len(l2) == 1:
			l2.append(max(sum(arr[i]), l2[0]))
		else:
			l2.append(sum(arr[i]))
			l2[-1] = max(l2[-3] + l2[-1], l2[-2])
	else:
		if lst != []:
			arr_count += max(l2)
			lst = []
		arr_count += sum(arr[i])
print(arr_count)


n = int(input())
ch = input()
l = ch.split(' ')
r = sorted(l)
for i in range(n):
	r[i] = int(r[i])
pd = [0 for i in range(int(max(r)) + 1)]
p1 = [0 for i in range(int(max(r)) + 1)]
for i in range(n):
	pd[int(r[i])] = pd[int(r[i])] + int(r[i])
p1[1] = pd[1]
for i in range(2, int(max(r)) + 1):
	p1[i] = max(pd[i] + p1[i - 2], pd[i] + p1[i - 3])
print(max(p1))


import sys
from math import log2, floor, ceil, sqrt, gcd
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 998244353
n = int(ri())
a = Ri()
lis = [0] * (10 ** 5 + 1)
for i in range(len(a)):
	lis[a[i]] += 1
dp = [0] * (10 ** 5 + 1)
dp[0] = 0
dp[1] = lis[1] * 1
for i in range(1, 10 ** 5 + 1):
	dp[i] = max(dp[i - 1], dp[i - 2] + lis[i] * i)
print(dp[10 ** 5])


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())
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])