package main

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

var scanner = bufio.NewScanner(os.Stdin)

func init() {
	scanner.Split(bufio.ScanWords)
}

func scanString() string {
	scanner.Scan()
	return scanner.Text()
}

func scanInt64() int64 {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v
}

func scanInt() int {
	scanner.Scan()
	v, _ := strconv.Atoi(scanner.Text())
	return v
}

func scanInts(n int) []int {
	l := make([]int, n)
	for i := 0; i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.Atoi(scanner.Text())
	}

	return l
}

func scanInts64(n int64) []int64 {
	l := make([]int64, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		l[i], _ = strconv.ParseInt(scanner.Text(), 10, 64)
	}

	return l
}

func scanBool() bool {
	scanner.Scan()
	v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
	return v == 1
}

func scanBools(n int64) []bool {
	l := make([]bool, n)
	for i := int64(0); i < n; i++ {
		scanner.Scan()
		v, _ := strconv.ParseInt(scanner.Text(), 10, 64)
		l[i] = v == 1
	}

	return l
}

func main() {
	n, s := scanInt(), scanInt()
	OF, OB := scanBools(int64(n)), scanBools(int64(n))

	if !OF[0] {
		fmt.Println("NO")
		return
	}

	if OF[s-1] {
		fmt.Println("YES")
		return
	}

	if !OF[s-1] && !OB[s-1] {
		fmt.Println("NO")
		return
	}

	for i := s - 1; i < n; i++ {
		if OF[i] && OB[i] {
			fmt.Println("YES")
			return
		}
	}

	fmt.Println("NO")
}

func abs(a int64) int64 {
	if a >= 0 {
		return a
	}

	return -a
}

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

	return b
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)

func read_int_array(array_length int) []int {
    input_array := make([]int, array_length)
    for i := 0; i < array_length; i++ {
        fmt.Fscan(reader, &input_array[i])
    }
    return input_array
}

func main() {
    var n, s int
    fmt.Fscan(reader, &n)
    fmt.Fscanln(reader, &s)
    first_track := read_int_array(n)
    second_track := read_int_array(n)
    norm_s := s-1
    if first_track[0] == 0 {
        fmt.Print("NO")
        return
    }
    if first_track[norm_s] == 1 {
        fmt.Print("YES")
        return
    } else {
        if second_track[norm_s] == 1 {
            for i:=norm_s+1;i<n;i++ {
                if first_track[i]==1 && second_track[i]==1 {
                    fmt.Print("YES")
                    return
                }
            }
            fmt.Print("NO")
            return
        } else {
            fmt.Print("NO")
            return
        }
    }
}

package main

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

func solve() {
	n := readInt()
	s := readInt()
	g := make([][]int, 2 * n)
	for i := 0; i < 2 * n; i++ {
		g[i] = make([]int, 0)
	}
	a:=readIntArray(n)
	b:=readIntArray(n)

	prev := -1
	for i := 0; i < n; i++ {
		if a[i] == 1 {
			if prev != -1 {
				g[prev] = append(g[prev], i)
			}
			prev = i
		}
	}
	prev = -1
	for i := n - 1; i >= 0; i-- {
		if b[i] == 1 {
			if prev != -1 {
				g[prev + n] = append(g[prev + n], i + n)
			}
			prev = i
		}
	}
	for i := 0; i < n; i++ {
		if a[i] == 1 && b[i] == 1 {
			g[i] = append(g[i], i + n)
		}
	}
	vis := make([]bool, 2*n)
	dfs(g, 0, vis)
	if vis[0] && (vis[s-1] || vis[s-1+n]) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

func dfs(g [][]int, u int, vis []bool) {
	vis[u] = true
	for _, next := range g[u] {
		if !vis[next] {
			dfs(g, next, vis)
		}
	}
}

var scanner *bufio.Scanner

func main() {
	scanner = bufio.NewScanner(os.Stdin)
	const MaxTokenLength = 1024 * 1024
	scanner.Buffer(make([]byte, 0, MaxTokenLength), MaxTokenLength)
	scanner.Split(bufio.ScanWords)
	solve()
}

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

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

// IO

func readString() string {
	scanner.Scan()
	return scanner.Text()
}

func readInt() int {
	val, _ := strconv.Atoi(readString())
	return val
}

func readInt64() int64 {
	v, _ := strconv.ParseInt(readString(), 10, 64)
	return v
}

func readIntArray(sz int) []int {
	a := make([]int, sz)
	for i := 0; i < sz; i++ {
		a[i] = readInt()
	}
	return a
}

func readInt64Array(n int) []int64 {
	res := make([]int64, n)
	for i := 0; i < n; i++ {
		res[i] = readInt64()
	}
	return res
}

package main

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

var n, s int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &n, &s)

	a := make([]int, n+5)
	b := make([]int, n+5)

	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &a[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &b[i])
	}

	if a[s] == 0 && b[s] == 0 || a[1] == 0 {
		fmt.Println("NO")
		return
	}

	if a[s] == 1 {
		fmt.Println("YES")
		return
	} else {
		ok := 0
		for i := s + 1; i <= n; i++ {
			if a[i] == 1 && b[i] == 1 {
				ok = 1
				break
			}
		}

		if ok == 1 {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

package main

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

var n, s int

func main() {
	var input io.Reader = bufio.NewReader(os.Stdin)

	fmt.Fscan(input, &n, &s)

	a := make([]bool, n+5)
	b := make([]bool, n+5)

	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &a[i])
	}

	for i := 1; i <= n; i++ {
		fmt.Fscan(input, &b[i])
	}

	if a[s] == false && b[s] == false || a[1] == false {
		fmt.Println("NO")
		return
	}

	if a[s] == true {
		fmt.Println("YES")
		return
	} else {
		ok := false
		for i := s + 1; i <= n; i++ {
			if a[i] == true && b[i] == true {
				ok = true
				break
			}
		}

		if ok == true {
			fmt.Println("YES")
		} else {
			fmt.Println("NO")
		}
	}
}

