#include <bits/stdc++.h>
using ll = int64_t;
const int MAX = 1e5;
int32_t main() {
  std::ios::sync_with_stdio(false), std::cin.tie(nullptr);
  int n, k;
  std::cin >> n >> k;
  std::vector<int> number_count(MAX + 1), favorite_count(MAX + 1), h(k + 1);
  int lim = k * n;
  for (int i = 0; i < lim; i++) {
    int x;
    std::cin >> x;
    number_count[x]++;
  }
  for (int i = 0; i < n; i++) {
    int x;
    std::cin >> x;
    favorite_count[x]++;
  }
  for (int i = 1; i <= k; i++) std::cin >> h[i];
  std::vector<std::vector<int>> dp(501, std::vector<int>(5001 + 1000));
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= n * (k); j++) {
      for (int cnt = 0; cnt <= k; cnt++) {
        dp[i + 1][j + cnt] = std::max(dp[i + 1][j + cnt], dp[i][j] + h[cnt]);
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= MAX; i++) {
    if (favorite_count[i] > 0) ans += dp[favorite_count[i]][number_count[i]];
  }
  std::cout << ans;
  return 0;
}
