Polycarp likes to play with numbers. He takes some integer number $$$x$$$, writes it down on the board, and then performs with it $$$n - 1$$$ operations of the two kinds:   divide the number $$$x$$$ by $$$3$$$ ($$$x$$$ must be divisible by $$$3$$$);  multiply the number $$$x$$$ by $$$2$$$. After each operation, Polycarp writes down the result on the board and replaces $$$x$$$ by the result. So there will be $$$n$$$ numbers on the board after all.You are given a sequence of length $$$n$$$ — the numbers that Polycarp wrote down. This sequence is given in arbitrary order, i.e. the order of the sequence can mismatch the order of the numbers written on the board.Your problem is to rearrange (reorder) elements of this sequence in such a way that it can match possible Polycarp's game in the order of the numbers written on the board. I.e. each next number will be exactly two times of the previous number or exactly one third of previous number.It is guaranteed that the answer exists.

The first line of the input contatins an integer number $$$n$$$ ($$$2 \le n \le 100$$$) — the number of the elements in the sequence. The second line of the input contains $$$n$$$ integer numbers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 3 \cdot 10^{18}$$$) — rearranged (reordered) sequence that Polycarp can wrote down on the board.

Print $$$n$$$ integer numbers — rearranged (reordered) input sequence that can be the sequence that Polycarp could write down on the board. It is guaranteed that the answer exists.

NoteIn the first example the given sequence can be rearranged in the following way: $$$[9, 3, 6, 12, 4, 8]$$$. It can match possible Polycarp's game which started with $$$x = 9$$$.

object Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = map(N)(_ => nl())

    def factorize(a: Long) = {
      var x = a

      var i = 0
      while(x % 2 == 0) {
        i += 1
        x /= 2
      }

      var j = 0
      while(x % 3 == 0) {
        j += 1
        x /= 3
      }

      (i, j, x)
    }

    def toNum(p: (Int, Int, Long)) = {
      pow(2, p._1) * pow(3, p._2) * p._3
    }

    val p = (A map factorize).sortBy(a => a._1 + a._2 * -1)
    val n = p map toNum
    out.println(n.mkString(" "))
  }

  def pow(x: Long, n: Long): Long = {
    n match {
      case 0 => 1
      case _ =>
        val r = pow(x * x, n / 2)
        if (n % 2 == 1) r * x else r
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

object D977 {

  import IO._
  import collection.{mutable => cu}
  import scala.collection.mutable.ArrayBuffer

  def main(args: Array[String]): Unit = {
    val n = readInt
    val arr = readLongs(n).toSet
    val res = ArrayBuffer.empty[Long]
    arr.exists { _start =>
      var start = _start
      res.clear()
      res.append(start)
      while (res.length != n && ((start % 3 == 0 && arr.contains(start / 3)) || (start <= (Long.MaxValue >> 1) && arr
               .contains(start * 2)))) {
        if (start % 3 == 0 && arr.contains(start / 3)) {
          res.append(start / 3)
          start /= 3
        } else {
          res.append(start * 2)
          start *= 2
        }
      }
      res.length == n
    }

    out.println(res.mkString(" "))
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(
      new java.io.InputStreamReader(
        if (System.getProperty("ONLINE_JUDGE") != null) System.in
        else new java.io.FileInputStream("src/input")
      )
    )
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object _977D extends CodeForcesApp {
  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def apply(io: IO): io.type = {
    val nums = io.read[Vector[Long]]
    val counts = nums.groupBy(identity).mapValues(_.size).toMutable

    val Some(first) = nums.find(i => !counts.contains(3*i) && (i%2 == 1 || !counts.contains(i/2)))

    val ans = Vector.iterate(first, nums.length) {i =>
      dec(counts, i)
      if(i%3 == 0 && counts.contains(i/3)) {
        i/3
      } else if (counts.contains(2*i)) {
        2*i
      } else {
        throw new IllegalStateException("Cannot be here!")
      }
    }

    io.writeAll(ans)
  }

  def dec[A](map: mutable.Map[A, Int], key: A) = {
    if (map(key) == 1) map.remove(key) else map(key) = map(key) - 1
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    tokenizers.headOption
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object problemA {
    import java.io.{BufferedReader, FileInputStream, InputStreamReader}
    import scala.collection.mutable.ArrayBuffer
    import scala.collection.mutable
    import scala.util.control.Breaks._
    import scala.collection.JavaConverters._

    val source = System.in
    implicit val reader = new BufferedReader(new InputStreamReader(source))

    def read()(implicit reader: BufferedReader): String = reader.readLine().split(" ")(0)
    def readArray()(implicit reader: BufferedReader): Array[String] = reader.readLine().split(" ")
    def readString()(implicit reader: BufferedReader): String = reader.readLine()

    def main(args: Array[String]): Unit = {
        val n = read().toInt
        val a = readArray().map(_.toLong)

        val ch = Array.fill[Boolean](n)(true)
        val f = new Array[Long](n)
        var c = 0

        def solve(k: Int): Unit = {
            if (c == n) {
                f.foreach(p => print(s"$p "))
                return
            }

            for (i <- 0 until n if ch(i)) {
                if (a(k) % 3 == 0 && a(k) / 3 == a(i)) {
                    f(c) = a(i)
                    c += 1
                    ch(i) = false
                    solve(i)
                    ch(i) = true
                    c -= 1

                } else if (a(k) * 2 == a(i)) {
                    f(c) = a(i)
                    c += 1
                    ch(i) = false
                    solve(i)
                    ch(i) = true
                    c -= 1
                }
            }
        }

        for (i <- 0 until n) {
            f(c) = a(i)
            c += 1
            ch(i) = false
            solve(i)
            ch(i) = true
            c -= 1
        }
    }
}


The Little Elephant loves playing with arrays. He has array a, consisting of n positive integers, indexed from 1 to n. Let's denote the number with index i as ai. Additionally the Little Elephant has m queries to the array, each query is characterised by a pair of integers lj and rj (1 ≤ lj ≤ rj ≤ n). For each query lj, rj the Little Elephant has to count, how many numbers x exist, such that number x occurs exactly x times among numbers alj, alj + 1, ..., arj.Help the Little Elephant to count the answers to all queries.

The first line contains two space-separated integers n and m (1 ≤ n, m ≤ 105) — the size of array a and the number of queries to it. The next line contains n space-separated positive integers a1, a2, ..., an (1 ≤ ai ≤ 109). Next m lines contain descriptions of queries, one per line. The j-th of these lines contains the description of the j-th query as two space-separated integers lj and rj (1 ≤ lj ≤ rj ≤ n).

In m lines print m integers — the answers to the queries. The j-th line should contain the answer to the j-th query.

object Main {
    def main(args: Array[String]): Unit = {
        val Array(n, m) = readLine().split(" ").map(_.toInt).take(2)
        val a = readLine().split(" ").map(_.toInt).take(n)

        val count = new Array[Int](n + 1)
        for(i <- a if (i <= n)) count(i) += 1
        val set = new Array[Int](500)

        var size = 0
        for(i <- 1 to n if (count(i) >= i)) {
            set(size) = i
            size += 1
        }

        val l = new Array[Int](m)
        val r = new Array[Int](m)
        val ret = new Array[Int](m)
        for(i <- 0 until m) {
            val Array(left, right) = readLine().split(" ").map(x => x.toInt - 1)
            l(i) = left
            r(i) = right
        }

        for(i <- 0 until size) {
            val sum = new Array[Int](n)
            for(j <- 0 until n) {
                if (j > 0) sum(j) = sum(j - 1)
                if (set(i) == a(j)) sum(j) += 1
            }
            for(j <- 0 until m) {
                var s = sum(r(j))
                if (l(j) > 0) s -= sum(l(j) - 1)
                if (s == set(i)) ret(j) += 1
            }
        }
        println(ret.mkString("\n"))
    }
}


You have $$$n$$$ sticks of the given lengths.Your task is to choose exactly four of them in such a way that they can form a rectangle. No sticks can be cut to pieces, each side of the rectangle must be formed by a single stick. No stick can be chosen multiple times. It is guaranteed that it is always possible to choose such sticks.Let $$$S$$$ be the area of the rectangle and $$$P$$$ be the perimeter of the rectangle. The chosen rectangle should have the value $$$\frac{P^2}{S}$$$ minimal possible. The value is taken without any rounding.If there are multiple answers, print any of them.Each testcase contains several lists of sticks, for each of them you are required to solve the problem separately.

The first line contains a single integer $$$T$$$ ($$$T \ge 1$$$) — the number of lists of sticks in the testcase. Then $$$2T$$$ lines follow — lines $$$(2i - 1)$$$ and $$$2i$$$ of them describe the $$$i$$$-th list. The first line of the pair contains a single integer $$$n$$$ ($$$4 \le n \le 10^6$$$) — the number of sticks in the $$$i$$$-th list. The second line of the pair contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_j \le 10^4$$$) — lengths of the sticks in the $$$i$$$-th list. It is guaranteed that for each list there exists a way to choose four sticks so that they form a rectangle. The total number of sticks in all $$$T$$$ lists doesn't exceed $$$10^6$$$ in each testcase.

Print $$$T$$$ lines. The $$$i$$$-th line should contain the answer to the $$$i$$$-th list of the input. That is the lengths of the four sticks you choose from the $$$i$$$-th list, so that they form a rectangle and the value $$$\frac{P^2}{S}$$$ of this rectangle is minimal possible. You can print these four lengths in arbitrary order. If there are multiple answers, print any of them.

NoteThere is only one way to choose four sticks in the first list, they form a rectangle with sides $$$2$$$ and $$$7$$$, its area is $$$2 \cdot 7 = 14$$$, perimeter is $$$2(2 + 7) = 18$$$. $$$\frac{18^2}{14} \approx 23.143$$$.The second list contains subsets of four sticks that can form rectangles with sides $$$(1, 2)$$$, $$$(2, 8)$$$ and $$$(1, 8)$$$. Their values are $$$\frac{6^2}{2} = 18$$$, $$$\frac{20^2}{16} = 25$$$ and $$$\frac{18^2}{8} = 40.5$$$, respectively. The minimal one of them is the rectangle $$$(1, 2)$$$.You can choose any four of the $$$5$$$ given sticks from the third list, they will form a square with side $$$5$$$, which is still a rectangle with sides $$$(5, 5)$$$.

import java.util

import scala.collection.mutable

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(t) = readInts(1)
  val res = new StringBuilder
  val counts = Array.fill(10001)(0)

  def getX(a: Int, b: Int): Double = {
    val p = 2d * (a + b)
    val s = a * b
    p * p / s
  }

  for (_ <- 1 to t) {
    val Array(n) = readInts(1)
    val as = readInts(n)

    var i = 0
    while (i < n) {
      counts(as(i)) = 0
      i += 1
    }

    i = 0
    val bsBuilder = new mutable.ArrayBuilder.ofInt
    while (i < n) {
      counts(as(i)) += 1
      if (counts(as(i)) == 2) bsBuilder += as(i)
      i += 1
    }
    val bs = bsBuilder.result().sorted

    i = 0
    var bestX = Double.PositiveInfinity
    var bestA = 0
    var bestB = 0
    while (i < bs.length) {
      val a = bs(i)
      if (counts(a) >= 4) {
        val x = getX(a, a)
        if (x < bestX) {
          bestX = x
          bestA = a
          bestB = a
        }
      }
      var j = i + 1
      while (j < bs.length) {
        val b = bs(j)
        val x = getX(a, b)
        if (x < bestX) {
          bestX = x
          bestA = a
          bestB = b
          j = bs.length
        } else {
          j = bs.length
        }
      }
      i += 1
    }
    val aStr = bestA.toString
    val bStr = bestB.toString
    res ++= aStr
    res += ' '
    res ++= aStr
    res += ' '
    res ++= bStr
    res += ' '
    res ++= bStr
    res += '\n'
  }

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  println(res.result)

  Console.flush
}

import java.io._
import java.util.StringTokenizer

import scala.collection.mutable

object C extends App {

  def solve(in: InputReader): Unit = {
    val sticks = new Array[Int](1000000)
    val t = in.nextInt
    val sb = StringBuilder.newBuilder
    val met = mutable.HashMap.empty[Int, Boolean]
    var x: Int = 0
    var y: Int = 0
    var a: Int = 0
    var b: Int = 0
    var n: Int = 0
    var count: Int = 0
    var cur: Int = 0

    for (_ <- 1 to t) {
      n = in.nextInt
      count = 0
      met.clear()
      for (_ <- 0 until n) {
        cur = in.nextInt
        if (met.getOrElse(cur, false)) {
          sticks.update(count, cur)
          count = count + 1
          met.update(cur, false)
        } else {
          met.update(cur, true)
        }
      }
      java.util.Arrays.sort(sticks, 0, count)
      x = sticks(0)
      y = sticks(1)
      for (i <- 0 until count - 1) {
        a = sticks(i)
        b = sticks(i + 1)
        if (x.toDouble / y.toDouble < a.toDouble / b.toDouble) {
          x = a
          y = b
        }
      }
      sb.append(x)
      sb.append(' ')
      sb.append(x)
      sb.append(' ')
      sb.append(y)
      sb.append(' ')
      sb.append(y)
      sb.append('\n')
    }
    print(sb.toString())
  }

  solve(new InputReader(System.in))

  private class InputReader(val in: InputStream) {

    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))
    private var tokenizer: StringTokenizer = _

    def nextInt: Int = {
      next.toInt
    }

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        tokenizer = new StringTokenizer(readLine)
      }
      tokenizer.nextToken
    }

    def readLine: String = {
      try {
        reader.readLine()
      } catch {
        case e: IOException => throw new RuntimeException(e)
      }
    }
  }

}

