import java.io.*
import java.lang.Math.*
import java.math.BigInteger
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashMap
import kotlin.math.sqrt

typealias IntInt = Array<IntArray>
typealias LongLong = Array<LongArray>

fun solve() {
    var nn = readInt()
    var n = 0
    var ar = readInts()
    for (i in ar) if (i == -1) n++
    var a = Array(n){ ArrayList<Int>() }
    var now = -1
    var set = TreeSet<Int>()
    for (i in 0 until n) set.add(i)
    for (i in ar) {
        now = set.higher(now) ?: set.first()
        if (i == -1)
            set.remove(now)
        else
            a[now].add(i)
    }
    println(n)
    for (b in a) {
        print("${b.size} ")
        for (i in b) print("$i ")
        println()
    }
}

fun init() {

}

const val MODULO = 1000 * 1000 * 1000 + 7

fun stress() {
    val rnd = Random(1234)

    for (it in 0 until 100) {
        val expected = brute()
        val actual = fast()

        if (expected != actual) {
            System.err.println("Gotcha!")
            System.err.println("$expected $actual")

            break
        }
    }
}

fun fast() {

}

fun brute() {

}

class Vect (var x: Double, var y: Double) {
    operator fun plus(b: Vect) = Vect(x + b.x, y + b.y)
    operator fun times(b: Int) = Vect(x * b, y * b)
    operator fun div(b: Int) = Vect(x / b, y / b)
    operator fun minus(b: Vect) = Vect(x - b.x, y - b.y)
    operator fun div(b: Double) = Vect(x / b, y / b)
    infix fun scalar(b: Vect) = x * b.x + y * b.y
    infix fun cross(b: Vect) = x * b.y - y * b.x
    fun rotated90() = Vect(-y, x)
    fun length() = sqrt(x * x + y * y)
    infix fun angle(b: Vect) =
        kotlin.math.atan2(cross(b).toDouble(), scalar(b).toDouble())
    fun polarAngel() = Vect(1.0, 0.0) angle this
    infix fun trap2(b: Vect) = (b.x - x) * (y + b.y)
    override fun toString() = "$x $y"
    fun normir() = this / length()
}
operator fun Int.times(a: Vect) = a * this

fun Long.mod() : Long {
    var result = this % MODULO
    if (result < 0) result += MODULO
    return result
}

infix fun Long.add(other : Long) = (this + other).mod()
infix fun Long.sub(other : Long) = this add -other.mod()
infix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()

fun Long.even() = (this and 1L) == 0L
fun Long.odd() = !even()

fun Int.even() = (this and 1) == 0
fun Int.odd() = !even()

fun Long.bitCount() = java.lang.Long.bitCount(this)
fun Int.bitCount() = java.lang.Integer.bitCount(this)

operator fun Long.get(bit : Int) = ((this shr bit) and 1).toInt()
infix fun Long.check(bit : Int) = this[bit] != 0

operator fun Int.get(bit : Int) = (this shr bit) and 1
infix fun Int.check(bit : Int) = this[bit] != 0

infix fun Long.binpow(power : Long) : Long {
    if (power == 0L) return 1L

    val half = binpow(power shl 1)

    var result = half mult half
    if (power.odd()) {
        result = result mult this
    }

    return result
}

val stepsXY = arrayOf(
    arrayOf(0, -1),
    arrayOf(0, 1),
    arrayOf(-1, 0),
    arrayOf(1, 0)
)

fun yesNo(yes : Boolean) {
    out.println(if (yes) "YES" else "NO")
}

fun run() {
    init()

    if (ONLINE_JUDGE) {
        solve()
    } else {
        while (true) {
            try {
                solve()
                out.println()
                out.flush()
            } catch (e : MultipleTestsEndException){
                break
            }
        }
    }
    out.close()
}

fun main(args: Array<String>) {
    run()
}

val ONLINE_JUDGE = !File("input.txt").exists()

val input = BufferedReader(
    if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader("input.txt")
)
val out =
    if (ONLINE_JUDGE) PrintWriter(System.out)
    else PrintWriter("output.txt")

fun readNullableLine(): String? = input.readLine()

class MultipleTestsEndException(): Exception()

fun readLine(): String {
    val line = readNullableLine()
    if (null == line) {
        throw MultipleTestsEndException()
    } else {
        return line
    }
}

fun readStrings(separator: String = " ", emptyWords: Boolean = false) : Array<String> {
    val line = readLine()

    val list = ArrayList<String>()
    var builder = StringBuilder()

    for (i in 0..line.length) {
        if (i == line.length || separator.contains(line[i])) {
            if (emptyWords || builder.isNotEmpty()) {
                list.add(builder.toString())
                builder = StringBuilder()
            }
        } else {
            builder.append(line[i])
        }
    }

    return list.toTypedArray()
}

fun readString(separator: String = " ") =
    readStrings(separator).first()

fun readInts(separator: String = " ") =
    readStrings(separator).map(String::toInt).toIntArray()

fun readDecreasedInts(separator : String = " ") =
    readInts(separator).map { it - 1 }.toIntArray()

fun readSortedInts(separator: String = " ") : IntArray {
    val a = readInts(separator)

    val aInteger = Array(a.size) { a[it] }
    Arrays.sort(aInteger)

    return aInteger.toIntArray()
}

fun readInt(separator: String = " ") =
    readInts(separator).first()

fun readLongs(separator: String = " ") =
    readStrings(separator).map(String::toLong).toLongArray()

fun readLong(separator: String = " ") =
    readLongs(separator).first()

fun readDoubles(separator: String = " ") =
    readStrings(separator).map(String::toDouble).toDoubleArray()

fun readDouble(separator: String = " ") =
    readDoubles(separator).first()

fun gcd(a : Int, b : Int) : Int =
    if (a == 0) b else gcd(b % a, a)

fun gcd(a : Long, b : Long) : Long =
    if (a == 0L) b else gcd(b % a, a)

fun getDivisors(x : Int) : MutableList<Int> {
    val divisors = ArrayList<Int>()

    var d = 1
    while (d * d <= x) {
        if (x % d == 0) {
            if (d != 1) divisors.add(d)
            if (x != d) divisors.add(x / d)
        }

        ++d
    }

    return divisors
}

fun getPrimeDivisors(xx : Int) : MutableList<Int> {
    val divisors = ArrayList<Int>()

    var d = 2
    var x = xx
    while (d * d <= x) {
        if (x % d == 0) {
            divisors.add(d)
            while (x % d == 0) {
                x /= d
            }
        }

        ++d
    }

    if (x > 1) divisors.add(x)

    return divisors
}

fun checkIndex(index : Int, size : Int) =
    0 <= index && index < size

fun toChar(index : Int, start : Char) =
    (index + start.toInt()).toChar()

class FenwickTree(n : Int) {

    val size = n + 1
    val tree = LongArray(size) { 0L }

    fun update(index : Int, delta : Int) {
        var x = index + 1
        while (x < size) {
            tree[x] = tree[x] + delta
            x += x and -x
        }
    }

    operator fun get(start : Int, end : Int) =
        get(end) - get(start - 1)

    operator fun get(index : Int) : Long {
        var result : Long = 0

        var x = index + 1
        while (x > 0) {
            result += tree[x]
            x -= x and -x
        }

        return result
    }
}


import java.io.*
import java.lang.Math.*
import java.math.BigInteger
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashMap
import kotlin.math.sqrt

typealias IntInt = Array<IntArray>
typealias LongLong = Array<LongArray>

fun solve() {
    var nn = readInt()
    var n = 0
    var ar = readInts()
    for (i in ar) if (i == -1) n++
    var a = Array(n){ ArrayList<Int>() }
    var now = -1
    var set = TreeSet<Int>()
    for (i in 0 until n) set.add(i)
    for (i in ar) {
        now = set.higher(now) ?: set.first()
        if (i == -1)
            set.remove(now)
        else
            a[now].add(i)
    }
    for (b in a) {
        print("${b.size} ")
        for (i in b) print("$i ")
        println()
    }
}

fun init() {

}

const val MODULO = 1000 * 1000 * 1000 + 7

fun stress() {
    val rnd = Random(1234)

    for (it in 0 until 100) {
        val expected = brute()
        val actual = fast()

        if (expected != actual) {
            System.err.println("Gotcha!")
            System.err.println("$expected $actual")

            break
        }
    }
}

fun fast() {

}

fun brute() {

}

class Vect (var x: Double, var y: Double) {
    operator fun plus(b: Vect) = Vect(x + b.x, y + b.y)
    operator fun times(b: Int) = Vect(x * b, y * b)
    operator fun div(b: Int) = Vect(x / b, y / b)
    operator fun minus(b: Vect) = Vect(x - b.x, y - b.y)
    operator fun div(b: Double) = Vect(x / b, y / b)
    infix fun scalar(b: Vect) = x * b.x + y * b.y
    infix fun cross(b: Vect) = x * b.y - y * b.x
    fun rotated90() = Vect(-y, x)
    fun length() = sqrt(x * x + y * y)
    infix fun angle(b: Vect) =
        kotlin.math.atan2(cross(b).toDouble(), scalar(b).toDouble())
    fun polarAngel() = Vect(1.0, 0.0) angle this
    infix fun trap2(b: Vect) = (b.x - x) * (y + b.y)
    override fun toString() = "$x $y"
    fun normir() = this / length()
}
operator fun Int.times(a: Vect) = a * this

fun Long.mod() : Long {
    var result = this % MODULO
    if (result < 0) result += MODULO
    return result
}

