import scala.collection.mutable

object C extends App {

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

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

  final case class AB(a: Int, b: Int)

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n) {
    0
  }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
    0
  }
  }

  def dfs1(u: Int, parent: Int): AB = {

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (adjs(u)(i) == parent) parentPos = i
      else {
        val ab = dfs1(v, u)
        childrenSize += ab.a
        sizeFrom(u)(i) = ab.a
        if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
        if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
        if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
        if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
      }
      i += 1
    }

    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
      if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
    }

    AB(childrenSize, maxSubtreeSize)
  }

  dfs1(0, -1)

  val maxSubtreeSize2a = Array.tabulate(n) { u =>
    val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
    maxWithInd.sortBy(-_.a).take(2)
  }

  def find(arr: Array[AB], v: Int): Int = {
    if (arr.length > 0 && arr(0).b != v) arr(0).a
    else if (arr.length > 1 && arr(1).b != v) arr(1).a
    else -1
  }

  def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

    var i = 0
    while (i < adjs(u).length) {
      if (adjs(u)(i) == parent) {
        if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
      }
      i += 1
    }

    i = 0
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v != parent) {
        val sub = find(maxSubtreeSize2a(u), v)
        dfs2(v, u, Math.max(sub, parentMaxSubtreeSize))
      }
      i += 1
    }
  }

  dfs2(0, -1, 0)

  val maxSubtreeSize2 = Array.tabulate(n) { u =>
    val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
    maxWithInd.sortBy(-_.a).take(2)
  }

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = find(maxSubtreeSize2(v), u)
        if (sub == -1 || sizeFrom(u)(i) - sub > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

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

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Option[Int] = {
        if (arr.size > 0 && arr(0).b != v) Some(arr(0).a)
        else if (arr.size > 1 && arr(1).b != v) Some(arr(1).a)
        else None
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, sub.map(Math.max(_, parentMaxSubtreeSize)).getOrElse(parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

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

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Int = {
        if (arr.length > 0 && arr(0).b != v) arr(0).a
        else if (arr.length > 1 && arr(1).b != v) arr(1).a
        else -1
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, Math.max(sub, parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == -1 || sizeFrom(u)(i) - sub > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

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

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Option[Int] = {
        if (arr.length > 0 && arr(0).b != v) Some(arr(0).a)
        else if (arr.length > 1 && arr(1).b != v) Some(arr(1).a)
        else None
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, sub.map(Math.max(_, parentMaxSubtreeSize)).getOrElse(parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

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

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(arr: Array[AB], v: Int): Int = {
        if (arr.length > 0 && arr(0).b != v) arr(0).a
        else if (arr.length > 1 && arr(1).b != v) arr(1).a
        else -1
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(maxSubtreeSize2a(u), v)
            dfs2(v, u, Math.max(sub, parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = Array.tabulate(n) { u =>
        val maxWithInd = Array.tabulate(adjs(u).size) { i => AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i)) }
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(maxSubtreeSize2(v), u)
            if (sub == -1 || sizeFrom(u)(i) - sub > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 64000000).start()
}

import scala.collection.mutable

object C extends App {

  val task = new Runnable {

    override def run(): Unit = {
      @inline def tokenizeLine = new java.util.StringTokenizer(readLine)

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

      final case class AB(a: Int, b: Int)

      val Array(n) = readInts(1)
      val m = n / 2

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

      for (_ <- 1 until n) {
        val Array(u, v) = readInts(2)
        adjBuilders(u - 1) += v - 1
        adjBuilders(v - 1) += u - 1
      }

      val adjs = adjBuilders.map(_.result)
      val res = Array.fill(n) {
        0
      }
      val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length) }
      val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) {
        0
      }
      }

      def dfs1(u: Int, parent: Int): AB = {

        var i = 0
        var childrenSize = 1
        var parentPos = -1
        var maxSubtreeSize = 0

        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (adjs(u)(i) == parent) parentPos = i
          else {
            val ab = dfs1(v, u)
            childrenSize += ab.a
            sizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = ab.a
            if (ab.b <= m && ab.b > maxSubtreeSize) maxSubtreeSize = ab.b
            if (ab.a <= m && ab.a > maxSubtreeSize) maxSubtreeSize = ab.a
          }
          i += 1
        }

        if (parentPos >= 0) {
          sizeFrom(u)(parentPos) = n - childrenSize
          if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
        }

        AB(childrenSize, maxSubtreeSize)
      }

      dfs1(0, -1)

      val maxSubtreeSize2a = for (u <- 0 until n) yield {
        val maxWithInd = for (i <- adjs(u).indices) yield AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i))
        maxWithInd.sortBy(-_.a).take(2)
      }

      def find(u: Int, v: Int): Option[Int] = {
        if (maxSubtreeSize2a(u).size > 0 && maxSubtreeSize2a(u)(0).b != v) Some(maxSubtreeSize2a(u)(0).a)
        else if (maxSubtreeSize2a(u).size > 1 && maxSubtreeSize2a(u)(1).b != v) Some(maxSubtreeSize2a(u)(1).a)
        else None
      }

      def dfs2(u: Int, parent: Int, parentMaxSubtreeSize: Int): Unit = {

        var i = 0
        while (i < adjs(u).length) {
          if (adjs(u)(i) == parent) {
            if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = parentMaxSubtreeSize
          }
          i += 1
        }

        i = 0
        while (i < adjs(u).length) {
          val v = adjs(u)(i)
          if (v != parent) {
            val sub = find(u, v)
            dfs2(v, u, sub.map(Math.max(_, parentMaxSubtreeSize)).getOrElse(parentMaxSubtreeSize))
          }
          i += 1
        }
      }

      dfs2(0, -1, 0)

      val maxSubtreeSize2 = for (u <- 0 until n) yield {
        val maxWithInd = for (i <- adjs(u).indices) yield AB(maxSubtreeSizeFrom(u)(i), adjs(u)(i))
        maxWithInd.sortBy(-_.a).take(2)
      }

      for (u <- 0 until n) {
        var ok = true
        for (i <- adjs(u).indices) {
          val v = adjs(u)(i)
          if (sizeFrom(u)(i) > m) {
            val sub = find(v, u)
            if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
          }
        }
        res(u) = if (ok) 1 else 0
      }

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

      println(res.mkString(" "))

      Console.flush
    }
  }

  new Thread(null, task, "1", 80000000).start()
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) { 0 } }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int): (Int, Int) = {

    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize) maxSubtreeSize = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize) maxSubtreeSize = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize)
  }

  dfs(0, -1, 0, 0)
  dfs(last, -1, 0, 0)

  val maxSubtreeSize2 = for (u <- 0 until n) yield {
    val maxWithInd = for (i <- adjs(u).indices) yield maxSubtreeSizeFrom(u)(i) -> adjs(u)(i)
    maxWithInd.sortBy(- _._1).take(2)
  }

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = maxSubtreeSize2(v).filter(_._2 != u).headOption.map(_._1)
        if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }

  def dfs(u: Int, parent: Int, size: Int): (Int, Int) = {
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0)
  dfs(1, -1, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) { 0 } }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int, parentMaxSubtreeSize: Int): (Int, Int) = {

    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    val maxForward = maxSubtreeSizeFrom(u).max

    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1, maxForward)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize) maxSubtreeSize = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize) maxSubtreeSize = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
      if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = parentMaxSubtreeSize
      if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize)
  }

  dfs(0, -1, 0, 0, 0)
  dfs(last, -1, 0, 0, 0)

  val maxSubtreeSize2 = for (u <- 0 until n) yield {
    val maxWithInd = for (i <- adjs(u).indices) yield maxSubtreeSizeFrom(u)(i) -> adjs(u)(i)
    maxWithInd.sortBy(- _._1).take(2)
  }

 // sizeFrom.foreach(s => println(s.mkString(" ")))
  //maxSubtreeSizeFrom.foreach(s => println(s.mkString(" ")))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = maxSubtreeSize2(v).filter(_._2 != u).headOption.map(_._1)
        if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSizeFrom = Array.tabulate(n) { i => Array.fill(adjs(i).length) { 0 } }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int, parentMaxSubtreeSize: Int): (Int, Int) = {

    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }

    var i = 0
    var childrenSize = 1
    var parentPos = -1
    var maxSubtreeSize = 0

    while (i < adjs(u).length) {
      if (adjs(u)(i) == parent) parentPos = i
      i += 1
    }

    if (parentPos >= 0) {
      if (parentMaxSubtreeSize <= m && parentMaxSubtreeSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = parentMaxSubtreeSize
      //if (n - childrenSize <= m && n - childrenSize > maxSubtreeSizeFrom(u)(parentPos)) maxSubtreeSizeFrom(u)(parentPos) = n - childrenSize
    }

    val maxForwardA = maxSubtreeSizeFrom(u).max
    val maxForwardB = maxSubtreeSizeFrom(u).sum + 1
    var maxForward = 0
    if (maxForwardA <= m) maxForward = maxForwardA
    //if (maxForwardB <= m && maxForwardB > maxForward) maxForward = maxForwardB

    i = 0
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v != parent) {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1, maxForward)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSizeFrom(u)(i)) maxSubtreeSizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize) maxSubtreeSize = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize) maxSubtreeSize = vSubtreeSize
      }
      i += 1
    }

    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }

    (childrenSize, maxSubtreeSize)
  }

  dfs(0, -1, 0, 0, 0)
  dfs(last, -1, 0, 0, 0)
  dfs(last, -1, 0, 0, 0)

  //maxSubtreeSizeFrom.foreach(s => println(s.mkString(" ")))

  val maxSubtreeSize2 = for (u <- 0 until n) yield {
    val maxWithInd = for (i <- adjs(u).indices) yield maxSubtreeSizeFrom(u)(i) -> adjs(u)(i)
    maxWithInd.sortBy(- _._1).take(2)
  }

  //maxSubtreeSize2.foreach(s => println(s.mkString(" ")))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        val sub = maxSubtreeSize2(v).filter(_._2 != u).headOption.map(_._1)
        if (sub == None || sizeFrom(u)(i) - sub.get > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int): (Int, Int) = {
    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0, 0)
  dfs(last, -1, 0, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = (n - 1) / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }
  var last = 0
  var maxDepth = -1

  def dfs(u: Int, parent: Int, size: Int, depth: Int): (Int, Int) = {
    if (depth > maxDepth) {
      last = u
      maxDepth = depth
    }
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1, depth + 1)
        childrenSize += vSubtreeSize
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0, 0)
  dfs(last, -1, 0, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}

