package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 3010
var n, k int
var s string
var ways [][]int
var ret [][]int
var t [N]int

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s", &s)
	ways = make([][]int, 0)
	for i := 0; i < n; i++ {
		if s[i] == 'L' {
			t[i] = 1
		}
	}

	var total = 0
	for true {
		var move = make([]int, 0)

		for i := 0; i < n - 1; i++ {
			if t[i] == 0 && t[i + 1] == 1 {
				move = append(move, i+1)
				t[i], t[i+1] = t[i+1], t[i]
				i++
				total++
			}
		}
		if len(move) == 0 {
			break
		}

		ways = append(ways, move)
	}

	if total < k || k < len(ways) {
		fmt.Fprintf(writer, "-1")
		return
	}

	ret = make([][]int, 0)
	var gt = k - len(ways)

	for _, dt := range ways {
		var z = min(gt, len(dt) - 1)
		gt -= z
		for i := 0; i < z; i++ {
			ret = append(ret, dt[i:i + 1])
		}
		ret = append(ret, dt[z:])
	}

	for _, dt := range ret {
		fmt.Fprintf(writer, "%d ", len(dt))
		for _, z := range dt {
			fmt.Fprintf(writer, "%d ", z)
		}
		fmt.Fprintf(writer, "\n")
	}

}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l int //, y, z int
	var arr []int
	var arr1 [][]int
	var ch byte
	var s string
	var ls list.List
	var e, ep, en, enn *list.Element
	arr1 = make([][]int, 0)
	fmt.Fscanf(rd, "%d %d\n", &n, &k)
	fmt.Fscanf(rd, "%s", &s)
	ch = 'L'
	j = 0
	for i = 0; i < len(s); i++ {
		if ch == s[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = s[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			l = ls.Front().Value.(int)
			e = ls.Front().Next()
			for e != nil {
				en = e.Next()
				if en == nil {
					break
				}
				ep = e.Prev()
				enn = en.Next()
				i = e.Value.(int)
				arr = append(arr, l+i)
				m = en.Value.(int)
				if i == 1 {
					if m == 1 {
						ep.Value = ep.Value.(int) + 1
						ls.Remove(en)
						if enn != nil {
							enn.Value = enn.Value.(int) + 1
							ls.Remove(e)
						}
						l += 1
					} else {
						ep.Value = ep.Value.(int) + 1
						en.Value = en.Value.(int) - 1
						l += i + m
					}
				} else {
					if m == 1 {
						e.Value = e.Value.(int) - 1
						if enn != nil {
							enn.Value = enn.Value.(int) + 1
						} else {
							ls.InsertAfter(1, en)
						}
						l += i + m - 1
					} else {
						e.Value = e.Value.(int) - 1
						en.Value = en.Value.(int) - 1
						ls.InsertAfter(1, e)
						ls.InsertAfter(1, e)
						l += i + m
					}
				}
				inv--
				if inv < k {
					// fmt.Fprintf(wr, "%d ", len(arr))
					// for i = 0; i < len(arr); i++ {
					// 	fmt.Fprintf(wr, "%d ", arr[i])
					// }
					// fmt.Fprintf(wr, "\n")
					arr1 = append(arr1, arr)
					arr = make([]int, 0)
					k--
					if k == 0 {
						break
					}
				}
				e = enn
			}
			if k == 0 {
				break
			}
			if len(arr) > 0 {
				// fmt.Fprintf(wr, "%d ", len(arr))
				// for i = 0; i < len(arr); i++ {
				// 	fmt.Fprintf(wr, "%d ", arr[i])
				// }
				// fmt.Fprintf(wr, "\n")
				arr1 = append(arr1, arr)
				arr = make([]int, 0)
				k--
				if k == 0 {
					break
				}
			}
		}
		if k == 0 && inv == 0 {
			for i = 0; i < len(arr1); i++ {
				fmt.Fprintf(wr, "%d ", len(arr1[i]))
				for j = 0; j < len(arr1[i]); j++ {
					fmt.Fprintf(wr, "%d ", arr1[i][j])
				}
				fmt.Fprintf(wr, "\n")
			}
		} else {
			fmt.Fprintf(wr, "-1")
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var s string
	var ls list.List
	var e, ep *list.Element
	fmt.Fscanf(rd, "%d %d\n", &n, &k)
	fmt.Fscanf(rd, "%s", &s)
	ch = 'L'
	j = 0
	for i = 0; i < len(s); i++ {
		if ch == s[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = s[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriterSize(os.Stdout, 100*1024)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
			wr.Flush()
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	rd := bufio.NewReader(os.Stdin)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l int //, y, z int
	var arr []int
	var ch byte
	var s string
	var ls list.List
	var e, ep, en, enn *list.Element
	fmt.Fscanf(rd, "%d %d\n", &n, &k)
	fmt.Fscanf(rd, "%s", &s)
	ch = 'L'
	j = 0
	for i = 0; i < len(s); i++ {
		if ch == s[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = s[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			l = ls.Front().Value.(int)
			e = ls.Front().Next()
			for e != nil {
				en = e.Next()
				if en == nil {
					break
				}
				ep = e.Prev()
				enn = en.Next()
				i = e.Value.(int)
				arr = append(arr, l+i)
				m = en.Value.(int)
				if i == 1 {
					if m == 1 {
						ep.Value = ep.Value.(int) + 1
						ls.Remove(en)
						if enn != nil {
							enn.Value = enn.Value.(int) + 1
							ls.Remove(e)
						}
						l += 1
					} else {
						ep.Value = ep.Value.(int) + 1
						en.Value = en.Value.(int) - 1
						l += i + m
					}
				} else {
					if m == 1 {
						e.Value = e.Value.(int) - 1
						if enn != nil {
							enn.Value = enn.Value.(int) + 1
						} else {
							ls.InsertAfter(1, en)
						}
						l += i + m - 1
					} else {
						e.Value = e.Value.(int) - 1
						en.Value = en.Value.(int) - 1
						ls.InsertAfter(1, e)
						ls.InsertAfter(1, e)
						l += i + m
					}
				}
				inv--
				if inv < k {
					fmt.Fprintf(wr, "%d ", len(arr))
					for i = 0; i < len(arr); i++ {
						fmt.Fprintf(wr, "%d ", arr[i])
					}
					fmt.Fprintf(wr, "\n")
					arr = make([]int, 0)
					k--
				}
				e = enn
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
				k--
			}
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriterSize(os.Stdout, 1000*1024)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
			wr.Flush()
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprint(wr, "-1")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
			wr.Flush()
		}
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
			wr.Flush()
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
			wr.Flush()
		}
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprint(wr, "-1")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprintf(wr, "-1\n")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
								if wr.Available() < 50 {
									wr.Flush()
								}
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
					if wr.Available() < 50 {
						wr.Flush()
					}
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			k--
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
			wr.Flush()
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	wr := bufio.NewWriter(os.Stdout)
	var n, m, k, i, j, inv, l, x int //, y, z int
	var arr []int
	var ch byte
	var ls list.List
	var e, ep *list.Element
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &n)
	sc.Scan()
	fmt.Sscanf(sc.Text(), "%d", &k)
	sc.Scan()
	ch = 'L'
	j = 0
	for i = 0; i < len(sc.Bytes()); i++ {
		if ch == sc.Bytes()[i] {
			j++
		} else {
			ls.PushBack(j)
			ch = sc.Bytes()[i]
			j = 1
		}
	}
	ls.PushBack(j)
	e = ls.Back()
	if ch == 'R' {
		e = e.Prev()
	}
	ch = 'L'
	j = 0
	for ; e != nil; e = e.Prev() {
		if ch == 'L' {
			l, _ = e.Value.(int)
			j += l
			ch = 'R'
		} else {
			l, _ = e.Value.(int)
			inv += l * j
			ch = 'L'
		}
	}

	if k > inv {
		fmt.Fprint(wr, "-1")
	} else {
		for ls.Len() > 2 {
			j = 0
			l = 0
			for e = ls.Front(); e != nil; e = e.Next() {
				x, _ = e.Value.(int)
				if j%2 == 0 && j > 0 {
					i, _ = e.Value.(int)
					ep = e.Prev()
					m, _ = ep.Value.(int)
					ls.InsertAfter(1, ep)
					ls.InsertBefore(1, e)
					if i-1 == 0 {
						if e.Next() != nil {
							e.Prev().Value = e.Prev().Value.(int) + e.Next().Value.(int)
							ls.Remove(e.Next())
						}
						e = e.Prev()
						ls.Remove(e.Next())
						x = e.Value.(int)
						j--
					} else {
						e.Value = i - 1
					}
					if m-1 == 0 {
						if ep.Next() != nil {
							ep.Prev().Value = ep.Prev().Value.(int) + ep.Next().Value.(int)
							ls.Remove(ep.Next())
						}
						ls.Remove(ep)
					} else {
						ep.Value = m - 1
					}
					// fmt.Fprintf(wr, "inv=%d k=%d\n", inv, k)
					if inv > k {
						arr = append(arr, l)
						inv--
					} else if inv == k {
						arr = append(arr, l)
						inv--
						k--
						if len(arr) > 0 {
							fmt.Fprintf(wr, "%d ", len(arr))
							for i = 0; i < len(arr); i++ {
								fmt.Fprintf(wr, "%d ", arr[i])
							}
							fmt.Fprintf(wr, "\n")
							arr = make([]int, 0)
						}
					} else {
						fmt.Fprintf(wr, " error ")
					}
				}
				l += x
				j++
			}
			if len(arr) > 0 {
				fmt.Fprintf(wr, "%d ", len(arr))
				for i = 0; i < len(arr); i++ {
					fmt.Fprintf(wr, "%d ", arr[i])
				}
				fmt.Fprintf(wr, "\n")
				arr = make([]int, 0)
			}
			// for e = ls.Front(); e != nil; e = e.Next() {
			// 	fmt.Fprintf(wr, "%d ", e.Value)
			// }
			// fmt.Fprintf(wr, "\n")
		}
	}
	wr.Flush()
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

const N = 3010
var n, k int
var s string
var ways [][]int
var ret [][]int
var t [N]int

func min(a int, b int) int {
	if a < b {
		return a
	}
	return b
}

func main()  {
	var reader = bufio.NewReader(os.Stdin)
	var writer = bufio.NewWriter(os.Stdout)
	defer writer.Flush()
	fmt.Fscanf(reader, "%d %d\n", &n, &k)
	fmt.Fscanf(reader, "%s", &s)
	ways = make([][]int, 0)
	for i := 0; i < n; i++ {
		if s[i] == 'L' {
			t[i] = 1
		}
	}

	var total = 0
	for true {
		var move = make([]int, 0)

		for i := 0; i < n - 1; i++ {
			if t[i] == 0 && t[i + 1] == 1 {
				move = append(move, i+1)
				t[i], t[i+1] = t[i+1], t[i]
				i++
				total++
			}
		}
		if len(move) == 0 {
			break
		}

		ways = append(ways, move)
	}

	if total < k || k < len(ways) {
		fmt.Fprintf(writer, "-1")
		return
	}

	ret = make([][]int, 0)
	var gt = k - len(ways)

	for _, dt := range ways {
		var z = min(gt, len(dt) - 1)
		gt -= z
		for i := 0; i < z; i++ {
			ret = append(ret, dt[i:i])
		}
		ret = append(ret, dt[z:])
	}

	for _, dt := range ret {
		fmt.Fprintf(writer, "%d ", len(dt))
		for _, z := range dt {
			fmt.Fprintf(writer, "%d ", z)
		}
		fmt.Fprintf(writer, "\n")
	}

}


/*
URL:
https://codeforces.com/contest/1428/problem/D
*/

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	n int
	A []int

	B [5][]int
	C []int
	N []int
)

func main() {
	defer stdout.Flush()

	n = readi()
	A = readis(n)

	for i := 0; i < n; i++ {
		B[A[i]] = append(B[A[i]], i)
	}
	C = make([]int, n)
	for i := 0; i < n; i++ {
		C[i] = -1
	}
	for i := 0; i < n; i++ {
		// 現在のカラムID以下のものはマッチング対象から除外する
		for j := 0; j <= 3; j++ {
			for len(B[j]) > 0 {
				if B[j][0] <= i {
					B[j] = B[j][1:]
				} else {
					break
				}
			}
		}

		if A[i] == 3 {
			// 3,2,1の順で優先的に使う
			if len(B[3]) > 0 {
				C[i] = B[3][0]
				B[3] = B[3][1:]
			} else if len(B[2]) > 0 {
				C[i] = B[2][0]
				B[2] = B[2][1:]
			} else if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		} else if A[i] == 2 {
			if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		}
	}

	N = make([]int, n)
	ans := [][2]int{}
	for i := 0; i < n; i++ {
		if A[i] == 0 {
			continue
		}
		if A[i] == 1 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}
			continue
		}

		if A[i] == 2 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}

			tid := C[i]
			N[tid]++
			ans = append(ans, [2]int{i + 1, tid + 1})

			continue
		}

		if N[i] == 0 {
			N[i]++
			ans = append(ans, [2]int{i + 1, i + 1})
		}
		tid := C[i]
		N[tid] += 2
		ans = append(ans, [2]int{i + 1, tid + 1})
		// ans = append(ans, [2]int{i + 2, tid + 1})
		ans = append(ans, [2]int{tid + 1, tid + 1})
	}

	printf("%d\n", len(ans))
	for _, P := range ans {
		printf("%d %d\n", P[0], P[1])
	}
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

type target struct {
	x, y int
}

func main() {
	var n int
	fmt.Fscan(reader, &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}

	var targets []target
	var ones []target
	var rest []target
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}

		t := target{i, i}

		if a[i] == 1 {
			targets = append(targets, t)
			ones = append(ones, t)
		} else if a[i] == 2 {
			if len(ones) == 0 {
				fmt.Println(-1)
				return
			}

			one := ones[0]
			ones = ones[1:]

			targets = append(targets, target{i, one.y})
			rest = append(rest, target{i, one.y})
		} else if a[i] == 3 {
			if len(ones) == 0 && len(rest) == 0 {
				fmt.Println(-1)
				return
			}

			var prev target
			if len(rest) == 0 {
				prev = ones[0]
				ones = ones[1:]
			} else {
				prev = rest[0]
				rest = rest[1:]
			}

			targets = append(targets, target{i, i})
			targets = append(targets, target{prev.x, i})
			rest = append(rest, target{i, i})
		}
	}

	fmt.Println(len(targets))
	for _, t := range targets {
		fmt.Println(t.y+1, t.x+1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	solve(n, a)
}

func solve(n int, a []int) {
	next := 0
	canPair := make([]bool, n)
	unpairedOnes := make([][]int, 0)
	ans := make([]string, 0)
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}
		if a[i] == 1 {
			if next == n {
				Println(-1)
				return
			}
			ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
			canPair[i] = true
			unpairedOnes = append(unpairedOnes, []int{i, next})
			next++
			continue
		}
		if a[i] == 2 {
			for {
				if len(unpairedOnes) == 0 {
					Println(-1)
					return
				}
				id, _ := unpairedOnes[0][0], unpairedOnes[0][1]
				if !canPair[id] {
					unpairedOnes = unpairedOnes[1:]
					continue
				}
				break
			}
			id, u := unpairedOnes[0][0], unpairedOnes[0][1]
			canPair[id] = true
			unpairedOnes = unpairedOnes[1:]
			ans = append(ans, fmt.Sprintf("%d %d", n-u, i+1))
			canPair[i] = true
			continue
		}
		if a[i] == 3 {
			ok := false
			for j := i + 1; j < n; j++ {
				if canPair[j] {
					ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
					ans = append(ans, fmt.Sprintf("%d %d", n-next, j+1))
					canPair[j] = false
					ok = true
					break
				}
			}
			canPair[i] = true
			next++
			if !ok {
				Println(-1)
				return
			}
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		Println(ans[i])
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	ans := make([][2]int, 0)
	index := make([][]int, 3)
	for i := n - 1; i >= 0; i-- {
		switch aa[i] {
		case 1:
			ans = append(ans, [2]int{i + 1, i + 1})
			index[0] = append(index[0], i)
		case 2:
			if len(index[0]) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{index[0][0] + 1, i + 1})
			index[0] = index[0][1:]
			index[1] = append(index[1], i)
		case 3:
			ans = append(ans, [2]int{i + 1, i + 1})
			c := func() int {
				for j := 2; j >= 0; j-- {
					if len(index[j]) > 0 {
						x := index[j][0]
						index[j] = index[j][1:]
						return x
					}
				}
				return -1
			}()
			if c == -1 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{i + 1, c + 1})
			index[2] = append(index[2], i)
		}
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	solve(n, a)
}

func solve(n int, a []int) {
	next := 0
	canPair := make([]bool, n)
	unpairedOnes := make([][]int, 0)
	ans := make([][]int, 0)
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}
		if a[i] == 1 {
			if next == n {
				Println(-1)
				return
			}
			ans = append(ans, []int{i, next})
			canPair[i] = true
			unpairedOnes = append(unpairedOnes, []int{i, next})
			next++
			continue
		}
		if a[i] == 2 {
			for {
				if len(unpairedOnes) == 0 {
					Println(-1)
					return
				}
				id, _ := unpairedOnes[0][0], unpairedOnes[0][1]
				if !canPair[id] {
					unpairedOnes = unpairedOnes[1:]
					continue
				}
				break
			}
			id, u := unpairedOnes[0][0], unpairedOnes[0][1]
			canPair[id] = true
			unpairedOnes = unpairedOnes[1:]
			ans = append(ans, []int{i, u})
			canPair[i] = true
			continue
		}
		if a[i] == 3 {
			ok := false
			for j := i + 1; j < n; j++ {
				if canPair[j] {
					ans = append(ans, []int{i, next})
					ans = append(ans, []int{j, next})
					canPair[j] = false
					ok = true
					break
				}
			}
			canPair[i] = true
			if !ok {
				Println(-1)
				return
			}
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		Println(n-ans[i][1]-1, ans[i][0]+1)
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	defer _w.Flush()
	n := ReadInt()
	a := ReadInts(n)
	solve(n, a)
}

func solve(n int, a []int) {
	next := 0
	canPair := make([]bool, n)
	unpairedOnes := make([][]int, 0)
	ans := make([]string, 0)
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}
		if a[i] == 1 {
			if next == n {
				Println(-1)
				return
			}
			ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
			canPair[i] = true
			unpairedOnes = append(unpairedOnes, []int{i, next})
			next++
			continue
		}
		if a[i] == 2 {
			for {
				if len(unpairedOnes) == 0 {
					Println(-1)
					return
				}
				id, _ := unpairedOnes[0][0], unpairedOnes[0][1]
				if !canPair[id] {
					unpairedOnes = unpairedOnes[1:]
					continue
				}
				break
			}
			id, u := unpairedOnes[0][0], unpairedOnes[0][1]
			canPair[id] = true
			unpairedOnes = unpairedOnes[1:]
			ans = append(ans, fmt.Sprintf("%d %d", n-u, i+1))
			canPair[i] = true
			continue
		}
		if a[i] == 3 {
			ok := false
			for j := i + 1; j < n; j++ {
				if canPair[j] {
					ans = append(ans, fmt.Sprintf("%d %d", n-next, i+1))
					ans = append(ans, fmt.Sprintf("%d %d", n-next, j+1))
					canPair[j] = false
					ok = true
					break
				}
			}
			canPair[i] = true
			if !ok {
				Println(-1)
				return
			}
		}
	}

	Println(len(ans))
	for i := 0; i < len(ans); i++ {
		Println(ans[i])
	}
}

