#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int N = 1e5 + 4;
int fa[N], pri[N];
vector<int> v[N];
int main() {
  int n, k;
  scanf("%d", &n);
  scanf("%d", &k);
  for (int i = 0; i < n * k; i++) {
    int temp;
    scanf("%d", &temp);
    fa[temp]++;
  }
  for (int i = 1; i < n + 1; i++) {
    int temp;
    scanf("%d", &temp);
    v[temp].push_back(i);
  }
  for (int i = 1; i < N; i++) {
    if (i <= k)
      scanf("%d", &pri[i]);
    else
      pri[i] = pri[k];
  }
  int total = 0;
  for (int i = 1; i < N; i++)
    if (v[i].size() and fa[i]) {
      int sz = v[i].size();
      int dp[fa[i] + 1][sz + 1];
      memset(dp, 0, sizeof(dp));
      for (int j = 0; j < sz; j++) {
        for (int l = 0; l < fa[i] + 1; l++) {
          for (int x = 0; x < k + 1; x++)
            if (l + x <= fa[i])
              dp[l + x][j + 1] = max(dp[l + x][j + 1], pri[x] + dp[l][j]);
        }
      }
      int here = 0;
      for (int j = 0; j < fa[i] + 1; j++) here = max(here, dp[j][sz]);
      total += here;
    }
  printf("%d", total);
  return 0;
}