import scala.collection.mutable

object C extends App {

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

  val Array(n) = readInts(1)
  val m = n / 2

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

  for (_ <- 1 until n) {
    val Array(u, v) = readInts(2)
    adjBuilders(u - 1) += v - 1
    adjBuilders(v - 1) += u - 1
  }

  val adjs = adjBuilders.map(_.result)
  val res = Array.fill(n){ 0 }
  val sizeFrom = Array.tabulate(n) { i => Array.ofDim[Int](adjs(i).length)}
  val maxSubtreeSize = Array.fill(n) { 0 }

  def dfs(u: Int, parent: Int, size: Int): (Int, Int) = {
    var i = 0
    var childrenSize = 1
    var parentPos = -1
    while (i < adjs(u).length) {
      val v = adjs(u)(i)
      if (v == parent) {
        parentPos = i
      } else {
        val (vSubtreeSize, vMaxSubtreeSize) = dfs(v, u, size + 1)
        childrenSize += vSubtreeSize
        (vSubtreeSize, vMaxSubtreeSize)
        sizeFrom(u)(i) = vSubtreeSize
        if (vMaxSubtreeSize <= m && vMaxSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vMaxSubtreeSize
        if (vSubtreeSize <= m && vSubtreeSize > maxSubtreeSize(u)) maxSubtreeSize(u) = vSubtreeSize
      }
      i += 1
    }
    if (parentPos >= 0) {
      sizeFrom(u)(parentPos) = n - childrenSize
    }
    (childrenSize, maxSubtreeSize(u))
  }

  dfs(0, -1, 0)

  //sizeFrom.foreach(s => println(s.mkString(" ")))
  //println(maxSubtreeSize.mkString(" "))

  for (u <- 0 until n) {
    var ok = true
    for (i <- adjs(u).indices) {
      val v = adjs(u)(i)
      if (sizeFrom(u)(i) > m) {
        if (sizeFrom(u)(i) - maxSubtreeSize(v) > m) ok = false
      }
    }
    res(u) = if (ok) 1 else 0
  }

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

  println(res.mkString(" "))

  Console.flush
}


object b extends App {
  class Point(val x: Long, val y: Long) extends Ordered[Point] {
	    def - (that: Point): Point = new Point(x - that.x, y - that.y)
	    def ^ (that: Point): Long = x * that.y - y * that.x
	    def * (that: Point): Long = x * that.x + y * that.y
	    override def compare(that: Point) = len compare that.len
	    def len = math.sqrt(x * x + y * y)
	  }
	  def readPoint = {
	    val line = readLine.split(" ")
	    new Point(line(0).toInt, line(1).toInt)
	  }

