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

  override def apply(io: IO): io.type = {
    val n, _ = io.read[Int]
    val map: Vector[String] = io.read(n)

    def bombCount(i: Int, j: Int) = {
      var c = 0
      for {
        dx <- -1 to 1
        row <- map.lift(i + dx)
        dy <- -1 to 1
        if !(dx == 0 && dy == 0)
        col <- row.lift(j + dy)
        if col == '*'
      } c += 1
      c
    }

    var ok = true
    for {
      i <- map.indices
      j <- map(i).indices
      if map(i)(j) != '*'
      c = if (map(i)(j).isDigit) map(i)(j) - '0' else 0
    } ok &= (c == bombCount(i, j))

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

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

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

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

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

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

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

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

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

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

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

import scala.io.StdIn

object Minesweeper extends App {

  type Field = Array[Array[String]]

  val l1s = StdIn.readLine().split(" ")
  val n = l1s(0).toInt
  val m = l1s(1).toInt

  val field = new Field(n)
  for (i <- 0 until n) {
    field(i) = StdIn.readLine().split("")
  }

  impl(n, m, field) match {
    case true => print("YES")
    case false => print("NO")
  }

  def impl(n: Int, m: Int, field: Field): Boolean = {
    for (i <- 0 until n) {
      for (j <- 0 until m) {
        if (!validateNeighbors(i, j, field, n, m)) return false
      }
    }
    true
  }

  private
  def validateNeighbors(i: Int, j: Int, field: Field, n: Int, m: Int): Boolean = {
    if (field(i)(j) != "*") {
      val mines =
        getMine(-1, -1, i, j, n, m, field) +
          getMine(-1, 0, i, j, n, m, field) +
          getMine(-1, 1, i, j, n, m, field) +
          getMine(0, -1, i, j, n, m, field) +
          getMine(0, 1, i, j, n, m, field) +
          getMine(1, -1, i, j, n, m, field) +
          getMine(1, 0, i, j, n, m, field) +
          getMine(1, 1, i, j, n, m, field)

      if (field(i)(j) == ".") {
        if (mines == 0) true
        else false
      } else {
        if (mines == field(i)(j).toInt) true
        else false
      }
    } else {
      true
    }
  }

  private
  def getMine(i_offset: Int, j_offset: Int, i: Int, j: Int, n: Int, m: Int, field: Field): Int = {
    if (inField(i + i_offset, j + j_offset, n, m)) {
      if (field(i + i_offset)(j + j_offset) == "*") 1
      else 0
    } else 0
  }

  private
  def inField(i: Int, j: Int, n: Int, m: Int): Boolean = {
    if (i < 0 || i >= n) false
    else if (j < 0 || j >= m) false
    else true
  }
}


object C extends App {

  def readString = Console.readLine
  val as = readString
  val k = readString.toLong

  var x = 0
  val TWO = BigInt(2)
  val M = 1000000007
  val l = as.length()

  val a = TWO.modPow(k * l, M) - 1
  val b = TWO.modPow(l, M) - 1
  val y = a * b.modInverse(M)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
    x %= M
  }

  println(x * y % M)
}

object C extends App {

  def readString = Console.readLine

  val as = readString //Array.fill(100000)('5')
  val k = readString.toLong

  var x = BigInt(0)
  val TWO = BigInt(2)
  val M = BigInt(1000000007)
  val l = as.length()

  val a = TWO.modPow(k * l, M) - 1
  val b = TWO.modPow(l, M) - 1
  val y = a * b.modInverse(M)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
    x %= M
  }

  println(x * y % M)
}

object CF327C extends App {
  val s = Console.readLine
  val n : Long = s.size.toLong
  val k : Long = Console.readLine.toLong
  val md = 1000000007L

  def p2(y : Long, x : Long) : Long = {
    if (x == 0) 1 else {
      val t = p2(y, x/2)
      if (x % 2 == 0) (t * t) % md else (((y * t) % md) * t) % md
    }
  }

  def inv(x : Long) : Long = {
    p2(x, md - 2)
  }

  val res = (0 until n.toInt).map{
    x => if (s(x) == '0' || s(x) == '5') p2(2, x) else 0
  }.reduce((x, y) => (x + y) % md)

  val outer = (p2(2, k * n) - 1 + md) % md * inv((p2(2, n) - 1 + md)% md) % md

  println (res * outer % md)
}

object C extends App {

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

  val as = readString //Array.fill(100000)('5') //
  val k = readString.toInt

  var x = BigInt(0)
  val TWO = BigInt(2)
  val M = BigInt(1000000007)
  val l = as.length()

  val a = k min l
  val b = k max l

  val y = ((TWO.modPow(b, M).modPow(a, l * M) - 1 + M) % M) / ((TWO.pow(l)- 1))

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
  }

  println(x * y % M)
}

object C extends App {

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

  val as = readString //Array.fill(100000)('5')
  val k = readString.toInt

  var x = 0L
  val TWO = BigInt(2)
  val M = 1000000007L
  val l = as.length()

  val a = TWO.modPow(k * l, M) - 1
  val b = TWO.modPow(l, M) - 1
  val y = a * b.modInverse(M)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
    x %= M
  }

  println(x * y % M)
}

object C extends App {

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

  val as = Array.fill(100000)('5')
  val k = readString.toInt

  var x = 0L
  val TWO = BigInt(2)
  val M = 1000000007
  val l = as.length()

  val a = TWO.modPow(k * l, M) - 1
  val b = TWO.modPow(l, M) - 1
  val y = a * b.modInverse(M)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
    x %= M
  }

  println(x * y % M)
}

object C extends App {

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

  val as = readString //Array.fill(100000)('5') //
  val k = readString.toInt

