#include <bits/stdc++.h>
using namespace std;
const int N = 505, K = 11, M = 1e5 + 5;
int n, k, x, fav[M], g[K], dp[N][N * K], counter[M], out;
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n * k; i++) cin >> x, counter[x]++;
  for (int i = 0; i < n; i++) cin >> x, fav[x]++;
  for (int i = 0; i < k; i++) cin >> g[i];
  for (int i = 1; i < N * K; i++) dp[n][i] = -1e9;
  for (int i = n - 1; i >= 0; i--)
    for (int j = 1; j <= n * k; j++)
      for (int w = 1; w <= k; w++)
        if (j >= w) dp[i][j] = max(dp[i][j], dp[i + 1][j - w] + g[w - 1]);
  for (int i = 0; i < M; i++)
    if (fav[i] > 0) out += dp[n - fav[i]][min(fav[i] * k, counter[i])];
  cout << out;
  return 0;
}
