#include <bits/stdc++.h>
using namespace std;
long long t = 1, n, k, c, f, h[15], frq_c[100010], frq_f[100010], dp[505][5005],
          ans;
long long rec(int person, long long card) {
  if (person == 0) return (card ? -1e9 : 0);
  long long &ret = dp[person][card];
  if (ret + 1) return ret;
  ret = 0;
  for (int i = 0; i <= min(card, k); i++)
    ret = max(ret, rec(person - 1, card - i) + h[i]);
  return ret;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n * k; i++) cin >> c, frq_c[c]++;
  for (int i = 0; i < n; i++) cin >> f, frq_f[f]++;
  for (int i = 1; i <= k; i++) cin >> h[i];
  for (int i = 0; i < 100010; i++)
    if (frq_c[i] && frq_f[i])
      memset(dp, -1, sizeof dp),
          ans += rec(frq_f[i], min(frq_c[i], frq_f[i] * k));
  cout << ans << '\n';
  return 0;
}
