#include <bits/stdc++.h>
using namespace std;
const int maxk = 20;
const int maxn = 500 + 10;
const int maxnum = 1e6 + 10;
int dp[maxn][maxn * maxk];
int n, K;
int a[maxn * maxk], val[maxk];
inline void DP(int ned, int cnt) {
  memset(dp, -1, sizeof dp);
  dp[0][0] = 0;
  for (int i = 1; i <= ned; ++i) {
    for (int j = 0; j <= i * K; ++j) {
      for (int k = 0; k <= j && k <= K; ++k)
        dp[i][j] = max(dp[i][j], dp[i - 1][j - k] + val[k]);
    }
  }
}
int c[maxnum], ned[maxnum];
int main() {
  cin >> n >> K;
  for (int i = 1; i <= n * K; ++i) {
    cin >> a[i];
    ++c[a[i]];
  }
  for (int i = 1, t; i <= n; ++i) {
    cin >> t;
    ++ned[t];
  }
  for (int i = 1; i <= K; ++i) {
    cin >> val[i];
  }
  DP(n, n * K);
  int ans = 0;
  for (int i = 1; i < maxnum; ++i)
    if (ned[i]) ans += dp[ned[i]][min(c[i], ned[i] * K)];
  cout << ans << endl;
  return 0;
}
