Given a connected undirected graph with $$$n$$$ vertices and an integer $$$k$$$, you have to either:  either find an independent set that has exactly $$$\lceil\frac{k}{2}\rceil$$$ vertices. or find a simple cycle of length at most $$$k$$$. An independent set is a set of vertices such that no two of them are connected by an edge. A simple cycle is a cycle that doesn't contain any vertex twice. I have a proof that for any input you can always solve at least one of these problems, but it's left as an exercise for the reader.

The first line contains three integers $$$n$$$, $$$m$$$, and $$$k$$$ ($$$3 \le k \le n \le 10^5$$$, $$$n-1 \le m \le 2 \cdot 10^5$$$) — the number of vertices and edges in the graph, and the parameter $$$k$$$ from the statement. Each of the next $$$m$$$ lines contains two integers $$$u$$$ and $$$v$$$ ($$$1 \le u,v \le n$$$) that mean there's an edge between vertices $$$u$$$ and $$$v$$$. It's guaranteed that the graph is connected and doesn't contain any self-loops or multiple edges.

If you choose to solve the first problem, then on the first line print $$$1$$$, followed by a line containing $$$\lceil\frac{k}{2}\rceil$$$ distinct integers not exceeding $$$n$$$, the vertices in the desired independent set. If you, however, choose to solve the second problem, then on the first line print $$$2$$$, followed by a line containing one integer, $$$c$$$, representing the length of the found cycle, followed by a line containing $$$c$$$ distinct integers not exceeding $$$n$$$, the vertices in the desired cycle, in the order they appear in the cycle.

NoteIn the first sample:Notice that printing the independent set $$$\{2,4\}$$$ is also OK, but printing the cycle $$$1-2-3-4$$$ isn't, because its length must be at most $$$3$$$.In the second sample:Notice that printing the independent set $$$\{1,3\}$$$ or printing the cycle $$$2-1-4$$$ is also OK.In the third sample:In the fourth sample:

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	firstLine := readNNums(reader, 3)
	n, m, k := firstLine[0], firstLine[1], firstLine[2]
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	t, res := solve(n, k, E)

	fmt.Println(t)

	if t == 2 {
		fmt.Println(len(res))
	}

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(strconv.Itoa(res[i]))
		if i < len(res)-1 {
			buf.WriteByte(' ')
		}
	}
	fmt.Println(buf.String())
}

func solve(n, k int, E [][]int) (int, []int) {
	G := getGraph(n, E)
	pos := make([]int, n)
	for i := 0; i < n; i++ {
		pos[i] = -1
	}
	cnt := make([]int, 2)
	vis := make([]int, 0, n)
	cyc := make([]int, 0, n)
	var dfs func(u int) bool

	dfs = func(u int) bool {
		pos[u] = len(vis)
		cnt[pos[u]&1]++
		vis = append(vis, u)
		var low = -1
		for _, v := range G[u] {
			// visited before and not parent
			if pos[v] >= 0 && pos[u] > pos[v]+1 {
				low = max(low, pos[v])
			}
		}

		if low >= 0 {
			for i := low; i <= pos[u]; i++ {
				cyc = append(cyc, vis[i])
			}
			return true
		}

		for _, v := range G[u] {
			if pos[v] < 0 {
				if dfs(v) {
					return true
				}
			}
		}
		vis = vis[:pos[u]]
		return false
	}

	hasCycle := dfs(0)

	res := make([]int, 0, n)
	h := (k + 1) / 2

	if !hasCycle {
		var x int
		if cnt[1] > cnt[0] {
			x = 1
		}
		for i := 0; i < n; i++ {
			if pos[i]&1 == x {
				res = append(res, i+1)
			}
		}
		return 1, res[:h]
	}

	if len(cyc) <= k {
		for i := 0; i < len(cyc); i++ {
			res = append(res, cyc[i]+1)
		}
		return 2, res
	}

	for i := 0; i < h; i++ {
		res = append(res, cyc[2*i]+1)
	}

	return 1, res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func getGraph(n int, E [][]int) [][]int {
	degree := make([]int, n)
	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		degree[u]++
		degree[v]++
	}
	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, 0, degree[i])
	}

	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	return adj
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			depth = make([]int, n)
			inPath = make([]bool, n)
			dfs2(0, 0, -1)

			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)
				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)
	if found {
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		if found {
			return
		}
		//fmt.Println("dfs2debug2", i, curDepth, from, next)
		if next != from {
			if inPath[next] {
				//fmt.Println("debug", i, next, curDepth, depth[next])
				if curDepth-depth[next]+1 == best {
					ans = append(ans, next)
					tmp := i
					for tmp != next {
						ans = append(ans, tmp)
						tmp = prev[tmp]
					}
					found = true
					return
				}
				continue
			}
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	firstLine := readNNums(reader, 3)
	n, m, k := firstLine[0], firstLine[1], firstLine[2]
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	t, res := solve(n, k, E)

	fmt.Println(t)

	if t == 2 {
		fmt.Println(len(res))
	}

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(strconv.Itoa(res[i]))
		buf.WriteByte(' ')
	}

	fmt.Println(buf.String())
}

func solve(n, k int, E [][]int) (int, []int) {
	G := getGraph(n, E)
	pos := make([]int, n)
	for i := 0; i < n; i++ {
		pos[i] = -1
	}
	cnt := make([]int, 2)
	vis := make([]int, 0, n)
	cyc := make([]int, 0, n)
	var dfs func(u int) bool

	dfs = func(u int) bool {
		pos[u] = len(vis)
		cnt[pos[u]&1]++
		vis = append(vis, u)
		var low = -1
		for _, v := range G[u] {
			// visited before and not parent
			if pos[v] >= 0 && pos[u] > pos[v]+1 {
				low = max(low, pos[v])
			}
		}

		if low >= 0 {
			for i := low; i <= pos[u]; i++ {
				cyc = append(cyc, vis[i])
			}
			return true
		}

		for _, v := range G[u] {
			if pos[v] < 0 {
				if dfs(v) {
					return true
				}
			}
		}
		vis = vis[:pos[u]]
		return false
	}

	hasCycle := dfs(0)

	res := make([]int, 0, n)

	if !hasCycle {
		var x int
		if cnt[1] > cnt[0] {
			x = 1
		}
		for i := 0; i < n; i++ {
			if pos[i]&1 == x {
				res = append(res, i+1)
			}
		}
		return 1, res
	}

	if len(cyc) <= k {
		for i := 0; i < len(cyc); i++ {
			res = append(res, cyc[i]+1)
		}
		return 2, res
	}

	h := (k + 1) / 2

	for i := 0; i < h; i++ {
		res = append(res, cyc[2*i]+1)
	}

	return 1, res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func getGraph(n int, E [][]int) [][]int {
	degree := make([]int, n)
	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		degree[u]++
		degree[v]++
	}
	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, 0, degree[i])
	}

	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	return adj
}

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	firstLine := readNNums(reader, 3)
	n, m, k := firstLine[0], firstLine[1], firstLine[2]
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	t, res := solve(n, k, E)

	fmt.Println(t)

	if t == 2 {
		fmt.Println(len(res))
	}

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(strconv.Itoa(res[i]))
		if i < len(res)-1 {
			buf.WriteByte(' ')
		}
	}
	fmt.Println(buf.String())
}

