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

import scala.annotation.tailrec

/**
  * Created by amir.
  */

object A extends App {

  class RW(val inputFile: String, val outputFile: String) {
    private var br = new BufferedReader(new InputStreamReader(System.in))
    private var out = new PrintWriter(new OutputStreamWriter(System.out))

    /* val f = new File(inputFile)
    if (f.exists && f.canRead)
    try {
    br = new BufferedReader(new FileReader(f))
    out = new PrintWriter(new FileWriter(outputFile))
    } catch {
    case e: IOException =>
    e.printStackTrace()
    }*/

    private var st: StringTokenizer = _
    var eof = false

    def nextLine: String = {
      var s = ""
      try
        s = br.readLine()
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      s
    }

    def next: String = {
      while (st == null || !st.hasMoreTokens)
        try
          st = new StringTokenizer(br.readLine)
        catch {
          case _: IOException =>
            eof = true
            ""
        }
      st.nextToken
    }

    def nextLong: Long = next.toLong

    def nextInt: Int = next.toInt

    def println(): Unit = out.println()

    def println(o: Any): Unit = out.println(o)

    def print(o: Any): Unit = out.print(o)

    def close(): Unit = {
      try {
        br.close()
      } catch {
        case e: IOException =>
          e.printStackTrace()
      }

      out.close()
    }
  }

  override def main(args: Array[String]) {
    val rw = new RW("input.txt", "output.txt")

    def count(s: IndexedSeq[Char], k: Int): Int = {
      @tailrec def count(cur: Int, i: Int, curSum: Int): Int =
        if (i >= s.length) curSum
        else if (s(i) == '*') count(0, i + 1, curSum)
        else count(cur + 1, i + 1, curSum + (if (cur + 1 >= k) 1 else 0))

      count(0, 0, 0)
    }

    val n, _, k = rw.nextInt
    val cl = for (_ <- 1 to n) yield rw.next

    rw.print(cl.map(s => count(s, k)).sum + (if (k == 1) 0 else cl.transpose.map(s => count(s, k)).sum))
    rw.close()
  }
}

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

import scala.annotation.tailrec

/**
  * Created by amir.
  */

object A extends App {

  class RW(val inputFile: String, val outputFile: String) {
    private var br = new BufferedReader(new InputStreamReader(System.in))
    private var out = new PrintWriter(new OutputStreamWriter(System.out))

    /* val f = new File(inputFile)
    if (f.exists && f.canRead)
    try {
    br = new BufferedReader(new FileReader(f))
    out = new PrintWriter(new FileWriter(outputFile))
    } catch {
    case e: IOException =>
    e.printStackTrace()
    }*/

    private var st: StringTokenizer = _
    var eof = false

    def nextLine: String = {
      var s = ""
      try
        s = br.readLine()
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      s
    }

    def next: String = {
      while (st == null || !st.hasMoreTokens)
        try
          st = new StringTokenizer(br.readLine)
        catch {
          case _: IOException =>
            eof = true
            ""
        }
      st.nextToken
    }

    def nextLong: Long = next.toLong

    def nextInt: Int = next.toInt

    def println(): Unit = out.println()

    def println(o: Any): Unit = out.println(o)

    def print(o: Any): Unit = out.print(o)

    def close(): Unit = {
      try {
        br.close()
      } catch {
        case e: IOException =>
          e.printStackTrace()
      }

      out.close()
    }
  }

  override def main(args: Array[String]) {
    val rw = new RW("input.txt", "output.txt")

    def count(s: IndexedSeq[Char], k: Int): Int = {
      @tailrec def count(cur: Int, i: Int, curSum: Int): Int =
      if (i >= s.length ) curSum
      else if (s(i) == '*') count(0, i + 1, curSum)
      else count(cur + 1, i + 1, curSum + (if (cur + 1 >= k) 1 else 0))
      count(0, 0, 0)
    }

    val n, m, k = rw.nextInt
    val cl = for (_ <- 1 to n) yield rw.next

    rw.print(cl.map(s => count(s, k)).sum + (if (k == 1) 0 else cl.transpose.map(s => count(s, k)).sum))
    rw.close()
  }
}

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

import scala.annotation.tailrec

/**
  * Created by amir.
  */

object A extends App {

  class RW(val inputFile: String, val outputFile: String) {
    private var br = new BufferedReader(new InputStreamReader(System.in))
    private var out = new PrintWriter(new OutputStreamWriter(System.out))

    /* val f = new File(inputFile)
    if (f.exists && f.canRead)
    try {
    br = new BufferedReader(new FileReader(f))
    out = new PrintWriter(new FileWriter(outputFile))
    } catch {
    case e: IOException =>
    e.printStackTrace()
    }*/

    private var st: StringTokenizer = _
    var eof = false

    def nextLine: String = {
      var s = ""
      try
        s = br.readLine()
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      s
    }

    def next: String = {
      while (st == null || !st.hasMoreTokens)
        try
          st = new StringTokenizer(br.readLine)
        catch {
          case _: IOException =>
            eof = true
            ""
        }
      st.nextToken
    }

    def nextLong: Long = next.toLong

    def nextInt: Int = next.toInt

    def println(): Unit = out.println()

    def println(o: Any): Unit = out.println(o)

    def print(o: Any): Unit = out.print(o)

    def close(): Unit = {
      try {
        br.close()
      } catch {
        case e: IOException =>
          e.printStackTrace()
      }

      out.close()
    }
  }

  override def main(args: Array[String]) {
    val rw = new RW("input.txt", "output.txt")

    def count(s: IndexedSeq[Char], k: Int): Int = {
      def count(cur: Int, i: Int): Int =
      if (i >= s.length ) 0
      else if (s(i) == '*') count(0, i + 1)
      else count(cur + 1, i + 1) + (if (cur + 1 >= k) 1 else 0)
      count(0, 0)
    }

    val n, m, k = rw.nextInt
    val cl = for (_ <- 1 to n) yield rw.next

    rw.print(cl.map(s => count(s, k)).sum + cl.transpose.map(s => count(s, k)).sum)
    rw.close()
  }
}

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

import scala.annotation.tailrec

/**
  * Created by amir.
  */

object A extends App {

  class RW(val inputFile: String, val outputFile: String) {
    private var br = new BufferedReader(new InputStreamReader(System.in))
    private var out = new PrintWriter(new OutputStreamWriter(System.out))

    /* val f = new File(inputFile)
    if (f.exists && f.canRead)
    try {
    br = new BufferedReader(new FileReader(f))
    out = new PrintWriter(new FileWriter(outputFile))
    } catch {
    case e: IOException =>
    e.printStackTrace()
    }*/

    private var st: StringTokenizer = _
    var eof = false

    def nextLine: String = {
      var s = ""
      try
        s = br.readLine()
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      s
    }

    def next: String = {
      while (st == null || !st.hasMoreTokens)
        try
          st = new StringTokenizer(br.readLine)
        catch {
          case _: IOException =>
            eof = true
            ""
        }
      st.nextToken
    }

    def nextLong: Long = next.toLong

    def nextInt: Int = next.toInt

    def println(): Unit = out.println()

    def println(o: Any): Unit = out.println(o)

    def print(o: Any): Unit = out.print(o)

    def close(): Unit = {
      try {
        br.close()
      } catch {
        case e: IOException =>
          e.printStackTrace()
      }

      out.close()
    }
  }

  override def main(args: Array[String]) {
    val rw = new RW("input.txt", "output.txt")

    def count(s: IndexedSeq[Char], k: Int): Int = {
      @tailrec def count(cur: Int, i: Int, curSum: Int): Int =
        if (i >= s.length) curSum
        else if (s(i) == '*') count(0, i + 1, curSum)
        else count(cur + 1, i + 1, curSum + (if (cur + 1 >= k) 1 else 0))

      count(0, 0, 0)
    }

    val n, _, k = rw.nextInt
    val cl = for (_ <- 1 to n) yield rw.next

    def f[T <: IndexedSeq[String]]: T => Int = _.map(s => count(s, k)).sum

    rw.print(f(cl) + (if (k == 1) 0 else f(cl.transpose.map(_.toString))))
    rw.close()
  }
}


