This is the easy version of this problem. The only difference is the constraint on $$$k$$$ — the number of gifts in the offer. In this version: $$$k=2$$$.Vasya came to the store to buy goods for his friends for the New Year. It turned out that he was very lucky — today the offer "$$$k$$$ of goods for the price of one" is held in store. Remember, that in this problem $$$k=2$$$.Using this offer, Vasya can buy exactly $$$k$$$ of any goods, paying only for the most expensive of them. Vasya decided to take this opportunity and buy as many goods as possible for his friends with the money he has.More formally, for each good, its price is determined by $$$a_i$$$ — the number of coins it costs. Initially, Vasya has $$$p$$$ coins. He wants to buy the maximum number of goods. Vasya can perform one of the following operations as many times as necessary:  Vasya can buy one good with the index $$$i$$$ if he currently has enough coins (i.e $$$p \ge a_i$$$). After buying this good, the number of Vasya's coins will decrease by $$$a_i$$$, (i.e it becomes $$$p := p - a_i$$$).  Vasya can buy a good with the index $$$i$$$, and also choose exactly $$$k-1$$$ goods, the price of which does not exceed $$$a_i$$$, if he currently has enough coins (i.e $$$p \ge a_i$$$). Thus, he buys all these $$$k$$$ goods, and his number of coins decreases by $$$a_i$$$ (i.e it becomes $$$p := p - a_i$$$). Please note that each good can be bought no more than once.For example, if the store now has $$$n=5$$$ goods worth $$$a_1=2, a_2=4, a_3=3, a_4=5, a_5=7$$$, respectively, $$$k=2$$$, and Vasya has $$$6$$$ coins, then he can buy $$$3$$$ goods. A good with the index $$$1$$$ will be bought by Vasya without using the offer and he will pay $$$2$$$ coins. Goods with the indices $$$2$$$ and $$$3$$$ Vasya will buy using the offer and he will pay $$$4$$$ coins. It can be proved that Vasya can not buy more goods with six coins.Help Vasya to find out the maximum number of goods he can buy.

The first line contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases in the test. The next lines contain a description of $$$t$$$ test cases.  The first line of each test case contains three integers $$$n, p, k$$$ ($$$2 \le n \le 2 \cdot 10^5$$$, $$$1 \le p \le 2\cdot10^9$$$, $$$k=2$$$) — the number of goods in the store, the number of coins Vasya has and the number of goods that can be bought by the price of the most expensive of them. The second line of each test case contains $$$n$$$ integers $$$a_i$$$ ($$$1 \le a_i \le 10^4$$$) — the prices of goods. It is guaranteed that the sum of $$$n$$$ for all test cases does not exceed $$$2 \cdot 10^5$$$. It is guaranteed that in this version of the problem $$$k=2$$$ for all test cases.

For each test case in a separate line print one integer $$$m$$$ — the maximum number of goods that Vasya can buy.

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("MY_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 upperBound(a: Array[Long], x: Long): Int = {
    def step(l: Int, h: Int): Int = {
      if (h - l == 1) h
      else {
        val mid = (l + h) / 2
        if (a(mid) > x) step(l, mid)
        else step(mid, h)
      }
    }

    step(-1, a.length)
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  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 = {
    REP(ni()) { _ =>
      val N, P, K = ni()
      val A = na(N)
      sort(A)
      val S = Array.ofDim[Long](N + 1)
      REP(N) { i =>
        if (i + 1 >= K) {
          S(i + 1) = S(i + 1 - K) + A(i)
        }
      }
      debug(S)
      val cum = Array.ofDim[Long](K - 1)
      cum(0) = A(0)
      REP(K - 2, 1) { i =>
        cum(i) = cum(i - 1) + A(i)
      }
      debug(cum)

      var ans = 0
      REP(N) { i =>
         if (S(i + 1) <= P) {
           val remain = P - S(i + 1)
           val c1 = (i + 1) / K * K
           val c2 = upperBound(cum, remain)
           val c = c1 + min(c2, i + 1 - c1)
           ans = max(ans, c)
         }
      }
      out.println(ans)
    }
  }
}


There are some beautiful girls in Arpa’s land as mentioned before.Once Arpa came up with an obvious problem:Given an array and a number x, count the number of pairs of indices i, j (1 ≤ i < j ≤ n) such that , where  is bitwise xor operation (see notes for explanation).  Immediately, Mehrdad discovered a terrible solution that nobody trusted. Now Arpa needs your help to implement the solution to that problem.

First line contains two integers n and x (1 ≤ n ≤ 105, 0 ≤ x ≤ 105) — the number of elements in the array and the integer x. Second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 105) — the elements of the array.

Print a single integer: the answer to the problem.

NoteIn the first sample there is only one pair of i = 1 and j = 2.  so the answer is 1.In the second sample the only two pairs are i = 3, j = 4 (since ) and i = 1, j = 5 (since ).A bitwise xor takes two bit integers of equal length and performs the logical xor operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. You can read more about bitwise xor operation here: https://en.wikipedia.org/wiki/Bitwise_operation#XOR.

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).groupBy(identity).mapValues(_.length.toLong).toArray.sortBy(_._1)
//    println(nums.mkString(" "))
    var ex = 0.toLong
    val ns = nums.map(_._1)
