#include <bits/stdc++.h>
inline int scan() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void Out(int a) {
  if (a < 0) {
    putchar('-');
    a = -a;
  }
  if (a >= 10) Out(a / 10);
  putchar(a % 10 + '0');
}
using namespace std;
const int maxn = 100005;
long long f[maxn];
long long h[maxn];
long long sum[maxn];
long long c[maxn];
long long dp[5005][505];
long long ji = 0;
map<long long, long long> M;
struct A {
  long long num1;
  long long num2;
};
A node[maxn];
int n, k;
int main() {
  ios::sync_with_stdio(false);
  cin >> n >> k;
  for (long long i = 1; i <= n * k; i++) {
    cin >> c[i];
    sum[c[i]]++;
  }
  for (long long i = 1; i <= n; i++) {
    cin >> f[i];
    if (M[f[i]] == 0) {
      M[f[i]] = ++ji;
      node[M[f[i]]].num1++;
      node[M[f[i]]].num2 = sum[f[i]];
    } else {
      node[M[f[i]]].num1++;
    }
  }
  for (long long i = 1; i <= k; i++) cin >> h[i];
  for (int i = 1; i <= n * k; i++) {
    dp[i][1] = h[min(i, k)];
    for (int j = 2; j <= n; j++)
      for (int u = 1; i - u >= 0 && u <= k; u++)
        dp[i][j] = max(dp[i][j], dp[i - u][j - 1] + h[u]);
  }
  long long ans = 0;
  for (long long i = 1; i <= ji; i++) {
    ans += dp[node[i].num2][node[i].num1];
  }
  cout << ans << endl;
  return 0;
}
