#include <bits/stdc++.h>
using namespace std;
const int INF = 999999999;
const int maxn = 1e5 + 5;
const int minm = -0x7;
const long long mod = 10000007;
const double ABS = 1e-6;
long long dp[505][6005], h[505];
int n, K;
void init(void) {
  for (int i = 1; i <= n; i++) {
    for (int res = 0; res <= n * K; res++) {
      for (int j = 0; j <= K; j++) {
        dp[i][res + j] = max(dp[i][res + j], dp[i - 1][res] + h[j]);
      }
    }
  }
}
int cnt1[maxn], cnt2[maxn];
int main() {
  int x;
  cin >> n >> K;
  for (int i = 0; i < n * K; i++) {
    scanf("%d", &x);
    cnt1[x]++;
  }
  for (int i = 0; i < n; i++) {
    scanf("%d", &x);
    cnt2[x]++;
  }
  for (int i = 1; i <= K; i++) cin >> h[i];
  init();
  long long ans = 0;
  for (int i = 1; i < maxn; i++) {
    if (cnt2[i] != 0) ans += dp[cnt2[i]][cnt1[i]];
  }
  cout << ans << endl;
}