//    println(ns.mkString(" "))
    val vs = nums.map(_._2)
    if (x > 0) {
      nums.foreach(y => ns.search(x ^ y._1) match {
        case Found(cc) =>
        {
          ex += vs(cc) * y._2
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object Main{
  def main(args:Array[String])={
    val sc = new java.util.Scanner(System.in)
    val n, x = sc.nextInt
    val a = Array.fill(1000001)(0)
    var ans:BigInt = 0
    for(i <- 1 to n)
    {
      var xx = sc.nextInt
      ans += a(xx^x)
      a(xx) += 1
    }
    println(ans)
  }
}

object B742 {

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

  def main(args: Array[String]): Unit = {
    val Array(n, x) = readInts(2)
    val in = readInts(n)
    val map = cu.Map.empty[Int, Int].withDefaultValue(0)
    var res = 0L
    for(a <- in) {
      val c = x ^ a
      if(map(c) > 0)
        res += map(c)
      map(a) += 1
    }
    println(res)
  }

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

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).groupBy(identity).mapValues(_.length).toArray.sortBy(_._1)
//    println(nums.mkString(" "))
    var ex = 0.toLong
    val ns = nums.map(_._1)
//    println(ns.mkString(" "))
    val vs = nums.map(_._2)
    if (x > 0) {
      nums.foreach(y => ns.search(x ^ y._1) match {
        case Found(cc) =>
        {
          ex += vs(cc) * y._2
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).groupBy(identity).mapValues(_.length).toArray.sortBy(_._1)
//    println(nums.mkString(" "))
    var ex = 0
    val ns = nums.map(_._1)
//    println(ns.mkString(" "))
    val vs = nums.map(_._2)
    if (x > 0) {
      nums.foreach(y => ns.search(x ^ y._1) match {
        case Found(cc) =>
        {
          ex += vs(cc) * y._2
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted.groupBy(identity).mapValues(_.size)
//    println(nums.mkString(" "))
    var ex = 0
    val ns = nums.keys.toArray
    val vs = nums.values.toArray
    if (x > 0) {
      ns.zipWithIndex.foreach(y => ns.search(x ^ y._1) match {
        case Found(cc) =>
        {
          ex += vs(cc)
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted.groupBy(identity).mapValues(_.length)
    println(nums.mkString(" "))
    var ex = 0
    val ns = nums.keys.toArray
    println(ns.mkString(" "))
    val vs = nums.values.toArray
    if (x > 0) {
      ns.foreach(y => ns.search(x ^ y) match {
        case Found(cc) =>
        {
          ex += vs(cc)
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted
    var ex = 0
    if (x > 0) {
      nums.foreach(y => nums.search(x ^ y) match {
        case Found(cc) =>
        {
          ex += 1
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = nums.groupBy(identity).mapValues(nn => nn.size * (nn.size - 1) / 2).values.sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).groupBy(identity).mapValues(_.length).toArray.sortBy(_._1)
//    println(nums.mkString(" "))
    var ex = 0
    val ns = nums.map(_._1)
//    println(ns.mkString(" "))
    val vs = nums.map(_._2)
    if (x > 0) {
      ns.foreach(y => ns.search(x ^ y) match {
        case Found(cc) =>
        {
          ex += vs(cc)
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).groupBy(identity).mapValues(_.length).toArray.sortBy(_._1)
    println(nums.mkString(" "))
    var ex = 0
    val ns = nums.map(_._1)
    println(ns.mkString(" "))
    val vs = nums.map(_._2)
    if (x > 0) {
      ns.foreach(y => ns.search(x ^ y) match {
        case Found(cc) =>
        {
          ex += vs(cc)
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted.groupBy(identity).mapValues(_.length)
//    println(nums.mkString(" "))
    var ex = 0
    val ns = nums.keys.toArray
//    println(ns.mkString(" "))
    val vs = nums.values.toArray
    if (x > 0) {
      ns.foreach(y => ns.search(x ^ y) match {
        case Found(cc) =>
        {
          ex += vs(cc)
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex = (ex + 1) / 2
    } else {
      ex = vs.map(nn => nn * (nn - 1) / 2).sum
    }
    println(ex)
  }
}

object B {
  import scala.collection.Searching._

  def main(args: Array[String]): Unit = {
    val Array(n, x) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val nums = scala.io.StdIn.readLine.split(" ").map(_.toInt).sorted
    var ex = 0
    if (x > 0) {
      nums.foreach(y => nums.search(x ^ y) match {
        case Found(cc) =>
        {
          ex += 1
//          println(Array(x, y, nums(cc)).mkString(" "))
        }
        case InsertionPoint(cc) =>
        {
//          println(Array(-1, x, y, cc).mkString(" "))
          0
        }
      })
      ex /= 2
    } else {
      ex = nums.groupBy(identity).mapValues(nn => nn.size * (nn.size - 1) / 2).values.sum
    }
    println(ex)
  }
}

object Main{
  def main(args:Array[String])={
    val sc = new java.util.Scanner(System.in)
    val n, x = sc.nextInt
    val a = Array.fill(1000001)(0)
    var ans = 0
    for(i <- 1 to n)
    {
      var xx = sc.nextInt
      ans += a(xx^x)
      a(xx) += 1
    }
    println(ans)
  }
}

object B742 {

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

  def main(args: Array[String]): Unit = {
    val Array(n, x) = readInts(2)
    val in = readInts(n)
    val set = cu.Set.empty[Int]
    var res = 0L
    for(a <- in) {
      val c = x ^ a
      if(set.contains(c))
        res += 1
      set.add(a)
    }
    println(res)
  }

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

    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}


The new "Die Hard" movie has just been released! There are n people at the cinema box office standing in a huge line. Each of them has a single 100, 50 or 25 ruble bill. A "Die Hard" ticket costs 25 rubles. Can the booking clerk sell a ticket to each person and give the change if he initially has no money and sells the tickets strictly in the order people follow in the line?

The first line contains integer n (1 ≤ n ≤ 105) — the number of people in the line. The next line contains n integers, each of them equals 25, 50 or 100 — the values of the bills the people have. The numbers are given in the order from the beginning of the line (at the box office) to the end of the line.

Print "YES" (without the quotes) if the booking clerk can sell a ticket to each person and give the change. Otherwise print "NO".

object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    var b25 = 0
    var b50 = 0
    var b100 = 0
    for (i <- 0 until n) {
      val b = sc.nextInt
      if (b == 25)
        b25 += 1
      else if (b == 50) {
        b50 += 1
        b25 -= 1
      }
      else if (b == 100) {
        b100 += 1
        b50 -= 1
        b25 -= 1
      }
      while (b50 < 0) {
        b25 -= 2
        b50 += 1
      }
      if (b25 < 0) {
        println("NO")
        return
      }
    }
    println("YES")
  }
}

import java.util.StringTokenizer

object _349A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt)
  def f(a: List[Int], cb: Int, wb: Int): Boolean =
    if (cb < 0 || wb < 0) false
    else if (a == Nil) true
    else if (a.head == 25) f(a.tail, cb + 1, wb)
    else if (a.head == 50) f(a.tail, cb - 1, wb + 1)
    else {
      if (wb > 0) f(a.tail, cb - 1, wb - 1)
      else f(a.tail, cb - 3, wb)
    }

  if (f(a.toList, 0, 0)) println("YES")
  else println("NO")
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  in.next()
  val data = in.next().split(" ").map(_.toInt).foldLeft((0, 0, true)) {
    case((s, m, false), el) => (s, m, false)
    case((s, m, true), 25) => (s + 1, m, true)
    case((s, m, true), 50) => (s - 1, m + 1, s >= 1)
    case((s, m, true), 100) if m >= 1 => (s - 1, m - 1, s >= 1)
    case((s, m, true), 100) => (s - 3, m, s >= 3)
  }
  if (data._3)
    println("YES")
  else
    println("NO")
}

object A349 {
  @inline def read = scala.io.StdIn.readLine

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = readInts(n)

    var curr25 = 0
    var curr50 = 0
    var break = false

    for(i <- 0 until n if !break) {
      if(input(i) == 25) {
        curr25 += 1
      } else if(input(i) == 50) {
        if(curr25 >= 1) {
          curr25 -= 1
          curr50 += 1
        } else {
          println("NO")
          break = true
        }
      } else {
        if(curr50 >= 1 && curr25 >= 1) {
          curr50 -= 1
          curr25 -= 1
        } else if(curr25 >= 3) {
          curr25 -= 3
        } else {
          println("NO")
          break = true
        }
      }
    }
    if(!break) {
      println("YES")
    }
  }
}

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

object P349A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val P = List.fill(N)(sc.nextInt)

  def solve(): String = {

    @tailrec
    def loop(r50: Int, r25: Int, line: List[Int]): String =
      line match {
        case Nil       => "YES"
        case 25 :: xs  => loop(r50, r25 + 1, xs)
        case 50 :: xs  => if (r25 < 1) "NO"
                          else loop(r50 + 1, r25 - 1, xs)
        case 100 :: xs => if (r50 < 1) {
          if (r25 < 3) "NO"
          else loop(r50, r25 - 3, xs)
        }
        else {
          if (r25 < 1) "NO"
          else loop(r50 - 1, r25 - 1, xs)
        }
      }

    loop(0, 0, P)
  }

  out.println(solve)
  out.close
}

import java.util.Scanner

object Codeforces extends App {
  val in = new Scanner(System.in)
  var a = 0
  var b = 0
  var res = "YES"
  val n = in.nextInt()
  for (i <- 0 until n) {
    val k = in.nextInt()
    if (k == 25) {
      a += 1
    }
    if (k == 50) {
      a -= 1
      b += 1
    }
    if (k == 100) {
      if (b != 0) {
        a -= 1
        b -= 1
      } else {
        a -= 3
      }
    }
    if (a < 0 || b < 0) {
      res = "NO"
    }
  }
  println(res)
}

object Main {
  class Cash {
    private var n25, n50 = 0

    def add(n: Int) = n match {
      case 25 => n25 += 1; true
      case 50 =>
        n50 += 1
        n25 -= 1
        n25 != -1
      case 100 =>
        if (n50 == 0) {
          n25 -= 3
          n25 >= 0
        } else {
          n50 -= 1
          n25 -=  1
          n25 != -1
        }
    }
  }

  def main(args: Array[String]) {
    val c = new Cash
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val r = a.foldLeft(true){ (r, n) => r & c.add(n) }
    if (r) println("YES")
    else println("NO")
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else if(m("25") > 2){m("25") -= 3} else yesOrNo = "NO"}
         case _ =>    {yesOrNo = "NO"}
      }
    }
    println(yesOrNo)
  }
}

import scala.io.StdIn

/**
 * @author unit7
 */
object Main {
  def main(args: Array[String]) {
    val n = StdIn.readInt()
    val denominations = StdIn.readLine().split("\\s").map(_.toInt)

    var can = true

    val cashBox = scala.collection.mutable.HashMap[Int, Int](25 -> 0, 50 -> 0)

    for (i <- 0 until n) {
      val denomination = denominations(i)

      if (denomination == 25) {
        cashBox.update(25, cashBox(25) + 1)
      } else if (denomination == 50) {
        val curTwentyFive = cashBox(25)

        if (curTwentyFive > 0) {
          cashBox.update(25, curTwentyFive - 1)
          cashBox.update(50, cashBox(50) + 1)
        } else {
          can = false
        }
      } else {
        var need = 3
        val curFifty = cashBox(50)

        if (curFifty > 0) {
          need -= 2
          cashBox.update(50, curFifty - 1)
        }

        val curTwentyFive = cashBox(25)

        if (curTwentyFive >= need) {
          cashBox.update(25, curTwentyFive - need)
        } else {
          can = false
        }
      }
    }

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

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  in.next()
  val data = in.next().split(" ").map(_.toInt).foldLeft((0, 0, true)) {
    case((s, m, false), el) => (s, m, false)
    case((s, m, true), 25) => (s + 1, m, true)
    case((s, m, true), 50) => (s - 1, m + 1, s >= 1)
    case((s, m, true), 100) if m > 1 => (s - 1, m - 1, s >= 1)
    case((s, m, true), 100) => (s - 3, m, s >= 3)
  }
  if (data._3)
    println("YES")
  else
    println("NO")
}

object A349 {
  @inline def read = scala.io.StdIn.readLine

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = readInts(n)

    var curr = 0
    var break = false
    for(i <- 0 until n if !break) {
      if(input(i) == 25) {
        curr += 1
      } else if(input(i) == 50) {
        if(curr >= 1) {
          curr -= 1
        } else {
          println("NO")
          break = true
        }
      } else {
        if(curr >= 2) {
          curr -= 2
        } else {
          println("NO")
          break = true
        }
      }
    }
    if(!break) {
      println("YES")
    }
  }
}

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

object P349A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val P = List.fill(N)(sc.nextInt)

  def solve(): String = {

    @tailrec
    def loop(r50: Int, r25: Int, line: List[Int]): String =
      line match {
        case Nil     => "YES"
        case 25 :: xs => loop(r50, r25 + 1, xs)
        case 50 :: xs => if (r25 < 1) "NO"
                         else loop(r50 + 1, r25 - 1, xs)
        case 100 :: xs => if (r50 > 0) loop(r50 - 1, r25, 50 :: xs)
                          else if (r25 < 3) "NO"
                          else loop(r50, r25 -3, xs)
      }

    loop(0, 0, P)
  }

  out.println(solve)
  out.close
}

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

object P349A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val P = List.fill(N)(sc.nextInt)

  def solve(): String = {

    @tailrec
    def loop(r50: Int, r25: Int, line: List[Int]): String =
      line match {
        case Nil     => "YES"
        case 25 :: xs => loop(r50, r25 + 1, xs)
        case 50 :: xs => if (r25 < 1) "NO"
                         else loop(r50 + 1, r25 - 1, xs)
        case 100 :: xs => if (r50 > 0) loop(r50 - 1, r25, 50 :: xs)
                          else if (r25 < 3) "NO"
                          else loop(r50, r25 - 3, xs)
      }

    loop(0, 0, P)
  }

  out.println(solve)
  out.close
}

import java.util.Scanner

object Codeforces extends App {
  val in = new Scanner(System.in)
  var a = 0
  var b = 0
  var res = "YES"
  val n = in.nextInt()
  for (i <- 1 until n) {
    var k = in.nextInt()
    if (k == 25) {
      a += 1
    }
    if (k == 50) {
      a -= 1
      b += 1
    }
    if (k == 100) {
      if (b != 0) {
        a -= 1
        b -= 1
      } else {
        a -= 3
      }
    }
    if (a < 0 || b < 0) {
      res = "NO"
    }
  }
  println(res)
}

object Main {
  class Cash {
    private var n25, n50 = 0

    def add(n: Int) = n match {
      case 25 => n25 += 1; true
      case 50 =>
        n50 += 1
        n25 -= 1
        n25 != -1
      case 100 =>
        if (n50 == 0) {
          n25 -= 3
          n25 >= 0
        } else {
          n50 -= 1
          n25 -=  1
          n25 != 1
        }
    }
  }

  def main(args: Array[String]) {
    val c = new Cash
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val r = a.foldLeft(true){ (r, n) => r & c.add(n) }
    if (r) println("YES")
    else println("NO")
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else if(m("25") > 1){m("25") -= 2} else yesOrNo = "NO"}
         case _ =>    {}
      }
    }
    println(yesOrNo)
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else if(m("25") > 1){m("25") -= 2} else yesOrNo = "NO"}
         case _ =>    {yesOrNo = "NO"}
      }
    }
    println(yesOrNo)
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else if(m("25") > 1){m("25") -= 2} else yesOrNo = "NO"}
         case _ =>    {}
      }
    }
    println(m("25")  + " " + m("50") + " " + m("100"))
    println(yesOrNo)
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else if(m("25") > 2){m("25") -= 1} else yesOrNo = "NO"}
         case _ =>    {}
      }
    }
    println(yesOrNo)
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else if(m("25") > 2){m("25") -= 2} else yesOrNo = "NO"}
         case _ =>    {}
      }
    }
    println(yesOrNo)
  }
}

import scala.math._
import scala.Console
object Object {

  def main(args : Array[String]){

    var n = readInt
    var ar = readLine split " "
    var m = scala.collection.mutable.Map("25" -> 0, "50" -> 0, "100" -> 0)
    var yesOrNo = "YES"

    for(i <- 0 until n){
      ar(i) match {
         case "25" => {m("25") += 1}
         case "50" => {m("50") += 1;if(m("25") > 0)m("25") -= 1 else yesOrNo = "NO"}
         case "100"=> {if(m("25") > 0 && m("50") > 0){m("25") -= 1; m("50") -= 1}  else yesOrNo = "NO"}
         case _ =>    {}
      }
    }
    println(yesOrNo)
  }
}


George has recently entered the BSUCP (Berland State University for Cool Programmers). George has a friend Alex who has also entered the university. Now they are moving into a dormitory. George and Alex want to live in the same room. The dormitory has n rooms in total. At the moment the i-th room has pi people living in it and the room can accommodate qi people in total (pi ≤ qi). Your task is to count how many rooms has free place for both George and Alex.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of rooms. The i-th of the next n lines contains two integers pi and qi (0 ≤ pi ≤ qi ≤ 100) — the number of people who already live in the i-th room and the room's capacity.

Print a single integer — the number of rooms where George and Alex can move in.

import scala.io.StdIn._

object Accommodation {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val nums =
      for {
        _ <- 0 until n
        a :: b :: _ = readLine().split(" ").map(_.toInt).toList
      } yield (a, b)
    val space = nums.map { case (a, b) => b - a }
    val ans = space.count(_ >= 2)
    println(ans)
  }
}

object CF0467A extends App {

  var n = readInt()
  var result = 0
  (1 to n ).foreach(n => {
    val Array(p, q) = readLine().split(" ").map(_.toInt)
    if (q >= (p + 2)) {
      result += 1
    }
  })

  println(result)

}

object GandAcc {
    def main(args: Array[String]) {
        // println("Hello, world!")
        val n = readLine().toInt
        var ctr = 0
        for (i <- 1 to n){
            var Array(p,q) = readLine().split(" ").map(_.toLong)
            if (q - p >= 2)
                ctr+=1;
        }
        printf("%d\n", ctr)
        ctr = 0
    }
}

import scala.io.StdIn

object Task467A {
	def main(args: Array[String]): Unit ={
		var r = 0
		for (_ <- 0 until StdIn.readInt()) {
			val in = StdIn.readf2("{0} {1}")
			if (in._1.asInstanceOf[String].toInt + 1 < in._2.asInstanceOf[String].toInt)
				r += 1
		}
		println(r)
	}
}

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

/**
 * Created by arseny on 18.09.14.
 */
object A 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 n = nextInt
    var ans = 0
    for(i <- 0 until n) {
      val p = nextInt
      val q = nextInt
      if(q - p >= 2) {
        ans += 1
      }
    }
    out.print(ans)
  }

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

object Main {

  def main(args: Array[String]) {
    val std = scala.io.StdIn

    val n = std.readLine().toInt
    var result = 0
    for (_ <- 0 until n) {
      val str = std.readLine().split(" ").map(_.toInt)
      val p = str(0)
      val q = str(1)
      result += (if (q - p >= 2) 1 else 0)
    }
    print(result)
  }
}

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

object HelloWorld {
  def main(args: Array[String]) {

    val n = readLine.toInt

    var counter = 0
    for (i <- 0 until n) {
      val line = readLine.split(" ")
      val p = line(0).toInt
      val q = line(1).toInt

      if (p + 2 <= q) counter+=1
    }

    println(counter)
  }
}

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

object HelloWorld {
  def main(args: Array[String]) {

    val n = readLine.toInt

    var counter = 0
    for (i <- 0 until n) {
      val pq = readLine.split(" ").map(value => value.toInt)

      if (pq(0) + 2 <= pq(1)) counter+=1
    }

    println(counter)
  }
}

import scala.io.StdIn

/**
 * Created by richard on 2015/6/10.
 */
object cf467a {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    var c = 0
    for (i <- 0 until n) {
      val in = StdIn.readf2("{0} {1}")
      if ( in._2.asInstanceOf[String].toInt - in._1.asInstanceOf[String].toInt > 1 ) {
        c+=1
      }
    }
    println(c)
  }
}

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = Array.fill(n)(readInts(2))

    println(input.map{arr => arr(1) - arr(0)}.count(_ > 1))
  }
}

