#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
unordered_map<int, int> cf, ff;
int h[N];
int dp[505][5005];
int pers;
int k;
int rec(int pos, int rem) {
  if (pos == pers) {
    return 0;
  }
  if (dp[pos][rem] != -1) return dp[pos][rem];
  int ans = 0;
  for (int i = 1; i <= k; i++) {
    if (rem - i >= 0) {
      ans = max(ans, rec(pos + 1, rem - i) + h[i]);
    }
  }
  dp[pos][rem] = ans;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n;
  cin >> n >> k;
  for (int i = 0; i < n * k; i++) {
    int c;
    cin >> c;
    cf[c]++;
  }
  for (int i = 0; i < n; i++) {
    int num;
    cin >> num;
    ff[num]++;
  }
  for (int i = 1; i <= k; i++) cin >> h[i];
  int ans = 0;
  for (auto i : cf) {
    if (ff.find(i.first) != ff.end()) {
      for (int ii = 0; ii <= ff[i.first]; ii++)
        for (int jj = 0; jj <= i.second; jj++) dp[ii][jj] = -1;
      pers = ff[i.first];
      ans += rec(0, i.second);
    }
  }
  cout << ans << "\n";
  return 0;
}
