#include<bits/stdc++.h>
using namespace std;
int n,m;
int dan[60];
int ren[1030];
int vr[1030];
int vd[60];
int ans=0;
bool cmp(int x,int y){
return x>y;
}
void dfs(int k,int d){
if(k==m){
cout<<m;
exit(0);
}
if(d==n){
ans=max(k,ans);
return;
}
int temp1=1,ff=0;
for(int i=1;i<=m;i++){
if(vd[temp1]==1){
temp1++;
continue;
}
if(ren[i]<=dan[temp1]&&vr[i]==0){
ff=1;
break;
}
}
if(ff==0){
vd[temp1]=1;
dfs(k,d+1);
}
for(int i=1,temp=1;i<=n,temp<=m;i++){
if(vr[temp]==0&&ren[temp]<dan[i]){
dan[i]-=ren[temp];
vr[temp]=1;
dfs(k+1,d);
vr[temp]=0;
dan[i]+=ren[temp];
}
}
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>dan[i];
}
cin>>m;
for(int i=1;i<=m;i++){
cin>>ren[i];
}
sort(dan+1,dan+1+n,cmp);
sort(ren+1,ren+m+1);
dfs(0,0);
cout<<ans;
return 0;
}