object A342 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val num = readInts(n)
    val map = cu.Map.empty[Int, Int].withDefaultValue(0)
    num.foreach{n1 => map(n1)+=1}
    if(map(1) == n/3 && Array(5,7).forall(map(_) == 0)) {
      if(map(3) <= map(6)) {
        if(map(2) == map(6)-map(3)+map(4)) {
          for(i <- 0 until map(3)) {
            println(s"1 3 6")
          }
          for(i <- 0 until map(6)-map(3)) {
            println(s"1 2 6")
          }
          for(i <- 0 until map(4)) {
            println(s"1 2 4")
          }
        } else {
          out.println("-1")
        }
      } else {
        out.println("-1")
      }
    } else {
      out.println("-1")
    }
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(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 Main {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)

    val n7 = map.getOrElse(7, 0)
    val n6 = map.getOrElse(6, 0)
    val n5 = map.getOrElse(5, 0)
    val n4 = map.getOrElse(4, 0)
    var n3 = map.getOrElse(3, 0)
    var n2 = map.getOrElse(2, 0)
    var n1 = map.getOrElse(1, 0)

    var seq = scala.collection.mutable.Seq[String]()

    if (n5 != 0 || n7 != 0) { println("-1"); return }

    if (n6 < n3) { println("-1"); return }
    else {
      for (_ <- 1 to n3) seq ++= Seq("1 3 6")
      n2 -= (n6 - n3)
      n1 -= n6
      if (n2 < 0) { println("-1"); return }
      for (_ <- 1 to (n6 - n3)) seq ++= Seq("1 2 6")
    }

    if (n4 != n2) { println("-1"); return }
    else {
      n1 -= n4
      for (_ <- 1 to n2) seq ++= Seq("1 2 4")
    }

    if (n1 != 0) println("-1")
    else seq.foreach(println)
  }
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.immutable.Queue
import scala.util.Random

object P342A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val X = Array.fill(N)(sc.nextInt)

  // Possible groups
  // 1 2 4 => g4
  // 1 2 6 => g62
  // 1 3 6 => g63

  def solve(): Unit = {
    val c = Array.fill(8)(0)
    X foreach { x => c(x) += 1 }

    if (c(5) > 0 ||  c(7) > 0) out.println("-1")
    else {
      val g4 = c(4)
      c(1) -= g4
      c(2) -= g4

      if (c(2) < 0 || c(1) != c(6) || c(2) + c(3) != c(6)) out.println(-1)
      else {
        for (i <- 0 until g4) out.println("1 2 4")
        for (i <- 0 until c(2)) out.println("1 2 6")
        for (i <- 0 until c(3)) out.println("1 3 6")
      }
    }
  }

  solve
  out.close
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = Array.ofDim[Int](8)
  in.next().split(' ').foreach {
    i => data(i.toInt) += 1
  }
  val rest = if (data(5) != 0 || data(7) != 0)
    Nil
  else {
    var res = List.empty[(Int, Int, Int)]

    (1 to data(3)).foreach { _ =>
      res ::= (1, 3, 6)
    }
    data(1) -= data(3)
    data(6) -= data(3)
    data(3) = 0
    if (data(1) < 0 || data(6) < 0)
      Nil
    else {
      var count = data(1) + data(2) + data(4) + data(6)
      while (count > 0) {
        val list = List(data(4) -> 4, data(6) -> 6).sorted.tail.map(_._2)
        val d = (1 :: 2 :: list).sorted
        res ::= (d.head, d(1), d.last)
        count -= 3
        d.foreach(i => data(i) -= 1)

        if (d.exists(i => data(i) < 0)) {
          count = -1
          res = Nil
        }
      }
      res
    }
  }
  if (rest.isEmpty)
    println(-1)
  else
    println(rest.map(i => s"${i._1} ${i._2} ${i._3}").mkString("\n"))

}

object B {
  def main(args: Array[String]) {
    var n = readInt()
    var a:Array[Int] = readLine() split(" ") map(_.toInt)
    var cnt = (Range(0, 8) map (x=> a.count(_==x))).toArray;
    f(a, cnt, 1, 2, 4)
    f(a, cnt, 1, 2, 6)
    f(a, cnt, 1, 3, 6)
    println(if ((cnt count(_ > 0)) > 0) -1 else result)
  }

  val result = new StringBuilder();
  def f(a:IndexedSeq[Int], cnt:Array[Int], i1:Int, i2:Int, i3:Int) {

    val m = math.min(cnt(i1), math.min(cnt(i2), cnt(i3)));
    for (i <- 1 to m) result.append("%d %d %d\n".format(i1, i2, i3))
    for (i <- List(i1, i2, i3)) cnt(i) -= m;
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = Array.ofDim[Int](8)
  in.next().split(' ').foreach {
    i => data(i.toInt) += 1
  }
  val rest = if (data(5) != 0 || data(7) != 0)
    Nil
  else {
    var res = List.empty[(Int, Int, Int)]

    (1 to data(3)).foreach { _ =>
      res ::= (1, 3, 6)
    }
    data(1) -= data(3)
    data(6) -= data(3)
    data(3) = 0
    if (data(1) < 0 || data(6) < 0)
      Nil
    else {
      var count = data(1) + data(2) + data(4) + data(6)
      while (count > 0) {
        val list = List(data(1) -> 1, data(4) -> 4, data(6) -> 6).sorted.tail.map(_._2)
        val d = (2 :: list).sorted
        res ::= (d.head, d(1), d.last)
        count -= 3
        d.foreach(i => data(i) -= 1)

        if (d.exists(i => data(i) < 0)) {
          count = -1
          res = Nil
        }
      }
      res
    }
  }
  if (rest.isEmpty)
    println(-1)
  else
    println(rest.map(i => s"${i._1} ${i._2} ${i._3}").mkString("\n"))

}

object A342 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val num = readInts(n)
    val map = cu.Map.empty[Int, Int].withDefaultValue(0)
    num.foreach{n1 => map(n1)+=1}
    if(map(1) == n/3) {
      if(map(3) <= map(6)) {
        if(map(2) == map(6)-map(3)+map(4)) {
          for(i <- 0 until map(3)) {
            println(s"1 3 6")
          }
          for(i <- 0 until map(6)-map(3)) {
            println(s"1 2 6")
          }
          for(i <- 0 until map(4)) {
            println(s"1 2 4")
          }
        } else {
          out.println("-1")
        }
      } else {
        out.println("-1")
      }
    } else {
      out.println("-1")
    }
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(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))
    }
  }

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.immutable.Queue
import scala.util.Random

object P342A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val X = Array.fill(N)(sc.nextInt)

  // Possible groups
  // 1 2 4 => g4
  // 1 2 6 => g62
  // 1 3 6 => g63

  def solve(): Unit = {
    val c = Array.fill(8)(0)
    X foreach { x => c(x) += 1 }

    if (c(5) * c(7) > 0) out.println(-1)
    else {
      val g4 = c(4)
      c(1) -= g4
      c(2) -= g4

      if (c(1) != c(6) || c(2) + c(3) != c(6)) out.println(-1)
      else {
        for (i <- 0 until g4) out.println("1 2 4")
        for (i <- 0 until c(2)) out.println("1 2 6")
        for (i <- 0 until c(3)) out.println("1 3 5")
      }
    }
  }

  solve
  out.close
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.immutable.Queue
import scala.util.Random

