#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; #define MOD 1000000007 // 10^9 + 7 #define INF 1000000000 // 10^9 #define LLINF 1LL<<60 int main() { cin.tie(0); ios::sync_with_stdio(false); int N1; cin >> N1; priority_queue W; for (int i = 0; i < N1; i++) { int tmp; cin >> tmp; W.push(tmp); } int N2; cin >> N2; priority_queue B; for (int i = 0; i < N2; i++) { int tmp; cin >> tmp; B.push(tmp); } int fw = 0; bool color = 1; // 1 : 次に乗せる色は白 int under = INF; bool flag = true; priority_queue tmpW = W; priority_queue tmpB = B; while (flag) { flag = false; if (color) { while (!tmpW.empty() && tmpW.top() >= under) tmpW.pop(); if (!tmpW.empty()) { under = tmpW.top(); tmpW.pop(); fw++; color = false; flag = true; } } else { while (!tmpB.empty() && tmpB.top() >= under) tmpB.pop(); if (!tmpB.empty()) { under = tmpB.top(); tmpB.pop(); fw++; color = true; flag = true; } } } int fb = 0; color = 0; // 1 : 次に乗せる色は白 under = INF; flag = true; tmpW = W; tmpB = B; while (flag) { flag = false; if (color) { while (!tmpW.empty() && tmpW.top() >= under) tmpW.pop(); if (!tmpW.empty()) { under = tmpW.top(); tmpW.pop(); fb++; color = false; flag = true; } } else { while (!tmpB.empty() && tmpB.top() >= under) tmpB.pop(); if (!tmpB.empty()) { under = tmpB.top(); tmpB.pop(); fb++; color = true; flag = true; } } } cout << max(fw, fb) << endl; return 0; }