/**
 * <a href="http://codeforces.com/problemset/problem/467/A"/>
 *
 * @author pvasilyev
 * @since 08 Apr 2016
 */
object Problem145 extends App {

  private val numberOfLines: Int = scala.io.StdIn.readInt()
  private var answer = 0
  for (i <- 0 until numberOfLines) {
    val Array(p, q) = scala.io.StdIn.readLine().split(" ").map(_.toLong)
    if (q - p >= 2) {
      answer += 1
    }
  }

  println(answer)
}

/**
 * @author pvasilyev
 * @since 08 Apr 2016
 */
object Problem145 extends App {
  private val lines: Iterator[String] = scala.io.Source.stdin.getLines().takeWhile(s => s nonEmpty)
  val firstLine = lines.next()
  var answer = 0
  lines.foreach(line => {
    val strings: Array[String] = line.split(" ")
    val first = strings(0).toInt
    val second = strings(1).toInt
    if (second - first >= 2) {
      answer += 1
    }
  })

  println(answer)
}

object GeorgeAndAccommodation {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt()
		var counter = 0
		for (i <- 1 to n) {
		  val p = scanner.nextInt
		  val q = scanner.nextInt
		  counter += (if (q - p >= 2) 1 else 0)
		}
		println(counter)
	}
}