object P342A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val X = Array.fill(N)(sc.nextInt)

  // Possible groups
  // 1 2 4 => g4
  // 1 2 6 => g62
  // 1 3 6 => g63

  def solve(): Unit = {
    val c = Array.fill(8)(0)
    X foreach { x => c(x) += 1 }

    if (c(5) * c(7) > 0) out.println(-1)
    else {
      val g4 = c(4)
      c(1) -= g4
      c(2) -= g4

      if (c(2) < 0 || c(1) != c(6) || c(2) + c(3) != c(6)) out.println(-1)
      else {
        for (i <- 0 until g4) out.println("1 2 4")
        for (i <- 0 until c(2)) out.println("1 2 6")
        for (i <- 0 until c(3)) out.println("1 3 6")
      }
    }
  }

  solve
  out.close
}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.immutable.Queue
import scala.util.Random

object P342A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val X = Array.fill(N)(sc.nextInt)

  // Possible groups
  // 1 2 4 => g4
  // 1 2 6 => g62
  // 1 3 6 => g63

  def solve(): Unit = {
    val c = Array.fill(8)(0)
    X foreach { x => c(x) += 1 }

    if (c(5) * c(7) > 0) out.println(-1)
    else {
      val g4 = c(4)
      c(1) -= g4
      c(2) -= g4

      if (c(2) < 0 || c(1) != c(6) || c(2) + c(3) != c(6)) out.println(-1)
      else {
        for (i <- 0 until g4) out.println("1 2 4")
        for (i <- 0 until c(2)) out.println("1 2 6")
        for (i <- 0 until c(3)) out.println("1 3 5")
      }
    }
  }

  solve
  out.close
}

object B {
  def main(args: Array[String]) {
    var n = readInt()
    var a:Array[Int] = readLine() split(" ") map(_.toInt)
    var cnt = (Range(0, 7) map (x=> a.count(_==x))).toArray;
    f(a, cnt, 1, 2, 4)
    f(a, cnt, 1, 2, 6)
    f(a, cnt, 1, 3, 6)
    println(if ((cnt count(_ > 0)) > 0) -1 else result)
  }

  val result = new StringBuilder();
  def f(a:IndexedSeq[Int], cnt:Array[Int], i1:Int, i2:Int, i3:Int) {

    val m = math.min(cnt(i1), math.min(cnt(i2), cnt(i3)));
    for (i <- 1 to m) result.append("%d %d %d\n".format(i1, i2, i3))
    for (i <- List(i1, i2, i3)) cnt(i) -= m;
  }
}

object A {
  var b = false;
  def main(args: Array[String]) {
    var n = readInt()
    var a:Array[Int] = readLine() split(" ") map(_.toInt)
    var cnt = (Range(0, 7) map (x=> a.count(_==x))).toArray;
    f(a, cnt, 1, 2, 4)
    f(a, cnt, 1, 2, 6)
    f(a, cnt, 1, 3, 6)
    if (!b) println(-1)

  }

  def f(a:IndexedSeq[Int], cnt:Array[Int], i1:Int, i2:Int, i3:Int) {
    val m = math.min(cnt(i1), math.min(cnt(i2), cnt(i3)));
    for (i <- 1 to m) { printf("%d %d %d\n", i1, i2, i3); b = true }
    for (i <- List(i1, i2, i3)) cnt(i) -= m;
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)

    val n6 = map.getOrElse(6, 0)
    val n5 = map.getOrElse(5, 0)
    val n4 = map.getOrElse(4, 0)
    var n3 = map.getOrElse(3, 0)
    var n2 = map.getOrElse(2, 0)
    var n1 = map.getOrElse(1, 0)

    var seq = scala.collection.mutable.Seq[String]()

    if (n5 != 0) { println("-1"); return }

    if (n6 < n3) { println("-1"); return }
    else {
      for (_ <- 1 to n3) seq ++= Seq("1 3 6")
      n2 -= (n6 - n3)
      n1 -= n6
      if (n2 < 0) { println("-1"); return }
      for (_ <- 1 to (n6 - n3)) seq ++= Seq("1 2 6")
    }

    if (n4 != n2) { println("-1"); return }
    else {
      n1 -= n4
      for (_ <- 1 to n2) seq ++= Seq("1 2 4")
    }

    if (n1 != 0) println("-1")
    else seq.foreach(println)
  }
}


import scala.collection.mutable.ArrayBuilder

object P2775D extends App {

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

  val Array(n, m) = readInts(2)

  val adjBuilders = Array.fill(n) { new ArrayBuilder.ofInt }
  val revBuilders = Array.fill(n) { new ArrayBuilder.ofInt }

  for (i <- 0 until m) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
  }

  val adj = adjBuilders.map(_.result)

  val cnts = Array.fill(n, n)(0)

  for {
    u <- 0 until n
    v <- adj(u)
    w <- adj(v)
    if w != u
  } cnts(w)(u) += 1

  var sum = 0L

  for {
    u <- 0 until n
    c <- cnts(u)
    if c > 1
  } sum += c * (c - 1) / 2

  println(sum)
}

import scala.collection.mutable.ArrayBuilder

object P2775D extends App {

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

  val Array(n, m) = readInts(2)

  val adjBuilders = Array.fill(n) { new ArrayBuilder.ofInt }
  val revBuilders = Array.fill(n) { new ArrayBuilder.ofInt }

  for (i <- 0 until m) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
  }

  val adj = adjBuilders.map(_.result)

  val cnts = Array.fill(n, n)(0)

  for (u <- 0 until n)
    for (v <- adj(u))
      for (w <- adj(v))
        if (w != u) cnts(w)(u) += 1

  var sum = 0L

  for (u <- 0 until n)
    for (c <- cnts(u))
      if (c > 1) sum += c * (c - 1) / 2

  println(sum)
}

import scala.collection.mutable.ArrayBuilder

object P2775D extends App {

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

  val Array(n, m) = readInts(2)

  val adjBuilders = Array.fill(n) { new ArrayBuilder.ofInt }
  val revBuilders = Array.fill(n) { new ArrayBuilder.ofInt }

  for (i <- 0 until m) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
  }

  val adj = adjBuilders.map(_.result)

  val cnts = Array.fill(n, n)(0)

  for {
    u <- 0 until n
    v <- adj(u)
    w <- adj(v)
    if w != u
  } cnts(w)(u) += 1

  var sum = 0L

  for {
    u <- 0 until n
    c <- cnts(u)
  } sum += c * (c - 1) / 2

  println(sum)
}