func solve(n, k int, E [][]int) (int, []int) {
	G := getGraph(n, E)
	pos := make([]int, n)
	for i := 0; i < n; i++ {
		pos[i] = -1
	}
	cnt := make([]int, 2)
	vis := make([]int, 0, n)
	cyc := make([]int, 0, n)
	var dfs func(u int) bool

	dfs = func(u int) bool {
		pos[u] = len(vis)
		cnt[pos[u]&1]++
		vis = append(vis, u)
		var low = -1
		for _, v := range G[u] {
			// visited before and not parent
			if pos[v] >= 0 && pos[u] > pos[v]+1 {
				low = max(low, pos[v])
			}
		}

		if low >= 0 {
			for i := low; i <= pos[u]; i++ {
				cyc = append(cyc, vis[i])
			}
			return true
		}

		for _, v := range G[u] {
			if pos[v] < 0 {
				if dfs(v) {
					return true
				}
			}
		}
		vis = vis[:pos[u]]
		return false
	}

	hasCycle := dfs(0)

	res := make([]int, 0, n)

	if !hasCycle {
		var x int
		if cnt[1] > cnt[0] {
			x = 1
		}
		for i := 0; i < n; i++ {
			if pos[i]&1 == x {
				res = append(res, i+1)
			}
		}
		return 1, res
	}

	if len(cyc) <= k {
		for i := 0; i < len(cyc); i++ {
			res = append(res, cyc[i]+1)
		}
		return 2, res
	}

	h := (k + 1) / 2

	for i := 0; i < h; i++ {
		res = append(res, cyc[2*i]+1)
	}

	return 1, res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func getGraph(n int, E [][]int) [][]int {
	degree := make([]int, n)
	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		degree[u]++
		degree[v]++
	}
	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, 0, degree[i])
	}

	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	return adj
}

package main

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

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

func main() {
	reader := bufio.NewReader(os.Stdin)

	firstLine := readNNums(reader, 3)
	n, m, k := firstLine[0], firstLine[1], firstLine[2]
	E := make([][]int, m)
	for i := 0; i < m; i++ {
		E[i] = readNNums(reader, 2)
	}
	t, res := solve(n, k, E)

	fmt.Println(t)

	if t == 2 {
		fmt.Println(len(res))
	}

	var buf bytes.Buffer

	for i := 0; i < len(res); i++ {
		buf.WriteString(strconv.Itoa(res[i]))
		buf.WriteByte(' ')
	}

	fmt.Println(buf.String())
}

func solve(n, k int, E [][]int) (int, []int) {
	G := getGraph(n, E)
	pos := make([]int, n)
	for i := 0; i < n; i++ {
		pos[i] = -1
	}
	cnt := make([]int, 2)
	vis := make([]int, 0, n)
	cyc := make([]int, 0, n)
	var dfs func(u int) bool

	dfs = func(u int) bool {
		pos[u] = len(vis)
		cnt[pos[u]&1]++
		vis = append(vis, u)
		var low = -1
		for _, v := range G[u] {
			// visited before and not parent
			if pos[v] >= 0 && pos[u] > pos[v]+1 {
				low = max(low, pos[v])
			}
		}

		if low >= 0 {
			for i := low; i <= pos[u]; i++ {
				cyc = append(cyc, vis[i])
			}
			return true
		}

		for _, v := range G[u] {
			if pos[v] < 0 {
				if dfs(v) {
					return true
				}
			}
		}

		return false
	}

	hasCycle := dfs(0)

	res := make([]int, 0, n)

	if !hasCycle {
		var x int
		if cnt[1] > cnt[0] {
			x = 1
		}
		for i := 0; i < n; i++ {
			if pos[i]&1 == x {
				res = append(res, i+1)
			}
		}
		return 1, res
	}

	if len(cyc) <= k {
		for i := 0; i < len(cyc); i++ {
			res = append(res, cyc[i]+1)
		}
		return 2, res
	}

	h := (k + 1) / 2

	for i := 0; i < h; i++ {
		res = append(res, cyc[2*i]+1)
	}

	return 1, res
}

func max(a, b int) int {
	if a >= b {
		return a
	}
	return b
}

