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[] num = new int[(int)1e5+1];
            int l = 0;

            for (int i = 0; i < n; i++){
                int aa = readInt();
                num[aa]++;
                if (num[aa] == 1) l++;
            }
            int[] a = new int[l];
            boolean[] b = new boolean[l];
            for (int i = 0, j = 0; i < num.length; i++){
                if (num[i] > 0) a[j++] = i;
            }

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

                int c = num[a[i]]*a[i];
                int c2 = 0;
                int c3 = 0;
                if (i+1 < a.length && a[i+1] - 1 == a[i] && !b[i+1]){
                    c3 = num[a[i+1]]*a[i+1];
                }

                if (i-1 >= 0 && a[i-1] +1 == a[i] && !b[i-1]){
                    c2 = num[a[i-1]]*a[i-1];
                }

                if (c2 >= c && c2 >= c3){
                    res += c2;
                    if (i-2 >= 0 && a[i-2] + 1 == a[i-1]){
                        b[i-2] = true;
                    }
                    b[i-1] = true;
                    b[i] = true;
                    continue;
                }
                if (c3 >= c && c3 >= c2){
                    res += c3;
                    if (i+2 < a.length && a[i+2] - 1 == a[i+1]){
                        b[i+2] = true;
                    }
                    b[i+1] = true;
                    b[i] = true;
                    continue;
                }

                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;
                }
            }

            for (int i = a.length-1; i >= 0; i--){
                if (!b[i]){
                    res += a[i]*num[a[i]];
                }

            }

            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;
            }
        }

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


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
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("");

        boolean HasTokens(){
            while(!tok.hasMoreTokens()){
                try{
                        tok = new StringTokenizer(in.readLine());
                }catch (Exception e){
                        return false;
                }
            }
            return true;
        }

        String readString() throws IOException{
            return HasTokens() ? tok.nextToken():null;
        }
        String readString(String delim) throws IOException{
            return HasTokens() ? tok.nextToken(delim):null;
        }

        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 x2; int x1;
            public Point(){}
            public Point(int a, int b){x1 = a;x2=b;}
            public int compareTo(Point o) {
                return (int)-(x1*x2 - o.x1*o.x2);
                //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;
            }
            @Override
            public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + getOuterType().hashCode();
                result = prime * result + x1;
                result = prime * result + x2;
                return result;
            }
            @Override
            public boolean equals(Object obj) {
                if (this == obj)
                    return true;
                if (obj == null)
                    return false;
                if (getClass() != obj.getClass())
                    return false;
                Point other = (Point) obj;
                if (!getOuterType().equals(other.getOuterType()))
                    return false;
                if (x1 != other.x1)
                    return false;
                if (x2 != other.x2)
                    return false;
                return true;
            }
            private solver getOuterType() {
                return solver.this;
            }
        }
        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 z = (int)1e5+1;
            int[] num = new int[z];

//            HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();

            for (int i = 0; i < n; i++) {
                int a = readInt();
//              Integer x = hm.get(a);
//              if (x!= null){
//                  hm.put(a, x+1);
//              }else{
//                  hm.put(a, 1);
//              }
                num[a]++;
            }

            long[] dp = new long[z];

            dp[1] = max(dp[0], num[1]*1);

            for (int i = 2; i < z; i++){
                dp[i] = max(dp[i-2] + i*num[i], dp[i-1]);
            }

            out.println(dp[z-1]);

        }

//----------------------------------------
        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]);
            }
        }
        long get(long[] 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;
            }
        }

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


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) {
                return -(x1*x2 - o.x1*o.x2);
                //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[] num = new int[(int)1e5+2];
            int l = 0;

            for (int i = 0; i < n; i++){
                int aa = readInt();
                num[aa]++;
                if (num[aa] == 1) l++;
            }
            int[] a = new int[l];
            boolean[] b = new boolean[(int)1e5+2];
            Point[] p = new Point[l];
            for (int i = 0, j = 0; i < num.length; i++){
                if (num[i] > 0) {
                    a[j++] = i;
                    p[j-1] = new Point(i, num[i]);
                }
            }

            Arrays.sort(p);

            long res = 0;
            for (int i = 0; i < a.length; i++){

                if (b[p[i].x1]) continue;

                long c = p[i].x1*p[i].x2;
                long c2 = !b[p[i].x1-1] ? num[p[i].x1-1]*(p[i].x1-1) : 0;
                long c3 = !b[p[i].x1+1] ? num[p[i].x1+1]*(p[i].x1+1) : 0;

                if (c2 >= c && c2 >= c3){
                    res += c2;
                    b[p[i].x1-1] = true;
                    b[p[i].x1] = true;
                    if (p[i].x1-2 >= 0)
                        b[p[i].x1-2] = true;
                    continue;
                }
                if (c3 >= c && c3 >= c2){
                    res += c3;
                    b[p[i].x1+1] = true;
                    b[p[i].x1] = true;
                    if (p[i].x1+2 < (int)1e5+2)
                        b[p[i].x1+2] = true;
                    continue;
                }

                res += c;
                b[p[i].x1-1] = true;
                b[p[i].x1+1] = true;
                b[p[i].x1] = 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;
            }
        }

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