object Main {
    def main(args: Array[String]) = {
      val t = readInt
      (0 until t).foreach((x) => f1)
    }
    def f1(): Unit = {
        val n = readLong
        val as = readLine.split(" ").map(_.toInt)
        val x: Map[Int, Int] = as.foldLeft(Map[Int, Int]()){
            case (m, i) => {
                val (c, n) = f2(i, 0)
                m.lift(c) match {
                    case Some(x) => if (x > n) m else m + (c -> n)
                    case None => m + (c -> n)
                }
            }
        }
        println(x.values.foldLeft(0)(_ + _))
    }

    def f2(i: Int, c: Int): (Int, Int) = {
        if (i % 2 != 0) (i, c) else f2(i / 2, c + 1)
    }

  }

import scala.collection.mutable

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

  val t = nextInt
  for (_ <- 1 to t) {
    val n = nextInt
    val as = nextInts(n)
    val map = mutable.Map.empty[Int, Int]
    var i = 0
    while (i < n) {
      var a = as(i)
      var p = 0
      while ((a & 1) == 0) {
        p += 1
        a >>>= 1
      }
      if (p > 0) {
        if (map.contains(a)) {
          if (map(a) < p) map(a) = p
        } else map(a) = p
      }
      i += 1
    }
    val res = map.valuesIterator.sum
    out.println(res)
  }

  out.flush()

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


object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val A=nextString
    val B=nextString
    val C=nextString
    val a=Array.fill(26)(0)
    val b=Array.fill(26)(0)
    val c=Array.fill(26)(0)
    val ascii0='a'.toInt
    for(i<-0 until A.length()){
      a(A(i).toInt-ascii0)+=1
    }
    for(i<-0 until B.length()){
      b(B(i).toInt-ascii0)+=1
    }
    for(i<-0 until C.length()){
      c(C(i).toInt-ascii0)+=1
    }
    var max= -3
    var maxcurrent= -1
    var nb=0
    while(maxcurrent>=max){
      max=maxcurrent
      var nc=Int.MaxValue

      for(i<-0 until 26){
        if(a(i)<nb*b(i))
          {
            nc= -nb-1
          }
          else if(c(i)>0){

          val ncc=(a(i)-nb*b(i))/c(i)
          if(ncc<nc){
            nc=ncc
          }

        }
      }
      maxcurrent=nc+nb
      nb+=1
//      out.println(maxcurrent)
    }
    nb-=2

    for(i<-0 until nb){out.print(B)}
    for(i<-0 until max-nb){out.print(C)}
    for(i<-0 until 26){
      out.print((i+ascii0).toChar.toString*(a(i)-nb*b(i)-(max-nb)*c(i)))
    }
    out.println
    //code ends here
    out.flush
    out.close
  }
}

import java.util.Scanner
import scala.math
import scala.util.control.Breaks._
import java.lang.Exception

object CF551B extends App {
  //var in = new Scanner(System.in)
  val a = readLine()
  val b = readLine()
  val c = readLine()
  val ca = ('a' to 'z').map(x => a.count { y => x == y })
  val cb = ('a' to 'z').map(x => b.count { y => x == y })
  val cc = ('a' to 'z').map(x => c.count { y => x == y })
  var bestX = 0
  var bestY = 0
  try {
  for (x <- 0 to 100000) {
    var y = 100000
    for (i <- 0 to 25) {
      val tmp = ca(i) - cb(i) * x
      if (tmp < 0)
        y = -1
      else {
        if (cc(i) > 0)
          y = Math.min(y, tmp / cc(i))
      }
    }
    if (y < 0)
      throw new Exception()
    if (y >= 0 && x + y > bestX + bestY) {
      bestX = x
      bestY = y
    }
  }
  } catch {
    case _ =>
  }

  for (x <- 1 to bestX)
    print(b)
  for (y <- 1 to bestY)
    print(c)
  for (i <- 0 to 25) {
    val rest = ca(i) - cb(i) * bestX - cc(i) * bestY
    for (j <- 1 to rest)
      print((97 + i).toChar)
  }
}

import java.util.Scanner
import scala.math
import scala.util.control.Breaks._
import java.lang.Exception

object CF551B extends App {
  var in = new Scanner(System.in)
  val a = in.next()
  val b = in.next()
  val c = in.next()
  val ca = ('a' to 'z').map(x => a.count { y => x == y })
  val cb = ('a' to 'z').map(x => b.count { y => x == y })
  val cc = ('a' to 'z').map(x => c.count { y => x == y })
  var bestX = 0
  var bestY = 0
  try {
  for (x <- 0 to 100000) {
    var y = 100000
    for (i <- 0 to 25) {
      val tmp = ca(i) - cb(i) * x
      if (tmp < 0)
        y = -1
      else {
        if (cc(i) > 0)
          y = Math.min(y, tmp / cc(i))
      }
    }
    if (y < 0)
      throw new Exception()
    if (y >= 0 && x + y > bestX + bestY) {
      bestX = x
      bestY = y
    }
  }
  } catch {
    case _ =>
  }

  for (x <- 1 to bestX)
    print(b)
  for (y <- 1 to bestY)
    print(c)
  for (i <- 0 to 25) {
    val rest = ca(i) - cb(i) * bestX - cc(i) * bestY
    for (j <- 1 to rest)
      print((97 + i).toChar)
  }
}

import java.util.Scanner
import scala.math

object CF551B extends App {
  var in = new Scanner(System.in)
  val a = in.next()
  val b = in.next()
  val c = in.next()
  val ca = ('a' to 'z').map(x => a.count { y => x == y })
  val cb = ('a' to 'z').map(x => b.count { y => x == y })
  val cc = ('a' to 'z').map(x => c.count { y => x == y })
  var bestX = 0
  var bestY = 0
  for (x <- 0 to 100000) {
    var y = 100000
    for (i <- 0 to 25) {
      val tmp = ca(i) - cb(i) * x
      if (tmp < 0)
        y = -1
      else {
        if (cc(i) > 0)
          y = Math.min(y, tmp / cc(i))
      }
    }
    if (y >= 0 && x + y > bestX + bestY) {
      bestX = x
      bestY = y
    }
  }
  var str = ""
  for (x <- 1 to bestX) str += b
  for (y <- 1 to bestY) str += c
  for (i <- 0 to 25) {
    val rest = ca(i) - cb(i) * bestX + cc(i) * bestY
    for (j <- 1 to rest)
      str += (97 + i).toChar;
  }
  println(str)
}

import java.util.Scanner
import scala.math

object CF551B extends App {
  var in = new Scanner(System.in)
  val a = in.next()
  val b = in.next()
  val c = in.next()
  val ca = ('a' to 'z').map(x => a.count { y => x == y })
  val cb = ('a' to 'z').map(x => b.count { y => x == y })
  val cc = ('a' to 'z').map(x => c.count { y => x == y })
  var bestX = 0
  var bestY = 0
  for (x <- 0 to 100000) {
    var y = 100000
    for (i <- 0 to 25) {
      val tmp = ca(i) - cb(i) * x
      if (tmp < 0)
        y = -1
      else {
        if (cc(i) > 0)
          y = Math.min(y, tmp / cc(i))
      }
    }
    if (y >= 0 && x + y > bestX + bestY) {
      bestX = x
      bestY = y
    }
  }
  println(bestX, bestY)
  var str = ""
  for (x <- 1 to bestX) str += b
  for (y <- 1 to bestY) str += c
  for (i <- 0 to 25) {
    val rest = ca(i) - cb(i) * bestX - cc(i) * bestY
    for (j <- 1 to rest)
      str += (97 + i).toChar;
  }
  println(str)
}