// A<->B X円
// B<->C Y円

package main

import (
	"fmt"
)

func main() {
	var (
		N, S int
	)
    ans := "NO"
	fmt.Scan(&N, &S)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&B[i])
	}

    var max_N int
    for max_N = N; 0 < max_N; max_N-- {
        if A[max_N-1] == 1 {
            break
        }
    }

    if A[0] == 0 && S != 1 {
	 	ans = "NO"
    } else {
        if A[S-1] == 1 {
            ans = "YES"
        } else {
            var max_can_turn int
            for i:=0; i < N; i++ {
                if A[i] == 1 && B[i] == 1 {
                    max_can_turn = i
                }
            }
            for i:=max_can_turn; 0 <= i; i-- {
                if B[i] == 1 {
                    if i == S-1 {
                        ans = "YES"
                        break
                    }
                }
            }
        }
    }

    // else if max_N <= S {
    //     ans = "NO"
	// } else if A[S-1] == 0 && B[S-1] == 0 {
	// 	ans = "NO"
	// } else {
	// 	ans = "YES"
	// }
	fmt.Println(ans)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	n, s := 0, 0

	scanf("%d %d\n", &n, &s)

	s--
	a := make([]int, n)
	b := make([]int, n)
	f := make([]bool, n)
	for i := 0; i < n; i++ {
		scanf("%d", &a[i])
		f[i] = false
	}
	scanf("\n")
	for i := 0; i < n; i++ {
		scanf("%d", &b[i])
		if b[i] == 1 && a[i] == 1 {
			f[i] = true
		}
	}

	if a[0] == 0 {
		printf("NO")
		return
	}

	if a[s] == 1 {
		printf("YES")
		return
	}

	for i := s + 1; i < n; i++ {
		if f[i] && b[s] == 1 {
			printf("YES")
			return
		}
	}

	printf("NO")

}

// A<->B X円
// B<->C Y円

package main

import (
	"fmt"
)

func main() {
	var (
		N, S int
		ans  string
	)
	fmt.Scan(&N, &S)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&B[i])
	}

    var max_N int
    for max_N = N-1; 0 <= max_N; max_N-- {
        if A[max_N] == 1 {
            break
        }
    }

	if A[0] == 0 && S != 1 {
		ans = "NO"
    } else if max_N < S {
        ans = "NO"
	} else if A[S-1] == 0 && B[S-1] == 0 {
		ans = "NO"
	} else {
		ans = "YES"
	}
	fmt.Println(ans)
}

// A<->B X円
// B<->C Y円

package main

import (
	"fmt"
)

func main() {
	var (
		N, S int
	)
    ans := "NO"
	fmt.Scan(&N, &S)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&B[i])
	}

    var max_N int
    for max_N = N; 0 < max_N; max_N-- {
        if A[max_N-1] == 1 {
            break
        }
    }

    if A[0] == 0 && S != 1 {
	 	ans = "NO"
    } else {

        var turn int
        for i:=0; i < N; i++ {
            if A[i] == 1 {
                if i == S-1 {
                    ans = "YES"
                    break
                } else {
                    turn = i
                }
            }
        }
        for i:=turn; 0 <= i; i-- {
            if B[i] == 1 {
                if i == S-1 {
                    ans = "YES"
                    break
                }
            }
        }
    }

    // else if max_N <= S {
    //     ans = "NO"
	// } else if A[S-1] == 0 && B[S-1] == 0 {
	// 	ans = "NO"
	// } else {
	// 	ans = "YES"
	// }
	fmt.Println(ans)
}

// A<->B X円
// B<->C Y円

package main

import (
	"fmt"
)

func main() {
	var (
		N, S int
		ans  string
	)
	fmt.Scan(&N, &S)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&B[i])
	}

    var max_N int
    for max_N = N; 0 < max_N; max_N-- {
        if A[max_N-1] == 1 {
            break
        }
    }

	if A[0] == 0 && S != 1 {
		ans = "NO"
    } else if max_N <= S {
        ans = "NO"
	} else if A[S-1] == 0 && B[S-1] == 0 {
		ans = "NO"
	} else {
		ans = "YES"
	}
	fmt.Println(ans)
}

// A<->B X円
// B<->C Y円

package main

import (
	"fmt"
)