  var x = BigInt(0)
  val TWO = BigInt(2)
  val M = BigInt(1000000007)
  val l = as.length()

  val a = k min l
  val b = k max l

  val y = ((TWO.modPow(b, M).modPow(a, l * M) - 1 + M) % M) / ((TWO.modPow(l, M) + M - 1) % M)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
  }

  println(x * y % M)
}

object C extends App {

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

  val as = readString //Array.fill(100000)('5') //
  val k = readString.toInt

  var x = BigInt(0)
  val TWO = BigInt(2)
  val M = BigInt(1000000007)
  val l = as.length()

  val a = k min l
  val b = k max l

  val y = (TWO.modPow(b, M).modPow(a, l * M) - 1) / ((TWO.pow(l)- 1))

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
  }

  println(x * y % M)
}

object C extends App {

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

  val as = readString //Array.fill(100000)('5') //
  val k = readString.toInt

  var x = BigInt(0)
  val TWO = BigInt(2)
  val M = BigInt(1000000007)
  val l = as.length()

  val a = k min l
  val b = k max l

  val y = (TWO.modPow(b, M).modPow(a, l * M) - 1) / (TWO.modPow(l, M) - 1)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
  }

  println(x * y % M)
}

object C extends App {

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

  val as = readString //Array.fill(100000)('5') //
  val k = readString.toInt

  var x = BigInt(0)
  val TWO = BigInt(2)
  val M = BigInt(1000000007)
  val l = as.length()

  val y = (TWO.modPow(k * l, l * M) - 1) / (TWO.modPow(l, M) - 1)

  for (c <- as.reverse) {
    x = 2 * x
    if (c == '0' || c == '5') x += 1
  }

  println(x * y % M)
}

object CF327C extends App {
  val s = Console.readLine
  val n = s.size
  val k = Console.readLine.toInt
  val md = 1000000007

  def p2(y : Long, x : Long) : Long = {
    if (x == 0) 1 else {
      val t = p2(y, x/2)
      if (x % 2 == 0) (t * t) % md else ((y * t) % md) * t % md
    }
  }

  def inv(x : Long) : Long = {
    p2(x, md - 2)
  }

  val res = ((0 until n).reverse.map{
    x => {
      if (s(x) == '0' || s(x) == '5') p2(2, x) else 0
    }
  }.reduce((x, y) => (x + y) % md) * ((p2(2, k * n) - 1 + md) % md))% md * inv((p2(2, n) - 1 + md)% md) % md

  println (res)
}

object CF327C extends App {
  val s = Console.readLine
  val n = s.size
  val k = Console.readLine.toInt
  val md = 1000000007L

  def p2(y : Long, x : Long) : Long = {
    if (x == 0) 1 else {
      val t = p2(y, x/2)
      if (x % 2 == 0) (t * t) % md else (((y * t) % md) * t) % md
    }
  }

  def inv(x : Long) : Long = {
    p2(x, md - 2)
  }

  val res = (((0 until n).reverse.map{
    x => {
      if (s(x) == '0' || s(x) == '5') p2(2, x) else 0
    }
  }.reduce((x, y) => (x + y) % md) * ((p2(2, k * n) - 1 + md) % md))% md * inv((p2(2, n) - 1 + md)% md)) % md

  println (res)
}

object CF327C extends App {
  val s = Console.readLine
  val n = s.size
  val k = Console.readLine.toInt
  val md = 1000000007

  def p2(y : Long, x : Long) : Long = {
    if (x == 0) 1 else {
      val t = p2(y, x/2)
      if (x % 2 == 0) (t * t) % md else ((y * t) % md) * t % md
    }
  }

  def inv(x : Long) : Long = {
    p2(x, md - 2)
  }

  val res = ((0 until n).reverse.map{
    x => {
      if (s(x) == '0' || s(x) == '5') p2(2, x) else 0
    }
  }.reduce((x, y) => (x + y) % md) * ((p2(2, k * n) - 1 + md) % md))% md * inv(p2(2, n) - 1) % md

  println (res)
}

object CF327C extends App {
  val s = Console.readLine
  val n = s.size
  val k = Console.readLine.toInt
  val md = 1000000007

  def p2(y : Long, x : Long) : Long = {
    if (x == 0) 1 else {
      val t = p2(y, x/2)
      if (x % 2 == 0) (t * t) % md else (((y * t) % md) * t) % md
    }
  }

  def inv(x : Long) : Long = {
    p2(x, md - 2)
  }

  val res = (((0 until n).reverse.map{
    x => {
      if (s(x) == '0' || s(x) == '5') p2(2, x) else 0
    }
  }.reduce((x, y) => (x + y) % md) * ((p2(2, k * n) - 1 + md) % md))% md * inv((p2(2, n) - 1 + md)% md)) % md

  println (res)
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val cats = in.next().split(" ").map(_.toInt)
  val nodes = Array.fill(n){List.empty[Int]}
  (1 until n).foreach { _ =>
    val Array(a, b) = in.next().split(" ").map(_.toInt - 1)
    nodes(a) ::= b
    nodes(b) ::= a
  }

  def count(i: Int, parent: Int, soFar: Int, found: Boolean): Int = {
    val nSoFar = if (cats(i) == 1) soFar + 1 else 0
    val nFound = found || nSoFar == m + 1
    val children = nodes(i).filter(_ != parent).map{j => count(j, i, nSoFar, nFound)}
    if (children.isEmpty)
      if (nFound) 0 else 1
    else
      children.sum
  }

  println(count(0, 0, 0, false))
}