object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val A=nextString
    val B=nextString
    val C=nextString
    val a=Array.fill(26)(0)
    val b=Array.fill(26)(0)
    val c=Array.fill(26)(0)
    val ascii0='a'.toInt
    for(i<-0 until A.length()){
      a(A(i).toInt-ascii0)+=1
    }
    for(i<-0 until B.length()){
      b(B(i).toInt-ascii0)+=1
    }
    for(i<-0 until C.length()){
      c(C(i).toInt-ascii0)+=1
    }
    var max= -3
    var maxcurrent= -1
    var nb=0
    while(maxcurrent>=max){
      max=maxcurrent
      var nc=Int.MaxValue

      for(i<-0 until 26){
        if(a(i)<nb*b(i))
          {
            nc= -nb-1
            if(i==13){
      //        out.println(a(i)+" "+(nb*b(i)))
            }

          }
        if(c(i)>0){

          val ncc=(a(i)-nb*b(i))/c(i)
          if(ncc<nc){
            nc=ncc
          }

        }
      }
      maxcurrent=nc+nb
      nb+=1

//      out.println(maxcurrent)
    }
    nb-=1
    if(maxcurrent< 0){
      nb-= 1
    }
    for(i<-0 until nb){out.print(B)}
    for(i<-0 until max-nb){out.print(C)}
    for(i<-0 until 26){
      out.print((i+ascii0).toChar.toString*(a(i)-nb*b(i)-(max-nb)*c(i)))
    }
    out.println
    //code ends here
    out.flush
    out.close
  }
}

object B{
  //import scala.collection.mutable.PriorityQueue
  //import scala.collection.mutable.ArrayBuffer
  import util.control.Breaks._
  import java.io.{PrintWriter,InputStream,BufferedReader,InputStreamReader}
  import java.util.{Locale, Scanner,StringTokenizer}
  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
    val reader=new BufferedReader(new InputStreamReader(stream), 32768);

    def next():String = {
        while (!st.hasMoreTokens()){
          val currentLine = reader.readLine
          st=new StringTokenizer(currentLine)
        }
        return st.nextToken
    }

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

    def nextLong():Long = {
    	return next.toLong
    }
    def nextDouble:Double = {
      return next.toDouble
    }
  }

  def main(args: Array[String]){

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

    def nextInt = in.nextInt
    def nextLong = in.nextLong
    def nextDouble = in.nextDouble
    def nextString = in.next
    //code starts here
    val A=nextString
    val B=nextString
    val C=nextString
    val a=Array.fill(26)(0)
    val b=Array.fill(26)(0)
    val c=Array.fill(26)(0)
    val ascii0='a'.toInt
    for(i<-0 until A.length()){
      a(A(i).toInt-ascii0)+=1
    }
    for(i<-0 until B.length()){
      b(B(i).toInt-ascii0)+=1
    }
    for(i<-0 until C.length()){
      c(C(i).toInt-ascii0)+=1
    }
    var max= -3
    var maxcurrent= -1
    var nb=0
    while(maxcurrent>=max){
      max=maxcurrent
      var nc=Int.MaxValue

      for(i<-0 until 26){
        if(a(i)<nb*b(i))
          {
            nc= -nb-1
          }
          else if(c(i)>0){

          val ncc=(a(i)-nb*b(i))/c(i)
          if(ncc<nc){
            nc=ncc
          }

        }
      }
      maxcurrent=nc+nb
      nb+=1
//      out.println(maxcurrent)
    }
    nb-=1
    if(maxcurrent< 0){
      nb-= 1
    }
    for(i<-0 until nb){out.print(B)}
    for(i<-0 until max-nb){out.print(C)}
    for(i<-0 until 26){
      out.print((i+ascii0).toChar.toString*(a(i)-nb*b(i)-(max-nb)*c(i)))
    }
    out.println
    //code ends here
    out.flush
    out.close
  }
}


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

  override def apply(io: IO): io.type = {
    val input = io.read[Seq[Seq[Int]]]
    val ans = input.map(prices => (prices.sum*1.0/prices.size).ceil.toInt)
    io.writeAll(ans, separator = "\n")
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = apply(new IO(System.in, System.out)).close()
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]

  def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None

  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)

  implicit class GenericExtensions[A](a: A) {
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }

  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](t: C[A]) {
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]

    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)

    def toMultiSet: Map[A, Int] = t.groupBy(identity).mapValues(_.size)
  }

  implicit class PairExtensions[A, B](p: (A, B)) {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p.key, ev(p.value))
  }

  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
  }

  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](m: C[K, V]) {
    def toMutable: mutable.Map[K, V] = mutable.Map.empty[K, V] ++ m
  }

  implicit class SetExtensions[A, C[A] <: Set[A]](s: C[A]) {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }

  implicit class IterableExtensions[A, C[A] <: Seq[A]](s: C[A]) {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
  }

  implicit class BooleanExtensions(x: Boolean) {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }

  def desc[A](implicit order: Ordering[A]): Ordering[A] = order.reverse  //e.g. students.sortBy(_.height)(desc)

  def map[K] = new {
    def to[V](default: => V): mutable.Map[K, V] = using(_ => default)
    def using[V](f: K => V): mutable.Map[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }

  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]

  def memoize[A, B](f: A => B): A => B = map[A] using f
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

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

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

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

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

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

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

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

import scala.io.StdIn._

object taskA {
  def main(args: Array[String]): Unit = {
    var q = scala.io.StdIn.readInt()
    while(q > 0) {
      val n : Int = readInt()
      val array : Array[Int] = readLine().split(" ").map(_.toInt)
      val sum : Double = array.sum
      val ans : Int = Math.ceil(sum/n).toInt
      println(ans)
      q -= 1
    }
  }
}

object Ex1 extends App {
  import scala.annotation.tailrec
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer

  import scala.io.Codec

  /**
   * Faster Scanner in Scala by wrick
   * https://codeforces.com/blog/entry/21074
   *
   * Scala implementation of a faster java.util.Scanner
   * See: http://codeforces.com/blog/entry/7018
   */
  class Scanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {
    def this(reader: BufferedReader) = this(new LineNumberReader(reader))
    def this(reader: Reader) = this(new BufferedReader(reader))
    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))
    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))
    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)
    def this(str: String) = this(new StringReader(str))

    private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).filter(_.hasMoreTokens)
    private[this] var current: Option[StringTokenizer] = None

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

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

  def read2(): Seq[Seq[Int]] = {
    val in = new Scanner(System.in)
    val q = in.nextInt()
    (0 until q).map { _ =>
      val n = in.nextInt()
      (0 until n).map(_ => in.nextInt())
    }
  }

  def res(list: Seq[Int]) = {
    val sum = list.sum
    val len = list.length
    if (sum % len == 0) sum / len
    else sum / len + 1
  }

  read2().foreach(x => println(res(x)))

}


/**
 * @author pvasilyev
 * @since 19 Jun 2016
 */
object A288 extends App {

  def solve() = {
    val Array(n, k): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    if (n < k) {
      println("-1")
    } else if (k == 1) {
      if (n == 1) {
        println("a")
      } else {
        println("-1")
      }
    } else if (k == 2) {
      println(("a b " * n).split(" ").take(n).mkString(""))
    } else {
      val answer: Array[Char] = Array.ofDim[Char](n)
      for (j <- k.to(3, -1)) {
        answer(n - 1 - k + j) = ('a'.toInt + j - 1).toChar
      }
      var i = 0
      while (i < n - k + 2) {
        if (i % 2 == 0) {
          answer(i) = 'a'
        } else {
          answer(i) = 'b'
        }
        i += 1
      }
      println(answer.mkString(""))
    }
  }

  solve()

}

import scala.collection.mutable.StringBuilder
import java.util.Scanner

object Strings extends App {

	val scanner = new Scanner( System.in )

	val n = scanner.nextInt
	val k = scanner.nextInt