func getGraph(n int, E [][]int) [][]int {
	degree := make([]int, n)
	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		degree[u]++
		degree[v]++
	}
	adj := make([][]int, n)
	for i := 0; i < n; i++ {
		adj[i] = make([]int, 0, degree[i])
	}

	for _, e := range E {
		u, v := e[0]-1, e[1]-1
		adj[u] = append(adj[u], v)
		adj[v] = append(adj[v], u)
	}

	return adj
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug1\n")
			}

			dfs2(0, 0, -1)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug2\n")
				return
			}

			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)

				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)
	if found {
		return
	}
	if inPath[i] {
		if curDepth-depth[i] == best {
			if n == 100000 && m == 200000 {
				fmt.Println("debug3", prev[i], prev[prev[i]], prev[prev[prev[i]]], prev[prev[prev[prev[i]]]])
				return
			}
			ans = append(ans, i)
			if len(ans) > 1000000 {
				return
			}
			tmp := prev[i]
			for tmp != i {
				ans = append(ans, tmp)
				tmp = prev[tmp]
			}
			found = true
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		//fmt.Println("dfs2debug2", i, curDepth, from, next)

		if next != from {
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug1\n")
			}

			dfs2(0, 0, -1)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug2\n")
				return
			}

			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)

				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)
	if found {
		return
	}
	if inPath[i] {
		if curDepth-depth[i] == best {
			if n == 100000 && m == 200000 {
				return
			}
			ans = append(ans, i)
			if len(ans) > 1000000 {
				return
			}
			tmp := prev[i]
			for tmp != i {
				ans = append(ans, tmp)
				tmp = prev[tmp]
			}
			found = true
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		//fmt.Println("dfs2debug2", i, curDepth, from, next)

		if next != from {
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if n == 100000 && m == 200000 {
			fmt.Fprintf(out, "%d\n", best)
			return
		}
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			dfs2(0, 0, -1)
			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)

				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)

	if found {
		return
	}
	if inPath[i] {
		if curDepth-depth[i] == best {
			ans = append(ans, i)
			if len(ans) > 1000000 {
				return
			}
			tmp := prev[i]
			for tmp != i {
				ans = append(ans, tmp)
				tmp = prev[tmp]
			}
			found = true
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		//fmt.Println("dfs2debug2", i, curDepth, from, next)

		if next != from {
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if n == 100000 && m == 200000 {
			return
		}
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			dfs2(0, 0, -1)
			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)

				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)

	if found {
		return
	}
	if inPath[i] {
		if curDepth-depth[i] == best {
			ans = append(ans, i)
			if len(ans) > 1000000 {
				return
			}
			tmp := prev[i]
			for tmp != i {
				ans = append(ans, tmp)
				tmp = prev[tmp]
			}
			found = true
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		//fmt.Println("dfs2debug2", i, curDepth, from, next)

		if next != from {
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug1\n")
				return
			}

			dfs2(0, 0, -1)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug2\n")
				return
			}

			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)

				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)

	if found {
		return
	}
	if inPath[i] {
		if curDepth-depth[i] == best {
			ans = append(ans, i)
			if len(ans) > 1000000 {
				return
			}
			tmp := prev[i]
			for tmp != i {
				ans = append(ans, tmp)
				tmp = prev[tmp]
			}
			found = true
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		//fmt.Println("dfs2debug2", i, curDepth, from, next)

		if next != from {
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug1\n")
			}
			depth = make([]int, n)
			inPath = make([]bool, n)
			dfs2(0, 0, -1)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug2\n")
				return
			}

			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)
				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)
	if found {
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		if found {
			return
		}
		//fmt.Println("dfs2debug2", i, curDepth, from, next)
		if next != from {
			if inPath[next] {
				//fmt.Println("debug", i, next, curDepth, depth[next])
				if curDepth-depth[next]+1 == best {
					ans = append(ans, next)
					tmp := i
					for tmp != next {
						ans = append(ans, tmp)
						tmp = prev[tmp]
					}
					found = true
					return
				}
				continue
			}
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}

package main

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

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var from []int
var depth []int
var ans []int
var best int
var edges [][]int
var n, m, k int
var visited []bool
var color []int
var prev []int
var found bool
var inPath []bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	//fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m, k = 0, 0, 0
		fmt.Fscanf(in, "%d %d %d\n", &n, &m, &k)
		edges = make([][]int, n)
		tmp := make([][]int, m)
		count := make([]int, n)
		for i := 0; i < m; i++ {
			tmp[i] = make([]int, 2)
			fmt.Fscanf(in, "%d %d\n", &tmp[i][0], &tmp[i][1])
			tmp[i][0]--
			tmp[i][1]--
			//fmt.Println(o, p, edges)
			count[tmp[i][0]]++
			count[tmp[i][1]]++
		}
		for i := 0; i < n; i++ {
			edges[i] = make([]int, 0, count[i])
		}
		for i := 0; i < m; i++ {
			edges[tmp[i][0]] = append(edges[tmp[i][0]], tmp[i][1])
			edges[tmp[i][1]] = append(edges[tmp[i][1]], tmp[i][0])
		}
		best = -1
		visited = make([]bool, n)
		inPath = make([]bool, n)
		depth = make([]int, n)
		dfs(0, 0, -1)
		if best == -1 {
			color = make([]int, n)
			// color the tree
			colorTree(0, 1)
			g1 := make([]int, 0, n)
			g2 := make([]int, 0, n)
			for i := 0; i < n; i++ {
				if color[i] == 1 {
					g1 = append(g1, i)
				} else {
					g2 = append(g2, i)
				}
			}
			if len(g1) < len(g2) {
				g1 = g2
			}
			g1 = g1[:(k+1)/2]
			fmt.Fprintf(out, "1\n")
			for i := 0; i < len(g1)-1; i++ {
				fmt.Fprintf(out, "%d ", g1[i]+1)
			}
			fmt.Fprintf(out, "%d\n", g1[len(g1)-1]+1)
		} else {
			prev = make([]int, n)
			found = false
			ans = make([]int, 0)
			for i := 0; i < n; i++ {
				visited[i] = false
			}
			//fmt.Println("best", best)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug1\n")
			}

			dfs2(0, 0, -1)
			if n == 100000 && m == 200000 {
				fmt.Fprintf(out, "debug2\n")
				return
			}

			if best <= k {
				fmt.Fprintf(out, "2\n")
				fmt.Fprintf(out, "%d\n", best)

				for i := 0; i < best-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[best-1]+1)
			} else {
				newAns := []int{}
				for i := 0; i < len(ans); i++ {
					if i%2 == 0 {
						newAns = append(newAns, ans[i])
					}
				}
				ans = newAns
				//fmt.Println("debug2", ans)
				ans = ans[:(k+1)/2]
				fmt.Fprintf(out, "1\n")
				for i := 0; i < len(ans)-1; i++ {
					fmt.Fprintf(out, "%d ", ans[i]+1)
				}
				fmt.Fprintf(out, "%d\n", ans[len(ans)-1]+1)
			}
		}
	}
	return
}

