#include <bits/stdc++.h>
using namespace std;
int dp[501][5001];
int main() {
  std::ios::sync_with_stdio(false);
  int T;
  T = 1;
  while (T--) {
    int n, k, i, j, l;
    cin >> n >> k;
    int ar[k * n + 100], ar2[n + 100], ar3[k + 100];
    for (i = 0; i < n * k; ++i) cin >> ar[i];
    for (i = 0; i < n; ++i) cin >> ar2[i];
    for (i = 0; i < k; ++i) cin >> ar3[i];
    for (i = 1; i <= n; ++i) {
      for (j = 1; j <= i * k; ++j) {
        if (i == 1)
          dp[i][j] = ar3[j - 1];
        else if (j == 1)
          dp[i][j] = ar3[0];
        else {
          dp[i][j] = max(dp[i][j], dp[i - 1][j]);
          for (l = j - 1; l >= 0 && j - l <= k; --l) {
            if (l > (i - 1) * k) continue;
            dp[i][j] = max(dp[i][j], ar3[j - l - 1] + dp[i - 1][l]);
          }
        }
      }
    }
    sort(ar2, ar2 + n);
    long long ans = 0;
    int ct = 0, pre = -1, ct2 = 0;
    for (i = 0; i < n;) {
      pre = ar2[i];
      ct = 0;
      while (i < n && ar2[i] == pre) {
        ++ct, ++i;
      }
      ct2 = 0;
      for (j = 0; j < n * k; ++j) {
        if (ar[j] == pre) ++ct2;
      }
      ct2 = min(ct2, k * ct);
      if (ct2 == 0)
        ;
      else
        ans = ans + dp[ct][ct2];
    }
    cout << ans << endl;
  }
  return 0;
}