import java.io.*;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Time;
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("");

        boolean HasTokens(){
            while(!tok.hasMoreTokens()){
                try{
                        tok = new StringTokenizer(in.readLine());
                }catch (Exception e){
                        return false;
                }
            }
            return true;
        }

        String readString() throws IOException{
            return HasTokens() ? tok.nextToken():null;
        }
        String readString(String delim) throws IOException{
            return HasTokens() ? tok.nextToken(delim):null;
        }

        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 x2; int x1;
            public Point(){}
            public Point(int a, int b){x1 = a;x2=b;}
            public int compareTo(Point o) {
                return (int)-(x1*x2 - o.x1*o.x2);
                //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;
            }
            @Override
            public int hashCode() {
                final int prime = 31;
                int result = 1;
                result = prime * result + getOuterType().hashCode();
                result = prime * result + x1;
                result = prime * result + x2;
                return result;
            }
            @Override
            public boolean equals(Object obj) {
                if (this == obj)
                    return true;
                if (obj == null)
                    return false;
                if (getClass() != obj.getClass())
                    return false;
                Point other = (Point) obj;
                if (!getOuterType().equals(other.getOuterType()))
                    return false;
                if (x1 != other.x1)
                    return false;
                if (x2 != other.x2)
                    return false;
                return true;
            }
            private solver getOuterType() {
                return solver.this;
            }
        }
        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 z = (int)1e5+1;
            int[] num = new int[z];

//            HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();

            for (int i = 0; i < n; i++) {
                int a = readInt();
//              Integer x = hm.get(a);
//              if (x!= null){
//                  hm.put(a, x+1);
//              }else{
//                  hm.put(a, 1);
//              }
                num[a]++;
            }

            long[] dp = new long[z];

            dp[1] = max(dp[0], num[1]*1);

            for (int i = 2; i < z; i++){
                dp[i] = max(dp[i-2] + (long)i*num[i], dp[i-1]);
            }

            out.println(dp[z-1]);

        }

//----------------------------------------
        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]);
            }
        }
        long get(long[] 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;
            }
        }

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


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) {
                return -(x1*x2 - o.x1*o.x2);
                //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[] num = new int[(int)1e5+2];
            int l = 0;

            for (int i = 0; i < n; i++){
                int aa = readInt();
                num[aa]++;
                if (num[aa] == 1) l++;
            }
            int[] a = new int[l];
            boolean[] b = new boolean[(int)1e5+2];
            Point[] p = new Point[l];
            for (int i = 0, j = 0; i < num.length; i++){
                if (num[i] > 0) {
                    a[j++] = i;
                    p[j-1] = new Point(i, num[i]);
                }
            }

            Arrays.sort(p);

            long res = 0;
            for (int i = 0; i < a.length; i++){

                if (b[p[i].x1]) continue;

                int c = p[i].x1*p[i].x2;
                int c2 = !b[p[i].x1-1] ? num[p[i].x1-1]*(p[i].x1-1) : 0;
                int c3 = !b[p[i].x1+1] ? num[p[i].x1+1]*(p[i].x1+1) : 0;

                if (c2 >= c && c2 >= c3){
                    res += c2;
                    b[p[i].x1-1] = true;
                    b[p[i].x1] = true;
                    if (p[i].x1-2 >= 0)
                        b[p[i].x1-2] = true;
                    continue;
                }
                if (c3 >= c && c3 >= c2){
                    res += c3;
                    b[p[i].x1+1] = true;
                    b[p[i].x1] = true;
                    if (p[i].x1+2 < (int)1e5+2)
                        b[p[i].x1+2] = true;
                    continue;
                }

                res += c;
                b[p[i].x1-1] = true;
                b[p[i].x1+1] = true;
                b[p[i].x1] = 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;
            }
        }

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


import java.util.*;
public class c260
{
	public static void main(String ar[])
	{
		Scanner obj=new Scanner(System.in);
		int n=obj.nextInt();
		int count[]=new int[100001];
		Arrays.fill(count,0);
		long dp[]=new long[100001];
		for(int i=0;i<n;i++)
			count[obj.nextInt()]++;
		dp[0]=0;
		for(int i=1;i<100001;i++)
		{
			dp[i]=(long)(i*count[i]);
			dp[i]+=	i-2>=0?dp[i-2]:0;
			dp[i]=Math.max(dp[i],dp[i-1]);
		}
		System.out.println(dp[100000]);
	}
}


import java.util.*;
public class c260
{
	public static void main(String ar[])
	{
		Scanner obj=new Scanner(System.in);
		int n=obj.nextInt();
		int count[]=new int[100001];
		Arrays.fill(count,0);
		long dp[]=new long[100001];
		int max=0;
		int temp;
		for(int i=0;i<n;i++){
			temp=obj.nextInt();
			count[temp]++;
			max=Math.max(max,temp);
		}
		dp[0]=0;
		for(int i=1;i<=max;i++)
		{
			dp[i]=(long)(i)*(long)(count[i]);
			dp[i]+=	i-2>=0?dp[i-2]:0;
			dp[i]=Math.max(dp[i],dp[i-1]);
		}
		System.out.println(dp[max]);
	}
}


