#include using namespace std; int main(){ int N; cin >> N; int A,B; cin >> A; vector a(A); for(int i = 0 ; i < A ; i++) cin >> a[i]; cin >> B; vector b(B); for(int i = 0 ; i < B ; i++) cin >> b[i]; sort(b.begin(),b.end()); multiset xx; int answer = 0; for(int k = 0 ; k < b.size() ; k++){ int ans = 0; for(int i = 0 ; i < N ; i++){ if( xx.size() == 0 ){ for(int j = 0 ; j < a.size() ; j++) xx.insert(a[j]); } auto it = xx.upper_bound(b[i%b.size()]); //cout << "(" << xx.size() << ")"; //cout << b[i%b.size()] << " vs "; if( it == xx.end() ){ //cout << *xx.begin() << endl; xx.erase(xx.begin()); }else{ //cout << *it << " win!" << endl; ans++; xx.erase(it); } } answer = max(answer,ans); rotate(b.begin(),b.begin()+1,b.end()); } cout << answer << endl; }