import java.io._
import java.util.StringTokenizer

import scala.collection.mutable

object C extends App {

  def solve(in: InputReader): Unit = {
    val sticks = new Array[Int](1000000)
    val t = in.nextInt
    val sb = StringBuilder.newBuilder
    val met = mutable.HashMap.empty[Int, Boolean]
    var x: Int = 0
    var y: Int = 0
    var a: Int = 0
    var b: Int = 0
    var n: Int = 0
    var count: Int = 0
    var cur: Int = 0

    for (_ <- 1 to t) {
      n = in.nextInt
      count = 0
      for (_ <- 0 until n) {
        cur = in.nextInt
        if (met.getOrElse(cur, false)) {
          sticks.update(count, cur)
          count = count + 1
          met.update(cur, false)
        } else {
          met.update(cur, true)
        }
      }
      java.util.Arrays.sort(sticks, 0, count)
      x = sticks(0)
      y = sticks(1)
      for (i <- 0 until count - 1) {
        a = sticks(i)
        b = sticks(i + 1)
        if (x.toDouble / y.toDouble < a.toDouble / b.toDouble) {
          x = a
          y = b
        }
      }
      sb.append(x)
      sb.append(' ')
      sb.append(x)
      sb.append(' ')
      sb.append(y)
      sb.append(' ')
      sb.append(y)
      sb.append('\n')
    }
    print(sb.toString())
  }