import java.util.*;
public class c260
{
	public static void main(String ar[])
	{
		Scanner obj=new Scanner(System.in);
		int n=obj.nextInt();
		int count[]=new int[100001];
		Arrays.fill(count,0);
		long dp[]=new long[100001];
		int max=0;
		int temp;
		for(int i=0;i<n;i++){
			temp=obj.nextInt();
			count[temp]++;
			max=Math.max(max,temp);
		}
		dp[0]=0;
		for(int i=1;i<=max;i++)
		{
			dp[i]=(long)(i*count[i]);
			dp[i]+=	i-2>=0?dp[i-2]:0;
			dp[i]=Math.max(dp[i],dp[i-1]);
		}
		System.out.println(dp[max]);
	}
}


import java.util.Scanner;

/**
 * Created by Nikolay on 09.08.14.
 */

public class Boring {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] a = new long[100_001];

        int max = 0;
        while (--n >= 0) {
            int i = sc.nextInt();
            a[i]++;

            if (max < i) {
                max = i;
            }
        }

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

        System.out.println(a[max]);
    }
}


public class Boring {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[100_001];

        int max = 0;
        while (--n >= 0) {
            int i = sc.nextInt();
            a[i]++;

            if (max < i) {
                max = i;
            }
        }

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

        System.out.println(a[max]);
    }
}


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Nikolay on 09.08.14.
 */

public class Boring {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        int i = 0;
        while (i < n) {
            a[i] = sc.nextInt();
            i++;
        }

        Arrays.sort(a);

        int[] helper = new int[2];
        int r = 0;
        int m = 0;
        for (int j = 1; j < n; j++) {
            if (a[j] == a[j - 1]) {
                helper[r] += a[j];
            } else if (a[j] == a[j - 1] + 1) {
                r ^= 1;
                helper[r] += a[j];
            } else {
                m += Math.max(helper[0], helper[1]);
                r = 0;
                helper[0] = a[j];
                helper[1] = 0;
            }
        }

        m += Math.max(helper[0], helper[1]);

        System.out.println(m);

    }
}


import java.util.Arrays;
import java.util.Scanner;

/**
 * Created by Nikolay on 09.08.14.
 */

public class Boring {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        int i = 0;
        while (i < n) {
            a[i] = sc.nextInt();
            i++;
        }

        Arrays.sort(a);

        int[] helper = new int[2];

        int m = 0;
        int r = 0;
        helper[0] = a[0];
        helper[1] = 0;

        for (int j = 1; j < n; j++) {
            if (a[j] == a[j - 1]) {
                helper[r] += a[j];
            } else if (a[j] == a[j - 1] + 1) {
                r ^= 1;
                helper[r] += a[j];
            } else {
                m += Math.max(helper[0], helper[1]);
                r = 0;
                helper[0] = a[j];
                helper[1] = 0;
            }
        }

        m += Math.max(helper[0], helper[1]);

        System.out.println(m);

    }
}


import java.util.Scanner;

/**
 * Created by Nikolay on 09.08.14.
 */

public class Boring {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[100_001];

        int max = 0;
        while (--n >= 0) {
            int i = sc.nextInt();
            a[i]++;

            if (max < i) {
                max = i;
            }
        }

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

        System.out.println(a[max]);
    }
}


import java.util.*;
import java.io.*;
public class CF260C {
	public static void main(String [] args) {
		Scanner input = new Scanner(System.in);

		int n = input.nextInt();

		int [] a = new int[100001];

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

		input.close();

		long [] dp = new long[100001];
		dp[1] = a[1];

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

		PrintWriter out = new PrintWriter(System.out);
		out.println(dp[100000]);
		out.close();
	}
}


import java.util.*;
import java.io.*;
public class CF260C {
	public static void main(String [] args) {
		Scanner input = new Scanner(System.in);

		int n = input.nextInt();

		long [] a = new long[100001];

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

		input.close();

		long [] dp = new long[100001];
		dp[1] = a[1];

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

		PrintWriter out = new PrintWriter(System.out);
		out.println(dp[100000]);
		out.close();
	}
}


import java.util.*;

public class C {
    void doIt() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        Scanner sc2 = new Scanner(sc.nextLine());
        final int MAX_VAL = 100000 + 10;
        int [] cnt = new int[MAX_VAL];
        int max_val = 0;
        for(int i = 1; i < n; i++) {
            int a = Integer.parseInt(sc2.next());
            cnt[a]++;
            Math.max(max_val, a);
        }
        long [][] dp = new long[max_val+1][2];
        for(int i = 1; i <= max_val; i++) {
            dp[i][0] += Math.max(dp[i-1][0], dp[i-1][1]);
            dp[i][1] += dp[i-1][0] + (long)i * (long)cnt[i];
        }
        System.out.println(Math.max(dp[max_val][0], dp[max_val][1]));
    }
    public static void main(String args[]) {
        new C().doIt();
    }
}


import java.util.*;