infix fun Long.add(other : Long) = (this + other).mod()
infix fun Long.sub(other : Long) = this add -other.mod()
infix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()

fun Long.even() = (this and 1L) == 0L
fun Long.odd() = !even()

fun Int.even() = (this and 1) == 0
fun Int.odd() = !even()

fun Long.bitCount() = java.lang.Long.bitCount(this)
fun Int.bitCount() = java.lang.Integer.bitCount(this)

operator fun Long.get(bit : Int) = ((this shr bit) and 1).toInt()
infix fun Long.check(bit : Int) = this[bit] != 0

operator fun Int.get(bit : Int) = (this shr bit) and 1
infix fun Int.check(bit : Int) = this[bit] != 0

infix fun Long.binpow(power : Long) : Long {
    if (power == 0L) return 1L

    val half = binpow(power shl 1)

    var result = half mult half
    if (power.odd()) {
        result = result mult this
    }

    return result
}

val stepsXY = arrayOf(
    arrayOf(0, -1),
    arrayOf(0, 1),
    arrayOf(-1, 0),
    arrayOf(1, 0)
)

fun yesNo(yes : Boolean) {
    out.println(if (yes) "YES" else "NO")
}

fun run() {
    init()

    if (ONLINE_JUDGE) {
        solve()
    } else {
        while (true) {
            try {
                solve()
                out.println()
                out.flush()
            } catch (e : MultipleTestsEndException){
                break
            }
        }
    }
    out.close()
}

fun main(args: Array<String>) {
    run()
}

val ONLINE_JUDGE = !File("input.txt").exists()

val input = BufferedReader(
    if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader("input.txt")
)
val out =
    if (ONLINE_JUDGE) PrintWriter(System.out)
    else PrintWriter("output.txt")

fun readNullableLine(): String? = input.readLine()

class MultipleTestsEndException(): Exception()

fun readLine(): String {
    val line = readNullableLine()
    if (null == line) {
        throw MultipleTestsEndException()
    } else {
        return line
    }
}

fun readStrings(separator: String = " ", emptyWords: Boolean = false) : Array<String> {
    val line = readLine()

    val list = ArrayList<String>()
    var builder = StringBuilder()

    for (i in 0..line.length) {
        if (i == line.length || separator.contains(line[i])) {
            if (emptyWords || builder.isNotEmpty()) {
                list.add(builder.toString())
                builder = StringBuilder()
            }
        } else {
            builder.append(line[i])
        }
    }

    return list.toTypedArray()
}

fun readString(separator: String = " ") =
    readStrings(separator).first()

fun readInts(separator: String = " ") =
    readStrings(separator).map(String::toInt).toIntArray()

fun readDecreasedInts(separator : String = " ") =
    readInts(separator).map { it - 1 }.toIntArray()

fun readSortedInts(separator: String = " ") : IntArray {
    val a = readInts(separator)

    val aInteger = Array(a.size) { a[it] }
    Arrays.sort(aInteger)

    return aInteger.toIntArray()
}

fun readInt(separator: String = " ") =
    readInts(separator).first()

fun readLongs(separator: String = " ") =
    readStrings(separator).map(String::toLong).toLongArray()

fun readLong(separator: String = " ") =
    readLongs(separator).first()

fun readDoubles(separator: String = " ") =
    readStrings(separator).map(String::toDouble).toDoubleArray()

fun readDouble(separator: String = " ") =
    readDoubles(separator).first()

fun gcd(a : Int, b : Int) : Int =
    if (a == 0) b else gcd(b % a, a)

fun gcd(a : Long, b : Long) : Long =
    if (a == 0L) b else gcd(b % a, a)

fun getDivisors(x : Int) : MutableList<Int> {
    val divisors = ArrayList<Int>()

    var d = 1
    while (d * d <= x) {
        if (x % d == 0) {
            if (d != 1) divisors.add(d)
            if (x != d) divisors.add(x / d)
        }

        ++d
    }

    return divisors
}

fun getPrimeDivisors(xx : Int) : MutableList<Int> {
    val divisors = ArrayList<Int>()

    var d = 2
    var x = xx
    while (d * d <= x) {
        if (x % d == 0) {
            divisors.add(d)
            while (x % d == 0) {
                x /= d
            }
        }

        ++d
    }

    if (x > 1) divisors.add(x)

    return divisors
}

fun checkIndex(index : Int, size : Int) =
    0 <= index && index < size

fun toChar(index : Int, start : Char) =
    (index + start.toInt()).toChar()

class FenwickTree(n : Int) {

    val size = n + 1
    val tree = LongArray(size) { 0L }

    fun update(index : Int, delta : Int) {
        var x = index + 1
        while (x < size) {
            tree[x] = tree[x] + delta
            x += x and -x
        }
    }

    operator fun get(start : Int, end : Int) =
        get(end) - get(start - 1)

    operator fun get(index : Int) : Long {
        var result : Long = 0

        var x = index + 1
        while (x > 0) {
            result += tree[x]
            x -= x and -x
        }

        return result
    }
}


import java.io.*
import java.lang.Math.*
import java.math.BigInteger
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.collections.LinkedHashMap
import kotlin.math.sqrt

typealias IntInt = Array<IntArray>
typealias LongLong = Array<LongArray>

fun solve() {
    var nn = readInt()
    var n = 0
    var ar = readInts()
    for (i in ar) if (i == -1) n++
    var a = Array(n){ ArrayList<Int>() }
    var now = -1
    var set = TreeSet<Int>()
    for (i in 0 until n) set.add(i)
    for (i in ar) {
        now = set.higher(now) ?: set.first()
        if (i == -1)
            set.remove(now)
        else
            a[now].add(i)
    }
    print(3)
    for (b in a) {
        print("${b.size} ")
        for (i in b) print("$i ")
        println()
    }
}

fun init() {

}

const val MODULO = 1000 * 1000 * 1000 + 7

fun stress() {
    val rnd = Random(1234)

    for (it in 0 until 100) {
        val expected = brute()
        val actual = fast()

        if (expected != actual) {
            System.err.println("Gotcha!")
            System.err.println("$expected $actual")

            break
        }
    }
}

fun fast() {

}

fun brute() {

}

class Vect (var x: Double, var y: Double) {
    operator fun plus(b: Vect) = Vect(x + b.x, y + b.y)
    operator fun times(b: Int) = Vect(x * b, y * b)
    operator fun div(b: Int) = Vect(x / b, y / b)
    operator fun minus(b: Vect) = Vect(x - b.x, y - b.y)
    operator fun div(b: Double) = Vect(x / b, y / b)
    infix fun scalar(b: Vect) = x * b.x + y * b.y
    infix fun cross(b: Vect) = x * b.y - y * b.x
    fun rotated90() = Vect(-y, x)
    fun length() = sqrt(x * x + y * y)
    infix fun angle(b: Vect) =
        kotlin.math.atan2(cross(b).toDouble(), scalar(b).toDouble())
    fun polarAngel() = Vect(1.0, 0.0) angle this
    infix fun trap2(b: Vect) = (b.x - x) * (y + b.y)
    override fun toString() = "$x $y"
    fun normir() = this / length()
}
operator fun Int.times(a: Vect) = a * this

fun Long.mod() : Long {
    var result = this % MODULO
    if (result < 0) result += MODULO
    return result
}

infix fun Long.add(other : Long) = (this + other).mod()
infix fun Long.sub(other : Long) = this add -other.mod()
infix fun Long.mult(other : Long) = (this.mod() * other.mod()).mod()

fun Long.even() = (this and 1L) == 0L
fun Long.odd() = !even()

fun Int.even() = (this and 1) == 0
fun Int.odd() = !even()

fun Long.bitCount() = java.lang.Long.bitCount(this)
fun Int.bitCount() = java.lang.Integer.bitCount(this)

operator fun Long.get(bit : Int) = ((this shr bit) and 1).toInt()
infix fun Long.check(bit : Int) = this[bit] != 0

operator fun Int.get(bit : Int) = (this shr bit) and 1
infix fun Int.check(bit : Int) = this[bit] != 0

infix fun Long.binpow(power : Long) : Long {
    if (power == 0L) return 1L

    val half = binpow(power shl 1)

    var result = half mult half
    if (power.odd()) {
        result = result mult this
    }

    return result
}

val stepsXY = arrayOf(
    arrayOf(0, -1),
    arrayOf(0, 1),
    arrayOf(-1, 0),
    arrayOf(1, 0)
)

fun yesNo(yes : Boolean) {
    out.println(if (yes) "YES" else "NO")
}

fun run() {
    init()

    if (ONLINE_JUDGE) {
        solve()
    } else {
        while (true) {
            try {
                solve()
                out.println()
                out.flush()
            } catch (e : MultipleTestsEndException){
                break
            }
        }
    }
    out.close()
}

fun main(args: Array<String>) {
    run()
}

val ONLINE_JUDGE = !File("input.txt").exists()

val input = BufferedReader(
    if (ONLINE_JUDGE) InputStreamReader(System.`in`) else FileReader("input.txt")
)
val out =
    if (ONLINE_JUDGE) PrintWriter(System.out)
    else PrintWriter("output.txt")

fun readNullableLine(): String? = input.readLine()

class MultipleTestsEndException(): Exception()

fun readLine(): String {
    val line = readNullableLine()
    if (null == line) {
        throw MultipleTestsEndException()
    } else {
        return line
    }
}

