object Main {
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val m = cin.nextInt()
    val n = cin.nextInt()
    var ans: Double = 0.0
    for (i <- 1 to m)
      ans += i * (Math.pow(i.toDouble / m, n) - Math.pow((i - 1.0) / m, n))
    println(ans)
  }
}

import java.io.PrintWriter
import java.util.Scanner

/**
 * Created by arseny on 01.08.14.
 */
object C extends App {

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val m = nextDouble
    val n = nextDouble
    if (m == 1) {
      out.println(1)
    } else {
      var ans = m
      for (i <- 1 to (m - 1).toInt) {
        val p = i.toDouble / m
        val q = math.pow(p, n)
        ans = ans - q
      }
      out.println("%.6f".format(ans))
    }
  }

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

/**
 * I've tried to make this piece of code as readable as possible.
 * Enjoy hacking it!
 */
import scala.collection._

object C extends App {

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

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

  val mn = math.pow(m.toDouble, n)
  var sum = 0d
  var prevCount = 0d
  for (i <- 1 to m) {
    val count = math.pow(i.toDouble / m.toDouble, n)
    //println(sum, count, i)
    sum += (count - prevCount) * i
    prevCount = count// - prevCount
  }

  println(sum)
}

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

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

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

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

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

  def solve: Int = {
    val m = nextInt
    val n = nextInt
    var ans: Double = m.toDouble
    for (i <- 0 to m - 1) {
      ans -= Math.pow(i.toDouble / m.toDouble, n)
    }
    out.println(ans)
    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

import scala.io.StdIn._

object Main {

  def power(a: Double, n: Int): Double = {
    var ans = 1.0
    var b = a
    var p = n
    while (p > 0) {
      if ( (p & 0x01) != 0) ans = b * ans
      b = b * b
      p = p >> 1;
    }
    ans
  }
  def main(args: Array[String]): Unit = {
    val mn = readLine.split(" ").map(_.toInt)
    val m = mn.head
    val n = mn.last
    val ans = (1 to m).map { k =>
      k * (power((k*1.0)/m, n) - power(((k*1.0) - 1.0)/m, n))
    }.sum
    println(ans)
  }
}

object Main {
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val m = cin.nextInt()
    val n = cin.nextInt()
    def solve(i: Int, res: Double):Double =
      if (i == 0) res
      else solve(i - 1, res + i * (Math.pow((1.0 * i) / m, n) - Math.pow((i - 1.0) / m, n)))
    println(solve(m, 0))
  }
}

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

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

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

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

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

  def solve: Int = {
    val m = nextInt
    val n = nextInt
    var ans: Double = 0.0d
    val delimeter: Double = Math.pow(m, n)
    for (i <- 1 to m) {
      ans += Math.pow(i.toDouble, n + 1) - Math.pow(i - 1, n) * i.toDouble
    }
    out.println(ans / delimeter)
    return 1
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}


import scala.io.Source
import scala.collection.mutable

object Main extends App {
  // process input!
  val input = Source.stdin.getLines.map(_.split(" ").map(_.toInt))
  type Node = Int
  type Weight = Int
  val graph = mutable.Map.empty[Node, mutable.Map[Node, Weight]]
  val (n :: numEdges :: Nil) = input.next.toList
  val edges = input.map(_.toList)

  // construct the graph!
  def makeEdge(from: Node, to: Node, weight: Weight) = {
      val source = graph.getOrElseUpdate(from, mutable.Map.empty[Node, Weight])
      source.get(to) match {
        case None => source.update(to, weight)
        case Some(prevWeight) => if(weight < prevWeight) source.update(to, weight)
      }
  }
  edges.foreach {
    case from :: to :: weight :: Nil => {
      makeEdge(from, to, weight)
      makeEdge(to, from, weight)
    }
    case _ => ()
  }

  // Prepare for Dijkstra! This represents a graph path!
  case class Path(val fullPath: List[Node], val cost: Weight) {
    def location = fullPath.head
    override def toString = fullPath.mkString(" ")
  }

  // Sort by lowest cost! and then target, so paths with same weight don't clobber each other!
  implicit val pathOrdering: Ordering[Path] = Ordering.by(path => (path.cost, path.location))

  // For example, we begin at node 1 with a cost of 0!
  val end = Path(List(n), 0)

  // Here are the Dijkstra Data Doodads of Doom!
  val conquered = mutable.Set.empty[Node]
  val frontier = new java.util.PriorityQueue[Path](10, pathOrdering)
  frontier.offer(end)

  // Here is the algorithm! Yay! I AM NAPOLEON!!!!
  var warPath: Option[Path] = None
  while(warPath.isEmpty && !frontier.isEmpty) {
    val battlefield = frontier.poll
    val location = battlefield.location
    if(location == 1) {
      warPath = Some(battlefield)
    } else {
      conquered += location
      for {
        connections <- graph.get(location).toList
        (target, weight) <- connections
        if !conquered(target)
      } yield {
        frontier.add(Path(
          fullPath = target :: battlefield.fullPath,
          cost = battlefield.cost + weight))
      }
    }
  }

