#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const int N = 1e5 + 5, M = 5e2 + 5;
int n, k;
int cnt[N];
int first[M], h[15];
vector<int> idx[N];
int sz, dp[M][M * 10];
int vis[M][M * 10], vid;
int solve(int i, int rem) {
  if (i == sz) return 0;
  if (vis[i][rem] == vid) return dp[i][rem];
  vis[i][rem] = vid;
  int &ret = dp[i][rem];
  ret = 0;
  for (int kam = 1; kam <= min(k, rem); ++kam)
    ret = max(ret, solve(i + 1, rem - kam) + h[kam]);
  return ret;
}
int main() {
  scanf("%d%d", &n, &k);
  for (int i = 0; i < n * k; ++i) {
    int x;
    scanf("%d", &x);
    ++cnt[x];
  }
  for (int i = 0; i < n; ++i) {
    int x;
    scanf("%d", &x);
    idx[x].emplace_back(i);
  }
  for (int i = 1; i <= k; ++i) scanf("%d", h + i);
  int ans = 0;
  for (int i = 0; i < N; ++i) {
    sz = idx[i].size();
    if (sz == 0) continue;
    int kam = min(cnt[i], sz * k);
    ++vid;
    int here = solve(0, kam);
    ans += here;
  }
  printf("%d\n", ans);
}