import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Double) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  case class Point(x: BigInt, y: BigInt)

  def direction(uv: (Point, Point), w: Point) =
    (uv._2.x - uv._1.x) * (w.y - uv._1.y) - (w.x - uv._1.x) * (uv._2.y - uv._1.y)

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s * (s - al) * (s - bl) * (s - cl))
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = 0
  var abc = Double.PositiveInfinity
  val pA = Point(xs(a - 1), ys(a - 1))
  val pB = Point(xs(b - 1), ys(b - 1))
  val pAB = pA -> pB

  for (i <- 2 to n) if (i != b && direction(pAB, Point(xs(i - 1), ys(i - 1))) != 0) {
    val a2 = area(a, b, i)
    if (a2 < abc) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

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

object CF2016_C {

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

    //COMMENT ME !
    is = new ByteArrayInputStream(Test.t50.trim.getBytes("ISO-8859-1"))
//    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    val ad = 1000000000
    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long+ad, line.long+ad)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, BigDecimal, BigDecimal)](n-1)
    for(i <- 2 to n) {
      val xDif = BigDecimal((x - stars(i)._1).abs)
      val yDif = BigDecimal((y - stars(i)._2).abs)

      val xSq = xDif*xDif
      val ySq = yDif*yDif
      val dist = (xSq + ySq)

//      val dist = Math.sqrt(xDif*xDif + yDif*yDif)
//      val xDifAbs = BigDecimal((x - stars(i)._1))
//      val relSin = (xDif*xDif)/dist * xDifAbs.signum
      val relSin = (xDif*xDif)/dist
      val alpha = relSin

      distances(i-2) = (i, dist, alpha)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var zerro = false
    def calcFun(s1:Int, s2:Int) :(BigDecimal, BigDecimal) = {
      if (stars(s2)._1 - stars(s1)._1 == 0) {
        zerro = true
        return (0,0)
      }
      val a = (BigDecimal(stars(s2)._2) - stars(s1)._2) / (stars(s2)._1 - stars(s1)._1)
      val b = (BigDecimal(stars(s1)._2)-ad) - a * (BigDecimal(stars(s1)._1) - ad)
      (a, b)
    }

    var secondInd = 1
    val alpha1 = distances(0)._3
    val coef = calcFun(1, 2)
    db("coef = " + coef)
//    while (secondInd < distances.size && check(alpha1,distances(secondInd)._3)) {
    while (secondInd < distances.size && check(alpha1,distances(secondInd)._3) &&
        (isZerro(distances(secondInd)._1) ||
            belongs(coef._1, coef._2, distances(secondInd)._1))) {
      secondInd+= 1
    }

    def isZerro(st:Int): Boolean = {
      if (zerro && stars(st)._1 == x) {
        true
      } else {
    	  false
      }
    }

    def check(v1:BigDecimal, v2:BigDecimal) = {
//      val diff = (v1 - v2).abs
//      diff < 0.00000000001
      v1 == v2
    }

    def belongs(a:BigDecimal, b:BigDecimal, st:Int):Boolean = {
      val y = a*(stars(st)._1-ad) + b
      val diff = (y - (stars(st)._2-ad)).abs
      db("func diff " + st + " -> " + diff)
      return diff < 0.000000001
    }

//    def area(a:BigDecimal, b:BigDecimal, c:BigDecimal) = {
//      s;
//    }

    def dist(v1:(Long,Long), v2:(Long,Long)) {
       val xDif = BigDecimal((v1._1 - v2._1).abs)
       val yDif = BigDecimal((v1._2 - v2._2).abs)
        val xSq = xDif*xDif
      val ySq = yDif*yDif
      val dist = (xSq + ySq)
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 1000000000
"""

val t15 = """
10
13303280 387243789
30131431 723806809
404775998 670757742
-25996011 -398742031
25599613 633170449
38471092 890600029
-33017802 -539177851
-47620079 -831223391
1425218 149682549
-3745401 46270169
"""

val t49 = """
10
999999999 1
999999998 1
999999997 1
1000000000 1
999999996 1
999999995 1
999999994 1
999999992 1
999999993 1
0 0
"""

val t50 = """
4
0 1
0 2
0 3
7 7
"""

val t84 = """
3
1 2
2 1
2 3
"""
}

}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Double) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  case class Point(x: Long, y: Long)

  def direction(uv: (Point, Point), w: Point) =
    (uv._2.x - uv._1.x) * (w.y - uv._1.y) - (w.x - uv._1.x) * (uv._2.y - uv._1.y)

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s * (s - al) * (s - bl) * (s - cl))
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = 0
  var abc = Double.PositiveInfinity
  val pA = Point(xs(a - 1), ys(a - 1))
  val pB = Point(xs(b - 1), ys(b - 1))
  val pAB = pA -> pB

  for (i <- 2 to n) if (i != b && direction(pAB, Point(xs(i - 1), ys(i - 1))) != 0) {
    val a2 = area(a, b, i)
    if (a2 < abc) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

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

object CF2016_C_2 {

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

    //COMMENT ME !
    is = new ByteArrayInputStream(Test.t84.trim.getBytes("ISO-8859-1"))
    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long, line.long)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, Double)](n-1)
    for(i <- 2 to n) {
      val xDif = (x - stars(i)._1).abs
      val yDif = (y - stars(i)._2).abs

      val xSq = xDif*xDif //overflow?
      val ySq = yDif*yDif
      val dist = (xSq + ySq)

      distances(i-2) = (i, dist)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var zerro = false
    def calcFun(s1:Int, s2:Int) :(Double, Double) = {
      val xDif = stars(s2)._1 - stars(s1)._1
      if (xDif == 0) {
        zerro = true
        return (0,0)
      }
      val a = (stars(s2)._2 - stars(s1)._2) / xDif
      val b = stars(s1)._2 - a * stars(s1)._1
      (a, b)
    }

    var secondInd = 1
    val fun = calcFun(1, distances(0)._1)
    db("fun = " + fun + " zerro=" + zerro)
    while (secondInd < distances.size &&
            belongs(fun, distances(secondInd)._1)) {
      secondInd+= 1
    }

    def belongs(fun:(Double, Double), st:Int):Boolean = {
      val star = stars(st)
      if (zerro && star._1 == x) {
        true
      } else {
	      val (a,b) = fun
	      val y = a*star._1 + b
	      val diff = (y - star._2).abs
	      db("func diff " + st + " -> " + diff)
	      return diff < 0.000000001
      }
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 999999999
"""

val t15 = """
10
13303280 387243789
30131431 723806809
404775998 670757742
-25996011 -398742031
25599613 633170449
38471092 890600029
-33017802 -539177851
-47620079 -831223391
1425218 149682549
-3745401 46270169
"""

val t49 = """
10
999999999 1
999999998 1
999999997 1
1000000000 1
999999996 1
999999995 1
999999994 1
999999992 1
999999993 1
0 0
"""

val t50 = """
4
0 1
0 2
0 3
7 7
"""

val t84 = """
3
1 2
2 1
2 3
"""
}

}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Double) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  case class Point(x: BigInt, y: BigInt)

  def direction(uv: (Point, Point), w: Point) =
    (uv._2.x - uv._1.x) * (w.y - uv._1.y) - (w.x - uv._1.x) * (uv._2.y - uv._1.y)

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s * (s - al) * (s - bl) * (s - cl))
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = if (b == 2) 3 else 2
  var abc = area(a, b, c)
  val pA = Point(xs(a - 1), ys(a - 1))
  val pB = Point(xs(b - 1), ys(b - 1))
  val pAB = pA -> pB

  for (i <- 2 to n) if (i != b && direction(pAB, Point(xs(i - 1), ys(i - 1))) != 0) {
    val a2 = area(a, b, i)
    if (a2 > 0.1d && (a2 < abc || abc < 0.1d)) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Double) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s) * (s - al) * (s - bl) * (s - cl)
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = if (b == 2) 3 else 2
  var abc = area(a, b, c)

  for (i <- 2 to n) if (i != b) {
    val a2 = area(a, b, i)
    if (a2 > 0.1d && (a2 < abc || abc < 0.1d)) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Long) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s) * (s - al) * (s - bl) * (s - cl)
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = if (b == 2) 3 else 2
  var abc = area(a, b, c)

  for (i <- 2 to n) if (i != b) {
    val a2 = area(a, b, i)
    if (a2 > 0.1d && (a2 < abc || abc < 0.1d)) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

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

object CF2016_C {

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

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa2.trim.getBytes("ISO-8859-1"))
    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    val ad = 1000000000
    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long+ad, line.long+ad)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, Double, Double)](n-1)
    for(i <- 2 to n) {
      val xDif = (x - stars(i)._1).abs
      val yDif = (y - stars(i)._2).abs

      val dist = Math.sqrt(xDif*xDif + yDif*yDif)
      val relSin = xDif/dist
      val alpha = relSin

      distances(i-2) = (i, dist, alpha)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var secondInd = 1
    val alpha1 = distances(0)._3
    while (secondInd < distances.size && alpha1 == distances(secondInd)._3) {
      secondInd+= 1
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 1000000000
"""

}

}

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

object CF2016_C {

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

    //COMMENT ME !
    is = new ByteArrayInputStream(Test.t15.trim.getBytes("ISO-8859-1"))
    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    val ad = 1000000000
    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long+ad, line.long+ad)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, BigDecimal, BigDecimal)](n-1)
    for(i <- 2 to n) {
      val xDif = BigDecimal((x - stars(i)._1).abs)
      val yDif = BigDecimal((y - stars(i)._2).abs)

      val xSq = xDif*xDif
      val ySq = yDif*yDif
      val dist = (xSq + ySq)

//      val dist = Math.sqrt(xDif*xDif + yDif*yDif)
      val xDifAbs = BigDecimal((x - stars(i)._1))
      val relSin = (xDif*xDif)/dist * xDifAbs.signum
      val alpha = relSin

      distances(i-2) = (i, dist, alpha)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var zerro = false
    def calcFun(s1:Int, s2:Int) :(Double, Double) = {
      if (stars(s2)._1 - stars(s1)._1 == 0) {
        zerro = true
        return (0,0)
      }
      val a = (stars(s2)._2 - stars(s1)._2) / (stars(s2)._1 - stars(s1)._1)
      val b = stars(s1)._2 - a * stars(s1)._1 - ad*2
      (a, b)
    }

    var secondInd = 1
    val alpha1 = distances(0)._3
    val coef = calcFun(1, 2)
    db("coef = " + coef)
//    while (secondInd < distances.size && check(alpha1,distances(secondInd)._3)) {
    while (secondInd < distances.size && check(alpha1,distances(secondInd)._3) && (zerro || belongs(coef._1, coef._2, secondInd+1))) {
      secondInd+= 1
    }

    def check(v1:BigDecimal, v2:BigDecimal) = {
//      val diff = (v1 - v2).abs
//      diff < 0.00000000001
      v1 == v2
    }

    def belongs(a:Double, b:Double, st:Int):Boolean = {
      val y = a*stars(st)._1 + b
      return (y - stars(st)._2).abs < 0.000000001
    }

//    def area(a:BigDecimal, b:BigDecimal, c:BigDecimal) = {
//      s;
//    }

    def dist(v1:(Long,Long), v2:(Long,Long)) {
       val xDif = BigDecimal((v1._1 - v2._1).abs)
       val yDif = BigDecimal((v1._2 - v2._2).abs)
        val xSq = xDif*xDif
      val ySq = yDif*yDif
      val dist = (xSq + ySq)
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 1000000000
"""

val t15 = """
10
13303280 387243789
30131431 723806809
404775998 670757742
-25996011 -398742031
25599613 633170449
38471092 890600029
-33017802 -539177851
-47620079 -831223391
1425218 149682549
-3745401 46270169
"""

val t49 = """
10
999999999 1
999999998 1
999999997 1
1000000000 1
999999996 1
999999995 1
999999994 1
999999992 1
999999993 1
0 0
"""

val t84 = """
3
1 2
2 1
2 3
"""
}

}

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