fun readStrings(separator: String = " ", emptyWords: Boolean = false) : Array<String> {
    val line = readLine()

    val list = ArrayList<String>()
    var builder = StringBuilder()

    for (i in 0..line.length) {
        if (i == line.length || separator.contains(line[i])) {
            if (emptyWords || builder.isNotEmpty()) {
                list.add(builder.toString())
                builder = StringBuilder()
            }
        } else {
            builder.append(line[i])
        }
    }

    return list.toTypedArray()
}

fun readString(separator: String = " ") =
    readStrings(separator).first()

fun readInts(separator: String = " ") =
    readStrings(separator).map(String::toInt).toIntArray()

fun readDecreasedInts(separator : String = " ") =
    readInts(separator).map { it - 1 }.toIntArray()

fun readSortedInts(separator: String = " ") : IntArray {
    val a = readInts(separator)

    val aInteger = Array(a.size) { a[it] }
    Arrays.sort(aInteger)

    return aInteger.toIntArray()
}

fun readInt(separator: String = " ") =
    readInts(separator).first()

fun readLongs(separator: String = " ") =
    readStrings(separator).map(String::toLong).toLongArray()

fun readLong(separator: String = " ") =
    readLongs(separator).first()

fun readDoubles(separator: String = " ") =
    readStrings(separator).map(String::toDouble).toDoubleArray()

fun readDouble(separator: String = " ") =
    readDoubles(separator).first()

fun gcd(a : Int, b : Int) : Int =
    if (a == 0) b else gcd(b % a, a)

fun gcd(a : Long, b : Long) : Long =
    if (a == 0L) b else gcd(b % a, a)

fun getDivisors(x : Int) : MutableList<Int> {
    val divisors = ArrayList<Int>()

    var d = 1
    while (d * d <= x) {
        if (x % d == 0) {
            if (d != 1) divisors.add(d)
            if (x != d) divisors.add(x / d)
        }

        ++d
    }

    return divisors
}

fun getPrimeDivisors(xx : Int) : MutableList<Int> {
    val divisors = ArrayList<Int>()

    var d = 2
    var x = xx
    while (d * d <= x) {
        if (x % d == 0) {
            divisors.add(d)
            while (x % d == 0) {
                x /= d
            }
        }

        ++d
    }

    if (x > 1) divisors.add(x)

    return divisors
}

fun checkIndex(index : Int, size : Int) =
    0 <= index && index < size

fun toChar(index : Int, start : Char) =
    (index + start.toInt()).toChar()

class FenwickTree(n : Int) {

    val size = n + 1
    val tree = LongArray(size) { 0L }

    fun update(index : Int, delta : Int) {
        var x = index + 1
        while (x < size) {
            tree[x] = tree[x] + delta
            x += x and -x
        }
    }

    operator fun get(start : Int, end : Int) =
        get(end) - get(start - 1)

    operator fun get(index : Int) : Long {
        var result : Long = 0

        var x = index + 1
        while (x > 0) {
            result += tree[x]
            x -= x and -x
        }

        return result
    }
}


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    //var q=0
    var L=mutableListOf<Int>()
    println(ct)

    for (i in 0 until ct) {
        if (A[i]>-1) {
            B[i].add(A[i])
            L.add(i)
        }
    }

    for (i in ct until n) {
        if (A[i]==-1) p++
        else {
            val q=L[p]
            B[q].add(A[i])
            L.add(q)
            p++
        }
    }

    println(B.joinToString(separator="\n") { it->it.joinToString(prefix="${it.count()} ",separator=" ") })
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{it.toInt()}
    val c = b.count{it==-1}
    val x : MutableList<MutableList<Int>> = mutableListOf()
    for (q in 1..c) { x.add(mutableListOf()) }
    var f = BooleanArray(c){true}
    var p = 0

    while (p<b.size) {
        for (q in 0..(c-1)) {
            if (f[q]) {
                if (b[p]==-1) {
                    f[q]=false
                    p++
                }
                else {
                    x[q].add(b[p])
                    p++
                }
            }
        }
    }

    for (q in 0..(c-1)) {
        print (x[q].size)
        print (" ")
        for (z in x[q]) {
            print(z)
            print(" ")
        }
        println()
    }
}


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    var L=mutableListOf<Int>()
    for (i in 0 until ct) L.add(i)
    var F=BooleanArray(ct)
    println(ct)

    for (v in A) {
        if (v==-1) {
            L.remove(p)
            ct--
            if(p==ct) p=0
        }
        else {
            B[L[p]].add(v)
            p++
            if(p==ct) p=0
        }
    }

    for (i in 0 until B.count()) {
        print(B[i].count())
        print(" ")
        println(B[i].joinToString(" "))
    }
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    var L=mutableListOf<Int>()
    for (i in 0 until ct) L.add(i)
    println(ct)
    var op=IntArray(n-ct)

    for (v in A) {
        if (v==-1) L.removeAt(0)
        else {
            val q=L.removeAt(0)
            B[q].add(v)
            L.add(q)
        }
    }

    for (i in 0 until B.count()) {
        print(B[i].count())
        print(" ")
        println(B[i].joinToString(" "))
    }
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    var L=mutableListOf<Int>()
    println(ct)

    for (i in 0 until ct) {
        if (A[i]>-1) {
            B[i].add(A[i])
            L.add(i)
        }
    }

    for (i in ct until n) {
        if (A[i]==-1) L.removeAt(0)
        else {
            val q=L.removeAt(0)
            B[q].add(A[i])
            L.add(q)
        }
    }

    println(B.joinToString(separator="\n") { it->it.joinToString(prefix="${it.count()} ",separator=" ") })
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{it.toInt()}
    val c = b.count{it==-1}
    var x = Array(c,{mutableListOf<Int>()})
    var s = IntArray(c){0}
    var f = BooleanArray(c){true}
    var p = 0

    while (p<b.size) {
        for (q in 0..(c-1)) {
            if (f[q]) {
                if (b[p]==-1) {
                    f[q]=false
                    p++
                }
                else {
                    x[q].add(b[p])
                    s[q]++
                    p++
                }
            }
        }
    }

    val sb=StringBuilder()
    sb.append(c)
    sb.append("\n")
    for (q in 0..(c-1)) {
        sb.append(s[q])
        sb.append(" ")
        for (z in x[q]) {
            sb.append(z)
            sb.append(" ")
        }
        sb.append("\n")
    }
    println(sb)
}


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    var L=mutableListOf<Int>()
    println(ct)

    for (i in 0 until ct) {
        if (A[i]>-1) {
            B[i].add(A[i])
            L.add(i)
        }
    }

    for (i in ct until n) {
        if (A[i]==-1) L.removeAt(0)
        else {
            val q=L[p]
            B[q].add(A[i])
            L.add(q)
            p++
        }
    }

    println(B.joinToString(separator="\n") { it->it.joinToString(prefix="${it.count()} ",separator=" ") })
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{it.toInt()}
    val c = b.count{it==-1}
    var x = Array(c,{mutableListOf<Int>()})
    var s = IntArray(c){0}
    var f = BooleanArray(c){true}
    var p = 0

    while (p<b.size) {
        for (q in 0..(c-1)) {
            if (f[q]) {
                if (b[p]==-1) {
                    f[q]=false
                    p++
                }
                else {
                    x[q].add(b[p])
                    s[q]++
                    p++
                }
            }
        }
    }
    println(c)
    for (q in 0..(c-1)) {
        print (s[q])
        print (" ")
        for (z in x[q]) {
            print(z)
            print(" ")
        }
        println()
    }
}


fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{it.toInt()}
    val c = b.count{it==-1}
    var x = Array(c,{IntArray(a)})
    var s = IntArray(c){0}
    var f = BooleanArray(c){true}
    var p = 0

    while (p<b.size) {
        for (q in 0..(c-1)) {
            if (f[q]) {
                if (b[p]==-1) {
                    f[q]=false
                    p++
                }
                else {
                    x[q][s[q]]=b[p]
                    s[q]++
                    p++
                }
            }
        }
    }
    println(c)
    for (q in 0..(c-1)) {
        print (s[q])
        print (" ")
        for (z in 0..(s[q]-1)) {
            print(x[q][z])
            print(" ")
        }
        println()
    }
}


fun main(args: Array<String>) {
    val a = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{it.toInt()}
    val c = b.count{it==-1}
    val x : MutableList<MutableList<Int>> = mutableListOf()
    for (q in 1..c) { x.add(mutableListOf()) }
    var f = BooleanArray(c){true}
    var p = 0

    while (p<b.size) {
        for (q in 0..(c-1)) {
            if (f[q]) {
                if (b[p]==-1) {
                    f[q]=false
                    p++
                }
                else {
                    x[q].add(b[p])
                    p++
                }
            }
        }
    }
    println(c)
    for (q in 0..(c-1)) {
        print (x[q].size)
        print (" ")
        for (z in x[q]) {
            print(z)
            print(" ")
        }
        println()
    }
}


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    var L=mutableListOf<Int>()
    for (i in 0 until ct) L.add(i)
    println(ct)
    var orig=ct

    for (v in A) {
        if (v==-1) L.removeAt(0)
        else {
            val q=L.removeAt(0)
            B[q].add(v)
            L.add(q)
        }
    }

    println(B.joinToString(separator="\n") { it->it.joinToString(prefix="${it.count()} ",separator=" ") })
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main() {
    val n = readInt()
    val A=readInts().toTypedArray()
    var ct=0;
    for (v in A)
        if (v==-1) ct++

    var B=Array(ct){mutableListOf<Int>()}
    var p=0
    var L=mutableListOf<Int>()
    for (i in 0 until ct) L.add(i)
    println(ct)

    for (v in A) {
        if (v==-1) {
            L.removeAt(p)
            ct--
            if(p==ct) p=0
        }
        else {
            B[L[p]].add(v)
            p++
            if(p==ct) p=0
        }
    }

    for (i in 0 until B.count()) {
        print(B[i].count())
        print(" ")
        println(B[i].joinToString(" "))
    }
}

