#include <bits/stdc++.h>
using namespace std;
int n,k;
long long a[5510];
map<int,int>ma;
long long f[501];
long long h[101];
vector<int>v;
map<int,int>freq;
long long solve(int idx,map<int,int>m)
{
// cout<<m[f[idx]]<<endl;
if(idx>n)
{
return 0;
}
int i;
long long ans=0;
if(m[f[idx]]==0)
{
return solve(idx+1,m);
}
long long int g=m[f[idx]];
for(i=1;i<=min(g,(long long)k);i++)
{
m[f[idx]]--;
long long ans1=h[i]+solve(idx+1,m);
if(ans1>ans)
{
ans=ans1;
}
}
return ans;
}
int main()
{
cin>>n>>k;
int i;
for(i=1;i<=n*k;i++)
{
cin>>a[i];
freq[a[i]]++;
}
for(i=1;i<=n;i++)
{
cin>>f[i];
}
for(i=1;i<=k;i++)
{
cin>>h[i];
}
cout<<solve(1,freq)<<endl;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBuLGs7CmxvbmcgbG9uZyBhWzU1MTBdOwptYXA8aW50LGludD5tYTsKbG9uZyBsb25nIGZbNTAxXTsKbG9uZyBsb25nIGhbMTAxXTsKdmVjdG9yPGludD52OwptYXA8aW50LGludD5mcmVxOwpsb25nIGxvbmcgc29sdmUoaW50IGlkeCxtYXA8aW50LGludD5tKQp7CiAgIC8vIGNvdXQ8PG1bZltpZHhdXTw8ZW5kbDsKICAgIGlmKGlkeD5uKQogICAgewogICAgICAgIHJldHVybiAwOwogICAgfQoKICAgIGludCBpOwogICAgbG9uZyBsb25nIGFucz0wOwogICAgaWYobVtmW2lkeF1dPT0wKQogICAgewogICAgICAgIHJldHVybiBzb2x2ZShpZHgrMSxtKTsKICAgIH0KICAgIGxvbmcgbG9uZyBpbnQgZz1tW2ZbaWR4XV07CiAgICBmb3IoaT0xO2k8PW1pbihnLChsb25nIGxvbmcpayk7aSsrKQogICAgewogICAgICAgIG1bZltpZHhdXS0tOwogICAgICAgIGxvbmcgbG9uZyBhbnMxPWhbaV0rc29sdmUoaWR4KzEsbSk7CiAgICAgICAgaWYoYW5zMT5hbnMpCiAgICAgICAgewogICAgICAgICAgICBhbnM9YW5zMTsKICAgICAgICB9CiAgICB9CiAgICByZXR1cm4gYW5zOwp9CmludCBtYWluKCkKewogICAgY2luPj5uPj5rOwogICAgaW50IGk7CiAgICBmb3IoaT0xO2k8PW4qaztpKyspCiAgICB7CiAgICAgICAgY2luPj5hW2ldOwogICAgICAgIGZyZXFbYVtpXV0rKzsKICAgIH0KICAgIGZvcihpPTE7aTw9bjtpKyspCiAgICB7CiAgICAgICAgY2luPj5mW2ldOwogICAgfQoKICAgIGZvcihpPTE7aTw9aztpKyspCiAgICB7CiAgICAgICAgY2luPj5oW2ldOwogICAgfQogICAgY291dDw8c29sdmUoMSxmcmVxKTw8ZW5kbDsKfQo=