func main() {
	var (
		N, S int
		ans  string
	)
	fmt.Scan(&N, &S)

	A := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&A[i])
	}
	B := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&B[i])
	}

	if A[0] == 0 && S != 1 {
		ans = "NO"
	} else if A[S-1] == 0 && B[S-1] == 0 {
		ans = "NO"
	} else {
		ans = "YES"
	}
	fmt.Println(ans)
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	n, s := 0, 0

	scanf("%d %d\n", &n, &s)
	s--
	a := make([]int, n)
	b := make([]int, n)
	f := make([]bool, n)
	for i := 0; i < n; i++ {
		scanf("%d", &a[i])
	}

	for i := n - 1; i >= 0; i-- {
		scanf("%d", &b[i])
		if b[i] == 1 && a[i] == 1 {
			f[i] = true
		}
	}

	if a[0] == 0 {
		printf("NO")
		return
	}

	if a[s] == 1 {
		printf("YES")
		return
	}

	for i := s + 1; i < n; i++ {
		if f[i] && b[s] == 1 {
			printf("YES")
			return
		}
	}

	printf("NO")

}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

func main() {
	defer writer.Flush()
	n, s := 0, 0

	scanf("%d %d\n", &n, &s)
	s--
	a := make([]int, n)
	b := make([]int, n)
	f := make([]bool, n)
	for i := 0; i < n; i++ {
		scanf("%d", &a[i])
	}

	for i := 0; i < n; i++ {
		scanf("%d", &b[i])
		if b[i] == 1 && a[i] == 1 {
			f[i] = true
		}
	}

	if a[0] == 0 {
		printf("NO")
		return
	}

	if a[s] == 1 {
		printf("YES")
		return
	}

	for i := s + 1; i < n; i++ {
		if f[i] && b[s] == 1 {
			printf("YES")
			return
		}
	}

	printf("NO")

}


// http://codeforces.com/contest/142/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

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

	return b
}

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

	return b
}

func lost(a, b, c int64) int64 {
	return (a + 1)*(b + 2)*(c + 2) - a*b*c
}

func main () {
	var n int64

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)

	mx := int64(0)
	mn := int64(math.MaxInt64)

	for a := int64(1); a * a * a <= n; a++ {
		if n % a == 0 {
			for b := a; b * b <= n / a; b++ {
				if (n / a) % b == 0 {
					c := n / a / b

					l := lost(a, b, c)
					mx = max(mx, l)
					mn = min(mn, l)

					l = lost(b, a, c)
					mx = max(mx, l)
					mn = min(mn, l)

					l = lost(c, a, b)
					mx = max(mx, l)
					mn = min(mn, l)

				}
			}
		}
	}

	fmt.Println(mn, mx)
}

// http://codeforces.com/contest/142/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

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

	return b
}

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

	return b
}

func lost(a, b, c int64) int64 {
	return (a + 1)*(b + 2)*(c + 2) - a*b*c
}

func main () {
	var n int64

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)

	mx := int64(0)
	mn := int64(math.MaxInt64)

	for a := int64(1); a * a * a <= n; a++ {
		if n % a == 0 {
			for b := a; b * b <= n / a; b++ {
				if n / a % b == 0 {
					c := n / a / b

					l := lost(a, b, c)
					mx = max(mx, l)
					mn = min(mn, l)

					l = lost(b, a, c)
					mx = max(mx, l)
					mn = min(mn, l)

					l = lost(c, a, b)
					mx = max(mx, l)
					mn = min(mn, l)

				}
			}
		}
	}

	fmt.Println(mn, mx)
}

// http://codeforces.com/contest/142/problem/A
package main

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

// (c) Dmitriy Blokhin (sv.dblokhin@gmail.com)

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

	return b
}

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

	return b
}

func lost(a, b, c int64) int64 {
	return (a + 1)*(b + 2)*(c + 2) - a*b*c
}

func main () {
	var n int64

	//f, _ := os.Open("input.txt")
	//input := bufio.NewReader(f)
	input := bufio.NewReader(os.Stdin)

	fmt.Fscanln(input, &n)

	mx := int64(0)
	mn := int64(math.MaxInt64)

	for a := int64(1); a * a * a < n; a++ {
		if n % a == 0 {
			for b := a; b * b <= n / a; b++ {
				if (n / a) % b == 0 {
					c := n / a / b

					l := lost(a, b, c)
					mx = max(mx, l)
					mn = min(mn, l)

					l = lost(b, a, c)
					mx = max(mx, l)
					mn = min(mn, l)

					l = lost(c, a, b)
					mx = max(mx, l)
					mn = min(mn, l)

				}
			}
		}
	}

	fmt.Println(mn, mx)
}


package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextLongArray(N)

	F := make(map[int64]int)
	for _, v := range A {
		F[v]++
	}

	arr := make([]int64, N)
	good := false
	for _, v := range A {
		if attempt(F, arr, v, 0) {
			good = true
			break
		}
	}
	if !good {
		fmt.Println("WTF THIS FAILED?")
	}
	for i := 1; i < N; i++ {
		if arr[i] != arr[i - 1] * 2 && arr[i - 1] != arr[i] * 3 {
			fmt.Printf("WTF: %d, [%d %d]\n", i, arr[i - 1], arr[i])
		}
	}
	for _, v := range arr {
		io.Printf("%d ", v)
	}
	io.Println()
}