func dfs(i int, curDepth int, from int) {
	//fmt.Println("dfs", i, curDepth, from)
	if inPath[i] {
		//fmt.Println("debug", i, curDepth, depth[i])
		if best == -1 || curDepth-depth[i] < best {
			//fmt.Println("debug")
			best = curDepth - depth[i]
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth
	for _, next := range edges[i] {
		if next != from {
			dfs(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func dfs2(i int, curDepth int, from int) {
	//fmt.Println("dfs2debug1", i, curDepth, from)
	if found {
		return
	}
	if inPath[i] {
		if curDepth-depth[i] == best {
			if n == 100000 && m == 200000 {
				fmt.Println("debug3", i, prev[i], prev[prev[i]], prev[prev[prev[i]]], prev[prev[prev[prev[i]]]])
				return
			}
			ans = append(ans, i)
			tmp := prev[i]
			for tmp != i {
				ans = append(ans, tmp)
				tmp = prev[tmp]
			}
			found = true
		}
		return
	}
	if visited[i] {
		return
	}
	visited[i] = true
	inPath[i] = true
	depth[i] = curDepth

	for _, next := range edges[i] {
		//fmt.Println("dfs2debug2", i, curDepth, from, next)

		if next != from {
			prev[next] = i
			dfs2(next, curDepth+1, i)
		}
	}
	inPath[i] = false
	//visited[i] = false
}

func colorTree(i int, curColor int) {
	//fmt.Println("color", i, curColor)
	if color[i] != 0 {
		return
	}
	color[i] = curColor
	for _, edge := range edges[i] {
		colorTree(edge, 3-curColor)
	}
}


You are given $$$n$$$ words, each of which consists of lowercase alphabet letters. Each word contains at least one vowel. You are going to choose some of the given words and make as many beautiful lyrics as possible.Each lyric consists of two lines. Each line consists of two words separated by whitespace. A lyric is beautiful if and only if it satisfies all conditions below.   The number of vowels in the first word of the first line is the same as the number of vowels in the first word of the second line.  The number of vowels in the second word of the first line is the same as the number of vowels in the second word of the second line.  The last vowel of the first line is the same as the last vowel of the second line. Note that there may be consonants after the vowel. Also, letters "a", "e", "o", "i", and "u" are vowels. Note that "y" is never vowel.For example of a beautiful lyric,  "hello hellooowww" "whatsup yowowowow"  is a beautiful lyric because there are two vowels each in "hello" and "whatsup", four vowels each in "hellooowww" and "yowowowow" (keep in mind that "y" is not a vowel), and the last vowel of each line is "o".For example of a not beautiful lyric,  "hey man""iam mcdic"  is not a beautiful lyric because "hey" and "iam" don't have same number of vowels and the last vowels of two lines are different ("a" in the first and "i" in the second).How many beautiful lyrics can you write from given words? Note that you cannot use a word more times than it is given to you. For example, if a word is given three times, you can use it at most three times.

The first line contains single integer $$$n$$$ ($$$1 \le n \le 10^{5}$$$) — the number of words. The $$$i$$$-th of the next $$$n$$$ lines contains string $$$s_{i}$$$ consisting lowercase alphabet letters — the $$$i$$$-th word. It is guaranteed that the sum of the total word length is equal or less than $$$10^{6}$$$. Each word contains at least one vowel.

In the first line, print $$$m$$$ — the number of maximum possible beautiful lyrics. In next $$$2m$$$ lines, print $$$m$$$ beautiful lyrics (two lines per lyric). If there are multiple answers, print any.

14
wow
this
is
the
first
mcdics
codeforces
round
hooray
i
am
proud
about
that

7
arsijo
suggested
the
idea
for
this
problem

3
about proud
hooray round
wow first
this is
i that
mcdics am

NoteIn the first example, those beautiful lyrics are one of the possible answers. Let's look at the first lyric on the sample output of the first example. "about proud hooray round" forms a beautiful lyric because "about" and "hooray" have same number of vowels, "proud" and "round" have same number of vowels, and both lines have same last vowel. On the other hand, you cannot form any beautiful lyric with the word "codeforces".In the second example, you cannot form any beautiful lyric from given words.In the third example, you can use the word "same" up to three times.

package main

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

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	n := 0
	fmt.Fscanf(in, "%d\n", &n)
	used := make([]bool, n)
	totalc := make(map[int][]int)
	ac := make(map[int][]int)
	ec := make(map[int][]int)
	ic := make(map[int][]int)
	oc := make(map[int][]int)
	uc := make(map[int][]int)
	a := make([]string, n)
	for i := 0; i < n; i++ {
		s := ""
		fmt.Fscanf(in, "%s\n", &s)
		a[i] = s
		cnt := 0
		lv := 'a'
		for _, c := range s {
			if c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u' {
				cnt++
				lv = c
			}
		}
		totalc[cnt] = append(totalc[cnt], i)
		if lv == 'a' {
			ac[cnt] = append(ac[cnt], i)
		} else if lv == 'e' {
			ec[cnt] = append(ec[cnt], i)
		} else if lv == 'i' {
			ic[cnt] = append(ic[cnt], i)
		} else if lv == 'o' {
			oc[cnt] = append(oc[cnt], i)
		} else if lv == 'u' {
			uc[cnt] = append(uc[cnt], i)
		}
	}

	tp := 0
	for _, v := range totalc {
		tp += len(v) / 2
	}

	canLast := [][]string{}
	for _, v := range ac {
		for j := 0; j < len(v); j += 2 {
			if j+1 == len(v) {
				continue
			}
			if len(canLast) >= tp/2 {
				break
			}
			canLast = append(canLast, []string{a[v[j]], a[v[j+1]]})
			used[v[j]] = true
			used[v[j+1]] = true
		}
	}
	for _, v := range ec {
		for j := 0; j < len(v); j += 2 {
			if j+1 == len(v) {
				continue
			}
			if len(canLast) >= tp/2 {
				break
			}
			canLast = append(canLast, []string{a[v[j]], a[v[j+1]]})
			used[v[j]] = true
			used[v[j+1]] = true
		}
	}
	for _, v := range ic {
		for j := 0; j < len(v); j += 2 {
			if j+1 == len(v) {
				continue
			}
			if len(canLast) >= tp/2 {
				break
			}
			canLast = append(canLast, []string{a[v[j]], a[v[j+1]]})
			used[v[j]] = true
			used[v[j+1]] = true
		}
	}
	for _, v := range oc {
		for j := 0; j < len(v); j += 2 {
			if j+1 == len(v) {
				continue
			}
			if len(canLast) >= tp/2 {
				break
			}
			canLast = append(canLast, []string{a[v[j]], a[v[j+1]]})
			used[v[j]] = true
			used[v[j+1]] = true
		}
	}
	for _, v := range uc {
		for j := 0; j < len(v); j += 2 {
			if j+1 == len(v) {
				continue
			}
			if len(canLast) >= tp/2 {
				break
			}
			canLast = append(canLast, []string{a[v[j]], a[v[j+1]]})
			used[v[j]] = true
			used[v[j+1]] = true
		}
	}

	// fmt.Println(used)
	// fmt.Println(canLast)

	first := [][]string{}
	for _, v := range totalc {
		valid := []int{}
		for j := 0; j < len(v); j++ {
			if !used[v[j]] {
				valid = append(valid, v[j])
			}
		}
		for j := 0; j < len(valid); j += 2 {
			if j+1 == len(valid) {
				break
			}
			first = append(first, []string{a[valid[j]], a[valid[j+1]]})
		}
	}
	fmt.Fprintf(out, "%d\n", len(canLast))
	for i := 0; i < len(canLast); i++ {
		fmt.Fprintf(out, "%s %s\n", first[i][0], canLast[i][0])
		fmt.Fprintf(out, "%s %s\n", first[i][1], canLast[i][1])
	}
	return
}

// find num of elem >= k
func find(a []int, k int) int {
	if len(a) == 0 {
		return 0
	}
	n := len(a)
	if a[0] > k {
		return n
	}
	if a[n-1] < k {
		return 0
	}
	l := 0
	r := len(a) - 1
	for l < r {
		mid := (l + r) / 2
		if a[mid] < k {
			l = mid + 1
		} else {
			r = mid
		}
	}
	return n - l
}

func gcd(a, b uint64) uint64 {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

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

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

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func ok(a, b int) bool {
	if min(abs(a-b), abs(a+b)) <= min(abs(a), abs(b)) && max(abs(a+b), abs(a-b)) >= max(abs(a), abs(b)) {
		return true
	}
	return false
}

// Author: sighduck
// URL: https://codeforces.com/contest/1182/problem/C

package main

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

type VowelData struct {
	vowelCount int
	lastVowel  string
}

type Pair struct {
	word1 string
	word2 string
}

type Lyrics struct {
	line1word1 string
	line1word2 string
	line2word1 string
	line2word2 string
}

func parseString(s string) VowelData {
	vowelData := VowelData{}
	for i := 0; i < len(s); i++ {
		if strings.Contains("aeiou", string(s[i])) {
			vowelData.vowelCount += 1
			vowelData.lastVowel = string(s[i])
		}
	}
	return vowelData
}

func processPairs(lastVowelPairs []Pair, vowelCountPairs []Pair, results []Lyrics) []Lyrics {
	if len(lastVowelPairs) == 0 {
		return results
	}
	if len(vowelCountPairs) > 0 {
		var lastVowelPair, vowelCountPair Pair
		lastVowelPair, lastVowelPairs = lastVowelPairs[len(lastVowelPairs)-1], lastVowelPairs[:len(lastVowelPairs)-1]
		vowelCountPair, vowelCountPairs = vowelCountPairs[len(vowelCountPairs)-1], vowelCountPairs[:len(vowelCountPairs)-1]
		lyrics := Lyrics{
			line1word1: vowelCountPair.word1,
			line1word2: lastVowelPair.word1,
			line2word1: vowelCountPair.word2,
			line2word2: lastVowelPair.word2,
		}
		results = append(results, lyrics)
		return processPairs(lastVowelPairs, vowelCountPairs, results)
	}
	if len(lastVowelPairs) >= 2 {
		var lastVowelPair1, lastVowelPair2 Pair
		lastVowelPair1, lastVowelPairs = lastVowelPairs[len(lastVowelPairs)-1], lastVowelPairs[:len(lastVowelPairs)-1]
		lastVowelPair2, lastVowelPairs = lastVowelPairs[len(lastVowelPairs)-1], lastVowelPairs[:len(lastVowelPairs)-1]
		lyrics := Lyrics{
			line1word1: lastVowelPair1.word1,
			line1word2: lastVowelPair2.word1,
			line2word1: lastVowelPair1.word2,
			line2word2: lastVowelPair2.word2,
		}
		results = append(results, lyrics)
		return processPairs(lastVowelPairs, vowelCountPairs, results)
	}
	return results
}

func Solve(n int, stringList []string) []Lyrics {
	vowelMap := make(map[int]map[string][]string)
	for _, s := range stringList {
		vowelData := parseString(s)
		if vowelMap[vowelData.vowelCount] == nil {
			vowelMap[vowelData.vowelCount] = make(map[string][]string)
		}
		vowelMap[vowelData.vowelCount][vowelData.lastVowel] = append(
			vowelMap[vowelData.vowelCount][vowelData.lastVowel],
			s,
		)
	}
	var lastVowelPairs []Pair
	for count, vowelWordMap := range vowelMap {
		for vowel, _ := range vowelWordMap {
			if len(vowelMap[count][vowel]) != 1 {
				for len(vowelMap[count][vowel]) > 1 {
					var word1, word2 string
					word1, vowelMap[count][vowel] = vowelMap[count][vowel][len(vowelMap[count][vowel])-1], vowelMap[count][vowel][:len(vowelMap[count][vowel])-1]
					word2, vowelMap[count][vowel] = vowelMap[count][vowel][len(vowelMap[count][vowel])-1], vowelMap[count][vowel][:len(vowelMap[count][vowel])-1]
					lastVowelPairs = append(lastVowelPairs, Pair{word1: word1, word2: word2})
				}
			}
		}
	}
	var vowelCountPairs []Pair
	for _, vowelWordMap := range vowelMap {
		var wordList []string
		for _, words := range vowelWordMap {
			if len(words) == 1 {
				wordList = append(wordList, words[0])
			}
		}
		for len(wordList) > 1 {
			var word1, word2 string
			word1, wordList = wordList[len(wordList)-1], wordList[:len(wordList)-1]
			word2, wordList = wordList[len(wordList)-1], wordList[:len(wordList)-1]
			vowelCountPairs = append(vowelCountPairs, Pair{word1: word1, word2: word2})
		}
	}
	return processPairs(lastVowelPairs, vowelCountPairs, []Lyrics{})
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	stringList := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &stringList[i])
	}
	solution := Solve(n, stringList)
	fmt.Fprintf(writer, "%d\n", len(solution))
	for _, lyrics := range solution {
		fmt.Fprintf(writer, "%s %s\n", lyrics.line1word1, lyrics.line1word2)
		fmt.Fprintf(writer, "%s %s\n", lyrics.line2word1, lyrics.line2word2)
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1182/problem/C

package main

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

type VowelData struct {
	vowelCount int
	lastVowel  string
}

type Pair struct {
	word1 string
	word2 string
}

type Lyrics struct {
	line1word1 string
	line1word2 string
	line2word1 string
	line2word2 string
}

func parseString(s string) VowelData {
	vowelData := VowelData{}
	for i := 0; i < len(s); i++ {
		if strings.Contains("aeiou", string(s[i])) {
			vowelData.vowelCount += 1
			vowelData.lastVowel = string(s[i])
		}
	}
	return vowelData
}

func processPairs(lastVowelPairs []Pair, vowelCountPairs []Pair, results []Lyrics) []Lyrics {
	if len(lastVowelPairs) == 0 {
		return results
	}
	if len(vowelCountPairs) > 0 {
		var lastVowelPair, vowelCountPair Pair
		lastVowelPair, lastVowelPairs = lastVowelPairs[len(lastVowelPairs)-1], lastVowelPairs[:len(lastVowelPairs)-1]
		vowelCountPair, vowelCountPairs = vowelCountPairs[len(vowelCountPairs)-1], vowelCountPairs[:len(vowelCountPairs)-1]
		lyrics := Lyrics{
			line1word1: vowelCountPair.word1,
			line1word2: lastVowelPair.word1,
			line2word1: vowelCountPair.word2,
			line2word2: lastVowelPair.word2,
		}
		results = append(results, lyrics)
		return processPairs(lastVowelPairs, vowelCountPairs, results)
	}
	if len(lastVowelPairs) == 2 {
		var lastVowelPair1, lastVowelPair2 Pair
		lastVowelPair1, lastVowelPairs = lastVowelPairs[len(lastVowelPairs)-1], lastVowelPairs[:len(lastVowelPairs)-1]
		lastVowelPair2, lastVowelPairs = lastVowelPairs[len(lastVowelPairs)-1], lastVowelPairs[:len(lastVowelPairs)-1]
		lyrics := Lyrics{
			line1word1: lastVowelPair1.word1,
			line1word2: lastVowelPair2.word1,
			line2word1: lastVowelPair1.word2,
			line2word2: lastVowelPair2.word2,
		}
		results = append(results, lyrics)
		return processPairs(lastVowelPairs, vowelCountPairs, results)
	}
	return results
}

func Solve(n int, stringList []string) []Lyrics {
	vowelMap := make(map[int]map[string][]string)
	for _, s := range stringList {
		vowelData := parseString(s)
		if vowelMap[vowelData.vowelCount] == nil {
			vowelMap[vowelData.vowelCount] = make(map[string][]string)
		}
		vowelMap[vowelData.vowelCount][vowelData.lastVowel] = append(
			vowelMap[vowelData.vowelCount][vowelData.lastVowel],
			s,
		)
	}
	var lastVowelPairs []Pair
	for count, vowelWordMap := range vowelMap {
		for vowel, _ := range vowelWordMap {
			if len(vowelMap[count][vowel]) != 1 {
				for len(vowelMap[count][vowel]) > 1 {
					var word1, word2 string
					word1, vowelMap[count][vowel] = vowelMap[count][vowel][len(vowelMap[count][vowel])-1], vowelMap[count][vowel][:len(vowelMap[count][vowel])-1]
					word2, vowelMap[count][vowel] = vowelMap[count][vowel][len(vowelMap[count][vowel])-1], vowelMap[count][vowel][:len(vowelMap[count][vowel])-1]
					lastVowelPairs = append(lastVowelPairs, Pair{word1: word1, word2: word2})
				}
			}
		}
	}
	var vowelCountPairs []Pair
	for _, vowelWordMap := range vowelMap {
		var wordList []string
		for _, words := range vowelWordMap {
			if len(words) == 1 {
				wordList = append(wordList, words[0])
			}
		}
		for len(wordList) > 1 {
			var word1, word2 string
			word1, wordList = wordList[len(wordList)-1], wordList[:len(wordList)-1]
			word2, wordList = wordList[len(wordList)-1], wordList[:len(wordList)-1]
			vowelCountPairs = append(vowelCountPairs, Pair{word1: word1, word2: word2})
		}
	}
	return processPairs(lastVowelPairs, vowelCountPairs, []Lyrics{})
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var n int
	fmt.Fscanf(reader, "%d\n", &n)
	stringList := make([]string, n)
	for i := 0; i < n; i++ {
		fmt.Fscanf(reader, "%s\n", &stringList[i])
	}
	solution := Solve(n, stringList)
	fmt.Fprintf(writer, "%d\n", len(solution))
	for _, lyrics := range solution {
		fmt.Fprintf(writer, "%s %s\n", lyrics.line1word1, lyrics.line1word2)
		fmt.Fprintf(writer, "%s %s\n", lyrics.line2word1, lyrics.line2word2)
	}
}


In the rush of modern life, people often forget how beautiful the world is. The time to enjoy those around them is so little that some even stand in queues to several rooms at the same time in the clinic, running from one queue to another.(Cultural note: standing in huge and disorganized queues for hours is a native tradition in Russia, dating back to the Soviet period. Queues can resemble crowds rather than lines. Not to get lost in such a queue, a person should follow a strict survival technique: you approach the queue and ask who the last person is, somebody answers and you join the crowd. Now you're the last person in the queue till somebody else shows up. You keep an eye on the one who was last before you as he is your only chance to get to your destination) I'm sure many people have had the problem when a stranger asks who the last person in the queue is and even dares to hint that he will be the last in the queue and then bolts away to some unknown destination. These are the representatives of the modern world, in which the ratio of lack of time is so great that they do not even watch foreign top-rated TV series. Such people often create problems in queues, because the newcomer does not see the last person in the queue and takes a place after the "virtual" link in this chain, wondering where this legendary figure has left.The Smart Beaver has been ill and he's made an appointment with a therapist. The doctor told the Beaver the sad news in a nutshell: it is necessary to do an electrocardiogram. The next day the Smart Beaver got up early, put on the famous TV series on download (three hours till the download's complete), clenched his teeth and bravely went to join a queue to the electrocardiogram room, which is notorious for the biggest queues at the clinic.Having stood for about three hours in the queue, the Smart Beaver realized that many beavers had not seen who was supposed to stand in the queue before them and there was a huge mess. He came up to each beaver in the ECG room queue and asked who should be in front of him in the queue. If the beaver did not know his correct position in the queue, then it might be his turn to go get an ECG, or maybe he should wait for a long, long time...As you've guessed, the Smart Beaver was in a hurry home, so he gave you all the necessary information for you to help him to determine what his number in the queue can be.

The first line contains two integers n (1 ≤ n ≤ 103) and x (1 ≤ x ≤ n) — the number of beavers that stand in the queue and the Smart Beaver's number, correspondingly. All willing to get to the doctor are numbered from 1 to n. The second line contains n integers a1, a2, ..., an (0 ≤ ai ≤ n) — the number of the beaver followed by the i-th beaver. If ai = 0, then the i-th beaver doesn't know who is should be in front of him. It is guaranteed that values ai are correct. That is there is no cycles in the dependencies. And any beaver is followed by at most one beaver in the queue. The input limits for scoring 30 points are (subproblem B1):    It is guaranteed that the number of zero elements ai doesn't exceed 20.  The input limits for scoring 100 points are (subproblems B1+B2):    The number of zero elements ai is arbitrary.

Print all possible positions of the Smart Beaver in the line in the increasing order.

package main

import (
	"fmt"
)

func main() {
	var n, x int
	fmt.Scanf("%d %d\n", &n, &x)
	prev := make([]int, n + 1)
	next := make([]int, n + 1)
	for i := 1;i <= n;i ++ {
		fmt.Scanf("%d", &prev[i])
		if prev[i] != 0 {
			next[prev[i]] = i
		}
	}

	queue := make([]int, 0, n)
	var wisePos int

	for i := 1;i <= n;i ++ {
		var isWise bool
		var length int
		if prev[i] == 0 {
			for cur := i; cur != 0; cur, length = next[cur], length + 1 {
				if x == cur {
					isWise = true
					wisePos = length + 1
					break
				}
			}
			if !isWise {
				queue = append(queue, length)
			}
		}
	}

	dp := make([]bool, n + 1)
	dp[0] = true
	for i := 0;i < len(queue);i ++ {
		for j := len(dp) - 1;j >= queue[i];j -- {
			if dp[j - queue[i]] {
				dp[j] = true
			}
		}
	}
	for i := 0;i < len(dp);i ++ {
		if dp[i] {
			fmt.Printf("%d\n", i + wisePos)
		}
	}
}


Petya has got 2n cards, each card contains some integer. The numbers on the cards can be the same. Let's index all cards by consecutive integers from 1 to 2n. We'll denote the number that is written on a card with number i, as ai. In order to play one entertaining game with his friends, Petya needs to split the cards into pairs so that each pair had equal numbers on the cards. Help Petya do that.

The first line contains integer n (1 ≤ n ≤ 3·105). The second line contains the sequence of 2n positive integers a1, a2, ..., a2n (1 ≤ ai ≤ 5000) — the numbers that are written on the cards. The numbers on the line are separated by single spaces.

If it is impossible to divide the cards into pairs so that cards in each pair had the same numbers, print on a single line integer -1. But if the required partition exists, then print n pairs of integers, a pair per line — the indices of the cards that form the pairs. Separate the numbers on the lines by spaces. You can print the pairs and the numbers in the pairs in any order. If there are multiple solutions, print any of them.

package main

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

func main() {
    var flag [50001]int
    var ans [300001][2]int
    var n int
    now:=0
    input, _ := os.Open("input.txt")
    defer input.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    output, _ := os.Create("output.txt")
    defer output.Close()
    writer := bufio.NewWriter(output)
    scanner.Scan()
    aa, _ := strconv.Atoi(scanner.Text())
    n=aa
    for i:=1;i<=2*n;i++ {
    	var x int
    	scanner.Scan()
    	bb, _ := strconv.Atoi(scanner.Text())
    	x=bb
    	if flag[x]!=0 {
    		ans[now][0]=flag[x]
    		ans[now][1]=i
    		now++
    		flag[x]=0
    	} else {
    		flag[x]=i
    	}
    }
    if now!=n {
    	writer.WriteString("-1")
    } else {
    	for i:=0;i<now;i++ {
    		writer.WriteString(strconv.Itoa(ans[i][0])+" "+strconv.Itoa(ans[i][1]))
    		    writer.WriteString("\n")
    	}
    }

    writer.Flush()
}

package main

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

var scanner *bufio.Scanner

func getI64() int64 {
  scanner.Scan()
  x, _ := strconv.ParseInt(scanner.Text(), 10, 64)
  return x
}
func getI() int {
  return int(getI64())
}
func getF() float64 {
  scanner.Scan()
  x, _ := strconv.ParseFloat(scanner.Text(), 64)
  return x
}
func getS() string {
  scanner.Scan()
  return scanner.Text()
}

func main() {
  inFile, _ := os.Open("input.txt")
  outFile, _ := os.Create("output.txt")
  scanner = bufio.NewScanner(inFile)
  scanner.Split(bufio.ScanWords)
  writer := bufio.NewWriter(outFile)
  defer writer.Flush()

  n := 2 * getI()
  count := map[int][]int{}
  for i := 1; i <= n; i++ {
    x := getI()
    count[x] = append(count[x], i)
  }
  for _, list := range count {
    if len(list) % 2 == 1 {
      writer.WriteString("-1\n")
      return
    }
  }
  for _, list := range count {
    for i := 0; i < len(list); i += 2 {
      writer.WriteString(fmt.Sprintf("%d %d\n", list[i], list[i+1]))
    }
  }
}

package main

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

type Card struct {
    v,p int
}

type CardSlice []Card

func (c CardSlice) Len() int { return len(c) }
func (c CardSlice) Swap(i,j int) { c[i], c[j] = c[j], c[i] }
func (c CardSlice) Less(i,j int) bool { return c[i].v < c[j].v }

func main() {
    input, _ := os.Open("input.txt")
    defer input.Close()
    output, _ := os.Create("output.txt")
    defer output.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    writer := bufio.NewWriter(output)

    ScanInts := func(a... *int) {
        for i := 0; i < len(a); i++ {
            scanner.Scan()
            *(a[i]), _ = strconv.Atoi(scanner.Text())
        }
    }

    var n int
    ScanInts(&n)
    a := make(CardSlice,2*n)
    for i := 0; i < 2*n; i++ {
        ScanInts(&a[i].v)
        a[i].p = i+1
    }
    sort.Sort(a)
    ok, ans := true, make([]string,0,n)
    for i := 0; i < (2*n); i += 2 {
        if a[i].v != a[i+1].v {
            ok = false
            break
        } else {
            ans = append(ans,strconv.Itoa(a[i].p)+" "+strconv.Itoa(a[i+1].p)+"\n")
        }
    }
    if ok {
        for i := 0; i < len(ans); i++ {
            writer.WriteString(ans[i])
        }
    } else {
        writer.WriteString("-1\n")
    }
    writer.Flush()
}

package main

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

func main() {
    var flag [50001]int
    var ans [300001][2]int
    var n int
    now:=0
    input, _ := os.Open("input.txt")
    defer input.Close()
    scanner := bufio.NewScanner(input)
    scanner.Split(bufio.ScanWords)
    output, _ := os.Create("output.txt")
    defer output.Close()
    writer := bufio.NewWriter(output)
    scanner.Scan()
    aa, _ := strconv.Atoi(scanner.Text())
    n=aa
    for i:=1;i<=2*n;i++ {
    	var x int
    	scanner.Scan()
    	bb, _ := strconv.Atoi(scanner.Text())
    	x=bb
    	if flag[x]!=0 {
    		ans[now][0]=flag[x]
    		now++
    		ans[now][1]=i
    		flag[x]=0
    	} else {
    		flag[x]=i
    	}
    }
    if now!=n {
    	writer.WriteString("-1")
    } else {
    	for i:=0;i<now;i++ {
    		writer.WriteString(strconv.Itoa(ans[i][0])+" "+strconv.Itoa(ans[i][1]))
    	}
    }
    writer.WriteString("\n")
    writer.Flush()
}


Monocarp had a tree which consisted of $$$n$$$ vertices and was rooted at vertex $$$1$$$. He decided to study BFS (Breadth-first search), so he ran BFS on his tree, starting from the root. BFS can be described by the following pseudocode:a = [] # the order in which vertices were processedq = Queue()q.put(1) # place the root at the end of the queuewhile not q.empty():    k = q.pop() # retrieve the first vertex from the queue    a.append(k) # append k to the end of the sequence in which vertices were visited    for y in g[k]: # g[k] is the list of all children of vertex k, sorted in ascending order        q.put(y)Monocarp was fascinated by BFS so much that, in the end, he lost his tree. Fortunately, he still has a sequence of vertices, in which order vertices were visited by the BFS algorithm (the array a from the pseudocode). Monocarp knows that each vertex was visited exactly once (since they were put and taken from the queue exactly once). Also, he knows that all children of each vertex were viewed in ascending order.Monocarp knows that there are many trees (in the general case) with the same visiting order $$$a$$$, so he doesn't hope to restore his tree. Monocarp is okay with any tree that has minimum height.The height of a tree is the maximum depth of the tree's vertices, and the depth of a vertex is the number of edges in the path from the root to it. For example, the depth of vertex $$$1$$$ is $$$0$$$, since it's the root, and the depth of all root's children are $$$1$$$.Help Monocarp to find any tree with given visiting order $$$a$$$ and minimum height.

The first line contains a single integer $$$t$$$ ($$$1 \le t \le 1000$$$) — the number of test cases. The first line of each test case contains a single integer $$$n$$$ ($$$2 \le n \le 2 \cdot 10^5$$$) — the number of vertices in the tree. The second line of each test case contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le n$$$; $$$a_i \neq a_j$$$; $$$a_1 = 1$$$) — the order in which the vertices were visited by the BFS algorithm. It's guaranteed that the total sum of $$$n$$$ over test cases doesn't exceed $$$2 \cdot 10^5$$$.

For each test case print the minimum possible height of a tree with the given visiting order $$$a$$$.

NoteIn the first test case, there is only one tree with the given visiting order:   In the second test case, there is only one tree with the given visiting order as well:   In the third test case, an optimal tree with the given visiting order is shown below:

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 9 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

type node struct {
	x        int
	children []*node
}

func newNode(x int) *node {
	return &node{
		x:        x,
		children: make([]*node, 0),
	}
}

func maxDepth(u *node, depth int) int {
	max := depth
	for _, v := range u.children {
		vDepth := maxDepth(v, depth+1)
		if vDepth > max {
			max = vDepth
		}
	}
	return max
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		ord := append(make([]*node, 0), newNode(1))
		cur := 0

		for i := 1; i < n; i++ {
			if arr[i] < arr[i-1] {
				cur++
			}
			x := newNode(arr[i])
			ord[cur].children = append(ord[cur].children, x)
			ord = append(ord, x)
		}

		ans := maxDepth(ord[0], 0)
		out.println(ans)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1437D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := []int{}
		for i := 1; i < n; {
			st := i
			for i++; i < n && a[i] > a[i-1]; i++ {
			}
			b = append(b, i-st)
		}
		q := []int{b[0]}
		ans := 1
		for i, n := 1, len(b); i < n; {
			ans++
			qq := q
			q = nil
			for _, sz := range qq {
				for ; sz > 0 && i < n; sz-- {
					q = append(q, b[i])
					i++
				}
			}
		}
		Fprintln(out, ans)
	}
}

func main() { CF1437D(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1437D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var T, n int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		a := make([]int, n)
		for i := range a {
			Fscan(in, &a[i])
		}
		b := []int{}
		for i := 1; i < n; {
			st := i
			for i++; i < n && a[i] > a[i-1]; i++ {
			}
			b = append(b, i-st)
		}
		q := []int{b[0]}
		b = b[1:]
		ans := 1
		for len(q) > 0 && len(b) > 0 {
			ans++
			qq := q
			q = nil
			for _, sz := range qq {
				for ; sz > 0 && len(b) > 0; sz-- {
					q = append(q, b[0])
					b = b[1:]
				}
			}
		}
		Fprintln(out, ans)
	}
}

func main() { CF1437D(os.Stdin, os.Stdout) }

package main
import (
	"fmt"
	"bufio"
	"os"
)
func main() {
	rd := bufio.NewReader(os.Stdin)
	q := 0
	fmt.Fscan(rd, &q)
	for t := 0; t < q; t++ {
		n := 0
		fmt.Fscan(rd, &n)
		a := make([]int, n)
		for i := range a {
			fmt.Fscan(rd, &a[i])
		}
		var seg [][]int
		i := 1
		for i < n {
			j := i
			for j + 1 < n && a[j + 1] > a[j] {
				j++
			}
			seg = append(seg, []int{i, j})
			i = j + 1
		}
		res, cur, k, nxt := 1, 1, 0, 0
		for i, v := range seg {
			k++
			nxt += v[1] - v[0] + 1
			if k == cur {
				k, cur = 0, nxt
				nxt = 0
				if i < len(seg) - 1 {
					res++
				}
			}
  		}
  		fmt.Println(res)
	}
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 10 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		depth := 1
		gapByDepth := make([]int, 2)

		for i := 2; i < n; i++ {
			if arr[i] > arr[i-1] {
				gapByDepth[depth]++
			} else {
				if gapByDepth[depth-1] == 0 {
					depth++
					gapByDepth = append(gapByDepth, 0)
				} else {
					gapByDepth[depth-1]--
				}
			}
		}

		out.println(depth)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 10 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		ans := 1
		for i := 2; i < n; i++ {
			if arr[i] < arr[i-1] {
				ans++
			}
		}

		out.println(ans)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 10 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		ans := 1
		gap := 0

		for i := 2; i < n; i++ {
			if arr[i] < arr[i-1] {
				if gap > 0 {
					gap--
				} else {
					ans++
				}
			} else {
				gap++
			}
		}

		out.println(ans)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 10 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

type node struct {
	x        int
	children []*node
}

func newNode(x int) *node {
	return &node{
		x:        x,
		children: make([]*node, 0),
	}
}

func maxDepth(u *node, depth int) int {
	max := depth
	for _, v := range u.children {
		vDepth := maxDepth(v, depth+1)
		if vDepth > max {
			max = vDepth
		}
	}
	return max
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		ord := append(make([]*node, 0), newNode(1))
		cur := 0

		for i := 1; i < n; i++ {
			if arr[i] < arr[i-1] {
				cur++
			}
			x := newNode(arr[i])
			ord[cur].children = append(ord[cur].children, x)
			ord = append(ord, x)
		}

		ans := maxDepth(ord[0], 0)
		out.println(ans)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 10 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		depth := 1
		gapByDepth := make([]int, 2)

		for i := 1; i < n; i++ {
			if arr[i] > arr[i-1] {
				gapByDepth[depth]++
			} else {
				if gapByDepth[depth-1] == 0 {
					gapByDepth[depth]--
					depth++
					gapByDepth = append(gapByDepth, 1)
				} else {
					gapByDepth[depth-1]--
				}
			}
		}

		out.println(depth)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}

package main

import (
	"bufio"
	"container/heap"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
type vdPair struct{ v, dis int }
type vdHeap []vdPair

func (h vdHeap) Len() int              { return len(h) }
func (h vdHeap) Less(i, j int) bool    { return h[i].dis < h[j].dis }
func (h vdHeap) Swap(i, j int)         { h[i], h[j] = h[j], h[i] }
func (h *vdHeap) Push(v interface{})   { *h = append(*h, v.(vdPair)) }
func (h *vdHeap) Pop() (v interface{}) { a := *h; *h, v = a[:len(a)-1], a[len(a)-1]; return }
func (h *vdHeap) push(v vdPair)        { heap.Push(h, v) }
func (h *vdHeap) pop() vdPair          { return heap.Pop(h).(vdPair) }

func CF1437C(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	const inf int = 1e9
	abs := func(x int) int {
		if x < 0 {
			return -x
		}
		return x
	}

	var T, n, t int
	for Fscan(in, &T); T > 0; T-- {
		Fscan(in, &n)
		type neighbor struct{ to, rid, cap, cost int }
		g := make([][]neighbor, 3*n+2)
		addEdge := func(from, to, cap, cost int) {
			g[from] = append(g[from], neighbor{to, len(g[to]), cap, cost})
			g[to] = append(g[to], neighbor{from, len(g[from]) - 1, 0, -cost})
		}
		st, end := 0, 3*n+1
		for i := 1; i <= n; i++ {
			addEdge(st, i, 1, 0)
		}
		for i := 1; i <= n; i++ {
			Fscan(in, &t)
			for j := 1; j <= 2*n; j++ {
				addEdge(i, n+j, inf, abs(t-j))
			}
		}
		for i := n + 1; i <= 3*n; i++ {
			addEdge(i, end, 1, 0)
		}

		n = 3*n + 2
		const inf int = 1e9
		h := make([]int, n)
		dist := make([]int, n)
		type pair struct{ v, i int }
		fa := make([]pair, n)
		dijkstra := func() bool {
			for i := range dist {
				dist[i] = inf
			}
			dist[st] = 0
			q := vdHeap{{st, 0}}
			for len(q) > 0 {
				p := q.pop()
				v := p.v
				if dist[v] < p.dis {
					continue
				}
				for i, e := range g[v] {
					if e.cap == 0 {
						continue
					}
					w := e.to
					if newD := dist[v] + int(e.cost) + h[v] - h[w]; newD < dist[w] {
						dist[w] = newD
						fa[w] = pair{v, i}
						q.push(vdPair{w, newD})
					}
				}
			}
			return dist[end] < inf
		}
		minCost := 0
		for dijkstra() {
			for i, d := range dist {
				h[i] += d
			}
			for v := end; v != st; {
				p := fa[v]
				e := &g[p.v][p.i]
				e.cap--
				g[v][e.rid].cap++
				v = p.v
			}
			minCost += h[end]
		}
		Fprintln(out, minCost)
	}
}

func main() { CF1437C(os.Stdin, os.Stdout) }

package main

import (
	"io"
	"io/ioutil"
	"os"
)

// OutputBuffer implements a faster way to print values
type OutputBuffer struct {
	i      int
	memo   []byte
	writer io.Writer
}

// NewOutputBuffer returns an OutputBuffer initialized instance
func NewOutputBuffer(out io.Writer) *OutputBuffer {
	return &OutputBuffer{
		memo:   make([]byte, 1024*1024),
		writer: out,
	}
}

func (o *OutputBuffer) println(x int) {
	aux := make([]byte, 6)
	i := 0

	for x > 10 {
		aux[i] = byte(x%10) + '0'
		i++
		x /= 10
	}

	aux[i] = byte(x%10) + '0'
	i++

	for i > 0 {
		i--
		o.memo[o.i] = aux[i]
		o.i++
	}

	o.memo[o.i] = '\n'
	o.i++

	if o.i >= len(o.memo)-16 {
		o.flush()
	}
}

func (o *OutputBuffer) flush() {
	if o.i > 0 {
		o.writer.Write(o.memo[:o.i])
		o.i = 0
	}
}

// Test has each test definition
type Test struct {
	n   int
	arr []int
}

func readInt(b []byte, i int) (int, int) {
	var x int
	l := len(b)

	for ; b[i] < '0' || b[i] > '9'; i++ {
	}

	for ; i < l && b[i] >= '0' && b[i] <= '9'; i++ {
		x = (x << 3) + (x << 1) + int(b[i]&15)
	}

	return x, i
}

func processInput(in io.Reader) (int, []*Test) {
	buff, _ := ioutil.ReadAll(in)
	k := 0

	var t int
	t, k = readInt(buff, k)
	tests := make([]*Test, t)

	for i := 0; i < t; i++ {
		var n int
		n, k = readInt(buff, k)
		arr := make([]int, n)

		for j := 0; j < n; j++ {
			arr[j], k = readInt(buff, k)
		}

		tests[i] = &Test{
			n:   n,
			arr: arr[:],
		}
	}

	return t, tests
}

// Solution to Minimal Height Tree problem
func Solution(reader io.Reader, writer io.Writer) {
	out := NewOutputBuffer(writer)

	t, tests := processInput(reader)

	for _t := 0; _t < t; _t++ {
		test := tests[_t]
		n, arr := test.n, test.arr[:]

		depth := 1
		gapByDepth := make([]int, 2)

		for i := 1; i < n; i++ {
			if arr[i] > arr[i-1] {
				gapByDepth[depth]++
			} else {
				if gapByDepth[depth-1] == 0 {
					gapByDepth[depth]--
					depth++
					gapByDepth = append(gapByDepth, 0)
				} else {
					gapByDepth[depth-1]--
				}
			}
		}

		out.println(depth)
	}

	out.flush()
}

func main() {
	Solution(os.Stdin, os.Stdout)
}