	  def readInput(n: Int, acc: List[Point] = Nil): List[Point] =
	    if (n == 0)
	      acc
	    else
	      readInput(n - 1, readPoint :: acc)

	  val line = readLine.split(" ")
	  val n = line(0).toInt
	  val p = new Point(line(1).toInt, line(2).toInt)
	  val arr = new Array[Point](n)
	  for (i <- 0 until n)
	    arr(i) = readPoint
	  //if (n == 100000)
	  //  throw new Exception
	  val dists = for (i <- 0 until n if (arr(i) - arr((i + 1) % n)) * (p - arr((i + 1) % n)) >= 0 &&
	      (arr((i + 1) % n) - arr(i)) * (p - arr(i)) >= 0 && arr(i) != arr((i + 1) % n))
	    yield math.abs(((arr(i) - p) ^ (arr((i + 1) % n) - p)) / (arr(i) - arr((i + 1) % n)).len)

	  val dmin = if (dists.length == 0) 1e15; else dists.min
	  val min = List(dmin, arr.map(cur_p => (cur_p - p)).min.len).min
	  val max = arr.map(cur_p => (cur_p - p)).max
	  println((max.len * max.len - min * min) * math.Pi)
}

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

object _614C extends CodeForcesApp {
  override def apply(io: IO) = {
    val (n, z) = io[(Int, Point2D)]
    val ps = io[Seq, Point2D](n)
    val shape = (ps :+ ps.head) sliding 2 map {case Seq(p1, p2) => new Line2D.Double(p1, p2)}
    val closest = shape.map(_.ptSegDistSq(z))
    val farthest = ps.map(_.distanceSq(z))
    io += Math.PI * (farthest.max - closest.min)
  }
}
/****************************[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 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 = t.head.ensuring(t.size == 1)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap
  }
  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 PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).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 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 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 LongExtensions(val x: Long) extends AnyVal {
    def bitCount: Int = java.lang.Long.bitCount(x)
  }
  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 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(n.min(x, y), n.max(x, y), n.one)
  }
  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] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])
  }
  def memoize[I] = new {
    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {
      override def apply(key: I) = getOrElseUpdate(key, f(key))
    }
  }
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  val mod: Int = (1e9 + 7).toInt
  val newLine: String = "\n"
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer, java.awt.geom._

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {
  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

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

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

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine(): String = till("\n\r")

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

  var separator = " "
  private[this] var isNewLine = true

  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {
    write(this)(x)
    this
  }
  def ++=[A: IO.Write](xs: Traversable[A]): this.type = this.+=(xs.size).appendNewLine().+=(xs)

  def appendNewLine(): this.type = {
    println()
    this
  }

  override def print(obj: String) = {
    if (isNewLine) isNewLine = false else super.print(separator)
    super.print(obj)
  }
  override def println() = if (!isNewLine) {
    super.println()
    isNewLine = true
  }
  override def close() = {
    flush()
    in.close()
    super.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[C, A](r[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)
    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[A], r[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))
    implicit val point                                        : Read[Point2D]      = tuple2[Double, Double].map {case (x, y) => new Point2D.Double(x, y)}
  }
  trait Write[-A] {
    def apply(out: PrintWriter)(x: A): Unit
  }
  trait DefaultWrite {
    implicit def any[A]: Write[A] = Write(_.toString)
  }
  object Write extends DefaultWrite {
    def apply[A](f: A => String) = new Write[A] {
      override def apply(out: PrintWriter)(x: A) = out.print(f(x))
    }
    implicit val boolean: Write[Boolean] = Write(b => if (b) "YES" else "NO")
    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s"$a $b"}
    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {
      override def apply(out: PrintWriter)(xs: Traversable[A]) = {
        xs foreach write(out)
        out.println()
      }
    }
  }
}

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

object _614C extends CodeForcesApp {
  override def apply(io: IO) = {
    val (n, z) = io[(Int, Point2D)]
    val ps = io[Seq, Point2D](n)
    val shape = ((ps :+ ps.head) sliding 2 map {case Seq(p1, p2) => new Line2D.Double(p1, p2)}).toSeq
    val closest = shape map {line => line ptSegDistSq z}
    val farthest = shape map {line => (line.getP1 distanceSq z) max (line.getP2 distanceSq z)}
    io += Math.PI * (farthest.max - closest.min)
  }
}
/****************************[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 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 = t.head.ensuring(t.size == 1)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap
  }
  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 PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_._1).mapValues(_._2)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_._1).mapValues(_.map(_._2).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 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 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 LongExtensions(val x: Long) extends AnyVal {
    def bitCount: Int = java.lang.Long.bitCount(x)
  }
  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 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(n.min(x, y), n.max(x, y), n.one)
  }
  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] = Dict.empty[K, V] withDefaultValue default // also to(Dict.empty[K2, V])
  }
  def memoize[I] = new {
    def apply[O](f: I => O): I => O = new mutable.HashMap[I, O]() {
      override def apply(key: I) = getOrElseUpdate(key, f(key))
    }
  }
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  val mod: Int = (1e9 + 7).toInt
  val newLine: String = "\n"
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer, java.awt.geom._

class IO(in: BufferedReader, out: BufferedWriter) extends PrintWriter(out, true) with Iterator[String] {
  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

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

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

  def till(delim: String): String = tokenizer().get.nextToken(delim)
  def tillEndOfLine(): String = till("\n\r")

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

  var separator = " "
  private[this] var isNewLine = true

  def +=[A](x: A)(implicit write: IO.Write[A]): this.type = {
    write(this)(x)
    this
  }
  def ++=[A: IO.Write](xs: Traversable[A]): this.type = this.+=(xs.size).appendNewLine().+=(xs)

  def appendNewLine(): this.type = {
    println()
    this
  }

  override def print(obj: String) = {
    if (isNewLine) isNewLine = false else super.print(separator)
    super.print(obj)
  }
  override def println() = if (!isNewLine) {
    super.println()
    isNewLine = true
  }
  override def close() = {
    flush()
    in.close()
    super.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[C, A](r[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val boolean                                      : Read[Boolean]      = string.map(_.toBoolean)
    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[A], r[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r[A], r[B], r[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r[A], r[B], r[C], r[D]))
    implicit val point                                        : Read[Point2D]      = tuple2[Double, Double].map {case (x, y) => new Point2D.Double(x, y)}
  }
  trait Write[-A] {
    def apply(out: PrintWriter)(x: A): Unit
  }
  trait DefaultWrite {
    implicit def any[A]: Write[A] = Write(_.toString)
  }
  object Write extends DefaultWrite {
    def apply[A](f: A => String) = new Write[A] {
      override def apply(out: PrintWriter)(x: A) = out.print(f(x))
    }
    implicit val boolean: Write[Boolean] = Write(b => if (b) "YES" else "NO")
    implicit def tuple2[A, B]: Write[(A, B)] = Write {case (a, b) => s"$a $b"}
    implicit def iterable[A](implicit write: Write[A]): Write[Traversable[A]] = new Write[Traversable[A]] {
      override def apply(out: PrintWriter)(xs: Traversable[A]) = {
        xs foreach write(out)
        out.println()
      }
    }
  }
}

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

object _614C extends CodeForcesApp {
  override type Result = BigDecimal

  override def solve(scanner: Scanner) = {
    import scanner._
    val (n, px, py) = (nextInt(), nextBigInt(), nextBigInt())
    val polygon = Seq.fill(n)(nextBigInt() -> nextBigInt())
    val radii = polygon map {case (x, y) => (px - x)*(px - x) + (py - y)*(py - y)}
    BigDecimal(radii.max - radii.min) * BigDecimal(Math.PI)
  }
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null)

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

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

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

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

object _614C extends CodeForcesApp {
  override type Result = Double

  override def solve(scanner: Scanner) = {
    import scanner._
    val (n, px, py) = (nextInt(), nextLong(), nextLong())
    val polygon = Seq.fill(n)(nextLong() -> nextLong())
    val radii = polygon map {case (x, y) =>
      (px - x)*(px - x) + (py - y)*(py - y)
    }
    Math.PI * (radii.max - radii.min)
  }
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null)

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

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

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

object Main extends App {
	  class Point(val x: Int, val y: Int) extends Ordered[Point] {
	    def - (that: Point): Point = new Point(x - that.x, y - that.y)
	    override def compare(that: Point) = len compare that.len
	    val len = math.sqrt(x * x + y * y)
	  }
	  def readPoint = {
	    val line = readLine.split("\\s+")
	    new Point(line(0).toInt, line(1).toInt)
	  }
	  def readInput(n: Int, acc: List[Point] = Nil): List[Point] =
	    if (n == 0)
	      acc
	    else
	      readInput(n - 1, readPoint :: acc)
	  val line = readLine.split("\\s+")
	  val n = line(0).toInt
	  val p = new Point(line(1).toInt, line(2).toInt)
	  val arr = readInput(n)
	  val min = arr.map(cur_p => (cur_p - p)).min
	  val max = arr.map(cur_p => (cur_p - p)).max
	  println((max.len * max.len - min.len * min.len) * math.Pi)
}

object Main extends App {
	  class Point(val x: Int, val y: Int) extends Ordered[Point] {
	    def - (that: Point): Point = new Point(x - that.x, y - that.y)
	    def ^ (that: Point): Long = x.toLong * that.y - y.toLong * that.x
	    def * (that: Point): Long = x.toLong * that.x + y.toLong * that.y
	    override def compare(that: Point) = len compare that.len
	    val len = math.sqrt(x * x + y * y)
	  }
	  def readPoint = {
	    val line = readLine.split("\\s+")
	    new Point(line(0).toInt, line(1).toInt)
	  }
	  def readInput(n: Int, acc: List[Point] = Nil): List[Point] =
	    if (n == 0)
	      acc
	    else
	      readInput(n - 1, readPoint :: acc)
	  val line = readLine.split("\\s+")
	  val n = line(0).toInt
	  val p = new Point(line(1).toInt, line(2).toInt)
	  val arr = readInput(n)

	  val dists = for (i <- 0 until n if (arr(i) - arr((i + 1) % n)) * (arr(i) - p) >= 0 &&
	      (arr((i + 1) % n) - arr(i)) * (arr((i + 1) % n) - p) >= 0)
	    yield ((arr(i) - p) ^ (arr((i + 1) % n) - p)) / (arr(i) - arr((i + 1) % n)).len

	  val min = List(dists.min, arr.map(cur_p => (cur_p - p)).min.len).min

	  val max = arr.map(cur_p => (cur_p - p)).max
	  println((max.len * max.len - min * min) * math.Pi)
}

object b extends App {
  class Point(val x: Int, val y: Int) extends Ordered[Point] {
	    def - (that: Point): Point = new Point(x - that.x, y - that.y)
	    def ^ (that: Point): Long = x.toLong * that.y - y.toLong * that.x
	    def * (that: Point): Long = x.toLong * that.x + y.toLong * that.y
	    override def compare(that: Point) = len compare that.len
	    def len = math.sqrt(x * x + y * y)
	  }
	  def readPoint = {
	    val line = readLine.split(" ")
	    new Point(line(0).toInt, line(1).toInt)
	  }

	  def readInput(n: Int, acc: List[Point] = Nil): List[Point] =
	    if (n == 0)
	      acc
	    else
	      readInput(n - 1, readPoint :: acc)

	  val line = readLine.split(" ")
	  val n = line(0).toInt
	  val p = new Point(line(1).toInt, line(2).toInt)
	  val arr = new Array[Point](n)
	  for (i <- 0 until n)
	    arr(i) = readPoint
	  //if (n == 100000)
	  //  throw new Exception
	  val dists = for (i <- 0 until n if (arr(i) - arr((i + 1) % n)) * (p - arr((i + 1) % n)) >= 0 &&
	      (arr((i + 1) % n) - arr(i)) * (p - arr(i)) >= 0 && arr(i) != arr((i + 1) % n))
	    yield math.abs(((arr(i) - p) ^ (arr((i + 1) % n) - p)) / (arr(i) - arr((i + 1) % n)).len)

	  val dmin = if (dists.length == 0) 1e15; else dists.min
	  val min = List(dmin, arr.map(cur_p => (cur_p - p)).min.len).min
	  val max = arr.map(cur_p => (cur_p - p)).max
	  println((max.len * max.len - min * min) * math.Pi)
}

object b extends App {
  class Point(val x: Int, val y: Int) extends Ordered[Point] {
	    def - (that: Point): Point = new Point(x - that.x, y - that.y)
	    def ^ (that: Point): Long = x.toLong * that.y - y.toLong * that.x
	    def * (that: Point): Long = x.toLong * that.x + y.toLong * that.y
	    override def compare(that: Point) = len compare that.len
	    def len = math.sqrt(x * x + y * y)
	  }
	  def readPoint = {
	    val line = readLine.split(" ")
	    new Point(line(0).toInt, line(1).toInt)
	  }

	  def readInput(n: Int, acc: List[Point] = Nil): List[Point] =
	    if (n == 0)
	      acc
	    else
	      readInput(n - 1, readPoint :: acc)

	  val line = readLine.split(" ")
	  val n = line(0).toInt
	  val p = new Point(line(1).toInt, line(2).toInt)
	  val arr = new Array[Point](n)
	  for (i <- 0 until n)
	    arr(i) = readPoint
	  //if (n == 100000)
	  //  throw new Exception
	  val dists = for (i <- 0 until n if (arr(i) - arr((i + 1) % n)) * (p - arr((i + 1) % n)) >= 0 &&
	      (arr((i + 1) % n) - arr(i)) * (p - arr(i)) >= 0)
	    yield math.abs(((arr(i) - p) ^ (arr((i + 1) % n) - p)) / (arr(i) - arr((i + 1) % n)).len)

	  val dmin = if (dists.length == 0) 1e15; else dists.min
	  val min = List(dmin, arr.map(cur_p => (cur_p - p)).min.len).min
	  val max = arr.map(cur_p => (cur_p - p)).max
	  println((max.len * max.len - min * min) * math.Pi)
}

object Main extends App {
	  class Point(val x: Int, val y: Int) extends Ordered[Point] {
	    def - (that: Point): Point = new Point(x - that.x, y - that.y)
	    def * (that: Point): Long = x.toLong * that.y - y * that.x
	    override def compare(that: Point) = len compare that.len
	    val len = math.sqrt(x * x + y * y)
	  }
	  def readPoint = {
	    val line = readLine.split("\\s+")
	    new Point(line(0).toInt, line(1).toInt)
	  }
	  def readInput(n: Int, acc: List[Point] = Nil): List[Point] =
	    if (n == 0)
	      acc
	    else
	      readInput(n - 1, readPoint :: acc)
	  val line = readLine.split("\\s+")
	  val n = line(0).toInt
	  val p = new Point(line(1).toInt, line(2).toInt)
	  val arr = readInput(n)

	  val dists = for (i <- 0 until n)
	    yield arr(i) * arr((i + 1) % n) / (arr(i) - arr((i + 1) % n)).len

	  val min = dists.min

	  val max = arr.map(cur_p => (cur_p - p)).max
	  println((max.len * max.len - min * min) * math.Pi)
}

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

object _614C extends CodeForcesApp {
  override type Result = Double

  override def solve(scanner: Scanner) = {
    import scanner._
    val (n, px, py) = (nextInt(), nextInt(), nextInt())
    val polygon = Seq.fill(n)(nextInt() -> nextInt())
    val radii = polygon map {
      case (x, y) => Math.sqrt(((px - x)*(px - x) + (py - y)*(py - y)).toDouble)
    }
    val (r2, r1) = (radii.max, radii.min)
    Math.PI * ((r2 * r2) - (r1 * r1))
  }
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
 * Scala implementation of a faster java.util.Scanner
 * See: http://codeforces.com/blog/entry/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
  def this(str: String) = this(new StringReader(str))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null)

  private[this] val tokenizers = lines.map(new StringTokenizer(_)).filter(_.hasMoreTokens)
  private[this] var current: Option[StringTokenizer] = None

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

  /**
   * Unlike Java's scanner which returns till end of current line, this actually returns the next line
   * @see line() if you want the Java behaviour
   */
  def nextLine(): String = {
    current = None   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}


import scala.io.StdIn._

object EducationalGame178A2  extends App {

    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)