object CF2016_C {

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

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa2.trim.getBytes("ISO-8859-1"))
    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    val ad = 1000000000
    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long+ad, line.long+ad)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, Double, Double)](n-1)
    for(i <- 2 to n) {
      val xDif = (x - stars(i)._1).abs
      val yDif = (y - stars(i)._2).abs

      val dist = Math.sqrt(xDif*xDif + yDif*yDif)
      val relSin = dist/(xDif+1)
      val alpha = Math.asin(relSin)

      distances(i-2) = (i, dist, alpha)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var secondInd = 1
    val alpha1 = distances(0)._3
    while (secondInd < distances.size && alpha1 == distances(secondInd)._3) {
      secondInd+= 1
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 1000000000
"""

}

}

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

object CF2016_C {

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

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa2.trim.getBytes("ISO-8859-1"))
    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    val ad = 1000000000
    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long+ad, line.long+ad)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, Double, Double)](n-1)
    for(i <- 2 to n) {
      val xDif = (x - stars(i)._1).abs
      val yDif = (y - stars(i)._2).abs

      val dist = Math.sqrt(xDif*xDif + yDif*yDif)
      val relSin = dist/xDif
      val alpha = Math.asin(relSin)

      distances(i-2) = (i, dist, alpha)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var secondInd = 1
    val alpha1 = distances(0)._3
    while (secondInd < distances.size && alpha1 == distances(secondInd)._3) {
      secondInd+= 1
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 1000000000
"""

}

}

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

object CF2016_C {

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

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa1.trim.getBytes("ISO-8859-1"))
//    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val stars = new Array[(Long, Long)](n+1)

    val ad = 1000000000
    for(i <- 1 to n) {
      val line = readLine()
      stars(i) = (line.long+ad, line.long+ad)
    }

    val x = stars(1)._1
    val y = stars(1)._2
    var distances = new Array[(Int, BigDecimal, BigDecimal)](n-1)
    for(i <- 2 to n) {
      val xDif = BigDecimal((x - stars(i)._1).abs)
      val yDif = BigDecimal((y - stars(i)._2).abs)

      val xSq = xDif*xDif
      val ySq = yDif*yDif
      val dist = (xSq + ySq)

//      val dist = Math.sqrt(xDif*xDif + yDif*yDif)
//      val xDifAbs = BigDecimal((x - stars(i)._1))
//      val relSin = (xDif*xDif)/dist * xDifAbs.signum
      val relSin = (xDif*xDif)/dist
      val alpha = relSin

      distances(i-2) = (i, dist, alpha)
      db(i + " -> " + dist)
    }

    distances = distances.sortWith(_._2 < _._2)
    db(distances.mkString(", "))

    var zerro = false
    def calcFun(s1:Int, s2:Int) :(BigDecimal, BigDecimal) = {
      if (stars(s2)._1 - stars(s1)._1 == 0) {
        zerro = true
        return (0,0)
      }
      val a = (BigDecimal(stars(s2)._2) - stars(s1)._2) / (stars(s2)._1 - stars(s1)._1)
      val b = (BigDecimal(stars(s1)._2)-ad) - a * (BigDecimal(stars(s1)._1) - ad)
      (a, b)
    }

    var secondInd = 1
    val alpha1 = distances(0)._3
    val coef = calcFun(1, 2)
    db("coef = " + coef)