public class C {
    void doIt() {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.nextLine());
        Scanner sc2 = new Scanner(sc.nextLine());
        final int MAX_VAL = 100000 + 10;
        //        final int MAX_VAL = 10 + 10;
        int [] cnt = new int[MAX_VAL];
        int max_val = 0;
        for(int i = 0; i < n; i++) {
            int a = Integer.parseInt(sc2.next());
            cnt[a]++;
            max_val = Math.max(max_val, a);
        }
        //System.out.println(max_val);
        //System.out.println(Arrays.toString(cnt));
        long [][] dp = new long[max_val+1][2];
        for(int i = 1; i <= max_val; i++) {
            dp[i][0] += Math.max(dp[i-1][0], dp[i-1][1]);
            dp[i][1] += dp[i-1][0] + (long)i * (long)cnt[i];
            //System.out.println(Arrays.toString(dp[i]));
        }
        System.out.println(Math.max(dp[max_val][0], dp[max_val][1]));
    }
    public static void main(String args[]) {
        new C().doIt();
    }
}


//package R315;
import java.util.Scanner;
import java.util.TreeMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map;

public class q3 {
    static int S[]=new int[100005];
    static int A[]=new int[100005];
    static int n;
    public static void main(String args[]){
        FasterScanner s=new FasterScanner();
        n=s.nextInt();
        for(int i=1; i<=n; i++){
            A[i]=s.nextInt();
            S[A[i]]=S[A[i]]+A[i];
        }
        int D[]=new int[100005];
        D=Arrays.copyOf(S,100005);
        for(int i=99999; i>0; i--){
            if(D[i+1]>D[i+2]+S[i]){
                D[i]=D[i+1];
            }
            else {
                D[i]=D[i+2]+S[i];
            }
        }
        System.out.println(D[1]);
    }

    private static int solve(int i) {
        if(i<=0)
            return 0;
        if(dp[i]!=-1)
            return dp[i];

        dp[i]=Math.max(solve(i-1),solve(i-2)+a[i]*i);
        return dp[i];
    }

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.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 int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


//package R315;
import java.util.Scanner;
import java.util.TreeMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map;

public class q3 {
    static int S[]=new int[100005];
    static int A[]=new int[100005];
    static int n;
    public static void main(String args[]){
        FasterScanner s=new FasterScanner();
        n=s.nextInt();
        for(int i=1; i<=n; i++){
            A[i]=s.nextInt();
            S[A[i]]=S[A[i]]+A[i];
        }
        int D[]=new int[100005];
        D=Arrays.copyOf(S,100005);
        for(int i=99999; i>0; i--){
            if(D[i+1]>D[i+2]+S[i]){
                D[i]=D[i+1];
            }
            else {
                D[i]=D[i+2]+S[i];
            }
        }
        System.out.println(D[1]);
    }

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.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 int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


//package R315;
import java.util.Scanner;
import java.util.TreeMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map;

public class q3 {
    static long S[]=new long[100005];
    static int A[]=new int[100005];
    static int n;
    public static void main(String args[]){
        FasterScanner s=new FasterScanner();
        n=s.nextInt();
        for(int i=1; i<=n; i++){
            A[i]=s.nextInt();
            S[A[i]]=S[A[i]]+A[i];
        }
        long D[]=new long[100005];
        D=S;
        for(int i=99999; i>0; i--){
            if(D[i+1]>D[i+2]+S[i]){
                D[i]=D[i+1];
            }
            else {
                D[i]=D[i+2]+S[i];
            }
        }
        System.out.println(D[1]);
    }

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.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 int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


//package R315;
import java.util.Scanner;
import java.util.TreeMap;
import java.io.IOException;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.InputMismatchException;
import java.util.LinkedList;
import java.util.Map;

public class q3 {
    static int S[]=new int[100005];
    static int A[]=new int[100005];
    static int n;
    public static void main(String args[]){
        FasterScanner s=new FasterScanner();
        n=s.nextInt();
        for(int i=1; i<=n; i++){
            A[i]=s.nextInt();
            S[A[i]]=S[A[i]]+A[i];
        }
        int D[]=new int[100005];
        D=S;
        for(int i=99999; i>0; i--){
            if(D[i+1]>D[i+2]+S[i]){
                D[i]=D[i+1];
            }
            else {
                D[i]=D[i+2]+S[i];
            }
        }
        System.out.println(D[1]);
    }

    public static class FasterScanner {
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;