object Main extends App{
        val n = readLine().toInt
        var ctr = 0
        for (i <- 1 to n){
        	var Array(p,q) = readLine().split(" ").map(_.toLong)
        	if (q - p >= 2)
        		ctr+=1;
        }
        println(ctr)
        ctr = 0
    }

object Codeforces467A extends App{

  def FindRoom(totalroom:Int):Int={
    var ans:Int=0
    for (i <- 0 until totalroom){
      var tempa=scala.io.StdIn.readLine.split(" ").map(_.toInt)
      if (tempa(0)+2 <= tempa(1)) ans+=1
    }
    return ans
  }
  val totalroom=scala.io.StdIn.readInt
  println(FindRoom(totalroom))

}

import scala.io.StdIn._

object A_467 extends App {
  val n = readInt()
  println(
    1 to n count { _ =>
      val Array(a, b) = readLine().split(" ").map(_.toInt)
      b - a >= 2
    }
  )
}

/**
 * @author unit7
 */
object Codeforces {
  def main(args: Array[String]) {
    val input = scala.io.Source.fromInputStream(System.in)
    val lines = input.getLines()
    val n = lines.next().toInt

    var answer = 0

    for (i <- 0 until n) {
      val pq = lines.next().split(' ')
      val p = pq(0).toInt
      val q = pq(1).toInt

      answer += (if (q - p >= 2) 1 else 0)
    }

    println(answer)
  }
}

import scala.io.StdIn.readLine
object problem {
  def main(args: Array[String]) {
  val n = readLine.toInt
    var cnt = 0
    for(i<-0 until n){
      val Array(a,b) = readLine.split(" ").map(_.toInt)
      if( b - a >= 2) cnt += 1
    }
    println(cnt)
  }
}

import java.io.BufferedReader

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

    import java.util.Scanner
    import java.io.InputStreamReader

    val streamReader: InputStreamReader = new InputStreamReader(System.in)
    val scanner: Scanner = new Scanner(new BufferedReader(streamReader))

    val n: Int = Integer.parseInt(scanner.next())
    var capacity: Int = 0
    var people: Int = 0
    var count: Int = 0

    for (i <- 0 until n){
      people = Integer.parseInt(scanner.next())
      capacity = Integer.parseInt(scanner.next())
      if (capacity - people >= 2){
        count = count + 1
      }
    }

    println(count)
  }
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-19.
 */
object A467 extends App{
  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  var i = 0
  var res = 0

  while (i < n) {
    val p, q = sc.nextInt()

    if (q - p >= 2) {
      res += 1
    }

    i += 1
  }

  println(res)
}

import java.util.Scanner

object HelloWorldMain {

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

    val n = sc.nextInt()
    var q : Int = 0
    var p : Int = 0

    var numberOfRooms : Int = 0
    for(i <- 1 to n ){
            p = sc.nextInt()
            q = sc.nextInt()
            if(q - p > 1) numberOfRooms +=1
    }
    println(numberOfRooms)
  }
}

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

object George {
   def main(args: Array[String]) {
     val n = readInt
     val rooms = for {
       i <- 1 to n
       line = readLine.split(' ').map(_.toInt)
     } yield(line(0),line(1))
     println(rooms.count(x => x._2 - x._1 >= 2))
   }
}

object Main extends App{

	val sc = new java.util.Scanner(System.in)
	val n = sc.nextInt

	case class room(living: Int, accommodate: Int){
		val vacancy = accommodate - living
		val canMoveIn: Boolean = vacancy >= 2
	}

	val rooms = Array.fill(n)(room(sc.nextInt, sc.nextInt))
	val res = rooms.filter(_.canMoveIn == true)
	println(res.length)
}

import scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val n = StdIn.readLine().toInt
    var ans = 0
    var cur = 0
    for(i<-0 to n-1) {
      val Array(a,b) = StdIn.readLine().split(" ").map(_.toInt)
      if(b - a >= 2)
        ans += 1
    }
    println(ans)
  }

}

import java.util.Scanner

object TEST extends App{
    val sc = new Scanner(System.in)
    val n = sc.nextInt
    val d = List.fill(n)(-sc.nextInt+sc.nextInt())
    print(d.count(_>=2))
}

import scala.io.StdIn._

object Task extends App{
  val N = readLine.split(" ") map {_.toInt} head
  val rooms = for(i <- 1 to N) yield {
    val Array(a,b) = readLine.split(" ") map {_.toLong}
    (a,b)
  }

  val ans = rooms filter { case(a,b) => (a-b).abs > 1}

  println(ans.size)
}

object Main extends App{
val n = readLine().toInt
        var ctr = 0
        for (i <- 1 to n){
        	var Array(p,q) = readLine().split(" ").map(_.toLong)
        	if (q - p >= 2)
        		ctr+=1;
        }
        println("%d\n", ctr)
        ctr = 0
}


Everybody knows that the capital of Berland is connected to Bercouver (the Olympic capital) by a direct road. To improve the road's traffic capacity, there was placed just one traffic sign, limiting the maximum speed. Traffic signs in Berland are a bit peculiar, because they limit the speed only at that point on the road where they are placed. Right after passing the sign it is allowed to drive at any speed.It is known that the car of an average Berland citizen has the acceleration (deceleration) speed of a km/h2, and has maximum speed of v km/h. The road has the length of l km, and the speed sign, limiting the speed to w km/h, is placed d km (1 ≤ d < l) away from the capital of Berland. The car has a zero speed at the beginning of the journey. Find the minimum time that an average Berland citizen will need to get from the capital to Bercouver, if he drives at the optimal speed.The car can enter Bercouver at any speed.

The first line of the input file contains two integer numbers a and v (1 ≤ a, v ≤ 10000). The second line contains three integer numbers l, d and w (2 ≤ l ≤ 10000; 1 ≤ d < l; 1 ≤ w ≤ 10000).

Print the answer with at least five digits after the decimal point.

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = distance - signDistance

  val t1: Double = math.min(limitV, maxV) / a
  val s1: Double = a * (t1 * t1) / 2.0

  val t3 = (maxV - limitV) / a
  val s3 = limitV * t3 + (a * t3 * t3) / 2.0

  val t5 = maxV / a
  val s5 = a * t5 * t5 / 2

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s1 > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s1 < signDistance) {
      if (maxV <= limitV) {
        (t1 + (signDistance - s1) / math.min(maxV, limitV), math.min(maxV, limitV))
      } else {
        if (s3 + s5 < signDistance) {
          (temp(), limitV)
        } else {
          (compute(), limitV)
        }
      }
    }
    else (t1, math.min(limitV, maxV))

  def compute(): Double = {
    val d = (signDistance - s1) / 2.0
    val t4 = (-2.0 * limitV + Math.sqrt(4.0 * Math.pow(limitV, 2.0) + 8.0 * a * d)) / (2.0 * a)
    t1 + t4 * 2.0
  }

  def temp(): Double = {
    t3 + t5 + (signDistance - s3 - s5) / maxV
  }

  val t2 = (maxV - speedUntilSign) / a
  val s2 = speedUntilSign * t2 + a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) rest / maxV
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + Math.sqrt(4.0 * Math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

  println(timeAfterSign + timeUntilSign)

  /*
4 120
5112 3000 130

  57.600000000000

  */

}

object main extends App with fastIO {

  def tAVS(a: Double, v: Double, s: Double) = {
    val d = v * v + 2 * a * s
    (math.sqrt(d) - v) / a
  }

  def tsAVV(a: Double, v1: Double, v2: Double) = {
    val t = (v2 - v1) / a
    (t, (v1 + v2) * 0.5 * t)
  }

  val Array(a, v) = readLine split " " map {_ toDouble}
  val Array(l, d, w) = readLine split " " map {_ toDouble}

