#include <bits/stdc++.h>
using namespace std;
int fav[100005];
int cnt[100005];
long long cost[20];
int n, k;
long long dp[501][5001];
long long call(int idx, int remain) {
  if (remain == 0) return 0;
  if (idx <= 0) return 0;
  long long &ret = dp[idx][remain];
  if (ret != -1) return ret;
  ret = 0;
  for (int i = 1; i <= k && remain - i >= 0; i++) {
    ret = max(ret, cost[i] + call(idx - 1, remain - i));
  }
  return ret;
}
int main() {
  scanf("%d %d", &n, &k);
  for (int i = 0; i < n * k; i++) {
    int a;
    scanf("%d", &a);
    cnt[a]++;
  }
  for (int i = 0; i < n; i++) {
    int a;
    scanf("%d", &a);
    fav[a]++;
  }
  for (int i = 1; i <= k; i++) scanf("%lld", &cost[i]);
  long long ans = 0;
  memset(dp, -1, sizeof(dp));
  for (int i = 0; i < 100005; i++) {
    if (cnt[i] && fav[i]) {
      ans += call(fav[i], min(cnt[i], fav[i] * k));
    }
  }
  printf("%lld\n", ans);
  return 0;
}
