import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
         ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(in.nextInt());

        }
        Collections.sort(a);

        System.out.println(count(a));

    }

    public static int count(ArrayList<Integer> al){
        if (al.size() == 1) {
            return al.get(0);
        }
        if (al.size() == 2) {
            if (al.get(0)==al.get(1)-1) {
                return al.get(1);
            }
            else if(al.get(1)==al.get(0)-1){
                return al.get(0);
            }
            else {
                return al.get(1)+al.get(0);
            }
        }
        if (al.isEmpty()) {
            return 0;
        }
        else{
        int size2 = 0;
        int size = (al.size())/2;
        ArrayList<Integer> a1 = new ArrayList<>();
        ArrayList<Integer> a11 = new ArrayList<>();
        int count1 = 0;
        for (int i = 0; i <al.size(); i++) {
            if(al.get(i) < al.get(size) - 1){
               a1.add(al.get(i));
               size2 = i;
            }

            if(al.get(i)  == al.get(size) ){
               count1+= al.get(size);
            }
            if(al.get(i) > al.get(size) + 1){

               a11.add(al.get(i));
            }
        }

        ArrayList<Integer> a2 = new ArrayList<>();
        ArrayList<Integer> a22 = new ArrayList<>();
        int count2 = 0;
        for (int i = 0; i < al.size(); i++) {
            if(al.get(i) < al.get(size2) - 1){
               a2.add(al.get(i));
            }
            if(al.get(i)  == al.get(size2) ){
               count2+= al.get(size2);
            }
            if(al.get(i) > al.get(size2) + 1){
               a22.add(al.get(i));
            }
        }

        int ans1 =count1 + count(a1)+count(a11) ;
        int ans2 = count2 + count(a2)+count(a22);

        int max = Math.max(ans1, ans2);

        return max;

    }}

}


import java.util.Scanner;

public class newC {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
        int[]a = new int[100001];
        int[] p = new int[100001];
        for (int i = 0; i < n; i++) {

           p[in.nextInt()]++;

        }

        int max ;
        max = p[1];
        a[1]=p[1];
        for (int i = 2; i < 100001; i++) {
            a[i] = Math.max(a[i-1],a[i-2]+i*p[i]);

        }

        System.out.println(a[100000]);

    }
}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
         ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(in.nextInt());

        }
        Collections.sort(a);
        System.out.println(count(a));

    }

    public static int count(ArrayList<Integer> al){
        if (al.size() == 1) {
            return al.get(0);
        }
        if (al.size() == 2) {
            if (al.get(0)==al.get(1)-1) {
                return al.get(1);
            }
            else if(al.get(1)==al.get(0)-1){
                return al.get(0);
            }
            else {
                return al.get(1)+al.get(0);
            }
        }
        if (al.size() == 0) {
            return 0;
        }
        else{

        int size = (al.size())/2;
        ArrayList<Integer> a1 = new ArrayList<>();
        ArrayList<Integer> a11 = new ArrayList<>();
        int count1 = 0;
        for (int i = 0; i <al.size(); i++) {
            if(al.get(i) < al.get(size) - 1){
               a1.add(al.get(i));
            }
            if(al.get(i)  == al.get(size) ){
               count1+= al.get(size);
            }
            if(al.get(i) > al.get(size) + 1){
               a11.add(al.get(i));
            }
        }

        int size2 = (al.size())/2 + 1;
        ArrayList<Integer> a2 = new ArrayList<>();
        ArrayList<Integer> a22 = new ArrayList<>();
        int count2 = 0;
        for (int i = 0; i < al.size(); i++) {
            if(al.get(i) < al.get(size2) - 1){
               a2.add(al.get(i));
            }
            if(al.get(i)  == al.get(size2) ){
               count2+= al.get(size2);
            }
            if(al.get(i) > al.get(size2) + 1){
               a22.add(al.get(i));
            }
        }

        int size3 = (al.size())/2 - 1;
        ArrayList<Integer> a3 = new ArrayList<>();
        ArrayList<Integer> a33 = new ArrayList<>();
        int count3 = 0;
        for (int i = 0; i < al.size(); i++) {
            if(al.get(i) < al.get(size3) - 1){
               a3.add(al.get(i));
            }
            if(al.get(i)  == al.get(size3) ){
               count3+=al.get(size3);
            }
            if(al.get(i) > al.get(size3) + 1){
               a33.add(al.get(i));
            }
        }

        int ans1 =count1 + count(a1)+count(a11) ;
        int ans2 = count2 + count(a2)+count(a22);
        int ans3 = count3 + count(a3)+count(a33);

        int max = Math.max(ans1, ans2);
        max = Math.max(max, ans3);

        return max;

    }}

}


import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class C {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);

        int n = in.nextInt();
         ArrayList<Integer> a = new ArrayList<>();
        for (int i = 0; i < n; i++) {
            a.add(in.nextInt());

        }
        Collections.sort(a);
        System.out.println(count(a));

    }

    public static int count(ArrayList<Integer> al){
        if (al.size() == 1) {
            return al.get(0);
        }
        if (al.size() == 2) {
            if (al.get(0)==al.get(1)-1) {
                return al.get(1);
            }
            else if(al.get(1)==al.get(0)-1){
                return al.get(0);
            }
            else {
                return al.get(1)+al.get(0);
            }
        }
        if (al.size() == 0) {
            return 0;
        }
        else{

        int size = (al.size())/2;
        ArrayList<Integer> a1 = new ArrayList<>();
        ArrayList<Integer> a11 = new ArrayList<>();
        int count1 = 0;
        for (int i = 0; i <al.size(); i++) {
            if(al.get(i) < al.get(size) - 1){
               a1.add(al.get(i));
            }
            if(al.get(i)  == al.get(size) ){
               count1+= al.get(size);
            }
            if(al.get(i) > al.get(size) + 1){
               a11.add(al.get(i));
            }
        }

        int size2 = (al.size())/2 + 1;
        ArrayList<Integer> a2 = new ArrayList<>();
        ArrayList<Integer> a22 = new ArrayList<>();
        int count2 = 0;
        for (int i = 0; i < al.size(); i++) {
            if(al.get(i) < al.get(size2) - 1){
               a2.add(al.get(i));
            }
            if(al.get(i)  == al.get(size2) ){
               count2+= al.get(size2);
            }
            if(al.get(i) > al.get(size2) + 1){
               a22.add(al.get(i));
            }
        }

        int size3 = (al.size())/2 - 1;
        ArrayList<Integer> a3 = new ArrayList<>();
        ArrayList<Integer> a33 = new ArrayList<>();
        int count3 = 0;
        for (int i = 0; i < al.size(); i++) {
            if(al.get(i) < al.get(size3) - 1){
               a3.add(al.get(i));
            }
            if(al.get(i)  == al.get(size3) ){
               count3+=al.get(size3);
            }
            if(al.get(i) > al.get(size3) + 1){
               a33.add(al.get(i));
            }
        }

        int ans1 =count1 + count(a1)+count(a11) ;
        int ans2 = count2 + count(a2)+count(a22);
        int ans3 = count3 + count(a3)+count(a33);

        int max = Math.max(ans1, ans2);
        max = Math.min(max, ans3);

        return max;

    }}

}