	if( n < k || n > 1 && k == 1 )
		println( "-1" )
	else {
		// initialize the string with default "abab..." value
		val sb = new StringBuilder( "ab" * ( n / 2 ) + "a" * ( n % 2 ))
		// fill the rest with k-2 different characters
		for( i <- ( k - 1 to 2 by -1 ))
			sb( n - k + i ) = ( 'a' + i ).toChar
		println( sb.result )
	}
}

import io.Source
import java.io.PrintWriter

object CF288A {

  def solve(in: In, out: PrintWriter) {
    val n, k = in().toInt
    if (n < k || k == 1 && n > 1) {
      out.println("-1")
    } else {
      for (i <- 0 until math.min(n, n - (k - 2))) {
        out.print(if (i % 2 == 0) 'a' else 'b')
      }
      for (i <- 2 until k) {
        out.print((i + 'a').toChar)
      }
      out.println()
    }
  }

  def main(args: Array[String]) {
    val in: In = new In(Source.fromInputStream(System.in))
    val out: PrintWriter = new PrintWriter(System.out)
    solve(in, out)
    out.close()
  }

  class TokenIterator(iter: BufferedIterator[Char], delims: String) extends Iterator[String] {
    private val sb = new StringBuilder

    def hasNext: Boolean = {
      skipDelims()
      iter.hasNext
    }

    def skipDelims() {
      while (iter.hasNext && delims.indexOf(iter.head) != -1) {
        iter.next()
      }
    }

    def next(): String = {
      skipDelims()
      while (iter.hasNext && delims.indexOf(iter.head) == -1) {
        sb.append(iter.next())
      }
      val ret = sb.toString()
      sb.clear()
      ret
    }
  }

  class In(source: Source) {
    val iter = source.buffered

    val tokenIterator = new TokenIterator(iter, " \r\n")

    val lineIterator = new TokenIterator(iter, "\r\n")

    def apply() = tokenIterator.next()

    def apply(n: Int) = tokenIterator.take(n)
  }
}

object C {
  def READ: Array[Int] = readLine() split (" ") map (_.toInt);

  def main(args: Array[String]) {
    var Array(n, k) = READ
    if (n < k || k == 1) {
      println(if (n*k == 1) 'a' else -1);
      return;
    }
    var result:StringBuilder = new StringBuilder;
    for (i <- 1 to n-k+2) result.append(if (i%2 == 1)  'a' else 'b');
    for (i <- 1 to k-2) result.append(('a'+i+1).toChar)
    println(result)
  }
}

object A extends App
{
    val Array(n, k) = readLine.split(" ").map(_.toInt)
    if (n < k || (k==1 && n>1))
        println(-1)
    else
    {
        for (i <- 0 until math.min(n,n-k+2))
            print(if ((i&1)==0) 'a' else 'b')
        for (ch <- 'c' until ('a'+k).toChar)
            print(ch)
        println()
    }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  if (k > n || (n > 1 && k == 1)) println(-1)
  else if (n == 1) println("a")
  else {
    println(((1 to n - k + 2).map(i => if (i % 2 == 1) 'a' else 'b').toList
      ::: ('c' until ('c' + k - 2).toChar).toList).mkString(""))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  if (k > n || (n > 1 && k == 1)) println(-1)
  else {
    println(((1 to n - k + 2).map(i => if (i % 2 == 1) 'a' else 'b').toList
      ::: ('c' until ('c' + k - 2).toChar).toList).mkString(""))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  if (k > n) println(-1)
  else {
    println(((1 to n - k + 2).map(i => if (i % 2 == 1) 'a' else 'b').toList
      ::: ('c' until ('c' + k - 2).toChar).toList).mkString(""))
  }
}

object A extends App
{
    val Array(n, k) = readLine.split(" ").map(_.toInt)
    if (n < k)
        println(-1)
    else
    {
        for (i <- 0 until math.min(n,n-k+2))
            print(if ((i&1)==0) 'a' else 'b')
        for (ch <- 'c' until ('a'+k).toChar)
            print(ch)
        println()
    }
}

object A extends App
{
    val Array(n, k) = readLine.split(" ").map(_.toInt)
    if (k > n)
        println(-1)
    else
    {
        for (i <- 0 until n-k+2)
            print(if ((i&1)==0) 'a' else 'b')
        for (ch <- 'c' until ('a'+k).toChar)
            print(ch)
        println()
    }
}


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

object _1557A {
  def main(args: Array[String]): Unit = {
    var t = readInt()
    while(t > 0 ){
      t -= 1
      val n = readInt()
      val ar = readLine().split(" ").map(_.toDouble)
      Sorting.quickSort(ar)
      val sum : Double = (ar.sum - ar(n - 1)) / (n - 1.0);
      println(sum + ar(n - 1))
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt).sorted(Ordering[Int].reverse)

    val ans = an.head + an.tail.foldLeft(0L)(_ + _) / (n - 1.0)

    println(ans)
  }
}

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

object _1557A {
  def main(args: Array[String]): Unit = {
    var t = readInt()
    while(t > 0 ){
      t -= 1
      val n = readInt()
      val ar = readLine().split(" ").map(_.toInt)
      Sorting.quickSort(ar)
//      println(ar.mkString(", "))
      val sum : Double = (ar.sum - ar(n - 1)) / (n - 1.0);
      println(sum + ar(n - 1))
    }
  }
}


//package codeforces.contests._1487

object CatCycle {

  def main(args: Array[String]): Unit = {
    println({
      for (_ <- 1 to io.StdIn.readInt()) yield {
        val Array(n, k) = io.StdIn.readLine.split(" ").map(_.toInt)

        if ((n % 2) == 0) ((k - 1) % n)
        else {
          // 0 based
          val w      = (k-1) / (n - 1)
          val offset = (k - 1) % (n - 1)
          val start  = w % n

          (if (offset < n / 2) (start + offset) % n else (start + offset + 1) % n)
        }

      } + 1
    }.mkString("\n"))
  }
}

import scala.io.StdIn._

object Cat_Cycle extends App{
  val t = readInt()
  var n = 0
  var k = 0
  for (i <- 1 to t) {
    val Array(x, y) = readLine().split(" ").map(_.toInt)
    n = x // Number of spots
    k = y // Hours
    var A = n
    var B = 1
    if (n % 2 == 0) {
      if (k % n == 0) {
        println(n)
      }
      else {
        println(k % n)
      }
    }
    else {
      val step = n / 2
      val meets = (k - 1) / step
      if ((B * k) % n == 0) B = n else B = (B * k) % n
      B += meets
      if (B % n == 0) B = n else B = B % n
      println(B)
    }
  }
}

object B {
  import scala.io.{StdIn => in}

  def main(args: Array[String]): Unit = {
    val tests = in.readInt()
    (1 to tests).foreach { _ =>
      val Array(n, k) = in.readLine().split(' ').map(_.toInt)
      println((k - 1 + n % 2 * (k - 1) / (n / 2)) % n + 1)
    }
  }
}

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

    for (_ <- 1 to nextInt) {
      val n, k = nextInt
      val b = if (n % 2 == 0) (k - 1) % n
      else (k + (k - 1) / (n / 2) - 1) % n

      out.println(b + 1)
    }

    out.flush()
  }

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

import scala.io.StdIn._

object Cat_Cycle extends App{
  val t = readInt()
  var n = 0
  var k = 0
  for (i <- 1 to t) {
    val Array(x, y) = readLine().split(" ").map(_.toInt)
    n = x // Number of spots
    k = y // Hours
    var A = n
    var B = 1
    if (n % 2 == 0) {
      if (k % n == 0) {
        println(n)
      }
      else {
        println(k % n)
      }
    }
    else {
      val step = n / 2
      val meets = (k - 1) / step
      if ((B * k) % n == 0) B = n else B = (B * k) % n
      B += meets
      if (B % n == 0) B == n else B = B % n
      println(B)
    }
  }
}

import scala.io.StdIn._

object test extends App {
  val t = readInt()
  var n = 0;
  var k = 0
  for (i <- 1 to t) {
    val Array(x, y) = readLine().split(" ").map(_.toInt)
    n = x // Number of spots
    k = y // Hours
    if (n % 2 == 0) {
      if (k % n == 0) {
        println(n)
      }
      else {
        println(k % n)
      }
    }
    else {
      var A = n
      var B = 1
      for (j <- 1 until k) {
        A -= 1
        B += 1
        if (A < 1) {
          A += n
        }
        if (B > n) {
          B -= n
        }
        if (A == B) {
          B += 1
        }
      }
      println(B)
    }
  }

}

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