var _r, _w = bufio.NewReader(os.Stdin), bufio.NewWriter(os.Stdout)

func Print(a ...interface{})            { fmt.Fprint(_w, a...) }
func Printf(f string, a ...interface{}) { fmt.Fprintf(_w, f, a...) }
func Println(a ...interface{})          { fmt.Fprintln(_w, a...) }
func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(_r, a...); err != nil {
		panic(err)
	}
}
func ReadString() (s string) { Scan(&s); return }
func ReadInt() (i int)       { Scan(&i); return }
func ReadInts(n int) (a []int) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt())
	}
	return
}
func ReadInt64() (i int64) { Scan(&i); return }
func ReadInt64s(n int) (a []int64) {
	for i := 0; i < n; i++ {
		a = append(a, ReadInt64())
	}
	return
}

/*
URL:
https://codeforces.com/contest/1428/problem/D
*/

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

var (
	n int
	A []int

	B [5][]int
	C []int
	N []int
)

func main() {
	defer stdout.Flush()

	n = readi()
	A = readis(n)

	for i := 0; i < n; i++ {
		B[A[i]] = append(B[A[i]], i)
	}
	C = make([]int, n)
	for i := 0; i < n; i++ {
		C[i] = -1
	}
	for i := 0; i < n; i++ {
		// 現在のカラムID以下のものはマッチング対象から除外する
		for j := 0; j <= 3; j++ {
			for len(B[j]) > 0 {
				if B[j][0] <= i {
					B[j] = B[j][1:]
				} else {
					break
				}
			}
		}

		if A[i] == 3 {
			// 2の列を優先的に使う
			if len(B[2]) > 0 {
				C[i] = B[2][0]
				B[2] = B[2][1:]
			} else if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		} else if A[i] == 2 {
			if len(B[1]) > 0 {
				C[i] = B[1][0]
				B[1] = B[1][1:]
			} else {
				// マッチング出来なかったら終了
				fmt.Println(-1)
				return
			}
		}
	}

	N = make([]int, n)
	ans := [][2]int{}
	for i := 0; i < n; i++ {
		if A[i] == 0 {
			continue
		}
		if A[i] == 1 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}
			continue
		}

		if A[i] == 2 {
			if N[i] == 0 {
				N[i]++
				ans = append(ans, [2]int{i + 1, i + 1})
			}

			tid := C[i]
			N[tid]++
			ans = append(ans, [2]int{i + 1, tid + 1})

			continue
		}

		if N[i] == 0 {
			N[i]++
			ans = append(ans, [2]int{i + 1, i + 1})
		}
		tid := C[i]
		N[tid] += 2
		ans = append(ans, [2]int{i + 1, tid + 1})
		ans = append(ans, [2]int{i + 2, tid + 1})
	}

	printf("%d\n", len(ans))
	for _, P := range ans {
		printf("%d %d\n", P[0], P[1])
	}
}

