#include <bits/stdc++.h>
using namespace std;
long long a[100010], cnt[100010], b[100010], p[100010], h[100];
long long mem[501][5001], nn, k;
vector<pair<int, int> > v;
long long dp(int x, int nm) {
  if (x == nn) return 0;
  if (mem[x][nm] != -1) return mem[x][nm];
  long long ans = 0;
  for (int i = 0; i <= min(k, (long long)nm); ++i) {
    ans = max(ans, h[i] + dp(x + 1, nm - i));
  }
  mem[x][nm] = ans;
  v.push_back(make_pair(x, nm));
  return ans;
}
int main() {
  int n;
  while (cin >> n >> k) {
    set<int> s;
    for (int i = 0; i < n * k; ++i) {
      cin >> a[i];
      ++cnt[a[i]];
      s.insert(a[i]);
    }
    for (int i = 0; i < n; ++i) {
      cin >> b[i];
      ++p[b[i]];
    }
    for (int i = 1; i <= k; ++i) {
      cin >> h[i];
    }
    h[0] = 0;
    long long ans = 0;
    memset(mem, -1, sizeof mem);
    for (auto it : s) {
      nn = p[it];
      ans += dp(0, cnt[it]);
      for (int i = 0; i < v.size(); ++i) {
        mem[v[i].first][v[i].second] = -1;
      }
      v.clear();
    }
    cout << ans << endl;
  }
  return 0;
}
