#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int> > memo(501, vector<long long int>(5001, -1));
vector<long long int> h;
long long int n, k;
long long int dp(long long int num_players, long long int num_cards) {
  if (num_cards < 0) {
    return -INT_MAX;
  }
  if (num_players == 0) {
    return 0;
  }
  if (num_cards == 0) {
    return 0;
  }
  if (memo[num_players][num_cards] != -1) {
    return memo[num_players][num_cards];
  }
  long long int maxa = -INT_MAX;
  for (long long int i = 0; i <= k; i++) {
    maxa = max(maxa, dp(num_players - 1, num_cards - i) + h[i]);
  }
  memo[num_players][num_cards] = maxa;
  return maxa;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> k;
  vector<long long int> numcards(100001, 0);
  vector<long long int> favour_num(100001, 0);
  for (long long int i = 0; i < k * n; i++) {
    long long int temp;
    cin >> temp;
    numcards[temp]++;
  }
  for (long long int i = 0; i < n; i++) {
    long long int temp;
    cin >> temp;
    favour_num[temp]++;
  }
  h.resize(k + 1, 0);
  for (long long int i = 0; i < k; i++) {
    cin >> h[i + 1];
  }
  long long int ans = 0;
  for (long long int i = 0; i < 100001; i++) {
    if (favour_num[i] > 0 && numcards[i] > 0) {
      ans += dp(favour_num[i], numcards[i]);
    }
  }
  cout << ans << endl;
  return 0;
}
