#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int MAXN = 1e5 + 10;
const int MAXM = 2e6 + 10;
const long long mod = 1e9 + 7;
long long dp[510][5010];
int f[510], h[15];
int num[MAXN], player[MAXN];
bool vis[MAXN];
int main() {
  memset((dp), (0), sizeof(dp));
  memset((num), (0), sizeof(num));
  memset((player), (0), sizeof(player));
  memset((vis), (false), sizeof(vis));
  int n, k;
  scanf("%d%d", &n, &k);
  int m = n * k;
  for (int i = 0; i < m; i++) {
    int c;
    scanf("%d", &c);
    num[c]++;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &f[i]);
    player[f[i]]++;
  }
  h[0] = 0;
  for (int i = 1; i <= k; i++) scanf("%d", &h[i]);
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    if (vis[f[i]]) continue;
    vis[f[i]] = true;
    memset((dp), (0), sizeof(dp));
    long long maxx = 0;
    for (int j = 0; j <= min(k, num[f[i]]); j++) {
      dp[1][j] = (long long)h[j];
      maxx = max(maxx, (long long)h[j]);
    }
    for (int j = 2; j <= player[f[i]]; j++) {
      for (int l = 0; l <= min(j * k, num[f[i]]); l++) {
        for (int g = 0; g <= min(k, l); g++) {
          dp[j][l] = max(dp[j][l], dp[j - 1][l - g] + (long long)h[g]);
          maxx = max(maxx, dp[j][l]);
        }
      }
    }
    ans += maxx;
  }
  printf("%lld\n", ans);
  return 0;
}
