The first line gives the board length L (1≤L≤3000).
The second line gives the number of pieces n in the initial state (1≤n≤L).
The third line gives n numbers a1,a2,...,an. They list each piece length from the leftmost piece, and each number is 1 or 2. The n numbers sum to L.
The fourth line gives the number of pieces m in the target state (1≤m≤L).
The fifth line gives m numbers b1,b2,...,bm in the same format as the third line.