object C580 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val isCat = readInts(n)
    val vis = Array.fill(n)(false)
    val _G = Array.fill(n)(collection.mutable.ArrayBuffer.empty[Int])
    for(i <- 0 until n-1){
      val in = readInts(2)
      _G(in(0)-1) += in(1)-1
      _G(in(1)-1) += in(0)-1
    }
    val G = _G.map(_.toArray)

    def dfs(idx: Int, cats: Int): Int = {
      val newCats = if(isCat(idx)==1) cats+1 else 0
      vis(idx) = true
      if(newCats <= m) {
        if(G(idx).length == 1 && idx!=0) {
          1
        } else {
          var sum = 0
          for (i <- G(idx)) {
            if(!vis(i))
              sum += dfs(i, newCats)
          }
          sum
        }
      } else {
        0
      }
    }

    var res = dfs(0, 0)
    println(res)
  }

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

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

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

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

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

}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _580C extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  val hasCats = IndexedSeq.fill(n)(nextInt == 1)
  val edge = map[Int].to(List.empty[Int])
  repeat(n-1) {
    val (i, j) = (nextInt, nextInt)
    edge(i) = j :: edge(i)
    edge(j) = i :: edge(j)
  }

  val visited = bag[Int]

  def solve(pos: Int, prevCats: Int): Int = {
    visited += pos
    val cats = if (hasCats(pos - 1)) 1 + prevCats else 0
    edge(pos).filterNot(visited) match {
      case _ if cats > m => 0
      case Nil => 1
      case children => children.map(solve(_, cats)).sum
    }
  }

  solve(1, 0)
}) {
  override def format(result: Result) = super.format(result)
}
/********************************************************************************************/
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final type Result = A
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: Result): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
  import scala.collection.mutable.{Map => Dict, Set => Bag}
  final def bag[A]: Bag[A] = Bag.empty[A]
  final def map[A] = new {
    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default
  }
}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _580C extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  val hasCats = IndexedSeq.fill(n)(nextInt == 1)
  val edge = map[Int].to(Set.empty[Int])
  repeat(n-1) {
    val (i, j) = (nextInt, nextInt)
    edge(i) = edge(i) + j
    edge(j) = edge(j) + i
  }

  val visited = mutable.Set.empty[Int]

  def solve(pos: Int, prevCats: Int): Int = {
    visited += pos
    val cats = if (hasCats(pos - 1)) 1 + prevCats else 0
    if (cats > m) {
      0     // more than m consecutive cats. Exit!
    } else {
      val children = edge(pos).filterNot(visited).view
      if (children.isEmpty) {
        1           // Leaf node
      } else {
        var sum = 0     // inner node
        for {i <- children} {
          sum += solve(i, cats)
        }
        sum
      }
    }
  }

  solve(1, 0)
})
/****************************************************************************************/
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final type Result = A
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: Result): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
  final def map[A] = new {
    import scala.collection.mutable.{Map => Dict}
    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default
  }
}

/**
 * @author netman
 */

import java.io._
import scala._
import scala.collection.mutable._
import java.util.StringTokenizer

object HelloWorld {

  class InputReader(reader: BufferedReader) {

    var tokenizer: StringTokenizer = null;

    def this(stream: InputStream) = {
      this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));
    }

    def this(f: File) = {
      this(new BufferedReader(new FileReader(f), (1 << 20)));
    }

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

    def nextInt(): Int = next().toInt

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

    def close() = reader.close();
  }

  class OutputWriter(writer: PrintWriter) {
    def this(stream: OutputStream) {
      this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));
    }

    def this(f: File) = {
      this(new PrintWriter(new BufferedWriter(new FileWriter(f))));
    }

    def print(x: Any) = writer.print(x);

    def println(x: Any) = writer.println(x);

    def close() = writer.close();
  }

  val in = new InputReader(System.in)
  val out = new OutputWriter(System.out)

  var a: Array[Int] = null
  var g: Array[ArrayBuffer[Int]] = null
  var m = 0
  var result = 0

  def dfs(v: Int, p: Int, cur: Int): Unit = {
    val ncur = if (a(v) == 0) 0 else cur + 1
    if (ncur <= m) {
    if (g(v).length == 1 && v != 1) {
      result += 1
      //out.println(v)
    }
    for (to <- g(v)) {
      if (to != p) {
        dfs(to, v, ncur)
      }
    }
    }
  }

  def main(args: Array[String]): Unit = {
    val n = in.nextInt
    m = in.nextInt

    a = new Array[Int](n + 1)
    g = Array.fill[ArrayBuffer[Int]](n + 1)(new ArrayBuffer[Int])

    for (i <- 1 to n) {
      a(i) = in.nextInt
    }

    for (i <- 1 to n - 1) {
      val (x, y) = (in.nextInt, in.nextInt)
      g(x) += y
      g(y) += x
    }

    dfs(1, -1, 0)

    out.println(result)

    out.close
  }
}

import scala.collection.mutable.ArrayBuffer

//https://codeforces.com/problemset/problem/580/C
object KefaAndPark {
  case class Cou(var c:Int=0)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    val m=line.split(" ")(1).toInt
    val cats=in.readLine().split(" ").map(_.toInt)
    val graph = Array.fill[ArrayBuffer[Int]](n)(new ArrayBuffer[Int]())
    for(i<- 0 until n-1){
      line=in.readLine()
      addUndirectedEdge(graph,line.split(" ")(0).toInt-1,(line.split(" ")(1).toInt-1))
    }
    getNumberOfPossibleRestaurants(graph,n,m,cats)
  }

  def getNumberOfPossibleRestaurants(graph:Array[ArrayBuffer[Int]],n:Int,m:Int,cats:Array[Int]):Int={
    val cou=Cou()
    postOrder(graph,cats,0,-1,cats(0),m,cou)
    println(cou.c)
    return cou.c
  }

  def postOrder(graph:Array[ArrayBuffer[Int]],cats:Array[Int],n:Int,pr:Int,curM:Int,m:Int,cou: Cou):Unit={
    if(curM<=m){
      var x=1
      for(i<- 0 until graph(n).length ){
        if(graph(n)(i)!=pr) {
          x=0
          postOrder(graph, cats, graph(n)(i), n, cats(graph(n)(i))*curM+cats(graph(n)(i)), m, cou)
        }
      }
      cou.c+=x
    }
  }
  def addUndirectedEdge(graph: Array[ArrayBuffer[Int]], u: Int, v: Int): Unit = {
    //It is an undirected graph, so the an edge a to b can be used to travel both a to b and b to aa
    graph(u) += v
    graph(v) += u
  }
}

