#include <bits/stdc++.h>
using namespace std;
const long long p = 1000000007;
const int N = 501;
const int K = 11;
int n, k;
int cards[N * K];
int m[2 * 100000 + 1];
int amount[N * K];
int fav[N * K];
int dp[N][N * K];
int h[K + 1];
int DP(int card) {
  for (int i = 0; i < amount[card]; i++) dp[0][i] = 0;
  for (int a = 1; a < fav[card] + 1; a++) {
    for (int b = 0; b < amount[card] + 1; b++) {
      int mx = 0;
      for (int j = 0; j < min(b, k) + 1; j++) {
        mx = max(dp[a - 1][b - j] + h[j], mx);
      }
      dp[a][b] = mx;
    }
  }
  return dp[fav[card]][amount[card]];
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> n >> k;
  for (int i = 0; i < n * k; i++) {
    cin >> cards[i];
  }
  sort(cards, cards + k * n);
  int it = 1;
  int i = 1;
  while (i < k * n) {
    if (cards[i] != cards[i - 1]) {
      m[cards[i - 1]] = it;
      it++;
    }
    i++;
  }
  m[cards[n * k - 1]] = it;
  for (int i = 0; i < n * k; i++) amount[m[cards[i]]]++;
  for (int i = 0; i < n; i++) {
    int x;
    cin >> x;
    fav[m[x]]++;
  }
  for (int i = 0; i < k; i++) cin >> h[i + 1];
  int result = 0;
  for (int i = 1; i < it + 1; i++) {
    result += DP(i);
  }
  cout << result << endl;
}
