#include <bits/stdc++.h>
using namespace std;
int memo[5001][501];
int k;
int h[11];
long long distribute(int cards, int players) {
  if (cards <= 0 or players <= 0) return 0;
  if (cards >= k * players) return players * h[k];
  if (memo[cards][players] != -1) {
    return memo[cards][players];
  }
  int min_cards = max(0, cards - k * (players - 1));
  long long best = 0;
  for (int c = min_cards; c <= min(k, cards); ++c) {
    best = max(best, h[c] + distribute(cards - c, players - 1));
  }
  return memo[cards][players] = best;
}
void solve() {
  memset(memo, -1, sizeof memo);
  int n;
  cin >> n >> k;
  vector<int> c, f;
  c.reserve(n * k);
  copy_n(istream_iterator<int>(cin), n * k, back_inserter(c));
  f.reserve(n);
  copy_n(istream_iterator<int>(cin), n, back_inserter(f));
  h[0] = 0;
  for (int i = 1; i <= k; ++i) cin >> h[i];
  sort(begin(c), end(c));
  sort(begin(f), end(f));
  long long joy = 0;
  auto itf = begin(f);
  auto itc = begin(c);
  while (itf != end(f)) {
    int x = *itf;
    auto foo = equal_range(itf, end(f), x);
    auto bar = equal_range(itc, end(c), x);
    joy += distribute(bar.second - bar.first, foo.second - foo.first);
    itf = foo.second;
    itc = bar.second;
  }
  cout << joy << endl;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  solve();
  return 0;
}