  val u = v min w
  val (t0v, s0v) = tsAVV(a, 0, v)
  val (t0u, s0u) = tsAVV(a, 0, u)
  val (tuv, suv) = tsAVV(a, u, v)
  val (t0vu, s0vu) = (t0v + tuv, s0v + suv)

  val t1 = d match {
    case s if (s < s0u) => tAVS(a, 0, s)
    case s if (s < s0vu) => t0u + tAVS(a, u, (s - s0u) * 0.5) * 2
    case s => t0vu + (s - s0vu) / v
  }

  val z = u min a * t1
  val (tzv, szv) = tsAVV(a, z, v)

  val t2 = l - d match {
    case s if (s < szv) => tAVS(a, z, s)
    case s => tzv + (s - szv) / v
  }

  print(t1 + t2 formatted "%.15f" replace (",", "."))
  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile)new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken()
    in.sval
  }

  def nextInt: Int = {
    in.nextToken()
    in.nval.toInt
  }

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

  def nextDouble: Double = {
    in.nextToken()
    in.nval
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush() = out.flush()
}

object P5D {
    def tAVS(a : Double, v0 : Double, s : Double) = {
        val delta = v0 * v0 + a * s * 2
        (Math.sqrt(delta) - v0) / a
    }

    def tsAVV(a : Double, v0 : Double, v1 : Double) = {
        val t = (v1 - v0) / a
        (t, (v0 + v1) * 0.5 * t)
    }

    def main(args: Array[String]) {
        val Array(a, v) = readLine split " " map {_.toDouble}
        val Array(l, d, w) = readLine split " " map {_.toDouble}
        val u = v min w
        val (t0u, s0u) = tsAVV(a, 0, u)
        val (t0v, s0v) = tsAVV(a, 0, v)
        val (tuv, suv) = tsAVV(a, u, v)
        val (t0vu, s0vu) = (t0v + tuv, s0v + suv)
        val t1 = d match {
            case s if (s < s0u) => tAVS(a, 0, s)
            case s if (s < s0vu) => t0u + tAVS(a * 0.5, u, s - s0u)
            case s => t0vu + (s - s0vu) / v
        }
        val z = u min a * t1
        val (tzv, szv) = tsAVV(a, z, v)
        val t2 = l - d match {
            case s if (s < szv) => tAVS(a, z, s)
            case s => tzv + (s - szv) / v
        }
        println(t1 + t2 formatted "%.5f")
    }
}

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = distance - signDistance

  val t1: Double = math.min(limitV, maxV) / a
  val s1: Double = a * (t1 * t1) / 2.0

  val t3 = (maxV - limitV) / a
  val s3 = limitV * t3 + (a * t3 * t3) / 2

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s1 > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s1 < signDistance) {
      if (maxV <= limitV) {
        (t1 + (signDistance - s1) / math.min(maxV, limitV), math.min(maxV, limitV))
      } else {
        (compute(), limitV)
      }
    }
    else (t1, math.min(limitV, maxV))

  def compute():Double = {
    val d = (signDistance - s1) / 2.0
    val t4 = (-2.0 * limitV + Math.sqrt(4.0 * Math.pow(limitV, 2.0) + 8.0 * a * d)) / (2.0 * a)
    t1 + t4 * 2.0
  }

  val t2 = (maxV - speedUntilSign) / a
  val s2 = speedUntilSign * t2 + a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) maxV * rest
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + Math.sqrt(4.0 * Math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

  println(timeAfterSign + timeUntilSign)

  /*
  20 40
  10000 1 30

  */

}

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = distance - signDistance

  val t1: Double = math.min(limitV, maxV) / a
  val s1: Double = a * (t1 * t1) / 2.0

  val t3 = (maxV - limitV) / a
  val s3 = limitV * t3 + (a * t3 * t3) / 2

  //сначала в любом случае разгон до math.min(limitV, maxV)

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s1 > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s1 < signDistance) {
      if (maxV <= limitV) {
        (t1 + (signDistance - s1) / math.min(maxV, limitV), math.min(maxV, limitV))
      } else {
        (compute(), limitV)
      }
    }
    else (t1, math.min(limitV, maxV))

  def compute():Double = {
    val d = (signDistance - s1) / 2
    val t4 = (-2.0 * limitV + Math.sqrt(4.0 * Math.pow(limitV, 2.0) + 8.0 * a * d)) / (2.0 * a)
    t1 + t4 * 2
  }

  val t2 = (maxV - speedUntilSign) / a
  val s2 = a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) maxV * rest
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + Math.sqrt(4.0 * Math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

  println(timeAfterSign + timeUntilSign)

  /*
  5 70
  200 170 40
  */

}

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = (distance - signDistance).toDouble

  val t1: Double = math.min(limitV, maxV) / a

  val s: Double = a * (t1 * t1) / 2.0

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s < signDistance) (t1 + (signDistance - s) / math.min(maxV, limitV), math.min(maxV, limitV))
    else (t1, math.min(limitV, maxV))

  val t2 = (maxV - speedUntilSign) / a

  val s2 = a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) maxV * rest
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + math.sqrt(4.0 * math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

}

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = distance - signDistance

  val t1: Double = math.min(limitV, maxV) / a
  val s1: Double = a * (t1 * t1) / 2.0

  val t3 = (maxV - limitV) / a
  val s3 = limitV * t3 + (a * t3 * t3) / 2.0

  val t5 = maxV / a
  val s5 = a * t5 * t5 / 2

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s1 > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s1 < signDistance) {
      if (maxV <= limitV) {
        (t1 + (signDistance - s1) / math.min(maxV, limitV), math.min(maxV, limitV))
      } else {
        if (s3 + s5 < signDistance) {
          (temp(), limitV)
        } else {
          (compute(), limitV)
        }
      }
    }
    else (t1, math.min(limitV, maxV))

  def compute(): Double = {
    val d = (signDistance - s1) / 2.0
    val t4 = (-2.0 * limitV + Math.sqrt(4.0 * Math.pow(limitV, 2.0) + 8.0 * a * d)) / (2.0 * a)
    t1 + t4 * 2.0
  }

  def temp(): Double = {
    println(signDistance - s3 - s5)
    println(a * 5)
    println(s5)
    t3 + t5 + (signDistance - s3 - s5) / maxV
  }

  val t2 = (maxV - speedUntilSign) / a
  val s2 = speedUntilSign * t2 + a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) maxV * rest
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + Math.sqrt(4.0 * Math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

  println(timeAfterSign + timeUntilSign)

  /*
  20 40
  10000 799 30

  251.125000000000

  */

}

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = distance - signDistance

  val t1: Double = math.min(limitV, maxV) / a
  val s1: Double = a * (t1 * t1) / 2.0

  val t3 = (maxV - limitV) / a
  val s3 = limitV * t3 + (a * t3 * t3) / 2.0

  val t5 = maxV / a
  val s5 = a * t5 * t5 / 2

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s1 > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s1 < signDistance) {
      if (maxV <= limitV) {
        (t1 + (signDistance - s1) / math.min(maxV, limitV), math.min(maxV, limitV))
      } else {
        if (s3 + s5 < signDistance) {
          (temp(), limitV)
        } else {
          (compute(), limitV)
        }
      }
    }
    else (t1, math.min(limitV, maxV))

  def compute(): Double = {
    val d = (signDistance - s1) / 2.0
    val t4 = (-2.0 * limitV + Math.sqrt(4.0 * Math.pow(limitV, 2.0) + 8.0 * a * d)) / (2.0 * a)
    t1 + t4 * 2.0
  }

  def temp(): Double = {
    t3 + t5 + (signDistance - s3 - s5) / maxV
  }

  val t2 = (maxV - speedUntilSign) / a
  val s2 = speedUntilSign * t2 + a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) maxV * rest
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + Math.sqrt(4.0 * Math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

  println(timeAfterSign + timeUntilSign)

  /*
  20 40
  10000 799 30

  251.125000000000

  */

}

import java.util.Scanner

object DRules extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt().toDouble
  val maxV = scanner.nextInt().toDouble
  val distance = scanner.nextInt().toDouble
  val signDistance = scanner.nextInt().toDouble
  val limitV = scanner.nextInt().toDouble
  val rest = (distance - signDistance).toDouble

  val t1: Double = math.min(limitV, maxV) / a

  val s: Double = a * (t1 * t1) / 2.0

  val (timeUntilSign: Double, speedUntilSign: Double) =
    if (s > signDistance) {
      val t = math.sqrt(2.0 * signDistance / a)
      (t, t * a)
    }
    else if (s < signDistance) (t1 + (signDistance - s) / math.min(maxV, limitV), math.min(maxV, limitV))
    else (t1, math.min(limitV, maxV))

  val t2 = (maxV - speedUntilSign) / a

  val s2 = a * (t2 * t2) / 2.0

  val timeAfterSign: Double =
    if (t2 == 0.0) maxV * rest
    else if (s2 < rest) t2 + (rest - s2) / maxV
    else if (s2 > rest) (-2.0 * speedUntilSign + math.sqrt(4.0 * math.pow(speedUntilSign, 2.0) + 8.0 * a * rest)) / (2.0 * a)
    else t2

  println(timeAfterSign + timeUntilSign)

}