  // And our answer!!!!!!!!!!!
  warPath match {
    case None => println("-1")
    case Some(path) => println(path)
  }
}

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

object C {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

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

  def nextInt: Int = {
    return Integer.parseInt(next)
  }

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

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val g = new ArrayList[List[(Int, Long)]]
    for (i <- 0 until n) {
      g.add(new util.ArrayList[(Int, Long)]())
    }
    for (i <- 0 until m) {
      val a = nextInt - 1
      val b = nextInt - 1
      val len = nextLong
      g.get(a).add((b, len))
      g.get(b).add((a, len))
    }
    val graph = new Array[Array[(Int, Long)]](n)
    for (i <- 0 until n) {
      graph(i) = new Array[(Int, Long)](g.get(i).size)
      val len = graph(i).length
      for (j <- 0 until len) {
        graph(i)(j) = g.get(i).get(j)
      }
    }

    object Dijkstra {
      val path = new Array[Int](n)

      def findShortestPath(start: Int, end: Int): (Long, Array[Int]) = {
        val dist = new Array[Long](n)
        val relaxed = new Array[Boolean](n)
        Arrays.fill(dist, Long.MaxValue)
        dist(start) = 0
        val set = new util.PriorityQueue[Edge]()
        val path = new Array[Int](n)
        Arrays.fill(path, -1)
        set.add(new Edge(dist(start), start))
        while (!set.isEmpty) {
          val v = set.poll().to
          if (!relaxed(v)) {
            for (i <- 0 until graph(v).length) {
              val to = graph(v)(i)._1
              val len = graph(v)(i)._2
              if (dist(v) + len < dist(to)) {
                relaxed(v) = true
                dist(to) = dist(v) + len
                path(to) = v
                set.add(new Edge(dist(to), to))
              }
            }
          }
        }
        return (dist(end), path)
      }
    }
    val (dist, p) = Dijkstra.findShortestPath(0, n - 1)
    if (dist == Long.MaxValue) {
      out.println(-1)
    } else {
      val path = new util.ArrayList[Int]()
      var v = n - 1
      while (v != 0) {
        path.add(v + 1)
        v = p(v)
      }
      path.add(1)
      for (i <- path.size - 1 to 0 by -1) {
        out.print(path.get(i) + " ")
      }
    }
    return 1
  }

  class Edge(var len: Long, var to: Int) extends Comparable[Edge] {

    override def compareTo(o: Edge): Int = -java.lang.Long.compare(o.len, this.len)
  }

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }
}

import scala.io.Source
import scala.collection.mutable

object Main extends App {
  // process input!
  val input = Source.stdin.getLines.map(_.split(" ").map(_.toInt))
  type Node = Int
  type Weight = Int
  val graph = mutable.Map.empty[Node, mutable.Map[Node, Weight]]
  val (n :: numEdges :: Nil) = input.next.toList
  val edges = input.map(_.toList)

  // construct the graph!
  def makeEdge(from: Node, to: Node, weight: Weight) = {
      val source = graph.getOrElseUpdate(from, mutable.Map.empty[Node, Weight])
      source.get(to) match {
        case None => source.update(to, weight)
        case Some(prevWeight) if(weight < prevWeight) => source.update(to, weight)
        case _ => ()
      }
  }
  edges.foreach {
    case from :: to :: weight :: Nil => {
      makeEdge(from, to, weight)
      makeEdge(to, from, weight)
    }
    case _ => ()
  }

  // Prepare for Dijkstra! This represents a graph path!
  sealed abstract class Path {
    def cost: Int
  }
  case object Stop extends Path {
    override val toString = ""
    override val cost = 0
  }
  case class Go(val location: Node, val cost: Weight, val prev: Path) extends Path {
    override val toString = s"${prev.toString} $location".trim
  }

  // Sort by lowest cost!
  implicit val goOrdering: Ordering[Go] = Ordering.by(_.cost)

  // For example, we begin at node 1 with a cost of 0!
  val start = Go(1, 0, Stop)

  // Here are the Dijkstra Data Doodads of Doom!
  val conquered = mutable.Set.empty[Path]
  val frontier = mutable.SortedSet[Go](start)
  val enemy = mutable.Set((2 to n).toList:_*)

  // Here is the algorithm! Yay!
  var warPath: Option[Path] = None
  while(warPath.isEmpty && !frontier.isEmpty) {
    val battlefield = frontier.min
    frontier -= battlefield
    if(battlefield.location == n) {
      warPath = Some(battlefield)
    } else {
      conquered += battlefield
      for {
        connections <- graph.get(battlefield.location).toList
        (target, weight) <- connections
        totalCost = battlefield.cost + weight
        if enemy(target) || frontier.exists {
          case Go(targ, cost, _) => targ == target && cost > totalCost
        }
      } yield {
        frontier += Go(
          location = target,
          cost = totalCost,
          prev = battlefield)
        enemy -= target
      }
    }
  }

  // And our answer!!!!!!!!!!!
  warPath match {
    case None => println("-1")
    case Some(path) => println(path)
  }
}

import scala.io.Source
import scala.collection.mutable

