#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = static_cast<ll>(1e9) + 7;
const int MAXN = static_cast<int>(4e5) + 17;
int n, k;
int a[MAXN], cnt1[MAXN], cnt2[MAXN], f[MAXN], h[MAXN];
bool read() {
  if (!(cin >> n >> k)) return false;
  for (ll i = 0; i < (ll)(n * k); ++i) cin >> a[i];
  for (ll i = 0; i < (ll)(n); ++i) cin >> f[i];
  for (ll i = 0; i < (ll)(k); ++i) cin >> h[i + 1];
  return true;
}
void solve() {
  for (ll i = 0; i < (ll)(n * k); ++i) ++cnt1[a[i]];
  for (ll i = 0; i < (ll)(n); ++i) ++cnt2[f[i]];
  ll ans = 0;
  for (int x = 1; x <= 100000; ++x)
    if (cnt2[x] != 0) {
      vector<vector<int> > dp(cnt2[x] + 1, vector<int>(cnt1[x] + 1, 0));
      for (int i = 0; i < cnt2[x]; ++i)
        for (int j = 0; j <= cnt1[x]; ++j)
          for (int dj = 0; dj <= k && j + dj <= cnt1[x]; ++dj)
            dp[i + 1][j + dj] = max(dp[i + 1][j + dj], dp[i][j] + h[dj]);
      ans += dp[cnt2[x]][cnt1[x]];
    }
  cout << ans << '\n';
}
int main() {
  cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::mt19937 rand('S' + 'E' + 'R' + 'E' + 'Z' + 'H' + 'K' + 'A');
  while (read()) solve();
  return 0;
};
