// No.110 しましまピラミッド // https://yukicoder.me/problems/no/110 // #include #include #include #include using namespace std; int solve(vector w_blocks, vector b_blocks); int main() { std::cin.tie(nullptr); std::ios::sync_with_stdio(false); unsigned int nw; cin >> nw; vector w_blocks(nw); for (auto i = 0; i < nw; ++i) cin >> w_blocks[i]; unsigned int nb; cin >> nb; vector b_blocks(nb); for (auto i = 0; i < nb; ++i) cin >> b_blocks[i]; int ans = solve(w_blocks, b_blocks); cout << ans << endl; } int solve(vector w_blocks, vector b_blocks) { w_blocks.push_back(-1); b_blocks.push_back(-1); sort(w_blocks.begin(), w_blocks.end()); sort(b_blocks.begin(), b_blocks.end()); const int WHITE = 0; const int BLACK = 1; vector> blocks(2); blocks[WHITE] = move(w_blocks); blocks[BLACK] = move(b_blocks); // 白いブロックを土台にする場合 vector ans_w; ans_w.push_back(blocks[WHITE][blocks[WHITE].size()-1]); int next_block = BLACK; while (true) { auto p = lower_bound(blocks[next_block].begin(), blocks[next_block].end(), ans_w[ans_w.size()-1]); if (*(p-1) == -1) break; ans_w.push_back(*(p-1)); next_block = next_block == BLACK? WHITE: BLACK; } // 黒いブロックを土台にする場合 vector ans_b; ans_b.push_back(blocks[BLACK][blocks[BLACK].size()-1]); next_block = WHITE; while (true) { auto p = lower_bound(blocks[next_block].begin(), blocks[next_block].end(), ans_b[ans_b.size()-1]); if (*(p-1) == -1) break; ans_b.push_back(*(p-1)); next_block = next_block == BLACK? WHITE: BLACK; } return max(ans_w.size(), ans_b.size()); }