object Main extends App {
  // process input!
  val input = Source.stdin.getLines.map(_.split(" ").map(_.toInt))
  type Node = Int
  type Weight = Int
  val graph = mutable.Map.empty[Node, mutable.Map[Node, Weight]]
  val (n :: numEdges :: Nil) = input.next.toList
  val edges = input.map(_.toList)

  // construct the graph!
  def makeEdge(from: Node, to: Node, weight: Weight) = {
      val source = graph.getOrElseUpdate(from, mutable.Map.empty[Node, Weight])
      source.get(to) match {
        case None => source.update(to, weight)
        case Some(prevWeight) => if(weight < prevWeight) source.update(to, weight)
      }
  }
  edges.foreach {
    case from :: to :: weight :: Nil => {
      makeEdge(from, to, weight)
      makeEdge(to, from, weight)
    }
    case _ => ()
  }

  // Prepare for Dijkstra! This represents a graph path!
  case class Path(val fullPath: List[Node], val cost: Weight) {
    def location = fullPath.head
    override def toString = fullPath.mkString(" ")
  }

  // Sort by lowest cost! and then target, so paths with same weight don't clobber each other!
  implicit val pathOrdering: Ordering[Path] = Ordering.by(path => (-path.cost, path.location))

  // For example, we begin at node 1 with a cost of 0!
  val end = Path(List(n), 0)

  // Here are the Dijkstra Data Doodads of Doom!
  val conquered = mutable.Set.empty[Node]
  val frontier = new java.util.PriorityQueue[Path](10, pathOrdering)
  frontier.offer(end)

  // Here is the algorithm! Yay! I AM NAPOLEON!!!!
  var warPath: Option[Path] = None
  while(warPath.isEmpty && !frontier.isEmpty) {
    val battlefield = frontier.poll
    val location = battlefield.location
    if(location == 1) {
      warPath = Some(battlefield)
    } else {
      conquered += location
      for {
        connections <- graph.get(location).toList
        (target, weight) <- connections
        if !conquered(target)
      } yield {
        frontier.add(Path(
          fullPath = target :: battlefield.fullPath,
          cost = battlefield.cost + weight))
      }
    }
  }

  // And our answer!!!!!!!!!!!
  warPath match {
    case None => println("-1")
    case Some(path) => println(path)
  }
}


object eCashback {

    import scala.collection.mutable
    import scala.io.StdIn.readLine

    class SortedSeq {
      private val storage: mutable.TreeMap[Int, Int] = new mutable.TreeMap[Int, Int]
      private var sum:BigInt = 0

      def add(elem: Int):Unit = {
        storage(elem) = storage.getOrElse(elem, 0) + 1
        sum+=elem
      }

      def remove(elem: Int): Unit = {
        storage.get(elem) match {
          case None => ()
          case Some(1) => storage-= elem
          case Some(x) => storage(elem) = x - 1
        }
        sum-=elem
      }

      def min:Int = storage.head._1

      def cost:BigInt = sum - min

      override def toString: String = storage.toString()
    }

    def cashback(n: Int, c: Int, arr: Array[Int]):BigInt = {

    val seq = new SortedSeq

    val dp: Array[BigInt] = (0 until n).map(_ => BigInt(0)).toArray
    for (i <- 0 until n) {
      seq.add(arr(i))
      if (i < c - 1) dp(i) = {if (i > 0) dp(i-1) else BigInt(0)} + arr(i)
      else if (i == c - 1) dp(i) = seq.cost
      else {
        seq.remove(arr(i - c))
        dp(i) = if (dp(i - 1) + arr(i) < dp(i - c) + seq.cost) dp(i - 1) + arr(i) else dp(i - c) + seq.cost
      }
    }
    dp(n - 1)
  }

  def main(args: Array[String]):Unit = {
    val n::c::Nil = readLine().split(" ").map(_.toInt).toList
    val arr = readLine.split(" ").map(_.toInt)
    println(cashback(n, c, arr))
  }
}

import java.util.StringTokenizer

import scala.collection.mutable

object E extends App {
  val INF = 1 << 30

  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt
  def long() = st.nextToken().toLong

  read()
  val n = int()
  val c = int()

  read()
  val a = Array.fill(n)(int())
  val b = new Array[Long](n)
  var globalMax = 0L

  val latest = mutable.SortedMap.empty[Int, Int]

  for (i <- 0 until n) {
    var previous = 0L
    val v = a(i)
    latest(v) = latest.getOrElse(v, 0) + 1
    if (i >= c) {
      val q = a(i-c)
      val qq = latest(q)
      if (qq == 1) latest.remove(q)
      else latest(q) = qq - 1
      previous = b(i-c)
    }
    if (i >= c-1) {
      globalMax = Math.max(globalMax, previous + latest.firstKey)
    }
    b(i) = globalMax
  }

  val sum = a.foldLeft(0L)(_ + _)
  println(sum - globalMax)

}

object eCashback {

    import scala.collection.mutable
    import scala.io.StdIn.readLine

    class SortedSeq {
      private val storage: mutable.TreeMap[Int, Int] = new mutable.TreeMap[Int, Int]
      private var sum:BigInt = 0

      def add(elem: Int):Unit = {
        storage(elem) = storage.getOrElse(elem, 0) + 1
        sum+=elem
      }