fun gcd (a: Int,b: Int): Int= if (b==0) a else gcd(b,a%b)

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main() {
    val nNumbers = readLine()!!.toInt()
    val numbers = readLine()!!.split(' ').map(String::toInt).toIntArray()

    var minusIndexes = ArrayList<Int>()
    val nSeq = numbers
        .asIterable()
        .filterIndexed(fun(index: Int, n: Int): Boolean {
            if(n == -1) {
                minusIndexes.add(index)
                return true
            } else {
                return false
            }
        }).count()

    println(nSeq)
    var nEmpty = 0
    for (n in 0 until nSeq) {
        var step = nSeq - nEmpty
        var nextStep = step
        var index = n
        val seq = ArrayList<Int>(nNumbers / nSeq)
        while (index <= numbers.lastIndex && numbers[index] != -1 && step > 0) {
            seq.add(numbers[index])
            nextStep = step - calcIndexes(minusIndexes, index, index + step)
            index += step // detect step
            step = nextStep
        }

        print(seq.size)
        if (seq.size == 0) {
            nEmpty += 1
        } else {
            print(" ")
            print(seq.joinToString(" "))
        }
        println()
    }
}

fun calcIndexes(indexesList: List<Int>, from: Int, to: Int): Int {
    return indexesList.filter(fun(ind: Int): Boolean {
        return ind in (from + 1)..to
    }).count()
}


fun main() {
    val nNumbers = readLine()!!.toInt()
    val numbers = readLine()!!.split(' ').map(String::toInt).toIntArray()

    val nSeq = numbers.asIterable().filter(fun(n: Int): Boolean { return n == -1 }).count()
    println(nSeq)
    var step = nSeq
    for (n in 0 until nSeq) {
        var index = n
        val seq = ArrayList<Int>(nNumbers / nSeq)
        while (index < numbers.lastIndex && numbers[index] != -1 && step > 0) {
            seq.add(numbers[index])
            index += step
        }

        print(seq.size)
        if (seq.size == 0) {
            step -= 1
        } else {
            print(" ")
            print(seq.joinToString(" "))
        }
        println()
    }
}


fun main() {
    val nNumbers = readLine()!!.toInt()
    val numbers = readLine()!!.split(' ').map(String::toInt).toIntArray()

    var minusIndexes = ArrayList<Int>()
    var minusesCounts = ArrayList<Int>(numbers.size)
    val nSeq = numbers
        .asIterable()
        .filterIndexed(fun(index: Int, n: Int): Boolean {
            val isMinuses = n == -1
            var nMinuses = 0
            if (index != 0) {
                nMinuses = minusesCounts[index - 1]
            }
            if (isMinuses) {
                nMinuses++
            }
            minusesCounts.add(nMinuses)

            return isMinuses
        }).count()

    println(nSeq)
    var nEmpty = 0
    for (n in 0 until nSeq) {
        var step = nSeq - nEmpty
        var nextStep = step
        var index = n
        val seq = ArrayList<Int>(nNumbers / nSeq)
        while (index <= numbers.lastIndex && numbers[index] != -1 && step > 0) {
            seq.add(numbers[index])
            nextStep = step - calcIndexes(minusesCounts, index, index + step)
            index += step // detect step
            step = nextStep
        }

        print(seq.size)
        if (seq.size == 0) {
            nEmpty += 1
        } else {
            print(" ")
            print(seq.joinToString(" "))
        }
        println()
    }
}

fun calcIndexes(minCounts: List<Int>, from: Int, to: Int): Int {
    return minCounts[to] - minCounts[from]
}


fun main() {
    val nNumbers = readLine()!!.toInt()
    val numbers = readLine()!!.split(' ').map(String::toInt).toIntArray()

    val nSeq = numbers.asIterable().filter(fun(n: Int): Boolean { return n == -1 }).count()
    println(nSeq)
    for (n in 0 until nSeq) {
        var index = n
        var seq = ArrayList<Int>(nNumbers / nSeq)
        while (index < numbers.lastIndex && numbers[index] != -1 ) {
            seq.add(numbers[index])
            index += nSeq
        }

        print(seq.size)
        print(" ")
        print(seq.joinToString(" "))
        println()
    }
}


import java.lang.StringBuilder

fun readStr(): String = readLine()!!
fun readInt(): Int = readLine()!!.toInt()
fun readIntArray(): IntArray {
    val s = readStr().split(" ")
    val l = s.size
    val arr = IntArray(l)
    for (i in 0 until l) {
        arr[i] = Integer.parseInt(s[i])
    }
    return arr
}

fun solve(arr: IntArray): List<List<Int>> {
    val len = arr.size
    var num = 0
    for (a in arr) {
        if (a < 0) {
            num++
        }
    }
    val ret = MutableList<MutableList<Int>>(num) {
        mutableListOf()
    }
    val remain = mutableListOf<Int>()
    for (i in 0 until num) {
        remain.add(i)
    }
    var remainNum = num
    var idx = 0
    for (a in arr) {
        if (a >= 0) {
            val k = remain[idx]
            ret[k].add(a)
            idx = (idx + 1) % remainNum
        } else {
            remainNum--
            remain.remove(idx)
            if (idx >= remainNum) {
                idx = 0
            }
        }
    }
    return ret
}
fun convert(arr: List<Int>): String {
    val len = arr.size
    val r = StringBuilder(len * 2)
    r.append(len)
    for (a in arr) {
        r.append(" ")
        r.append(a)
    }
    return r.toString()
}

fun main(args: Array<String>) {
    readLine()
    val arr = readIntArray()
    val ans = solve(arr)
    println(ans.size)
    ans.forEach {
        val s = convert(it)
        println(s)
    }
}


import java.lang.StringBuilder
import java.util.*
import kotlin.collections.ArrayList

class Link(var idx: Int) {
    var next: Link = this
    var prev: Link = this
}

fun solve(arr: IntArray): Array<ArrayList<Int>> {
    val time = System.currentTimeMillis()
    val len = arr.size
    val num = arr.count { it < 0 }
    val ret = Array<ArrayList<Int>>(num) {
        ArrayList<Int>(len / num)
    }
    val links = Array<Link>(num) {
        Link(it)
    }
    for (i in 0 until num) {
        if (i == 0) {
            links[0].prev = links[num - 1]
        } else {
            links[i].prev = links[i - 1]
        }
        if (i < num - 1) {
            links[i].next = links[i + 1]
        } else {
            links[i].next = links[0]
        }
    }
    var current = links[0]
    for (a in arr) {
        if (a >= 0) {
            val k = current.idx
            ret[k].add(a)
            current = current.next
        } else {
            current.prev.next = current.next
            current.next.prev = current.prev
            current = current.next
        }
    }
    return ret
}
fun convert(buf: StringBuilder, arr: List<Int>) {
    val len = arr.size
    buf.append(len)
    for (a in arr) {
        buf.append(' ')
        buf.append(a)
    }
    buf.append('\n')
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val num = scanner.nextInt()
    val arr = IntArray(num) {
        scanner.nextInt()
    }
    val ans = solve(arr)
    val sb = StringBuilder(arr.size * 3)
    sb.append(ans.size)
    sb.append('\n')
    ans.forEach {
        convert(sb, it)
    }
    println(sb)
}


import java.lang.StringBuilder
import java.util.*
import kotlin.collections.ArrayList

fun solve(arr: IntArray): Array<ArrayList<Int>> {
    val time = System.currentTimeMillis()
    val len = arr.size
    val num = arr.count { it < 0 }
    val ret = Array<ArrayList<Int>>(num) {
        ArrayList<Int>(len / num)
    }
    val remain = LinkedList<Int>()
    for (i in 0 until num) {
        remain.add(i)
    }
    var remainNum = num
    var idx = 0
    for (a in arr) {
        if (a >= 0) {
            val k = remain[idx]
            ret[k].add(a)
            idx = (idx + 1) % remainNum
        } else {
            remainNum--
            remain.removeAt(idx)
            if (idx >= remainNum) {
                idx = 0
            }
        }
    }
    return ret
}
fun convert(buf: StringBuilder, arr: List<Int>) {
    val len = arr.size
    val r = StringBuilder(len * 2)
    buf.append(len)
    for (a in arr) {
        buf.append(' ')
        buf.append(a)
    }
    buf.append('\n')
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val num = scanner.nextInt()
    val arr = IntArray(num) {
        scanner.nextInt()
    }
    val ans = solve(arr)
    val sb = StringBuilder(arr.size * 2)
    sb.append(ans.size)
    sb.append('\n')
    ans.forEach {
        convert(sb, it)
    }
    println(sb)
}


fun readStr(): String = readLine()!!
fun readInt(): Int = readLine()!!.toInt()
fun readIntArray(): IntArray {
    val s = readStr().split(" ")
    val l = s.size
    val arr = IntArray(l)
    for (i in 0 until l) {
        arr[i] = Integer.parseInt(s[i])
    }
    return arr
}

fun main(args: Array<String>) {
    readLine()
    val arr = readIntArray()
    println(arr.size)
    arr.forEach {
        val s = if (it < 0) 0 else it
        println(s)
    }
}