import java.util.Arrays;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Comparator;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[]args){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1,in,out);
        out.close();
    }
}

class TaskC{

    int n;
    long cnt[];
    long pd[];

    public void solve(int testNumber, InputReader in, PrintWriter out){
        n = in.nextInt();

        cnt = new long[10000100];
        pd = new long[10000100];

        for(int i=0;i<=1000000;++i) cnt[i] = pd[i] = 0;

        for(int i=0;i<n;++i)
        {
            int x = in.nextInt();
            cnt[x]++;
        }

        for(int i=1;i<=1000000;++i)
        {
            if(i==1) pd[i] = cnt[i];
            else pd[i] = Math.max( (cnt[i]*i)+pd[i-2] , pd[i-1] );
        }

        out.println(pd[1000000]);
    }
}

class InputReader
{
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next(){
        while (tokenizer == null || !tokenizer.hasMoreTokens()){
            try{
                tokenizer = new StringTokenizer(reader.readLine());
            }
            catch (IOException e){
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
}


import java.util.Arrays;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Comparator;
import java.io.IOException;
import java.util.StringTokenizer;

public class Main{
    public static void main(String[]args){
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1,in,out);
        out.close();
    }
}

class TaskC{

    int n;
    int cnt[];
    int pd[];

    public void solve(int testNumber, InputReader in, PrintWriter out){
        n = in.nextInt();

        cnt = new int[1000010];
        pd = new int[1000010];

        for(int i=0;i<=100000;++i)
        {
            cnt[i] = pd[i] = 0;
        }

        for(int i=0;i<n;++i)
        {
            int x = in.nextInt();
            cnt[x]++;
        }

        for(int i=1;i<=100000;++i)
        {
            if(i==1) pd[i] = cnt[i];
            else pd[i] = Math.max( (cnt[i]*i)+pd[i-2] , pd[i-1] );
        }

        out.println(pd[100000]);
    }
}

class InputReader
{
    public BufferedReader reader;
    public StringTokenizer tokenizer;
    public InputReader(InputStream stream){
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }
    public String next(){
        while (tokenizer == null || !tokenizer.hasMoreTokens()){
            try{
                tokenizer = new StringTokenizer(reader.readLine());
            }
            catch (IOException e){
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }
    public int nextInt() {
        return Integer.parseInt(next());
    }
}


import java.util.List;
import java.io.InputStreamReader;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.ArrayList;
import java.awt.Point;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Turaev Timur
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		OutputWriter out = new OutputWriter(outputStream);
		TaskA solver = new TaskA();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskA {
    public void solve(int testNumber, InputReader in, OutputWriter out) {
        int n = in.nextInt();
        long[] a = in.nextLongArray(n);
        Arrays.sort(a);

        int i = 0;
        long ans = 0;
        ArrayList<Long> b = new ArrayList<>();
        while (i < n) {
            long currentElementSum = 0;
            long k = a[i];
            while (i < n && a[i] == k) {
                currentElementSum += a[i];
                i++;
            }
            b.add(currentElementSum);
            if (i >= n || a[i] != k + 1) {
                ans += calc(b);
                b.clear();
            }
        }
        out.print(ans);
    }

    private long calc(ArrayList<Long> a) {
        long[] dp = new long[a.size() + 1];
        dp[0] = 0;
        dp[1] = a.get(0);
        if (a.size() > 1) {
            dp[2] = Math.max(a.get(0), a.get(1));
        }
        for (int i = 2; i < a.size(); i++) {
            dp[i + 1] = Math.max(dp[i - 1] + a.get(i), a.get(i - 1) + dp[i - 2]);
        }
        return ArrayEx.max(dp);
    }
}

class InputReader {
    BufferedReader in;
    StringTokenizer stringTokenizer;

    public InputReader(InputStream inputStream) {
        in = new BufferedReader(new InputStreamReader(inputStream));
    }

    public String next() {
        while (stringTokenizer == null || !stringTokenizer.hasMoreElements()) {
            try {
                stringTokenizer = new StringTokenizer(in.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return stringTokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public long[] nextLongArray(int size) {
        long[] array = new long[size];
        for (int index = 0; index < size; ++index) {
            array[index] = nextLong();
        }
        return array;
    }

}

class OutputWriter extends PrintWriter {
    final int DEFAULT_PRECISION = 12;

    int precision;
    String format, formatWithSpace;

    {
        precision = DEFAULT_PRECISION;
        format = createFormat(precision);
        formatWithSpace = format + " ";
    }

    public OutputWriter(OutputStream out) {
        super(out);
    }

    private String createFormat(int precision) {
        return "%." + precision + "f";
    }

}

class ArrayEx {

    public static long max(long[] array) {
        long ans = array[0];
        for (long e : array)
            ans = Math.max(ans, e);
        return ans;
    }
}


/* Shubhang Verma */
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {

    public static void main(String[] args)
    {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter out = new OutputWriter(outputstream);
        mysolver mysol = new mysolver();
        mysol.solve(in, out);
        out.close();
    }

}
class node implements Comparable<node>{
	int count;
	long value;
	public int compareTo(node t)
	{
		if(this.value == t.value)
			return 0;
		else if(this.value < t.value)
			return -1;
		else
			return 1;
	}
}
class mysolver {
	int length = 0;
	int idx = 0;
	public long mod = 1000000009;
    public void solve(InputReader in,OutputWriter out)
    {
    	PrintWriter pout = new PrintWriter(new BufferedOutputStream(System.out));
    	int n = in.readInt();
    	int A[] = new int[n];
    	TreeSet<node> ts = new TreeSet<node>();

    	int count[] = new int[100002];

    	for(int i=0;i<n;i++)
    	{
    		int x = in.readInt();
    		count[x]++;
    	}
    	ArrayList<Integer> ar = new ArrayList();
    	for(int i=0;i<100002;i++)
    	{
    		if(count[i] > 0)
    		{
    			ar.add(i);
    		}
    	}
    	int length = ts.size()-1;

    	long v1 =0;
    	long v2 =0;
    	//System.out.println(ar.size());
    	for(int i=0;i<ar.size();i++)
    	{
    		///System.out.println(ar.get(i)+" "+ar.get(i).value);
    		if(i==0)
    		{
    			v1 = ar.get(i)*(long)count[ar.get(i)];
    			v2 = 0;
    		}
    		else
    		{
    			long prevv2 = v2;
    			long prevv1 = v1;
    			if(ar.get(i)==ar.get(i-1)+1)
    			{
    				v2 = Math.max(prevv1, prevv2);
    				v1 = prevv2 + ar.get(i)*(long)count[ar.get(i)];
    			}
    			else
    			{
    				v2 = Math.max(prevv1, prevv2);
    				v1 = Math.max(prevv1, prevv2) +ar.get(i)*(long)count[ar.get(i)];

    			}
    			//v1 = v2+ ar.get(i)*(long)count[ar.get(i)];
    			//v2 = v1;
    		}
    		//System.out.println(v1+" "+v2);
    	}
    	if(v1>v2)
    		System.out.println(v1);
    	else
    		System.out.println(v2);
        pout.close();
    }

}
class InputReader {
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return isWhitespace(c);
    }

    public static boolean isWhitespace(int c) {
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void close() {
        writer.close();
    }

    public void printLine(int i) {
        writer.println(i);
    }
}

class IOUtils {

    public static void readIntArrays(InputReader in, int[]... arrays) {
        for (int i = 0; i < arrays[0].length; i++) {
            for (int j = 0; j < arrays.length; j++)
                arrays[j][i] = in.readInt();
        }
    }

    }


import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

public class Main {

	public static void main(String[] args) {
		TaskC mSol = new TaskC();
		mSol.solve();
		mSol.flush();
		mSol.close();
	}

}

class TaskC {

	public FasterScanner mFScanner;
	public PrintWriter mOut;
	public static final int sMAX = 1000005;
	public long mArray[];
	public long mMem[][];
	public static final int sINCLUDE = 1;
	public static final int sEXCLUDE = 0;

	public TaskC() {
		mFScanner = new FasterScanner();
		mOut = new PrintWriter(System.out);
		mArray = new long[sMAX];
		mMem = new long[2][sMAX];
		for (int i = 0; i < 2; i++)
			Arrays.fill(mMem[i], -1);
	}

	public void solve() {
		int N;
		int num;
		long ans;
		int max;
		N = mFScanner.nextInt();

		max = 0;

		for (int i = 0; i < N; i++) {
			num = mFScanner.nextInt();
			mArray[num] += num;
			max = Math.max(num, max);
		}

		ans = Math.max(rec(1, max + 1), rec(0, max + 1));

		mOut.println(ans);
	}

	public long rec(int status, int val) {

		long max;

		if (val == 0)
			return 0;

		if (mMem[status][val] != -1)
			return mMem[status][val];

		if (status == 1)
			max = mArray[val] + rec(0, val - 1);

		else {
			max = rec(1, val - 1);
			max = Math.max(max, rec(0, val - 1));
		}

		mMem[status][val] = max;

		return max;

	}

	public void flush() {
		mOut.flush();
	}

	public void close() {
		mOut.close();
	}
}

class FasterScanner {
	private InputStream mIs;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;

	public FasterScanner() {
		this(System.in);
	}

	public FasterScanner(InputStream is) {
		mIs = is;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = mIs.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public String nextLine() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isEndOfLine(c));
		return res.toString();
	}

	public String nextString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long nextLong() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public int nextInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public boolean isSpaceChar(int c) {
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public boolean isEndOfLine(int c) {
		return c == '\n' || c == '\r' || c == -1;
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class DZYLovesHash {

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(in, out);
        out.close();
    }
}

class TaskC {

    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        long cnt[] = new long[(int)1e5+1];
        int temp,max = 0;

        for (int i = 0; i < n; i++) {
            temp = in.nextInt();
            cnt[temp]++;
            max = Math.max(max, temp);
        }

        for (int i = 2; i <= max; i++) {
            cnt[i] *= i;
            cnt[i] = Math.max(cnt[i-2] + cnt[i], cnt[i-1]);
        }

        out.println(cnt[max]);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.*;

public class Boredom {

    public static void main(String[] args) {

        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(in, out);
        out.close();
    }
}

class TaskC {

    public void solve(InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int cnt[] = new int[(int)1e5+1];
        int temp,max = 0;

        for (int i = 0; i < n; i++) {
            temp = in.nextInt();
            cnt[temp]++;
            max = Math.max(max, temp);
        }

        for (int i = 2; i <= max; i++) {
            cnt[i] *= i;
            cnt[i] = Math.max(cnt[i-2] + cnt[i], cnt[i-1]);
        }

        out.println(cnt[max]);
    }
}

class InputReader {
    public BufferedReader reader;
    public StringTokenizer tokenizer;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream), 32768);
        tokenizer = null;
    }

    public String next() {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }

}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int[] cnt = new int[100000 + 1];
                int N = nextInt();
                for(int i = 0; i < N; i++) cnt[nextInt()]++;

                long[] f = new long[100000 + 1];
                for(int i = 1; i <= 100000; i++){
                    f[i] = (long)i * cnt[i];
                    if(i >= 2){
                        f[i] += f[i-2];
                    }
                    f[i] = Math.max(f[i], f[i-1]);
                }

                System.out.println(f[100000]);
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int N = nextInt();
                long[] a = new long[100000 + 10];
                for(int i = 0; i < N; i++){
                    int now = nextInt();
                    a[now] += now;
                }

                long[] answer = new long[2];
                for(int i = 0; i < a.length; i++){
                    answer[i%2] += a[i];
                }
                System.out.println(Math.max(answer[0], answer[1]));
	}

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int N = nextInt();
                long[] a = new long[100000 + 10];
                for(int i = 0; i < N; i++){
                    int now = nextInt();
                    a[now] += now;
                }
               long ans = 0;
               int i = 0, j = 0;
               while(i <  a.length && j < a.length){
                   while(i < a.length && a[i] == 0)i++;
                   j = i;
                   while(j+1 < a.length && a[j+1] != 0) j++;
                   if(i > 100000 || j > 100000) break;
                   ans += get(i, j, a);
                   i = j + 1;
               }

                System.out.println(ans);
	}

	private long get(int ii, int jj, long[] a){
            System.out.println(ii + " " + jj);
             long[] answer = new long[2];
                for(int i = ii; i <= jj; i++){
                    answer[i%2] += a[i];
                }

                return Math.max(answer[0], answer[1]);
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.util.*;
import java.io.*;

public class Main implements Runnable {

	public void solve() throws IOException {
		int N = nextInt();
                long[] a = new long[100000 + 10];
                for(int i = 0; i < N; i++){
                    int now = nextInt();
                    a[now] += now;
                }
               long ans = 0;
               int i = 0, j = 0;
               while(i <  a.length && j < a.length){
                   while(i < a.length && a[i] == 0)i++;
                   j = i;
                   while(j+1 < a.length && a[j+1] != 0) j++;
                   if(i > 100000 || j > 100000) break;
                   ans += get(i, j, a);
                   i = j + 1;
               }

                System.out.println(ans);
	}

	private long get(int ii, int jj, long[] a){
           // System.out.println(ii + " " + jj);
             long[] answer = new long[2];
                for(int i = ii; i <= jj; i++){
                    answer[i%2] += a[i];
                }

                return Math.max(answer[0], answer[1]);
        }

	//-----------------------------------------------------------
	public static void main(String[] args) {
		new Main().run();
	}

        public void print1Int(int[] a){
                for(int i = 0; i < a.length; i++)
                        System.out.print(a[i] + " ");
                System.out.println();
        }

        public void print2Int(int[][] a){
                for(int i = 0; i < a.length; i++){
                        for(int j = 0; j < a[0].length; j++){
                                System.out.print(a[i][j] + " ");
                        }
                        System.out.println();
                }
        }

	public void run() {
		try {
			in = new BufferedReader(new InputStreamReader(System.in));
			tok = null;
			solve();
			in.close();
		} catch (IOException e) {
			System.exit(0);
		}
	}

	public String nextToken() throws IOException {
		while (tok == null || !tok.hasMoreTokens()) {
			tok = new StringTokenizer(in.readLine());
		}
		return tok.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}

	public long nextLong() throws IOException {
		return Long.parseLong(nextToken());
	}

	public double nextDouble() throws IOException {
		return Double.parseDouble(nextToken());
	}

	BufferedReader in;
	StringTokenizer tok;
}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        int n = in.readInt();
        int arr[] = new int[n];

        for(int i=0;i<n;i++){
            arr[i] = in.readInt();

        }

        long s1 = 0;
        long s2 = 0;
        Long brr[] = new Long[100001];
        for(int i=0;i<100001;i++)
            brr[i] = new Long("0");
        int z = 0;
        for(int i=0;i<n;i++){
            brr[arr[i]] = brr[arr[i]]+1;
        }
        for(int i=1;i<100001;i++){
            brr[i] = i*brr[i];
        }
        long crr[] = new long[100001];
        crr[100000] = Math.max(brr[99999], brr[100000]);
        for(int i=1;i<100000;i++){
            if(brr[i]==0)
                continue;
            long x = Math.max(brr[i-1], brr[i+1]);
            crr[i] = Math.max(brr[i], x);
        }

        for(int i=1;i<100001;i++){
            if(i%2==0)
                s1 = s1 + crr[i];
            else
                s2 = s2 + crr[i];
        }
        outt.printLine(Math.max(s1, s2));
        outt.close();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        int n = in.readInt();
        int arr[] = new int[n];

        for(int i=0;i<n;i++){
            arr[i] = in.readInt();

        }

        Long brr[] = new Long[100001];
        for(int i=0;i<100001;i++)
            brr[i] = new Long("0");

        for(int i=0;i<n;i++){
            brr[arr[i]] = brr[arr[i]]+1;
        }
        for(int i=1;i<100001;i++){
            brr[i] = i*brr[i];
        }
        long s1 = 0;
        long s2 = brr[1];
        for(int i=3;i<100001;i++){
            brr[i] += Math.max(s2, s1);
            s2 = brr[i-1];
            s1 = brr[i-2];
        }
        outt.printLine(Math.max(brr[99999], brr[100000]));
        outt.close();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        int n = in.readInt();
        int arr[] = new int[n];

        for(int i=0;i<n;i++){
            arr[i] = in.readInt();

        }

        long s1 = 0;
        long s2 = 0;
        Long brr[] = new Long[100001];
        for(int i=0;i<100001;i++)
            brr[i] = new Long("0");
        int z = 0;
        for(int i=0;i<n;i++){
            brr[arr[i]] = brr[arr[i]]+1;
        }
        for(int i=1;i<100001;i++){
            brr[i] = i*brr[i];
        }
        long crr[] = new long[100001];
        for(int i=0;i<100001;i++)
            crr[i] = brr[i];
        crr[100000] = Math.max(brr[99999], brr[100000]);

        crr[0] = Math.max(brr[1], brr[2]);
        for(int i=2;i<100000;i++){
            if(brr[i]==0)
                continue;

            if(brr[i+1]==0||brr[i-1]==0){

                long x = 0;
                if(brr[i-2]==0)
                    x = Math.max(brr[i-1], brr[i]);
                if(brr[i+2]==0)
                    crr[i] = Math.max(brr[i], x);
            }
        }

        for(int i=1;i<100001;i++){
            if(i%2==0)
                s1 = s1 + crr[i];
            else
                s2 = s2 + crr[i];
        }
        outt.printLine(Math.max(s1, s2));
        outt.close();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        int n = in.readInt();
        int arr[] = new int[n];

        for(int i=0;i<n;i++){
            arr[i] = in.readInt();

        }

        long s1 = 0;
        long s2 = 0;
        Long brr[] = new Long[100001];
        for(int i=0;i<100001;i++)
            brr[i] = new Long("0");
        int z = 0;
        for(int i=0;i<n;i++){
            brr[arr[i]] = brr[arr[i]]+1;
        }

        for(int i=1;i<100001;i++){
            if(i%2==0)
                s1 = s1 + (i*brr[i]);
            else
                s2 = s2 + (i*brr[i]);
        }
        outt.printLine(Math.max(s1, s2));
        outt.close();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }}


import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 *
 * @author jigsaw
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        InputStream inputstream = System.in;
        OutputStream outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        OutputWriter outt = new OutputWriter(outputstream);
        int n = in.readInt();
        Integer arr[] = new Integer[n];

        for(int i=0;i<n;i++){
            arr[i] = in.readInt();

        }

        long s1 = 0;
        long s2 = 0;
        Long brr[] = new Long[100001];
        for(int i=0;i<100001;i++)
            brr[i] = new Long("0");
        int z = 0;
        for(int i=0;i<n;i++){
            brr[arr[i]] += 1l;
        }
        for(int i=1;i<100001;i++){
            if(i%2==0)
                s1 = s1 + i*brr[i];
            else
                s2 = s2 + i*brr[i];
        }
        outt.printLine(Math.max(s1, s2));
        outt.close();
    }
}
class InputReader {

    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;
    private InputReader.SpaceCharFilter filter;

    public InputReader(InputStream stream) {
        this.stream = stream;
    }

    public int read() {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars) {
            curChar = 0;
            try {
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    public int readInt() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        int sgn = 1;
        if (c == '-') {
            sgn = -1;
            c = read();
        }
        int res = 0;
        do {
            if (c < '0' || c > '9')
                throw new InputMismatchException();
            res *= 10;
            res += c - '0';
            c = read();
        } while (!isSpaceChar(c));
        return res * sgn;
    }

    public String readString() {
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuffer res = new StringBuffer();
        do {
            res.appendCodePoint(c);
            c = read();
        } while (!isSpaceChar(c));
        return res.toString();
    }

    public boolean isSpaceChar(int c) {
        if (filter != null)
            return filter.isSpaceChar(c);
        return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
    }

    public String next() {
        return readString();
    }

    public interface SpaceCharFilter {
        public boolean isSpaceChar(int ch);
    }
}

class OutputWriter {
    private final PrintWriter writer;

    public OutputWriter(OutputStream outputStream) {
        writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream)));
    }