      def remove(elem: Int): Unit = {
        storage.get(elem) match {
          case None => ()
          case Some(1) => storage-= elem
          case Some(x) => storage(elem) = x - 1
        }
        sum-=elem
      }

      def min:Int = storage.head._1

      def cost:BigInt = sum - min

      override def toString: String = storage.toString()
    }

    def cashback(n: Int, c: Int, arr: Array[Int]):BigInt = {

    val seq = new SortedSeq

    val dp: Array[BigInt] = (0 until n).map(_ => BigInt(0)).toArray
    dp(0) = arr(0)
    seq.add(arr(0))
    for (i <- 1 until n) {
      seq.add(arr(i))
      if (i < c - 1) dp(i) = dp(i-1) + arr(i)
      else if (i == c - 1) {
        dp(i) = seq.cost
      }
      else {
        seq.remove(arr(i - c))
        dp(i) = if (dp(i - 1) + arr(i) < dp(i - c) + seq.cost) dp(i - 1) + arr(i) else dp(i - c) + seq.cost
      }
    }
    dp(n - 1)
  }

  def main(args: Array[String]):Unit = {
    val n::c::Nil = readLine().split(" ").map(_.toInt).toList
    val arr = readLine.split(" ").map(_.toInt)
    println(cashback(n, c, arr))
  }
}

object eCashback {

    import scala.collection.mutable
    import scala.io.StdIn.readLine

    class SortedSeq {
      private val storage: mutable.TreeMap[Int, Int] = new mutable.TreeMap[Int, Int]
      private var sum = 0

      def add(elem: Int):Unit = {
        storage(elem) = storage.getOrElse(elem, 0) + 1
        sum+=elem
      }

      def remove(elem: Int): Unit = {
        storage.get(elem) match {
          case None => ()
          case Some(1) => storage-= elem
          case Some(x) => storage(elem) = x - 1
        }
        sum-=elem
      }

      def min:Int = storage.head._1

      def cost:Int = sum - min

      override def toString: String = storage.toString()
    }

    def cashback(n: Int, c: Int, arr: Array[Int]):Int = {

    val seq = new SortedSeq

    val dp: Array[Int] = (0 until n).map(_ => 0).toArray
    dp(0) = arr(0)
    seq.add(arr(0))
    for (i <- 1 until n) {
      seq.add(arr(i))
      if (i < c - 1) dp(i) = dp(i-1) + arr(i)
      else if (i == c - 1) {
        dp(i) = seq.cost
      }
      else {
        seq.remove(arr(i - c))
        dp(i) = math.min(dp(i - 1) + arr(i), dp(i - c) + seq.cost)
      }
    }
    dp(n - 1)
  }

  def main(args: Array[String]):Unit = {
    val n::c::Nil = readLine().split(" ").map(_.toInt).toList
    val arr = readLine.split(" ").map(_.toInt)
    println(cashback(n, c, arr))
  }
}


object A43 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val goals = Array.fill(n)(read)
    val diff = goals.toSet.toArray
    val map = collection.mutable.Map[String, Int]().withDefaultValue(0)
    for(i <- diff) {
      map(i) = goals.count(_ == i)
    }
    println(map.toArray.maxBy(_._2)._1)
  }

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

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

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

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

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

}

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

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

  val N = sc.nextInt
  sc.nextLine
  val GOALS = List.fill(N)(sc.nextLine)

  def solve(): String = GOALS.groupBy(identity).toSeq.sortWith(_._2.size > _._2.size).head._1

  out.println(solve)
  out.close
}

import scala.io._
import scala.collection.mutable._
import java.io.FileWriter
import java.io.PrintWriter

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var n = readInt;
    var map = Map[String, Int]();
    for (i <- 0 until n) {
      var s = readLine;
      map.put(s, map.getOrElse(s, 0) + 1);
    }
    println(map.maxBy(_._2)._1);
  }
}

object Main {
  def main(args: Array[String]) = {
    var n = readInt()
    val map = scala.collection.mutable.Map[String, Int]()
    for(_ <- 1 to n) {
      val c = readLine()
      map(c) = map.getOrElse(c, 0) + 1
    }
    val e = map.toList.sortBy(_._2).reverse.apply(0)
    println(e._1)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println((1 to n).map(_ => in.next()).groupBy(x => x).maxBy(_._2.length)._1)
}


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

  val t = readInt()

  (0 until t).foreach { _ =>
    val s = readLine()

    val ans = s
      .foldLeft(List.empty[Char]) {
        case ('A' :: t, 'B') => t
        case ('B' :: t, 'B') => t
        case (ls, c)         => c :: ls
      }
      .length

    println(ans)
  }
}

