#include <bits/stdc++.h>
using namespace std;
int n, ans;
int c[100010], f[100010], h[20], k;
int dp[510][5010];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> k;
  for (int i = 0; i < k * n; ++i) {
    int x;
    cin >> x;
    ++c[x];
  }
  for (int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    f[x]++;
  }
  for (int i = 0; i < k; ++i) {
    cin >> h[i + 1];
  }
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < k * n; ++j) {
      for (int e = 0; e <= k; ++e) {
        dp[i][j + e] = max(dp[i][j + e], dp[i - 1][j] + h[e]);
      }
    }
  }
  for (int i = 0; i < 100010; ++i) {
    ans += dp[f[i]][c[i]];
  }
  cout << ans << "\n";
}
