//package codeforces.contest1139
import scala.collection.immutable.TreeSet

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedVertexSet(v: Int, p: Int, set: Set[Int])(implicit graph: Graph): Set[Int] = {
    graph.get(v).map(neighbors => neighbors.filter(_ != p).foldLeft(set + v)((res, neighbor) => connectedVertexSet(neighbor, v, res)))
      .getOrElse(set + v)
  }

//  def connectedComponentSizesList(graph: Graph): List[Int] = {
//    graph.keySet.foldLeft((TreeSet[Int](), List[Int]())) {
//      case ((visited: Set[Int], result: List[Int]), root: Int) =>
//        if (!visited(root)) {
//          val vertexSet = connectedVertexSet(root, -1, Set[Int]())(graph)
//          (visited ++ vertexSet, vertexSet.size :: result)
//        } else
//          (visited, result)
//    }._2
//  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          //          val vertexSet = collection.mutable.Set[Int](root)
          //          connectedVertexSet(root, -1)(graph, vertexSet)
          val vertexSet = connectedVertexSet(root, -1, Set[Int]())(graph)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedVertexSet(root: Int, graph: Graph): Set[Int] = {
    def connectedVertexSet(v: Int, p: Int)(implicit set: collection.mutable.Set[Int]): Unit= {
      for {
        neighbors <- graph.get(v)
        neighbor <- neighbors
        if neighbor != p
      } {
        set += neighbor
        connectedVertexSet(neighbor, v)
      }
    }

    val result = collection.mutable.Set[Int](root)
    connectedVertexSet(root, -1)(result)
    result.toSet
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          val vertexSet = connectedVertexSet(root, graph)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedVertexSet(v: Int, p: Int)(implicit graph: Graph, set: collection.mutable.Set[Int]): Unit = {
    for {
      neighbors <- graph.get(v)
      neighbor <- neighbors
      if neighbor != p
    } {
      set += neighbor
      connectedVertexSet(neighbor, v)
    }
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          val vertexSet = collection.mutable.Set[Int](root)
          connectedVertexSet(root, -1)(graph, vertexSet)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer
  import java.util.Arrays

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

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

  def solve(): Unit = {
    val N, K = ni()
    val uf = new UnionFind(N)
    REP(N - 1) { _ =>
      val from, to = ni() - 1
      val c = ni()
      if (c == 0) uf.unite(from, to)
    }

    val C = Array.ofDim[Int](N)
    REP(N) { i =>
      C(uf.find(i)) += 1
    }

    var minus = 0L
    REP(N) { i =>
      if (C(i) > 0) {
        // longを超えないだろ
        minus += powMod(C(i), K, MOD)
      }
    }

    val ans = (MOD + powMod(N, K, MOD) - minus % MOD) % MOD
    out.println(ans)
  }

  def powMod(x: Int, n: Int, m: Int): Int = {
    def step(x: Long, n: Int, stack: Long): Long = {
      n match {
        case 0 => stack
        case _ => step(x * x % m, n / 2, if (n % 2 == 1) stack * x % m else stack)
      }
    }
    step(x, n, 1).toInt
  }

  class UnionFind(val n: Int) {
    private val par = Array.ofDim[Int](n)
    REP(n) (i => par(i) = i)
    val rank: Array[Int] = Array.fill[Int](n)(1) // 集合の要素数
    private val visits = Array.ofDim[Int](n) // 訪れた場所をfind毎に用意するのがもったいないのでつかいまわす

    def find(x: Int): Int = {
      var ptr = 0
      def step(x: Int): Int = {
        if (par(x) == x) x
        else {
          visits(ptr) = x
          ptr += 1
          step(par(x))
        }
      }

      val res = step(x)
      REP(ptr){ i => par(visits(i)) = res }
      res
    }

    def unite(x: Int, y: Int): Int = {
      val x1 = find(x)
      val y1 = find(y)
      if (x1 == y1) x1
      else {
        if (rank(x1) < rank(y)) {
          par(x1) = y1
          y1
        } else {
          par(y1) = x1
          if (rank(x1) == rank(y1)) rank(x1) += rank(y1)
          x1
        }
      }
    }

    /**
      * xを解決する必要がないときは直にrankをみる
      */
    def cntNodes(x: Int): Int = rank(find(x))
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null

  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }

  def debug(as: Array[Boolean]): Unit = DEBUG {
    debug(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = DEBUG {
    debug(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = DEBUG {
    debug(as.mkString(" "))
  }

  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }

  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, 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) { i =>
      f(i)
    }
  }

  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]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedVertexSet(v: Int, p: Int)(implicit graph: Graph, set: collection.mutable.Set[Int]): Unit = {
    for {
      neighbors <- graph.get(v)
      neighbor <- neighbors
      if neighbor != p
    } {
      set += neighbor
      connectedVertexSet(neighbor, v)
    }
  }

  def connectedVertexSet(v: Int, p: Int, set: Set[Int])(implicit graph: Graph): Set[Int] = {
    graph.get(v).map(neighbors => neighbors.filter(_ != p).foldLeft(set + v)((res, neighbor) => connectedVertexSet(neighbor, v, res)))
      .getOrElse(set + v)
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          //          val vertexSet = collection.mutable.Set[Int](root)
          //          connectedVertexSet(root, -1)(graph, vertexSet)
          val vertexSet = connectedVertexSet(root, -1, Set[Int]())(graph)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedVertexSet(v: Int, p: Int)(implicit graph: Graph, set: collection.mutable.Set[Int]): Unit = {
    for {
      neighbors <- graph.get(v)
      neighbor <- neighbors
      if neighbor != p
    } {
      set += neighbor
      connectedVertexSet(neighbor, v)
    }
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          val vertexSet = collection.mutable.Set[Int](root)
          connectedVertexSet(root, -1)(graph, vertexSet)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    //    val graph = collection.mutable.Map[Int, Set[Int]]()
    //
    //    1 until n foreach (_ => {
    //      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
    //      graph += (x -> graph.getOrElse(x, Set())) += (y -> graph.getOrElse(y, Set()))
    //
    //      if (color == 0) {
    //        val setX: Set[Int] = graph.getOrElse(x, Set())
    //        val setY: Set[Int] = graph.getOrElse(y, Set())
    //
    //        graph += (x -> (setX + y)) += (y -> (setY + x))
    //      }
    //
    //    })

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph.toMap)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def connectedVertexSet(v: Int, p: Int)(implicit graph: Graph, set: collection.mutable.Set[Int]): Unit = {
    for {
      neighbors <- graph.get(v)
      neighbor <- neighbors
      if neighbor != p
    } {
      set += neighbor
      connectedVertexSet(neighbor, v)
    }
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          val vertexSet = collection.mutable.Set[Int](root)
          connectedVertexSet(root, -1)(graph, vertexSet)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = collection.mutable.Map[Int, Set[Int]]()

    1 until n foreach (_ => {
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      graph += (x -> graph.getOrElse(x, Set())) += (y -> graph.getOrElse(y, Set()))

      if (color == 0) {
        val setX: Set[Int] = graph.getOrElse(x, Set())
        val setY: Set[Int] = graph.getOrElse(y, Set())

        graph += (x -> (setX + y)) += (y -> (setY + x))
      }

    })

    //    (1 until n).foldLeft(graph) { case (graph: Graph, _) =>
    //      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
    //      val g = addSingleVertices(graph, List(x, y))
    //      if (color == 0)
    //        addBidirectionalEdge(g, x, y, color == 1)
    //      else
    //        g
    //    }

    val connectedComponentsSizes = connectedComponentSizesList(graph.toMap)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          val vertexSet = connectedVertexSet(root, graph)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def connectedVertexSet(v: Int, graph: Graph): Set[Int] = {
    def connectedVertexSet(v: Int, p: Int, set: Set[Int] = Set()): Set[Int] =
      graph.get(v).map(_.filter(_ != p).foldLeft(set + v)((res, neighbor) => connectedVertexSet(neighbor, v, res))).getOrElse(set + v)

    connectedVertexSet(v, -1)
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}

//package codeforces.contest1139

object EdgyTrees {
  type Graph = Map[Int, Set[Int]]

  def addBidirectionalEdge(graph: Graph, x: Int, y: Int, color: Boolean): Graph = {
    val setX: Set[Int] = graph.getOrElse(x, Set())
    val setY: Set[Int] = graph.getOrElse(y, Set())

    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def addSingleVertices(graph: Graph, v: List[Int]): Graph = {
    v.foldLeft(graph)((g, v) => g + (v -> g.getOrElse(v, Set())))
  }

  def connectedVertexSet(v: Int, graph: Graph): Set[Int] = {
    def connectedVertexSet(v: Int, p: Int)(implicit set: collection.mutable.Set[Int]): Unit= {
      for {
        neighbors <- graph.get(v)
        neighbor <- neighbors
        if neighbor != p
      } {
        set += neighbor
        connectedVertexSet(neighbor, v)
      }
    }

    val result = collection.mutable.Set[Int]()
    connectedVertexSet(v, -1)(result)
    result.toSet
  }

  def connectedComponentSizesList(graph: Graph): List[Int] = {
    val visited = collection.mutable.Set[Int]()
    graph.keySet.foldLeft(List[Int]()) {
      case (result: List[Int], root: Int) =>
        if (!visited(root)) {
          val vertexSet = connectedVertexSet(root, graph)
          visited ++= vertexSet
          vertexSet.size :: result
        } else result
    }
  }

  def power(n: Int, k: Int, mod: Int): Int = {
    (1 to k).foldLeft(1l)((res, _) => (res * n) % mod).toInt
  }

  def main(args: Array[String]): Unit = {
    val Array(n, k) = io.StdIn.readLine().split(" ").map(_.toInt)

    val graph = (1 until n).foldLeft(Map[Int, Set[Int]]()) { case (graph: Graph, _) =>
      val Array(x, y, color) = io.StdIn.readLine().split(" ").map(_.toInt)
      val g = addSingleVertices(graph, List(x, y))
      if (color == 0)
        addBidirectionalEdge(g, x, y, color == 1)
      else
        g
    }

    val connectedComponentsSizes = connectedComponentSizesList(graph)

    val mod = 1000000007

    val result = power(n, k, mod) - connectedComponentsSizes.foldLeft(0l)((res, size) => (res + power(size, k, mod)) % mod) // n^k - sigma p^k

    println(if (result < 0) result + mod else result)
  }
}


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

object D extends App {
	def pred(x: Int) = (for (e <- f) yield e / x).sum >= k

	def binSearch(pred: Int => Boolean, a: Int, b: Int) = {
		var st = a
		var nd = b
		var ans = 0

		while (st <= nd) {
			val mid = (st + nd) / 2

			if (pred(mid)) {
				ans = ans max mid
				st = mid + 1
			}

			else nd = mid - 1
		}

		ans
	}

	val MAX = 2 * 100000

	val n = InputReader.nextInt
	var k = InputReader.nextInt
	val arr = InputReader.readLine.split(" ").map(_.toInt)

	var f = Array.fill(MAX + 1)(0)

	for (e <- arr) f(e) += 1

	val ans = binSearch(pred, 1, n)

	for(i <- 1 to MAX) f(i) /= ans

	val out = new PrintWriter(System.out)

	for {
		e <- arr
		if f(e) > 0
		if k > 0
	} {
		out.print(s"$e ")
		f(e) -= 1
		k -= 1
	}

	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	var tk = new StringTokenizer("")

	def read() = {
		while (!tk.hasMoreTokens)
			tk = new StringTokenizer(readLine)

		tk.nextToken
	}

	def readLine() = rd.readLine
	def nextInt() = read.toInt
	def nextLong() = read.toLong
	def nextDouble() = read.toDouble
}

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

object D extends App {
	def pred(x: Int) = (for (e <- f) yield e / x).sum >= k

	def binSearch(pred: Int => Boolean, a: Int, b: Int) = {
		var st = a
		var nd = b
		var ans = 0

		while (st <= nd) {
			val mid = (st + nd) / 2

			if (pred(mid)) {
				ans = ans max mid
				st = mid + 1
			}

			else nd = mid - 1
		}

		ans
	}

	def constructAnswer(x: Int) = {
		val arr = Array.fill(k)(0)
		var p = 0

		for ((e, i) <- f.zipWithIndex) {
			var v = e / x

			while (p < k && v > 0) {
				arr(p) = i
				p += 1
				v -= 1
			}
		}

		arr
	}

	val MAX = 2 * 100000

	val n = InputReader.nextInt
	val k = InputReader.nextInt
	val arr = InputReader.readLine.split(" ").map(_.toInt)

	val f = Array.fill(MAX + 1)(0)

	for (e <- arr) f(e) += 1

	val ans = binSearch(pred, 1, n)

	val out = new PrintWriter(System.out)
	constructAnswer(ans).foreach(x => out.print(s"$x "))
	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	var tk = new StringTokenizer("")

	def read() = {
		while (!tk.hasMoreTokens)
			tk = new StringTokenizer(readLine)

		tk.nextToken
	}

	def readLine() = rd.readLine
	def nextInt() = read.toInt
	def nextLong() = read.toLong
	def nextDouble() = read.toDouble
}

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

object D extends App {
	def pred(x: Int) = (for (e <- f) yield e / x).sum >= k

	def binSearch(pred: Int => Boolean, a: Int, b: Int) = {
		var st = a
		var nd = b
		var ans = 0

		while (st <= nd) {
			val mid = (st + nd) / 2

			if (pred(mid)) {
				ans = ans max mid
				st = mid + 1
			}

			else nd = mid - 1
		}

		ans
	}

	def constructAnswer(x: Int) = {
		val arr = Array.fill(k)(0)
		var p = 0

		for ((e, i) <- f.zipWithIndex) {
			var v = e / x

			while (p < k && v > 0) {
				arr(p) = i
				p += 1
				v -= 1
			}
		}

		arr
	}

	val MAX = 2 * 100000

	val n = InputReader.nextInt
	val k = InputReader.nextInt
	val arr = InputReader.readLine.split(" ").map(_.toInt)

	val f = Array.fill(MAX + 1)(0)

	for (e <- arr) f(e) += 1

	val ans = binSearch(pred, 1, n)

	constructAnswer(ans).foreach(x => print(s"$x "))
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	var tk = new StringTokenizer("")

	def read() = {
		while (!tk.hasMoreTokens)
			tk = new StringTokenizer(readLine)

		tk.nextToken
	}

	def readLine() = rd.readLine
	def nextInt() = read.toInt
	def nextLong() = read.toLong
	def nextDouble() = read.toDouble
}

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

object D extends App {
	def pred(x: Int) = (for (e <- f) yield e / x).sum >= k

	def binSearch(pred: Int => Boolean, a: Int, b: Int) = {
		var st = a
		var nd = b
		var ans = 0

		while (st <= nd) {
			val mid = (st + nd) / 2

			if (pred(mid)) {
				ans = ans max mid
				st = mid + 1
			}

			else nd = mid - 1
		}

		ans
	}

	def constructAnswer(x: Int) = {
		val arr = Array.fill(k)(0)
		var p = 0

		for ((e, i) <- f.zipWithIndex) {
			var v = e / x

			while (p < k && v > 0) {
				arr(p) = i
				p += 1
				v -= 1
			}
		}

		arr
	}

	val MAX = 2 * 100000

	val n = InputReader.nextInt
	val k = InputReader.nextInt
	val arr = InputReader.readLine.split(" ").map(_.toInt)

	val f = Array.fill(MAX + 1)(0)

	for (e <- arr) f(e) += 1

	val ans = binSearch(pred, 1, n)

	val out = new PrintWriter(System.out)
	out.println(constructAnswer(ans).mkString(" "))
	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	var tk = new StringTokenizer("")

	def read() = {
		while (!tk.hasMoreTokens)
			tk = new StringTokenizer(readLine)

		tk.nextToken
	}

	def readLine() = rd.readLine
	def nextInt() = read.toInt
	def nextLong() = read.toLong
	def nextDouble() = read.toDouble
}

object CF_521_3_D {
  def solve(n: Int, k: Int, ss: Seq[Int]): Seq[Int] = {
    val counts: Map[Int, Int] = ss.groupBy(identity).mapValues(_.size)
    // sort biggest first so we can stop early
    val ordered = counts.toSeq.sortWith(_._2 > _._2).toStream
    // `trial` is the number of copies of t. Start with 1 and increase until it's not possible to build such a Seq
    // It's possible if we can find k or more elements that have enough copies.
    def isPossible(trial: Int, xs: Seq[(Int, Int)], found: Int, out: Seq[Int]): Option[Seq[Int]] =
      if(found >= k) Some(out.take(k))
      else if(xs.isEmpty) None
      else {
        val (e, c) = xs.head
        // instances is the number of instances of xs.head we'll use
        val instances = c/trial
        if (instances < 1) None
        else {
          val add = Seq.fill(instances)(e)
          isPossible(trial, xs.tail, found + instances, out ++ add)
        }
      }
    def find(trial: Int, best: Seq[Int]): Seq[Int] = {
      val poss = isPossible(trial, ordered, 0, Vector.empty)
      poss match {
        case None => best
        case Some(seq) => find(trial + 1, seq)
      }
    }

    find(1,Seq.empty)
  }

  // Specify Input and Output formats here:
  def formatIn(i: Input) = (i.int, i.int, {i.nextLine; i.intSeq})
  def formatOut(out: Seq[Int]) = out.mkString(" ")

//     ~~~ Boilerplate that doesn't change ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

  def main(args: Array[String]) = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

//     ~~~ Utility methods ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  import java.util.Scanner
  class Input(sc: Scanner) {
    def this(i: java.io.InputStream) = this(new Scanner(i))
    def this(s: String) = this(new Scanner(s.stripMargin))
    def int = sc.nextInt()
    def long = sc.nextLong()
    def double = sc.nextDouble()
    def nextLine = sc.nextLine()
    // If there are prior values, remember to call nextLine to advance past the newline character before collecting the line:
    def collect[T](f: String => T) = {sc.nextLine().split(" ").toVector.map(f)}
    def intSeq() = collect(_.toInt)
    def doubleSeq() = collect(_.toDouble)
    def solveVals = (solve _).tupled(formatIn(this))
    def solveStr = formatOut(solveVals)
  }

  def ceil(a: Int, b: Int) = (a - 1) / b + 1
  def ceil(a: Long, b: Long) = (a - 1) / b + 1

  import language.implicitConversions
  implicit def stringToInput(s: String): Input = new Input(s)
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

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

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

  def solve(): Unit = {
    val N, K = ni()
    val S = na(N)
    val C = Array.ofDim[Int](2e5.toInt + 1)
    rep(N) { i =>
      C(S(i)) += 1
    }

    case class Elm(cnt: Int, num: Int) extends Comparable[Elm] {
      override def compareTo(o: Elm): Int = Integer.compare(o.cnt, cnt) // desc
    }

    val queue = new java.util.PriorityQueue[Elm]()
    rep(C.length) { i =>
      if (C(i) > 0) queue.add(Elm(C(i), i))
    }

    val times = Array.ofDim[Int](2e5.toInt + 1)
    val ans = ArrayBuffer[Int]()
    while (ans.length < K) {
      val a = queue.poll()
      ans += a.num
      times(a.num) += 1
      queue.add(Elm(C(a.num) / (times(a.num) + 1) , a.num))
    }

    out.println(ans.mkString(" "))
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, 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 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]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    rep(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

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

object D extends App {
	def pred(x: Int) = (for (e <- f) yield e / x).sum >= k

	def binSearch(pred: Int => Boolean, a: Int, b: Int) = {
		var st = a
		var nd = b
		var ans = 0

		while (st <= nd) {
			val mid = (st + nd) / 2

			if (pred(mid)) {
				ans = ans max mid
				st = mid + 1
			}

			else nd = mid - 1
		}

		ans
	}

	val MAX = 2 * 100000

	val n = InputReader.nextInt
	var k = InputReader.nextInt
	val arr = InputReader.readLine.split(" ").map(_.toInt)

	var f = Array.fill(MAX + 1)(0)

	for (e <- arr) f(e) += 1

	val ans = binSearch(pred, 1, n)

	f = f.map(_ / ans)

	val out = new PrintWriter(System.out)

	for(e <- arr) {
		if(f(e) > 0 && k > 0) {
			out.print(s"$e ")
			f(e) -= 1
			k -= 1
		}
	}

	out.close
}

object InputReader {
	val rd = new BufferedReader(new InputStreamReader(System.in), 32768);
	var tk = new StringTokenizer("")

	def read() = {
		while (!tk.hasMoreTokens)
			tk = new StringTokenizer(readLine)

		tk.nextToken
	}

	def readLine() = rd.readLine
	def nextInt() = read.toInt
	def nextLong() = read.toLong
	def nextDouble() = read.toDouble
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

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

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

  def solve(): Unit = {
    val N, K = ni()
    val S = na(N)
    val C = Array.ofDim[Int](2e5.toInt + 1)
    rep(N) { i =>
      C(S(i)) += 1
    }

    case class Elm(cnt: Int, num: Int) extends Comparable[Elm] {
      override def compareTo(o: Elm): Int = Integer.compare(o.cnt, cnt) // desc
    }

    val queue = new java.util.PriorityQueue[Elm]()
    rep(C.length) { i =>
      if (C(i) > 0) queue.add(Elm(C(i), i))
    }

    val times = Array.ofDim[Int](2e5.toInt + 1)
    val ans = ArrayBuffer[Int]()
    while (ans.length < K) {
      val a = queue.poll()
      ans += a.num
      times(a.num) += 1
      queue.add(Elm(a.cnt / (times(a.num) + 1) , a.num))
    }

    out.println(ans.mkString(" "))
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, 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 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]) = {
    val cum = Array.ofDim[Int](as.length + 1)
    rep(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}


object ProblemB extends App {

  import java.io.{BufferedReader, InputStreamReader, PrintWriter}
  import java.util.StringTokenizer

  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  class FastScanner(val in: BufferedReader) {
    var st: StringTokenizer = _;

    def nextToken(): String = {
      while (st == null || !st.hasMoreTokens) {
        st = new StringTokenizer(in.readLine);
      }
      return st.nextToken();
    }

    def nextInt(): Integer = {
      Integer.parseInt(nextToken());
    }

    def nextLong(): Long = {
      nextToken().toLong;
    }

    def nextDouble(): Double = {
      nextToken().toDouble;
    }
  }

  val t = in.nextInt()
  for (_ <- 1 to t) {
    val m = in.nextInt()
    val s = in.nextToken()
    var hasOne = false
    var onePosition = -1
    var lastZero = -1

    for (i <- 0 until s.length) {
      if (s(i) == '0' && hasOne) {
        lastZero = i
      } else if (s(i) == '1' && !hasOne) {
        hasOne = true
        onePosition = i
      }
    }

    val res = if (hasOne && lastZero != -1) {
      s.take(onePosition) + s.takeRight(s.length - lastZero)
    } else {
      s
    }

    println(res)
  }

}

import java.util.StringTokenizer

import scala.io.StdIn

object Main {
  object Scanner {
    private var st: StringTokenizer = _

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

    def nextInt: Int = nextToken().toInt
    def nextLong: Long = nextToken().toLong
    def nextShort: Short = nextToken().toShort
    def nextByte: Byte = nextToken().toByte
  }

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to Scanner.nextInt) {
      val n = Scanner.nextInt
      val s = StdIn.readLine()
      var m1 = 0
      while (m1 < n && s(m1) == '0') {
        m1 += 1
      }
      var m2 = 0
      while (m2 < n && s(n - m2 - 1) == '1') {
        m2 += 1
      }
      if (m1 + m2 == n) {
        println(s)
      } else {
        for (_ <- 1 to m1) {
          print('0')
        }
        print('0')
        for (_ <- 1 to m2) {
          print('1')
        }
        println()
      }
    }
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    val kd = readLine().split(" ").map(_.toInt)
    val k = kd(0)
    val d = kd(1)

    if (k == 1) println(d)
    else if (d == 0) println("No solution")
    else println((Seq(d) ++ (1 to (k - 1)).map(_ => 0)).mkString)
  }
}

import java.util.Scanner

object Sum {
  class Sum{
  def max(a:Char,b:Char):Char=
     if (a<b)
        a
    else
        b
  }
  def taskA(){
    val F=new Sum
      val in = new Scanner(System.in)
      val s=readLine()
      var ans = if(s(0)!='-') s else s.substring(0,s.length()-2)+F.max(s(s.length()-1),s(s.length()-2))
      if(ans(0)=='-' && ans(1)=='0'){
        print(0)
      }
      else
          print(ans)

  }
  def taskB(){
    val in = new Scanner(System.in)
    val s = in.nextLine()
    var arr=new Array[Int](s.length()+5)
    arr(0)=0
    for{i<-1 to s.length()-1}
        if (s(i)==s(i-1)){
          arr(i)=arr(i-1)+1
        }
        else
          arr(i)=arr(i-1)
    val k = in.nextInt()

    for{i<-1 to k}{
        val left=in.nextInt()
        var l = if(left>1) left-1 else 0
        val r=in.nextInt()
        var ans = arr(r-1)-arr(l)
        println(ans)
    }

  }

  def taskA_206(){
    val in=new Scanner(System.in)
    val k=in.nextInt()
    val v=in.nextInt()
    val b=if(k>1 && v==0) false else true
    if(b){
        print(v)
        for{i<-1 to k-1}print(0)
    }
    else
      print("No solution")
  }
  def main(args: Array[String]) {
    taskA_206
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  var Array(k, d) = in.next().split(" ").map(_.toInt)
  if (d == 0 && k > 1)
    println("No solution")
  else {
    print(d)
    print("0" * (k - 1))
  }

}

object A355 {

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

  def main(args: Array[String]): Unit = {
    val Array(k, d) = readInts(2)
    if(d == 0 && k > 1)
      println("No solution")
    else
      println((Array(d) ++ Array.fill(k-1)(0)).mkString(""))
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

    @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.util.Random

object P355A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val K, D = sc.nextInt

  def solve(): Unit = {
    (K, D) match {
      case (1, 0) => out.println(0)
      case (_, 0) => out.println("No solution")
      case _      => out.println(D.toString + "0" * (K - 1))
    }
  }

  solve
  out.close
}

import java.util.Scanner

object Sum {
  class Sum{
  def max(a:Char,b:Char):Char=
     if (a<b)
        a
    else
        b
  }
  def taskA(){
    val F=new Sum
      val in = new Scanner(System.in)
      val s=readLine()
      var ans = if(s(0)!='-') s else s.substring(0,s.length()-2)+F.max(s(s.length()-1),s(s.length()-2))
      if(ans(0)=='-' && ans(1)=='0'){
        print(0)
      }
      else
          print(ans)

  }
  def taskB(){
    val in = new Scanner(System.in)
    val s = in.nextLine()
    var arr=new Array[Int](s.length()+5)
    arr(0)=0
    for{i<-1 to s.length()-1}
        if (s(i)==s(i-1)){
          arr(i)=arr(i-1)+1
        }
        else
          arr(i)=arr(i-1)
    val k = in.nextInt()

    for{i<-1 to k}{
        val left=in.nextInt()
        var l = if(left>1) left-1 else 0
        val r=in.nextInt()
        var ans = arr(r-1)-arr(l)
        println(ans)
    }

  }

  def taskA_206(){
    val in=new Scanner(System.in)
    val k=in.nextInt()
    val v=in.nextInt()
    print(v)
    for{i<-1 to k-1}print(0)
  }
  def main(args: Array[String]) {
    taskA_206
  }
}

object A355 {

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

  def main(args: Array[String]): Unit = {
    val Array(k, d) = readInts(2)
    if(d == 0)
      println("0")
    else
      println((Array(d) ++ Array.fill(k-1)(0)).mkString(""))
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

    @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 A355 {

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

  def main(args: Array[String]): Unit = {
    val Array(k, d) = readInts(2)
    println((Array(d) ++ Array.fill(k-1)(0)).mkString(""))
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

    @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.util.Random

object P355A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val K, D = sc.nextInt

  def solve(): Unit = {

    @tailrec
    def loop(acc: Int, x: Int): Int = if (x == 1) acc
                                      else loop(acc * 10, x - 1)

    (K, D) match {
      case (1, 0) => out.println(0)
      case (_, 0) => out.println("No solution")
      case _      => out.println(loop(D, K))
    }
  }

  solve
  out.close
}

object Main {
  def main(args: Array[String]): Unit = {
    val kd = readLine().split(" ").map(_.toInt)
    val k = kd(0)
    val d = kd(1)

    if (k == 1) println(d)
    else if (d == 0) println((Seq(1, 9) ++ (1 to (k - 2)).map(_ => 0)).mkString)
    else println((Seq(d) ++ (1 to (k - 1)).map(_ => 0)).mkString)
  }
}


import scala.io.StdIn._

object taskB extends App {

  val input: Array[Int] = readLine.split(" ").map(_.toInt)
 // println(s"${input(0)} ${input(1)} ${input(2)} ${input(3)}")
  val sizeX = input(0)
  val sizeY = input(1)
  var locX = input(2)
  var locY = input(3)

  println(locX +" "+ locY)

  def visitWholeLine(): Unit = {
    (2 to sizeY).foreach {_ =>
      if (locY == sizeY) locY = 1
      else locY += 1
      println(locX +" "+ locY)
    }
  }

  visitWholeLine()
  (2 to sizeX).foreach { _ =>
    if (locX == sizeX) locX = 1
    else locX += 1
    println(locX +" "+ locY)

    visitWholeLine()
  }

}

object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val n  = in.nextInt()
    val m  = in.nextInt()
    val x1 = in.nextInt()
    val y1 = in.nextInt()

    println(s"$x1 $y1")
    println(s"1 $y1")
    println(s"1 1")

    1.to(n)
      .foreach(r => {
        var start = if (r % 2 == 1) 1 else m
        val inc   = if (r % 2 == 1) 1 else -1
        1.to(m)
          .foreach(_ => {
            val curRow = r
            val curCol = start
            if (!((curRow == x1 && curCol == y1) || (curRow == 1 && curCol == y1) || (curRow == 1 && curCol == 1))) {
              println(s"$curRow $curCol")
            }
            start = start + inc
          })
      })
  }

  try {
    solve()
  } catch {
    case ex: Exception =>
      println(ex)
      sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {

    def this(reader: BufferedReader) = this(new LineNumberReader(reader))

    def this(reader: Reader) = this(new BufferedReader(reader))

    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

    def this(str: String) = this(new StringReader(str))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .map(new StringTokenizer(_))
        .filter(_.hasMoreTokens)
    }

    private[this] var current: Option[StringTokenizer] = None

    @inline private[this] def tokenizer(): Option[StringTokenizer] =
      current.find(_.hasMoreTokens) orElse {
        current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
        current
      }

    /**
      * Unlike Java's scanner which returns till end of current line, this actually returns the next line
      * @see line() if you want the Java behaviour
      */
    def nextLine(): String = {
      current = None // reset
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextString(): String = next()

    def nextChar(): Char = next().ensuring(_.length == 1).head

    def nextBoolean(): Boolean = next().toBoolean

    def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

    def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

    def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

    def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

    def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

    def nextFloat(): Float = next().toFloat

    def nextDouble(): Double = next().toDouble

    def nextBigDecimal(): BigDecimal = BigDecimal(next())

    override def next(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

object B extends App {
  import scala.io.StdIn._

  val Array(n, m, sx, sy) = readLine().split(" ").map(_.toInt)

  (0 until n).foldLeft((sx, sy)) {
    case ((x, y), i) =>
      val moves = (x, y) +: (1 to m).collect { case j if j != y => (x, j) }

      moves.foreach { case (x, y) => println(s"$x $y") }

      moves.last match {
        case (1, y) => (n, y)
        case (x, y) => (x - 1, y)
      }
  }
}

import scala.io.StdIn._

object taskB extends App {

  val input: Array[Int] = readLine.split(" ").map(_.toInt)
 // println(s"${input(0)} ${input(1)} ${input(2)} ${input(3)}")
  val sizeX = input(0)
  val sizeY = input(1)
  var locX = input(2)
  var locY = input(3)

  var visited: List[(Int, Int)] = List((locX, locY))

  def visitWholeLine(): Unit = {
    (2 to sizeY).foreach {_ =>
      if (locY == sizeY) locY = 1
      else locY += 1
      println(locX +" "+ locY)
    }
  }

  visitWholeLine()
  (2 to sizeX).foreach { _ =>
    if (locX == sizeX) locX = 1
    else locX += 1
    println(locX +" "+ locY)

    visitWholeLine()
  }

}

import scala.io.StdIn._

object taskB extends App {

  val input: Array[Int] = readLine.split(" ").map(_.toInt)
 // println(s"${input(0)} ${input(1)} ${input(2)} ${input(3)}")
  val sizeX = input(0)
  val sizeY = input(1)
  var locX = input(2)
  var locY = input(3)

  var visited: List[(Int, Int)] = List((locX, locY))

  def visitWholeLine(): Unit = {
    (2 to sizeY).foreach {_ =>
      if (locY == sizeY) locY = 1
      else locY += 1
      visited = visited :+ (locX, locY)
    }
  }

  visitWholeLine()
  (2 to sizeX).foreach { _ =>
    if (locX == sizeX) locX = 1
    else locX += 1

    visitWholeLine()
  }

  visited.foreach { x =>
    println(s"${x._1} ${x._2}")
  }

}


object prob2 {
  def main(args: Array[String]) = {
    import scala.collection.mutable.ListBuffer
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {
  import java.util.StringTokenizer
  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val n = tokenizer.nextToken().toInt
    for (i <- 1 to n) {
      tokenizer = new StringTokenizer(input.readLine())
      val j = tokenizer.nextToken().toInt
      if (j % 2 != 0) {
        output.println(-1)
      }
      else {
        output.println((j/2).toString + " " +(j/2).toString + " " + "0" )
      }
    }
  }

}

import scala.io.StdIn._

object Main extends App {

  val t = readInt()

  (1 to t).foreach(_ => solution());

  def solution() = {
    val n = readInt()
    if (n % 2 == 0)
      println(s"0 ${n / 2} ${n / 2}")
    else
      println(-1)

  }

}

import scala.io.StdIn

object Main extends App {
  val t = StdIn.readInt()
  for(i <- 0 until t){
    val n = StdIn.readInt()
    if (n % 2 == 1) {
      println(-1)
    } else {
      println("0 0 " + n / 2)
    }
  }
}

object prob2 {
  def main(args: Array[String]) = {
    import scala.collection.mutable.ListBuffer
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {
  import java.util.StringTokenizer
  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val n = tokenizer.nextToken().toInt
    for (i <- 1 to n) {
      tokenizer = new StringTokenizer(input.readLine())
      val j = tokenizer.nextToken().toInt
      if (i % 2 != 0) {
        output.println(-1)
      }
      else {
        output.println((j/2).toString + " " +(j/2).toString + " " + "0" )
      }
    }
  }

}

object prob2 {
  def main(args: Array[String]) = {
    import scala.collection.mutable.ListBuffer
    new Resolver3(Console.in, Console.out).run()
  }
}

class Resolver3(input: java.io.BufferedReader, output: java.io.PrintStream) {
  import java.util.StringTokenizer
  def run() {
    var tokenizer = new StringTokenizer(input.readLine())
    val n = tokenizer.nextToken().toInt
    for (i <- 1 to n) {
      tokenizer = new StringTokenizer(input.readLine())
      val j = tokenizer.nextToken().toInt
      if (i % 2 == 0) {
        output.println(-1)
      }
      else {
        output.println((j/2).toString + " " +(j/2).toString + " " + "0" )
      }
    }
  }

}


object A703 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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))
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = Array.fill(n)(readInts(2)).filter(arr => arr(0) != arr(1))
    val m = input.count(arr => arr(0) > arr(1))
    val c = input.count(arr => arr(0) < arr(1))
    if(m == c) {
      println("Friendship is magic!^^")
    } else if (m > c) {
      println("Mishka")
    } else {
      println("Chris")
    }
  }
}

object mishkaAndGame_703A extends App {

  val rounds = readLine().toInt
  var mishka = 0
  var chris = 0
  for (i <- 0 until rounds){
    val round = readLine().split(" ").toList
    if (round.head > round.last) mishka = mishka + 1
    else if (round.head < round.last) chris = chris + 1
  }

  if (mishka > chris) println("Mishka")
  else if (chris > mishka) println("Chris")
  else  println("Friendship is magic!^^")
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val n = lines.next().toInt
  val (mish, chri) = lines.take(n).map(_.split(' ').map(_.toInt)).foldLeft((0, 0)) {
    case((mishka, chris), Array(m, c)) if m > c => (mishka + 1, chris)
    case((mishka, chris), Array(m, c)) if m < c => (mishka, chris + 1)
    case((mishka, chris), _) => (mishka, chris)
  }
  if (mish > chri)
    println("Mishka")
  else if (mish < chri)
    println("Chris")
  else
    println("Friendship is magic!^^")
}

object A 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)

  var cnt = 0

  for (_ <- 0 until n) {
    val Array(a, b) = readInts(2)
    cnt += Integer.signum(b - a)
  }

  val res = if (cnt < 0) "Mishka"
  else if (cnt > 0) "Chris"
  else "Friendship is magic!^^"

  println(res)
}

/**
  * Created by BFD_299 on 2016/8/5.
  */

object code365A {
  def main(args:Array[String]): Unit ={
    var m = 0
    var c = 0
    val round = io.StdIn.readInt()
    for (i <- 1 to round){
      val cin = io.StdIn.readLine()
      val cins = cin.split(" ")
      if(cins(0) > cins(1)) m += 1
      if(cins(0) < cins(1)) c += 1
    }
    if(m > c) println("Mishka")
    if(m < c) println("Chris")
    if(m == c) println("Friendship is magic!^^")
  }
}

/**
  * Created by BFD_299 on 2016/8/5.
  */

object code365A {
  def main(args:Array[String]): Unit ={
    var m = 0
    var c = 0
    val round = io.StdIn.readInt()
    var cin: String = null
    var cins: Array[String] = null
    for (i <- 1 to round){
      cin = io.StdIn.readLine()
      cins = cin.split(" ")
      if(cins(0) > cins(1)) m += 1
      if(cins(0) < cins(1)) c += 1
    }
    if(m > c) println("Mishka")
    if(m < c) println("Chris")
    if(m == c) println("Friendship is magic!^^")
  }
}

object main extends App{
  val n = readInt
  println(List.range(0, n).foldLeft(Array(0,0))({ (res: Array[Int], i: Int) =>
    val Array(m, c) = readLine.split(" ").map(_.toInt)
    if (m>c) res(0) +=1 else if (m<c) res(1)+=1
    res
  }) match {
    case Array(m, c) => if (m > c) "Mishka" else if ( m<c ) "Chris" else "Friendship is magic!^^"
  })
}

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

object _703A extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write}
    val n = read[Int]
    var mishka, chris = 0
    repeat(n) {
      val m, c = read[Int]
      if (m < c) chris += 1 else if (m > c) mishka += 1
    }

    val ans = if (mishka < chris) {
      "Chris"
    } else if (chris < mishka) {
      "Mishka"
    } else {
      "Friendship is magic!^^"
    }

    write(ans)
  }
}
/****************************[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 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 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, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeOnNextLine(obj: Any, more: Any*): this.type = {
    printer.println()
    write(obj, more: _*)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)

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

object Main extends App {
  import scala.io. { StdIn => In }
  val n = In.readInt
  var s = 0
  for(i <- 0 until n) {
    val Array(u,v) = In.readLine().split(" ").map(_.toInt)
    if (u < v) s -= 1
    else if (u > v) s += 1
  }
  if (s < 0) println ("Chris")
  else if (s > 0) println ("Mishka")
  else println("Friendship is magic!^^")
}

import scala.io.StdIn._

object A extends App {
  val t = readInt()
  var winner = 0
  1 to t foreach { _ =>
    val Array(a, b) = readLine().split(" ").map(_.toInt)
    if (a > b) winner += 1
    else if (b > a) winner -= 1
  }

  if (winner > 0) println("Mishka")
  else if (winner <0) print("Chris")
  else println("Friendship is magic!^^")
}

object mishkaAndGame_703A extends App {

  val rounds = readLine().toInt
  var mishka = 0
  var chris = 0
  for (i <- 0 until rounds){
    val round = readLine().split(" ").toList
    mishka = mishka + round.head.toInt
    chris = chris + round.last.toInt
  }
  if (mishka > chris) println("Mishka")
  else if (chris > mishka) println("Chris")
  else  println("Friendship is magic!^^")
}

object mishkaAndGame_703A extends App {

  val rounds = readLine().toInt
  var mishka = 0
  var chris = 0
  for (i <- 0 until rounds){
    val round = readLine().split(" ").toList
    if (round.head > round.last) mishka = mishka + 1
    else chris = chris + 1
  }
  if (mishka > chris) println("Mishka")
  else if (chris > mishka) println("Chris")
  else  println("Friendship is magic!^^")
}

object mishkaAndGame_703A extends App {

  val rounds = readLine().toInt
  var mishka = 0
  var chris = 0
  for (i <- 0 until rounds){
    val round = readLine().split(" ").toList
    if (round.head > round.last) mishka = mishka + 1
    else chris = chris + 1
  }
  if (mishka > chris) println("Mishka")
  else if (chris > mishka) println("Chris")
  else if (chris < mishka) println("Friendship is magic!^^")
}

object mishkaAndGame_703A extends App {

  val rounds = readLine().toInt
  var mishka = 0
  var chris = 0
  for (i <- 0 until rounds){
    val round = readLine().split(" ").toList
    if (round.head > round.last) mishka = mishka + 1
    else if (round.head > round.last) chris = chris + 1
  }
  if (mishka > chris) println("Mishka")
  else if (chris > mishka) println("Chris")
  else println("Friendship is magic!^^")
}

object A703 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.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))
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = Array.fill(n)(readInts(2)).count(arr => arr(0) > arr(1))
    if(input == n-input) {
      println("Friendship is magic!^^")
    } else if (input > n-input) {
      println("Mishka")
    } else {
      println("Chris")
    }
  }
}

object Main extends App {
  import scala.io. { StdIn => In }
  val n = In.readInt
  var s = 0
  for(i <- 0 until n) {
    val Array(u,v) = In.readLine().split(" ").map(_.toInt)
    if (u < v) s -= -1
    else if (u > v) s += 1
  }
  if (s < 0) println ("Chris")
  else if (s > 0) println ("Mishka")
  else println("Friendship is magic!^^")
}


import scala.io.StdIn

/**
  * @author hongchen.cao
  * @date 2020/03/15 17:55
  **/
object Test {
  def main(args: Array[String]): Unit = {
    val t: Int = StdIn.readInt()
    for (i <- 1 to t) {
      val n = StdIn.readInt()

      val psum = StdIn.readLine().split(" ").map(_.toInt % 2).sum

      psum match {
        case s if s == 0 || s == n => println("YES")
        case _ => println("NO")
      }
    }
  }

}

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 C627A(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 C627A(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t = ni()
    REP(t) { _ =>
      val n = ni()
      val a = na(n).toIndexedSeq.sorted

      var yes = true
      REP(n-1) { i =>
        val x = a(i+1) - a(i)
        yes = yes & (x % 2 == 0)
      }
      if(yes) out.println("YES") else out.println("NO")
    }
  }
}

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

  override def solve(io: IO) = io.repeat {
    val as = io.read[Vector[Int]]

    val diffs = for {
      i <- as.indices.view
      j <- as.indices.drop(i + 1)
    } yield (as(j) - as(i))%2 == 0

    val ans = diffs.forall(identity)

    io.write(ans.toEnglish.toUpperCase)
  }
}
/****************************[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)

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

import scala.io.StdIn

/**
  * @author hongchen.cao
  * @date 2020/03/15 17:55
  **/
object Test {
  def main(args: Array[String]): Unit = {
    val t: Int = StdIn.readInt()
    for (_ <- 1 to t) {
      val n = StdIn.readInt()

      val psum = StdIn.readLine().split(" ").map(_.toInt.%(2)).sum

      psum match {
        case s if s == 0 || s == n => println("YES")
        case _ => println("NO")
      }
    }
  }

}


object A extends App {
  val n = readInt
  val sizes = for(i <- 0 until n) yield readInt
  val ss = sizes.sorted.toArray
  var canfit = 0
  var cantfit = n / 2 + 1
  while(canfit + 1 < cantfit) {
    val attempt = (canfit + cantfit) / 2
    var failed = false
    for(i <- 0 until attempt) {
      if(2 * ss(i) > ss(n-attempt+i)) {
        failed = true
      }
    }
    if(failed)
      cantfit = attempt
    else
      canfit = attempt
  }
  println(n - canfit)
}

import scala.io.Source

object Solution extends App {

  def count(small: List[Int], big: List[Int]): Int = {
    if (small.isEmpty || big.isEmpty) 0
    else if (small.head * 2 <= big.head) 1 + count(small.tail, big.tail)
    else count(small, big.tail)
  }

  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = (1 to n).map(_ => in.next().toInt).sorted.toList
  println(n - count(data.take(n / 2), data.takeRight(n / 2)))
}


object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val Array(n, m) = readInts

  val a = Array.ofDim[Int](n, m)

  for (i <- 0 until n) a(i) = readInts

  val pair = Array.fill(m, m)(0)

  var max = 0
  var row = 0

  while (row < n) {
    var i = 0
    while (i < m - 1) {
      val ai = a(row)(i)
      if (ai > max) {
        var j = i + 1
        while (j < m) {
          val aj = a(row)(j)
          if (aj > max) {
            val aa = math.min(ai, aj)
            val result = math.min(pair(i)(j), aa)
            if (result > max) max = result
            if (aa > result) pair(i)(j) = aa
          }
          j += 1
        }
      }
      i += 1
    }
    row += 1
  }

  println(max)
}

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val Array(n, m) = readInts

  val pair = Array.fill(m, m)(0)

  var max = 0
  var row = 0

  while (row < n) {
    val as = readInts
    var i = 0
    while (i < m - 1) {
      val ai = as(i)
      if (ai > max) {
        var j = i + 1
        while (j < m) {
          val aj = as(j)
          if (aj > max) {
            val aa = math.min(ai, aj)
            val result = math.min(pair(i)(j), aa)
            if (result > max) max = result
            if (aa > result) pair(i)(j) = aa
          }
          j += 1
        }
      }
      i += 1
    }
    row += 1
  }

  println(max)
}

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val Array(n, m) = readInts

  val a = Array.ofDim[Int](n, m)

  for (i <- 0 until n) a(i) = readInts

  val pair = Array.fill(m, m)(0)

  var row = 0
  var max = 0

  while (row < n) {
    var i = 0
    while (i < m - 1) {
      val ai = a(row)(i)
      if (ai > max) {
        var j = i + 1
        while (j < m) {
          val aj = a(row)(j)
          if (aj > max) {
            val aa = math.min(ai, aj)
            val result = math.min(pair(i)(j), aa)
            if (result > max) max = result
            if (aa > result) pair(i)(j) = aa
          }
          j += 1
        }
      }
      i += 1
    }
    row += 1
  }

  println(max)
}

object D extends App {

  def readString = Console.readLine
  def readInts = readString.split(" ").map(_.toInt)

  val Array(n, m) = readInts

  val a = Array.ofDim[Int](n, m)

  for (i <- 0 until n) a(i) = readInts

  val pair = Array.fill(m, m)(0)

  var row = 0
  var max = 0

  while (row < n) {
    var i = 0
    while (i < m - 1) {
      val ai = a(row)(i)
      if (ai > max) {
        var j = i + 1
        while (j < m) {
          val aj = a(row)(j)
          if (aj > max) {
            val aa = math.min(ai, aj)
            val result = math.min(pair(i)(j), aa)
            if (result > max) max = result
            pair(i)(j) = aa
          }
          j += 1
        }
      }
      i += 1
    }
    row += 1
  }

  println(max)
}


import java.io.PrintWriter
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer

// if there is k1 left in G1 and k2 left in G2 and k1 > 0 & k2 > 0 then
//   if we can prove that edge exist which satisfies problem
//   we can add it and move problem to k1-1 & k2-1
//   let's assume that's true
object Solution {
  def solve(input: Int): Int = {
    input
  }

  def run(test: Int, input: Scanner, output: PrintWriter): Unit = {
    output.println(solve(1))
  }

  def connect(colors: Array[Int], v: Int, u: Int): Unit = {
    val toMatch = colors(v)
    colors.indices.foreach { idx =>
      if (colors(idx) == toMatch) colors(idx) = colors(u)
    }
  }

  def connected(colors: Array[Int], v: Int, u: Int): Boolean = colors(v) == colors(u)

  def run(input: Scanner, output: PrintWriter): Unit = {
    val n = input.nextInt()
    val m1 = input.nextInt()
    val m2 = input.nextInt()

    val c1 = (0 until n).toArray
    val c2 = (0 until n).toArray

    (1 to m1).foreach { _ =>
      val u = input.nextInt() - 1
      val v = input.nextInt() - 1
      connect(c1, u, v)
    }
    (1 to m2).foreach { _ =>
      val u = input.nextInt() - 1
      val v = input.nextInt() - 1
      connect(c2, u, v)
    }

    val ans = ArrayBuffer[(Int, Int)]()
    (0 until (n - 1)).foreach { u =>
      (u + 1).until(n).foreach { v =>
        if (!connected(c1, u, v) && !connected(c2, u, v)) {
          ans.append((u + 1, v + 1))
          connect(c1, u, v)
          connect(c2, u, v)
        }
      }
    }

    output.println(ans.length)
    ans.foreach { case (u, v) =>
      output.println(u + " " + v)
    }
    output.flush()
  }

  def main(args: Array[String]): Unit = {
    run(new Scanner(System.in), new PrintWriter(System.out))
  }
}

import java.io._
import scala.collection.immutable.TreeSet
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import util.control.Breaks._

object Solution {
    val reader = new BufferedReader(new java.io.InputStreamReader(System.in))
    val writer =  new PrintWriter(System.out)
    def readInt(): Int = reader.readLine().toInt
    def readLong(): Long = reader.readLine().toLong
    def readArrayInt(): Array[Int] = reader.readLine().split(" ").map(_.toInt)
    def readArrayLong(): Array[Long] = reader.readLine().split(" ").map(_.toLong)
    def readString(): String = reader.readLine()

    def multiTest(f: Int => Unit): Unit = {
        val t = readInt()
        for (i <- 1 to t) f(i)
    }

    def GCD(a: Int, b: Int): Int = {
        if (a == 0) return b
        GCD(b % a, a)
    }

    def dfs(u: Int, e: Array[ArrayBuffer[Int]], ch: Array[Boolean], f: Array[Int]): Unit = {
        for (v <- e(u) if !ch(v)) {
            ch(v) = true
            f(v) = f(u)
            dfs(v, e, ch, f)
        }
    }

    def root(u: Int, f: Array[Int]): Int = {
        if (f(u) < 0) return u
        f(u) = root(f(u), f)
        f(u)
    }

    def join(u: Int, v: Int, f: Array[Int]): Unit = {
        var x = root(u, f)
        var y = root(v, f)
        if (x == y) return

        if (f(y) < f(x)) {
            val t = x
            x = y
            y = t
        }
        f(x) += f(y)
        f(y) = x
    }

    def solve(t: Int = 0): Unit = {
        val Array(n,m1,m2) = readArrayInt()
        //val e1 = Array.fill(n)(new ArrayBuffer[Int]())
        //val e2 = Array.fill(n)(new ArrayBuffer[Int]())

        val f1 = new Array[Int](n)
        val f2 = new Array[Int](n)

        for (i <- 0 until n) {
            f1(i) = -1
            f2(i) = -1
        }

        for (_ <- 0 until m1) {
            val Array(u,v) = readArrayInt()
            //e1(u - 1) += v - 1
            //e1(v - 1) += u - 1
            join (u - 1, v - 1, f1)
        }

        for (_ <- 0 until m2) {
            val Array(u,v) = readArrayInt()
           // e2(u - 1) += v - 1
            //e2(v - 1) += u - 1
            join (u - 1, v - 1, f2)
        }

        /*val f1 = new Array[Int](n)
        val f2 = new Array[Int](n)
        var ch = Array.fill[Boolean](n)(false)
        var c = 1
        for (i <- 0 until n if !ch(i)) {
            f1(i) = c
            dfs(i, e1, ch, f1)
            c += 1
        }

        ch = Array.fill[Boolean](n)(false)
        c = 1
        for (i <- 0 until n if !ch(i)) {
            f2(i) = c
            dfs(i, e2, ch, f2)
            c += 1
        }*/

        val rs = new ArrayBuffer[(Int, Int)]()

        for (i <- 0 until n - 1; j <- i + 1 until n) {
            if (root(i, f1) != root(j, f1) && root(i, f2) != root(j, f2)) {
                rs += ((i + 1, j + 1))
                join(i, j, f1)
                join(i, j, f2)
            }
        }

        println(rs.length)

        for ((u,v) <- rs)
            writer.println(s"$u $v")
    }

    def main(args: Array[String]) {
        //multiTest(solve)
        solve()
        writer.flush()
    }
}


object Demo {
  def main(args: Array[String]): Unit
  =
  {
    var arr = new Array[Int](4)

      //arr = readLine.split(" ").map(_.toInt)
      val Array(a,b,c,d)=readLine.split(" ").map(_.toInt)
    arr(0)=a
    arr(1)=b
    arr(2)=c
    arr(3)=d
   // arr.sorted
    for(i<-0 to 3)
      {
        for(j<-i+1 to 3)
          {
            if(arr(i)>arr(j))
              {
                var temp=arr(i)
                arr(i)=arr(j)
                arr(j)=temp
              }
          }
      }
    println((arr(3)-arr(0))+" "+(arr(3)-arr(1))+" "+(arr(3)-arr(2)))
    /*for(i<-0 to 3)
      println(arr(i))*/
  }
}

object Example extends App {
  def greater(i: Int, j : Int): Int =
    i > j match {
      case true => i
      case _ => j
    }

  def myPrint (g :Int, b :Int) =
    g == b match {
      case false => print( g - b + " ")
      case _ =>
    }

  var lol = scala.io.StdIn.readLine().split(" ")
  var a = lol(0).toInt
  var b = lol(1).toInt
  var c = lol(2).toInt
  var d = lol(3).toInt

  var g = greater(greater(c,d), greater(a,b))
  myPrint (g, a)
  myPrint (g, b)
  myPrint (g, c)
  myPrint (g, d)

}

object Example extends App {
  def greater(i: Int, j : Int): Int =
    i > j match {
      case true => i
      case _ => j
    }

  def myPrint (g : Int, b :Int) =
    g == b match {
      case false => print( g.toInt - b.toInt + " ")
      case _ =>
    }

  var input = scala.io.StdIn.readLine().split(" ")
  var r = input.map(e => e.toInt)
  var g = greater(greater(r(0), r(1)), greater(r(2) , r(3)))
  input.map( e => myPrint(g, e.toInt))
}

object Example extends App {
  def greater(i: Int, j : Int): Int =
    i > j match {
      case true => i
      case _ => j
    }

  def myPrint (g : Int, b :Int) =
    g == b match {
      case false => print( g.toInt - b.toInt + " ")
      case _ =>
    }

  var input = scala.io.StdIn.readLine().split(" ")
  var r = input.map(e => e.toInt)
  var g = greater(greater(r(0), r(1)), greater(r(2) , r(3)))
  r.map( e => myPrint(g, e))
}

object Example extends App {
  def greater(i: Int, j : Int): Int =
    i > j match {
      case true => i
      case _ => j
    }

  def myPrint (g : Int, b :Int) =
    g == b match {
      case false => print( g - b + " ")
      case _ =>
    }

  var input = scala.io.StdIn.readLine().split(" ")
  var r = input.map(e => e.toInt)
  var g = greater(greater(r(0), r(1)), greater(r(2) , r(3)))
  r.map( e => myPrint(g, e))
}

 /**
  * @author ShankarShastri
  *         Algorithm: RestoringThreeNumbers
  */

import scala.io.StdIn._
import scala.annotation.tailrec

object RestoringThreeNumbers {
  def main(args: Array[String]): Unit = {
    val l = readLine.split(" ").map(_.toInt)
    val abc = l.max
    println(l.filter(abc - _ != 0).map(abc - _).mkString(" "))
  }
}

object Puzzle {
  def main(args: Array[String]): Unit = {
    val Array(a, b, c, d) = scala.io.StdIn.readLine()
      .split(" ")
      .map(_.toInt)
      .sorted
    print(d - a + " ")
    print(d - b + " ")
    print(d - c)
  }
}

import java.util.Scanner

object Solution {
  def main(args : Array[String]) : Unit = {
    val scanner = new Scanner(System.in)
    val x_1 = scanner.nextInt()
    val x_2 = scanner.nextInt()
    val x_3 = scanner.nextInt()
    val x_4 = scanner.nextInt()
    val xs = Seq(x_1, x_2, x_3, x_4)
    val m = xs.max
    val ms = Seq(m)
    val xs_minus_ms = xs.diff(ms)
    for (x <- xs_minus_ms) {
      val a = m - x
      print(s"${a} ")
    }
    println()
  }
}

import scala.io.StdIn

object Codeforces1154A extends App {
  var Array(x1, x2, x3, x4) = StdIn.readLine().split("\\s").map(s => s.toLong)

  var abc = math.max(x1, math.max(x2, math.max(x3, x4)))
  if (x1 != abc) print((abc - x1) + " ")
  if (x2 != abc) print((abc - x2) + " ")
  if (x3 != abc) print((abc - x3) + " ")
  if (x4 != abc) print((abc - x4) + " ")
}

import scala.io.StdIn._

object Main2 extends App {
  val numbers = readLine().split(" ").map(_.toLong).sorted
  println(s"${numbers(3) - numbers(1)} ${numbers(3) - numbers(2)} ${numbers(3) - numbers(0)}")
}

object Puzzle {
  def main(args: Array[String]): Unit = {
    val Array(a, b, c, d) = scala.io.StdIn.readLine()
      .split(" ")
      .map(_.toInt)
      .sorted
    print(d - a + " ")
    print(d - b + " ")
    print(d - a)
  }
}