    public OutputWriter(Writer writer) {
        this.writer = new PrintWriter(writer);
    }

    public void print(Object...objects) {
        for (int i = 0; i < objects.length; i++) {
            if (i != 0)
                writer.print(' ');
            writer.print(objects[i]);
        }
    }

    public void printLine(Object...objects) {
        print(objects);
        writer.println();
    }

    public void close() {
        writer.close();
    }}


import java.io.*;
import java.util.*;

public class CF260C {

    /**
     * @param args
     */

    public static long solve(int i){

        if (i >= sorted.size()) {
            return 0;
        }
        if (dp[i] != -1) {
            return dp[i];
        }
        long x = sorted.get(i);
        long ans = (long)(x * array[(int) x]);
        if(i+1 < sorted.size()){
            long y = sorted.get(i+1);
            if(y - x == 1){
                ans += solve(i+2);
            }
            else {
                ans += solve(i+1);
            }
        }

        ans = Math.max(ans, solve(i+1));

        return dp[i] = ans;

    }

    public static int n;
    public static long[]array = new long[100002];
    public static long[]dp = new long[100002];
    public static ArrayList<Long>sorted;
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        BufferedReader k=new BufferedReader(new InputStreamReader(System.in));

         n = Integer.parseInt(k.readLine());
         sorted = new ArrayList<>();
        StringTokenizer str=new StringTokenizer(k.readLine());
        for (int i = 0; i < n; i++) {
            long x = Long.parseLong(str.nextToken());
            array[(int) x]++;
            if (array[(int) x] == 1) {
                sorted.add(x);
            }
        }
        Collections.sort(sorted);
        Arrays.fill(dp, -1);
        System.out.println(solve(0));

    }

}