import scala.collection.mutable.ArrayBuffer

//https://codeforces.com/problemset/problem/580/C
object KefaAndPark {
  case class Cou(var c:Int=0)
  var graph:Array[ArrayBuffer[Int]] =null
  var cats:Array[Int]=null
  var m:Int=0
  val cou=Cou()
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    m=line.split(" ")(1).toInt
    cats=in.readLine().split(" ").map(_.toInt)
    graph = Array.fill[ArrayBuffer[Int]](n)(new ArrayBuffer[Int]())
    for(i<- 0 until n-1){
      line=in.readLine()
      addUndirectedEdge(graph,line.split(" ")(0).toInt-1,(line.split(" ")(1).toInt-1))
    }
    postOrder(0,-1,cats(0))
    println(cou.c)
  }

  def postOrder(n:Int,pr:Int,curM:Int):Unit={
    if(curM<=m){
      var x=1
      for(i<- 0 until graph(n).length ){
        if(graph(n)(i)!=pr) {
          x=0
          postOrder(graph(n)(i), n, cats(graph(n)(i))*curM+cats(graph(n)(i)))
        }
      }
      cou.c+=x
    }
  }
  def addUndirectedEdge(graph: Array[ArrayBuffer[Int]], u: Int, v: Int): Unit = {
    //It is an undirected graph, so the an edge a to b can be used to travel both a to b and b to aa
    graph(u) += v
    graph(v) += u
  }
}

import scala.collection.mutable.ArrayBuffer

//https://codeforces.com/problemset/problem/580/C
object KefaAndPark {
  case class Cou(var c:Int=0)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    val m=line.split(" ")(1).toInt
    val cats=in.readLine().split(" ").map(_.toInt)
    val edges=new ArrayBuffer[Int]()
    for(i<- 0 until n-1){
      line=in.readLine()
      edges+=(line.split(" ")(0).toInt-1)
      edges+=(line.split(" ")(1).toInt-1)
    }
    getNumberOfPossibleRestaurants(n,m,cats,edges)
  }

  def getNumberOfPossibleRestaurants(n:Int,m:Int,cats:Array[Int],edges:ArrayBuffer[Int]):Int={
    val graph=getDirectedGraph(edges,n)
    val cou=Cou()
    postOrder(graph,cats,0,-1,cats(0),m,cou)
    println(cou.c)
    return cou.c
  }

  def postOrder(graph:Array[ArrayBuffer[Int]],cats:Array[Int],n:Int,pr:Int,curM:Int,m:Int,cou: Cou):Unit={
    if(curM<=m){

      var x=1
        for(i<- 0 until graph(n).length ){
          if(graph(n)(i)!=pr) {
            x=0
            if (cats(graph(n)(i)) == 0) {
              postOrder(graph, cats, graph(n)(i), n, 0, m, cou)
            } else {
              postOrder(graph, cats, graph(n)(i), n, curM + 1, m, cou)
            }
          }
        }
        cou.c+=x
      }
  }

  def getDirectedGraph(edges: ArrayBuffer[Int], N: Int): Array[ArrayBuffer[Int]] = {
    //Adjacency list representation is used to represent the graph

    //We have N vertices
    val graph = new Array[ArrayBuffer[Int]](N)

    //Every vertices can be associated to multiple adjacent vertices
    for (i <- 0 until N) {
      graph(i)= new ArrayBuffer[Int]()
    }

    //Every pair array elements represent a edge
    for (i <- 0 until edges.length by 2) {
      addDirectedEdge(graph, edges(i), edges(i + 1))
    }

    return graph
  }

  def addDirectedEdge(graph: Array[ArrayBuffer[Int]], u: Int, v: Int): Unit = {
    //It is a directed graph, so the an edge a to b can be used to travel from a to b
    graph(u) += v
    graph(v) += u
  }
}

import scala.collection.mutable.ArrayBuffer

//https://codeforces.com/problemset/problem/580/C
object KefaAndPark {
  case class Cou(var c:Int=0)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    val m=line.split(" ")(1).toInt
    val cats=in.readLine().split(" ").map(_.toInt)
    val graph = Array.fill[ArrayBuffer[Int]](n)(new ArrayBuffer[Int]())
    for(i<- 0 until n-1){
      line=in.readLine()
      val u=line.split(" ")(0).toInt-1
      val v=(line.split(" ")(1).toInt-1)
      addUndirectedEdge(graph,u,v)
    }
    getNumberOfPossibleRestaurants(graph,n,m,cats)
  }

  def getNumberOfPossibleRestaurants(graph:Array[ArrayBuffer[Int]],n:Int,m:Int,cats:Array[Int]):Int={
    val cou=Cou()
    postOrder(graph,cats,0,-1,cats(0),m,cou)
    println(cou.c)
    return cou.c
  }

  def postOrder(graph:Array[ArrayBuffer[Int]],cats:Array[Int],n:Int,pr:Int,curM:Int,m:Int,cou: Cou):Unit={
    if(curM<=m){
      var x=1
      for(i<- 0 until graph(n).length ){
        if(graph(n)(i)!=pr) {
          x=0
          postOrder(graph, cats, graph(n)(i), n, cats(graph(n)(i))*curM+cats(graph(n)(i)), m, cou)
        }
      }
      cou.c+=x
    }
  }
  def addUndirectedEdge(graph: Array[ArrayBuffer[Int]], u: Int, v: Int): Unit = {
    //It is an undirected graph, so the an edge a to b can be used to travel both a to b and b to aa
    graph(u) += v
    graph(v) += u
  }
}