object P5D {
    def tAVS(a : Double, v0 : Double, s : Double) = {
        val delta = v0 * v0 + a * s * 2
        (Math.sqrt(delta) - v0) / a
    }

    def tsAVV(a : Double, v0 : Double, v1 : Double) = {
        val t = (v1 - v0) / a
        (t, (v0 + v1) * 0.5 * t)
    }

    def main(args: Array[String]) {
        val Array(a, v) = readLine split " " map {_.toDouble}
        val Array(l, d, w) = readLine split " " map {_.toDouble}
        val u = v min w
        val (t0u, s0u) = tsAVV(a, 0, u)
        val (t0v, s0v) = tsAVV(a, 0, v)
        val (tuv, suv) = tsAVV(a, u, v)
        val (t0vu, s0vu) = (t0v + tuv, s0v + suv)
        val t1 = d match {
            case s if (s < s0u) => tAVS(a, 0, s)
            case s if (s < s0vu) => t0u + tAVS(a * 0.5, u, s - s0u)
            case s => t0vu + (s - s0vu) / v
        }
        val t2 = l - d match {
            case s if (s < suv) => tAVS(a, u, s)
            case s => tuv + (s - suv) / v
        }
        println(t1 + t2 formatted "%.5f")
    }
}


Olga came to visit the twins Anna and Maria and saw that they have many cookies. The cookies are distributed into bags. As there are many cookies, Olga decided that it's no big deal if she steals a bag. However, she doesn't want the sisters to quarrel because of nothing when they divide the cookies. That's why Olga wants to steal a bag with cookies so that the number of cookies in the remaining bags was even, that is, so that Anna and Maria could evenly divide it into two (even 0 remaining cookies will do, just as any other even number). How many ways there are to steal exactly one cookie bag so that the total number of cookies in the remaining bags was even?

The first line contains the only integer n (1 ≤ n ≤ 100) — the number of cookie bags Anna and Maria have. The second line contains n integers ai (1 ≤ ai ≤ 100) — the number of cookies in the i-th bag.

Print in the only line the only number — the sought number of ways. If there are no such ways print 0.

NoteIn the first sample Olga should take the only bag so that the twins ended up with the even number of cookies.In the second sample Olga can take any of five bags with two cookies or any of three bags with four cookies — 5 + 3 = 8 ways in total.In the third sample, no matter which bag with two cookies Olga chooses, the twins are left with 2 * 9 + 99 = 117 cookies. Thus, Olga has only one option: to take the bag with 99 cookies.

object CF0129A extends App {

  val n = readInt()

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

  val sum = a.sum

  println(a.filter(value => (sum - value)%2 == 0).size)

}

import java.util.Scanner
object Cookies {

  val scanner = new Scanner(System.in)
  val n = scanner.nextInt();
  val bags = (1 to n) map {i=>scanner.nextInt()}

  def main(args: Array[String]): Unit = {
    var count =  (0/:(0 until n)) {(count, pos) =>
        if(((0/:(0 until n)){(sum,i)=> sum + (if (i!=pos) bags(i) else 0) })%2==0) count+1 else count
    }
    print(count)
  }

}

object Solver {
  def main(args: Array[String]) {
    Console.readLine
    var data = List.fromArray(Console.readLine.split(" ").map(s => s.toInt))

    var summary = data.reduceRight((a, b) => a + b)
    println(data.count(x => x % 2 == summary % 2))
  }
}

import java.util.StringTokenizer

object _129A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt)
  val sum = a.sum
  val odd = a.count(i => i % 2 == 1)
  val even = a.length - odd
  if (sum % 2 == 0) println(even)
  else println(odd)
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next()
  val data = in.next().split(" ").map(_.toInt)
  val sum = data.sum
  println(data.count(t => (sum - t) % 2 == 0))

}

object A129 {

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

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

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

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

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

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

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

}

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

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

  val N = sc.nextInt
  val bags = List.fill(N)(sc.nextInt)

  val answer: Int =
    if (bags.sum % 2 == 0) bags.filter(_ % 2 == 0).size
    else bags.filter(_ % 2 == 1).size

  out.println(answer)
  out.close
}

import annotation.tailrec
import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readInt = reader.readLine().toInt

  reader.readLine()
  val cookies = readInts
  val sum = cookies.sum
  def ans = cookies.count(x => (x + sum) % 2 == 0)

  def main(args: Array[String]) {
    println(ans)
  }
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val odd = a.sum % 2
    println(a.count(_ % 2 == odd))
  }
}


Vasya plays the Geometry Horse.The game goal is to destroy geometric figures of the game world. A certain number of points is given for destroying each figure depending on the figure type and the current factor value. There are n types of geometric figures. The number of figures of type ki and figure cost ci is known for each figure type. A player gets ci·f  points for destroying one figure of type i, where f is the current factor. The factor value can be an integer number from 1 to t + 1, inclusive. At the beginning of the game the factor value is equal to 1. The factor is set to i + 1 after destruction of pi (1 ≤ i ≤ t) figures, so the (pi + 1)-th figure to be destroyed is considered with factor equal to i + 1.Your task is to determine the maximum number of points Vasya can get after he destroys all figures. Take into account that Vasya is so tough that he can destroy figures in any order chosen by him.

The first line contains the only integer number n (1 ≤ n ≤ 100) — the number of figure types. Each of the following n lines contains two integer numbers ki and ci (1 ≤ ki ≤ 109, 0 ≤ ci ≤ 1000), separated with space — the number of figures of the i-th type and the cost of one i-type figure, correspondingly. The next line contains the only integer number t (1 ≤ t ≤ 100) — the number that describe the factor's changes.  The next line contains t integer numbers pi (1 ≤ p1 < p2 < ... < pt ≤ 1012), separated with spaces. Please, do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

Print the only number — the maximum number of points Vasya can get.

NoteIn the first example Vasya destroys three figures first and gets 3·1·10 = 30 points. Then the factor will become equal to 2 and after destroying the last two figures Vasya will get 2·2·10 = 40 points. As a result Vasya will get 70 points.In the second example all 8 figures will be destroyed with factor 1, so Vasya will get (3·8 + 5·10)·1 = 74 points.

/**
 * Created by IntelliJ IDEA.
 * User: ymatsux
 * Date: 12/05/06
 * Time: 2:27
 * To change this template use File | Settings | File Templates.
 */

import java.util.Scanner
import scala.util.Sorting

object CF115C {
  def main(args: Array[String]): Unit = {
    (new CF115C).solve
  }
}

class CF115C {
  val sc = new Scanner(System.in)

  val n = sc.nextInt()

  val xs = new Array[(Long, Long)](n)
  for (i <- 0 until n) {
    xs(i) = (sc.nextLong(), sc.nextLong())
  }
  Sorting.stableSort(xs, (x: (Long, Long)) => x._2)

  val t = sc.nextInt()
  val ts = new Array[Long](t)
  for (i <- 0 until t) {
    ts(i) = sc.nextLong()
  }

  var xInd = 0
  var tInd = 0

  var defeated = 0L
  var score = 0L

  def factor: Int = tInd + 1

  def defeatEnemies(defeatNum: Long, incrementX: Boolean, incrementT: Boolean): Unit = {
    val (enemyNum, enemyPoint) = xs(xInd)
    score += defeatNum * enemyPoint * factor
    defeated += defeatNum
    xs(xInd) = (enemyNum - defeatNum, enemyPoint)
    if (incrementX) xInd += 1
    if (incrementT) tInd += 1
  }

  def solve: Unit = {
    while (xInd < xs.length) {
      val (enemyNum, enemyPoint) = xs(xInd)
      if (tInd >= ts.length) {
        defeatEnemies(enemyNum, true, false)
      } else {
        if (enemyNum < ts(tInd) - defeated) {
          defeatEnemies(enemyNum, true, false)
        } else if (enemyNum == ts(tInd) - defeated) {
          defeatEnemies(enemyNum, true, true)
        } else {
          defeatEnemies(ts(tInd) - defeated, false, true)
        }
      }
    }

    println(score)
  }
}

/**
 * Created by IntelliJ IDEA.
 * User: ymatsux
 * Date: 12/05/06
 * Time: 2:27
 * To change this template use File | Settings | File Templates.
 */

import java.util.Scanner
import scala.util.Sorting