import scala.collection.mutable

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

    for (_ <- 1 to nextInt) {
      val s = nextLine
      var prev = ' '
      val cntsBuilder = new mutable.ArrayBuilder.ofInt
      var cnt = 1
      for (c <- s) {
        if (c == prev) {
          cnt += 1
        } else if (prev == 'A') {
          cntsBuilder += -cnt
          cnt = 1
        } else if (prev == 'B') {
          cntsBuilder += cnt
          cnt = 1
        }
        prev = c
      }
      if (prev == 'A') {
        cntsBuilder += -cnt
      } else if (prev == 'B') {
        cntsBuilder += cnt
      }
      var cnts = cntsBuilder.result()

      var changed = true
      while (changed) {
//        println(cnts.mkString(" "))
        changed = false
        for (i <- 1 until cnts.length) {
          val a = cnts(i - 1)
          val b = cnts(i)
          if (a < 0 && b > 0) {
            val c = math.min(-a, b)
            cnts(i - 1) += c
            cnts(i) -= c
            changed = true
          }
        }
        cnts = cnts.filter(_ != 0)
      }

      changed = true
      while (changed) {
        changed = false
        for (i <- cnts.indices) {
          if (cnts(i) > 1) {
            cnts(i) %= 2
            changed = true
          }
        }
        cnts = cnts.filter(_ != 0)
        for (i <- 1 until cnts.length) {
          if (cnts(i - 1) == 1 && cnts(i) == 1) {
            cnts(i - 1) = 0
            cnts(i) = 0
          }
        }
        cnts = cnts.filter(_ != 0)
      }

      out.println(cnts.map(math.abs).sum)
    }

    out.flush()
  }

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


object Solution extends App {
  val in = io.Source.stdin.getLines()
  val n = in.next().toInt
  val line = in.next().split(' ').map(_.toInt).scanLeft(2) {
    case(a, b) => (a + b + 1) % 2
  }.tail.map(2 - _)
  println(line.toList.mkString("\n"))
}

object B705 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    var player = in(0)%2
    println(player+1)
    for(i <- 1 until n) {
      if(in(i)%2 == 0)
        player = 1 - player
      println(player+1)
    }
  }

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

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

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

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

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

}

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

object _705B extends CodeForcesApp {
  override def apply(io: IO) = {import io.{read, write}
    val cycles = read[Vector[Int]]

    var last: Int = 0
    cycles foreach {c =>
      val ans = (last, c%2) match {
        case (0, 0) => 1
        case (0, 1) => 2

        case (1, 0) => 2
        case (1, 1) => 1

        case (2, 0) => 1
        case (2, 1) => 2
      }
      io.writeOnNextLine(ans)
      last = ans
    }

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

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

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

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

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

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

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

  def write(obj: Any, more: Any*): this.type = {
    printer.print(obj)
    more foreach {i =>
      printer.print(' ')
      printer.print(i)
    }
    this
  }
  def writeOnNextLine(obj: Any, more: Any*): this.type = {
    printer.println()
    write(obj, more: _*)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)

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

object Cycles extends App {

  def iter(seq: List[Int], results: List[Int]): List[Int] = seq match {
    case Nil => results
    case x :: xs => iter(xs, (results.headOption.getOrElse(0) + x - 1) % 2 :: results)
  }

  val n: Int = readLine.toInt
  val a: List[Int] = readLine.split(' ').map(_.toInt).toList
  val results = iter(a, Nil)

  results.reverse.map {
    case 0 => 2
    case x => x.abs
  }.foreach(println)

}


object E1 extends App {

  def permutationMinimizationByDeque(an: List[Int]): List[Int] = {
    val (left, right) = an.foldLeft((List.empty[Int], List.empty[Int])) {
      case ((Nil, ys), a)                  => (a :: Nil, ys)
      case ((xs @ x :: _, ys), a) if a < x => (a :: xs, ys)
      case ((xs, ys), a)                   => (xs, a :: ys)
    }

    left ++ right.reverse
  }

  import InOut._

  val t = nextInt()

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

    val bn = permutationMinimizationByDeque(an)

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

  out.flush()

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

    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 = _

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

object E1 extends App {

  def permutationMinimizationByDeque(an: List[Int]): List[Int] = {
    require(an.length > 0, "The size of an permutation should be at least 1")

    val (left, right) = an.drop(1).foldLeft((List(an.head), List.empty[Int])) {
      case ((xs @ x :: _, ys), a) if a < x => (a :: xs, ys)
      case ((xs, ys), a)                   => (xs, a :: ys)
    }

    left ++ right.reverse
  }

  import InOut._

  val t = nextInt()

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

    val bn = permutationMinimizationByDeque(an)

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

  out.flush()

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

    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 = _

    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.collection.mutable._
import scala.util.Sorting.quickSort
import scala.math._

object sample 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 myType(left: Int, right: Int, index: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (left < that.left || (left == that.left && right < that.right))
                return -1
            else if (left == that.left && right == that.right)
                return 0
            else
                return 1
        }
    }

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        val left = new ArrayBuffer[Int]()
        val right = new ArrayBuffer[Int]()
        var tmp = 0
        for (i <- 1 to n) {
            tmp = readInt()
            if (left.isEmpty || tmp <= left(left.length-1))
                left.append(tmp)
            else
                right.append(tmp)
        }
        for (i <- left.indices.reverse)
            writer.print(left(i) + " ")
        for (i <- right.indices)
            writer.print(right(i) + " ")
        writer.println()
    }
    writer.flush()
}


import Array._
import scala.io.StdIn.readLine
object problem {
  def main(args: Array[String]) {
    var cnt = 1
    val Array(n, m) = readLine.split(" ").map(_.toInt)
    val a = readLine.split(" ").map(_.toInt)
    while(cnt < m) cnt += a(cnt - 1)
    if(cnt == m){
      println("YES")
    }else println("NO")
  }
}

import scala.io.StdIn

object NewYearTransport {
  // https://codeforces.com/problemset/problem/500/A
  def main(args: Array[String]): Unit = {
    val (n, t) = StdIn.readLine().split(" ") match {
      case Array(n, t) => (n.toInt, t.toInt)
    }

    val arrA = StdIn.readLine().split(" ").map(_.toInt)

    val res = if (canReach(1, arrA, t)) "YES" else "NO"
    println(res)
  }

