#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
int n, k, h[100001], first[100001], c[100001], t;
set<int> second;
long long ans, dp[501][5001];
long long calc(int u, int v) {
  if (!u) return 0;
  long long& res = dp[u][v];
  if (~res) return res;
  res = 0;
  for (int i = 0; i < min(v, k) + 1; i++) {
    res = max(res, (long long)calc(u - 1, v - i) + h[i]);
  }
  return dp[u][v] = res;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> k;
  for (int i = 0; i < n * k; i++) cin >> t, c[t]++;
  for (int i = 0; i < n; i++) cin >> t, first[t]++, second.insert(t);
  for (int i = 1; i < k + 1; i++) cin >> h[i];
  memset(dp, -1, sizeof(dp));
  for (int a : second) {
    ans += calc(first[a], c[a]);
  }
  cout << ans;
  return 0;
}