import java.io.*;
import java.util.*;

public class CF260C {

    /**
     * @param args
     */

    public static long solve(int i){

        if (i >= sorted.size()) {
            return 0;
        }
        if (dp[i] != -1) {
            return dp[i];
        }
        int x = sorted.get(i);
        long ans = x * array[x];
        if(i+1 < sorted.size()){
            int y = sorted.get(i+1);
            if(y - x == 1){
                ans += solve(i+2);
            }
            else {
                ans += solve(i+1);
            }
        }

        ans = Math.max(ans, solve(i+1));

        return dp[i] = ans;

    }

    public static int n;
    public static int[]array = new int[100002];
    public static long[]dp = new long[100002];
    public static ArrayList<Integer>sorted;
    public static void main(String[] args) throws IOException {
        // TODO Auto-generated method stub
        BufferedReader k=new BufferedReader(new InputStreamReader(System.in));

         n = Integer.parseInt(k.readLine());
         sorted = new ArrayList<>();
        StringTokenizer str=new StringTokenizer(k.readLine());
        for (int i = 0; i < n; i++) {
            int x = Integer.parseInt(str.nextToken());
            array[x]++;
            if (array[x] == 1) {
                sorted.add(x);
            }
        }
        Collections.sort(sorted);
        Arrays.fill(dp, -1);
        System.out.println(solve(0));

    }

}