/*******************************************************************/

/********** common constants **********/

const (
	MOD = 1000000000 + 7
	// MOD          = 998244353
	ALPH_N  = 26
	INF_I64 = math.MaxInt64
	INF_B60 = 1 << 60
	INF_I32 = math.MaxInt32
	INF_B30 = 1 << 30
	NIL     = -1
	EPS     = 1e-10
)

/********** bufio setting **********/

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	reads = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

// mod can calculate a right residual whether value is positive or negative.
func mod(val, m int) int {
	res := val % m
	if res < 0 {
		res += m
	}
	return res
}

// min returns the min integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func min(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m > integer {
			m = integer
		}
	}
	return m
}

// max returns the max integer among input set.
// This function needs at least 1 argument (no argument causes panic).
func max(integers ...int) int {
	m := integers[0]
	for i, integer := range integers {
		if i == 0 {
			continue
		}
		if m < integer {
			m = integer
		}
	}
	return m
}

// chmin accepts a pointer of integer and a target value.
// If target value is SMALLER than the first argument,
//	then the first argument will be updated by the second argument.
func chmin(updatedValue *int, target int) bool {
	if *updatedValue > target {
		*updatedValue = target
		return true
	}
	return false
}

// chmax accepts a pointer of integer and a target value.
// If target value is LARGER than the first argument,
//	then the first argument will be updated by the second argument.
func chmax(updatedValue *int, target int) bool {
	if *updatedValue < target {
		*updatedValue = target
		return true
	}
	return false
}