  def canReach(i: Int, arr: Array[Int], t: Int): Boolean = {
    if (i == t) true
    else if (i > t) false
    else canReach(i + arr.head, arr.slice(arr.head, arr.length), t)
  }

}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
import scala.util.Sorting._
import scala.math._
import scala.collection._
import java.util._

object HelloWorld {
  def main(args: Array[String]): Unit = {
    val Array(n, t) = readLine.split(" ").map(_.toInt)
    val portals = readLine.split(" ").map(_.toInt)

    var current_index = 0
    var possible_to_escape = false
    while (current_index < t - 1 && !possible_to_escape) {
      if ((current_index + 1) + portals(current_index) == t){
        possible_to_escape = true
      }

      current_index += portals(current_index)
    }

    println(if(possible_to_escape) "YES" else "NO")
  }
}

import java.util.Scanner

object Main {
def main(args: Array[String]) {
val scanner = new Scanner(System.in)
val n = scanner.nextInt()
val t = scanner.nextInt()

var next = 0
for(i <- 0 to (n - 2)) {
val jump = scanner.nextInt()
if(i == next) {
next += jump
if(next == t - 1) {
println("YES")
return
}
}
}

println("NO")
}
}

object A500 {
  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)

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

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

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

  def main(args: Array[String]): Unit = {
    var Array(n, t) = readInts(2)
    val input = readInts(n-1)
    var curr = 1

    while(curr-1 < n-1 && curr != t) {
      curr = curr + input(curr-1)
    }
    if(curr == t) println("YES") else println("NO")
  }
}

import scala.collection._

object A extends App {

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

  val Array(n, t) = readInts(2)
  val as = Array(0) ++ readInts(n - 1)

  val q = mutable.Queue(1)
  var can = false

  while (!q.isEmpty) {
    val u = q.dequeue
    if (u == t) can = true
    if (u < n) q.enqueue(u + as(u))
  }

  println(if (can) "YES" else "NO")
}

import collection.mutable.SortedSet;

object NewYearTransportation {
	def main (args: Array[String]) {
		// Parsing the input
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
		val t = scanner.nextInt() - 1;
		var map = new Array[Int](n);
		for (i <- 0 to n - 2) {
			map(i) = scanner.nextInt();
		}
		map(n-1) = 0;
		// Computation
		var visited = SortedSet[Int]();
		var toVisit = SortedSet[Int](0);
		while (toVisit != SortedSet.empty && !(visited contains t)){
			val elt = toVisit.head;
			toVisit -= elt;
			visited += elt;
			val next = map(elt)+elt;
			if (! (visited contains next))
				toVisit += next
		}
		if (visited contains t)
			println("YES")
			else
				println("NO")
	}
}

object P500A {
	def readInts() : Array[Int] = {
		scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}

	def solve(t: Int, as: Iterable[Int]) : Unit = {
		if (t < 0)
			println("NO")
		else if (t == 0)
			println("YES")
		else
			solve(t - as.head, as.drop(as.head))
	}

	def main(args: Array[String]) {
		val Array(n, t) = readInts()
		val as = readInts().toList
		solve(t - 1, as)
	}
}

object P500A {
	@inline def parseInts(n: Int, line: String) : Array[Int] = {
		val tokenizer = new java.util.StringTokenizer(line)
		Array.fill(n)(tokenizer.nextToken.toInt)
	}

	def solve(t: Int, as: Iterable[Int]) : Unit = {
		if (t > 0)
			solve(t - as.head, as.drop(as.head))
		else if (t == 0)
			println("YES")
		else
			println("NO")
	}

	def main(args: Array[String]) {
		val Array(n, t) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		val as = parseInts(n - 1, scala.io.StdIn.readLine).toList
		solve(t - 1, as)
	}
}

import java.util.Scanner
import scala.io.StdIn
import Array._
import scala.io.StdIn.readLine
object problem {
  def main(args: Array[String]) {
  val cin = new Scanner(System.in)
    val n = cin.nextInt()
    val m = cin.nextInt()
  var cnt = 0
    for( i <- 0 to (n - 2)){
      val s = cin.nextInt()
      if(cnt == i){
      cnt += s
        if(cnt == m - 1){
          println("YES"); return
        }
      }
  }
    println("NO")
  }
}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object NewYearTransportation {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def reachable(current: Int, goal: Int, portal: IndexedSeq[Int]) : Boolean = {
     if (current == goal) true
     else if (current > goal) false else reachable(current + portal(current), goal, portal)
   }

   def main(args: Array[String]) {
     val nt = readInts
     val n = nt(0)
     val t = nt(1)  - 1
     val portals = readInts
     if (reachable(0,t,portals)) println("YES") else println("NO")
   }

}

