#include #include #include using namespace std; const int INF = 1 << 30; int main() { int Nw, Nb; cin >> Nw; vector W(Nw); for (int i = 0; i < Nw; ++i) cin >> W[i]; cin >> Nb; vector B(Nb); for (int i = 0; i < Nb; ++i) cin >> B[i]; sort(W.begin(), W.end()); sort(B.begin(), B.end()); int res = 0; int w_idx = Nw - 1; int b_idx = Nb - 1; int cur = INF; bool w_flag = true; bool b_flag = true; while (true) { if ((w_flag && w_idx < 0) || (b_flag && b_idx < 0)) break; int neww = 0, newb = 0; if (w_idx >= 0 && w_flag && W[w_idx] < cur) { neww = W[w_idx]; } if (b_idx >= 0 && b_flag && B[b_idx] < cur) { newb = B[b_idx]; } if (neww > newb) { cur = neww; w_flag = false; b_flag = true; --w_idx; ++res; } else if (newb) { cur = newb; w_flag = true; b_flag = false; --b_idx; ++res; } else { if (w_flag) --w_idx; if (b_flag) --b_idx; } } cout << res << endl; }