//    while (secondInd < distances.size && check(alpha1,distances(secondInd)._3)) {
    while (secondInd < distances.size && check(alpha1,distances(secondInd)._3) &&
        (!zerro &&
            belongs(coef._1, coef._2, distances(secondInd)._1))) {
      secondInd+= 1
    }

    def check(v1:BigDecimal, v2:BigDecimal) = {
//      val diff = (v1 - v2).abs
//      diff < 0.00000000001
      v1 == v2
    }

    def belongs(a:BigDecimal, b:BigDecimal, st:Int):Boolean = {
      val y = a*(stars(st)._1-ad) + b
      val diff = (y - (stars(st)._2-ad)).abs
      db("func diff " + st + " -> " + diff)
      return diff < 0.000000001
    }

//    def area(a:BigDecimal, b:BigDecimal, c:BigDecimal) = {
//      s;
//    }

    def dist(v1:(Long,Long), v2:(Long,Long)) {
       val xDif = BigDecimal((v1._1 - v2._1).abs)
       val yDif = BigDecimal((v1._2 - v2._2).abs)
        val xSq = xDif*xDif
      val ySq = yDif*yDif
      val dist = (xSq + ySq)
    }

    println(1 + " " + distances(0)._1 + " " + distances(secondInd)._1)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
5
0 0
0 2
2 0
2 2
1 1
"""

val sa2 = """
3
-1000000000 -1000000000
1000000000 1000000000
1000000000 1000000000
"""

val t15 = """
10
13303280 387243789
30131431 723806809
404775998 670757742
-25996011 -398742031
25599613 633170449
38471092 890600029
-33017802 -539177851
-47620079 -831223391
1425218 149682549
-3745401 46270169
"""

val t49 = """
10
999999999 1
999999998 1
999999997 1
1000000000 1
999999996 1
999999995 1
999999994 1
999999992 1
999999993 1
0 0
"""

val t84 = """
3
1 2
2 1
2 3
"""
}

}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Long) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s) * (s - al) * (s - bl) * (s - cl)
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = if (b == 2) 3 else 2
  var abc = area(a, b, c)

  for (i <- 2 to n) if (i != b) {
    val a2 = area(a, b, i)
    if (a2 > 0.0000001d && (a2 < abc || abc < 0.0000001d)) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Long) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s) * (s - al) * (s - bl) * (s - cl)
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = if (b == 2) 3 else 2
  var abc = area(a, b, c)

  for (i <- 2 to n) if (i != b) {
    val a2 = area(a, b, i)
    if (a2 > 0.5d && (a2 < abc || abc < 0.5d)) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}

import scala.collection._

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(n) = readInts(1)
  val xs, ys = Array.ofDim[Long](n)
  for (i <- 0 until n) {
    val Array(x, y) = readLongs(2)
    xs(i) = x
    ys(i) = y
  }

  def sqr(x: Double) = x * x
  def dist(i: Int, j: Int) = sqr(xs(i - 1) - xs(j - 1)) + sqr(ys(i - 1) - ys(j - 1))

  case class Point(x: Long, y: Long)

  def direction(uv: (Point, Point), w: Point) =
    (uv._2.x - uv._1.x) * (w.y - uv._1.y) - (w.x - uv._1.x) * (uv._2.y - uv._1.y)

  def area(i: Int, j: Int, k: Int) = {
    val al = Math.sqrt(dist(i, j))
    val bl = Math.sqrt(dist(j, k))
    val cl = Math.sqrt(dist(i, k))
    val s = (al + bl + cl) / 2d
    Math.sqrt(s * (s - al) * (s - bl) * (s - cl))
  }

  val a = 1
  var b = 2
  var ab = dist(a, b)
  for (i <- 3 to n) {
    val d2 = dist(a, i)
    if (d2 < ab) {
      b = i
      ab = d2
    }
  }

  var c = if (b == 2) 3 else 2
  var abc = area(a, b, c)
  val pA = Point(xs(a - 1), ys(a - 1))
  val pB = Point(xs(b - 1), ys(b - 1))
  val pAB = pA -> pB

  for (i <- 2 to n) if (i != b && direction(pAB, Point(xs(i - 1), ys(i - 1))) != 0) {
    val a2 = area(a, b, i)
    if (a2 > 0.1d && (a2 < abc || abc < 0.1d)) {
      c = i
      abc = a2
    }
  }

  println(s"$a $b $c")
}


import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.annotation.switch
import scala.annotation.unchecked
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.collection.immutable.TreeSet
import scala.util.Random
import scala.util.control.Breaks._

object P298B extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

    // If the wind blows to the east, the boat will move to (x + 1, y).
    // If the wind blows to the south, the boat will move to (x, y - 1).
    // If the wind blows to the west, the boat will move to (x - 1, y).
    // If the wind blows to the north, the boat will move to (x, y + 1).

  def solve(): Int = {
    val T, sx, sy, ex, ey = sc.nextInt
    sc.nextLine
    val Winds = sc.nextLine.toList
    val N = (ey - sy) max 0
    val S = (sy - ey) max 0
    val E = (ex - sx) max 0
    val W = (sx - ex) max 0

    @tailrec
    def loop(n: Int, s: Int, e: Int, w: Int, ws: List[Char]): Int = {
      if (n >= N && s >= S && e >= E && w >= W) {
        T - ws.size
      }
      else {
        (ws: @unchecked) match {
          case Nil => -1
          case 'N' :: xs => loop(n + 1, s, e, w, xs)
          case 'S' :: xs => loop(n, s + 1, e, w, xs)
          case 'E' :: xs => loop(n, s, e + 1, w, xs)
          case 'W' :: xs => loop(n, s, e, w + 1, xs)
        }
      }
    }

    loop(0, 0, 0, 0, Winds)
  }

  out.println(solve)
  out.close
}

import java.util.Scanner

object B {
  def main(args: Array[String]) {
      var scan = new Scanner(System.in)
      var t = scan.nextInt
      var sx = scan.nextInt
      var sy = scan.nextInt
      var ex = scan.nextInt
      var ey = scan.nextInt
      var dx = sx - ex
      var dy=sy-ey
      var s = scan.next
      var r=0
      if(dx==0 &&dy==0){
        println(r)
        return
      }
      for (c <- s) {
        if(c=='S' && dy>0)dy-=1
        if(c=='N' && dy<0)dy+=1
        if(c=='W' && dx>0)dx-=1
        if(c=='E' && dx<0)dx+=1
        r += 1
        if(dx==0 &&dy==0){
          println(r)
          return
        }

      }
      println(-1)
  }
}

object Main {
  val sdir: PartialFunction[Char, (Int, Int)] = { case 'S' => (0, -1) }
  val ndir: PartialFunction[Char, (Int, Int)] = { case 'N' => (0,  1) }
  val edir: PartialFunction[Char, (Int, Int)] = { case 'E' => ( 1, 0) }
  val wdir: PartialFunction[Char, (Int, Int)] = { case 'W' => (-1, 0) }
  val nop: PartialFunction[Char, (Int, Int)] = { case _ => (0, 0) }

  def main(args: Array[String]) {
    val op = readLine().split(" ").map(_.toInt)
    val a = readLine()
    val dir = ((op(3) - op(1)).signum, (op(4) - op(2)).signum) match {
      case (1, 1) => edir orElse ndir orElse nop
      case (1, 0) => edir orElse nop
      case (1, -1) => edir orElse sdir orElse nop
      case (-1, 1) => wdir orElse ndir orElse nop
      case (-1, 0) => wdir orElse nop
      case (-1, -1) => wdir orElse sdir orElse nop
      case (0, 1) => ndir orElse nop
      case (0, 0) => nop
      case (0, -1) => sdir orElse nop
    }
    val r = a.scanLeft(op(1), op(2)) { (pos, c) =>
      var nd = dir(c)
      (pos._1 + nd._1, pos._2 + nd._2)
    }
    val ho = r.zipWithIndex.find(_._1._1 == op(3)).map(_._2)
    val vo = r.zipWithIndex.find(_._1._2 == op(4)).map(_._2)
    (ho, vo) match {
      case (Some(h), Some(v)) => println(h.max(v))
      case _ => println("-1")
    }
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(t, x1, y1, x2, y2) = in.next().split(' ').map(_.toLong)
  val (tr, xr, yr) = in.next().foldLeft((0l, x1, y1)) {
    case ((time, x, y), _) if x == x2 && y == y2 => (time, x, y)
    case ((time, x, y), 'N') if y < y2 => (time + 1, x, y + 1)
    case ((time, x, y), 'S') if y > y2 => (time + 1, x, y - 1)
    case ((time, x, y), 'W') if x > x2 => (time + 1, x - 1, y)
    case ((time, x, y), 'E') if x < x2 => (time + 1, x + 1, y)
    case ((time, x, y), _) => (time + 1, x, y)
  }
  if (xr == x2 && yr == y2)
    println(tr)
  else
    println(-1)

}

object Solution {

  def main(args: Array[String]) {
    val si = io.Source.stdin.getLines
    val Array(n, s1, s2, e1, e2) = si.next.split(' ').map(_.toInt)
    val w = si.next.toArray

    var v = e2 - s2
    var vd = 'N'
    if (v < 0) {
      vd = 'S'
    }

    v = math.abs(v)

    var h = e1 - s1
    var hd = 'E'
    if (h < 0) {
      hd = 'W'
    }

    h = math.abs(h)

    var sec = -1

    (0 to w.length - 1) foreach {i =>
      if(v != 0 && w(i) == vd) v -= 1
      else if (h != 0 && w(i) == hd) h -= 1

      if(h == 0 && v == 0 && sec == -1) {
        sec = i + 1
      }
    }

    if (sec > n) sec == -1

    println(sec)

  }

}

import java.util.Scanner

object Sail {

  def mv(x:Int, d:Int):Int = if(x==0 || x.signum==d.signum)x else x+d
  val M = Map('E' -> (1,0), 'W'->(-1,0), 'S'->(0,-1), 'N'->(0,1))
  def solveDist(s:Iterator[Char], dx:Int, dy:Int, acc: Int):Int = {
    if (dx.abs + dy.abs == 0)  acc
    else if (s.isEmpty) -1
     else {
       val t = M(s.next())
       solveDist(s,mv(dx,t._1), mv(dy,t._2), acc+1)
     }
  }
  def solve(s:Iterator[Char], sx:Int, sy:Int, ex:Int, ey:Int):Int = solveDist(s, sx-ex, sy-ey,0)

  def main(args: Array[String]) {
   val scan = new Scanner(System.in)
   scan.nextInt()
   val sx = scan.nextInt
   val sy = scan.nextInt
   val ex = scan.nextInt
   val ey = scan.nextInt
   val c = scan.next
   println(solve(c.iterator,sx,sy,ex,ey))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(t, x1, y1, x2, y2) = in.next().split(' ').map(_.toInt)
  val (tr, xr, yr) = in.next().foldLeft((0, 0, 0)) {
    case ((time, x, y), _) if x == x2 && y == y2 => (time, x, y)
    case ((time, x, y), 'N') if y < y2 => (time + 1, x, y + 1)
    case ((time, x, y), 'S') if y > y2 => (time + 1, x, y - 1)
    case ((time, x, y), 'W') if x < x2 => (time + 1, x - 1, y)
    case ((time, x, y), 'E') if x < x2 => (time + 1, x + 1, y)
    case ((time, x, y), _) => (time + 1, x, y)
  }
  if (xr == x2 && yr == y2)
    println(tr)
  else
    println(-1)

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(t, x1, y1, x2, y2) = in.next().split(' ').map(_.toLong)
  val (tr, xr, yr) = in.next().foldLeft((0l, 0l, 0l)) {
    case ((time, x, y), _) if x == x2 && y == y2 => (time, x, y)
    case ((time, x, y), 'N') if y < y2 => (time + 1, x, y + 1)
    case ((time, x, y), 'S') if y > y2 => (time + 1, x, y - 1)
    case ((time, x, y), 'W') if x < x2 => (time + 1, x - 1, y)
    case ((time, x, y), 'E') if x < x2 => (time + 1, x + 1, y)
    case ((time, x, y), _) => (time + 1, x, y)
  }
  if (xr == x2 && yr == y2)
    println(tr)
  else
    println(-1)

}

object Solution {

  def main(args: Array[String]) {
    val si = io.Source.stdin.getLines
    val Array(n, s1, s2, e1, e2) = si.next.split(' ').map(_.toInt)
    val w = si.next.toArray

    var v = e2 - s2
    var vd = 'N'
    if (v < 0) {
      vd = 'S'
    }

    var h = e1 - s1
    var hd = 'E'
    if (h < 0) {
      hd = 'W'
    }

    var sec = -1

    (0 to w.length - 1) foreach {i =>
      if(v != 0 && w(i) == vd) v -= 1
      else if (h != 0 && w(i) == hd) h -= 1

      if(h == 0 && v == 0 && sec == -1) {
        sec = i + 1
      }
    }

    if (sec > n) sec == -1

    println(sec)

  }

}

object Solution {

  def main(args: Array[String]) {
    val si = io.Source.stdin.getLines
    val Array(n, s1, s2, e1, e2) = si.next.split(' ').map(_.toInt)
    val w = si.next.toArray

    var v = e2 - s2
    var vd = 'N'
    if (v < 0) {
      vd = 'S'
    }

    var h = e1 - s1
    var hd = 'E'
    if (h < 0) {
      hd = 'W'
    }

    var sec = -1

    (0 to w.length - 1) foreach {i =>
      if(w(i) == vd) v -= 1
      else if (w(i) == hd) h -= 1

      if(h == 0 && v == 0 && sec == -1) {
        sec = i + 1
      }
    }

    if (sec > n) sec == -1

    println(sec)

  }

}

object Main {
  val sdir: PartialFunction[Char, (Int, Int)] = { case 'S' => (0, -1) }
  val ndir: PartialFunction[Char, (Int, Int)] = { case 'N' => (0,  1) }
  val edir: PartialFunction[Char, (Int, Int)] = { case 'E' => ( 1, 0) }
  val wdir: PartialFunction[Char, (Int, Int)] = { case 'W' => (-1, 0) }
  val nop: PartialFunction[Char, (Int, Int)] = { case _ => (0, 0) }

  def main(args: Array[String]) {
    val op = readLine().split(" ").map(_.toInt)
    val a = readLine()
    val dir = ((op(3) - op(1)).signum, (op(4) - op(2)).signum) match {
      case (1, 1) => ndir orElse edir orElse nop
      case (1, 0) => ndir orElse nop
      case (1, -1) => ndir orElse wdir orElse nop
      case (-1, 1) => sdir orElse edir orElse nop
      case (-1, 0) => sdir orElse nop
      case (-1, -1) => sdir orElse wdir orElse nop
      case (0, 1) => edir orElse nop
      case (0, 0) => nop
      case (0, -1) => wdir orElse nop
    }
    val r = a.scanLeft(op(1), op(2)) { (pos, c) =>
      var nd = dir(c)
      (pos._1 + nd._1, pos._2 + nd._2)
    }
    val ho = r.zipWithIndex.find(_._1._1 == op(3)).map(_._2)
    val vo = r.zipWithIndex.find(_._1._2 == op(4)).map(_._2)
    (ho, vo) match {
      case (Some(h), Some(v)) => println(h.max(v))
      case _ => println("-1")
    }
  }
}


import Utils._, annotation.tailrec, collection.mutable, util._, control._, math.Ordering.Implicits._, collection.Searching._

object _745B extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll, writeLine}
    val n, m = read[Int]

    val row = Array.ofDim[Int](n)
    val col = Array.ofDim[Int](m)

    row.indices foreach {r =>
      val line = read[String]
      line.indices foreach {c =>
        if (line(c) == 'X') {
          row(r) += 1
          col(c) += 1
        }
      }
    }

    val rr = row.toSet - 0
    val cc = col.toSet - 0
    val ans = rr.size == 1 && cc.size == 1

    write(ans.toEnglish)
  }
}
/****************************[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()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "YES" else "NO"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

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

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

  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 = "\n"): 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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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
      }
    }
  }
}

import java.io._
import scala.io.Source

import scala.annotation.tailrec

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

  def processStdInOut(): Unit = {
    val src = Source.fromInputStream(System.in)
    processFromSource(src)
  }

  def processFromSource(src: Source): Unit = {
    try {
      val bw = new BufferedWriter(new OutputStreamWriter(System.out));
      try {
        val lines = src.getLines()
        processLines(lines, bw)
      } finally {
        bw.flush()
      }
    } finally {
      src.close();
    }
  }

  // Standard code above, custom code below

  def processLines(lines: Iterator[String], bw: BufferedWriter): Unit = {
    val dims = lines.next().split(" ").map(_.toInt)
    val rowCount = dims(0)
    val colCount = dims(1)
    val emptyRow = "." * colCount
    var nonEmptyRow: Option[String] = None
    var inRectangle = false

    def doesRowHaveHoles(row: String): Boolean = {
      val (start, afterStart) = row.partition(_ == '.')
      val (pieces, end) = afterStart.partition(_ != '.')
      end.exists(_ != '.')
    }

    def isNextRowValid(i: Int): Boolean = {
      val row = lines.next()
      val isRowEmpty = row.forall(_ == '.')
      nonEmptyRow match {
        // First row not found yet...
        case None if isRowEmpty => true          // First row with parts of piece not found yet, so all fine
        case None => {
          nonEmptyRow = Some(row)
          inRectangle = true
          !doesRowHaveHoles(row)    // Don't allow a row with holes
        }

        // In rectangle:
        case Some(rowPatternToMatch) if inRectangle => if (isRowEmpty) {
          inRectangle = false  // an empty row means we are no longer in the rectangle
          true
        } else {
          row == rowPatternToMatch
        }

        // After rectangle:
        case _ => isRowEmpty  // All rows after the rectangular piece must be empty
      }
    }

    val validRows = (0 until rowCount).map(isNextRowValid)
    val soln = validRows.forall(isValid => isValid)
    bw.write(if (soln) "YES" else "NO")
    bw.newLine()
  }
}


object Main {
  def main(args: Array[String]) {
    val n = readLong()
    val a = readLine().split(" ").map(_.toInt).zipWithIndex.sortBy(_._1).map(_._2.toLong)

    val m = readLong();
    val r = readLine().split(" ").map(_.toLong)
    val r1 = r.map(i => a(i.toInt - 1) + 1L).sum
    val r2 = (n + 1) * m - r1
    println(r1 + " " + r2)
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val index = Array.ofDim[Int](n)
  val data = in.next().split(' ').map(_.toInt)
  data.indices.foreach { i =>
    index(data(i) - 1) = i
  }
  val m = in.next().toInt
  val res =  in.next().split(' ').map(_.toInt).foldLeft(0l, 0l) {
    case((left, right), i) =>
      (left + index(i - 1) + 1, right + n - index(i - 1))
  }

  println(s"${res._1} ${res._2}")
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt).zipWithIndex.sortBy(_._1).map(_._2)

    val m = readInt();
    val r = readLine().split(" ").map(_.toInt)
    val r1 = r.map(i => a(i - 1) + 1).sum
    val r2 = (n + 1) * m - r1
    println(r1 + " " + r2)
  }
}


object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val Array(n, x) = in.next().split(" ").map(_.toInt)
  val data = Range(0, n).map{ i =>
    val Array(a, b) = in.next().split(" ").map(_.toInt)
    (a, b)}.sorted
  println(data.foldLeft((1, 0)) {
    case((current_min, watched), (start, finish)) if finish < current_min =>
      (current_min, watched)
    case((current_min, watched), (start, finish)) =>
      val nStart = (start - current_min) / x * x
      (finish + 1, watched + (finish - current_min - nStart + 1))
  }._2)
}

import java.util.StringTokenizer

object _499A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val x = next.toInt
  val (l, r) = (1 to n).map(i => (next.toInt, next.toInt)).toArray.unzip

  def doit(i: Int, t: Int, acc: Int): Int = {
    if (i == n) acc
    else if (t < l(i)) {
      if (t + x <= l(i)) doit(i, t + x, acc)
      else doit(i, t + 1, acc + 1)
    } else doit(i + 1, r(i) + 1, acc + r(i) - l(i) + 1)
  }

  println(doit(0, 1, 0))
}

object A499 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = readInts(2)
    val in = Array.fill(n)(readInts(2)).map(arr => (arr(0), arr(1)))
    var curr = 1
    var res = 0
    for(i <- in.indices) {
      if(in(i)._1 >= curr + x) {
        res += (in(i)._1 - curr) % x
      } else {
        res += (in(i)._1 - curr)
      }
      res += in(i)._2 - in(i)._1 + 1
      curr = in(i)._2 + 1

      //dlksj
    }
    println(res)
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

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

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

}

import scala.io.StdIn

object A extends App {
  def readPair() = {
    val a = StdIn.readLine() split " " map { _.toInt }
    (a(0), a(1))
  }

  val (n, x) = readPair()

  var res = 0
  var c = 1
  for (i <- 1 to n) {
    val (l, r) = readPair()

    res = res + (l - c) % x + (r - l) + 1
    c = r + 1
  }

  Console.println(res)
}

object Main extends App {

  val Array(n, x) = readLine.split(" ").map(_.toInt)
  val init = (1, 0)
  val (_, total) = (1 to n).foldLeft(init) {
    case ((cursor, total), _) =>
       val Array(from, to) = readLine.split(" ").map(_.toInt)
       (to+1, total + 1 + (to-from) + ((from-cursor) % x))
  }
  println(total)

}

import java.io._

object Problem499A extends App {
  val problem = new Problem499A(
    new InputStreamReader(System.in),
    new OutputStreamWriter(System.out)
  )

  problem.run()
}

class Problem499A(input: Reader, output: Writer) {
  private val tokenizer = new StreamTokenizer(new BufferedReader(input))

  private var currentMinute = 1
  private var rewindSize = 0
  private var seenMinutes: Int = 0

  def run(): Unit = {
    tokenizer.eolIsSignificant(true)

    var n = readInt()
    rewindSize = readInt()
    tokenizer.nextToken() // Next line

    while (n > 0) {
      readBestMoments()

      n -= 1
    }

    output.write(seenMinutes.toString)
    output.flush()
  }

  private def readBestMoments(): Unit = {
    val start = readInt()
    val end = readInt()
    tokenizer.nextToken()

    val minutesToStart = start - currentMinute
    seenMinutes += minutesToStart % rewindSize + (end - start + 1)

    currentMinute = end + 1
  }

  private def readInt(): Int = {
    if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER) {
      throw new RuntimeException("Integer expected")
    }

    tokenizer.nval.toInt
  }
}

import java.io._

object Problem499A extends App {
  val problem = new Problem499A(
    new InputStreamReader(System.in),
    new OutputStreamWriter(System.out)
  )

  problem.run()
}

class Problem499A(input: Reader, output: Writer) {
  private val tokenizer = new StreamTokenizer(new BufferedReader(input))

  private var currentMinute = 1
  private var rewindSize = 0
  private var seenMinutes: Int = 0

  def run(): Unit = {
    tokenizer.eolIsSignificant(true)

    var n = readInt()
    rewindSize = readInt()
    tokenizer.nextToken() // Next line

    while (n > 0) {
      readBestMoments()

      n -= 1
    }

    output.write(seenMinutes.toString)
  }

  private def readBestMoments(): Unit = {
    val start = readInt()
    val end = readInt()
    tokenizer.nextToken()

    val minutesToStart = start - currentMinute
    seenMinutes += minutesToStart % rewindSize + (end - start + 1)

    currentMinute = end + 1
  }

  private def readInt(): Int = {
    if (tokenizer.nextToken() != StreamTokenizer.TT_NUMBER) {
      throw new RuntimeException("Integer expected")
    }

    tokenizer.nval.toInt
  }
}


import scala.io.StdIn.readLine

object A {

  def solution(a: Seq[Int], k: Int): Boolean = {
    val cc = a.count(_ % 2 == 0)
    if (cc == a.length)
      false
    else if (cc == 0)
      k % 2 != 0
    else
      k < a.length || (a.length - cc) % 2 == 1
  }

  def main(args: Array[String]): Unit = {
    for {_ <- 0 until readLine.toInt} {
      val Seq(_, k) = readLine.split(" ").toSeq.map(_.toInt)
      val a = readLine.split(" ").toSeq.map(_.toInt)
      println(if (solution(a, k)) "Yes" else "No")
    }
  }
}

//package codeforces.contests._1363

object OddSelection {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(n, x) = io.StdIn.readLine.split(" ").map(_.toInt)

      val odds = io.StdIn.readLine.split(" ").map(_.toInt).count(_ % 2 == 1)
      val evens = n - odds

      if (evens == 0) {
        println(if (x % 2 == 1) "Yes" else "No")
      } else {
        val requested = { // 5 then need 5 odds, if 6 then need 7 odds, if evens == 0
          val r = (x - evens) max 0
          r + (if (r % 2 == 0) 1 else 0)
        }

        val available = requested <= odds

        println(if (available) "Yes" else "No")
      }
    }
  }
}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nx = readIntLine()
      val arr = readIntLine()
      val ans = can(arr, nx.last)
      println(if (ans) "Yes" else "No")
    }
    //      println(calcWays(4, 5))
  }

  def can(list: List[Int], x: Int) = {
    (1 to (x + 1) / 2).exists(i => list.count(_ % 2 == 1) >= 2 * i - 1 && list.count(_ % 2 == 0) >= x - 2 * i + 1)
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

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

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CF646(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())

    def nextLong(): Long = java.lang.Long.parseLong(next())

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(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 TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

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

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class CF646(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val T = ni()
    REP(T) { _ =>
      val n = ni()
      val x = ni()
      val a = na(n)

      var cntO = 0
      var cntE = 0

      REP(n) { i =>
        if(a(i) % 2 == 0) cntE += 1
        else cntO += 1
      }

      if(cntE >= x && cntO > 0) {
        out.println("Yes")
      } else if(cntO > 0) {
        val rm = x - cntE
        if(rm % 2 != 0 && cntO >= rm) out.println("Yes")
        else if(cntE > 0 && cntO >= rm + 1) out.println("Yes")
        else out.println("No")
      } else out.println("No")
    }
  }
}

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

  override def solve(io: IO) = io.repeat {
    val n, x = io.read[Int]
    val xs = io.read[List, Int](n)
    val evens = xs.count(_%2 == 0)
    val odds = n - evens
    val ans = (1 to odds by 2).exists(o => (x - o) >= 0 && (x - o) <= evens)
    io.write(ans.toEnglish)
  }
}
/****************************[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 solve(io: IO): Any
  def main(args: Array[String]): Unit = {
    val io = new IO(System.in, System.out)
    try solve(io) finally io.close()
  }
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None

  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)

  val charToInt: Char => Int = Character.getNumericValue
  val intToChar: Int => Char = Character.forDigit(_, 10)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  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
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }

  implicit class IntExtensions(val x: Int) extends AnyVal {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }

  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]

  def memoize[A, B](f: A => B): A => B = map[A] using f
}
/***********************************[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")

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

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

  def repeat(f: => Unit): Unit = Utils.repeat(read[Int]){f; writeLine()}

  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
      }
    }
  }
}

//package codeforces.contests._1363

object OddSelection {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val Array(n, x) = io.StdIn.readLine.split(" ").map(_.toInt)

      val odds = io.StdIn.readLine.split(" ").map(_.toInt).count(_ % 2 == 1)
      val evens = n - odds

      val requested = { // 5 then need 5 odds, if 6 then need 7 odds
        val r = (x - evens) max 0
        r + (if (r % 2 == 0) 1 else 0)
      }

      val available = requested <= odds

      println(if (available) "Yes" else "No")
    }
  }
}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    val t = readLine().toInt
    for (i <- 1 to t) {
      val nx = readIntLine()
      val arr = readIntLine()
      val ans = can(arr, nx.last)
      println(if (ans) "Yes" else "No")
    }
    //      println(calcWays(4, 5))
  }

  def can(list: List[Int], x: Int) = {
    (1 to (x + 1) / 2).exists(i => list.count(_ % 2 == 1) >= 2 * i + 1 && list.count(_ % 2 == 0) >= x - 2 * i - 1)
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

  def printArray[T](arr: Array[T]) {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

}

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

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new CF646(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = Integer.parseInt(next())

    def nextLong(): Long = java.lang.Long.parseLong(next())

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(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 TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

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

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class CF646(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val T = ni()
    REP(T) { _ =>
      val n = ni()
      val x = ni()
      val a = na(n)

      var cntO = 0
      var cntE = 0

      a.foreach { f =>
        if(f%2 == 0) cntE += 1
        else cntO += 1
      }

      if(cntO % 2 != 0) {
        out.println("Yes")
      } else {
        if(cntO > 0) {
          if(cntO + cntE - 1 >= x) {
            out.println("Yes")
          } else out.println("No")
        } else out.println("No")
      }
    }
  }
}