    val toPrint = (0 until (n-1)).scanLeft(0: Long){case (prev,indx) => {
      val currentCell = a(indx)

      val t = 1 << minimun2k(n-indx-1)

      a(indx+t) += currentCell
      prev+currentCell
    }}.tail.mkString(System.lineSeparator())

    System.out.println(toPrint)

  /**
    * 2^k <= n < 2^(k+1)
    * @param n
    * @return k
    */
  def minimun2k(n: Int): Int = {
    var k = 0
    var nn = n
    while(nn > 1){
      k+=1
      nn >>=1
    }
    k
  }
}

object EducationalGame178A2 extends App {
  import java.io.{InputStream, PrintStream}
  import java.util.Scanner
  solve(System.in,System.out)
  def solve(in: InputStream, out: PrintStream): Unit = {
    val scanner = new Scanner(in)
    val n = scanner.nextInt()
    val a = (1 to n).map(_ => scanner.nextLong()).toArray
    val results = Array.fill(n)(0)
    (0 until (n-1)).scanLeft(0: Long){case (prev,indx) => {
      val currentCell = a(indx)

      val t = 1 << minimun2k(n-indx-1)

      a(indx) = 0
      a(indx+t) += currentCell
      prev+currentCell
    }}.tail.foreach(out.println)

  }

