Under construction

Still being built. Things may change

Couple Destroyer Minuk (Large)

Time limit1sMemory limit1024 MB

Summary
Split a line of people into the fewest contiguous groups that can be reordered so no couple ends up adjacent, then list up to 100 valid arrangements.
Level

Medium7 of 10

Topics
Dynamic programming, Backtracking, Greedy
Solved
No attempts yet

Problem

Minuk, who is single, dislikes seeing couples together. He finds a waiting line of NN people standing in a row. He plans to split this line into MM groups and reorder the groups so that no couple is adjacent. The groups do not need to have the same size. However, the people inside a group cannot be reordered or reversed.

Minuk wants MM to be as small as possible, because a large MM makes reordering the groups a headache. Let CC be the number of valid ways when MM is minimal. He wants to find min⁡(C,100)\min (C, 100) of these ways, chosen arbitrarily. Two ways count as different if the group order differs, even when all groups have the same size. Two ways with the same group order also count as different if any group has a different size.

Input

The first line contains an integer NN (1≤N≤1031 \le N \le 10^{3}), the number of people.

The second line contains integers a1,a2,a3,⋯ ,aNa_{1}, a_{2}, a_{3}, \cdots, a_{N} (0≤ai≤1030 \le a_{i} \le 10^{3}), separated by spaces. aia_{i} describes the person at position ii from the front of the line. If ai=0a_{i} = 0, that person is single. If ai=aja_{i} = a_{j} and ai≠0a_{i} \ne 0, persons ii and jj are a couple. Every nonzero value appears exactly twice.

Output

On the first line, print the minimum value of MM.

From the second line to line 2×min⁡(C,100)+12 \times \min (C, 100) + 1, print min⁡(C,100)\min (C, 100) valid ways in total.

On line 2k2k, print the group sizes for the kk-th way in the order group 1, group 2, group 3, ⋯\cdots, group MM, separated by spaces.

On line 2k+12k + 1, print the group numbers from the front of the line after the groups are reordered in the kk-th way.

If C<100C < 100, print −1-1 on line 2C+22C + 2 and print nothing after that.

If no way to split the line into groups and arrange them avoids having at least one couple adjacent, print −1-1 on the first line and print nothing after that.

Examples2

  1. Example 1

    Input
    6
    3 1 1 3 2 2
    
    Expected output
    3
    2 3 1
    1 3 2
    2 3 1
    2 1 3
    2 3 1
    3 2 1
    -1
    
  2. Example 2

    Input
    4
    0 0 0 0
    
    Expected output
    1
    4
    1
    -1