    for (_ <- 1 to nextInt) {
      val n, k = nextInt
      var a = n - 1
      var b = 0
      if (n % 2 == 0) {
        b = (k - 1) % n
      } else {
        var rep = -1
        var step = 0
        while (step < k - 1) {
          val d = Math.min(k - step -1, (a - b - 1) / 2)
          if (a == n - 1 && b == 0 && step > 0 && step * 2 < k) {
            println(step, rep, a, b)
            if (rep == -1) {
              rep = step
            } else {
              step += (k - step - 1) / rep * rep
            }
          } else if (d > 0) {
            a -= d
            b += d
            step += d
          } else if (b + 2 == a) {
            a -= 1
            b += 2
            step += 1
          } else {
            val dd = Math.min(k - step-1, (n - 1) / 2)
            a = (a + n - dd) % n
            b = (b + n + dd) % n
            if (b == a) b = (b + 1) % n
            step += dd
          }
//          println(step, a, b)
        }
      }
//      println(b + 1)
      out.println(b + 1)
    }

    out.flush()
  }

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


object Solver {
    def main(args: Array[String]) {
        var total = 0
        var n = Console.readLine.toInt
        var drinks = Set("ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE")

        for (i <- 1 to n) {
            var input = Console.readLine
            var suspicious = if ( input.forall(_.isDigit) ) input.toInt < 18 else drinks.contains(input)
            if (suspicious) total += 1
        }
        println(total)
    }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val drinks = List("ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE",
    "TEQUILA", "VODKA", "WHISKEY", "WINE")
  println((1 to n).count{
    _ => val str = in.next()
      if (str.forall(_.isDigit))
        str.toInt < 18
      else
        drinks.contains(str)
  })
}

object A56 {

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

  def main(args: Array[String]): Unit = {
    val Array(tests) = readInts(1)
    var res = 0
    val alcohol = Array("ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM", "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE")
    for(_ <- 1 to tests) {
      val str = read
      if(alcohol.contains(str))
        res += 1
      else {
        util.Try{str.toInt}.foreach { int=>
          if(int < 18)
            res += 1
        }
      }
    }
    out.println(res)
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

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

}

/**
  * Created by John Compitello on 7/26/16.
  */
object Main {
  def main(args: Array[String]) = {
    val drinkList: List[String] = List("ABSINTH", "BEER", "BRANDY", "CHAMPAGNE", "GIN", "RUM",
      "SAKE", "TEQUILA", "VODKA", "WHISKEY", "WINE")
    val lines: Array[String] = (for (ln <- io.Source.stdin.getLines) yield ln).toArray
    val numClients = lines(0).toInt
    val clientList = lines.tail

    val (numList, nameList): (Array[String], Array[String]) = clientList.partition(isANumber)

    println(numList.map(_ toInt).filter(_ < 18).length + nameList.filter(x => drinkList contains x).length)
  }

  //Must check people in client list who are either drinking alcohol or under 18.
  def isANumber(x: String): Boolean = x forall Character.isDigit
}


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

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

    case class myType(left: Int, right: Int, index: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (left < that.left || (left == that.left && right < that.right))
                return -1
            else if (left == that.left && right == that.right)
                return 0
            else
                return 1
        }
    }

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        val ans = new ArrayBuffer[(Int, Int, Int)]()
        val arr = new Array[Int](n)
        for (i <- 1 to n)
            arr(i-1) = readInt()
        for (i <- 0 until n) {
            var mm = arr(i)
            var po = i
            for (j <- i until n)
                if (arr(j) < mm) {
                    mm = arr(j)
                    po = j
                }
            if (po != i) {
                ans.append((i+1, po+1, po-i))
                for (j <- (i until po).reverse)
                    arr(j+1) = arr(j)
                arr(i) = mm
            }
        }
        writer.println(ans.length)
        for (mv <- ans)
            writer.println(mv._1 + " " + mv._2 + " " + mv._3)
    }
    writer.flush()
}

object B extends App {

  type Shift = (Int, Int, Int)

  def shiftingSort(an: IndexedSeq[Int]): List[Shift] = {
    val bn = an.zipWithIndex.sorted

    bn.indices
      .foldLeft(List.empty[Shift]) { (shifts, i) =>
        val j = shifts.foldRight(bn(i)._2) {
          case ((l, r, d), j) if l <= j && j <= r =>
            val size = r - l + 1
            l + (j - l - d + size) % size
          case (_, j)                             => j
        }

        if (i == j) shifts else (i, j, j - i) :: shifts
      }
      .reverse
  }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt)

    val shifts = shiftingSort(an)

    println(shifts.length)
    println(shifts.map { case (l, r, d) => s"${l + 1} ${r + 1} $d" }.mkString("\n"))
  }
}

object B extends App {

  type Shift = (Int, Int, Int)

  def shiftingSort(an: IndexedSeq[Int]): List[Shift] = {
    val bn = an.zipWithIndex.sorted

    bn.indices
      .foldLeft(List.empty[Shift]) { (shifts, i) =>
        val j = shifts.reverse.foldLeft(bn(i)._2) {
          case (j, (l, r, d)) if l <= j && j <= r => l + (j - l - d + r - l + 1) % (r - l + 1)
          case (j, _)                             => j
        }

        if (i == j) shifts else (i, j, j - i) :: shifts
      }
      .reverse
  }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val n  = readInt()
    val an = readLine().split(" ").map(_.toInt)

    val shifts = shiftingSort(an)

    println(shifts.length)
    println(shifts.map { case (l, r, d) => s"${l + 1} ${r + 1} $d" }.mkString("\n"))
  }
}

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

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

    case class myType(left: Int, right: Int, index: Int)extends Ordered[myType] {
        override def compare(that: myType): Int = {
            if (left < that.left || (left == that.left && right < that.right))
                return -1
            else if (left == that.left && right == that.right)
                return 0
            else
                return 1
        }
    }

    val t = readInt()
    for (tt <- 1 to t) {
        val n = readInt()
        val ans = new ArrayBuffer[(Int, Int, Int)]()
        val arr = new Array[Int](n)
        for (i <- 1 to n)
            arr(i-1) = readInt()
        for (i <- 0 until n) {
            var mm = arr(i)
            var po = i
            for (j <- i until n)
                if (arr(j) < mm) {
                    mm = arr(j)
                    po = j
                }
            if (po != i) {
                ans.append((i+1, po+1, po-i))
                for (j <- i until po)
                    arr(j+1) = arr(j)
                arr(i) = mm
            }
        }
        writer.println(ans.length)
        for (mv <- ans)
            writer.println(mv._1 + " " + mv._2 + " " + mv._3)
    }
    writer.flush()
}


import java.io.BufferedWriter
import java.io.OutputStreamWriter
import java.util.StringTokenizer

import scala.util.Try

