#include <bits/stdc++.h>
using namespace std;
int n, k;
int c[5005], h[11], f[505];
int cnt[100005];
int fcnt[100005];
int cache[5005][505];
int solve(int idx1, int idx2) {
  if (idx1 == 0 || idx2 == 0) return 0;
  int &ret = cache[idx1][idx2];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 0; i <= k && i <= idx1; i++)
    ret = max(ret, solve(idx1 - i, idx2 - 1) + h[i]);
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n * k; i++) {
    scanf("%d", &c[i]);
    cnt[c[i]]++;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &f[i]);
    fcnt[f[i]]++;
  }
  for (int i = 1; i <= k; i++) scanf("%d", &h[i]);
  int ans = 0;
  for (int i = 0; i < 100005; i++) {
    if (fcnt[i]) {
      memset(cache, -1, sizeof(cache));
      ans += solve(cnt[i], fcnt[i]);
    }
  }
  printf("%d\n", ans);
  return 0;
}