object CF115C {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // (number, point)
    val xs = new Array[(Long, Long)](n)
    for (i <- 0 until n) {
      xs(i) = (sc.nextLong(), sc.nextLong())
    }
    val t = sc.nextInt()
    val ts = new Array[Long](t)
    for (i <- 0 until t) {
      ts(i) = sc.nextLong()
    }

    Sorting.stableSort(xs, (x: (Long, Long)) => x._2)

    // println(xs.toList)

    var xInd = 0
    var tInd = 0
    var defeated = 0L
    var score = 0L
    while (xInd < xs.length) {
      val (enemyNum, enemyPoint) = xs(xInd)
      val factor = 1 + tInd
      if (tInd >= ts.length) {
        score += enemyNum * enemyPoint * factor
        defeated += enemyNum
        xs(xInd) = (0L, enemyPoint)
        xInd += 1
      } else {
        if (enemyNum < ts(tInd) - defeated) {
          score += enemyNum * enemyPoint * factor
          defeated += enemyNum
          xs(xInd) = (0L, enemyPoint)
          xInd += 1
        } else if (enemyNum == ts(tInd) - defeated) {
          score += enemyNum * enemyPoint * factor
          defeated += enemyNum
          xs(xInd) = (0L, enemyPoint)
          xInd += 1
          tInd += 1
        } else {
          val defeatNum = ts(tInd) - defeated
          score += defeatNum * enemyPoint * factor
          defeated += defeatNum
          xs(xInd) = (enemyNum - defeatNum, enemyPoint)
          tInd += 1
        }
      }
    }
    println(score)
  }
}

/**
 * Created by IntelliJ IDEA.
 * User: ymatsux
 * Date: 12/05/06
 * Time: 2:27
 * To change this template use File | Settings | File Templates.
 */

import java.util.Scanner
import scala.util.Sorting

object CF115C {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // (number, point)
    val xs = new Array[(Long, Long)](n)
    for (i <- 0 until n) {
      xs(i) = (sc.nextLong(), sc.nextLong())
    }
    val t = sc.nextInt()
    val ts = new Array[Long](t)
    for (i <- 0 until t) {
      ts(i) = sc.nextLong()
    }

    Sorting.stableSort(xs, (x: (Long, Long)) => x._2)

    var xInd = 0
    var tInd = 0
    var score = 0L
    while (xInd < xs.length) {
      val (enemyNum, enemyPoint) = xs(xInd)
      val factor = 1 + tInd
      if (tInd >= ts.length) {
        score += enemyNum * enemyPoint * factor
        xs(xInd) = (0L, enemyPoint)
        xInd += 1
      } else {
        if (enemyNum < ts(tInd)) {
          score += enemyNum * enemyPoint * factor
          xs(xInd) = (0L, enemyPoint)
          ts(tInd) -= enemyNum
          xInd += 1
        } else if (enemyNum == ts(tInd)) {
          score += enemyNum * enemyPoint * factor
          xs(xInd) = (0L, enemyPoint)
          ts(tInd) = 0L
          xInd += 1
          tInd += 1
        } else {
          score += ts(tInd) * enemyPoint * factor
          xs(xInd) = (enemyNum - ts(tInd), enemyPoint)
          ts(tInd) = 0L
          tInd += 1
        }
      }
    }
    println(score)
  }
}

/**
 * Created by IntelliJ IDEA.
 * User: ymatsux
 * Date: 12/05/06
 * Time: 2:27
 * To change this template use File | Settings | File Templates.
 */

import java.util.Scanner
import scala.util.Sorting

object CF115C {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    // (number, point)
    val xs = new Array[(Long, Long)](n)
    for (i <- 0 until n) {
      xs(i) = (sc.nextLong(), sc.nextLong())
    }
    val t = sc.nextInt()
    val ts = new Array[Long](t)
    for (i <- 0 until t) {
      ts(i) = sc.nextLong()
    }

    Sorting.stableSort(xs, (x: (Long, Long)) => x._2)

    // println(xs.toList)

    var xInd = 0
    var tInd = 0
    var defeated = 0L
    var score = 0L
    while (xInd < xs.length) {
      val (enemyNum, enemyPoint) = xs(xInd)
      val factor = 1 + tInd
      if (tInd >= ts.length) {
        score += enemyNum * enemyPoint * factor
        defeated += enemyNum
        xs(xInd) = (0L, enemyPoint)
        xInd += 1
      } else {
        if (enemyNum < ts(tInd) - defeated) {
          score += enemyNum * enemyPoint * factor
          defeated += enemyNum
          xs(xInd) = (0L, enemyPoint)
          xInd += 1
        } else if (enemyNum == ts(tInd) - defeated) {
          score += enemyNum * enemyPoint * factor
          defeated += enemyNum
          xs(xInd) = (0L, enemyPoint)
          xInd += 1
          tInd += 1
        } else {
          score += (ts(tInd) - defeated) * enemyPoint * factor
          defeated += enemyNum
          xs(xInd) = (enemyNum - (ts(tInd) - defeated), enemyPoint)
          tInd += 1
        }
      }
    }
    println(score)
  }
}


Find the number of k-divisible numbers on the segment [a, b]. In other words you need to find the number of such integer values x that a ≤ x ≤ b and x is divisible by k.

The only line contains three space-separated integers k, a and b (1 ≤ k ≤ 1018; - 1018 ≤ a ≤ b ≤ 1018).

object Solution extends App {
  val in = io.Source.stdin.getLines()
  var Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val start = if (a % k == 0) a else if ((a / k) * k > a) (a / k) * k else ((a + k) / k) * k
  val end = if (b % k == 0) b else if (b / k * k < b) b / k * k else (b - k) / k * k
  println(if (end >= start) (end - start) / k + 1 else 0)
}

import scala.io.StdIn

object Main extends App {
  def countDivisible(a: Long, k: Long) = {
    a / k
  }

  override def main(args: Array[String]) = {
    val tokens = StdIn.readLine().split(" ").map(_.toLong)
    val (k, a, b) = (tokens(0), tokens(1), tokens(2))

    val total = (a,b) match {
      case (a, b) if (a == 0 && b == 0) => 1
      case (a, b) if (a == 0 && b > 0) => countDivisible(b, k) + 1
      case (a, b) if (a < 0 && b == 0) => countDivisible(-a, k) + 1
      case (a, b) if (a < 0 && b < 0) => countDivisible(-a, k) - countDivisible(-b - 1, k)
      case (a, b) if (a > 0 && b > 0) => countDivisible(b, k) - countDivisible(a - 1, k)
      case (a, b) if (a < 0 && b > 0) => countDivisible(b, k) + countDivisible(-a, k) + 1
      case _ => 0
    }
    println(total)
  }
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val start = if (a % k == 0) a else (a / k + 1) * k
  val end = if (b % k == 0) b else (b / k - 1) * k

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val ans = (b - a) / k + (if (a % k == 0) 1 else 0)
  println(ans)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  var Array(k, a, b) = in.next().split(' ').map(_.toLong)
  if (a < 0) {
    a = -a
    b = -b
  }
  val start = if (a % k == 0) a else ((a + k) / k) * k
  val end = if (b % k == 0) b else b / k * k

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  var Array(k, a, b) = in.next().split(' ').map(_.toLong)
  if (a < 0) {
    a = -a
    b = -b
  }
  val start = if (a % k == 0) a else ((a + k) / k) * k
  val end = if (b % k == 0) b else b / k * k

  println(start)
  println(end)

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val start = if (a % k == 0) a else (a / k + 1) * k
  val end = if (b % k == 0) b else b / k * k

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val ans = (b - a) / k + (if (b % k == 0) 1 else 0)
  println(ans)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  var Array(k, a, b) = in.next().split(' ').map(_.toLong)
  if (b < 0) {
    a = -a
    b = -b
  }
  val start = if (a % k == 0) a else ((a + k) / k) * k
  val end = if (b % k == 0) b else b / k * k

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val start = if (a % k == 0) a else ((a + k) / k) * k
  val end = if (b % k == 0) b else b / k * k

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  var Array(k, a, b) = in.next().split(' ').map(_.toLong)
  val start = if (a % k == 0) a else if ((a / k) * k > a) (a / k) * k else ((a + k) / k) * k
  val end = if (b % k == 0) b else b / k * k

//  println(start)
//  println(end)

  val full = if (end >= start) (end - start) / k + 1 else 0

  println(full)
}