//package round321.c

import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt
  val m = sc.nextInt

  val hasCat = (0 until n).map(_ => sc.nextInt == 1)

  var tree = Array.fill[List[Int]](n)(Nil)

  (0 until (n-1)).foreach { _ =>
    val (a, b) = (sc.nextInt - 1, sc.nextInt - 1)
    tree(a) = b :: tree(a)
    tree(b) = a :: tree(b)
  }

  def dfs(v: Int, parent: Int, consCatsSoFar: Int): Int = {
    val consCats = if(hasCat(v)) 1 + consCatsSoFar else 0
    if(consCats > m) 0
    else {
      val children = tree(v).filterNot(_ == parent)
      if(children.isEmpty) 1
      else {
        children.foldLeft(0){ case (s, vNext) =>
          s + dfs(vNext, v, consCats)
        }
      }
    }
  }

  println(dfs(0, -1, 0))
}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _580C extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  val hasCats = IndexedSeq.fill(n)(nextInt == 1)
  val tree = map[Int].to(Set.empty[Int])
  repeat(n-1) {
    val (i, j) = (nextInt, nextInt)
    tree(i) = tree(i) + j
  }

  def solve(pos: Int, prevCats: Int): Int = {
    val cats = if (hasCats(pos - 1)) 1 + prevCats else 0
    //debug(pos, prevCats, cats, tree(pos))
    tree(pos).toSeq match {
      case _ if cats > m => 0
      case Nil => 1
      case children => children.map(solve(_, cats)).sum
    }
  }

  solve(1, 0)
}) {
  override def format(result: Result) = super.format(result)
}
/****************************************************************************************/
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final type Result = A
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: Result): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
  final def map[A] = new {
    import scala.collection.mutable.{Map => Dict}
    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default
  }
}

/**
 * @author netman
 */

import java.io._
import scala._
import scala.collection.mutable._
import java.util.StringTokenizer

object HelloWorld {

  class InputReader(reader: BufferedReader) {

    var tokenizer: StringTokenizer = null;

    def this(stream: InputStream) = {
      this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));
    }

    def this(f: File) = {
      this(new BufferedReader(new FileReader(f), (1 << 20)));
    }

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

    def nextInt(): Int = next().toInt

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

    def close() = reader.close();
  }

  class OutputWriter(writer: PrintWriter) {
    def this(stream: OutputStream) {
      this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));
    }

    def this(f: File) = {
      this(new PrintWriter(new BufferedWriter(new FileWriter(f))));
    }

    def print(x: Any) = writer.print(x);

    def println(x: Any) = writer.println(x);

    def close() = writer.close();
  }

  val in = new InputReader(System.in)
  val out = new OutputWriter(System.out)

  var a: Array[Int] = null
  var g: Array[ArrayBuffer[Int]] = null
  var m = 0
  var result = 0

  def dfs(v: Int, p: Int, cur: Int): Unit = {
    val ncur = if (a(v) == 0) 0 else cur + 1
    if (ncur > m) return
    if (g(v).length == 1) result += 1
    for (to <- g(v)) {
      if (to != p) {
        dfs(to, v, ncur)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    val n = in.nextInt
    m = in.nextInt

    a = new Array[Int](n + 1)
    g = Array.fill[ArrayBuffer[Int]](n + 1)(new ArrayBuffer[Int])

    for (i <- 1 to n) {
      a(i) = in.nextInt
    }

    for (i <- 1 to n - 1) {
      val (x, y) = (in.nextInt, in.nextInt)
      g(x) += y
      g(y) += x
    }

    dfs(1, -1, 0)

    out.println(result)

    out.close
  }
}

/**
 * @author netman
 */

import java.io._
import scala._
import scala.collection.mutable._
import java.util.StringTokenizer

object HelloWorld {

  class InputReader(reader: BufferedReader) {

    var tokenizer: StringTokenizer = null;

    def this(stream: InputStream) = {
      this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));
    }

    def this(f: File) = {
      this(new BufferedReader(new FileReader(f), (1 << 20)));
    }

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

    def nextInt(): Int = next().toInt

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

    def close() = reader.close();
  }

  class OutputWriter(writer: PrintWriter) {
    def this(stream: OutputStream) {
      this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));
    }

    def this(f: File) = {
      this(new PrintWriter(new BufferedWriter(new FileWriter(f))));
    }

    def print(x: Any) = writer.print(x);

    def println(x: Any) = writer.println(x);

    def close() = writer.close();
  }

  val in = new InputReader(System.in)
  val out = new OutputWriter(System.out)

  var a: Array[Int] = null
  var g: Array[ArrayBuffer[Int]] = null
  var m = 0
  var result = 0

  def dfs(v: Int, p: Int, cur: Int): Unit = {
    val ncur = if (a(v) == 0) 0 else cur + 1
    if (ncur <= m) {
    if (g(v).length == 1) result += 1
    for (to <- g(v)) {
      if (to != p) {
        dfs(to, v, ncur)
      }
    }
    }
  }

  def main(args: Array[String]): Unit = {
    val n = in.nextInt
    m = in.nextInt

    a = new Array[Int](n + 1)
    g = Array.fill[ArrayBuffer[Int]](n + 1)(new ArrayBuffer[Int])

    for (i <- 1 to n) {
      a(i) = in.nextInt
    }

    for (i <- 1 to n - 1) {
      val (x, y) = (in.nextInt, in.nextInt)
      g(x) += y
      g(y) += x
    }

    dfs(1, -1, 0)

    out.println(result)

    out.close
  }
}