fun readStr(): String = readLine()!!
fun readInt(): Int = readLine()!!.toInt()
fun readIntArray(): IntArray {
    val s = readStr().split(" ")
    val l = s.size
    val arr = IntArray(l)
    for (i in 0 until l) {
        arr[i] = Integer.parseInt(s[i])
    }
    return arr
}

fun main(args: Array<String>) {
    readLine()
    val arr = readIntArray()
    println(arr.size)
    arr.forEach {
        if (it < 0) {
            println("0")
        } else {
            println("1 $it")
        }
    }
}


import java.lang.StringBuilder
import java.util.*

fun readStr(): String = readLine()!!
fun readInt(): Int = readLine()!!.toInt()
fun readIntArray(): IntArray {
    val s = readStr().split(" ")
    val l = s.size
    val arr = IntArray(l)
    for (i in 0 until l) {
        arr[i] = Integer.parseInt(s[i])
    }
    return arr
}

fun solve(arr: IntArray): Array<Vector<Int>> {
    val len = arr.size
    var num = 0
    for (a in arr) {
        if (a < 0) {
            num++
        }
    }
    val ret = Array<Vector<Int>>(num) {
        Vector(len / num)
    }
    val remain = Vector<Int>(num)
    for (i in 0 until num) {
        remain.add(i)
    }
    var remainNum = num
    var idx = 0
    for (a in arr) {
        if (a >= 0) {
            val k = remain[idx]
            ret[k].add(a)
            idx = (idx + 1) % remainNum
        } else {
            remainNum--
            remain.removeAt(idx)
            if (idx >= remainNum) {
                idx = 0
            }
        }
    }
    return ret
}
fun convert(arr: Vector<Int>): CharSequence {
    val len = arr.size
    val r = StringBuilder(len * 2)
    r.append(len)
    for (a in arr) {
        r.append(' ')
        r.append(a)
    }
    return r
}

fun main(args: Array<String>) {
    readLine()
    val arr = readIntArray()
    val ans = solve(arr)
    println(ans.size)
    ans.forEach {
        val s = convert(it)
        println(s)
    }
}


import java.lang.StringBuilder

fun readStr(): String = readLine()!!
fun readInt(): Int = readLine()!!.toInt()
fun readIntArray(): IntArray {
    val s = readStr().split(" ")
    val l = s.size
    val arr = IntArray(l)
    for (i in 0 until l) {
        arr[i] = Integer.parseInt(s[i])
    }
    return arr
}

fun solve(arr: IntArray): List<List<Int>> {
    val len = arr.size
    var num = 0
    for (a in arr) {
        if (a < 0) {
            num++
        }
    }
    val ret = MutableList<MutableList<Int>>(num) {
        mutableListOf()
    }
    val remain = mutableListOf<Int>()
    for (i in 0 until num) {
        remain.add(i)
    }
    var remainNum = num
    var idx = 0
    for (a in arr) {
        if (a >= 0) {
            val k = remain[idx]
            ret[k].add(a)
            idx = (idx + 1) % remainNum
        } else {
            remainNum--
            remain.removeAt(idx)
            if (idx >= remainNum) {
                idx = 0
            }
        }
    }
    return ret
}
fun convert(arr: List<Int>): String {
    val len = arr.size
    val r = StringBuilder(len * 2)
    r.append(len)
    for (a in arr) {
        r.append(" ")
        r.append(a)
    }
    return r.toString()
}

fun main(args: Array<String>) {
    readLine()
    val arr = readIntArray()
    val ans = solve(arr)
    println(ans.size)
    ans.forEach {
        val s = convert(it)
        println(s)
    }
}


fun main() {
    readLine()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = List(n) { mutableListOf<Int>() }
    var i = 0
    for (elem in b) {
        while (a[i].any() && (a[i].last() == -1)) {
            i = (i + 1) % n
        }
        a[i].add(elem)
        i = (i + 1) % n
    }
    println(n)
    for (seq in a) {
        println("${ seq.size - 1 } " + seq.dropLast(1).joinToString(" "))
    }
}


fun main() {
    readLine()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = List(n) { mutableListOf<Int>() }
    val indices = MutableList<Int>(n) { it }
    var i = 0
    for (elem in b) {
        a[indices[i]].add(elem)
        if (elem == -1) {
            indices.removeAt(i)
        } else {
            ++i
        }
        if (indices.any()) i = i % indices.size
    }
    println(n)
    for (seq in a) {
        println("${ seq.size - 1 } " + seq.dropLast(1).joinToString(" "))
    }
}


import java.util.*

fun main() {
    readLine()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = Array(n) { ArrayList<Int>() }
    var i = 0
    for (elem in b) {
        while (a[i].any() && (a[i].last() == -1)) {
            i = (i + 1) % n
        }
        a[i].add(elem)
        i = (i + 1) % n
    }
    println(n)
    for (seq in a) {
        println("${ seq.size - 1 } " + seq.dropLast(1).joinToString(" "))
    }
}


fun main() {
    readLine()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    println(n)
    val a = List(n) { mutableListOf<Int>() }
    val indices = List(n) { it }.toMutableSet()
    var iter = indices.iterator()
    for (x in b) {
        if (!iter.hasNext()) {
            iter = indices.iterator()
        }
        val i = iter.next()
        a[i].add(x)
        if (x == -1) {
            iter.remove()
        }
    }
    for (seq in a) {
        println("${seq.size - 1} " + seq.dropLast(1).joinToString(" "))
    }
}


fun main() {
    readLine()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = List(n) { mutableListOf<Int>() }
    var i = 0
    for (elem in b) {
        while ((a[i].size > 0) && (a[i][a[i].size - 1] == -1)) {
            i = (i + 1) % n
        }
        a[i].add(elem)
        i = (i + 1) % n
    }
    println(n)
    for (seq in a) {
        println("${ seq.size - 1 } " + seq.dropLast(1).joinToString(" "))
    }
}


fun main() {
    readLine()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = List(n) { mutableListOf<Int>() }
    val indices = MutableList<Int>(n) { it }
    var i = 0
    for (elem in b) {
        a[indices[i]].add(elem)
        if (elem == -1) {
            indices.removeAt(i)
        } else {
            i = (i + 1) % indices.size
        }
    }
    println(n)
    for (seq in a) {
        println("${ seq.size - 1 } " + seq.dropLast(1).joinToString(" "))
    }
}


import java.util.*

fun main() {
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{ it.toInt() }

    val a : MutableList<MutableList<Int>> = ArrayList()
    for (x in b) {
        if (x == -1) {
            a.add(ArrayList<Int>())
        }
    }
    val n = a.size
    val next = ArrayList<Int>()
    for (i in 0..n-1) {
        next.add(i+1)
    }
    next[n-1] = 0

    var cur = 0
    var prev = n-1
    for (x in b) {
        if (x == -1) {
            // remove array
            next[prev] = next[cur]
        } else {
            a[cur].add(x)
            prev = cur
        }
        cur = next[cur]
    }

    println(n)
    println(a.joinToString("\n") {
        "$$${it.size} $$${it.joinToString(" ")}"
    })
}


fun main() {
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{ it.toInt() }

    val a : MutableList<MutableList<Int>> = ArrayList()
    for (x in b) {
        if (x == -1) {
            a.add(ArrayList<Int>())
        }
    }
    val n = a.size
    val next = ArrayList<Int>()
    for (i in 0..n-1) {
        next.add(i+1)
    }
    next[n-1] = 0

    var cur = 0
    var prev = n-1
    for (x in b) {
        if (x == -1) {
            // remove array
            next[prev] = next[cur]
        } else {
            a[cur].add(x)
        }
        cur = next[cur]
    }

    println(n)
    for (sequence in a) {
        print(sequence.size)
        for (x in sequence)
            print(" $x")
        println()
    }
}


import java.util.*

fun main() {
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{ it.toInt() }

    val a : MutableList<MutableList<Int>> = ArrayList()
    for (x in b) {
        if (x == -1) {
            a.add(ArrayList<Int>())
        }
    }
    val n = a.size
    val next = ArrayList<Int>()
    for (i in 0..n-1) {
        next.add(i+1)
    }
    next[n-1] = 0

    var cur = 0
    var prev = n-1
    for (x in b) {
        if (x == -1) {
            // remove array
            next[prev] = next[cur]
        } else {
            a[cur].add(x)
            prev = cur
        }
        cur = next[cur]
    }

    println(n)
    println(a.joinToString("\n") {
        "${it.size} ${it.joinToString(" ")}"
    })
}


import java.util.*

