#include <bits/stdc++.h>   using namespace std;   int n, m;   int a[107];   map<string, int> f;   vector<pair<int, string>> b;   bool cmp(pair<int, string> u, pair<int, string> v) { return u.first > v.first; }   int main() {     cin >> n >> m;     for (int i = 1; i <= n; i++) cin >> a[i];     for (int i = 1; i <= m; i++) {       string s;       cin >> s;       if (f[s] == 0)         f[s] = 1;       else         f[s]++;     }     sort(a + 1, a + n + 1);     for (map<string, int>::iterator it = f.begin(); it != f.end(); ++it) {       b.push_back(make_pair(it->second, it->first));     }     sort(b.begin(), b.end(), cmp);     long long minP = 0, maxP = 0;     for (int i = 0; i < b.size(); i++) {       minP += b[i].first * a[i + 1];       maxP += b[i].first * a[n - i];     }     cout << minP <<     << maxP << endl;   }   