import java.util.Scanner;
import java.util.Vector;

public class EX {

    private static int MAXN = 100001;
    private static int n, num;
    private static int[] cnt = new int[MAXN];
    private static long[] dp = new long[MAXN];

    /**
     *
     * @author Tabriz
     */

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            num = in.nextInt();
            cnt[num]++;
        }
        dp[0]= 0;
        for (int i = 1; i < MAXN; i++) {
            dp[i] = (long)cnt[i] * (long)i;
            dp[i] += i - 2 >= 0 ? dp[i - 2] : 0;
            dp[i] = Math.max(dp[i], dp[i - 1]);
        }
        System.out.println(dp[MAXN - 1]);
    }

}


import java.util.Scanner;
import java.util.Vector;

public class EX {

    private static int MAXN = 100005;
    private static int n, num;
    private static long[] cnt = new long[MAXN];
    private static long[] dp = new long[MAXN];
    public static Vector<Integer> G = new Vector();

    /**
     *
     * @author Tabriz
     */
    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        n = in.nextInt();
        for (int i = 0; i < n; i++) {
            num = in.nextInt();
            cnt[num]++;
        }
        for (int i = 0; i < MAXN; i++) {
            if (cnt[i] == 1) {
                G.add(i);
            }
        }
        System.out.println(work());
    }

    private static long work() {

        for (int i = 0; i < MAXN; i++) {
            dp[i] = -1;
        }
        dp[0] = 0;
        for (int i = 0; i < G.size(); i++) {
            if (i + 1 == G.size() || G.elementAt(i) + 1 != G.elementAt(i + 1)) {
                dp[i + 1] = Math.max(dp[i + 1], dp[i] + G.elementAt(i) * cnt[G.elementAt(i)]);
            } else {
                dp[i + 1] = Math.max(dp[i + 1], dp[i]);
                dp[i + 2] = Math.max(dp[i + 2], dp[i] + G.elementAt(i) * cnt[G.elementAt(i)]);
            }
        }
        long ans = -1;
        for(int i = 0; i < G.size() + 4; i++)
            ans  = Math.max(ans, dp[i]);
    return ans;}

}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		long val;

		node(long index, long val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static int max = (int) Math.pow(10, 5) + 10;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(in.readLine());
		long a[] = new long[max];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			int k = Integer.parseInt(y[i]);
			a[k]++;
		}
		PriorityQueue<node> q = new PriorityQueue<>();

		for (int i = 1; i < max; i++) {
			if (a[i] != 0) {
				q.add(new node((long) i * (long) a[i] * 1L, i));
			}
		}
		boolean vis[] = new boolean[max];
		long ans = 0;
		while (!q.isEmpty()) {
			node e = q.poll();
			long val = e.index;
			long f = e.val;
			if (vis[(int) f])
				continue;

			long bef = 0;
			long aft = 0;
			if (!vis[(int) f - 1])
				bef = (long) a[(int) (f - 1)] * (long) (f - 1);
			if (!vis[(int) f + 1])
				aft = a[(int) f + 1] * (f + 1);
			long bef2 = 0;
			long aft2 = 0;
			if (f >= 2 && !vis[(int) f - 2]) {
				bef2 = a[(int) f - 2] * (f - 2);
			}
			if (!vis[(int) f + 2])
				aft2 = a[(int) f + 2] * (f + 2);

			if (val + bef2 + aft2 >= bef + aft) {
				ans += val;
				vis[(int) f - 1] = true;
				vis[(int) f + 1] = true;
				vis[(int) f] = true;
			}

		}
		System.out.println(ans);
		out.close();

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		long val;

		node(long index, long val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static long a[];
	public static long dp[];
	public static int n = (int) Math.pow(10, 5) + 1;

	public static long solve(int i) {
		if (i == n)
			return 0;
		if (dp[i] != -1)
			return dp[i];
		long a1 = 0;
		long b1 = 0;
		if (a[i] == 0) {

		} else {
			a1 = solve(i + 2) + a[i];
			b1 = solve(i + 1);
		}
		return dp[i] = Math.max(a1, b1);

	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int t = Integer.parseInt(in.readLine());
		 a = new long[n+5];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < t; i++) {
			int k = Integer.parseInt(y[i]);
			a[k] += (long)k;
		}
		dp = new long[n];
		Arrays.fill(dp, -1);
		System.out.println(solve(1));

		out.close();

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		long val;

		node(long index, long val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static int max = (int) Math.pow(10, 5) + 10;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(in.readLine());
		long a[] = new long[max];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			int k = Integer.parseInt(y[i]);
			a[k]++;
		}
		PriorityQueue<node> q = new PriorityQueue<>();

		for (int i = 1; i < max; i++) {
			if (a[i] != 0) {
				q.add(new node((long) i * (long) a[i] * 1L, i));
			}
		}
		boolean vis[] = new boolean[max];
		long ans = 0;
		while (!q.isEmpty()) {
			node e = q.poll();
			long val = e.index;
			long f = e.val;
			if (vis[(int) f])
				continue;

			long bef = 0;
			long aft = 0;
			if (!vis[(int) f - 1])
				bef = (long) a[(int) (f - 1)] * (long) (f - 1);
			if (!vis[(int) f + 1])
				aft = a[(int) f + 1] * (f + 1);
			long bef2 = 0;
			long aft2 = 0;
			if (f >= 2 && !vis[(int) f - 2]) {
				bef2 = a[(int) f - 2] * (f - 2);
			}
			if (!vis[(int) f + 2])
				aft2 = a[(int) f + 2] * (f + 2);

			if (val + bef2 + aft2 >= bef + aft) {
				ans += val;
				vis[(int) f - 1] = true;
				vis[(int) f + 1] = true;
			}
			vis[(int) f] = true;

		}
		System.out.println(ans);
		out.close();

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		long val;

		node(long index, long val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static long a[];
	public static long dp[];
	public static int n = (int) Math.pow(10, 5) + 1;

	public static long solve(int i) {
		if (i >= n)
			return 0;
		if (dp[i] != -1)
			return dp[i];
		long a1 = 0;
		long b1 = 0;
		if (a[i] == 0) {
			a1 = solve(i + 1);
		} else {
			a1 = solve(i + 2) + a[i];
			b1 = solve(i + 1);
		}
		return dp[i] = Math.max(a1, b1);

	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int t = Integer.parseInt(in.readLine());
		a = new long[n + 5];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < t; i++) {
			int k = Integer.parseInt(y[i]);
			a[k] += (long) k;
		}
		dp = new long[n];
		Arrays.fill(dp, -1);
		System.out.println(solve(1));

		out.close();

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		int val;

		node(long index, int val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static int max = (int) Math.pow(10, 5) + 10;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(in.readLine());
		int a[] = new int[max];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			int k = Integer.parseInt(y[i]);
			a[k]++;
		}
		PriorityQueue<node> q = new PriorityQueue<>();

		for (int i = 1; i < max; i++) {
			if (a[i] != 0) {
				q.add(new node((long) i * (long) a[i] * 1L, i));
			}
		}
		boolean vis[] = new boolean[max];
		long ans = 0;
		while (!q.isEmpty()) {
			node e = q.poll();
			long val = e.index;
			int f = e.val;
			if (vis[f])
				continue;
			ans += val;
			vis[f - 1] = true;
			vis[f + 1] = true;

		}
		System.out.println(ans);
		out.close();

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		long val;

		node(long index, long val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static long a[];
	public static long dp[];
	public static int n = (int) Math.pow(10, 5) + 1;

	public static long solve(int i) {
		if (i == n)
			return 0;
		if (dp[i] != -1)
			return dp[i];
		long a1 = 0;
		long b1 = 0;
		if (a[i] == 0) {

		} else {
			a1 = solve(i + 2) + a[i];
			b1 = solve(i + 1);
		}
		return dp[i] = Math.max(a1, b1);

	}

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int t = Integer.parseInt(in.readLine());
		 a = new long[n+5];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < t; i++) {
			int k = Integer.parseInt(y[i]);
			a[k] += k;
		}
		dp = new long[n];
		Arrays.fill(dp, -1);
		System.out.println(solve(1));

		out.close();

	}
}


