#include <bits/stdc++.h>
using namespace std;
int dp[5005][505];
int h[12];
int n, k;
int getDp(int card, int people) {
  if (dp[card][people]) return dp[card][people];
  if (people == 1) return dp[card][people] = h[card];
  for (int i = 0; i <= k; ++i) {
    if (card == i) break;
    dp[card][people] =
        max(getDp(card - i, people - 1) + h[i], dp[card][people]);
    ;
  }
  return dp[card][people];
}
int main() {
  cin >> n >> k;
  map<int, int> card;
  map<int, int> f;
  int x;
  for (int i = 0; i < n * k; ++i) {
    scanf("%d", &x);
    card[x]++;
  }
  for (int i = 0; i < n; ++i) {
    scanf("%d", &x);
    f[x]++;
  }
  for (int i = 1; i <= k; i++) {
    scanf("%d", &h[i]);
  }
  int ans = 0;
  for (auto fav : f) {
    if (fav.second == 1) {
      int cardNum = min(card[fav.first], k);
      ans += h[cardNum];
    } else {
      int cardNum = min(card[fav.first], k * fav.second);
      ;
      ans += getDp(cardNum, fav.second);
    };
  }
  printf("%d", ans);
  return 0;
}