object G extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val t = int()
  val k = int()
  read()
  val a = 1 +: Array.fill(t)(int()) :+ 0

  Try {
    val kmin = (0 to t).foldLeft(0)((sum, i) => sum + Math.max(0, a(i)-a(i+1)))
    assert(kmin <= k)
    var dk = k - kmin

    val lines = new Array[Int](n+1)
    val heads = new Array[Int](t+1)
    var j = 1
    for (i <- 0 to t) {
      heads(i) = j
      j += a(i)
    }
    var l = 0
    for (i <- 1 to n) {
      if (heads(l) + a(l) <= i) l += 1
      lines(i) = l
    }

    val links = new Array[Int](n+1)
    for (i <- 2 to n) {
      l = lines(i)
      if (i == heads(l)) {
        links(i) = heads(l-1)
      } else {
        val z = i - heads(l) + heads(l - 1)
        val onPrev = lines(z) == l - 1
        if (dk > 0) {
          links(i) = heads(l-1)
          if (onPrev) dk -= 1
        } else {
          if (onPrev) links(i) = z
          else links(i) = heads(l-1)
        }
      }
    }
    assert(dk == 0)

    val out = new BufferedWriter(new OutputStreamWriter(System.out))
    out.write(n + "\n")
    for (i <- 2 to n) out.write(links(i) + " " + i + "\n")
    out.close()

  }.getOrElse(println(-1))
}

import java.util.StringTokenizer

import scala.util.Try

object G extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val t = int()
  val k = int()
  read()
  val a = 1 +: Array.fill(t)(int()) :+ 0

  Try {
    val kmin = (0 to t).foldLeft(0)((sum, i) => sum + Math.max(0, a(i)-a(i+1)))
    assert(kmin <= k)
    var dk = k - kmin

    val lines = new Array[Int](n+1)
    val heads = new Array[Int](t+1)
    var j = 1
    for (i <- 0 to t) {
      heads(i) = j
      j += a(i)
    }
    var l = 0
    for (i <- 1 to n) {
      if (heads(l) + a(l) <= i) l += 1
      lines(i) = l
    }

    val links = new Array[Int](n+1)
    for (i <- 2 to n) {
      l = lines(i)
      if (i == heads(l)) {
        links(i) = heads(l-1)
      } else {
        val z = i - heads(l) + heads(l - 1)
        val onPrev = lines(z) == l - 1
        if (dk > 0) {
          links(i) = heads(l-1)
          if (onPrev) dk -= 1
        } else {
          if (onPrev) links(i) = z
          else links(i) = heads(l-1)
        }
      }
    }
    assert(dk == 0)

    println(n)
    for (i <- 2 to n) println(links(i) + " " + i)

  }.getOrElse(println(-1))
}

import java.io.PrintWriter
import java.util.StringTokenizer

import scala.util.Try

object G extends App {
  val INF = 1 << 30
  var st: StringTokenizer = _
  def read() = { st = new StringTokenizer(readLine()) }
  def int() = st.nextToken().toInt

  read()
  val n = int()
  val t = int()
  val k = int()
  read()
  val a = 1 +: Array.fill(t)(int()) :+ 0

  Try {
    val kmin = (0 to t).foldLeft(0)((sum, i) => sum + Math.max(0, a(i)-a(i+1)))
    assert(kmin <= k)
    var dk = k - kmin

    val lines = new Array[Int](n+1)
    val heads = new Array[Int](t+1)
    var j = 1
    for (i <- 0 to t) {
      heads(i) = j
      j += a(i)
    }
    var l = 0
    for (i <- 1 to n) {
      if (heads(l) + a(l) <= i) l += 1
      lines(i) = l
    }

    val links = new Array[Int](n+1)
    for (i <- 2 to n) {
      l = lines(i)
      if (i == heads(l)) {
        links(i) = heads(l-1)
      } else {
        val z = i - heads(l) + heads(l - 1)
        val onPrev = lines(z) == l - 1
        if (dk > 0) {
          links(i) = heads(l-1)
          if (onPrev) dk -= 1
        } else {
          if (onPrev) links(i) = z
          else links(i) = heads(l-1)
        }
      }
    }
    assert(dk == 0)

    val out = new PrintWriter(System.out)
    out.println(n)
    for (i <- 2 to n) out.println(links(i) + " " + i)
    out.close()

  }.getOrElse(println(-1))
}


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

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

    def main(args: Array[String]): Unit = {
        val t = readInt()
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = readInt()
            s = readString()
            for (i <- 0 until s.length) {
                if (s(i) == 'U')
                    writer.print('D')
                else if (s(i) == 'D')
                    writer.print('U')
                else if (s(i) == 'L')
                    writer.print('L')
                else writer.print('R')
            }
            writer.flush()
            println()
        }
    }
}

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

object test {
    class FastReader() {
        br = new BufferedReader(new InputStreamReader(System.in))
        var br: BufferedReader = _
        var st: StringTokenizer = _

        def next: String = {
            while ( {
                st == null || !st.hasMoreElements
            }) try st = new StringTokenizer(br.readLine)
            catch {
                case e: IOException =>
                    e.printStackTrace()
            }
            st.nextToken
        }

        def nextInt: Int = next.toInt

        def nextLong: Long = next.toLong

        def nextDouble: Double = next.toDouble

        def nextLine: String = {
            var str = ""
            try str = br.readLine
            catch {
                case e: IOException =>
                    e.printStackTrace()
            }
            str
        }
    }

    def main(args: Array[String]): Unit = {
        val fastReader = new test.FastReader
        val t = fastReader.nextInt
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = fastReader.nextInt
            s = fastReader.nextLine
            for (i <- 0 until s.length) {
                if (s(i) == 'U')
                    print('D')
                else if (s(i) == 'D')
                    print('U')
                else if (s(i) == 'L')
                    print('L')
                else print('R')
            }
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val t = readInt()
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = readInt()
            s = readLine()
            for (i <- 0 until s.length) {
                if (s(i) == 'U')
                    print('D')
                else if (s(i) == 'D')
                    print('U')
                else if (s(i) == 'L')
                    print('L')
                else print('R')
            }
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val t = readInt()
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = readInt()
            s = readLine()
            for (x <- s) {
                if (x == 'U')
                    print('D')
                else if (x == 'D')
                    print('U')
                else if (x == 'L')
                    print('L')
                else print('R')
            }
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val mp = Map('U' -> 'D', 'D' -> 'U', 'L' -> 'L', 'R' -> 'R')
        val t = readInt()
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = readInt()
            s = readLine()
            for (i <- s)
                print(mp(i))
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val mp = Map('U' -> 'D', 'D' -> 'U', 'L' -> 'L', 'R' -> 'R')
        val t = readInt()
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = readInt()
            s = readLine()
            for (i <- 0 until s.length)
                print(mp(s(i)))
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val mp = Map('U' -> 'D', 'D' -> 'U', 'L' -> 'L', 'R' -> 'R')
        val t = readInt()
        for (tt <- 1 to t) {
            val n = readInt()
            val s = readLine()
            for (i <- 0 until s.length)
                print(mp(s(i)))
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val mp = Map('U' -> 'D', 'D' -> 'U', 'L' -> 'L', 'R' -> 'R')
        var t = readInt()
        for (tt <- 1 to t) {
            var n = readInt()
            var s = readLine()
            for (i <- 0 until s.length)
                print(mp(s(i)))
            println()
        }
    }
}

object A extends App {

  def grid(row: String): String =
    row.map {
      case 'U' => 'D'
      case 'D' => 'U'
      case 'L' => 'L'
      case 'R' => 'R'
    }

  import scala.io.StdIn._

  val t = readInt()

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

    println(grid(s))
  }

}

import java.io._
import java.util.StringTokenizer
import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer
import scala.util.Sorting.quickSort
import util.control.Breaks._

object Solution {
    val writer =  new PrintWriter(System.out)
    val reader = new BufferedReader(new InputStreamReader(System.in))
    var st = new StringTokenizer("")
    def next(): String = {
        while (!st.hasMoreTokens) {
            st = new StringTokenizer(reader.readLine())
        }
        st.nextToken()
    }

    def readInt() = next.toInt
    def readLong() = next.toLong
    def readString() = next()

    def pow(a: Int, b: Int): Long = {
        if (b == 0) return 1

        val rs = pow(a, b / 2)
        rs * rs * (if (b % 2 == 0) 1 else a)
    }

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