import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;
import java.util.StringTokenizer;

public class a {
	public static class node implements Comparable<node> {
		long index;
		long val;

		node(long index, long val) {
			this.index = index;
			this.val = val;

		}

		@Override
		public int compareTo(node o) {
			if (o.index > index)
				return 1;
			else
				return -1;
		}
	}

	public static int max = (int) Math.pow(10, 5) + 10;

	public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder qq = new StringBuilder();
		PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));

		int n = Integer.parseInt(in.readLine());
		long a[] = new long[max];
		String y[] = in.readLine().split(" ");
		for (int i = 0; i < n; i++) {
			int k = Integer.parseInt(y[i]);
			a[k]++;
		}
		PriorityQueue<node> q = new PriorityQueue<>();

		for (int i = 1; i < max; i++) {
			if (a[i] != 0) {
				q.add(new node((long) i * (long) a[i] * 1L, i));
			}
		}
		boolean vis[] = new boolean[max];
		long ans = 0;
		while (!q.isEmpty()) {
			node e = q.poll();
			long val = e.index;
			long f = e.val;
			if (vis[(int) f])
				continue;

			long bef = (long) a[(int) (f - 1)] * (long) (f - 1);
			long aft = a[(int) f + 1] * (f + 1);
			long bef2 = 0;
			long aft2 = 0;
			if (f >= 2) {
				bef2 = a[(int) f - 2] * (f - 2);
			}
			aft2 = a[(int) f + 2] * (f + 2);

			if (val + bef2 + aft2 >= bef + aft) {
				ans += val;
				vis[(int) f - 1] = true;
				vis[(int) f + 1] = true;
			}

		}
		System.out.println(ans);
		out.close();

	}
}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Boredom {

    static int f(int i){
        if(i>max)return 0;
        if(dp[i]!=-1)return dp[i];
        if(occ[i]==0)return dp[i]= f(i+1);

        return dp[i] = Math.max(occ[i]*i + f(i+2),f(i+1));

    }
    static int[]dp = new int[100000+5];

    static int[]  occ;
    static int max;
    public static void main(String[]args) throws IOException{

        skp();
        int n = nextInt();
        skp();
         max = 0 ;

        occ = new int[100000+5];
        Arrays.fill(dp, -1);
        for(int i = 0 ; i < n ; i++){
            int x = nextInt();
            occ[x]++;
            if(x>max)max = x;
        }
        System.out.println(f(0));

    }

    static boolean skp() throws IOException{
        String line = r.readLine();
        if(line == null)return false;
        tkn = new StringTokenizer(line);
        return true;
    }

    static int nextInt(){
        return Integer.parseInt(tkn.nextToken());
    }
    static int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(r.readLine());
    }
    static long nextLong(){
        return Long.parseLong(tkn.nextToken());
    }
    static long readLong() throws NumberFormatException, IOException{
        return Long.parseLong(r.readLine());
    }

    static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tkn ;

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Boredom {

    static long f(int i){
        if(i>max)return 0;
        if(dp[i]!=-1)return dp[i];
        if(occ[i]==0)return dp[i]= f(i+1);

        return dp[i] = Math.max((long)occ[i]*i + f(i+2),f(i+1));

    }
    static long[]dp = new long[100000+5];

    static int[]  occ;
    static int max;
    public static void main(String[]args) throws IOException{

        skp();
        int n = nextInt();
        skp();
         max = 0 ;
        int min = 1000000;
        occ = new int[100000+5];
        Arrays.fill(dp, -1);
        for(int i = 0 ; i < n ; i++){
            int x =nextInt();
            occ[x]++;
            if(x>max)max = x;
            min = Math.min(min, x);
        }
        System.out.println(f(min));

    }

    static boolean skp() throws IOException{
        String line = r.readLine();
        if(line == null)return false;
        tkn = new StringTokenizer(line);
        return true;
    }

    static int nextInt(){
        return Integer.parseInt(tkn.nextToken());
    }
    static int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(r.readLine());
    }
    static long nextLong(){
        return Long.parseLong(tkn.nextToken());
    }
    static long readLong() throws NumberFormatException, IOException{
        return Long.parseLong(r.readLine());
    }

    static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tkn ;

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Boredom {

    static long f(int i){
        if(i>max)return 0;
        if(dp[i]!=-1)return dp[i];
        if(occ[i]==0)return dp[i]= f(i+1);

        return dp[i] = Math.max(occ[i]*i + f(i+2),f(i+1));

    }
    static long[]dp = new long[100000+5];

    static int[]  occ;
    static int max;
    public static void main(String[]args) throws IOException{

        skp();
        int n = nextInt();
        skp();
         max = 0 ;

        occ = new int[100000+5];
        Arrays.fill(dp, -1);
        for(int i = 0 ; i < n ; i++){
            int x = nextInt();
            occ[x]++;
            if(x>max)max = x;
        }
        System.out.println(f(0));

    }

    static boolean skp() throws IOException{
        String line = r.readLine();
        if(line == null)return false;
        tkn = new StringTokenizer(line);
        return true;
    }

    static int nextInt(){
        return Integer.parseInt(tkn.nextToken());
    }
    static int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(r.readLine());
    }
    static long nextLong(){
        return Long.parseLong(tkn.nextToken());
    }
    static long readLong() throws NumberFormatException, IOException{
        return Long.parseLong(r.readLine());
    }

    static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tkn ;

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Boredom {

    static int f(int i){
        if(i>max)return 0;
        if(occ[i]==0)return f(i+1);

        return Math.max(occ[i]*i + f(i+2),f(i+1));

    }

    static int[]  occ;
    static int max;
    public static void main(String[]args) throws IOException{

        skp();
        int n = nextInt();
        skp();
         max = 0 ;

        occ = new int[100000+5];

        for(int i = 0 ; i < n ; i++){
            int x = nextInt();
            occ[x]++;
            if(x>max)max = x;
        }
        System.out.println(f(0));

    }

    static boolean skp() throws IOException{
        String line = r.readLine();
        if(line == null)return false;
        tkn = new StringTokenizer(line);
        return true;
    }

    static int nextInt(){
        return Integer.parseInt(tkn.nextToken());
    }
    static int readInt() throws NumberFormatException, IOException{
        return Integer.parseInt(r.readLine());
    }
    static long nextLong(){
        return Long.parseLong(tkn.nextToken());
    }
    static long readLong() throws NumberFormatException, IOException{
        return Long.parseLong(r.readLine());
    }

    static BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer tkn ;

}


