
class Solver:

    def __init__(self):
        self.n_ = 0
        self.v_ = []
        self.freq_ = []

    def read_input(self) -> None:
        self.n_ = int(input())
        self.v_ = list(map(int, input().split()))

    def process_freq(self) -> None:
        self.freq_ = [0] * (max(self.v_) + 1)

        for i in self.v_:
            self.freq_[i] += 1

    def solve(self):
        self.process_freq()
        dp = [0] * (max(self.v_)+1)
        dp[1] = self.freq_[1]
        for i in range(2, len(dp)):
            dp[i] = max(dp[i-1], dp[i-2] + i * self.freq_[i])
        
        print(dp[-1])


def main():
    solver = Solver()
    solver.read_input()
    solver.solve()


if __name__ == "__main__":
    main()