  /**
    * 2^k <= n < 2^(k+1)
    * @param n
    * @return k
    */
  def minimun2k(n: Int): Int = {
    var k = 0
    var nn = n
    while(nn > 1){
      k+=1
      nn >>=1
    }
    k
  }
}

object EducationalGame178A2 extends App {
  import java.io.{InputStream, PrintStream}
  import java.util.Scanner
  //solve(System.in,System.out)
  def solve(in: InputStream, out: PrintStream): Unit = {
    val scanner = new Scanner(in)
    val n = scanner.nextInt()
    val a = (1 to n).map(_ => scanner.nextLong()).toArray
    val results = Array.fill(n)(0)
    (0 until (n-1)).scanLeft(0: Long){case (prev,indx) => {
      val currentCell = a(indx)

      val t = 1 << minimun2k(n-indx-1)

      a(indx) = 0
      a(indx+t) += currentCell
      prev+currentCell
    }}.tail.foreach(out.println)

  }

  /**
    * 2^k <= n < 2^(k+1)
    * @param n
    * @return k
    */
  def minimun2k(n: Int): Int = {
    var k = 0
    var nn = n
    while(nn > 1){
      k+=1
      nn >>=1
    }
    k
  }
}


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

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

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

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

  def solve(): Unit = {
    val n, L, a = ni()
    val t, l = Array.ofDim[Int](n + 2)
    t(0) = -1
    l(0) = 1
    rep(n, 1) { i =>
      t(i) = ni()
      l(i) = ni()
    }
    t(n + 1) = L
    l(n + 1) = 1

    var ans = 0
    rep(n + 1) { i =>
      val len = t(i + 1) - (t(i) + l(i))
      ans += len / a
    }

    out.println(ans)
  }

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

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

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

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

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