import scala.collection.mutable.ArrayBuffer

//https://codeforces.com/problemset/problem/580/C
object KefaAndPark {
  case class Cou(var c:Int=0)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    val m=line.split(" ")(1).toInt
    val cats=in.readLine().split(" ").map(_.toInt)
    val edges=new ArrayBuffer[Int]()
    for(i<- 0 until n-1){
      line=in.readLine()
      edges+=(line.split(" ")(0).toInt-1)
      edges+=(line.split(" ")(1).toInt-1)
    }
    getNumberOfPossibleRestaurants(n,m,cats,edges)
  }

  def getNumberOfPossibleRestaurants(n:Int,m:Int,cats:Array[Int],edges:ArrayBuffer[Int]):Int={
    val graph=getDirectedGraph(edges,n)
    val cou=Cou()
    postOrder(graph,cats,0,-1,cats(0),m,cou)
    println(cou.c)
    return cou.c
  }

  def postOrder(graph:Array[ArrayBuffer[Int]],cats:Array[Int],n:Int,pr:Int,curM:Int,m:Int,cou: Cou):Unit={
    if(curM<=m){
      if(graph(n).length==1){
        cou.c+=1
      }else{
        for(i<- 0 until graph(n).length if(graph(n)(i)!=pr)){
          if(cats(graph(n)(i))==0) {
            postOrder(graph, cats, graph(n)(i),n, 0, m, cou)
          }else{
            postOrder(graph, cats, graph(n)(i),n, curM+1, m, cou)
          }
        }
      }
    }
  }

  def getDirectedGraph(edges: ArrayBuffer[Int], N: Int): Array[ArrayBuffer[Int]] = {
    //Adjacency list representation is used to represent the graph

    //We have N vertices
    val graph = new Array[ArrayBuffer[Int]](N)

    //Every vertices can be associated to multiple adjacent vertices
    for (i <- 0 until N) {
      graph(i)= new ArrayBuffer[Int]()
    }

    //Every pair array elements represent a edge
    for (i <- 0 until edges.length by 2) {
      addDirectedEdge(graph, edges(i), edges(i + 1))
    }

    return graph
  }

  def addDirectedEdge(graph: Array[ArrayBuffer[Int]], u: Int, v: Int): Unit = {
    //It is a directed graph, so the an edge a to b can be used to travel from a to b
    graph(u) += v
    graph(v) += u
  }
}

import scala.collection.mutable.ArrayBuffer

//https://codeforces.com/problemset/problem/580/C
object KefaAndPark {
  case class Cou(var c:Int=0)
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    val m=line.split(" ")(1).toInt
    val cats=in.readLine().split(" ").map(_.toInt)
    val edges=new ArrayBuffer[Int]()
    for(i<- 0 until n-1){
      line=in.readLine()
      edges+=line.split(" ")(0).toInt-1
      edges+=line.split(" ")(1).toInt-1
    }
    getNumberOfPossibleRestaurants(n,m,cats,edges)
  }

  def getNumberOfPossibleRestaurants(n:Int,m:Int,cats:Array[Int],edges:ArrayBuffer[Int]):Int={
    val graph=getDirectedGraph(edges,n)
    val cou=Cou()
    if(cats(0)==0)
      postOrder(graph,cats,0,0,m,cou)
    else
      postOrder(graph,cats,0,1,m,cou)
    println(cou.c)
    return cou.c
  }

  def postOrder(graph:Array[ArrayBuffer[Int]],cats:Array[Int],n:Int,curM:Int,m:Int,cou: Cou):Unit={
    if(curM<=m){
      if(graph(n).length==0){
        cou.c+=1
      }else{
        for(i<- 0 until graph(n).length){
          if(cats(graph(n)(i))==0) {
            postOrder(graph, cats, graph(n)(i), 0, m, cou)
          }else{
            postOrder(graph, cats, graph(n)(i), curM+1, m, cou)
          }
        }
      }
    }
  }

  def getDirectedGraph(edges: ArrayBuffer[Int], N: Int): Array[ArrayBuffer[Int]] = {
    //Adjacency list representation is used to represent the graph

    //We have N vertices
    val graph = new Array[ArrayBuffer[Int]](N)

    //Every vertices can be associated to multiple adjacent vertices
    for (i <- 0 until N) {
      graph(i)= new ArrayBuffer[Int]()
    }

    //Every pair array elements represent a edge
    for (i <- 0 until edges.length by 2) {
      addDirectedEdge(graph, edges(i), edges(i + 1))
    }

    return graph
  }

  def addDirectedEdge(graph: Array[ArrayBuffer[Int]], u: Int, v: Int): Unit = {
    //It is a directed graph, so the an edge a to b can be used to travel from a to b
    graph(u) += v
  }
}

object C580 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val isCat = readInts(n)
    val vis = Array.fill(n)(false)
    val _G = Array.fill(n)(collection.mutable.ArrayBuffer.empty[Int])
    for(i <- 0 until n-1){
      val in = readInts(2).sorted
      _G(in(0)-1) += in(1)-1
    }
    val G = _G.map(_.toArray)
    //bfs
    val q = collection.mutable.Queue.empty[(Int, Int)]
    q.enqueue((0, 0))
    while(q.nonEmpty) {
      val (top, cats) = q.dequeue()
      if(isCat(top) == 1) {
        if(cats+1 <= m) {
          vis(top) = true
          for(i <- G(top)) {
            q.enqueue((i, cats+1))
          }
        }
      } else {
        vis(top) = true
        for(i <- G(top)) {
          q.enqueue((i, 0))
        }
      }
    }
    var res = 0
    for(i <- 0 until n) {
      if(G(i).isEmpty && vis(i)) {
        res += 1
      }
    }
    println(res)
  }

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

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

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

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

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

}

