Merging Two Decks

There are two decks of cards lying on the table in front of you, some cards in these decks lay face up, some of them lay face down. You want to merge them into one deck in which each card is face down. You’re going to do it in two stages.

The first stage is to merge the two decks in such a way that the relative order of the cards from the same deck doesn’t change. That is, for any two different cards i and j in one deck, if card i lies above card j, then after the merge card i must also be above card j.

The second stage is performed on the deck that resulted from the first stage. At this stage, the executed operation is the turning operation. In one turn you can take a few of the top cards, turn all of them, and put them back. Thus, each of the taken cards gets turned and the order of these cards is reversed. That is, the card that was on the bottom before the turn, will be on top after it.

Your task is to make sure that all the cards are lying face down. Find such an order of merging cards in the first stage and the sequence of turning operations in the second stage, that make all the cards lie face down, and the number of turns is minimum.

Input

The first input line contains a single integer n — the number of cards in the first deck (1 ≤ n ≤ 105).

The second input line contains n integers, separated by single spaces a 1, a 2, …, a n (0 ≤ a i ≤ 1). Value a i equals 0, if the i-th card is lying face down, and 1, if the card is lying face up. The cards are given in the order from the topmost one to the bottommost one.

The third input line contains integer m — the number of cards in the second deck (1 ≤ m ≤ 105).

The fourth input line contains m integers, separated by single spaces b 1, b 2, …, b m (0 ≤ b i ≤ 1). Value b i equals 0, if the i-th card is lying face down, and 1, if the card is lying face up. The cards are given in the order from the topmost to the bottommost.

Output

In the first line print n + m space-separated integers — the numbers of the cards in the order, in which they will lie after the first stage. List the cards from top to bottom. The cards from the first deck should match their indexes from 1 to n in the order from top to bottom. The cards from the second deck should match their indexes, increased by n, that is, numbers from n + 1 to n + m in the order from top to bottom.

In the second line print a single integer x — the minimum number of turn operations you need to make all cards in the deck lie face down. In the third line print x integers: c 1, c 2, …, c x (1 ≤ c i ≤ n + m), each of them represents the number of cards to take from the top of the deck to perform a turn operation. Print the operations in the order, in which they should be performed.

If there are multiple optimal solutions, print any of them. It is guaranteed that the minimum number of operations doesn’t exceed 6·105.

Examples

input

3
1 0 1
4
1 1 1 1

output

1 4 5 6 7 2 3
3
5 6 7

input

5
1 1 1 1 1
5
0 1 0 1 0

output

6 1 2 3 4 5 7 8 9 10
4
1 7 8 9

Solution:

#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>

using namespace std;

const int N = 444444;

int a[N], b[N], c[N], d[N], e[N], ax[N], bx[N];
int n, m, i;

int main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
scanf("%d", &n);
for (i=0;i<n;i++) scanf("%d", &a[i]);
  scanf("%d", &m);
  for (i=0;i<m;i++) scanf("%d", &b[i]);
  int ka = 1, kb = 1;
  ax[0] = 1;
  for (i=1;i<n;i++) {
    if (a[i] != a[i-1]) ka++;
    ax[i] = ka;
  }
  if (a[n-1] == 0) ka--;
  bx[0] = 1;
  for (i=1;i<m;i++) {
    if (b[i] != b[i-1]) kb++;
    bx[i] = kb;
  }
  if (b[m-1] == 0) kb--;
  if (ka > kb && (ka % 2) != (kb % 2))
for (i=0;i<m;i++) bx[i]++;
  if (ka < kb && (ka % 2) != (kb % 2))
    for (i=0;i<n;i++) ax[i]++;
  int i = 0, j = 0, u = 0;
  for (int k=1;k<=ka || k <= kb;k++) {
    while (i < n && ax[i] == k) {
      c[u++] = i;
      i++;
    }
    while (j < m && bx[j] == k) {
      c[u++] = n+j;
      j++;
    }
  }
  while (i < n) {
    c[u++] = i;
    i++;
  }
  while (j < m) {
    c[u++] = n+j;
    j++;
  }
  for (i=0;i<u-1;i++) printf("%d ", c[i]+1);
  printf("%d\n", c[u-1]+1);
  for (i=0;i<u;i++)
    if (c[i] < n) d[i] = a];
    else d[i] = b-n];
  int ke = 0;
  for (i=0;i<u-1;i++)
    if (d[i] != d[i+1]) e[ke++] = i;
  if (d[u-1] == 1) e[ke++] = u-1;
  printf("%d\n", ke);
  for (i=0;i<ke-1;i++) printf("%d ", e[i]+1);
  if (ke > 0) printf("%d", e[ke-1]+1);
printf("\n");
return 0;
}