import scala.io.StdIn

object TaskA extends App {

  val Array(n, l, a) = StdIn.readLine.split(" ").map(_.toInt)

  def getCountCoffeeBreak(n: Int, L: Int, a: Int):Int = {
    if(n == 0) L / a
    else {
      val Array(t, l) = StdIn.readLine.split(" ").map(_.toInt)
      t / a + getCountCoffeeBreak(n - 1, L, a, t + l)
    }
  }

  def getCountCoffeeBreak(n: Int, L: Int, a: Int, last_end_time: Int):Int = {
    if(n == 0) (L - last_end_time) / a
    else {
      val Array(t, l) = StdIn.readLine.split(" ").map(_.toInt)
      (t - last_end_time) / a + getCountCoffeeBreak(n - 1, L, a, t + l)
    }
  }

  println(getCountCoffeeBreak(n, l, a))
}

object A extends App {
    import java.io.{PrintWriter, InputStreamReader, BufferedReader}
    import java.util.{Locale, Scanner}
    import scala.collection.mutable._

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = bufferedIn.readLine

    def solve = {
        val n = nextInt
        val L = nextInt
        val a = nextInt
        var ans = 0
        var cur = 0

        // println(s"$n $L $a")

        for (i <- 0 until n) {
            val ti = nextInt
            val li = nextInt

            ans += (ti - cur) / a
            cur = ti + li
        }
        ans += (L - cur) / a

        println(ans)
    }