import scala.collection.immutable.IndexedSeq

object Main extends App
{
  def dfs(g:Array[List[Int]], v: Int, used: Set[Int], need:Int): Set[Int] = {
    if(v>need)
      {
        println("NO")
        Set.empty[Int]
      } // печатаем или куда-то сохраняем
    else if(v == need)
      {
        println("YES")
        Set.empty[Int]
      } else
    (for(u <- g(v)) yield u).foldLeft(used){
      (usd, h) =>
        if (!usd.contains(h))
          usd ++ dfs(g, h, usd + h, need) + h
        else usd
    }
  }

def next_dfs(g:Array[List[Int]], v: Int, need:Int):Unit={
    if(v>need)
    {
      println("NO")
      Set.empty[Int]
    } // печатаем или куда-то сохраняем
    else if(v == need)
    {
      println("YES")
      Set.empty[Int]
    } else next_dfs(g, g(v)(0), need)
  }

  override def main(args: Array[String])
  {
    //dfs(input(), 0, Set(0), 4)
    //println(unique_substring(scala.io.StdIn.readLine()).toString())
    val t=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    //println(a.mkString(","))
    var i=0; // переменная по масиву а
    var con =0;
    var g = new Array[List[Int]](t(0))
    for(v <- 0 to g.length-2)// заполнение графа
    {
        g(v)=List(a(i)+v)
        con=a(i)-1
        i=i+1
    }
    //println(g.mkString(","))
    next_dfs(g, 0, t(1)-1)
  }
}

import scala.io.StdIn._

object Main2 extends App {
  val Array(cellNumber, destination) = readLine().split(" ").map(_.toInt)
  val portals = readLine().split(" ").map(_.toInt)
  val answers = Array.fill(cellNumber + 3)(false)
  answers(0) = true
  for ( i <- 0 until cellNumber-1) {
    if (answers(i)) answers(i + portals(i)) = true
  }
  println(if (answers(destination - 1)) "YES" else "NO")
}

import java.util.Scanner;

object Main extends App {
  var input = new Scanner(System.in)

  var N = input.nextInt()
  var T = input.nextInt()

  var X = new Array[Int](N + 1)

  for (i <- 1 to (N - 1)) {
    X(i) = input.nextInt()
  }

  var pos = 1
  var reach = false

  while (pos <= T) {
    if (pos == T) {
      reach = true
      pos = N + 1;
    } else {
      pos = pos + X(pos)
    }
  }

  if (reach) {
    println("YES")
  } else {
    println("NO")
  }
}

object Solution extends App {
  val Array(n, t) = readLine.split(" ").map(_.toInt)
  val as = readLine.split(" ").map(_.toInt)

  //as.zipWithIndex.map(_._1 + _._2)

  def can(i:Int):Boolean = {
    if(i==t-1)
      true
    else if(i>t-1)
      false
    else
      can(as(i) + i)
  }

  if(can(0))
    println("YES")
  else
    println("NO")
}

object ProblemA extends App {
    case class Node(
        offset: Int
    )

    def BFS(nodes: Array[Node], startIndex: Int, dstIndex: Int): Boolean = {
        if (startIndex == dstIndex) {
            true
        } else if (nodes(startIndex).offset == -1) {
            false
        } else {
            BFS(nodes, startIndex + nodes(startIndex).offset, dstIndex)
        }
    }

    val line1: String = scala.io.StdIn.readLine
    val line2: String = scala.io.StdIn.readLine

    val total :: dstIndex :: _  = line1.split(" ").map(_.toInt).toList
    val nodes = line2.split(" ").map { x =>
        Node(offset = x.toInt)
    }

    val msg: String = BFS(nodes ++ Array(Node(-1)), 0, dstIndex - 1) match {
        case true => "YES"
        case false => "NO"
    }
    println(msg)
}

object NewYearTransportation {
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var line=in.readLine()
    val n=line.split(" ")(0).toInt
    val t=line.split(" ")(1).toInt
    line=in.readLine()
    val a:Array[Int]=line.split(" ").map(_.toInt)
    var flag = false
    var i = 1
    while (i <= n - 1 && !flag){
      if(i==t){
        flag=true
      }
      i=i+a(i-1)
    }
    if(i==t){
      flag=true
    }
    println(if(flag) "YES" else "NO")
  }
}

import scala.io.StdIn

object Task500A {
	def main(args: Array[String]) {
		val t = StdIn.readLine().split(" ").map(_.toInt).apply(1)
		val numbers = StdIn.readLine().split(" ").map(_.toInt)
		var position = 1
		while (position < t) position += numbers(position - 1)
		if (position == t) println("YES") else println("NO")
	}
}

import scala.collection.immutable.IndexedSeq

object Main extends App
{
   def input() = {
    val n=scala.io.StdIn.readInt
    for(i <- 1 to n) yield {
          scala.io.StdIn.readLine.split(" ").map(_.toInt)
        }
  }

