Petya has n positive integers a1, a2, ..., an. 

His friend Vasya decided to joke and replaced all digits in Petya's numbers with a letters. He used the lowercase letters of the Latin alphabet from 'a' to 'j' and replaced all digits 0 with one letter, all digits 1 with another letter and so on. For any two different digits Vasya used distinct letters from 'a' to 'j'.

Your task is to restore Petya's numbers. The restored numbers should be positive integers without leading zeros. Since there can be multiple ways to do it, determine the minimum possible sum of all Petya's numbers after the restoration. It is guaranteed that before Vasya's joke all Petya's numbers did not have leading zeros.

Input

The first line contains a single integer n (1 ≤ n ≤ 1 000) — the number of Petya's numbers.

Each of the following lines contains non-empty string si consisting of lowercase Latin letters from 'a' to 'j' — the Petya's numbers after Vasya's joke. The length of each string does not exceed six characters.

Output

Determine the minimum sum of all Petya's numbers after the restoration. The restored numbers should be positive integers without leading zeros. It is guaranteed that the correct restore (without leading zeros) exists for all given tests.

Examples

Input

3
ab
de
aj


Output

47


Input

5
abcdef
ghij
bdef
accbd
g


Output

136542


Input

3
aa
jj
aa


Output

44

Note

In the first example, you need to replace the letter 'a' with the digit 1, the letter 'b' with the digit 0, the letter 'd' with the digit 2, the letter 'e' with the digit 3, and the letter 'j' with the digit 4. So after the restoration numbers will look like [10, 23, 14]. The sum of them is equal to 47, which is the minimum possible sum of the numbers after the correct restoration.

In the second example the numbers after the restoration can look like: [120468, 3579, 2468, 10024, 3]. 