    solve
}


object A extends App {

  def era(an: IndexedSeq[Int]): Long =
    an.zipWithIndex.foldLeft(0L) {
      case (count, (ai, i)) if ai <= i + 1 + count => count
      case (count, (ai, i))                        => ai - i - 1
    }

  import InOut._

  val t = nextInt()

  (0 until t).foreach { _ =>
    val n     = nextInt()
    val an    = nextInts(n)
    val count = era(an)

    out.println(count)
  }

  out.flush()

  object InOut {
    val in  = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    val out = new java.io.PrintWriter(System.out, false)

    def nextInt()        = Integer.parseInt(nextToken())
    def nextInts(n: Int) = Array.fill(n)(nextInt())

    def nextLong()        = java.lang.Long.parseLong(nextToken())
    def nextLongs(n: Int) = Array.fill(n)(nextLong())

    def nextBig()        = BigInt(nextToken())
    def nextBigs(n: Int) = Array.fill(n)(nextBig())

    def nextLine() = in.readLine()

    private[this] var tokenizer: java.util.StringTokenizer = _

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

}

import java.io._
import java.util.StringTokenizer
import scala.+:
import scala.collection.mutable
import scala.collection.mutable._
import scala.collection.immutable._
import scala.util.Sorting.quickSort
import scala.math._

object Main extends App {
    val writer =  new PrintWriter(System.out, false)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {while (!st.hasMoreTokens) {st = new StringTokenizer(reader.readLine())};st.nextToken()}
    def readInt(): Int = next().toInt
    def readLong(): Long = next().toLong
    def readString(): String = next()

    case class pair(var minl: Int, var maxl:  Int, var minr: Int, var maxr:  Int, var ind:  Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return minl.compareTo(that.minl)
        }
    }
    val rem = 1000000007
    def gcd(a: Int, b: Int): Int = b match {
        case 0 => a
        case n => gcd(b, a % b)
    }

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        var ans = 0
        for (i <- 1 to n) {
            val k = readInt()
            ans = max(ans, k - i)
        }
        writer.println(ans)
    }
    writer.flush()
}


