#include <bits/stdc++.h>
using namespace std;
map<int, int> ccnt, pcnt;
int n, k, dp[501][501 * 11], h[11], ans;
int main() {
  cin >> n >> k;
  for (int i = 0, c; i < k * n; ++i) {
    cin >> c;
    ccnt[c]++;
  }
  for (int i = 0, p; i < n; ++i) {
    cin >> p;
    pcnt[p]++;
  }
  for (int i = 1; i <= k; ++i) cin >> h[i];
  for (int p = 1; p <= n; ++p)
    for (int c = 1; c <= k * n; ++c)
      for (int i = 0; i <= min(k, c); ++i)
        dp[p][c] = max(dp[p][c], dp[p - 1][c - i] + h[i]);
  for (auto p : pcnt) ans += dp[p.second][ccnt[p.first]];
  cout << ans;
}
