# 2019 ACM NEERC, Semifinal

# Cactus Revenge

NE(E)RC featured a number of problems in previous years about cactuses — connected undirected graphs in which every edge belongs to at most one simple cycle. Intuitively, a cactus is a generalization of a tree where some cycles are allowed. The traditional cactus that was initially used in NEERC 2005 problem is given on the second picture in the Examples section.

You are given **n** integers `d`

, _{1}`d`

, ..., _{2}`d`

. Construct any cactus with _{n}**n** vertices such that vertex **i** has degree `d`

(i. e. exactly _{i}`d`

incident edges), or determine that no such cactus exists. Parallel edges and loops are not allowed._{i}

#### Input

The first line contains a single integer **n** (**2** ≤ **n** ≤ **2000**) - the number of vertices in the cactus. The second line contains **n** integers `d`

, _{1}`d`

, ..., _{2}`d`

(_{n}**1** ≤ `d`

≤ _{i}**n** - **1**) - the desired vertex degrees.

#### Output

If it’s impossible to construct a cactus satisfying the conditions, output a single integer **-1**.

Otherwise, by tradition, output the constructed cactus as a set of edge-distinct paths.

In the first line print an integer **m** - the number of such paths. Each of the following **m** lines should contain a path in the graph. A path should start with an integer `k`

(_{i}`k`

≥ _{i}**2**) followed by `k`

integers from _{i}**1** to **n**. These `k`

integers should represent consecutive vertices of this path. Adjacent vertices in the path should be distinct. The path can visit the same vertex multiple times, but every edge of the cactus should be traversed exactly once in the whole output._{i}

5 2 2 3 2 1

5 2 2 4 2 2 3 2 1 3 2 3 5 2 1 4

4 3 3 2 2

-1

6 1 2 1 1 2 1

-1

15 1 4 3 2 2 2 2 2 4 4 2 2 2 2 2

18 2 9 11 2 9 10 2 2 10 2 2 3 2 3 4 2 2 4 2 5 9 2 5 6 2 6 9 2 7 10 2 7 8 2 8 10 2 1 3 2 11 12 2 12 13 2 13 14 2 14 15 2 2 15