object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private[this] val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = {
    if (!oj){ System.err.println(s) }
  }
  def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

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

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

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

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

object Workspace {
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  def packUGraph(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    REP(m)(i => p(from(i)) += 1)
    REP(m)(i => p(to(i)) += 1)
    REP(n)(i => t(i) = new Array(p(i)))
    REP(m) { i =>
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
      p(to(i)) -= 1
      t(to(i))(p(to(i))) = from(i)
    }
    t
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) extends Runnable {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer
  import Workspace._

  // toIntとか+7とかするならvalにしろ
  final private[this] val MOD = 1000000007

  def solve(): Unit ={
    val t = new Thread(null, this, "solve", 1 << 27)
    t.start()
    t.join()
  }

  def run(): Unit = {
    val N = ni()
    val (from, to) = na2(N - 1, -1)
    val g = packUGraph(N, from, to)

    var n = 1
    val seg = Array.ofDim[Int](N, 2)

    def dfs(v: Int, p: Int): Unit = {
      if (seg(v)(0) == 0) {
        seg(v)(0) = n
        n += 1
      }

      var j = 0
      while(j < g(v).length) {
        val u = g(v)(j)
        if (u != p) {
          seg(u)(0) = n
          n += 1
        }
        j += 1
      }
      seg(v)(1) = n
      n += 1

      j = g(v).length - 1
      while(j >= 0) {
        val u = g(v)(j)
        if (u != p) {
          dfs(u, v)
        }
        j -= 1
      }
    }

    dfs(0, -1)
    REP(N) { v =>
      out.println(s"${seg(v)(0)} ${seg(v)(1)}")
    }
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private[this] val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = {
    if (!oj){ System.err.println(s) }
  }
  def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

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

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

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

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

object Workspace {
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  def packUGraph(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    REP(m)(i => p(from(i)) += 1)
    REP(m)(i => p(to(i)) += 1)
    REP(n)(i => t(i) = new Array(p(i)))
    REP(m) { i =>
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
      p(to(i)) -= 1
      t(to(i))(p(to(i))) = from(i)
    }
    t
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) extends Runnable {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer
  import Workspace._

  // toIntとか+7とかするならvalにしろ
  final private[this] val MOD = 1000000007

  def solve(): Unit ={
    val t = new Thread(null, this, "solve", 1 << 26)
    t.start()
    t.join()
  }

  def run(): Unit = {
    val N = ni()
    val (from, to) = na2(N - 1, -1)
    val g = packUGraph(N, from, to)

    var n = 1
    val seg = Array.ofDim[Int](N, 2)

    def dfs(v: Int, p: Int): Unit = {
      if (seg(v)(0) == 0) {
        seg(v)(0) = n
        n += 1
      }

      var j = 0
      while(j < g(v).length) {
        val u = g(v)(j)
        if (u != p) {
          seg(u)(0) = n
          n += 1
        }
        j += 1
      }
      seg(v)(1) = n
      n += 1

      j = g(v).length - 1
      while(j >= 0) {
        val u = g(v)(j)
        if (u != p) {
          dfs(u, v)
        }
        j -= 1
      }
    }

    dfs(0, -1)
    REP(N) { v =>
      out.println(s"${seg(v)(0)} ${seg(v)(1)}")
    }
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private[this] val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = {
    if (!oj){ System.err.println(s) }
  }
  def isDebug[A](debug: => A, online: => A): A = {
    if (oj) online else debug
  }

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

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

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

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

object Workspace {
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  def packUGraph(n: Int, from: Array[Int], to: Array[Int]): Array[Array[Int]] = {
    val t = new Array[Array[Int]](n)
    val p = new Array[Int](n)
    val m = from.length
    REP(m)(i => p(from(i)) += 1)
    REP(m)(i => p(to(i)) += 1)
    REP(n)(i => t(i) = new Array(p(i)))
    REP(m) { i =>
      p(from(i)) -= 1
      t(from(i))(p(from(i))) = to(i)
      p(to(i)) -= 1
      t(to(i))(p(to(i))) = from(i)
    }
    t
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) extends Runnable {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer
  import Workspace._

  // toIntとか+7とかするならvalにしろ
  final private[this] val MOD = 1000000007

  def solve(): Unit ={
    val t = new Thread(null, this, "solve", 1 << 26)
    t.start()
    t.join()
  }

  def run(): Unit = {
    val N = ni()
    val (from, to) = na2(N - 1, -1)
    val g = packUGraph(N, from, to)

    var n = 1
    val seg = Array.ofDim[Int](N, 2)

    def dfs(v: Int, p: Int): Unit = {
      if (seg(v)(0) == 0) {
        seg(v)(0) = n
        n += 1
      }

      REP(g(v).length) { j =>
        val u = g(v)(j)
        if (u != p) {
          seg(u)(0) = n
          n += 1
        }
      }
      seg(v)(1) = n
      n += 1

      REP(g(v).length) { j =>
        val u = g(v)(j)
        if (u != p) {
          dfs(u, v)
        }
      }
    }

    dfs(0, -1)
    REP(N) { v =>
      out.println(s"${seg(v)(0)} ${seg(v)(1)}")
    }
  }
}