#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; const double PI = 3.14159265358979323846; const double EPS = 1e-12; const int INF = 1<<25; typedef pair P; typedef long long ll; typedef unsigned long long ull; #define M 60 int N, A, B, a[M], a2[M], b[M]; int main(){ cin>>N; cin>>A; for(int i = 0; i < A; i++) cin>>a[i]; cin>>B; for(int i = 0; i < B; i++) cin>>b[i]; sort(a, a+A); sort(b, b+B); int res = 0; memcpy(a2, a, sizeof(a)); for(int i = 0; i < N; i++){ if(!(i%A)) memcpy(a2, a, sizeof(a)); int mn = -1, mx = -1; for(int j = 0; j < B; j++){ if(!b[j]) continue; if(mn==-1){ mn = mx = j; continue; } if(b[j]b[mx]) mx = j; } int pos = -1; for(int j = 0; j <= A; j++){ if(j==A){ a2[pos] = 0; b[mx] = 0; break; } if(pos<0 && a2[j]) pos = j; if(a2[j]>b[mn]){ a2[j] = 0; for(int k = B-1; k >= mn; k--){ if(a2[j]>b[k]){ b[k] = 0; break; } } res++; break; } } } cout<