#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x = 0;
  register bool f = 0;
  register char ch = getchar();
  while (!isdigit(ch)) {
    f ^= !(ch ^ '-');
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = ((x + (x << 2)) << 1) + (ch ^ '0');
    ch = getchar();
  }
  return f ? -x : x;
}
inline void print(int x) {
  register int sc[30] = {0}, tot = 0;
  do {
    sc[++tot] = x % 10;
    x /= 10;
  } while (x);
  while (tot) putchar('0' + sc[tot--]);
}
int n, maxn, k, ans;
int peo[510 * 510], tot[510 * 510], h[510];
int dp[5010][5010];
int main() {
  n = read();
  k = read();
  for (register int i = 1; i <= n * k; i++) {
    int tmp = read();
    tot[tmp]++;
    maxn = max(maxn, tmp);
  }
  for (register int i = 1; i <= n; i++) {
    int tmp = read();
    peo[tmp]++;
  }
  for (register int i = 1; i <= k; i++) h[i] = read();
  for (register int i = 1; i <= n; i++)
    for (register int j = 1; j <= n * k; j++)
      for (register int l = 1; l <= min(j, k); l++)
        dp[i][j] = max(dp[i][j], dp[i - 1][j - l] + h[l]);
  for (register int i = 1; i <= maxn; i++)
    if (peo[i]) ans += dp[peo[i]][tot[i]];
  printf("%d\n", ans);
  return 0;
}