In the second example the numbers after the restoration can look like: [11, 22, 11]. 
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.io.BufferedWriter;
import java.util.Set;
import java.util.InputMismatchException;
import java.io.IOException;
import java.util.HashSet;
import java.io.Writer;
import java.io.OutputStreamWriter;
import java.util.Comparator;
import java.io.InputStream;

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

    static class TaskC {
        public void solve(int testNumber, InputReader in, OutputWriter out) {
            int n = in.nextInt();
            char[][] strings = new char[n][6];

            Set<Character> msb = new HashSet<>();
            for (int i = 0; i < 10; i++) {
                msb.add(((char) ('a' + i)));
            }

            Tuple[] tuples = new Tuple[10];
            for (int i = 0; i < 10; i++) {
                tuples[i] = new Tuple((char) (i + 'a'));
            }

            for (int i = 0; i < n; i++) {
                String s = in.nextString();
                msb.remove(s.charAt(0));

                int k = 5;
                for (int j = s.length() - 1; j >= 0; j--) {
                    strings[i][k] = s.charAt(j);
                    tuples[s.charAt(j) - 'a'].x = s.charAt(j);
                    tuples[s.charAt(j) - 'a'].f[k]++;
                    k--;
                }
                for (int j = 0; j <= k; j++) {
                    strings[i][j] = ' ';
                }
            }

        /*for (int i = 0; i < 10; i++) {
            out.println(tuples[i]);
            }
        */

            int[] map = new int[10];
            Arrays.fill(map, -1);

            if (msb.size() > 0) {
                Tuple[] tuples2 = new Tuple[msb.size()];
                int k = 0;
                for (char c : msb) {
                    tuples2[k++] = tuples[c - 'a'];
                }

                Arrays.sort(tuples2, new Comparator<Tuple>() {

                    public int compare(Tuple o1, Tuple o2) {
                    /*int i = 1;
                    for (; i < 6; i++) {
                        if (o1.f[i] != o2.f[i]) {
                            break;
                        }
                    }
                    if (i == 6) {
                        return Integer.compare(o1.f[1], o2.f[1]);
                    } else {
                        return Integer.compare(o1.f[i], o2.f[i]);
                    }*/
                        return Long.compare(o1.func(), o2.func());
                    }
                });

                map[tuples2[msb.size() - 1].x - 'a'] = 0;
            }

            Arrays.sort(tuples, new Comparator<Tuple>() {

                public int compare(Tuple o1, Tuple o2) {
                /*int i = 0;
                for (; i < 6; i++) {
                    if (o1.f[i] != o2.f[i]) {
                        break;
                    }
                }
                if (i == 6) {
                    return Integer.compare(o1.f[0], o2.f[0]);
                } else {
                    return Integer.compare(o1.f[i], o2.f[i]);
                }*/

                    return Long.compare(o1.func(), o2.func());
                }
            });

        /*out.println("\nAfter sorting");
        for (int i = 0; i < 10; i++) {
            out.println(tuples[i]);
        }*/


//        Arrays.fill(map, -1);
//        boolean isZeroAssigned = false;
            int num = 1;

            for (int i = 9; i >= 0; i--) {
                char c = tuples[i].x;
                int idx = c - 'a';
//            if (!isZeroAssigned && !msb.contains(c)) {
//                isZeroAssigned = true;
//                map[idx] = 0;
//            } else {
                if (map[idx] == -1)
                    map[idx] = num++;
//            }
            }

        /*tuples.sort(new Comparator<Tuple>() {
            @Override
            public int compare(Tuple o1, Tuple o2) {
                return 0;
            }
        });*/

        /*int[] map = new int[10];
        Arrays.fill(map, -1);
        boolean isZeroAssigned = false;
        int num = 1;

        for (int i = 0; i < 6; i++) {
            Map<Character, Integer> freq = new HashMap<>();
            for (int j = 0; j < n; j++) {
                char c = strings[j][i];
                if (c >= 'a' && c <= 'j' && map[c - 'a'] == -1) {
                    freq.put(c, freq.getOrDefault(c, 0) + 1);
                }
            }

            List<Map.Entry<Character, Integer>> list = new ArrayList<>(freq.entrySet());
            list.sort(new Comparator<Map.Entry<Character, Integer>>() {
                @Override
                public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
                    return Integer.compare(o2.getValue(), o1.getValue());
                }
            });

            for (Map.Entry<Character, Integer> e : list) {
                if (!isZeroAssigned && !msb.contains(e.getKey())) {
                    isZeroAssigned = true;
                    map[e.getKey() - 'a'] = 0;
                } else {
                    map[e.getKey() - 'a'] = num++;
                }
            }
            if (num == 10 && isZeroAssigned) {
                break;
            }
        }*/

            long sum = 0L;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < 6; j++) {
                    if (strings[i][j] == ' ') {
                        strings[i][j] = '0';
                    } else {
                        int idx = strings[i][j] - 'a';
                        strings[i][j] = (char) ('0' + map[idx]);
                    }
                }
                sum += Long.parseLong(String.valueOf(strings[i]));
            }
            out.println(sum);
        }

    }

    static class OutputWriter {
        private final PrintWriter writer;

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

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

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

        public void println(long i) {
            writer.println(i);
        }

    }

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

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

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

        public int 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 String nextString() {
            int c = read();
            while (isSpaceChar(c)) {
                c = read();
            }
            StringBuilder res = new StringBuilder();
            do {
                if (Character.isValidCodePoint(c)) {
                    res.appendCodePoint(c);
                }
                c = read();
            } while (!isSpaceChar(c));
            return res.toString();
        }

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

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

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

        }

    }

    static class Tuple {
        char x;
        int[] f;

        public Tuple(char x) {
            this.x = x;
            f = new int[6];
        }


        public String toString() {
            return "Tuple{" +
                    "x=" + x +
                    ", f=" + Arrays.toString(f) +
                    '}';
        }

        public long func() {
            long x = 0L;
            long m = 1L;
            for (int i = 5; i >= 0; i--) {
                x += m * f[i];
                m = m * 10L;
            }
            return x;
        }

    }
}