  solve(new InputReader(System.in))

  private class InputReader(val in: InputStream) {

    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))
    private var tokenizer: StringTokenizer = _

    def nextInt: Int = {
      next.toInt
    }

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        tokenizer = new StringTokenizer(readLine)
      }
      tokenizer.nextToken
    }

    def readLine: String = {
      try {
        reader.readLine()
      } catch {
        case e: IOException => throw new RuntimeException(e)
      }
    }
  }

}

import java.io._
import java.util.StringTokenizer

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object C extends App {

  def solve(in: InputReader): Unit = {
    val met = mutable.HashMap.empty[Int, Int]
    val t = in.nextInt

    for (_ <- 1 to t) {
      met.clear()
      val n = in.nextInt
      val possibleSides = new ArrayBuffer[Int](n)
      for (_ <- 1 to n) {
        val cur = in.nextInt
        val times = met.getOrElse(cur, 0)
        if (times == 3) {
          printf("%d %d %d %d\n", cur, cur, cur, cur)
          return Unit
        }
        if (times % 2 == 1) {
          possibleSides.append(cur)
        }
        met.update(cur, times + 1)
      }
      val sorted = possibleSides.toVector.sorted
      var (x, y) = (sorted.head, sorted(1))
      sorted.sliding(2).foreach { case Seq(a, b) =>
        if (x.toDouble / y.toDouble < a.toDouble / b.toDouble) {
          x = a
          y = b
        }
      }
      printf("%d %d %d %d\n", x, x, y, y)
    }
  }

  solve(new InputReader(System.in))

  private class InputReader(val in: InputStream) {

    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))
    private var tokenizer: StringTokenizer = _

    def nextInt: Int = {
      next.toInt
    }

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        tokenizer = new StringTokenizer(readLine)
      }
      tokenizer.nextToken
    }

    def readLine: String = {
      try {
        reader.readLine()
      } catch {
        case e: IOException => throw new RuntimeException(e)
      }
    }
  }

}


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

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

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

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

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      if (u < k && v < k) {
        ajdBuilders(u) += v
        ajdBuilders(v) += u
      }
    }
    val adjs = ajdBuilders.map(_.result())

    val depths, path = Array.fill(n) {
      -1
    }

    def dfs1(u: Int, depth: Int): Unit = {
      val prev = if (depth == 0) -1 else path(depth - 1)
      depths(u) = depth
      path(depth) = u
      var i = 0
      while (i < adjs(u).length) {
        val v = adjs(u)(i)
        if (depths(v) == -1) {
          dfs1(v, depth + 1)
        } else if (v != prev && depths(v) < depth) {
          if (depth - depths(v) < k) {
            var j = depth
            val resBuilder = new mutable.ArrayBuilder.ofInt
            resBuilder += v + 1
            while (path(j) != v) {
              resBuilder += path(j) + 1
              j -= 1
            }
            val res = resBuilder.result()
            out.println(2)
            out.println(res.length)
            out.println(res.mkString(" "))
            out.flush()
            System.exit(0)
          }
        }
        i += 1
      }
    }

    for (u <- 0 until k) {
      if (depths(u) == -1) {
        dfs1(u, 0)
      }
    }

    val subsetBuilders = Array.fill(2){new mutable.ArrayBuilder.ofInt}
    for (i <- 0 until k) {
      subsetBuilders(depths(i) % 2) += i + 1
    }
    val subsets = subsetBuilders.map(_.result())
    val bigger = subsets.maxBy(_.length)
    out.println(1)
    out.println(bigger.iterator.take((k + 1) / 2).mkString(" "))
    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val depths, path = Array.fill(n) {
      -1
    }

    def dfs1(u: Int, depth: Int): Unit = {
      val prev = if (depth == 0) -1 else path(depth - 1)
      depths(u) = depth
      path(depth) = u
      var i = 0
      while (i < adjs(u).length) {
        val v = adjs(u)(i)
        if (depths(v) == -1) {
          dfs1(v, depth + 1)
        } else if (v != prev && depths(v) < depth) {
          if (depth - depths(v) < k) {
            var j = depth
            val resBuilder = new mutable.ArrayBuilder.ofInt
            resBuilder += v + 1
            while (path(j) != v) {
              resBuilder += path(j) + 1
              j -= 1
            }
            val res = resBuilder.result()
            out.println(2)
            out.println(res.length)
            out.println(res.mkString(" "))
            out.flush()
            System.exit(0)
          }
        }
        i += 1
      }
    }

    dfs1(0, 0)

    val subsetBuilders = Array.fill(2){new mutable.ArrayBuilder.ofInt}
    for (i <- 0 until n) {
      subsetBuilders(depths(i) % 2) += i + 1
    }
    val subsets = subsetBuilders.map(_.result())
    val Array(bigger, _) = subsets.sortBy(- _.length)
    out.println(1)
    out.println(bigger.iterator.take((k + 1) / 2).mkString(" "))
    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {
  import InOut._
  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n){ new mutable.ArrayBuilder.ofInt }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      out.println(2)

      val depths, path = Array.fill(n){ -1 }
      val resBuilder = new mutable.ArrayBuilder.ofInt

      def dfs(u: Int, depth: Int): Unit = {
        //val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs(v, depth + 1)
          } else {
            if (depth > 0 && v != path(depth - 1) && depth - depths(v) < k) {
              var i = depth
              resBuilder += v + 1
              while (i >= 0 && path(i) != v) {
                resBuilder += path(i) + 1
                i -= 1
              }
              val res = resBuilder.result()
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      new Thread(null,
        new Runnable() {
          def run(): Unit = {
            dfs(0, 0)
          }
        },
        "1",
        100000000).start()
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth > k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {
  import InOut._
  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n){ new mutable.ArrayBuilder.ofInt }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      out.println(2)

      val depths, path = Array.fill(n){ -1 }
      val resBuilder = new mutable.ArrayBuilder.ofInt

      def dfs(u: Int, depth: Int): Unit = {
        //val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs(v, depth + 1)
          } else {
            if (depth > 0 && v != path(depth - 1) && depth - depths(v) < k) {
              var j = depth
              resBuilder += v + 1
              while (j >= 0 && path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      dfs(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth >= k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            assert(res(j) > 0)
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth > k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            assert(res(j) > 0)
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth >= k) {
          var j = 0
          val resBuilder = new mutable.ArrayBuilder.ofInt
          while (j < k) {
            resBuilder += path(j) + 1
            j += 2
          }
          val res = resBuilder.result()
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth * 2 > k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth + 2 >= k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            assert(res(j) > 0)
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {
  import InOut._
  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n){ new mutable.ArrayBuilder.ofInt }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      out.println(2)

      val depths, path = Array.fill(n){ -1 }
      val resBuilder = new mutable.ArrayBuilder.ofInt

      def dfs(u: Int, depth: Int): Unit = {
        //val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          if (depths(adjs(u)(i)) == -1) {
            dfs(adjs(u)(i), depth + 1)
          } else {
            val v = adjs(u)(i)
            if ((depth == 0 || v != path(depth - 1)) && depth - depths(v) < k) {
              var i = depth
              resBuilder += v + 1
              while (i >= 0 && path(i) != v) {
                resBuilder += path(i) + 1
                i -= 1
              }
              val res = resBuilder.result()
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      new Thread(null,
        new Runnable() {
          def run(): Unit = {
            dfs(0, 0)
          }
        },
        "1",
        100000000).start()
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      out.println(2)

      val depths, path = Array.fill(n) {
        -1
      }

      def dfs(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            } else {
              var j = 1
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (j < k) {
                resBuilder += path(depth - j) + 1
                j += 2
              }
              val res = resBuilder.result()
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      dfs(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth > k) {
          var j = 0
          val resBuilder = new mutable.ArrayBuilder.ofInt
          while (j <= k) {
            resBuilder += path(j) + 1
            j += 2
          }
          val res = resBuilder.result()
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val depths, path = Array.fill(n) {
      -1
    }

    def dfs1(u: Int, depth: Int): Unit = {
      val prev = if (depth == 0) -1 else path(depth - 1)
      depths(u) = depth
      path(depth) = u
      var i = 0
      while (i < adjs(u).length) {
        val v = adjs(u)(i)
        if (depths(v) == -1) {
          dfs1(v, depth + 1)
        } else if (v != prev && depths(v) < depth) {
          if (depth - depths(v) < k) {
            var j = depth
            val resBuilder = new mutable.ArrayBuilder.ofInt
            resBuilder += v + 1
            while (path(j) != v) {
              resBuilder += path(j) + 1
              j -= 1
            }
            val res = resBuilder.result()
            out.println(2)
            out.println(res.length)
            out.println(res.mkString(" "))
            out.flush()
            System.exit(0)
          }
        }
        i += 1
      }
    }

    dfs1(0, 0)

    val subsetBuilders = Array.fill(2){new mutable.ArrayBuilder.ofInt}
    for (i <- 0 until n) {
      subsetBuilders(depths(i) % 2) += i + 1
    }
    val subsets = subsetBuilders.map(_.result())
    subsets.sortBy(- _.length)
    out.println(1)
    out.println(subsets(0).iterator.take((k + 1) / 2).mkString(" "))
    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth * 2 >= k) {
          var j = 0
          val resBuilder = new mutable.ArrayBuilder.ofInt
          while (j < k) {
            resBuilder += path(j) + 1
            j += 2
          }
          val res = resBuilder.result()
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val depths, path = Array.fill(n) {
      -1
    }

    def dfs1(u: Int, depth: Int): Unit = {
      val prev = if (depth == 0) -1 else path(depth - 1)
      depths(u) = depth
      path(depth) = u
      var i = 0
      while (i < adjs(u).length) {
        val v = adjs(u)(i)
        if (depths(v) == -1) {
          dfs1(v, depth + 1)
        } else if (v != prev && depths(v) < depth) {
          if (depth - depths(v) < k) {
            var j = depth
            val resBuilder = new mutable.ArrayBuilder.ofInt
            resBuilder += v + 1
            while (path(j) != v) {
              resBuilder += path(j) + 1
              j -= 1
            }
            val res = resBuilder.result()
            out.println(2)
            out.println(res.length)
            out.println(res.mkString(" "))
            out.flush()
            System.exit(0)
          }
        }
        i += 1
      }
    }

    dfs1(0, 0)

    val subsetBuilders = Array.fill(2){new mutable.ArrayBuilder.ofInt}
    for (i <- 0 until k) {
      subsetBuilders(depths(i) % 2) += i + 1
    }
    val subsets = subsetBuilders.map(_.result())
    val Array(bigger, _) = subsets.sortBy(- _.length)
    out.println(1)
    out.println(bigger.iterator.take((k + 1) / 2).mkString(" "))
    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth + 1 >= k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            assert(res(j) > 0)
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {
  import InOut._
  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n){ new mutable.ArrayBuilder.ofInt }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      out.println(2)

      val depths, path = Array.fill(n){ -1 }

      def dfs(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs(v, depth + 1)
          } else {
            if (v != prev && depths(v) < depth && depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      dfs(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _
    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }
    def nextInt = Integer.parseInt(nextToken)
    def nextLong = java.lang.Long.parseLong(nextToken)
    def nextBig = BigInt(nextToken)
    def nextInts(n: Int) = Array.fill(n) { nextInt }
    def nextLongs(n: Int) = Array.fill(n) { nextLong }
    def nextBigs(n: Int) = Array.fill(n) { nextBig }
    def nextLine = in.readLine
  }
}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth >= k) {
          var j = 0
          val resBuilder = new mutable.ArrayBuilder.ofInt
          while (j <= k) {
            resBuilder += path(j) + 1
            j += 2
          }
          val res = resBuilder.result()
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth >= k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val depths, path = Array.fill(n) {
      -1
    }

    def dfs1(u: Int, depth: Int): Unit = {
      val prev = if (depth == 0) -1 else path(depth - 1)
      depths(u) = depth
      path(depth) = u
      var i = 0
      while (i < adjs(u).length) {
        val v = adjs(u)(i)
        if (depths(v) == -1) {
          dfs1(v, depth + 1)
        } else if (v != prev && depths(v) < depth) {
          if (depth - depths(v) < k) {
            var j = depth
            val resBuilder = new mutable.ArrayBuilder.ofInt
            resBuilder += v + 1
            while (path(j) != v) {
              resBuilder += path(j) + 1
              j -= 1
            }
            val res = resBuilder.result()
            out.println(2)
            out.println(res.length)
            out.println(res.mkString(" "))
            out.flush()
            System.exit(0)
          }
        }
        i += 1
      }
    }

    def dfs2(u: Int, depth: Int): Unit = {
      depths(u) = depth
      path(depth) = u
      if (depth > k) {
        var j = 0
        val res = Array.ofDim[Int]((k + 1) / 2)
        while (j < res.length) {
          res(j) = path(2 * j) + 1
          j += 1
        }
        out.println(1)
        out.println(res.mkString(" "))
        out.flush()
        System.exit(0)
      } else {
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs2(v, depth + 1)
          }
          i += 1
        }
      }
    }

    dfs1(0, 0)
    util.Arrays.fill(depths, -1)
    dfs2(0, 0)

    val subsetBuilders = Array.fill(2){new mutable.ArrayBuilder.ofInt}
    for (i <- 0 until n) {
      subsetBuilders(depths(i) % 2) += i + 1
    }
    val subsets = subsetBuilders.map(_.result())
    subsets.sortBy(- _.length)
    out.println(1)
    out.println(subsets(0).iterator.take((k + 1) / 2).mkString(" "))
    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}

import java.util

import scala.collection.mutable

object D {

  import InOut._

  def main(args: Array[String]): Unit = {

    val n, m, k = nextInt
    val ajdBuilders = Array.fill(n) {
      new mutable.ArrayBuilder.ofInt
    }

    for (_ <- 1 to m) {
      val u, v = nextInt - 1
      ajdBuilders(u) += v
      ajdBuilders(v) += u
    }
    val adjs = ajdBuilders.map(_.result())

    val vs = new java.util.TreeSet[Int]
    for (i <- 0 until n) vs.add(i)

    val indepBuilder = new mutable.ArrayBuilder.ofInt
    while (!vs.isEmpty) {
      val v = vs.first()
      vs.remove(v)
      indepBuilder += v + 1
      var i = 0
      while (i < adjs(v).length) {
        vs.remove(adjs(v)(i))
        i += 1
      }
    }

    val indep = indepBuilder.result()
    if (indep.length >= (k + 1) / 2) {
      out.println(1)
      out.println(indep.iterator.take((k + 1) / 2).mkString(" "))
    } else {
      val depths, path = Array.fill(n){ -1 }

      def dfs1(u: Int, depth: Int): Unit = {
        val prev = if (depth == 0) -1 else path(depth - 1)
        depths(u) = depth
        path(depth) = u
        var i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (depths(v) == -1) {
            dfs1(v, depth + 1)
          } else if (v != prev && depths(v) < depth) {
            if (depth - depths(v) < k) {
              var j = depth
              val resBuilder = new mutable.ArrayBuilder.ofInt
              resBuilder += v + 1
              while (path(j) != v) {
                resBuilder += path(j) + 1
                j -= 1
              }
              val res = resBuilder.result()
              out.println(2)
              out.println(res.length)
              out.println(res.mkString(" "))
              out.flush()
              System.exit(0)
            }
          }
          i += 1
        }
      }

      def dfs2(u: Int, depth: Int): Unit = {
        depths(u) = depth
        path(depth) = u
        if (depth * 2 >= k) {
          var j = 0
          val res = Array.ofDim[Int]((k + 1) / 2)
          while (j < res.length) {
            res(j) = path(2 * j) + 1
            j += 1
          }
          out.println(1)
          out.println(res.mkString(" "))
          out.flush()
          System.exit(0)
        } else {
          var i = 0
          while (i < adjs(u).length) {
            val v = adjs(u)(i)
            if (depths(v) == -1) {
              dfs2(v, depth + 1)
            }
            i += 1
          }
        }
      }

      dfs1(0, 0)
      util.Arrays.fill(depths, -1)
      dfs2(0, 0)
    }

    out.flush()
  }

  final object InOut {
    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)
    private[this] var tokenizer: java.util.StringTokenizer = _

    def nextToken: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new java.util.StringTokenizer(in.readLine)
      tokenizer.nextToken
    }

    def nextInt = Integer.parseInt(nextToken)

    def nextLong = java.lang.Long.parseLong(nextToken)

    def nextBig = BigInt(nextToken)

    def nextInts(n: Int) = Array.fill(n) {
      nextInt
    }

    def nextLongs(n: Int) = Array.fill(n) {
      nextLong
    }

    def nextBigs(n: Int) = Array.fill(n) {
      nextBig
    }

    def nextLine = in.readLine
  }

}