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).
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.
5 3
4 2 1 10 5
apple
orange
mango
7 19
6 5
3 5 1 6 8 1
peach
grapefruit
banana
orange
orange
11 30
2 2
91 82
eiiofpfpmemlakcystpun
mcnzeiiofpfpmemlakcystpunfl
173 173
1 4
1
u
u
u
u
4 4
3 3
4 2 3
wivujdxzjm
awagljmtc
wivujdxzjm
7 11
3 4
10 10 10
odchpcsdhldqnkbhwtwnx
ldqnkbhwtwnxk
odchpcsdhldqnkbhwtwnx
ldqnkbhwtwnxk
40 40
3 1
14 26 22
aag
14 26
2 2
5 5
dcypj
piyqiagzjlvbhgfndhfu
10 10
4 3
5 3 10 3
xzjhplrzkbbzkypfazf
xzjhplrzkbbzkypfazf
h
9 25
5 5
10 10 6 7 9
iyerjkvzibxhllkeuagptnoqrzm
vzibxhllkeuag
iyerjkvzibxhllkeuagptnoqrzm
noq
noq
35 49
10 8
19 18 20 13 19 13 11 10 19 16
kayangqlsqmcd
qls
qydawlbludrgrjfjrhd
fjrh
qls
qls
rnmmayh
kayangqlsqmcd
94 154
5 15
61 56 95 42 85
oq
dwxivk
txdxzsfdj
oq
oq
dwxivk
txdxzsfdj
dwxivk
txdxzsfdj
k
k
dwxivk
oq
k
txdxzsfdj
891 1132
12 18
42 44 69 16 81 64 12 68 70 75 75 67
fm
qamklzfmrjnqgdspwfasjnplg
qamklzfmrjnqgdspwfasjnplg
qamklzfmrjnqgdspwfasjnplg
l
l
l
fm
qamklzfmrjnqgdspwfasjnplg
l
nplgwotfm
p
l
amklzfm
tkpubqamklzfmrjn
pwf
fm
p
606 1338
24 24
34 69 89 45 87 30 78 14 53 16 27 54 75 95 10 69 80 71 43 3 91 9 8 7
swtcofrcpeyszydwkrg
szyd
peyszyd
rcpeyszydwkrgfj
peyszydwkrgf
zydw
smzginydyrtua
j
j
tzwsw
gfj
yssoqnlpsm
inydyrtuatzw
inydy
lpsmzginydyrtuatzwswtcofrcpeyszy
yssoqnlpsm
peyszyd
yssoqnlpsm
inydy
peyszyd
inydyrtuatzw
at
fj
swtcofrcpeyszydwkrg
552 1769
from collections import defaultdict

N, M = map( int, input().split() )
A = list( map( int, input().split() ) )
A.sort()
minv, maxv = 0, 0

cnt = defaultdict( int )
for i in range( M ):
  fruit = input()
  cnt[ fruit ] += 1

B = [ cnt[ key ] for key in cnt ]
B.sort()

for i in range( len( B ) ):
  minv += A[ i ] * B[ len( B ) - 1 - i ]
  maxv += A[ len( A ) - 1 - i ] * B[ len( B ) - 1 - i ]

print( minv, maxv )
