#include <bits/stdc++.h>
using namespace std;
const int MAXK = 10;
const int MAXN = 500;
const int MAXC = 100000;
int n, k, h[MAXK + 2], ans;
int cnt[MAXC + 2], p[MAXC + 2];
int dp[MAXN + 2][MAXN * MAXK + 2];
vector<int> like;
inline void read(int &x) {
  x = 0;
  char c = getchar();
  bool f = 0;
  if (c == '-') f = 1;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
}
int main() {
  read(n);
  read(k);
  for (int i = 1; i <= n * k; i++) {
    int c;
    read(c);
    cnt[c]++;
  }
  for (int i = 1; i <= n; i++) {
    int f;
    read(f);
    if (!p[f]) like.push_back(f);
    p[f]++;
  }
  for (int i = 1; i <= k; i++) read(h[i]);
  for (int l = 0; l < like.size(); l++) {
    int u = like[l];
    int o = min(p[u] * k, cnt[u]);
    for (int i = 1; i <= p[u]; i++)
      for (int j = 0; j <= min(i * k, o); j++)
        for (int r = 0; r <= min(j, k); r++)
          dp[i][j] = max(dp[i][j], dp[i - 1][j - r] + h[r]);
    ans += dp[p[u]][o];
  }
  printf("%d\n", ans);
}