// sum returns multiple integers sum.
func sum(integers ...int) int {
	var s int
	s = 0

	for _, i := range integers {
		s += i
	}

	return s
}

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := reads()
//i := readi()
//X := readis(n)
//S := readrs()
//a := readf()
//A := readfs(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*********** Input ***********/

var (
	// reads returns a WORD string.
	reads  func() string
	stdout *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// readi returns an integer.
func readi() int {
	return int(_readInt64())
}
func readi2() (int, int) {
	return int(_readInt64()), int(_readInt64())
}
func readi3() (int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64())
}
func readi4() (int, int, int, int) {
	return int(_readInt64()), int(_readInt64()), int(_readInt64()), int(_readInt64())
}

// readll returns as integer as int64.
func readll() int64 {
	return _readInt64()
}
func readll2() (int64, int64) {
	return _readInt64(), _readInt64()
}
func readll3() (int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64()
}
func readll4() (int64, int64, int64, int64) {
	return _readInt64(), _readInt64(), _readInt64(), _readInt64()
}

func _readInt64() int64 {
	i, err := strconv.ParseInt(reads(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// readis returns an integer slice that has n integers.
func readis(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readi()
	}
	return b
}

// readlls returns as int64 slice that has n integers.
func readlls(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = readll()
	}
	return b
}

// readf returns an float64.
func readf() float64 {
	return float64(_readFloat64())
}

func _readFloat64() float64 {
	f, err := strconv.ParseFloat(reads(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func readfs(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = readf()
	}
	return b
}

// readrs returns a rune slice.
func readrs() []rune {
	return []rune(reads())
}

/*********** Output ***********/

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// Printf is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func printf(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*********** Debugging ***********/

// debugf is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func debugf(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var reader = bufio.NewReader(os.Stdin)

type target struct {
	x, y int
}

func main() {
	var n int
	fmt.Fscan(reader, &n)

	a := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Fscan(reader, &a[i])
	}

	var targets []target
	var ones []target
	var rest []target
	for i := n - 1; i >= 0; i-- {
		if a[i] == 0 {
			continue
		}

		t := target{i, i}

		if a[i] == 1 {
			targets = append(targets, t)
			ones = append(ones, t)
			continue
		}

		if a[i] == 2 {
			if len(ones) == 0 {
				fmt.Println(-1)
				return
			}

			one := ones[0]
			ones = ones[1:]

			targets = append(targets, target{i, one.y})
			rest = append(rest, target{i, one.y})
			continue
		}

		if a[i] == 3 {
			if len(ones) == 0 && len(rest) == 0 {
				fmt.Println(-1)
				return
			}

			var prev target
			if len(rest) == 0 {
				prev = ones[0]
				ones = ones[1:]
			} else {
				prev = rest[0]
				rest = rest[1:]
			}

			targets = append(targets, target{i, i})
			targets = append(targets, target{prev.x, i})
			rest = append(rest, target{i, i})
		}
	}

	fmt.Println(len(targets))
	for _, t := range targets {
		fmt.Println(t.x+1, t.y+1)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		enableh = append(enableh, i)
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		enableh = append(enableh, i)
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		if len(enableh) > 0 {
			enableh = enableh[1:]
		}
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			continue
		}
		if len(enableh) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enableh = enableh[1:]
		enablev = enablev[1:]
		enableh = append(enableh, i)
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{i + 1, i + 1})
			enablev = append(enablev, i)
			enableh = append(enableh, i)
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{i + 1, i + 1})
			ans = append(ans, [2]int{i + 1, enableh[0] + 1})
			enableh = enableh[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0] + 1, i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			if len(enablev) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			enablev = enablev[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		enablev = append(enablev, r)
		enableh = append(enableh, i)
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		if len(enableh) > 0 {
			enableh = enableh[1:]
		}
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n - 1
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if r == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			if len(enablev) > 0 {
				enablev = enablev[1:]
			}
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
		if len(enableh) > 0 {
			enableh = enableh[1:]
		}
		enableh = append(enableh, i)
	}
	fmt.Fprintln(writer, len(ans))
	for i := len(ans) - 1; i >= 0; i-- {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	enablev := make([]int, 0)
	enableh := make([]int, 0)
	ans := make([][2]int, 0)
	r := n - 1
	for i := n - 1; i >= 0; i-- {
		if aa[i] == 0 {
			continue
		}
		if r == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		if aa[i] == 1 {
			ans = append(ans, [2]int{r, i + 1})
			enablev = append(enablev, r)
			enableh = append(enableh, i)
			r--
			continue
		}
		if aa[i] == 3 {
			if len(enableh) == 0 {
				fmt.Fprintln(writer, -1)
				return
			}
			ans = append(ans, [2]int{r, i + 1})
			ans = append(ans, [2]int{r, enableh[0] + 1})
			r--
			enableh = enableh[1:]
			continue
		}
		if len(enablev) == 0 {
			fmt.Fprintln(writer, -1)
			return
		}
		ans = append(ans, [2]int{enablev[0], i + 1})
		enablev = enablev[1:]
	}
	fmt.Fprintln(writer, len(ans))
	sort.Slice(ans, func(i, j int) bool {
		if ans[i][0] == ans[j][0] {
			return ans[i][1] < ans[j][1]
		}
		return ans[i][0] < ans[j][0]
	})
	for i := 0; i < len(ans); i++ {
		fmt.Fprintln(writer, fmt.Sprintf("%d %d", ans[i][0], ans[i][1]))
	}
}


package main

import "fmt"
import "bufio"
import "os"
import "container/heap"

var bufin *bufio.Reader
var bufout *bufio.Writer

type Node struct {
	value int
	index int
}

type NodeList []*Node

func (nodes NodeList) Len() int {
	return len(nodes)
}

func (nodes NodeList) Less(i int, j int) bool {
	return nodes[i].value > nodes[j].value
}

func (nodes NodeList) Swap(i int, j int) {
	nodes[i], nodes[j] = nodes[j], nodes[i]
	nodes[i].index = i
	nodes[j].index = j
}

func (nodes *NodeList) Push(x interface{}) {
	node := x.(*Node)
	node.index = len(*nodes)
	*nodes = append(*nodes, node)
}

func (nodes *NodeList) Pop() interface{} {
	s := *nodes
	last := len(s) - 1
	r := s[last]
	*nodes = s[:last]
	r.index = -1
	return r
}

func main() {
	bufin = bufio.NewReader(os.Stdin)
	bufout = bufio.NewWriter(os.Stdout)
	defer bufout.Flush()

	var n int
	fmt.Fscanf(bufin, "%d\n", &n)

	var h NodeList
	var y int

	has := make(map[int]bool)
	for i := 0; i < n; i++ {
		fmt.Fscanf(bufin, "%d\n", &y)
		heap.Push(&h, &Node{value: y})
		has[y] = true
	}

	for h.Len() > 0 {
		node := heap.Pop(&h).(*Node)
		y = node.value
		has[y] = false
		x := y
		for y >= 2 {
			y /= 2
			if has[y] == false {
				x = y
				break
			}
		}
		has[x] = true
		heap.Push(&h, &Node{value: x})
		if x == node.value {
			break
		}
	}

	for h.Len() > 0 {
		node := heap.Pop(&h).(*Node)
		fmt.Fprintf(bufout, "%d ", node.value)
	}
	fmt.Fprintf(bufout, "\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left  *Node
	Value int64
	Index int
	Right *Node
}

func insert(node *Node, value int64, index int) *Node {
	if node == nil {
		return &Node{nil, value, index, nil}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, index)
		return node
	}
	node.Right = insert(node.Right, value, index)
	return node
}

func max(node *Node) *Node {
	if node == nil || node.Right == nil || node.Right.Index == -1 {
		return node
	}
	return max(node.Right)
}

func search(node *Node, value int64) *Node {
	if node == nil {
		return nil
	}
	if node.Value == value {
		return node
	}
	if node.Value > value {
		return search(node.Left, value)
	}
	return search(node.Right, value)
}

func deleteMax(node *Node) {
	node = max(node)
	if node.Left == nil {
		*node = Node{nil, -1, -1, nil}
	} else {
		*node = *node.Left
	}
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var node *Node
	var n int
	I(&n, "\n")
	y := make([]int64, n)
	for i := 0; i < n; i++ {
		I(&y[i], " ")
		node = insert(node, y[i], i)
	}
	count := n
	for count > 0 {
		maxNode := max(node)
		for i := maxNode.Value; i >= 1; i /= 2 {
			f := search(node, i)
			if f == nil {
				node = insert(node, i, maxNode.Index)
				deleteMax(node)
				count++
				break
			}
		}
		count--
	}
	for node.Index != -1 {
		O(max(node).Value, " ")
		deleteMax(node)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func I(t interface{}, delim string) {
	fmt.Fscanf(r, "%v"+delim, t)
}

func O(o interface{}, delim string) {
	fmt.Fprintf(w, "%v"+delim, o)
}

var r *bufio.Reader
var w *bufio.Writer

type Node struct {
	Left  *Node
	Value int64
	Index int
	Right *Node
}

func insert(node *Node, value int64, index int) *Node {
	if node == nil {
		return &Node{nil, value, index, nil}
	}
	if node.Value > value {
		node.Left = insert(node.Left, value, index)
		return node
	}
	node.Right = insert(node.Right, value, index)
	return node
}

func max(node *Node) *Node {
	if node == nil || node.Right == nil || node.Right.Index == -1 {
		return node
	}
	return max(node.Right)
}

func search(node *Node, value int64) *Node {
	if node == nil {
		return nil
	}
	if node.Value == value {
		return node
	}
	if node.Value > value {
		return search(node.Left, value)
	}
	return search(node.Right, value)
}

func deleteMax(node *Node) {
	node = max(node)
	if node.Left == nil {
		*node = Node{nil, -1, -1, nil}
	} else {
		*node = *node.Left
	}
}

func main() {
	r = bufio.NewReader(os.Stdin)
	w = bufio.NewWriter(os.Stdout)
	defer w.Flush()

	var node *Node
	var n int
	I(&n, "\n")
	y := make([]int64, n)
	for i := 0; i < n; i++ {
		I(&y[i], " ")
		node = insert(node, y[i], i)
	}
	count := n
	for count > 0 {
		maxNode := max(node)
		for i := maxNode.Value; i >= 1; i /= 2 {
			f := search(node, i)
			if f == nil {
				idx := maxNode.Index
				deleteMax(node)
				node = insert(node, i, idx)
				count++
				break
			}
		}
		count--
	}
	for node.Index != -1 {
		O(max(node).Value, " ")
		deleteMax(node)
	}
}