import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Anirudh "code_overlord" Rayabharam
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] cnt = new int[100001];
        long[] dp = new long[100001];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            ++cnt[a[i]];
        }

        dp[0] = 0;
        dp[1] = cnt[1];
        for (int i = 2; i <= 100000; i++) {
            dp[i] = Math.max(dp[i-1], dp[i-2] + (long)((long)i * (long)cnt[i]));
        }

        out.println(dp[n]);
    }
}

class InputReader {
    public BufferedReader reader;
    private int tokenCount, nextTokenIndex;
    private String[] tokens;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenCount = nextTokenIndex = 0;
    }

    public String next() {
        String nextLine;
        if (nextTokenIndex == tokenCount) {
            try {
                nextLine = reader.readLine();
                nextTokenIndex = 0;
                tokens = nextLine.split("\\s");
                tokenCount = tokens.length;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokens[nextTokenIndex++];
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Anirudh "code_overlord" Rayabharam
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] cnt = new int[100001];
        long[] dp = new long[100001];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            ++cnt[a[i]];
        }

        dp[0] = 0;
        dp[1] = cnt[1];
        for (int i = 2; i <= 100000; i++) {
            dp[i] = Math.max(dp[i-1], dp[i-2] + (long)((long)i * (long)cnt[i]));
        }

        long ans = 0;
        for (int i = 0; i < 100001; i++) {
            if (ans < dp[i]) ans = dp[i];
        }

        out.println(ans);
    }
}

