The spring is coming and it means that a lot of fruits appear on the counters. One sunny day little boy Valera decided to go shopping. He made a list of m fruits he wanted to buy. If Valera want to buy more than one fruit of some kind, he includes it into the list several times. 

When he came to the fruit stall of Ashot, he saw that the seller hadn't distributed price tags to the goods, but put all price tags on the counter. Later Ashot will attach every price tag to some kind of fruits, and Valera will be able to count the total price of all fruits from his list. But Valera wants to know now what can be the smallest total price (in case of the most «lucky» for him distribution of price tags) and the largest total price (in case of the most «unlucky» for him distribution of price tags).

Input

The first line of the input contains two integer number n and m (1 ≤ n, m ≤ 100) — the number of price tags (which is equal to the number of different kinds of fruits that Ashot sells) and the number of items in Valera's list. The second line contains n space-separated positive integer numbers. Each of them doesn't exceed 100 and stands for the price of one fruit of some kind. The following m lines contain names of the fruits from the list. Each name is a non-empty string of small Latin letters which length doesn't exceed 32. It is guaranteed that the number of distinct fruits from the list is less of equal to n. Also it is known that the seller has in stock all fruits that Valera wants to buy.

Output

Print two numbers a and b (a ≤ b) — the minimum and the maximum possible sum which Valera may need to buy all fruits from his list.

Examples

Input

5 3
4 2 1 10 5
apple
orange
mango


Output

7 19


Input

6 5
3 5 1 6 8 1
peach
grapefruit
banana
orange
orange


Output

11 30
import java.awt.Point;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

import javax.management.IntrospectionException;
import javax.swing.colorchooser.ColorSelectionModel;
import javax.xml.soap.MimeHeader;

import static java.lang.Math.*;
import static java.lang.Math.min;
import java.math.BigDecimal;
import java.math.RoundingMode;

public class Main {

    final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
    BufferedReader in;
    PrintWriter out;
    StringTokenizer tok = new StringTokenizer("");

    void init() throws FileNotFoundException {
        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");
        }
    }

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

    int readInt() throws IOException {
        return Integer.parseInt(readString());
    }

    long readLong() throws IOException {
        return Long.parseLong(readString());
    }

    double readDouble() throws IOException {
        return Double.parseDouble(readString());
    }

    public static void main(String[] args) {
        new Main().run();
        // Sworn to fight and die
    }

    public static void mergeSort(int[] a) {
        mergeSort(a, 0, a.length - 1);
    }

    private static void mergeSort(int[] a, int levtIndex, int rightIndex) {
        final int MAGIC_VALUE = 50;
        if (levtIndex < rightIndex) {
            if (rightIndex - levtIndex <= MAGIC_VALUE) {
                insertionSort(a, levtIndex, rightIndex);
            } else {
                int middleIndex = (levtIndex + rightIndex) / 2;
                mergeSort(a, levtIndex, middleIndex);
                mergeSort(a, middleIndex + 1, rightIndex);
                merge(a, levtIndex, middleIndex, rightIndex);
            }
        }
    }

    private static void merge(int[] a, int levtIndex, int middleIndex,
                              int rightIndex) {
        int length1 = middleIndex - levtIndex + 1;
        int length2 = rightIndex - middleIndex;
        int[] levtArray = new int[length1];
        int[] rightArray = new int[length2];
        System.arraycopy(a, levtIndex, levtArray, 0, length1);
        System.arraycopy(a, middleIndex + 1, rightArray, 0, length2);
        for (int k = levtIndex, i = 0, j = 0; k <= rightIndex; k++) {
            if (i == length1) {
                a[k] = rightArray[j++];
            } else if (j == length2) {
                a[k] = levtArray[i++];
            } else {
                a[k] = levtArray[i] <= rightArray[j] ? levtArray[i++]
                        : rightArray[j++];
            }
        }
    }

    private static void insertionSort(int[] a, int levtIndex, int rightIndex) {
        for (int i = levtIndex + 1; i <= rightIndex; i++) {
            int current = a[i];
            int j = i - 1;
            while (j >= levtIndex && a[j] > current) {
                a[j + 1] = a[j];
                j--;
            }
            a[j + 1] = current;
        }
    }

    public void run() {
        try {
            long t1 = System.currentTimeMillis();
            init();
            solve();
            out.close();
            long t2 = System.currentTimeMillis();
            System.err.println("Time = " + (t2 - t1));
        } catch (Exception e) {
            e.printStackTrace(System.err);
            System.exit(-1);
        }
    }

    class LOL implements Comparable<LOL> {

        int x;
        int y;



        public LOL(int x, int y) {
            this.x = x;
            this.y = y;

        }

        @Override
        public int compareTo(LOL o) {

            return (x - o.x); // ---->
            //return o.x * o.y - x * y; // <----
        }

    }

    class test implements Comparable<test> {

        int x;
        int y;



        public test(int x, int y) {
            this.x = x;
            this.y = y;

        }

        @Override
        public int compareTo(test o) {

            return (x - o.x); // ---->
            //return o.x * o.y - x * y; // <----
        }

    }

    class record implements Comparable<record> {
        String name;
        int price;

        public record(String name, int score) {
            this.name = name;
            this.price = score;
        }

        @Override
        public int compareTo(record o) {
            return (o.price - price);
        }

    }

    public long gcd(long a, long b) {
        if (a % b == 0)
            return b;
        else
            return gcd(b, a % b);
    }

    public int gcd(int a, int b) {
        if (a % b == 0)
            return b;
        else
            return gcd(b, a % b);
    }


    boolean prime(int n) {
        for (int i = 2; i <= sqrt(n); i++)
            if (n % i == 0)
                return false;
        return true;
    }

    public double factorial (int n) {
        double result = 1;
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }

    int[][] a;

    public int findSum (int i, int j, int k, int t) {
        int sum = 0;

        for (int newI = k; newI < k + i; newI++) {
            for (int newJ = t; newJ < t + j; newJ++) {
                sum += a[newI][newJ];
            }
        }

        return sum;
    }

    public long search (long left, long right, long x) {
        long mid = (left + right) / 2;

        if (mid * mid <= x && (mid + 1) * (mid + 1) > x) {
            return mid;
        }

        if (mid * mid > x) {
            return search(left, mid, x);
        } else {
            return search(mid, right, x);
        }

    }


    public void solve() throws IOException {


        int n = readInt();
        int m = readInt();

        ArrayList<Integer> prices = new ArrayList<Integer>();

        for (int i = 0; i < n; i++) {
            prices.add(readInt());
        }

        Map<String, Integer> fruits = new HashMap<String, Integer>();


        for (int i = 0; i < m; i++) {
            String name = readString();

            if (!fruits.containsKey(name)) {
                fruits.put(name, 1);
            } else {
                int currNum = fruits.get(name);
                fruits.put(name, currNum + 1);
            }
        }

        int size = fruits.size();

        record[] records = new record[size];
        int index = 0;
        for (String name: fruits.keySet()) {
            records[index] = new record(name, fruits.get(name));
            index += 1;
        }

        Arrays.sort(records);

        Collections.sort(prices);

        int minAns = 0;

        for (int i = 0; i < size; i++) {
            minAns += (prices.get(i) * records[i].price);
        }

        int maxAns = 0;

        Collections.sort(prices, Collections.reverseOrder());

        for (int i = 0; i < size; i++) {
            maxAns += (prices.get(i) * records[i].price);
        }

        out.print(minAns + " " + maxAns);



    }
}