func attempt(F map[int64]int, sofar []int64, what int64, idx int) bool {
	if idx >= len(sofar) {
		return true
	}

	if F[what] <= 0 {
		return false
	}

	sofar[idx] = what
	F[what]--

	if attempt(F, sofar, what << 1, idx + 1) {
		return true
	}

	if what % 3 == 0 && attempt(F, sofar, what / 3, idx + 1) {
		return true
	}

	F[what]++
	return false
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextLongArray(N)

	F := make(map[int64]int)
	for _, v := range A {
		F[v]++
	}

	arr := make([]int64, N)
	for _, v := range A {
		if attempt(F, arr, v, 0) {
			break
		}
	}
	for _, v := range arr {
		io.Printf("%d ", v)
	}
	io.Println()
}

func attempt(F map[int64]int, sofar []int64, what int64, idx int) bool {
	if idx >= len(sofar) {
		return true
	}

	if F[what] <= 0 {
		return false
	}

	sofar[idx] = what
	F[what]--

	if attempt(F, sofar, what << 1, idx + 1) {
		return true
	}

	if what % 3 == 0 && attempt(F, sofar, what / 3, idx + 1) {
		return true
	}

	F[what]++
	return false
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

var reader *bufio.Reader = bufio.NewReader(os.Stdin)
var writer *bufio.Writer = bufio.NewWriter(os.Stdout)

func printf(f string, a ...interface{}) { fmt.Fprintf(writer, f, a...) }
func scanf(f string, a ...interface{})  { fmt.Fscanf(reader, f, a...) }

type delimeters struct {
	twos   int
	threes int
}

type sortDelimeters []delimeters

func (arr sortDelimeters) Len() int {
	return len(arr)
}

func (arr sortDelimeters) Swap(i, j int) {
	arr[i], arr[j] = arr[j], arr[i]
}

func (arr sortDelimeters) Less(i, j int) bool {
	return arr[i].twos <= arr[j].twos && arr[i].threes >= arr[j].threes
}

func getDelimeters(n uint64) delimeters {
	r := delimeters{0, 0}
	for {
		if n%2 == 0 {
			r.twos++
			n /= 2
		} else if n%3 == 0 {
			r.threes++
			n /= 3
		} else {
			break
		}
	}
	return r
}

func insert(num uint64, i int, array *[]uint64) {
	*array = append(*array, 0)
	buffer := (*array)[i]
	(*array)[i] = num
	// printf("buffer: %v, a[i]: %v\n", buffer, (*array)[i])
	for f := i + 1; f < len((*array)); f++ {
		printf("f == %v\n", f)
		buffer, (*array)[f] = (*array)[f], buffer
	}
	// printf("array: %v\n", *array)
}

func main() {
	//STDOUT MUST BE FLUSHED MANUALLY
	defer writer.Flush()

	var n int
	scanf("%d\n", &n)
	arr := make([]uint64, n)
	sortedArr := make([]delimeters, n)
	answerArr := make([]uint64, n)
	delCounter := make(map[delimeters]uint64)

	for i := range arr {
		scanf("%d", &arr[i])
		del := getDelimeters(arr[i])
		delCounter[del] = arr[i]
		sortedArr[i] = del
	}

	// printf("sortedArr: %v\n", sortedArr)

	sort.Sort(sortDelimeters(sortedArr))

	// printf("sortedArr: %v\n", sortedArr)

	for i, val := range sortedArr {
		answerArr[i] = delCounter[val]
	}

	for _, val := range answerArr {
		printf("%v ", val)
	}

	printf("\n")

	// printf("%v\n", answerArr)
	// printf("%v\n", delCounter)

	// var a, b int
	// scanf("%d %d", &a, &b)
	// printf("%d\n", a+b)
}

package main

import (
	. "fmt"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func main() {
	g,n,v := [64][]int64{},0,int64(0)
	for Scan(&n); n > 0; n-- {
		Scan(&v)
		c := 0
		for w := v; w&1 == 0; w >>= 1 {
			c++
		}
		g[c] = append(g[c], v)
	}
	for _, a := range g {
		sort.Slice(a, func(i, j int) bool { return a[i] > a[j] })
		for _, v := range a {
			Print(v, " ")
		}
	}
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextLongArray(N)

	F := make(map[int64]int)
	for _, v := range A {
		F[v]++
	}

	arr := make([]int64, N)
	for _, v := range A {
		if attempt(F, arr, v, 0) {
			break
		}
	}
	for i := 1; i < N; i++ {
		if arr[i] != arr[i - 1] * 2 && arr[i - 1] != arr[i] * 3 {
			fmt.Printf("WTF: %d, [%d %d]\n", i, arr[i - 1], arr[i])
		}
	}
	for _, v := range arr {
		io.Printf("%d ", v)
	}
	io.Println()
}

func attempt(F map[int64]int, sofar []int64, what int64, idx int) bool {
	if idx >= len(sofar) {
		return true
	}

	sofar[idx] = what

	mul2 := what << 1
	if F[mul2] > 0 {
		F[mul2]--
		if attempt(F, sofar, mul2, idx + 1) {
			return true
		}
		F[mul2]++
	}

	div3 := what / 3
	if what % 3 == 0 && F[div3] > 0 {
		F[div3]--
		if attempt(F, sofar, div3, idx + 1) {
			return true
		}
		F[div3]++
	}

	return false
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}

package main

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

func Init() {
}

func Solve(io *FastIO) {
	N := io.NextInt()
	A := io.NextLongArray(N)

	F := make(map[int64]int)
	for _, v := range A {
		F[v]++
	}

	arr := make([]int64, N)
	for _, v := range A {
		if attempt(F, arr, v, 0) {
			break
		}
	}
	for _, v := range arr {
		io.Printf("%d ", v)
	}
	io.Println()
}

func attempt(F map[int64]int, sofar []int64, what int64, idx int) bool {
	if idx >= len(sofar) {
		return true
	}

	sofar[idx] = what

	mul2 := what << 1
	if F[mul2] > 0 {
		F[mul2]--
		if attempt(F, sofar, mul2, idx + 1) {
			return true
		}
		F[mul2]++
	}

	div3 := what / 3
	if what % 3 == 0 && F[div3] > 0 {
		F[div3]--
		if attempt(F, sofar, div3, idx + 1) {
			return true
		}
		F[div3]++
	}

	return false
}

type FastIO struct {
	reader *bufio.Reader
	writer *bufio.Writer
}

func (io *FastIO) NextChar() byte {
	c, _ := io.reader.ReadByte()
	return c
}

func (io *FastIO) NextInt() int {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := 1
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := 0
	for !IsSpaceChar(c) {
		res = (res * 10) + int(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextLong() int64 {
	c := io.NextChar()
	for IsSpaceChar(c) {
		c = io.NextChar()
	}
	sgn := int64(1)
	if c == '-' {
		sgn = -1
		c = io.NextChar()
	}
	res := int64(0)
	for !IsSpaceChar(c) {
		res = (res * 10) + int64(c - '0')
		c = io.NextChar()
	}
	return sgn * res
}

func (io *FastIO) NextIntArray(size int) []int {
	return io.NextIntArrayOffset(size, 0)
}

func (io *FastIO) NextIntArrayOffset(size, offset int) []int {
	arr := make([]int, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextInt()
	}
	return arr
}

func (io *FastIO) NextLongArray(size int) []int64 {
	return io.NextLongArrayOffset(size, 0)
}

func (io *FastIO) NextLongArrayOffset(size, offset int) []int64 {
	arr := make([]int64, size + offset)
	for i := 0; i < size; i++ {
		arr[i + offset] = io.NextLong()
	}
	return arr
}

func (io *FastIO) NextString() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsSpaceChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) NextLine() string {
	c := io.NextChar()
	for (IsSpaceChar(c)) {
		c = io.NextChar()
	}
	var sb bytes.Buffer
	for !IsLineBreakChar(c) {
		sb.WriteByte(c)
		c = io.NextChar()
	}
	return sb.String()
}

func (io *FastIO) Println(args ...interface{}) {
	io.writer.WriteString(fmt.Sprintln(args...))
}

func (io *FastIO) Printf(format string, args ...interface{}) {
	io.writer.WriteString(fmt.Sprintf(format, args...))
}

func (io *FastIO) FlushOutput() {
	io.writer.Flush()
}

func IsSpaceChar(c byte) bool {
	switch c {
	case 0, '\t', '\n', '\r', ' ':
		return true
	default:
		return false
	}
}

func IsLineBreakChar(c byte) bool {
	switch c {
		case 0, '\n', '\r':
			return true
		default:
			return false
	}
}

func main() {
	io := FastIO{reader: bufio.NewReader(os.Stdin), writer: bufio.NewWriter(os.Stdout)}
	Init()
	Solve(&io)
	io.FlushOutput()
}


package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	qs := make([][4]int, q)
	blockSize := int(math.Round(math.Sqrt(float64(n))))
	for i := range qs {
		var ql, qr int
		Fscan(in, &ql, &qr)
		qs[i] = [4]int{ql / blockSize, qr + 1, ql, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		for k := range qs[i] {
			if qs[i][k] != qs[j][k] {
				return qs[i][k] < qs[j][k]
			}
		}
		return true
	})

	cnt := make([]int, n+1)
	nowCnt := 0
	update := func(val, delta int) {
		if val > n {
			return
		}
		if cnt[val] == val {
			nowCnt--
		}
		cnt[val] += delta
		if cnt[val] == val {
			nowCnt++
		}
	}
	ans := make([]int, q)
	l, r := 1, 1
	for _, tuple := range qs {
		ql, qr, i := tuple[2], tuple[1], tuple[3]
		for ; l < ql; l++ {
			update(a[l], -1)
		}
		for ; r < qr; r++ {
			update(a[r], 1)
		}
		for l > ql {
			l--
			update(a[l], 1)
		}
		for r > qr {
			r--
			update(a[r], -1)
		}
		ans[i] = nowCnt
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	qs := make([][4]int, q)
	blockSize := int(math.Round(math.Sqrt(float64(q))))
	for i := range qs {
		var ql, qr int
		Fscan(in, &ql, &qr)
		qs[i] = [4]int{ql / blockSize, qr + 1, ql, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		for k := range qs[i] {
			if qs[i][k] != qs[j][k] {
				return qs[i][k] < qs[j][k]
			}
		}
		return true
	})

	cnt := make([]int, n+1)
	nowCnt := 0
	update := func(val, delta int) {
		if val > n {
			return
		}
		if cnt[val] == val {
			nowCnt--
		}
		cnt[val] += delta
		if cnt[val] == val {
			nowCnt++
		}
	}
	ans := make([]int, q)
	l, r := 1, 1
	for _, tuple := range qs {
		ql, qr, i := tuple[2], tuple[1], tuple[3]
		for ; l < ql; l++ {
			update(a[l], -1)
		}
		for ; r < qr; r++ {
			update(a[r], 1)
		}
		for l > ql {
			l--
			update(a[l], 1)
		}
		for r > qr {
			r--
			update(a[r], -1)
		}
		ans[i] = nowCnt
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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

package main

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

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

	var n, q int
	Fscan(in, &n, &q)
	a := make([]int, n+1)
	for i := 1; i <= n; i++ {
		Fscan(in, &a[i])
	}
	qs := make([][4]int, q)
	blockSize := int(math.Round(math.Sqrt(float64(q))))
	for i := range qs {
		var ql, qr int
		Fscan(in, &ql, &qr)
		qs[i] = [4]int{ql / blockSize, qr, ql, i}
	}
	sort.Slice(qs, func(i, j int) bool {
		for k := range qs[i] {
			if qs[i][k] != qs[j][k] {
				return qs[i][k] < qs[j][k]
			}
		}
		return true
	})

	cnt := make([]int, n+1)
	nowCnt := 0
	update := func(val, delta int) {
		if val > n {
			return
		}
		if cnt[val] == val {
			nowCnt--
		}
		cnt[val] += delta
		if cnt[val] == val {
			nowCnt++
		}
	}
	ans := make([]int, q)
	l, r := 1, 1
	for _, tuple := range qs {
		ql, qr, i := tuple[2], tuple[1], tuple[3]
		for ; l < ql; l++ {
			update(a[l], -1)
		}
		for ; r <= qr; r++ {
			update(a[r], 1)
		}
		for l > ql {
			l--
			update(a[l], 1)
		}
		for r > qr+1 {
			r--
			update(a[r], -1)
		}
		ans[i] = nowCnt
	}
	for _, v := range ans {
		Fprintln(out, v)
	}
}

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


package main

import."fmt"
import"bufio"
import"os"
import."sort"

func main(){
	var t int
	Scan(&t)
	in:=bufio.NewReader(os.Stdin)
	out:=bufio.NewWriter(os.Stdout)
	defer out.Flush()
	for i:=0;i<t;i++{
		var n int
		Fscan(in,&n)
		if n==4{
			var num1,num2,num3,num5 int
			Fscan(in,&num1,&num2,&num3,&num5)
			Fprintln(out,num1,num2,num3,num5)
			continue
		}
		m:=map[int]int{}
		for j:=0;j<n;j++{
			var num int
			Fscan(in,&num)
			_,ok:=m[num]
			if ok{
				m[num]++
			}else{
				m[num]=1
			}
		}
		a:=[]int{}
		isFound:=false
		for k,v:=range m{
			if v>=4{
				Fprintln(out,k,k,k,k)
				isFound=true
				break
			}
			if v>=2{
				a=append(a,k)
			}
		}
		if isFound{
			continue
		}
		Ints(a)
		len:=len(a)-1
		pos:=-1
		min:=100000.0
		for j:=0;j<len;j++{
			p:=(a[j]+a[j+1])<<1
			s:=a[j]*a[j+1]
			res:=float64(p*p)/float64(s)
			if min>res{
				min=res
				pos=j
			}
		}
		Fprintln(out,a[pos],a[pos],a[pos+1],a[pos+1])
	}
}

package main

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

var scanner * bufio.Scanner

func next_int()(result int64){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  res, err := strconv.ParseInt(scanner.Text(), 10, 32)
  if err != nil {
    panic(err)
  }
  return res
}

func next_str()(result string){
  if !scanner.Scan() {
    panic("Unable to read next token. Input has no data remain")
  }
  return scanner.Text()
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  T := int(next_int())
  for test := 1 ; test <= T; test++ {
    n := int(next_int())
    sticks := make([] int, n, n)
    for j := 0; j < n; j++ {
      sticks[j] = int(next_int())
    }

    sort.Slice(sticks, func(i, j int) bool { return sticks[i] < sticks[j] })
    var min_ratio float64 = 1e+30
    var side_a, side_b int = 0, 0
    for j := 0; j + 1 < n; {
      if sticks[j] == sticks[j + 1] {
        var k int = j + 2
        for k < n && sticks[k] == sticks[j] {
            k++;
        }
        if (k - j >= 4) {
          min_ratio = 16
          side_a = sticks[j]
          side_b = sticks[j]
          break
        }

        for (k+1) < n && sticks[k] != sticks[k+1] {
          k++;
        }

        if ((k+1 < n) && (sticks[k] == sticks[k+1])) {
          p := float64(sticks[j]*2 + sticks[k]*2)
          ratio := (p * p) / float64(sticks[j]*sticks[k])
          if ratio < min_ratio {
            min_ratio = ratio
            side_a = sticks[j]
            side_b = sticks[k]
          }
        }
        j = k
      } else {
        j++;
      }
    }
    fmt.Printf("%v %v %v %v\n", side_a, side_a, side_b, side_b)
  }
}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})

		x, y, prev, distP2, distS := int64(0), int64(0), int64(0), int64(math.MaxInt32), int64(1)

		for i := 0; i < n - 1; i++ {
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					p := 2 * arr[i] + 2 * prev
					s := arr[i] * prev
					if distP2 * s > p * p * distS {
						distP2 = p * p
						distS = s
						x, y = prev, arr[i]
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

var scanner * bufio.Scanner

func next_int()(result int64){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  res, err := strconv.ParseInt(scanner.Text(), 10, 32)
  if err != nil {
    panic(err)
  }
  return res
}

func next_str()(result string){
  if !scanner.Scan() {
    panic("Unable to read next token. Input has no data remain")
  }
  return scanner.Text()
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  T := int(next_int())
  for test := 1 ; test <= T; test++ {
    n := int(next_int())
    sticks := make([] int, n, n)
    for j := 0; j < n; j++ {
      sticks[j] = int(next_int())
    }

    if (n >= 40000) {
      cnt := make([]int, 10001, 10001)
      for j := 0; j < n; j++ {
        len := sticks[j];
        cnt[len]++;
        if (cnt[len] == 4) {
          fmt.Printf("%v %v %v %v\n", len, len, len, len);
          break;
        }
      }
      continue
    }

    sort.Slice(sticks, func(i, j int) bool { return sticks[i] < sticks[j] })
    var min_ratio float64 = 1e+30
    var side_a, side_b int = 0, 0
    for j := 0; j + 1 < n; {
      if sticks[j] == sticks[j + 1] {
        var k int = j + 2
        for k < n && sticks[k] == sticks[j] {
            k++;
        }
        if (k - j >= 4) {
          min_ratio = 16
          side_a = sticks[j]
          side_b = sticks[j]
          break
        }

        for (k+1) < n && sticks[k] != sticks[k+1] {
          k++;
        }

        if ((k+1 < n) && (sticks[k] == sticks[k+1])) {
          p := float64(sticks[j]*2 + sticks[k]*2)
          ratio := (p * p) / float64(sticks[j]*sticks[k])
          if ratio < min_ratio {
            min_ratio = ratio
            side_a = sticks[j]
            side_b = sticks[k]
          }
        }
        j = k
      } else {
        j++;
      }
    }
    fmt.Printf("%v %v %v %v\n", side_a, side_a, side_b, side_b)
  }
}

package main

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

var scanner * bufio.Scanner

func next_int()(result int64){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  res, err := strconv.ParseInt(scanner.Text(), 10, 32)
  if err != nil {
    panic(err)
  }
  return res
}

func next_str()(result string){
  if !scanner.Scan() {
    panic("Unable to read next token. Input has no data remain")
  }
  return scanner.Text()
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  sticks := make([] int, 1000000, 1000000)
  T := int(next_int())
  for test := 1 ; test <= T; test++ {
    sticks = sticks[0:0]
    n := int(next_int())
    for j := 0; j < n; j++ {
      sticks = append(sticks, int(next_int()))
    }

    /*if (n >= 40000) {
      cnt := make([]int, 10001, 10001)
      for j := 0; j < n; j++ {
        len := sticks[j];
        cnt[len]++;
        if (cnt[len] == 4) {
          fmt.Printf("%v %v %v %v\n", len, len, len, len);
          break;
        }
      }
      continue
    }*/

    sort.Slice(sticks, func(i, j int) bool { return sticks[i] < sticks[j] })
    var min_ratio float64 = 1e+30
    var side_a, side_b int = 0, 0
    for j := 0; j + 1 < n; {
      if sticks[j] == sticks[j + 1] {
        var k int = j + 2
        for k < n && sticks[k] == sticks[j] {
            k++;
        }
        if (k - j >= 4) {
          min_ratio = 16
          side_a = sticks[j]
          side_b = sticks[j]
          break
        }

        for (k+1) < n && sticks[k] != sticks[k+1] {
          k++;
        }

        if ((k+1 < n) && (sticks[k] == sticks[k+1])) {
          p := float64(sticks[j]*2 + sticks[k]*2)
          ratio := (p * p) / float64(sticks[j]*sticks[k])
          if ratio < min_ratio {
            min_ratio = ratio
            side_a = sticks[j]
            side_b = sticks[k]
          }
        }
        j = k
      } else {
        j++;
      }
    }
    fmt.Printf("%v %v %v %v\n", side_a, side_a, side_b, side_b)
  }
}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

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

		sort.Ints(arr)

		x, y, prev, dist := 0, 0, 0, int(1e4 + 1)

		for i := 0; i < n - 1; i++ {
			if i < n - 3 && arr[i] == arr[i + 1] && arr[i + 1] == arr[i + 2] && arr[i + 2] == arr[i + 3] {
				x, y = arr[i], arr[i]
				dist = 0
				continue
			}
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					if dist >= arr[i] - prev {
						dist = arr[i] - prev
						x, y = arr[i], prev
					}
				}
				prev = arr[i]
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Slice(arr, func(i, j int) bool {
			return arr[i] > arr[j]
		})

		x, y, prev, dist := int64(0), int64(0), int64(0), math.MaxFloat64

		for i := 0; i < n - 1; i++ {
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					p := 2 * arr[i] + 2 * prev
					s := arr[i] * prev
					distTmp := float64(p * p) / float64(s)
					if !(math.Abs(dist - distTmp) <= 1e-6) && dist > distTmp {
						dist = distTmp
						x, y = prev, arr[i]
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})

		x, y, prev, dist := int64(0), int64(0), int64(0), math.MaxFloat64

		for i := 0; i < n - 1; i++ {
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					p := 2 * arr[i] + 2 * prev
					s := arr[i] * prev
					distTmp := float64(p * p) / float64(s)
					if !(math.Abs(dist - distTmp) <= 1e-5) && dist > distTmp {
						dist = distTmp
						x, y = prev, arr[i]
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

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

		sort.Ints(arr)

		x, y, prev, dist := 0, 0, 0, int(1e4 + 1)

		for i := 0; i < n - 1; i++ {
			if i < n - 3 && arr[i] == arr[i + 1] && arr[i + 1] == arr[i + 2] && arr[i + 2] == arr[i + 3] {
				x, y = arr[i], arr[i]
				dist = 0
				i += 3
				continue
			}
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					if dist >= arr[i] - prev {
						dist = arr[i] - prev
						x, y = arr[i], prev
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

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

		sort.Ints(arr)

		x, y, prev, dist := 0, 0, 0, int(1e4 + 1)

		for i := 0; i < n - 1; i++ {
			if i < n - 3 && arr[i] == arr[i + 1] && arr[i] == arr[i + 2] && arr[i] == arr[i + 3] {
				x, y = arr[i], arr[i]
				dist = 0
				break
			}
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					if dist >= arr[i] - prev {
						dist = arr[i] - prev
						x, y = arr[i], prev
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

		arr := make([]int64, n)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &arr[i])
		}

		sort.Slice(arr, func(i, j int) bool {
			return arr[i] < arr[j]
		})

		x, y, prev, dist := int64(0), int64(0), int64(0), math.MaxFloat64

		for i := 0; i < n - 1; i++ {
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					p := 2 * arr[i] + 2 * prev
					s := arr[i] * prev
					distTmp := float64(p * p) / float64(s)
					if !(math.Abs(dist - distTmp) <= 1e-6) && dist > distTmp {
						dist = distTmp
						x, y = prev, arr[i]
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

func main()  {

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()

	var T int
	fmt.Fscan(in, &T)

	for t := 0; t < T; t++ {

		var n int
		fmt.Fscan(in, &n)

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

		sort.Ints(arr)

		x, y, prev, dist := 0, 0, 0, math.MaxFloat64

		for i := 0; i < n - 1; i++ {
			if arr[i] == arr[i + 1] {
				if prev != 0 {
					p := 2 * int64(arr[i]) + 2 * int64(prev)
					s := int64(arr[i]) * int64(prev)
					distTmp := float64(p * p) / float64(s)
					if !(math.Abs(dist - distTmp) <= 1e-6) && dist > distTmp {
						dist = distTmp
						x, y = prev, arr[i]
					}
				}
				prev = arr[i]
				i++
			}
		}

		fmt.Fprintln(out, x, x, y, y)

	}

}

package main

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

var scanner * bufio.Scanner

func next_int()(result int64){
  if !scanner.Scan() {
    panic("Unable to read next integer. Input has no data remain")
  }
  res, err := strconv.ParseInt(scanner.Text(), 10, 32)
  if err != nil {
    panic(err)
  }
  return res
}

func next_str()(result string){
  if !scanner.Scan() {
    panic("Unable to read next token. Input has no data remain")
  }
  return scanner.Text()
}

func main() {

  scanner = bufio.NewScanner(os.Stdin)
  scanner.Split(bufio.ScanWords)

  T := int(next_int())
  for test := 1 ; test <= T; test++ {
    n := int(next_int())
    sticks := make([] int, n, n)
    for j := 0; j < n; j++ {
      sticks[j] = int(next_int())
    }

    if (n >= 40000) {
      cnt := make([]int, 10001, 10001)
      for j := 0; j < n; j++ {
        len := sticks[j];
        cnt[len]++;
        if (cnt[len] == 4) {
          fmt.Printf("%v %v %v %v\n", len, len, len, len);
          break;
        }
      }
      continue
    }

    sort.Slice(sticks, func(i, j int) bool { return sticks[i] < sticks[j] })
    var min_ratio float64 = 1e+30
    var side_a, side_b int = 0, 0
    for j := 0; j + 1 < n; {
      if sticks[j] == sticks[j + 1] {
        var k int = j + 2
        for k < n && sticks[k] == sticks[j] {
          k++;
        }
        if (k - j >= 4) {
          min_ratio = 16
          side_a = sticks[j]
          side_b = sticks[j]
          break
        }
        if ((k+1 < n) && (sticks[k] == sticks[k+1])) {
          p := float64(sticks[j]*2 + sticks[k]*2)
          ratio := (p * p) / float64(sticks[j]*sticks[k])
          if ratio < min_ratio {
            min_ratio = ratio
            side_a = sticks[j]
            side_b = sticks[k]
          }
        }
        j = k
      } else {
        j++;
      }
    }
    fmt.Printf("%v %v %v %v\n", side_a, side_a, side_b, side_b)
  }
}


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]))
		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"
	"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)
	}
}