#include #include #include #include //#include #include #include #include #include #include //#include #include #include #include //#include #include #include //#include #include #include #include const int dx[] = {1, 0, -1, 0}; const int dy[] = {0, 1, 0, -1}; using namespace std; typedef long long ll; typedef vector vi; typedef vector vll; typedef pair pii; const int MAXN = 55; int B[MAXN], D[MAXN]; int A, C, N; bool done[MAXN]; int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; cin >> A; for (int i = 0; i < A; i++) cin >> B[i]; cin >> C; for (int i = 0; i < C; i++) cin >> D[i]; vector AA; for (int i = 1; i * A <= N; i++) { for (int j = 0; j < A; j++) AA.push_back(B[j]); } sort(B, B+A); reverse(B, B+A); for (int i = 0; i < N%A; i++) AA.push_back(B[i]); sort(D, D+C); int ans = 0, cnt = 0; for (int i = 0; i < N; i++) { if (cnt % C == 0) { cnt = 0; for (int j = 0; j < C; j++) done[j] = false; } int index = -1; for (int j = 0; j < C; j++) { if (D[j] < AA[i] && !done[j]) index = j; } if (index == -1) { for (int j = C-1; j >= 0; j--) { if (!done[j]) { index = j; break; } } } if (D[index] < AA[i]) ans++; done[index] = true; cnt++; } cout << ans << endl; return 0; }