constint maxn=505,maxk=15,maxs=5005; int n,K,h[maxk],f[maxs][maxn],cnt[100005],num[100005]; #define up(x,y) (x=max(x,y)) intmain(){ scanf("%d%d",&n,&K); for (int i=1,x;i<=n*K;i++) scanf("%d",&x),cnt[x]++; for (int i=1,x;i<=n;i++) scanf("%d",&x),num[x]++; for (int i=1;i<=K;i++) scanf("%d",&h[i]); for (int i=1;i<=n*K;i++) for (int j=1;j<=n;j++) for (int k=1;k<=i&&k<=K;k++) up(f[i][j],f[i-k][j-1]+h[k]); int ans=0; for (int i=1;i<=100000;i++) if (cnt[i]>0&&num[i]>0) ans+=f[cnt[i]][num[i]]; printf("%d",ans); return0; }