object C580 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val isCat = readInts(n)
    val vis = Array.fill(n)(false)
    val _G = Array.fill(n)(collection.mutable.ArrayBuffer.empty[Int])
    for(i <- 0 until n-1){
      val in = readInts(2)
      _G(in(0)-1) += in(1)-1
    }
    val G = _G.map(_.toArray)
    //bfs
    val q = collection.mutable.Queue.empty[(Int, Int)]
    q.enqueue((0, 0))
    while(q.nonEmpty) {
      val (top, cats) = q.dequeue()
      if(isCat(top) == 1) {
        if(cats+1 <= m) {
          vis(top) = true
          for(i <- G(top)) {
            q.enqueue((i, cats+1))
          }
        }
      } else {
        vis(top) = true
        for(i <- G(top)) {
          q.enqueue((i, 0))
        }
      }
    }
    var res = 0
    for(i <- 0 until n) {
      if(G(i).isEmpty && vis(i)) {
        res += 1
      }
    }
    println(res)
  }

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

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

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

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

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

}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _580C extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  val hasCats = IndexedSeq.fill(n)(nextInt == 1)
  val tree = map[Int].to(Set.empty[Int])
  repeat(n-1) {
    val (i, j) = (nextInt, nextInt)
    val (u, v) = (i min j, i max j)
    tree(u) = tree(u) + v
  }

  def solve(pos: Int, prevCats: Int): Int = {
    val cats = if (hasCats(pos - 1)) 1 + prevCats else 0
    tree(pos).toSeq match {
      case _ if cats > m => 0
      case Nil => 1
      case children => children.map(solve(_, cats)).sum
    }
  }

  solve(1, 0)
}) {
  override def format(result: Result) = super.format(result)
}
/****************************************************************************************/
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final type Result = A
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: Result): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
  final def map[A] = new {
    import scala.collection.mutable.{Map => Dict}
    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default
  }
}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _580C extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  val hasCats = IndexedSeq.fill(n)(nextInt == 1)
  val tree = mutable.Map.empty[Int, Set[Int]] withDefaultValue Set.empty[Int]
  repeat(n-1) {
    val (i, j) = (nextInt, nextInt)
    tree(i) = tree(i) + j
  }

  def solve(pos: Int, prevCats: Int): Int = {
    val cats = if (hasCats(pos - 1)) 1 + prevCats else 0
    if (cats > m) { // this path has > m consecutive cats, no point continuing
      0
    } else {
      val children = tree(pos)
      if (children.isEmpty) { // a leaf node
        1
      } else { // an inner node
        children.toSeq.map(solve(_, cats)).sum
      }
    }
  }

  solve(1, 0)
}) {
  override def format(result: Result) = super.format(result)
}
/****************************************************************************************/
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final type Result = A
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: Result): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  import scala.collection.mutable.{Map => Dict}
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0
  final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
}


object Main {
  def main(args: Array[String]): Unit = {
    val nk = readLine().split(" ").map(_.toInt)
    val a = readLine().split(" ").map(_.toInt)
    val neg = a.count(_ == -1)
    val pos = a.count(_ == 1)
    val min = neg.min(pos)

    for (_ <- 1 to nk(1)) {
      val ix = readLine().split(" ").map(_.toInt)
      val i0 = ix(0)
      val i1 = ix(1)
      if ((i1 - i0 + 1) % 2 == 1) println("0")
      else if ((i1 - i0 + 1) / 2 <= min) println("1")
      else println("0")
    }
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt)
  val countPlus = data.count(_ == 1)
  val countMinus = n - countPlus
  val res = (1 to m).map{ _ =>
    val Array(l, r) = in.next().split(" ").map(_.toInt)
    val distance = r - l + 1
    if (distance % 2 == 1 || (distance / 2 > countPlus || distance / 2 > countMinus))
      0
    else
      1
  }
  println(res.mkString("\n"))
}

object Main {
  def main(args: Array[String]) = {
    val m = readLine.dropWhile(_ != ' ').tail.toInt
    var a = 0
    var b = 0

    for(x <- readLine.split(" "))
      x.toInt match {
        case 1  => a += 1
        case -1 => b += 1
        case _  =>
      }

    for(i <- 1 to m) {
      val line = readLine
      val l = line.takeWhile(_ != ' ').toInt
      val r = line.dropWhile(_ != ' ').tail.toInt
      val x = r - l + 1

      if(x % 2 == 0 && x / 2 <= Math.min(a, b))
        println(1)
      else
        println(0)
    }
  }
}

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

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

  val N, M = sc.nextInt
  val as = Array.fill(N)(sc.nextInt)
  val max = 2 * (as.count(_ == 1) min as.count(_ == -1))

  def isEven(n: Int): Boolean = n % 2 == 0

  for (i <- 0 until M) {
    val l, r = sc.nextInt
    val y = r - l + 1
    val res = if (y > 0 && y <= max && isEven(y)) 1 else 0
    out.println(res)
  }

  out.close
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toInt)
  val countPlus = data.count(_ == 1)
  val countMinus = n - countPlus
  val res = (1 to m).map{ _ =>
    val Array(l, r) = in.next().split(" ").map(_.toInt)
    val distance = r - l + 1
    if (distance % 2 == 1 || (distance / 2 < countPlus || distance / 2 < countMinus))
      0
    else
      1
  }
  println(res.mkString("\n"))
}