Your program fails again. This time it gets "Wrong answer on test 233".This is the easier version of the problem. In this version $$$1 \le n \le 2000$$$. You can hack this problem only if you solve and lock both problems.The problem is about a test containing $$$n$$$ one-choice-questions. Each of the questions contains $$$k$$$ options, and only one of them is correct. The answer to the $$$i$$$-th question is $$$h_{i}$$$, and if your answer of the question $$$i$$$ is $$$h_{i}$$$, you earn $$$1$$$ point, otherwise, you earn $$$0$$$ points for this question. The values $$$h_1, h_2, \dots, h_n$$$ are known to you in this problem.However, you have a mistake in your program. It moves the answer clockwise! Consider all the $$$n$$$ answers are written in a circle. Due to the mistake in your program, they are shifted by one cyclically.Formally, the mistake moves the answer for the question $$$i$$$ to the question $$$i \bmod n + 1$$$. So it moves the answer for the question $$$1$$$ to question $$$2$$$, the answer for the question $$$2$$$ to the question $$$3$$$, ..., the answer for the question $$$n$$$ to the question $$$1$$$.We call all the $$$n$$$ answers together an answer suit. There are $$$k^n$$$ possible answer suits in total.You're wondering, how many answer suits satisfy the following condition: after moving clockwise by $$$1$$$, the total number of points of the new answer suit is strictly larger than the number of points of the old one. You need to find the answer modulo $$$998\,244\,353$$$.For example, if $$$n = 5$$$, and your answer suit is $$$a=[1,2,3,4,5]$$$, it will submitted as $$$a'=[5,1,2,3,4]$$$ because of a mistake. If the correct answer suit is $$$h=[5,2,2,3,4]$$$, the answer suit $$$a$$$ earns $$$1$$$ point and the answer suite $$$a'$$$ earns $$$4$$$ points. Since $$$4 > 1$$$, the answer suit $$$a=[1,2,3,4,5]$$$ should be counted.

The first line contains two integers $$$n$$$, $$$k$$$ ($$$1 \le n \le 2000$$$, $$$1 \le k \le 10^9$$$) — the number of questions and the number of possible answers to each question. The following line contains $$$n$$$ integers $$$h_1, h_2, \dots, h_n$$$, ($$$1 \le h_{i} \le k)$$$ — answers to the questions.

Output one integer: the number of answers suits satisfying the given condition, modulo $$$998\,244\,353$$$.

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
  @inline private final def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  @inline private final def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  @inline def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  @inline private final 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()
    }
  }
  @inline def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  @inline private final def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }
  private 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 = _

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

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

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

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

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

object Workspace {
  import Main._
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  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 = 998244353

  def solve(): Unit = {
    val N, K = ni()
    val H = na(N)

    if (K == 1) {
      out.println(0)
      return
    }

    var best, next = Array.ofDim[Long](2 * N + 1)
    best(N) = 1
    REP(N) { i =>
      import java.util
      util.Arrays.fill(next, 0)
      if (H(i) == H((i + 1)%N)) {
        REP(next.length) { j =>
          next(j) = best(j) * K % MOD
        }
      } else {
        REP(next.length) { j =>
          next(j) += best(j) * (K - 2)
          if (j > 0) next(j) += best(j - 1)
          if (j < next.length - 1) next(j) += best(j + 1)
          next(j) %= MOD
        }
      }
      val t = best
      best = next
      next = t
    }
    var ans = 0L
    TO(N + 1, 2 * N) { i =>
      ans += best(i)
    }
    out.println(ans % MOD)
  }
}

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
  @inline private final def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  @inline private final def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  @inline def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  @inline private final def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  @inline private final 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()
    }
  }
  @inline def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  @inline private final def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }
  private 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 = _

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

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

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

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

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

object Workspace {
  import Main._
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  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 = 998244353

  def solve(): Unit = {
    val N, K = ni()
    val H = na(N)

    if (K == 1) {
      out.println(1)
      return
    }

    var best, next = Array.fill[Long](2 * N + 1)(0)
    best(N) = 1
    REP(N) { i =>
      import java.util
      util.Arrays.fill(next, 0)
      if (H(i) == H((i + 1)%N)) {
        REP(next.length) { j =>
          next(j) = best(j) * K % MOD
        }
      } else {
        REP(next.length) { j =>
          next(j) += best(j) * (K - 2)
          if (j > 0) next(j) += best(j - 1)
          if (j < next.length - 1) next(j) += best(j + 1)
          next(j) %= MOD
        }
      }
      val t = best
      best = next
      next = t
    }
    var ans = 0L
    TO(N + 1, 2 * N) { i =>
      ans += best(i)
      ans %= MOD
    }
    out.println(ans)
  }
}


Mishka wants to buy some food in the nearby shop. Initially, he has $$$s$$$ burles on his card. Mishka can perform the following operation any number of times (possibly, zero): choose some positive integer number $$$1 \le x \le s$$$, buy food that costs exactly $$$x$$$ burles and obtain $$$\lfloor\frac{x}{10}\rfloor$$$ burles as a cashback (in other words, Mishka spends $$$x$$$ burles and obtains $$$\lfloor\frac{x}{10}\rfloor$$$ back). The operation $$$\lfloor\frac{a}{b}\rfloor$$$ means $$$a$$$ divided by $$$b$$$ rounded down.It is guaranteed that you can always buy some food that costs $$$x$$$ for any possible value of $$$x$$$.Your task is to say the maximum number of burles Mishka can spend if he buys food optimally.For example, if Mishka has $$$s=19$$$ burles then the maximum number of burles he can spend is $$$21$$$. Firstly, he can spend $$$x=10$$$ burles, obtain $$$1$$$ burle as a cashback. Now he has $$$s=10$$$ burles, so can spend $$$x=10$$$ burles, obtain $$$1$$$ burle as a cashback and spend it too.You have to answer $$$t$$$ independent test cases.

The first line of the input contains one integer $$$t$$$ ($$$1 \le t \le 10^4$$$) — the number of test cases. The next $$$t$$$ lines describe test cases. Each test case is given on a separate line and consists of one integer $$$s$$$ ($$$1 \le s \le 10^9$$$) — the number of burles Mishka initially has.

For each test case print the answer on it — the maximum number of burles Mishka can spend if he buys food optimally.

import java.io.PrintWriter
import util.control.Breaks._

object Solution {
    val reader = scala.io.StdIn
    def readInt = reader.readLine().toInt

    def main(args: Array[String]) {
        val c = new Array[Int](10)
        c(0) = 1
        for (i <- 1 to 9) c(i) = c(i-1) * 10
        var t = readInt
        while (t > 0) {
            var s = readInt
            var rs = 0
            for (i <- 9 to 0 by -1) {
                while (s >= c(i)){
                    s -= c(i)
                    s += c(i) / 10
                    rs += c(i)
                }
            }

            println(rs)
            t-= 1
        }
    }
}


You are a coach at your local university. There are $$$n$$$ students under your supervision, the programming skill of the $$$i$$$-th student is $$$a_i$$$.You have to form $$$k$$$ teams for yet another new programming competition. As you know, the more students are involved in competition the more probable the victory of your university is! So you have to form no more than $$$k$$$ (and at least one) non-empty teams so that the total number of students in them is maximized. But you also know that each team should be balanced. It means that the programming skill of each pair of students in each team should differ by no more than $$$5$$$. Teams are independent from one another (it means that the difference between programming skills of two students from two different teams does not matter).It is possible that some students not be included in any team at all.Your task is to report the maximum possible total number of students in no more than $$$k$$$ (and at least one) non-empty balanced teams.If you are Python programmer, consider using PyPy instead of Python when you submit your code.

The first line of the input contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le k \le n \le 5000$$$) — the number of students and the maximum number of teams, correspondingly. The second line of the input contains $$$n$$$ integers $$$a_1, a_2, \dots, a_n$$$ ($$$1 \le a_i \le 10^9$$$), where $$$a_i$$$ is a programming skill of the $$$i$$$-th student.

Print one integer — the maximum possible total number of students in no more than $$$k$$$ (and at least one) non-empty balanced teams.

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

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

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

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

  def solve(): Unit = {
    val N, K = ni()
    val A = na(N)
    sort(A)

    val dp = Array.fill[Int](N + 1, K + 1)(-1)
    dp(0)(0) = 0
    var r = 0
    REP(N) { l =>
      if (r < l) r = l
      while(r + 1 < N && A(r + 1) - A(l) <= 5) r += 1
      val len = r - l + 1
      REP(K + 1) { k =>
        if (dp(l)(k) != -1) {
          dp(l + 1)(k) = max(dp(l + 1)(k), dp(l)(k)) // スキップ
          if (k < K) dp(r + 1)(k + 1) = max(dp(r + 1)(k + 1), dp(l)(k) + len)
        }
      }
      DEBUG {
        debug("DUMP")
        REP(N + 1) { i =>
          debug(dp(i))
        }
      }
    }

    val ans = dp(N).max
    out.println(ans)
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    Sorting.stableSort(a)
    a
  }

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

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

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

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

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

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

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

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

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

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

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

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

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