#include <bits/stdc++.h>
using namespace std;
const long long SZ = 1e5 + 1;
vector<long long> cnt(SZ);
vector<long long> fav(SZ);
vector<long long> h;
long long n, k;
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> k;
  for (long long i = 0; i < n * k; i++) {
    long long x;
    cin >> x;
    cnt[x]++;
  }
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    fav[x]++;
  }
  h.resize(k + 1);
  for (long long i = 1; i <= k; i++) {
    cin >> h[i];
  }
  long long score = 0;
  for (long long i = 0; i < SZ; i++) {
    long long dp[fav[i] + 1][cnt[i] + 1];
    for (long long a = 0; a <= fav[i]; a++) {
      for (long long b = 0; b <= cnt[i]; b++) {
        if (a == 0 || b == 0) {
          dp[a][b] = 0;
        } else {
          dp[a][b] = 0;
          for (long long j = 1; j <= k && b - j >= 0; j++) {
            dp[a][b] = max(dp[a][b], dp[a - 1][b - j] + h[j]);
          }
        }
      }
    }
    score += dp[fav[i]][cnt[i]];
  }
  cout << score << '\n';
  fflush(stdout);
  return 0;
}