object Main {
  def main(args: Array[String]): Unit = {
    val nk = readLine().split(" ").map(_.toInt)
    val a = readLine().split(" ").map(_.toInt)
    val neg = a.count(_ == -1)
    val pos = a.count(_ == 1)
    val min = neg.min(pos)

    for (_ <- 1 to nk(1)) {
      val ix = readLine().split(" ").map(_.toInt)
      val i0 = ix(0)
      val i1 = ix(1)
      if ((i1 - i0 + 1) % 2 == 1) println("0")
      else if ((i1 - i1 + 1) / 2 <= min) println("1")
      else println("0")
    }
  }
}


import scala.io.StdIn._

object Main extends App {
  val Array(n, c) = readLine().split(" ").map(_.toInt)
  val a = readLine().split(" ").map(_.toInt)
  val intervals = a.zip(a.tail).map(x => x._2 - x._1)
  val ans = intervals.foldLeft(1)((sum, x) => if (x <= c) sum + 1 else 1)
  println(ans)
}

//package merofeev.contests.codeforces.rnd372

import java.util.Scanner

/**
  * @author erofeev
  * @since 17.09.16
  */
object A {

  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)
    val stuff: Array[String] = in.nextLine().split(" ")
    val words: Int = stuff(0).toInt
    val c: Int = stuff(1).toInt
    val secs = in.nextLine().split(" ").map(_.toInt)

    if (words == 1) {
      println(1)
      return
    }
    var res = 1
    for (i <- 1 until secs.length) {
      if (secs(i) - secs(i - 1) <= c) {
        res += 1
      } else {
        res = 1
      }
    }
    println(res)
  }
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val Array(n, c) = lines.next().split(' ').map(_.toInt)
  val line = lines.next().split(' ').map(_.toInt)
  val (_, amount) = line.foldLeft(0, 0) {
    case ((b, count), a) if a - b > c => (a, 1)
    case ((b, count), a) => (a, count + 1)
  }
  println(amount)
}

object A716 {
  @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, c) = readLongs(2)
    val input = readLongs(n.toInt)
    var curr = 0
    for(i <- 0 until n.toInt) {
      if(i == 0)
        curr += 1
      else if(input(i) - input(i-1) > c) {
        curr = 1
      } else {
        curr += 1
      }
    }

    println(curr)
  }
}

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, c) = readInts(2)
  val ts = readInts(n)

  var cnt = 1
  var t0 = ts.head

  for (t <- ts.tail) {
    if (t - t0 > c) cnt = 0
    cnt += 1
    t0 = t
  }

  println(cnt)
}

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

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

    var ans = 1
    var t1: Int = data.head

    data.drop(1) foreach {t2 =>
      if ((t2 - t1) > c) ans = 0
      ans += 1
      t1 = t2
    }

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

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

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

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

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

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

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

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

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object CF372_1B extends App {
   val nc = readLine.split(" ").map(_.toInt)
   val T = readLine.split(" ").map(_.toInt)
   var r = 0
   var last = -nc(1)
   for (t <- T) {
     r = if (t - last > nc(1)) 1 else (r+1)
     last = t
   }
   println(r)
}

import java.util.Scanner

object Main{
  //
  // val s = sc.nextLine()
  // val str = sc.next()

  def main (args: Array[String]){
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val c = sc.nextInt()

    var now = sc.nextInt()
    var cnt = 1
    for(i <- 1 until n){
      val t = sc.nextInt()

      if(t - now > c){
        cnt = 1
      }
      else
        cnt += 1

      now = t
    }

    println(cnt)
  }
}

import scala.io.StdIn._

object _372A extends App {
  val Array(n, c) = readLine().split(" ") map (_.toInt)
  val T = readLine().split(" ") map (_.toInt)

  var counter = 0
  var prev = 0
  for (i <- 0 until T.length) {
    if (T(i) - prev > c) {
      counter = 1
    } else {
      counter += 1
    }
    prev = T(i)
  }

  println(counter)
}

//package merofeev.contests.codeforces.rnd372

import java.util.Scanner

/**
  * @author erofeev
  * @since 17.09.16
  */
object A {

  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)
    val stuff: Array[String] = in.nextLine().split(" ")
    val words: Int = stuff(0).toInt
    val c: Int = stuff(1).toInt
    val secs = in.nextLine().split(" ").map(_.toInt)

    if (words == 1) {
      println(1)
      return
    }
    var res = 0
    for (i <- 1 until secs.length) {
      if (secs(i) - secs(i - 1) <= c) {
        res += 1
      } else {
        res = 1
      }
    }
    println(res)
  }
}

object Solution extends App {
  val lines = io.Source.stdin.getLines()
  val Array(n, c) = lines.next().split(' ').map(_.toInt)
  val line = lines.next().split(' ').map(_.toInt)
  val (_, amount) = line.foldLeft(0, 0) {
    case ((b, count), a) if b - a > c => (a, 1)
    case ((b, count), a) => (a, count + 1)
  }
  println(amount)
}

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

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

    val ans = data.sliding(2).foldLeft(0) {
      case (prev, Seq(t1, t2)) if (t2 - t1) > c => 1
      case (prev, t) if t.length <= 2 => prev + 1
      case (prev, x) => throw  new IllegalArgumentException(s"No idea what $x is")
    }

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

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

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

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

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

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

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

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

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

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

object _716A extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write, writeAll, writeLine}
    val (n, c) = read[(Int, Long)]
    val data = read[Seq, Int](n)

    val ans = data.sliding(2).foldLeft(0) {
      case (prev, Seq(t1, t2)) if (t2 - t1) > c => 1
      case (prev, _) => prev + 1
    }

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

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

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

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

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

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

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

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

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}