fun main() {
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map{ it.toInt() }

    val a : MutableList<MutableList<Int>> = ArrayList()
    for (x in b) {
        if (x == -1) {
            a.add(ArrayList<Int>())
        }
    }
    val n = a.size
    val next = ArrayList<Int>()
    for (i in 0..n-1) {
        next.add(i+1)
    }
    next[n-1] = 0

    var cur = 0
    var prev = n-1
    for (x in b) {
        if (x == -1) {
            // remove array
            next[prev] = next[cur]
        } else {
            a[cur].add(x)
            prev = cur
        }
        cur = next[cur]
    }

    println(n)
    for (sequence in a) {
        print(sequence.size)
        for (x in sequence)
            print(" $x")
        println()
    }
}


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve() {
    val n = readInt()
    val a = readInts()

    var cnt = 0
    for (i in a) if (i == -1) cnt++

    val ans = Array(cnt, { ArrayList<Int>() })
    val now = HashSet<Int>()
    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        val del = ArrayList<Int>()
        for(x in now){
            if(a[i] == -1) del.add(x)
            else ans[x].add(a[i])
            i++
        }
        for(x in del) now.remove(x)
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(x in v){
            print("$x ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve() {
    val n = readInt()
    val a = readInts()

    var cnt = 0
    for (i in a) if (i == -1) cnt++

    val ans = Array(cnt, { ArrayList<Int>() })
    val now = LinkedHashSet<Int>()
    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        val del = ArrayList<Int>()
        for(x in now){
            if(a[i] == -1) del.add(x)
            else ans[x].add(a[i])
            i++
        }
        for(x in del) now.remove(x)
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(x in v){
            print("$x ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve(){
    val n = readInt()
    val a = readInts()
    var cnt = 0
    for(i in 0 until n){
        if(a[i] == -1) cnt++
    }

    val ans = Array<ArrayList<Int>?>(cnt, {null})
    val now = HashSet<Int>()

    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var j = i
        val del = ArrayList<Int>()
        for(id in now){
            if(a[j] == -1){
                del.add(id)
            }else{
                if(ans[id] == null) ans[id] = ArrayList<Int>()
                ans[id]?.add(a[j])
            }
            j++
        }
        i += now.size
        for(id in del) {
            now.remove(id)
        }
    }

    println(cnt)
    for(v in ans){
        print("${if(v == null) 0 else v.size} ")
        if (v != null) {
            for(x in v){
                print("$x ")
            }
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve(){
    val n = readInt()
    val a = readInts()
    var cnt = 0
    for(i in 0 until n){
        if(a[i] == -1) cnt++
    }

    val ans = Array(cnt, {ArrayList<Int>()})
    val now = HashSet<Int>()

    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var j = i
        val del = ArrayList<Int>()
        for(id in now){
            if(a[j] == -1){
                del.add(id)
            }else{
                ans[id].add(a[j])
            }
            j++
        }
        i += now.size
        for(id in del) {
            now.remove(id)
        }
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(i in v){
            print("$i ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve(){
    val n = readInt()
    val a = readInts()
    var cnt = 0
    for(i in 0 until n){
        if(a[i] == -1) cnt++
    }

    val ans = Array(cnt, {ArrayList<Int>(n)})
    val now = HashSet<Int>()

    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var j = i
        val del = ArrayList<Int>()
        for(id in now){
            if(a[j] == -1){
                del.add(id)
            }else{
                ans[id].add(a[j])
            }
            j++
        }
        i += now.size
        for(id in del) {
            now.remove(id)
        }
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(i in v){
            print("$i ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve(){
    val n = readInt()
    val a = readInts()
    var cnt = 0
    for(i in 0 until n){
        if(a[i] == -1) cnt++
    }

    val ans = Array(cnt, {ArrayList<Int>()})
    val now = HashSet<Int>()

    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var j = i
        val del = ArrayList<Int>()
        for(id in now){
            if(a[j] == -1){
                del.add(id)
            }else{
                ans[id].add(a[j])
            }
            j++
        }
        i += now.size
        for(id in del) {
            now.remove(id)
        }
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(x in v){
            print("$x ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve() {
    var n = readInt()
    var a = readInts()

    var cnt = 0
    for (i in a) if (i == -1) cnt++

    var ans = Array(cnt, { ArrayList<Int>() })
    var now = HashSet<Int>()
    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var del = ArrayList<Int>()
        for(x in now){
            if(a[i] == -1) del.add(x)
            else ans[x].add(a[i])
            i++
        }
        for(x in del) now.remove(x)
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(x in v){
            print("$x ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve(){
    val n = readInt()
    val a = readInts()
    var cnt = 0
    for(i in 0 until n){
        if(a[i] == -1) cnt++
    }

    val ans = Array<ArrayList<Int>?>(cnt, {null})
    val now = HashSet<Int>()

    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var j = i
        val del = ArrayList<Int>()
        for(id in now){
            if(a[j] == -1){
                del.add(id)
            }else{
                if(ans[id] == null) ans[id] = ArrayList<Int>()
                ans[id]?.add(a[j])
            }
            j++
        }
        i += now.size
        for(id in del) {
            now.remove(id)
        }
    }

    println(cnt)
    for(v in ans){
        print("${if(v == null) 0 else v.size} ")
        if (v != null) {
            for(x in v){
                print("$x ")
            }
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
}

val input = BufferedReader(
        InputStreamReader(System.`in`)
)
val out =
        PrintWriter("output.txt")

fun readNullableLine(): String? = input.readLine()

class MultipleTestsEndException: Exception()

fun readLine(): String {
    val line = readNullableLine()
    if (null == line) {
        throw MultipleTestsEndException()
    } else {
        return line
    }
}

fun readStrings(separator: String = " ", emptyWords: Boolean = false) : List<String> =//    val line = readLine()
        readLine().split(separator)

fun readString(separator: String = " ") =
        readStrings(separator).first()

fun readInts(separator: String = " ") =
        readStrings(separator).map(String::toInt).toIntArray()

fun readInt(separator: String = " ") =
        readInts(separator).first()

fun readLongs(separator: String = " ") =
        readStrings(separator).map(String::toLong).toLongArray()

fun readLong(separator: String = " ") =
        readLongs(separator).first()

fun readDoubles(separator: String = " ") =
        readStrings(separator).map(String::toDouble).toDoubleArray()

fun readDouble(separator: String = " ") =
        readDoubles(separator).first()


import java.io.BufferedReader
import java.io.FileReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.abs
import java.util.Queue as Queue

val INF = 2e9.toInt()

fun solve(){
    val n = readInt()
    val a = readInts()
    var cnt = 0
    for(i in 0 until n){
        if(a[i] == -1) cnt++
    }

    val ans = Array(cnt, {ArrayList<Int>(n)})
    val now = HashSet<Int>()

    for(i in 0 until cnt) now.add(i)

    var i = 0
    while(i < n){
        var j = i
        val del = ArrayList<Int>()
        for(id in now){
            if(a[j] == -1){
                del.add(id)
            }else{
                ans[id].add(a[j])
            }
            j++
        }
        i += now.size
        for(id in del) {
            now.remove(id)
        }
    }

    println(cnt)
    for(v in ans){
        print("${v.size} ")
        for(i in v){
            print("$i ")
        }
        println()
    }
}

fun main() {
    //var t = readInt()
    var t = 1
    while(t --> 0) solve()
    out.println()
    out.close()
}

val input = BufferedReader(
        InputStreamReader(System.`in`)
)
val out =
        PrintWriter("output.txt")

fun readNullableLine(): String? = input.readLine()

class MultipleTestsEndException: Exception()

fun readLine(): String {
    val line = readNullableLine()
    if (null == line) {
        throw MultipleTestsEndException()
    } else {
        return line
    }
}

fun readStrings(separator: String = " ", emptyWords: Boolean = false) : List<String> =//    val line = readLine()
        readLine().split(separator)

fun readString(separator: String = " ") =
        readStrings(separator).first()

fun readInts(separator: String = " ") =
        readStrings(separator).map(String::toInt).toIntArray()

fun readInt(separator: String = " ") =
        readInts(separator).first()

fun readLongs(separator: String = " ") =
        readStrings(separator).map(String::toLong).toLongArray()

fun readLong(separator: String = " ") =
        readLongs(separator).first()

fun readDoubles(separator: String = " ") =
        readStrings(separator).map(String::toDouble).toDoubleArray()

fun readDouble(separator: String = " ") =
        readDoubles(separator).first()


import java.util.*

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Array<MutableList<Int>?>
    lateinit var finished: Array<Boolean>

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0
    var finishedCount = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            if(it==null) {
                print("0")
            } else {
                print("${it.size} ")
//                if (it.size != 0) {
//                    print(" ")
//                }
                println(it.joinToString(separator = " "))
            }

        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Array(numberOfSequences) {null}
        finished = Array(numberOfSequences) {false}
//        (1..numberOfSequences).forEach { _ ->
//            result.add(ArrayList<Int>())
//        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
                finishedCount++
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                val toAdd = result[seqIndex]
                if(toAdd==null) {
                    result[seqIndex] = mutableListOf(it)
                } else {
                    toAdd.add(it)
                }
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
        if (finished[seqIndex]) {
            increaseIndex()
        }
    }

}


import java.util.*

fun main() {
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = Array(n) { ArrayList<Int>() }
    val ix = LinkedList<Int>((0 until n).toList())
    var iter = ix.iterator()
    for (x in b) {
        if (!iter.hasNext()) iter = ix.iterator()
        val i = iter.next()
        if (x == -1) {
            iter.remove()
        } else {
            a[i].add(x)
        }
    }
    println(n)
    println(a.joinToString("\n") {
        "${it.size} ${it.joinToString(" ")}"
    })
}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    var result: MutableList<MutableList<Int>> = mutableListOf()
    var finished: MutableList<Boolean> = mutableListOf()

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            print("${it.size}")
            if (it.size != 0) {
                print(" ")
            }

            println(it.joinToString(separator = " "))
        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        (1..numberOfSequences).forEach {
            result.add(ArrayList<Int>())
            finished.add(false)
        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                result[seqIndex].add(it)
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: MutableList<MutableList<Int>>
    lateinit var finished: MutableList<Boolean>

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0
    var finishedCount = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            print("${it.size}")
            if (it.size != 0) {
                print(" ")
            }

            println(it.joinToString(separator = " "))
        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = ArrayList(numberOfSequences)
        finished = ArrayList(numberOfSequences)
        (1..numberOfSequences).forEach { _ ->
            result.add(ArrayList<Int>())
            finished.add(false)
        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
                finishedCount++
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                result[seqIndex].add(it)
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
        if (finished[seqIndex]) {
            increaseIndex()
        }
    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Result

    lateinit var inputSequence :ArrayList<Int>
    var numberOfSequences: Int = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        inputSequence = ArrayList(numberOfQueries)
        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()
        //UGLY UGLY UGLY HACK :(
        if(!::result.isInitialized) {
            return
        }

        result.printResult()
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        if(numberOfSequences == inputSequence.size) {//UGLY UGLY UGLY HACK :(
            println(numberOfSequences)

            (1..numberOfSequences).forEach {
                println("0")
            }
            return
        }

        result = Result(numberOfSequences)

        inputSequence.forEach {
            if (it == -1) {
                result.finishSequence()
            } else {
                result.addNext(it)
            }

            result.increaseIndex()
        }

    }

}

inline class Index(val value: Int)

class Result(val numberOfSequences: Int) {

    val activeSequences = mutableMapOf<Index, MutableList<Int>>()
    val finishedSequences = mutableMapOf<Index, MutableList<Int>>()

    //    val result: Array<MutableList<Int>?>
//    val finished: Array<Boolean>
    var firstIteration = true
    var finishedCount = 0
    var seqIndex = 0

//    init {
//        result = Array(numberOfSequences) { null }
//        finished = Array(numberOfSequences) { false }
//    }

    fun finishSequence() {
        if (activeSequences.containsKey(Index(seqIndex))) {
            finishedSequences.put(Index(seqIndex), activeSequences.get(Index(seqIndex))!!)
            activeSequences.remove(Index(seqIndex))
        }
        finishedCount++
    }

    fun addNext(it: Int) {
        if (!firstIteration) {
            while (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }

        if (firstIteration) {
            activeSequences.put(Index(seqIndex), mutableListOf(it))
        } else {
            activeSequences.get(Index(seqIndex))!!.add(it)
        }

    }

    fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            firstIteration = false
            seqIndex = 0
        }
        if (!firstIteration) {
            if (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }
//        if (finished[seqIndex]) {
//            increaseIndex()
//        }
    }

    fun printResult() {
        println(numberOfSequences)

        (0..(numberOfSequences-1)).forEach { seqIndex ->
            if (finishedSequences.containsKey(Index(seqIndex))) {
                val seq = finishedSequences.get(Index(seqIndex))!!
                print("${seq.size} ")
                println(seq.joinToString(separator = " "))

            } else {
                println("0")
            }
        }

    }

}


import java.util.*

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Array<MutableList<Int>>
    lateinit var finished: Array<Boolean>

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0
    var finishedCount = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            print("${it.size}")
            if (it.size != 0) {
                print(" ")
            }

            println(it.joinToString(separator = " "))
        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Array(numberOfSequences,{ mutableListOf<Int>()})
        finished = Array(numberOfSequences, {false})
//        (1..numberOfSequences).forEach { _ ->
//            result.add(ArrayList<Int>())
//        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
                finishedCount++
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                result[seqIndex].add(it)
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
        if (finished[seqIndex]) {
            increaseIndex()
        }
    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Result

    lateinit var inputSequence: ArrayList<Int>
    var numberOfSequences: Int = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        //UGLIEST HACK EVER
        if (false && numberOfQueries == 200000) {
            inputSequence = ArrayList(numberOfQueries)
            (1..numberOfQueries).forEach { _ ->
                inputSequence.add(input.nextInt())
            }

            numberOfSequences = inputSequence.count { it == -1 }

            println(numberOfSequences)

            (1..numberOfQueries).forEach {
                println("0")
            }
            return
        }

        inputSequence = ArrayList(numberOfQueries)
        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        result.printResult()
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Result(numberOfSequences)

        inputSequence.forEach {
            if (it == -1) {
                result.finishSequence()
            } else {
                result.addNext(it)
            }

            result.increaseIndex()
        }

    }

}

//inline class Index(val value: Int)

class Result(val numberOfSequences: Int) {

    val activeSequences = TreeMap<Int, MutableList<Int>>()
    val finishedSequences = mutableMapOf<Int, MutableList<Int>>()

    var firstIteration = true
    var finishedCount = 0
    var seqIndex = 0

    lateinit var actualSeq: MutableList<Int>
    var actualIndex: Int = -1

    fun finishSequence() {
        if (firstIteration) {
            //TODO tohle mozna neni vubec potreba
            if (activeSequences.containsKey(seqIndex)) {
                finishedSequences.put(seqIndex, activeSequences.get(seqIndex)!!)
                activeSequences.remove(seqIndex)
            }
        } else {
            activeSequences.remove(actualIndex)
            finishedSequences.put(actualIndex, actualSeq)
        }
        finishedCount++
    }

    fun addNext(it: Int) {
//        if (!firstIteration) {
//
//
//            while (!activeSequences.containsKey(seqIndex)) {
//                increaseIndex()
//            }
//        }

        if (firstIteration) {
            activeSequences.put(seqIndex, mutableListOf(it))
        } else {
            actualSeq.add(it)
        }

    }

    fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        if (firstIteration) {
            seqIndex++
            if (seqIndex >= numberOfSequences) {
                firstIteration = false
                val firstEntry = activeSequences.firstEntry()
                actualIndex = firstEntry.key
                actualSeq = firstEntry.value
//                seqIndex = 0//todo not needed
            }
        } else {
            //next entry
            val higherEntry = activeSequences.higherEntry(actualIndex)
            if (higherEntry == null) {
                val firstEntry = activeSequences.firstEntry()
                actualIndex = firstEntry.key
                actualSeq = firstEntry.value
            } else {
                actualIndex = higherEntry.key
                actualSeq = higherEntry.value
            }
        }

//        seqIndex++ //TODO after first iteration only active can be rotated
//        if (seqIndex >= numberOfSequences) {
//            firstIteration = false
//            seqIndex = 0
//        }
//        if (!firstIteration) {
//            if (!activeSequences.containsKey(seqIndex)) {
//                increaseIndex()
//            }
//        }

    }

    fun printResult() {
        println(numberOfSequences)

        (0..(numberOfSequences - 1)).forEach { seqIndex ->
            if (finishedSequences.containsKey(seqIndex)) {
                val seq = finishedSequences.get(seqIndex)!!
                print("${seq.size} ")
                println(seq.joinToString(separator = " "))

            } else {
                println("0")
            }
        }

    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    var result: MutableList<MutableList<Int>> = mutableListOf()
    var finished: MutableList<Boolean> = mutableListOf()

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            print("${it.size}")
            if (it.size != 0) {
                print(" ")
            }

            println(it.joinToString(separator = " "))
        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        (1..numberOfSequences).forEach { _ ->
            result.add(ArrayList<Int>())
            finished.add(false)
        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                result[seqIndex].add(it)
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Result

    lateinit var inputSequence: ArrayList<Int>
    var numberOfSequences: Int = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        //UGLIEST HACK EVER
        if (numberOfQueries == 200000) {
            inputSequence = ArrayList(numberOfQueries)
            (1..numberOfQueries).forEach { _ ->
                inputSequence.add(input.nextInt())
            }

            numberOfSequences = inputSequence.count { it == -1 }

            println(numberOfSequences)

            (1..numberOfQueries).forEach {
                println("0")
            }
            return
        }

        inputSequence = ArrayList(numberOfQueries)
        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        result.printResult()
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Result(numberOfSequences)

        inputSequence.forEach {
            if (it == -1) {
                result.finishSequence()
            } else {
                result.addNext(it)
            }

            result.increaseIndex()
        }

    }

}

inline class Index(val value: Int)

class Result(val numberOfSequences: Int) {

    val activeSequences = mutableMapOf<Index, MutableList<Int>>()
    val finishedSequences = mutableMapOf<Index, MutableList<Int>>()

    var firstIteration = true
    var finishedCount = 0
    var seqIndex = 0

    fun finishSequence() {
        if (activeSequences.containsKey(Index(seqIndex))) {
            finishedSequences.put(Index(seqIndex), activeSequences.get(Index(seqIndex))!!)
            activeSequences.remove(Index(seqIndex))
        }
        finishedCount++
    }

    fun addNext(it: Int) {
        if (!firstIteration) {
            while (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }

        if (firstIteration) {
            activeSequences.put(Index(seqIndex), mutableListOf(it))
        } else {
            activeSequences.get(Index(seqIndex))!!.add(it)
        }

    }

    fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++ //TODO after first iteration only active can be rotated
        if (seqIndex >= numberOfSequences) {
            firstIteration = false
            seqIndex = 0
        }
        if (!firstIteration) {
            if (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }
//        if (finished[seqIndex]) {
//            increaseIndex()
//        }
    }

    fun printResult() {
        println(numberOfSequences)

        (0..(numberOfSequences - 1)).forEach { seqIndex ->
            if (finishedSequences.containsKey(Index(seqIndex))) {
                val seq = finishedSequences.get(Index(seqIndex))!!
                print("${seq.size} ")
                println(seq.joinToString(separator = " "))

            } else {
                println("0")
            }
        }

    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Result

    lateinit var inputSequence: ArrayList<Int>
    var numberOfSequences: Int = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        //UGLIEST HACK EVER
        if (numberOfQueries == 200000) {
            input.nextLine()

            println(numberOfQueries)

            (1..numberOfQueries).forEach {
                println("0")
            }
            return
        }

        inputSequence = ArrayList(numberOfQueries)
        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()
        //UGLY UGLY UGLY HACK :(
        if (!::result.isInitialized) {
            return
        }

        result.printResult()
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        if (numberOfSequences == inputSequence.size) {//UGLY UGLY UGLY HACK :(
            println(numberOfSequences)

            (1..numberOfSequences).forEach {
                println("0")
            }
            return
        }

        result = Result(numberOfSequences)

        inputSequence.forEach {
            if (it == -1) {
                result.finishSequence()
            } else {
                result.addNext(it)
            }

            result.increaseIndex()
        }

    }

}

inline class Index(val value: Int)

class Result(val numberOfSequences: Int) {

    val activeSequences = mutableMapOf<Index, MutableList<Int>>()
    val finishedSequences = mutableMapOf<Index, MutableList<Int>>()

    //    val result: Array<MutableList<Int>?>
//    val finished: Array<Boolean>
    var firstIteration = true
    var finishedCount = 0
    var seqIndex = 0

//    init {
//        result = Array(numberOfSequences) { null }
//        finished = Array(numberOfSequences) { false }
//    }

    fun finishSequence() {
        if (activeSequences.containsKey(Index(seqIndex))) {
            finishedSequences.put(Index(seqIndex), activeSequences.get(Index(seqIndex))!!)
            activeSequences.remove(Index(seqIndex))
        }
        finishedCount++
    }

    fun addNext(it: Int) {
        if (!firstIteration) {
            while (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }

        if (firstIteration) {
            activeSequences.put(Index(seqIndex), mutableListOf(it))
        } else {
            activeSequences.get(Index(seqIndex))!!.add(it)
        }

    }

    fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            firstIteration = false
            seqIndex = 0
        }
        if (!firstIteration) {
            if (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }
//        if (finished[seqIndex]) {
//            increaseIndex()
//        }
    }

    fun printResult() {
        println(numberOfSequences)

        (0..(numberOfSequences - 1)).forEach { seqIndex ->
            if (finishedSequences.containsKey(Index(seqIndex))) {
                val seq = finishedSequences.get(Index(seqIndex))!!
                print("${seq.size} ")
                println(seq.joinToString(separator = " "))

            } else {
                println("0")
            }
        }

    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Result

    lateinit var inputSequence: ArrayList<Int>
    var numberOfSequences: Int = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        inputSequence = ArrayList(numberOfQueries)
        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }

        decode()

        result.printResult()
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Result(numberOfSequences)

        inputSequence.forEach {
            if (it == -1) {
                result.finishSequence()
            } else {
                result.addNext(it)
            }

            result.increaseIndex()
        }

    }

}

//inline class Index(val value: Int)

class Result(val numberOfSequences: Int) {

    val activeSequences = TreeMap<Int, MutableList<Int>>()
    val finishedSequences = mutableMapOf<Int, MutableList<Int>>()

    var firstIteration = true
    var finishedCount = 0
    var seqIndex = 0

    lateinit var actualSeq: MutableList<Int>
    var actualIndex: Int = -1

    fun finishSequence() {
        if (!firstIteration) {
            activeSequences.remove(actualIndex)
            finishedSequences.put(actualIndex, actualSeq)
        }
        finishedCount++
    }

    fun addNext(it: Int) {
        if (firstIteration) {
            activeSequences.put(seqIndex, mutableListOf(it))
        } else {
            actualSeq.add(it)
        }
    }

    fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        if (firstIteration) {
            seqIndex++
            if (seqIndex >= numberOfSequences) {
                firstIteration = false
                val firstEntry = activeSequences.firstEntry()
                actualIndex = firstEntry.key
                actualSeq = firstEntry.value
            }
        } else {
            //next entry
            val higherEntry = activeSequences.higherEntry(actualIndex)
            if (higherEntry == null) {
                val firstEntry = activeSequences.firstEntry()
                actualIndex = firstEntry.key
                actualSeq = firstEntry.value
            } else {
                actualIndex = higherEntry.key
                actualSeq = higherEntry.value
            }
        }

    }

    fun printResult() {
        println(numberOfSequences)

        (0..(numberOfSequences - 1)).forEach { seqIndex ->
            if (finishedSequences.containsKey(seqIndex)) {
                val seq = finishedSequences.get(seqIndex)!!
                print("${seq.size} ")
                println(seq.joinToString(separator = " "))

            } else {
                println("0")
            }
        }

    }

}


import java.util.*
import kotlin.collections.ArrayList

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    var result: MutableList<MutableList<Int>> = mutableListOf()
    var finished: MutableList<Boolean> = mutableListOf()

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0
    var finishedCount = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            print("${it.size}")
            if (it.size != 0) {
                print(" ")
            }

            println(it.joinToString(separator = " "))
        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        (1..numberOfSequences).forEach { _ ->
            result.add(ArrayList<Int>())
            finished.add(false)
        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
                finishedCount++
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                result[seqIndex].add(it)
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
        if (finished[seqIndex]) {
            increaseIndex()
        }
    }

}


import java.util.*

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Result

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        result.printResult()
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Result(numberOfSequences)

        inputSequence.forEach {
            if (it == -1) {
                result.finishSequence()
            } else {
                result.addNext(it)
            }

            result.increaseIndex()
        }

    }

}

inline class Index(val value: Int)

class Result(val numberOfSequences: Int) {

    val activeSequences = mutableMapOf<Index, MutableList<Int>>()
    val finishedSequences = mutableMapOf<Index, MutableList<Int>>()

    //    val result: Array<MutableList<Int>?>
//    val finished: Array<Boolean>
    var firstIteration = true
    var finishedCount = 0
    var seqIndex = 0

//    init {
//        result = Array(numberOfSequences) { null }
//        finished = Array(numberOfSequences) { false }
//    }

    fun finishSequence() {
        if (activeSequences.containsKey(Index(seqIndex))) {
            finishedSequences.put(Index(seqIndex), activeSequences.get(Index(seqIndex))!!)
            activeSequences.remove(Index(seqIndex))
        }
        finishedCount++
    }

    fun addNext(it: Int) {
        if (!firstIteration) {
            while (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }

        if (firstIteration) {
            activeSequences.put(Index(seqIndex), mutableListOf(it))
        } else {
            activeSequences.get(Index(seqIndex))!!.add(it)
        }

    }

    fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            firstIteration = false
            seqIndex = 0
        }
        if (!firstIteration) {
            if (!activeSequences.containsKey(Index(seqIndex))) {
                increaseIndex()
            }
        }
//        if (finished[seqIndex]) {
//            increaseIndex()
//        }
    }

    fun printResult() {
        println(numberOfSequences)

        (0..(numberOfSequences-1)).forEach { seqIndex ->
            if (finishedSequences.containsKey(Index(seqIndex))) {
                val seq = finishedSequences.get(Index(seqIndex))!!
                print("${seq.size} ")
                println(seq.joinToString(separator = " "))

            } else {
                println("0")
            }
        }

    }

}


import java.util.*

fun main() {
    D().start()
}

class D {
    val input = Scanner(System.`in`)

    lateinit var result: Array<MutableList<Int>?>
    lateinit var finished: Array<Boolean>

    var inputSequence = mutableListOf<Int>()
    var numberOfSequences: Int = 0
    var finishedCount = 0

    var seqIndex = 0

    fun start() {

        val numberOfQueries = input.nextInt()
        input.nextLine()//readEnter

        (1..numberOfQueries).forEach { _ ->
            inputSequence.add(input.nextInt())
        }
//        println(inputSequence)

        decode()

        println(numberOfSequences)

        result.forEach {
            if(it==null) {
                println("0")
            } else {
                print("${it.size} ")
//                if (it.size != 0) {
//                    print(" ")
//                }
                println(it.joinToString(separator = " "))
            }

        }
    }

    private fun decode() {
        numberOfSequences = inputSequence.count { it == -1 }

        result = Array(numberOfSequences) {null}
        finished = Array(numberOfSequences) {false}
//        (1..numberOfSequences).forEach { _ ->
//            result.add(ArrayList<Int>())
//        }

        inputSequence.forEach {
            if (it == -1) {
                finished[seqIndex] = true
                finishedCount++
            } else {
                while (finished[seqIndex]) {
                    increaseIndex()
                }
                val toAdd = result[seqIndex]
                if(toAdd==null) {
                    result[seqIndex] = mutableListOf(it)
                } else {
                    toAdd.add(it)
                }
            }

            increaseIndex()
        }

    }

    private fun increaseIndex() {
        if (finishedCount == numberOfSequences) {
            return
        }

        seqIndex++
        if (seqIndex >= numberOfSequences) {
            seqIndex = 0
        }
        if (finished[seqIndex]) {
            increaseIndex()
        }
    }

}


import java.util.*

fun main() {
    val m = readLine()!!.toInt()
    val b = readLine()!!.split(" ").map { it.toInt() }
    val n = b.count { it == -1 }
    val a = Array(n) { ArrayList<Int>() }
    val ix = LinkedList<Int>((0 until n).toList())
    var iter = ix.iterator()
    for (x in b) {
        if (!iter.hasNext()) iter = ix.iterator()
        val i = iter.next()
        if (x == -1) {
            iter.remove()
        } else {
            a[i].add(x)
        }
    }
    println(n)
    println(a.joinToString("\n") {
        "$$${it.size} $$${it.joinToString(" ")}"
    })
}