class InputReader {
    public BufferedReader reader;
    private int tokenCount, nextTokenIndex;
    private String[] tokens;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenCount = nextTokenIndex = 0;
    }

    public String next() {
        String nextLine;
        if (nextTokenIndex == tokenCount) {
            try {
                nextLine = reader.readLine();
                nextTokenIndex = 0;
                tokens = nextLine.split("\\s");
                tokenCount = tokens.length;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokens[nextTokenIndex++];
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 * @author Anirudh "code_overlord" Rayabharam
 */
public class Main {
	public static void main(String[] args) {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskC solver = new TaskC();
		solver.solve(1, in, out);
		out.close();
	}
}

class TaskC {
    public void solve(int testNumber, InputReader in, PrintWriter out) {
        int n = in.nextInt();
        int[] a = new int[n];
        int[] cnt = new int[100001];
        long[] dp = new long[100001];

        for (int i = 0; i < n; i++) {
            a[i] = in.nextInt();
            ++cnt[a[i]];
        }

        dp[0] = 0;
        dp[1] = cnt[1];
        for (int i = 2; i <= 10000; i++) {
            dp[i] = Math.max(dp[i-1], dp[i-2] + (long)i * (long)cnt[i]);
        }

        out.println(dp[n]);
    }
}

class InputReader {
    public BufferedReader reader;
    private int tokenCount, nextTokenIndex;
    private String[] tokens;

    public InputReader(InputStream stream) {
        reader = new BufferedReader(new InputStreamReader(stream));
        tokenCount = nextTokenIndex = 0;
    }

    public String next() {
        String nextLine;
        if (nextTokenIndex == tokenCount) {
            try {
                nextLine = reader.readLine();
                nextTokenIndex = 0;
                tokens = nextLine.split("\\s");
                tokenCount = tokens.length;
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokens[nextTokenIndex++];
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

}


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.*;
import java.util.Map.Entry;

import static java.lang.Math.*;

public class solver implements Runnable {
        final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
        BufferedReader in;
        PrintWriter out;
        StringTokenizer tok = new StringTokenizer("");

        String readString() throws IOException{
                while(!tok.hasMoreTokens()){
                        try{
                                tok = new StringTokenizer(in.readLine());
                        }catch (Exception e){
                                return null;
                        }
                }
                return tok.nextToken();
        }
        String readString(String delim) throws IOException{
            while(!tok.hasMoreTokens()){
                    try{
                         tok = new StringTokenizer(in.readLine());
                    }catch (Exception e){
                            return null;
                    }
            }
            return tok.nextToken(delim);
    }

        int readInt() throws IOException{
                return Integer.parseInt(readString());
        }
        long readLong() throws IOException{
                return Long.parseLong(readString());
        }
        double readDouble() throws IOException{
                return Double.parseDouble(readString());
        }
        char readChar() throws IOException {
            char val = 0;
            do{
                val = (char) in.read();
            }while(val == '\n' || val == '\r');
            return val;
        }
        char readChar(String skipChars)throws IOException{
            char val = 0;
            boolean ret;
            do{
                val = (char) in.read();
                ret = false;
                for (int i = skipChars.length()-1; i >= 0; i--){
                    if (skipChars.charAt(i) == val){
                        ret = true;
                        break;
                    }
                }
            }while(ret);
            return val;
        }
//----------------------------------
        int gcd(int x, int y){
            while (y != 0) {
                int temp = x%y; x = y; y = temp;
            }
            return x;
        }
//----------------------------------

        public class Pair<T1,T2> {
            public T1 x1;
            public T2 x2;
            public Pair(){};
            public Pair(T1 x1, T2 x2){
                this.x1 = x1;
                this.x2 = x2;
            }
            public String toString(){
                return x1 + ":" + x2;
            }
        }
        public class Point implements Comparable<Point>{
            public int x1, x2;
            public Point(){}
            public Point(int a, int b){x1 = a;x2=b;}
            public int compareTo(Point o) {
                if (x1 == o.x1) return -(x2 -o.x2);
                return (x1-o.x1);
                // (x1-o.x1) - increase; -(x1-o.x1) - decrease
            }
            public String toString(){
                return x1 + ":" + x2;
            }
            public boolean equals(Object o){
                Point p = (Point)o;
                return x1 ==p.x2;
            }
        }
        public class Three implements Comparable<Three>{
            public int x1, x2, x3;
            public Three(){}
            public Three(int a, int b, int c){x1 = a;x2=b;x3=c;}
            public int compareTo(Three o) {
                if(x1 == o.x1 && x2 == o.x2) return x3-o.x3;
                if(x1 == o.x1) return x2-o.x2;
                return (x1-o.x1);
                // (x1-o.x1) - increase; -(x1-o.x1) - decrease
            }
            public String toString(){
                return x1 + ":" + x2 + ":" + x3;
            }
        }
//----------------------------------------

        public void solve() throws IOException {

            int n = readInt();
            int[] arr = new int[n];
            int[] num = new int[(int)1e5+1];
            HashMap<Integer, Integer> set = new HashMap<Integer, Integer>();

            for (int i = 0; i < n; i++){
                int a = readInt();
                arr[i] = a;
                num[a]++;
                Integer val = set.get(a);
                if (val == null){
                    set.put(a, 1);
                }else{
                    set.put(a, val+1);
                }
            }

            Set<Integer> s = set.keySet();
            Integer[] a = new Integer[s.size()];
            boolean[] b = new boolean[s.size()];
            s.toArray(a);
            Arrays.sort(a);

            long res = 0;
            for (int i = a.length-1; i >= 0; i--){
                if (b[i]) continue;

                int c = set.get(a[i])*a[i];
                if (i-1 >= 0 && a[i-1] +1 == a[i]){
                    int c2 = set.get(a[i-1])*a[i-1];
                    if (c2 > c){
                        res += c2;
                        if (i-2 >= 0 && a[i-2] + 1 == a[i-1]){
                            b[i-2] = true;
                        }
                        b[i-1] = true;
                        b[i] = true;
                    }else{
                        res += c;
                        b[i] = true;
                        if (i-1 >= 0 && a[i-1] + 1 == a[i]){
                            b[i-1] = true;
                        }
                        if (i+1 < a.length && a[i+1] - 1 == a[i]){
                            b[i+1] = true;
                        }
                    }
                }else{
                    res += c;
                    b[i] = true;
                    if (i-1 >= 0 && a[i-1] + 1 == a[i]){
                        b[i-1] = true;
                    }
                    if (i+1 < a.length && a[i+1] - 1 == a[i]){
                        b[i+1] = true;
                    }
                }
            }

            out.print(res);

        }

//----------------------------------------
        public static void main(String[] args){
                new Thread(null, new solver(), "", 256 * (1L << 20)).start();
        }

        public void run(){
                try{
                        timeBegin = System.currentTimeMillis();
                        try{
                            if (ONLINE_JUDGE){
                                in = new BufferedReader(new InputStreamReader(System.in));
                                out = new PrintWriter(System.out);
                            }
                            else {
                                in = new BufferedReader(new FileReader("input.txt"));
                                out = new PrintWriter("output.txt");
                            }
                        }catch(Throwable e){
                            in = new BufferedReader(new InputStreamReader(System.in));
                            out = new PrintWriter(System.out);
                        }

                        solve();
                        out.close();

                        timeEnd = System.currentTimeMillis();
                        System.err.println("Time = " + (timeEnd - timeBegin));
                }catch (Exception e){
                        e.printStackTrace(System.err);
                        System.exit(-1);
                }
        }

        long timeBegin, timeEnd;

//----------
        void update(int[] doo, int v, int i, int val, int ll, int rr){
            if (ll == rr){
                doo[v] = val;
            }else{
                int med = ll + ((rr-ll)>>1);

                if (i <= med){
                    update(doo, v<<1, i, val, ll, med);
                }else{
                    update(doo, (v<<1)+1, i, val, med+1, rr);
                }
                doo[v] = min(doo[v<<1],doo[(v<<1)+1]);
            }
        }
        int get(int[] doo, int v, int l, int r, int ll, int rr){
            if (l > r){
                return Integer.MAX_VALUE;
            }
            if (ll == l && r == rr){
                return doo[v];
            }
            int med = ll + ((rr-ll)>>1);
            return min(get(doo, v<<1, l, min(r, med), ll, med),
                    get(doo, (v<<1)+1, max(l, med+1), r, med+1, rr));
        }
 //----------------------------------------

        int BinSearch(int[] a, int x, boolean increase){

            int first = 0;
            int last = a.length;

            if (increase){
                while (first <= last) {
                    int mid = first + ((last - first) >> 1);
                    if (x <= a[mid])
                        last = mid;
                    else
                        first = mid + 1;
                }
                return last;
            }else{
                while (first <= last) {
                    int mid = first + ((last - first) >> 1);
                    if (x > a[mid])
                        last = mid;
                    else
                        first = mid + 1;
                }
                return first;
            }
        }

//-----------------------------------------
}