    def LCM(a: Int, b: Int): Int = (a / GCD(a,b)) * b

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

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

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

    def solve(t: Int = 0): Unit = {
        val n = readInt()
        val s = readString()
        for (i <- 0 until n ) {
            if (s(i) == 'U')
                writer.print('D')
            else if (s(i) == 'D')
                writer.print('U')
            else writer.print(s(i))
        }

        writer.println()

    }

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

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

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

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

    def main(args: Array[String]): Unit = {
        val t = readInt()
        var n = 0
        var s = ""
        for (tt <- 1 to t) {
            n = readInt()
            s = readString()
            for (i <- 0 until s.length) {
                if (s(i) == 'U')
                    writer.print('D')
                else if (s(i) == 'D')
                    writer.print('U')
                else if (s(i) == 'L')
                    writer.print('L')
                else writer.print('R')
            }
            println()
        }
    }
}

import scala.io.StdIn._

object test {
    def main(args: Array[String]): Unit = {
        val mp = Map('U' -> 'D', 'D' -> 'U', 'L' -> 'R', 'R' -> 'L')
        var t = readInt()
        for (tt <- 1 to t) {
            var n = readInt()
            var s = readLine()
            for (i <- 0 until s.length)
                print(mp(s(i)))
            println()
        }
    }
}


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

    val n=readLine.toInt
    //arcs
    val arcs=new Array[Set[Int]](n);
    (0 to n-1).foreach(i=> arcs(i)=Set())

    (1 to 2*n).foreach{i=>
      val (a,b)={
        val sp=readLine.split(" ")
        (sp(0).toInt-1 , sp(1).toInt-1)
      }
      arcs(a)+=b
      arcs(b)+=a
    }//arc

    if(arcs.count(_.size!=4)>0){
      //NG
      println(-1)
      return
    }

    //check
    def check(p:List[Int]):Boolean={
      if(p.length!=n){
        false
      }else{
        val ap=p.toArray
        val arcs2=new Array[Set[Int]](n);
        (0 until n).foreach{i=>
          arcs2(ap(i))=Set(-2,-1,1,2).map{ii=>ap((i+ii+n)%n)}
        }
        //ret
        (0 to n-1).forall{i=>
          arcs(i)==arcs2(i)
        }
      }
    }

    //p or null
    val p=
      if(n<=6){
        //全pをcheck
        (0 until n).permutations.map(_.toList).find(check(_)).orNull

      }else{
        //pp
        val pp:List[Int]={
          val done=new Array[Boolean](n)
          val l=scala.collection.mutable.ListBuffer[Int]()

          def rec(now:Int){
            done(now)=true
            def neighbor(a:Int, b:Int):Boolean={
              (arcs(a)&arcs(b)).size==2
            }
            val nbopt=arcs(now).find{a=> !done(a)&&neighbor(a,now)}
            l+=now
            if(nbopt.isDefined){
              rec(nbopt.get)
            }
          }
          rec(0)
          l.toList
        }//pp

        if(check(pp)) pp else null
      }//p

    println(if(p==null) -1 else p.map(_ +1).mkString(" "))//end
  }
}

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

    val n=readLine.toInt
    //arcs
    val arcs=new Array[Set[Int]](n);
    (0 to n-1).foreach(i=> arcs(i)=Set())

    (1 to 2*n).foreach{i=>
      val (a,b)={
        val sp=readLine.split(" ")
        (sp(0).toInt-1 , sp(1).toInt-1)
      }
      arcs(a)+=b
      arcs(b)+=a
    }//arc

    if(arcs.count(_.size!=4)>0){
      //NG
      println(-1)
      return
    }

    //check
    def check(p:List[Int]):Boolean={
      if(p.length!=n){
        false
      }else{
        val ap=p.toArray
        val arcs2=new Array[Set[Int]](n);
        (0 until n).foreach{i=>
          arcs2(ap(i))=Set(-2,-1,1,2).map{ii=>ap((i+ii+n)%n)}
        }
        //ret
        (0 to n-1).forall{i=>
          arcs(i)==arcs2(i)
        }
      }
    }

    //p or null
    val p=
      if(n<=6){
        //全pをcheck
        (0 until n).permutations.map(_.toList).find(check(_)).orNull

      }else{
        val done=new Array[Boolean](n)
        //pp
        val pp={
          def rec(now:Int,l:List[Int]):List[Int]={
            done(now)=true
            def neighbor(a:Int, b:Int):Boolean={
              (arcs(a)&arcs(b)).size==2
            }
            val nbopt=arcs(now).find{a=> !done(a)&&neighbor(a,now)}
            if(nbopt.isEmpty){
              now::l
            }else{
              rec(nbopt.get,now::l)
            }
          }
          rec(0,Nil)
        }//pp

        if(check(pp)) pp else null
      }//p

    println(if(p==null) -1 else p.map(_ +1).mkString(" "))//end
  }
}

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

    val n=readLine.toInt
    //arcs
    val arcs=new Array[Set[Int]](n);
    (0 to n-1).foreach(i=> arcs(i)=Set())

    (1 to 2*n).foreach{i=>
      val (a,b)={
        val sp=readLine.split(" ")
        (sp(0).toInt-1 , sp(1).toInt-1)
      }
      arcs(a)+=b
      arcs(b)+=a
    }//arc

    if(arcs.count(_.size!=4)>0){
      //NG
      println(-1)
      return
    }

    //check
    def check(p:List[Int]):Boolean={
      if(p.length!=n){
        false
      }else{
        val ap=p.toArray
        val arcs2=new Array[Set[Int]](n);
        (0 until n).foreach{i=>
          arcs2(ap(i))=Set(-2,-1,1,2).map{ii=>ap((i+ii+n)%n)}
        }
        //ret
        (0 to n-1).forall{i=>
          arcs(i)==arcs2(i)
        }
      }
    }

    //p or null
    val p=
      if(n<=6){
        //全pをcheck
        (0 until n).permutations.map(_.toList).find(check(_)).orNull

      }else{
        val done=new Array[Boolean](n)
        //pp
        val pp={
          def rec(now:Int,l:List[Int]):List[Int]={
            def neighbor(a:Int, b:Int):Boolean={
              (arcs(a)&arcs(b)).size==2
            }
            val nbopt=arcs(now).find{a=> !done(a)&&neighbor(a,now)}
            if(nbopt.isEmpty){
              now::l
            }else{
              done(nbopt.get)=true
              rec(nbopt.get,now::l)
            }
          }
          rec(0,Nil)
        }//pp

        if(check(pp)) pp else null
      }//p

    println(if(p==null) -1 else p.map(_ +1).mkString(" "))//end
  }
}