        public int read() {
            if (numChars == -1)
                throw new InputMismatchException();
            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = System.in.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 int[] nextIntArray(int n) {
            int[] arr = new int[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

        public long[] nextLongArray(int n) {
            long[] arr = new long[n];
            for (int i = 0; i < n; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }

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

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


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;

public class C260 {
	InputStream is;
	PrintWriter out;
	/**
	 * Go to Sublime, copy & pase the input Use Ctrl+A, Ctrl+Shift+L, Ctrl+Enter
	 * to create this string
	 */
	String INPUT = "9\n1 2 1 3 2 2 2 2 3";

	void solve() {
		int n = ni();
		int[] ar = na(n);

		HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			if (!hm.containsKey(ar[i])) {
				hm.put(ar[i], ar[i]);
			} else {
				hm.put(ar[i], hm.get(ar[i]) + ar[i]);
			}
		}
		List<Integer> l = new ArrayList<Integer>(hm.keySet());
		Collections.sort(l);
		long rs = 0;

		long[] dp = new long[l.size()];
		dp[0] = hm.get(l.get(0));

		for(int i = 1; i < l.size(); i++) {
			if(l.get(i) > l.get(i-1) + 1) {
				dp[i] = dp[i-1] + hm.get(l.get(i));
			}else {
				dp[i] = i>=2? Math.max(dp[i-1], dp[i-2] + hm.get(l.get(i))) :
					Math.max(dp[i-1], hm.get(l.get(i)));
			}
		}
		out.println(dp[l.size() - 1]);
	}

	/**
	 * Built using CHelper plug-in Actual solution is at the top
	 */
	static final int INF = (int) 1e9;

	private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private static void debug(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

	static int[][] packD(int n, int[] from, int[] to) {
		int[][] result = new int[n][];
		int[] goOutCount = new int[n];
		for (int f : from)
			goOutCount[f]++;
		for (int i = 0; i < n; i++)
			result[i] = new int[goOutCount[i]];
		for (int i = 0; i < from.length; i++) {
			--goOutCount[from[i]];
			result[from[i]][goOutCount[from[i]]] = to[i];
		}
		return result;
	}

	void run() throws Exception {
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		debug(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new C260().run();
	}

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	/**
	 * Next Double.
	 */
	private double nd() {
		return Double.parseDouble(ns());
	}

	/**
	 * Next Char.
	 */
	private char nc() {
		return (char) skip();
	}

	/**
	 * Next String.
	 */
	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=
									// ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	/**
	 * Next Char array.
	 */
	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	/**
	 * Next Matrix.
	 */
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	/**
	 * Next Array.
	 */
	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	/**
	 * Next Integer.
	 */
	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	/**
	 * Next Long.
	 */
	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;

public class C260 {
	InputStream is;
	PrintWriter out;
	/**
	 * Go to Sublime, copy & pase the input Use Ctrl+A, Ctrl+Shift+L, Ctrl+Enter
	 * to create this string
	 */
	String INPUT = "9\n1 2 1 3 2 2 2 2 3";

	void solve() {
		int n = ni();
		int[] ar = na(n);

		HashMap<Integer, Long> hm = new HashMap<Integer, Long>();
		for (int i = 0; i < n; i++) {
			if (!hm.containsKey(ar[i])) {
				hm.put(ar[i], new Long(ar[i]));
			} else {
				hm.put(ar[i], hm.get(ar[i]) + ar[i]);
			}
		}
		debug(hm);
		List<Integer> l = new ArrayList<Integer>(hm.keySet());
		Collections.sort(l);

		long[] dp = new long[l.size()];
		dp[0] = hm.get(l.get(0));

		for(int i = 1; i < l.size(); i++) {
			if(l.get(i) > l.get(i-1) + 1) {
				dp[i] = dp[i-1] + hm.get(l.get(i));
			}else {
				dp[i] = i>=2? Math.max(dp[i-1], dp[i-2] + hm.get(l.get(i))) :
					Math.max(dp[i-1], hm.get(l.get(i)));
			}
		}
		debug(dp);
		out.println(dp[l.size() - 1]);
	}

	/**
	 * Built using CHelper plug-in Actual solution is at the top
	 */
	static final int INF = (int) 1e9;

	private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private static void debug(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

	static int[][] packD(int n, int[] from, int[] to) {
		int[][] result = new int[n][];
		int[] goOutCount = new int[n];
		for (int f : from)
			goOutCount[f]++;
		for (int i = 0; i < n; i++)
			result[i] = new int[goOutCount[i]];
		for (int i = 0; i < from.length; i++) {
			--goOutCount[from[i]];
			result[from[i]][goOutCount[from[i]]] = to[i];
		}
		return result;
	}

	void run() throws Exception {
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		debug(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new C260().run();
	}

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	/**
	 * Next Double.
	 */
	private double nd() {
		return Double.parseDouble(ns());
	}

	/**
	 * Next Char.
	 */
	private char nc() {
		return (char) skip();
	}

	/**
	 * Next String.
	 */
	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=
									// ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	/**
	 * Next Char array.
	 */
	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	/**
	 * Next Matrix.
	 */
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	/**
	 * Next Array.
	 */
	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	/**
	 * Next Integer.
	 */
	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	/**
	 * Next Long.
	 */
	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
}


import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;

public class C260 {
	InputStream is;
	PrintWriter out;
	/**
	 * Go to Sublime, copy & pase the input Use Ctrl+A, Ctrl+Shift+L, Ctrl+Enter
	 * to create this string
	 */
	String INPUT = "1\n1";

	void solve() {
		int n = ni();
		int[] ar = na(n);

		HashMap<Integer, Integer> hm = new HashMap<Integer, Integer>();
		for (int i = 0; i < n; i++) {
			if (!hm.containsKey(ar[i])) {
				hm.put(ar[i], ar[i]);
			} else {
				hm.put(ar[i], hm.get(ar[i]) + ar[i]);
			}
		}
		List<Integer> l = new ArrayList<Integer>(hm.keySet());
		Collections.sort(l);

//		debug(hm);
		long rs = 0;
		double a = 0;
		double b = 0;
		int turn = 0;
		for (int i = 0; i < l.size(); i++) {

			if (turn == 0) {
				a += hm.get(l.get(i));
				turn = 1;
			} else {
				b += hm.get(l.get(i));
				turn = 0;
			}

			if (i == l.size() - 1 || l.get(i+1) != l.get(i) + 1) {
//				debug(a);
//				debug(b);
				if (a > b) {
					rs += a;
				} else {
					rs += b;
				}

				a = 0;
				b = 0;
				turn = 0;
			}
		}

		out.println(rs);

	}

	/**
	 * Built using CHelper plug-in Actual solution is at the top
	 */
	static final int INF = (int) 1e9;

	private static boolean oj = System.getProperty("ONLINE_JUDGE") != null;

	private static void debug(Object... o) {
		if (!oj)
			System.out.println(Arrays.deepToString(o));
	}

	static int[][] packD(int n, int[] from, int[] to) {
		int[][] result = new int[n][];
		int[] goOutCount = new int[n];
		for (int f : from)
			goOutCount[f]++;
		for (int i = 0; i < n; i++)
			result[i] = new int[goOutCount[i]];
		for (int i = 0; i < from.length; i++) {
			--goOutCount[from[i]];
			result[from[i]][goOutCount[from[i]]] = to[i];
		}
		return result;
	}

	void run() throws Exception {
		is = oj ? System.in : new ByteArrayInputStream(INPUT.getBytes());
		out = new PrintWriter(System.out);

		long s = System.currentTimeMillis();
		solve();
		out.flush();
		debug(System.currentTimeMillis() - s + "ms");
	}

	public static void main(String[] args) throws Exception {
		new C260().run();
	}

	private byte[] inbuf = new byte[1024];
	private int lenbuf = 0, ptrbuf = 0;

	private int readByte() {
		if (lenbuf == -1)
			throw new InputMismatchException();
		if (ptrbuf >= lenbuf) {
			ptrbuf = 0;
			try {
				lenbuf = is.read(inbuf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (lenbuf <= 0)
				return -1;
		}
		return inbuf[ptrbuf++];
	}

	private boolean isSpaceChar(int c) {
		return !(c >= 33 && c <= 126);
	}

	private int skip() {
		int b;
		while ((b = readByte()) != -1 && isSpaceChar(b))
			;
		return b;
	}

	/**
	 * Next Double.
	 */
	private double nd() {
		return Double.parseDouble(ns());
	}

	/**
	 * Next Char.
	 */
	private char nc() {
		return (char) skip();
	}

	/**
	 * Next String.
	 */
	private String ns() {
		int b = skip();
		StringBuilder sb = new StringBuilder();
		while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b !=
									// ' ')
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	/**
	 * Next Char array.
	 */
	private char[] ns(int n) {
		char[] buf = new char[n];
		int b = skip(), p = 0;
		while (p < n && !(isSpaceChar(b))) {
			buf[p++] = (char) b;
			b = readByte();
		}
		return n == p ? buf : Arrays.copyOf(buf, p);
	}

	/**
	 * Next Matrix.
	 */
	private char[][] nm(int n, int m) {
		char[][] map = new char[n][];
		for (int i = 0; i < n; i++)
			map[i] = ns(m);
		return map;
	}

	/**
	 * Next Array.
	 */
	private int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}

	/**
	 * Next Integer.
	 */
	private int ni() {
		int num = 0, b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}

	/**
	 * Next Long.
	 */
	private long nl() {
		long num = 0;
		int b;
		boolean minus = false;
		while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'))
			;
		if (b == '-') {
			minus = true;
			b = readByte();
		}

		while (true) {
			if (b >= '0' && b <= '9') {
				num = num * 10 + (b - '0');
			} else {
				return minus ? -num : num;
			}
			b = readByte();
		}
	}
}


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

public class Boredom {

	public static void main(String[] args) throws IOException {
		Init(System.in);

		int n = nextInt();
		int temp;
		long a[] = new long[(int) (1e5 + 1)];
		for (int i = 0; i < n; ++i) {
			temp = nextInt();
			a[temp] += temp;
		}
		for (int i = 2; i <= 100000; ++i) {
			a[i] = Math.max(a[i - 2] + a[i], a[i - 1]);
		}

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

	static BufferedReader reader;
	static StringTokenizer tokenizer;

	static void Init(InputStream input) {
		reader = new BufferedReader(new InputStreamReader(input));
		tokenizer = new StringTokenizer("");
	}

	static String next() throws IOException {
		while (!tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	static int nextInt() throws IOException {
		return Integer.parseInt(next());
	}

	static long nextLong() throws IOException {
		return Long.parseLong(next());
	}

	static Double NextDouble() throws IOException {
		return Double.parseDouble(next());
	}
}


import java.util.*;
import java.io.*;
public class CF_260_C {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        long count[]=new long[100001];
        for(int i=0;i<n;i++)
            count[in.nextInt()]++;
        long res[][]=new long[100001][2];
        res[0][0]=0;
        res[0][1]=0;
        for(int i=1;i<100001;i++)
        {
            res[i][0]=Math.max(res[i-1][0], res[i-1][1]);
            res[i][1]=res[i-1][0]+count[i]*(long)i;
        }
        out.println(Math.max(res[100000][0], res[100000][1]));
        out.flush();

    }

}


import java.util.*;
import java.io.*;
public class CF_260_C {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        Scanner in=new Scanner(System.in);
        PrintWriter out=new PrintWriter(System.out);
        int n=in.nextInt();
        int count[]=new int[100001];
        for(int i=0;i<n;i++)
            count[in.nextInt()]++;
        long res[][]=new long[100001][2];
        res[0][0]=0;
        res[0][1]=0;
        for(int i=1;i<100001;i++)
        {
            res[i][0]=Math.max(res[i-1][0], res[i-1][1]);
            res[i][1]=res[i-1][0]+count[i]*i;
        }
        out.println(Math.max(res[100000][0], res[100000][1]));
        out.flush();

    }

}


/**
 * Created by Phillip on 8/8/2014.
 */
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[] input = new int[n];
        for(int i=0;i<n;i++){
            input[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(input);
        int current = input[0];
        int numberof = 1;
        for(int i=1;i<n;i++){
            if(input[i]!=current) numberof++;
            current = input[i];
        }
        int[][] stor = new int[2][numberof];
        current = input[0];
        int counter = 1;
        int counter2 = 0;
        for(int i=1;i<n;i++){
            if(input[i]!=current){
                stor[0][counter2] = current;
                stor[1][counter2] = counter;
                current = input[i];
                counter = 1;
                counter2++;
            }
            else{
                counter++;
            }
        }
        stor[0][numberof-1] = current;
        stor[1][numberof-1] = counter;
        int dp[] = new int[numberof];
        dp[0] = stor[0][0]*stor[1][0];
        if(numberof>=2) dp[1] = stor[1][1]*stor[0][1];
        if(numberof>=3) dp[2] = stor[0][2]*stor[1][2] + dp[0];
        for(int i=3;i<numberof;i++){
            dp[i] = stor[0][i]*stor[1][i] + Math.max(dp[i-2],dp[i-3]);
        }
        if(numberof==1) System.out.println(dp[0]);
        else if(numberof==2) System.out.println(Math.max(dp[0],dp[1]));
        else{
            System.out.println(Math.max(dp[numberof-1],dp[numberof-2]));
        }
    }
}


/**
 * Created by Phillip on 8/8/2014.
 */
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[] input = new int[n];
        for(int i=0;i<n;i++){
            input[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(input);
        int current = input[0];
        int numberof = 1;
        for(int i=1;i<n;i++){
            if(input[i]!=current) numberof++;
            current = input[i];
        }
        int[][] stor = new int[2][numberof];
        current = input[0];
        int counter = 1;
        int counter2 = 0;
        for(int i=1;i<n;i++){
            if(input[i]!=current){
                stor[0][counter2] = current;
                stor[1][counter2] = counter;
                current = input[i];
                counter = 1;
                counter2++;
            }
            else{
                counter++;
            }
        }
        stor[0][numberof-1] = current;
        stor[1][numberof-1] = counter;
        long dp[] = new long[numberof];
        dp[0] = stor[0][0]*stor[1][0];
        if(numberof>=2) dp[1] = stor[1][1]*stor[0][1];
        if(numberof>=3) dp[2] = stor[0][2]*stor[1][2] + dp[0];
        for(int i=3;i<numberof;i++){
            dp[i] = stor[0][i]*stor[1][i] + Math.max(dp[i-2],dp[i-3]);
        }
        if(numberof==1) System.out.println(dp[0]);
        else if(numberof==2) System.out.println(Math.max(dp[0],dp[1]));
        else{
            System.out.println(Math.max(dp[numberof-1],dp[numberof-2]));
        }
    }
}


/**
 * Created by Phillip on 8/8/2014.
 */
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        long[] input = new long[100001];
        for(int i=0;i<n;i++){
            input[Integer.parseInt(st.nextToken())]++;
        }
        long[] values = new long[100001];
        for(int i=0;i<100001;i++){
            values[i] = i*input[i];
        }
        long[] dp = new long[100001];
        dp[0] = 0;
        dp[1] = values[1];
        dp[2] = values[2];
        for(int i=3;i<100001;i++){
            dp[i] = values[i] + Math.max(dp[i-2],dp[i-3]);
        }
        System.out.println(Math.max(dp[100000],dp[99999]));
    }
}


/**
 * Created by Phillip on 8/8/2014.
 */
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws IOException{
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(in.readLine());
        StringTokenizer st = new StringTokenizer(in.readLine());
        int[] input = new int[n];
        for(int i=0;i<n;i++){
            input[i] = Integer.parseInt(st.nextToken());
        }
        Arrays.sort(input);
        int current = input[0];
        int numberof = 1;
        for(int i=1;i<n;i++){
            if(input[i]!=current) numberof++;
            current = input[i];
        }
        int[][] stor = new int[2][numberof];
        current = input[0];
        int counter = 1;
        int counter2 = 0;
        for(int i=1;i<n;i++){
            if(input[i]!=current){
                stor[0][counter2] = current;
                stor[1][counter2] = counter;
                current = input[i];
                counter = 1;
                counter2++;
            }
            else{
                counter++;
            }
        }
        stor[0][numberof-1] = current;
        stor[1][numberof-1] = counter;
        long dp[] = new long[numberof];
        dp[0] = (long)stor[0][0]*stor[1][0];
        if(numberof>=2) dp[1] = (long)stor[1][1]*stor[0][1];
        if(numberof>=3) dp[2] = (long)stor[0][2]*stor[1][2] + dp[0];
        for(int i=3;i<numberof;i++){
            dp[i] = (long)stor[0][i]*stor[1][i] + Math.max(dp[i-2],dp[i-3]);
        }
        if(numberof==1) System.out.println(dp[0]);
        else if(numberof==2) System.out.println(Math.max(dp[0],dp[1]));
        else{
            System.out.println(Math.max(dp[numberof-1],dp[numberof-2]));
        }
    }
}


import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R260_Div2_C
{
	FastReader in;
	PrintWriter out;

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

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int n = in.nextInt();

		int[] a = new int[n];
		int[] c = new int[100_001];
		for (int i = 0; i < n; i++)
		{
			a[i] = in.nextInt();
			c[a[i]]++;
		}

		Arrays.sort(a);
		long sum = 0;

		for (int i = 100_000; i > 0; i--)
		{
			if (c[i] > 0)
			{
				long cnt1 = c[i] * i - c[i-1] * (i-1);
				long cnt2 = c[i-1] * (i-1) - c[i]*i;
				if (i > 2) cnt2 -= c[i-2] * (i-2);
				if (cnt1 >= cnt2)
				{
					sum += c[i] * i;
					c[i] = 0; c[i-1] = 0;
				}
				else
				{
					sum += c[i-1] * (i-1);
					c[i] = 0; c[i-1] = 0;
					if (i > 2) c[i-2] = 0;
				}
			}
		}

		out.println(sum);
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

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

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}


import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R260_Div2_C
{
	FastReader in;
	PrintWriter out;

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

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int n = in.nextInt();

		int[] a = new int[n];
		long[] c = new long[100_001];
		for (int i = 0; i < n; i++)
		{
			a[i] = in.nextInt();
			c[a[i]]++;
		}

		//Arrays.sort(a);
		long sum = 0;

		for (int i = 100_000; i > 0; i--)
		{
			if (c[i] > 0)
			{
				long cnt1 = c[i] * i;
				if (i > 2) cnt1 += c[i-2] * (i-2);
				long cnt2 = c[i-1] * (i-1);
				if (cnt1 > cnt2)
				{
					sum += c[i] * i;
					c[i] = 0; c[i-1] = 0;
				}
				else
				{
					sum += c[i-1] * (i-1);
					c[i] = 0; c[i-1] = 0;
					if (i > 2) c[i-2] = 0;
				}
			}
		}

		out.println(sum);
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

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

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}


import java.io.*;    //PrintWriter
import java.math.*;  //BigInteger, BigDecimal
import java.util.*;  //StringTokenizer, ArrayList

public class R260_Div2_C //Name: Boredom
{
	//Fails at Pretest #11. Need to use dp it seems.
	FastReader in;
	PrintWriter out;

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

	void run()
	{
		in = new FastReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.close();
	}

	void solve()
	{
		int n = in.nextInt();

		int[] a = new int[n];
		long[] c = new long[100_001];
		long[] f = new long[100_001];
		for (int i = 0; i < n; i++)
		{
			a[i] = in.nextInt();
			c[a[i]]++;
		}

		//for (int i = 1; i <= 10; i++)
		//	out.println(i + " " + c[i]);

		f[1] = c[1];
		for (int i = 2; i <= 100_000; i++)
			f[i] = Math.max(f[i-1], f[i-2] + c[i]*i);

		out.println(f[100_000]);
	}

	//-----------------------------------------------------
	void runWithFiles() {
		in = new FastReader(new File("input.txt"));
		try {
			out = new PrintWriter(new File("output.txt"));
		}
		catch (FileNotFoundException e) {
			e.printStackTrace();
		}
		solve();
		out.close();
	}

	class FastReader
	{
	    BufferedReader br;
	    StringTokenizer tokenizer;

	    public FastReader(InputStream stream)
	    {
	        br = new BufferedReader(new InputStreamReader(stream));
	        tokenizer = null;
	    }
		public FastReader(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
				tokenizer = null;
			}
			catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

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

	    int nextInt() {
	        return Integer.parseInt(next());
	    }
	    long nextLong() {
	        return Long.parseLong(next());
	    }
	    double nextDouble() {
	        return Double.parseDouble(next());
	    }
	    BigInteger nextBigInteger() {
	        return new BigInteger(next());
	    }
	    BigDecimal nextBigDecimal() {
	        return new BigDecimal(next());
	    }
	}
}