#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 2;
const long long N1 = 1e2 + 2;
const long long mod = 1e9 + 7;
const int MASK = 1 << 17 + 1;
const int who = 6 * N * log2(N);
long long power(long long a, long long b, long long c) {
  long long ret = 1;
  while (b) {
    if (b % 2 == 1) {
      ret = (ret * a) % c;
    }
    b /= 2;
    a = (a * a) % c;
  }
  return ret;
}
map<int, int> ma, ma1;
int n, k, m;
int lev[13];
int dp[501][5001];
int calc(int count, int tot_avail) {
  if (count <= 1) {
    if (!count) return 0;
    return lev[min(tot_avail, k)];
  }
  if (dp[count][tot_avail] != -1) {
    return dp[count][tot_avail];
  }
  int solve = 0;
  for (int i = 1; i <= min(k, tot_avail); i++) {
    solve = max(solve, lev[i] + calc(count - 1, tot_avail - i));
  }
  return dp[count][tot_avail] = solve;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  m = n * k;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < m; i++) {
    int tm;
    cin >> tm;
    ma[tm]++;
  }
  for (int i = 0; i < n; i++) {
    int tm;
    cin >> tm;
    ma1[tm]++;
  }
  lev[0] = 0;
  for (int i = 1; i <= k; i++) {
    cin >> lev[i];
  }
  long long ans = 0;
  for (auto it : ma1) {
    int var = it.second;
    int temp = it.first;
    if (var <= 1) {
      ans += lev[min(ma[temp], k)];
      continue;
    }
    ans += calc(var, ma[temp]);
  }
  cout << ans << "\n";
}