import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)

  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o2.compareTo(o1)
      else c
    }
  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (minD > diff || maxD > diff) {
        recordResult()
        if (maxD > diff) {
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        }
        if (minD > diff) {
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        if (!ordMin.isEmpty && books(ordMin.last()) == books(i)) ordMin.pollLast()
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        if (!ordMin.isEmpty && books(ordMin.last()) == books(i)) ordMin.pollLast()
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

object P6E {
    class SegTree(m : Int, k : Int) {
        val s = 1 << Math.getExponent(m.toFloat) + 1
        val a = Array.fill(s + s){0}
        var time = 1
        def op(n : Int) = {
            def f(d : Int)(n : Int) {
                var i = s + n
                while (i > 1) {
                    val c = i ^ 1
                    val p = i >>> 1
                    if ((i & 1) == d) a(c) = time
                    a(p) = a(i) min a(c) max a(p)
                    i = p
                }
            }
            f(1)(n - k max 0)
            f(0)(n)
            val timeP = time
            time = time + 1
            timeP - a(1)
        }
    }

    def main(args : Array[String]) {
        val Array(n, k) = readLine split ' ' map {_.toInt}
        val h = readLine split ' ' map {_.toInt}
        val st = new SegTree(h.max + 1, k)
        val s = for (hi <- h) yield st op hi
        val s1 = s.max
        val r = for {
            i <- 0 until n
            if (s(i) == s1)
        } yield i + 1
        println(s1 + " " + r.size)
        for (i <- r) println(i - s1 + 1 + " " + i)
    }
}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)

  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o2.compareTo(o1)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff)
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (maxD > diff)
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

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

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt).toArray

  val deq = new java.util.LinkedList[Int]()
  var min = 0
  var max = 0
  deq.add(0)

  (1 until num) foreach { i =>
    val elem = books(i)
    val minD = math.abs(elem - books(min))
    val maxD = math.abs(elem - books(max))
    if (minD > diff) {
      recordResult()
      while (deq.getFirst != min) deq.removeFirst()
      deq.removeFirst()
      deq.addLast(i)
      findMin()
      findMax()
    } else if (maxD > diff) {
      recordResult()
      while (deq.getFirst != max) deq.removeFirst()
      deq.removeFirst()
      deq.addLast(i)
      findMin()
      findMax()
    } else {
      if (books(min) >= elem) min = i
      if (books(max) <= elem) max = i
      deq.addLast(i)
    }
  }
  recordResult()

  def findMin(): Unit = {
    var i = 0
    min = 0
    while (i < deq.size()) {
      if (books(deq.get(i)) <= books(min)) min = i
      i += 1
    }
  }

  def findMax(): Unit = {
    var i = 0
    max = 0
    while (i < deq.size()) {
      if (books(deq.get(i)) >= books(max)) max = i
      i += 1
    }
  }

  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._1 + " " + item._2)
  })

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)

  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o1.compareTo(o2)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      //if (!ordMin.isEmpty) println(books(ordMin.first()) + " " + books(ordMin.last()) + " ")
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff)
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (maxD > diff)
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

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

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt).toArray

  val deq = new java.util.LinkedList[Int]()
  var min = 0
  var max = 0
  deq.add(0)

  (1 until num) foreach { i =>
    val elem = books(i)
    val minD = math.abs(elem - books(min))
    val maxD = math.abs(elem - books(max))
    if (minD > diff) {
      recordResult()
      while (deq.getFirst != min) deq.removeFirst()
      deq.removeFirst()
      deq.addLast(i)
      findMin()
      findMax()
    } else if (maxD > diff) {
      recordResult()
      while (deq.getFirst != max) deq.removeFirst()
      deq.removeFirst()
      deq.addLast(i)
      findMin()
      findMax()
    } else {
      if (books(min) >= elem) min = i
      if (books(max) <= elem) max = i
      deq.addLast(i)
    }
  }
  recordResult()

  def findMin(): Unit = {
    var i = 0
    min = deq.getLast
    while (i < deq.size()) {
      if (books(deq.get(i)) <= books(min)) min = deq.get(i)
      i += 1
    }
  }

  def findMax(): Unit = {
    var i = 0
    max = deq.getLast
    while (i < deq.size()) {
      if (books(deq.get(i)) >= books(max)) max = deq.get(i)
      i += 1
    }
  }

  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._1 + " " + item._2)
  })

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = 10
  val diff = 1
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => Random.nextInt(3) + 1)
  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o2.compareTo(o1)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (!ordMin.isEmpty) {
        println(ordMin.first() + " " + ordMin.last() + " " + books(ordMin.first()) + " " + books(ordMin.last()) + " ")

      }
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff) {
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        } else if (maxD > diff) {
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

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

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt).toArray

  val deq = new java.util.LinkedList[Int]()

  deq.add(0)

  (1 until num) foreach { i =>
    val elem = books(i)
    val headDiff = math.abs(elem - books(deq.getFirst))
    val lastDiff = math.abs(elem - books(deq.getLast))
    if (headDiff > diff) {
      recordResult()
      deq.clear()
      deq.addFirst(i)
    } else if (lastDiff <= diff) {
      deq.addFirst(i)
    } else {
      recordResult()
      while (math.abs(elem - books(deq.getLast)) > diff) deq.removeLast()
      deq.addFirst(i)
    }
  }
  recordResult()

  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)

  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o2.compareTo(o1)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      //if (!ordMin.isEmpty) println(books(ordMin.first()) + " " + books(ordMin.last()) + " ")
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff)
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (maxD > diff)
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

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

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt).toArray

  val deq = new java.util.LinkedList[Int]()
  var min = 0
  var max = 0
  deq.add(0)

  (1 until num) foreach { i =>
    val elem = books(i)
    val minD = math.abs(elem - books(min))
    val maxD = math.abs(elem - books(max))
    if (minD > diff) {
      recordResult()
      while (deq.getLast != min) deq.removeLast()
      deq.removeFirst()
      deq.addLast(i)
      findMin()
      findMax()
    } else if (maxD > diff) {
      recordResult()
      while (deq.getLast != max) deq.removeLast()
      deq.removeFirst()
      deq.addLast(i)
      findMin()
      findMax()
    } else {
      if (books(min) >= elem) min = i
      if (books(max) <= elem) max = i
      deq.addLast(i)
    }
  }
  recordResult()

  def findMin(): Unit = {
    var i = 0
    min = deq.getLast
    while (i < deq.size()) {
      if (books(deq.get(i)) <= books(min)) min = deq.get(i)
      i += 1
    }
  }

  def findMax(): Unit = {
    var i = 0
    max = deq.getLast
    while (i < deq.size()) {
      if (books(deq.get(i)) >= books(max)) max = deq.get(i)
      i += 1
    }
  }

  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._1 + " " + item._2)
  })

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)

  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = books(o1).compareTo(books(o2))
  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff)
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (maxD > diff)
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)
  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o2.compareTo(o1)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (minD > diff || maxD > diff) {
        recordResult()
        if (maxD > diff) {
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        }
        if (minD > diff) {
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)

  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o1.compareTo(o2)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff)
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (maxD > diff)
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}

import java.util
import java.util.Comparator
import java.util.Scanner
import scala.collection.mutable.ArrayBuffer
import scala.util.Random

object EBooks extends App {

  val scanner = new Scanner(System.in)

  val num = scanner.nextInt()
  val diff = scanner.nextInt()
  var cnt = 0
  val buf = ArrayBuffer.empty[(Int, Int)]
  val books = (0 until num).map(i => scanner.next().toInt)
  val ordMin = new util.TreeSet[Int](new Comparator[Int] {
    override def compare(o1: Int, o2: Int): Int = {
      val c = books(o1).compareTo(books(o2))
      if (c == 0) o2.compareTo(o1)
      else c
    }

  })

  val deq = new java.util.LinkedList[Int]()
  deq.add(0)
  ordMin.add(0)

  (1 until num) foreach {
    i =>
      val elem = books(i)
      val minD = math.abs(elem - books(ordMin.first()))
      val maxD = math.abs(elem - books(ordMin.last()))
      if (minD > diff || maxD > diff) {
        recordResult()
        if (minD > diff) {
          while (deq.getLast != ordMin.first()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        } else if (maxD > diff) {
          while (!deq.isEmpty && deq.getLast != ordMin.last()) {
            ordMin.remove(deq.getLast)
            deq.removeLast()
          }
        }
        if (!deq.isEmpty) {
          ordMin.remove(deq.getLast)
          deq.removeLast()
        }
        deq.addFirst(i)
        ordMin.add(i)
      } else {
        deq.addFirst(i)
        ordMin.add(i)
      }
  }
  recordResult()
  println(cnt + " " + buf.size)
  buf.foreach(item => {
    println(item._2 + " " + item._1)
  })
  System.exit(0)

  def recordResult(): Unit = {
    if (deq.size() > cnt) {
      cnt = deq.size()
      buf.clear()
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    } else if (deq.size() == cnt) {
      buf += ((deq.getFirst + 1, deq.getLast + 1))
    }
  }

}