#include <bits/stdc++.h>
using namespace std;
const int N = (int)500 + 11;
const int M = (int)5000 + 11;
const int mod = (int)1e9 + 7;
const int inf = 0x3f3f3f3f;
map<int, int> cnt, ge;
map<int, int>::iterator it;
int h[N];
long long dp[M][N];
long long solve(long long k, long long x, long long y) {
  for (int i = 0; i <= y; i++) {
    for (int j = 0; j <= x; j++) {
      dp[i][j] = 0;
    }
  }
  for (int i = 1; i <= y; i++) {
    for (int j = 1; j <= x; j++) {
      for (int u = 1; u <= i && u <= k; u++) {
        dp[i][j] = max(dp[i][j], dp[i - u][j - 1] + h[u]);
      }
    }
  }
  return dp[y][x];
}
void init(long long n, long long k) {
  for (int i = 1; i <= n * k; i++) {
    for (int j = 1; j <= n; j++) {
      for (int u = 1; u <= i && u <= k; u++) {
        dp[i][j] = max(dp[i][j], dp[i - u][j - 1] + h[u]);
      }
    }
  }
}
int main() {
  long long n, k;
  scanf("%lld%lld", &n, &k);
  for (int i = 0; i < n * k; i++) {
    int val;
    scanf("%d", &val);
    cnt[val]++;
  }
  for (int i = 0; i < n; i++) {
    int f;
    scanf("%d", &f);
    ge[f]++;
  }
  for (int i = 1; i <= k; i++) scanf("%d", &h[i]);
  init(n, k);
  long long ans = 0;
  for (it = ge.begin(); it != ge.end(); it++) {
    ans += dp[cnt[it->first]][it->second];
  }
  printf("%lld", ans);
  return 0;
}