  def dfs(g:Array[List[Int]], v: Int, used: Set[Int], need:Int): Set[Int] = {
    if(v>need)
      {
        println("NO")
        Set.empty[Int]
      } // печатаем или куда-то сохраняем
    else if(v == need)
      {
        println("YES")
        Set.empty[Int]
      } else
    (for(u <- g(v)) yield u).foldLeft(used){
      (usd, h) =>
        if (!usd.contains(h))
          usd ++ dfs(g, h, usd + h, need) + h
        else usd
    }
  }

  def unique_substring(str:String): List[String] =
  {
    var ret=List.empty[String]
    for(i <- 1 to str.length-1)
      for(j <- 0 to str.length-i)
      {
        val substr=str.substring(j, j+i)
        if (str.indexOf(substr) == j && str.indexOf(substr, j+1) == -1)
          ret=ret.+:(substr)
      }
    ret
  }

  override def main(args: Array[String])
  {
    //dfs(input(), 0, Set(0), 4)
    //println(unique_substring(scala.io.StdIn.readLine()).toString())
    val t=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    //println(a.mkString(","))
    var i=0; // переменная по масиву а
    var con =0;
    var g = new Array[List[Int]](t(0))
    for(v <- 0 to g.length-1)// заполнение графа
    {
      if(con == 0)
      {
        g(v)=List(a(i)+v)
       //  g(v).+:(a(i)+v)
        con=a(i)-1
        i=i+1
      }
      else con=con-1
    }
    dfs(g, 0, Set(0), t(1))
  }
}

 import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val scanner = new Scanner(System.in)
    val n = scanner.nextInt()
    val t = scanner.nextInt()

    var next = 0
    for(i <- 1 to (n - 2)) {
      val jump = scanner.nextInt()
      if(i == next) {
        next += jump
        if(next == t - 1) {
          println("YES")
          return
        }
      }
    }

    println("NO")
  }
}

 import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val scanner = new Scanner(System.in)
    val n = scanner.nextInt()
    val t = scanner.nextInt()

    var next = 0
    for(i <- 0 to (n - 5)) {
      val jump = scanner.nextInt()
      if(i == next) {
        next += jump
        if(next == t - 1) {
          println("YES")
          return
        }
      }
    }

    println("NO")
  }
}

object P500A {
	def readInts() : Array[Int] = {
		scala.io.StdIn.readLine.split(" ").map(_.toInt)
	}

	def solve(t: Int, as: Iterable[Int]) : Unit = {
		if (t < 0)
			println("NO")
		else if (t == 0)
			println("YES")
		else
			solve(t - as.head, as.drop(as.head))
	}

	def main(args: Array[String]) {
		val Array(a, t) = readInts()
		val as = readInts()
		solve(t, as)
	}
}

import scala.collection.immutable.IndexedSeq

object Main extends App
{
   def dfs(g:Array[List[Int]], v: Int, used: Set[Int], need:Int): Set[Int] = {
    if(v>need)
      {
        println("NO")
        Set.empty[Int]
      } // печатаем или куда-то сохраняем
    else if(v == need)
      {
        println("YES")
        Set.empty[Int]
      } else
    (for(u <- g(v)) yield u).foldLeft(used){
      (usd, h) =>
        if (!usd.contains(h))
          usd ++ dfs(g, h, usd + h, need) + h
        else usd
    }
  }

  override def main(args: Array[String])
  {
    //dfs(input(), 0, Set(0), 4)
    //println(unique_substring(scala.io.StdIn.readLine()).toString())
    val t=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val a=scala.io.StdIn.readLine.split(" ").map(_.toInt)
    //println(a.mkString(","))
    var i=0; // переменная по масиву а
    var con =0;
    var g = new Array[List[Int]](t(0))
    for(v <- 0 to g.length-1)// заполнение графа
    {
      if(con == 0)
      {
        if(v < t(0)-1)
          g(v)=List(a(i)+v)
        con=a(i)-1
        i=i+1
      }
      else con=con-1
    }
    dfs(g, 0, Set(0), t(1))
  }
}

import java.io._;
import java.util._;

object Main extends App {
  var input = new Scanner(System.in)

  var N = input.nextInt()
  var T = input.nextInt()

  var X = new Array[Int](N)

  for (i <- 1 to (N - 1)) {
    X(i) = input.nextInt()
  }

  var pos = 1
  var reach = false

  while (pos < N - 1) {
    if (pos == T) {
      reach = true
    }
    pos = pos + X(pos)
  }

  if (reach) {
    println("YES")
  } else {
    println("NO")
  }
}

import java.io._;
import java.util._;

object Main extends App {
  var input = new Scanner(System.in)

  var N = input.nextInt()
  var T = input.nextInt()

  var X = new Array[Int](N - 1)

  for (i <- 0 to (N - 2)) {
    X(i) = input.nextInt()
  }

  var pos = 0
  var reach = false

  while (pos < N - 1) {
    if (pos == T - 1) {
      reach = true
    }
    pos = pos + X(pos)
  }

  if (reach) {
    println("YES")
  } else {
    println("NO")
  }
}