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

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

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

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val A = map(N)(_ => sc.nextInt())
    val M = Array.fill[mutable.Map[Int, Int]](11)(mutable.Map() withDefaultValue 0)
    val len = Array.ofDim[Int](N)

    val pow = Array.ofDim[Long](11)
    pow(0) = 1
    rep(10) { i => pow(i + 1) = pow(i) * 10 % K}

    def digits(x: Int): Int = {
      var d = 0
      var a = x
      while(a > 0) { a /= 10; d += 1}
      d
    }

    rep(N) { i =>
      val m = A(i) % K
      val d = digits(A(i))
      len(i) = d
      M(d)(m) = M(d)(m) + 1
    }

    var ans = 0L
    rep(N) { i =>
      rep(11) { d =>
        val m = (pow(d) * A(i) % K).toInt
        val r = if (m == 0) 0 else K - m
        ans += M(d)(r)
        if (d == len(i) && r == A(i) % K) ans -= 1
      }
    }

    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

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

object D extends App {

  def countLen(x: Long): Int = {
    var l = 0
    var xx = x
    while (xx > 0) {
      xx = xx / 10
      l += 1
    }
    l
  }

  def solve(in: InputReader): Unit = {
    val n = in.nextInt
    val k = in.nextLong
    val a = Array.fill(n)(in.nextLong)
    val map = scala.collection.mutable.Map[(Long, Int), Int]()
    a.foreach { v =>
      val key = (v % k, countLen(v))
      //println(key)
      map += key -> (map.getOrElse(key, 0) + 1)
    }
    var ans: Long = 0
    for {v <- a
         i <- 1 to 10
    } {
      //println((k - v * math.pow(10, i).toLong % k) % k -> i)
      ans += map.getOrElse((k - (v % k) * (math.pow(10, i) % k).toLong % k) % k -> i
        , 0
      )
    }
    //println(ans)
    a.foreach { v =>
      if (((v % k) + (v % k) * (math.pow(10, countLen(v)) % k)) % k == 0)
        ans -= 1
    }
    println(ans)
  }

  solve(new InputReader(System.in))

  private class InputReader(val in: InputStream) {

    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))
    private var tokenizer: StringTokenizer = _

    def nextInt: Int = {
      next.toInt
    }

    def nextDouble: Double = {
      next.toInt
    }

    def nextLong: Long = {
      next.toInt
    }

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

    def readLine: String = {
      try {
        reader.readLine()
      } catch {
        case e: IOException => throw new RuntimeException(e)
      }
    }
  }

}

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

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

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

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val A = map(N)(_ => sc.nextInt())
    val M = Array.fill[mutable.Map[Int, Int]](11)(mutable.Map() withDefaultValue 0)

    val pow = Array.ofDim[Long](11)
    pow(0) = 1
    rep(10) { i => pow(i + 1) = pow(i) * 10}

    def digits(x: Int): Int = x.toString.length

    rep(N) { i =>
      rep(11) { j =>
        val m = (pow(j) * A(i) % K).toInt
        M(j)(m) = M(j)(m) + 1
      }
    }

    var ans = 0L
    rep(N) { i =>
      val d = digits(A(i))
      val m = (K - A(i) % K) % K
      ans += M(d)(m)
      if (pow(d) * A(i) % K == m) ans -= 1
    }

    out.println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

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

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

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

  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N, K = sc.nextInt()
    val A = map(N)(_ => sc.nextInt())
    val M = Array.ofDim[Int](11, K)

    def digits(x: Int): Int = x.toString.length

    rep(N) { i =>
      rep(11) { j =>
        M(j)((A(i).toLong * pow(10, j) % K).toInt) += 1
      }
    }

    var ans = 0L
    rep(N) { i =>
      val d = digits(A(i))
      val m = (K - A(i) % K) % K
      ans += M(d)(m)
      if (pow(10, d) * A(i) % K == m) ans -= 1
    }

//    case class Seg(l: Int, r: Int) {
//      def length: Int = r - l
//    }
//    val S = map(N) { _ =>
//      val l, r = sc.nextInt()
//      Seg(l, r)
//    }
//
//    def intersect(s1: Seg, s2: Seg): Seg = {
//      Seg(max(s1.l, s2.l), min(s1.r, s2.r))
//    }
//
//    def merge(s1: Seg, s2: Seg): Seg = {
//      ???
//    }
//
//    val ms = S reduce intersect
//    var mx = 0
//    rep(N) { i =>
//      mx = max(mx, merge(S(i), ms).length)
//    }

    out.println(ans)
  }

  def pow(x: Int, n: Int): Int = {
    n match {
      case 0 => 1
      case _ =>
        val r = pow(x * x, n / 2)
        if (n % 2 == 1) r * x else r
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
    out.flush()
  }

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

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

  implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    // todo Orderingだとboxing発生するので自作Orderを用意したい
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(as.length)(i => map.getOrElseUpdate(f(as(i)), ArrayBuffer()) += as(i))
      map
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(as.length)(i => sum = num.plus(sum, f(as(i))))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}

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

object D extends App {

  def countLen(x: Long): Int = {
    var l = 0
    var xx = x
    while (xx > 0) {
      xx = xx / 10
      l += 1
    }
    l
  }

  def solve(in: InputReader): Unit = {
    val n = in.nextInt
    val k = in.nextLong
    val a = Array.fill(n)(in.nextLong)
    val map = scala.collection.mutable.Map[(Long, Int), Int]()
    a.foreach { v =>
      val key = (v % k, countLen(v))
      //println(key)
      map += key -> (map.getOrElse(key, 0) + 1)
    }
    var ans: Long = 0
    for {v <- a
         i <- 1 to 10
    } {
      //println(map.get((k - v * math.pow(10, i).toLong % k -> i))
      ans += map.getOrElse((k - v * math.pow(10, i).toLong % k) % k -> i, 0)
    }
    //println(ans)
    a.foreach { v =>
      if ((v + v * math.pow(10, countLen(v))) % k == 0)
        ans -= 1
    }
    println(ans)
  }

  solve(new InputReader(System.in))

  private class InputReader(val in: InputStream) {

    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))
    private var tokenizer: StringTokenizer = _

    def nextInt: Int = {
      next.toInt
    }

    def nextDouble: Double = {
      next.toInt
    }

    def nextLong: Long = {
      next.toInt
    }

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

    def readLine: String = {
      try {
        reader.readLine()
      } catch {
        case e: IOException => throw new RuntimeException(e)
      }
    }
  }

}

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

object D extends App {

  def countLen(x: Long): Int = {
    var l = 0
    var xx = x
    while (xx > 0) {
      xx = xx / 10
      l += 1
    }
    l
  }

  def solve(in: InputReader): Unit = {
    val n = in.nextInt
    val k = in.nextLong
    val a = Array.fill(n)(in.nextLong)
    val map = scala.collection.mutable.Map[(Long, Int), Int]()
    a.foreach { v =>
      val key = (v % k, countLen(v))
      //println(key)
      map += key -> (map.getOrElse(key, 0) + 1)
    }
    var ans: Long = 0
    for {v <- a
         i <- 1 to 10
    } {
      //println((k - v * math.pow(10, i).toLong % k) % k -> i)
      ans += map.getOrElse((k - (v % k) * math.pow(10, i).toLong % k) % k -> i, 0)
    }
    //println(ans)
    a.foreach { v =>
      if (((v % k) + (v % k) * math.pow(10, countLen(v))) % k == 0)
        ans -= 1
    }
    println(ans)
  }

  solve(new InputReader(System.in))

  private class InputReader(val in: InputStream) {

    private val reader: BufferedReader = new BufferedReader(new InputStreamReader(in))
    private var tokenizer: StringTokenizer = _

    def nextInt: Int = {
      next.toInt
    }

    def nextDouble: Double = {
      next.toInt
    }

    def nextLong: Long = {
      next.toInt
    }

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

    def readLine: String = {
      try {
        reader.readLine()
      } catch {
        case e: IOException => throw new RuntimeException(e)
      }
    }
  }

}


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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(h, w) = readLine().split(" ").map(_.toInt)

    (1 to h).foreach {
      case i if i == 1 || i == h   => println((1 to w).map(_ % 2).mkString(""))
      case i if i > 2 && i < h - 1 => println(s"${i % 2}${"0" * (w - 2)}${i % 2}")
      case _                       => println("0" * w)
    }
    println()
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(h, w) = readLine().split(" ").map(_.toInt)

    (1 to h).foreach {
      case i if i == 1 || i == h   =>
        val row = (1 to w).map(_ % 2).mkString("")
        println(row)
      case i if i > 2 && i < h - 1 =>
        val row = s"${i % 2}" + "0" * (w - 2) + s"${i % 2}"
        println(row)
      case _                       => println("0" * w)
    }
    println()
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(h, w) = readLine().split(" ").map(_.toInt)

    (0 until h).foreach { i =>
      val row = (0 until w).map {
        case j if i == 0 || i == h - 1                         => (j + 1) % 2
        case j if (j == 0 || j == w - 1) && i > 1 && i < h - 2 => (i + 1) % 2
        case _                                                 => 0
      }
      println(row.mkString(""))
    }
    println()
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(h, w) = readLine().split(" ").map(_.toInt)

    (1 to h).foreach {
      case i if i == 1 || i == h   =>
        val row = (1 to w).map(_ % 2).mkString("")
        println(row)
      case i if i > 2 && i < h - 1 =>
        val row = "s${i % 2}" + "0" * (w - 2) + "s${i % 2}"
        println(row)
      case _                       => println("0" * w)
    }
    println()
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(h, w) = readLine().split(" ").map(_.toInt)

    (1 to h).foreach {
      case i if i == 1 || i == h   => (1 to w).map(_ % 2).mkString("")
      case i if i > 2 && i < h - 1 => "s${i % 2}" + "0" * (w - 2) + "s${i % 2}"
      case _                       => "0" * 2
    }
    println()
  }
}


object B extends App {
  def remove(input: String): String = {
    lazy val singles  = input.collectFirst { case char @ ('1' | '4' | '6' | '8' | '9') => char.toString }
    lazy val pairs    = input.tail.collectFirst { case char @ ('2' | '5') => s"${input.head}$char" }
    lazy val doubles  = input.groupBy(identity).collectFirst { case (char, slice) if slice.length > 1 => s"$char$char" }
    lazy val specials = s"${input.head}7"

    singles getOrElse (pairs getOrElse (doubles getOrElse specials))
  }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val k      = readInt()
    val number = readLine()

    val output = remove(number)

    println(output.length)
    println(output)
  }

}

object B extends App {
  def remove(input: String): String =
    input.collectFirst { case char @ ('1' | '4' | '6' | '8' | '9') => char.toString } getOrElse {
      input.tail.collectFirst { case char @ ('2' | '5') => s"${input.head}$char" } getOrElse {
        input.groupBy(identity).collectFirst { case (char, slice) if slice.length > 1 => s"$char$char" } getOrElse {
          input.head match {
            case '2' => "27"
            case '5' => "57"
          }
        }
      }
    }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val k      = readInt()
    val number = readLine()

    val output = remove(number)

    println(s"${output.length}\n$output")
  }

}

object B extends App {
  def remove(input: String): String =
    input.head match {
      case char @ ('1' | '4' | '6' | '8' | '9') => char.toString
      case _                                    =>
        input.contains('1') match {
          case true => "1"
          case _    =>
            input.tail.indexWhere { char =>
              val digit = char - 48
              digit == 5 || digit % 2 == 0
            } match {
              case i if i >= 0 => input.take(i + 2)
              case _           =>
                input.groupBy(_ - 48).collectFirst {
                  case (digit, slice) if slice.length > 1 => s"$digit$digit"
                } match {
                  case Some(output) => output
                  case _            => input.take(input.indexOf('7') + 1)
                }
            }
        }

    }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val k      = readInt()
    val number = readLine()

    val output = remove(number)

    println(s"${output.length}\n$output")
  }

}

object B extends App {
  def remove(input: String): String =
    input.head match {
      case char @ ('1' | '4' | '6' | '8' | '9') => char.toString
      case _                                    =>
        input.contains('1') match {
          case true => "1"
          case _    =>
            input.tail.indexWhere { char =>
              val digit = char - 48
              digit == 5 || digit % 2 == 0
            } match {
              case i if i >= 0 => input.take(i + 2)
              case _           =>
                input.groupBy(_ - 48).collectFirst {
                  case (digit, slice) if slice.length > 1 => s"$digit$digit"
                } match {
                  case Some(output) => output
                  case _            => input.take(input.indexOf('7') + 1)
                }
            }
        }

    }

  import scala.io.StdIn._

  val t = readInt()

  (0 until t).foreach { _ =>
    val k      = readInt()
    val number = readLine()

    val output = remove(number)

    println(output.length)
    println(output)
  }

}


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

object Solution {
  def solve(arr: Array[Int]): Long = {
    val sum = arr.sum.toLong
    val count = arr.length.toLong

    if (sum == count) 0 else {
      // if sum < count then just add one more number with count-sum+1

      // you want to add (count-sum+1)
      // sum goes to sum+(count-sum+1)=count+1, and count goes to count+1
      // count-sum+1 >= 0, count >= sum-1
      if (count >= sum-1) 1 else {
        // count < sum-1
        // so we need to add a lot of zeros...
        // k zeros so (count+k) = sum => k = sum-count
        sum-count
      }
    }
  }

  def run(input: Scanner, output: PrintWriter): Unit = {
    val tests = input.nextInt()

    (1 to tests).foreach { test =>
      val n = input.nextInt()
      output.println(solve((1 to n).map { _ => input.nextInt() }.toArray))
    }

    output.flush()
  }

  def main(args: Array[String]): Unit = {
    run(new Scanner(System.in), new PrintWriter(System.out))
  }
}

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

  val t = readInt()

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

    val ans =
      if (n < asum) asum - n
      else if (n > asum) 1
      else 0

    println(ans)
  }
}

import scala.io.StdIn._

object Main {
  def main(args: Array[String]) {
    val t : Int = readInt()
    for (i <- Range(0,t)) {
      val n = readInt()
      val vec = readLine().split(" ").map(_.toInt)
      val sum = vec.sum
      if(sum == n) {
        println(0)
      } else if(sum > n) {
        println(sum - n)
      } else {
        println(1)
      }
    }
  }
}


object A extends App{
  val nk = readLine.split(" ").map(_.toInt)
  val nums = readLine.split(" ")
  println((nums.filter(_.filter(x=> x=='4' || x=='7').length <= nk(1))).length)
}

import scala.io._

object Test {
  def main(args: Array[String]): Unit = {
    val lines = Source.stdin.getLines().take(2).toArray
    val a = lines(0).split(' ').map(_.toInt)
    val (n,k) = (a(0), a(1))
    val ns = lines(1).split(' ').count(_.count(p => p=='4' || p=='7') <= k)
    println(ns)
  }

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  println(in.next().split(" ").map(_.count(ch => ch == '4' || ch == '7')).filter(_ <= k).size)

}

import java.util.Scanner

object Main extends App {
  def luckyCount(n : Int) = {
    var x = n
    var result = 0

    while(x != 0) {
      if(x % 10 == 4 || x % 10 == 7) result += 1
      x /= 10
    }

    result
  }

  val scanner = new Scanner(System.in)
  val n = scanner.nextInt()
  val k = scanner.nextInt()
  var answer = 0

  for(i <- 1 to n)
    if(luckyCount(scanner.nextInt) <= k)
      answer += 1

  println(answer)
}

object J {

  def main (args : Array[String]){
    var Array(n,k) = readLine.split(" ").map(_.toInt)
    var a = readLine.split(" ").map(_.toInt)
    var ans = 0;
    for (i <- a){
      var s = String.valueOf(i)
      var cnt = 0
      for (ch <- s){
        if (ch == '4' || ch == '7')cnt +=1
      }
      if (cnt<=k)ans += 1
    }
    println(ans)
  }

}

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

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

  val N, K = sc.nextInt

  def isLucky(c: Char): Boolean = c == '4' || c == '7'

  val answer = List.fill(N)(sc.nextInt).map(_.toString).filter { s =>
      s.filter(isLucky).size <= K
    }.size

  out.println(answer)
  out.close
}

import annotation.tailrec
import java.io._

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

  val Array(n, k) = readInts
  def ans = reader.readLine().split(" ").count(_.count("47".contains(_)) <= k)

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

object Main {
  def main(args: Array[String]) {
    val nk = readLine().split(" ").map(_.toInt)
    val n = nk(0)
    val k = nk(1)
    val a = readLine().split(" ")
    val r = a.count(_.count(c => c == '4' || c == '7') <= k)
    println(r)
  }
}

import scala.Math.pow;

object App {
	def readInts:Array[Int] = (readLine split " ") map (_.toInt)
                                                  //> readInts: => Array[Int]
	//def solve(s: java.lang.String, a:Int):Int = {
	//}                                         //> solve: (n: Int, m: Int, prev: Int, a: Int, b: Int)(Int, Int)

	def f1_io() = {
		val Array(n, k) = readInts
		val ans = (readLine split " ") map (x => (x filter(p => p == '4' || p == '7')).length)
		print((ans filter (p => p <= k)).length)
	}
  def main(args: Array[String]): Unit = {
	f1_io
  }

}

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

    //n,k
    val (n,k)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    //a,ans
    println(
      readLine.split(" ").toList.map({
          _.toList.filter(s=> s=='4'||s=='7').length
        })
        .filter({
          _<=k
        })
        //ans
        .length
    )
  }
}

import java.util

object Main {
  def lucky(n: Int, k: Int) = {
    var c = 0
    var x = n
    while (x != 0) {
      c += (x % 10 match {
        case 4 | 7 => 1
        case _ => 0
      })
      x = x / 10
    }
    c <= k
  }

  def main(args: Array[String]) {
    val n = readToken.toInt
    val k = readToken.toInt
    println((0 until n).filter(i => lucky(readToken.toInt, k)).size)
  }

  var st = new util.StringTokenizer("")
  def readToken() = {
    while (!st.hasMoreTokens) st = new java.util.StringTokenizer(readLine)
    st.nextToken
  }
}

object Codeforces extends App {
  val in = new java.util.Scanner(System.in)
  val n = in.nextInt()
  val k = in.nextInt()
  var cnt = 0
  for (i <- 0 until n) {
    var a = in.nextInt()
    var len = 0
    while (a > 0) {
      var b = a % 10
      a /= 10
      if (b == 4 || b == 7) {
        len += 1
      }
    }
    if (len <= k) {
      cnt += 1
    }
  }
  println(cnt)
}

object A extends App{
  val nk = readLine.split(" ").map(_.toInt)
  val nums = readLine.split(" ")
  println((nums.filter(cNum => cNum.filter(x=> x=='4' || x=='7').length < nk(0))).length)

}

object A extends App{
  // val in = io.Source//.stdin.getLines
  val nk = readLine.split(" ").map(_.toInt)
  val nums = readLine.split(" ")
  // println(n + " " + k)
  nums.foreach(println)
  println(nums.filter(_.length <= nk(1)).length)

}

object A extends App{
  // val in = io.Source//.stdin.getLines
  val nk = readLine.split(" ").map(_.toInt)
  val nums = readLine.split(" ")
  // println(n + " " + k)
  // nums.foreach(println)
  println(nums.filter(_.length <= nk(1)).length)

}


import java.util.StringTokenizer

object _548A extends App {
  var token = new StringTokenizer("")

  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }

  val s = next
  val k = next.toInt

  if (s.length % k != 0) println("NO")
  else {
    val a = s.grouped(s.length / k)

    def isPalindrome(s: String) = {
      def is(l: Int, r: Int): Boolean =
        if (l > r) true
        else if (s(l) == s(r)) is(l + 1, r - 1)
        else return false
      is(0, s.length - 1)
    }

    if (a.forall(isPalindrome)) println("YES")
    else println("NO")
  }
}

import scala.collection._

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

    var inLoop = true
    while (inLoop) {
      val words = scala.io.StdIn.readLine
      if (words != null) {
        var good = true
        val k = scala.io.StdIn.readLine.toInt

        if ((words.length % k) == 0) {
          val wordLen = words.length / k

          var i = 0
          var j = 0
          for (i <- 0 to (k - 1)) {
            val word = words.substring((i * wordLen), (i + 1) * wordLen)
            for (j <- 0 to (word.length / 2)) {
              if (word.charAt(j) != word.charAt(word.length - j - 1)) {
                good = false;
              }
            }
          }
        } else {
          good = false
        }

        if (good) println("YES") else println("NO")

      } else {

        inLoop = false
      }
    }
  }
}

import scala.math._
import scala.collection.mutable
import scala.util.control.Breaks
import scala.annotation.tailrec

object Problem extends App {
  import Scanner._
  def exit() = System.exit(0)

  val line = readLine
  val k = readInt
  val n = line.length

  if(n%k!=0) {
    println("NO")
    exit
  }

  val len = n/k

  for(i <- 0 until k; p <- 0 until len; if line(i*len+p) != line(i*len+len-p-1)) {
    println("NO")
    exit
  }

  println("YES")
}

object Scanner {
  def readInt() = {
    var acc = 0
    readWith {
      case c if c >= '0' && c <= '9' && (Int.MaxValue - acc) >= (c - '0') =>
        acc = (acc * 10) + (c - '0')
    }
    acc
  }
  def readLong() = {
    var acc = 0L
    readWith {
      case c if c >= '0' && c <= '9' && (Long.MaxValue - acc) >= (c - '0') =>
        acc = (acc * 10L) + (c - '0')
    }
    acc
  }
  def readDouble() = {
    var (acc, frac, fracPow, readFrac) = (0L, 0L, 1L, false)
    readWith {
      case c if c >= '0' && c <= '9' && !readFrac && (Long.MaxValue - acc) >= (c - '0') =>
        acc = (acc * 10) + (c - '0')
      case c if c >= '0' && c <= '9' && readFrac && (Long.MaxValue - frac) >= (c - '0') =>
        frac = (frac * 10) + (c - '0')
        fracPow *= 10
      case c if c == '.' && !readFrac =>
        readFrac = true
    }
    acc + (frac.toDouble / fracPow)
  }
  def readString() = {
    var string = new StringBuilder
    readWith { case c => string += c }
    string.toString
  }
  def readLine() = Console.in.readLine()
  def readChar() = Console.in.read().toChar
  def readWith(func: PartialFunction[Char, Unit]) {
    val handler = func orElse[Char, Unit] {
      case _ => throw new java.io.IOException("unexpected token")
    }

    var c = readChar
    while(c.isWhitespace)
      c = readChar

    while(!c.isWhitespace) {
      handler(c)

      c = readChar
    }
  }
}

import scala.io.StdIn._

object A {

	def isPalindromSubstring(s:String, pos:Int, length:Int):Boolean = {
		for {
			i <- 0 until length / 2
			c1 = s.charAt(pos + i)
			c2 = s.charAt(pos + length - 1 - i)
		} {
			if (c1 != c2)
				return false
		}
		return true
	}

	def isContainsKPalindroms(s:String, k:Int):Boolean = {
		if (s.length() % k == 0) {
			val length = s.length() / k;
			for (pos <- 0 until s.length() by length) {
				if (!isPalindromSubstring(s, pos, length)) {
					return false
				}
			}
			return true
		} else {
			return false
		}
	}

	def main(args:Array[String]) {
		println(if (isContainsKPalindroms(readLine, readInt)) "YES" else "NO")
	}

}

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

object A {

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

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

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

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

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

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  /**
   * Segment tree for any commutative function
   * @param values Array of Int
   * @param commutative function like min, max, sum
   * @param zero zero value - e.g. 0 for sum, Inf for min, max
   */
  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {
    private val SIZE = 1e5.toInt
    private val n = values.length
    val t = new Array[Int](2 * n)
    Array.copy(values, 0, t, n, n)

    // build segment tree
    def build = {
      for (i <- n - 1 until 0 by -1) {
        t(i) = commutative(t(2 * i), t(2 * i + 1))
      }
    }

    // change value at position p to x
    // TODO beatify
    def modify(p: Int, x: Int) = {
      var pos = p + n
      t(pos) = x
      while (pos > 1) {
        t(pos / 2) = commutative(t(pos), t(pos ^ 1))
        pos /= 2
      }
    }

    // TODO implement me!
    def modify(p: Int, left: Int, right: Int) = ???
    def query(p: Int) = ???

    // sum [l, r)
    // min l = 0
    // max r = n
    // TODO beatify
    def query(left: Int, right: Int): Int = {
      var res = zero
      var r = right + n
      var l = left + n
      while (l < r) {
        if (l % 2 == 1) {
          res = commutative(res, t(l))
          l += 1
        }
        if (r % 2 == 1) {
          r -= 1
          res = commutative(res, t(r))
        }
        l /= 2
        r /= 2
      }
      res
    }
  }

  def solve: Int = {
    val s = next.toCharArray
    val k = nextInt
    val len = s.length / k
    if (len == 0 || s.length % k != 0) {
      out.println("NO")
      return 1
    }
    var i = 0
    while (i < s.length) {
      var i1 = i
      var j1 = i + len - 1
      while (i1 <= j1) {
        if (i1 >= 0 && i1 < s.length && j1 >= 0 && j1 < s.length && s(i1) != s(j1)) {
          out.println("NO")
          return 1
        }
        j1 -= 1
        i1 += 1
      }
      i += len
    }
    out.println("YES")
    return 0
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine();
    val k = StdIn.readInt();

    if(s.length % k != 0) {
      println("NO");
      return;
    }

    def isPolyndrome : String => Boolean = {
      case str if str.length < 2 => true
      case str =>
        if(str.head != str.last)
          false
        else
          isPolyndrome(str.substring(1, str.length - 1));
    }

    println(if(s.grouped(s.length / k).forall(isPolyndrome)) "YES" else "NO");
  }
}

import scala.io.StdIn._

object A extends App {
  val input = readLine()
  val k = readInt()

  def solve() = {
    if (input.length % k != 0) "NO"
    else {
      var str = input
      var size = input.length / k
//      println(str.take(size))
      while (str.length > 0 && isPalindrome(str.take(size))) {
//        println(str.take(size) + " considered")
        str = str.drop(size)
      }
      if (str.length == 0) "YES" else "NO"
    }
  }

  def isPalindrome(s: String): Boolean = s == s.reverse

  println(solve())
}


object B {
  def main(args: Array[String]): Unit = {
    val Array(n, k) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val flowers = scala.io.StdIn.readLine.split(" ").map(_.toInt)
    val count = Array.fill[Int](n)(0)
    for(i <- 1 to k) {
      val Array(q, w) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
//      println(flowers.slice(q-1, w).mkString(" "))
      if (flowers.slice(q-1, w).sum > 0){
        for (j <- q - 1 until w){
          count(j) += 1
        }
      }
    }
//    println(count.mkString(" "))
    println(flowers.toStream.zip(count).map(x => x._2 * x._1).sum)
  }
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val a = in.next().split(' ').map(_.toInt).scanLeft(0)(_+_)
  println((1 to m).foldLeft(0) {
    case (acc, _) =>
      val Array(x, y) = in.next().split(' ').map(_.toInt)
      acc + Math.max(0, a(y) - a(x - 1))
  })
}


object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val symmetric = Set('o', 'O', 'v', 'V', 'I', 'M', 'T', 'U', 'w', 'W', 'x', 'X', 'Y', 'A', 'H')
  if (line.length % 2 == 1 && !symmetric.contains(line(line.length / 2)))
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => (i._1 == i._2 && symmetric.contains(i._1)) ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

import scala.io.StdIn._

object B extends App {
  val Sym = Map(
    'A' -> 'A',
    'b' -> 'd',
    'd' -> 'b',
    'H' -> 'H',
    'I' -> 'I',
    'M' -> 'M',
    'O' -> 'O',
    'o' -> 'o',
    'T' -> 'T',
    'U' -> 'U',
    'V' -> 'V',
    'v' -> 'v',
    'W' -> 'W',
    'w' -> 'w',
    'X' -> 'X',
    'x' -> 'x',
    'Y' -> 'Y',
    'p' -> 'q',
    'q' -> 'p'
  )

  val S = readLine().toCharArray

  def isSPal: Boolean = {
    for (i <- 0 until S.length / 2) {
      if (Sym.get(S(i)).isEmpty || Sym(S(i)) != S(S.length - i - 1)) {
        return false
      }
    }

    if (S.length % 2 == 0) true
    else {
      val mid = S(S.length / 2)
      Sym.get(mid).isDefined && Sym(mid) == mid
    }
  }

  println(if (isSPal) "TAK" else "NIE")

}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  if (line.length % 2 == 0)
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => i._1 == i._2 ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val symmetric = Set('o', 'O', 'v', 'V', 'I', 'M', 'T', 'U', 'w', 'W', 'x', 'X', 'Y')
  if (line.length % 2 == 1 && !symmetric.contains(line(line.length / 2 + 1)))
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => (i._1 == i._2 && symmetric.contains(i._1)) ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val symmetric = Set('o', 'O', 'v', 'V', 'I', 'M', 'T', 'U', 'w', 'W', 'x', 'X', 'Y')
  if (line.length % 2 == 0 || !symmetric.contains(line(line.length / 2)))
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => (i._1 == i._2 && symmetric.contains(i._1)) ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val symmetric = Set('o', 'O', 'v', 'V', 'I', 'M', 'T', 'U', 'w', 'W', 'x', 'X', 'Y', 'A')
  if (line.length % 2 == 1 && !symmetric.contains(line(line.length / 2)))
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => (i._1 == i._2 && symmetric.contains(i._1)) ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val symmetric = Set('o', 'O', 'v', 'V', 'I', 'M', 'T', 'U', 'w', 'W', 'x', 'X', 'Y')
  if (line.length % 2 == 1 && !symmetric.contains(line(line.length / 2)))
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => (i._1 == i._2 && symmetric.contains(i._1)) ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val line = in.next()
  val symmetric = Set('o', 'O', 'v', 'V', 'I', 'M', 'T', 'U', 'w', 'W', 'x', 'X', 'Y')
  if (line.length % 2 == 0 && symmetric.contains(line(line.length / 2)))
    println("NIE")
  else if (line.take(line.length / 2).zip(line.takeRight(line.length / 2).reverse).forall(i => (i._1 == i._2 && symmetric.contains(i._1)) ||
    (Math.min(i._1, i._2) == 'b' && Math.max(i._1, i._2) == 'd') || (Math.min(i._1, i._2) == 'p' && Math.max(i._1, i._2) == 'q'))) {
    println("TAK")
  } else println("NIE")
}

import scala.io.StdIn._

object B extends App {
  val Sym = Map(
    'A' -> 'A',
    'b' -> 'd',
    'd' -> 'b',
    'H' -> 'H',
    'I' -> 'I',
    'M' -> 'M',
    'm' -> 'm',
    'O' -> 'O',
    'o' -> 'o',
    'T' -> 'T',
    'U' -> 'U',
    'V' -> 'V',
    'v' -> 'v',
    'W' -> 'W',
    'w' -> 'w',
    'X' -> 'X',
    'x' -> 'x',
    'Y' -> 'Y',
    'p' -> 'q',
    'q' -> 'p'
  )

  val S = readLine().toCharArray

  def isSPal: Boolean = {
    for (i <- 0 until S.length / 2) {
      if (Sym.get(S(i)).isEmpty || Sym(S(i)) != S(S.length - i - 1)) {
        return false
      }
    }

    if (S.length % 2 == 0) true
    else {
      val mid = S(S.length / 2)
      Sym.get(mid).isDefined && Sym(mid) == mid
    }
  }

  println(if (isSPal) "TAK" else "NIE")

}

import scala.io.StdIn._

object B extends App {
  val Sym = Map(
    'A' -> 'A',
    'b' -> 'd',
    'd' -> 'b',
    'H' -> 'H',
    'I' -> 'I',
    'M' -> 'M',
    'm' -> 'm',
    'O' -> 'O',
    'o' -> 'o',
    'T' -> 'T',
    'U' -> 'U',
    'V' -> 'V',
    'v' -> 'v',
    'W' -> 'W',
    'w' -> 'w',
    'X' -> 'X',
    'x' -> 'x',
    'Y' -> 'Y'
  )

  val S = readLine().toCharArray

  def isSPal: Boolean = {
    for (i <- 0 until S.length / 2) {
      if (Sym.get(S(i)).isEmpty || Sym(S(i)) != S(S.length - i - 1)) {
        return false
      }
    }

    if (S.length % 2 == 0) true
    else {
      val mid = S(S.length / 2)
      Sym.get(mid).isDefined && Sym(mid) == mid
    }
  }

  println(if (isSPal) "TAK" else "NIE")

}


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

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

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

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

  def solve(): Unit = {
    val N = ni()
    val OR, AND = na(N - 1)

    val next = Array.fill[Int](N - 1, 4)(-1)
    rep(N - 1) { i =>
      rep(4) { t1 =>
        rep(4) { t2 =>
          if ((t1 & t2) == AND(i) && (t1 | t2) == OR(i)) next(i)(t1) = t2
        }
      }
    }

    def tryIt(s: Int): Boolean = {
      var p = s
      rep(N - 1) { i =>
        val nxt = next(i)(p)
        if (nxt == -1) return false
        p = nxt
      }
      true
    }

    def create(s: Int): Array[Int] = {
      val res = Array.ofDim[Int](N)
      res(0) = s
      rep(N - 1) { i =>
        res(i + 1) = next(i)(res(i))
      }
      res
    }

    val oks = 0 until 4 filter tryIt
    if (oks.isEmpty) {
      out.println("NO")
    } else {
      out.println("YES")
      out.println(create(oks.head).mkString(" "))
    }
  }

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

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

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

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

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

object B extends App {

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

  val Array(n) = readInts(1)
  val as, bs = readInts(n - 1)

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  val ts = Array.ofDim[Int](n)

  for (t0 <- 0 to 3) {
    ts(0) = t0
    var i = 1
    while (i < n) {
      var t = 0
      ts(i) = -1
      while (t <= 3) {
        if ((ts(i - 1) | t) == as(i - 1) &&
          (ts(i - 1) & t) == bs(i - 1)) {
          ts(i) = t
          t = 4
        } else t += 1
      }
      if (ts(i) >= 0) {
        i += 1
      } else i = n + 1
    }
    if (i == n) {
      println("YES")
      println(ts.mkString(" "))
      Console.flush
      System.exit(0)
    }
  }

  println("NO")

  Console.flush
}

object B extends App {

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

  val Array(n) = readInts(1)
  val as, bs = readInts(n - 1)

  Console.setOut(new java.io.BufferedOutputStream(Console.out))
  val ts = Array.ofDim[Int](n)

  for (t0 <- 0 until 3) {
    ts(0) = t0
    var i = 1
    while (i < n) {
      var t = 0
      ts(i) = -1
      while (t <= 3) {
        if ((ts(i - 1) | t) == as(i - 1) &&
          (ts(i - 1) & t) == bs(i - 1)) {
          ts(i) = t
          t = 4
        } else t += 1
      }
      if (ts(i) >= 0) {
        i += 1
      } else i = n + 1
    }
    if (i == n) {
      println("YES")
      println(ts.mkString(" "))
      Console.flush
      System.exit(0)
    }
  }

  println("NO")

  Console.flush
}


import scala.collection._

object A extends App {

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

  val n = readString.toInt
  var r = 0
  var prev = ""

  for (i <- 0 until n) {
    val s = readString
    if (s != prev) {
      r += 1
      prev = s
    }
  }

  println(r)
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import scala.math._

object Main {

	def main(args: Array[String]) {
		val n = in.rdInt
		var ans = 1
		var last = in.next
		for (i <- 2 to n) {
			val cur = in.next
			if (last != cur) ans+=1
			last = cur
		}
		println(ans)
	}

	object in {
		val in = new BufferedReader(new InputStreamReader(System.in))
		var st = new StringTokenizer("")

		def next : String = {
			while (!st.hasMoreTokens) {
				val line = in.readLine
				if (line == null) return null
				eat(line)
			}
			st.nextToken
		}

		def FastReader = eat("")
		def eat(s : String) = st = new StringTokenizer(s)
		def rdInt = next.toInt
		def rdLong = next.toLong
		def rdDouble = next.toDouble
	}

}

import scala.io.StdIn

object Main extends App {
  val n = StdIn.readInt()
  var prev = StdIn.readLine()
  var count = 1

  for (_ <- 2 to n) {
    val next = StdIn.readLine()
    if (next.head == prev.last) count += 1
    prev = next
  }

  println(count)
}

object CF0344A extends App {

  val n = readInt()
  var count = 0
  var str = "\0"
  (1 to n) foreach(k => {
    val s = readLine()
    if(str == "\0" || s != str) {
      count += 1
      str = s
    }
  })

  println(count)
}

object Magnets {
    def main(arg: Array[String]) {
        val changes = (0 until readInt()).
        map(x=>readInt).
        sliding(2,1).
        map(l=>l.distinct.length).
        filter(_ > 1).
        length
        println(changes + 1)
    }
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val first = in.next()
  println(Range(0, n - 1).map(_ => in.next()).foldLeft((first, 1)) {
    case((prev, count), el) if prev == el => (el, count)
    case((prev, count), el) => (el, count + 1)
  }._2)
}

import scala.io.StdIn

object Magnets extends App {

  val count = StdIn.readLine().toInt

  val magnets = new collection.mutable.ArrayBuffer[String]()
  for (i <- 0 until count) {
    magnets += StdIn.readLine()
  }
  print(impl(magnets.toArray))

  def impl(magnets: Array[String]): Int = {
    var groups = 1
    var prev = magnets(0)

    for (magnet <- magnets) {
      if (magnet != prev) {
        groups += 1
        prev = magnet
      }
    }

    groups
  }
}

import scala.collection.JavaConversions._
import scala.collection.mutable.ArraySeq

object Codeforces344A {
    def main(args: Array[String]) {
        val n = scala.io.StdIn.readLine().toInt
        var lastChar = scala.io.StdIn.readLine().charAt(1)
        var groups = 1
        for (i <- 0 until n-1) {
            val m = scala.io.StdIn.readLine()
            if (m.charAt(0) == lastChar)
                groups += 1
            lastChar = m.charAt(1)
        }
        println(groups)
    }
}

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

        val n = readInt()
        var pole1 = readLine()
        var res = 0
        for(i <- 1 to n){
          val pole = readLine()
          if(pole != pole1){
            res += 1
            pole1 = pole
          }
        }

        println(res)

    }
}

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

object HelloWorld {

  def main(args: Array[String]) {

    val n = readInt().toInt
    val magnets = for(i <- 0 until n) yield readLine.trim

    var islands = 0
    for(i <- 0 until n - 1) {
      islands += (if (magnets(i)(1) == magnets(i+1)(0)) 1 else 0)
    }

    println(islands + 1)
  }
}

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

object HelloWorld {

  def main(args: Array[String]) {

    val n = readInt().toInt
    var islands = 0
    var magnets = ArrayBuffer[String]()

    for(i <- 0 until n) {
      val magnet = readLine.trim
      magnets += magnet
    }

    for(i <- 0 until n - 1) {
      if (magnets(i)(1) == magnets(i+1)(0)) islands += 1
    }

    println(islands + 1)
  }
}

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = new Array[String](n)
    for(i <- 0 until n) {
      input(i) = scala.io.StdIn.readLine
    }
    var res = 1
    for(i <- 1 until n) {
      if(input(i)(0) == input(i-1)(1)) {
        res += 1
      }
    }
    println(res)
  }
}

import scala.collection._

object A extends App {

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

  val n = readString.toInt
  var r = 0
  var prev = ""

  var i = 0
  while (i < n) {
    i += 1
    val s = readString
    if (!s.equals(prev)) {
      r += 1
      prev = s
    }
  }

  println(r)
}

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

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

  def solve(): Unit = {

    @tailrec
    def loop(acc: Int, last: String, ms: List[String]): Int = ms match {
        case Nil     => acc
        case x :: xs => if (x == last) loop(acc, x, xs)
                        else loop(acc + 1, x, xs)
    }

    out.println(loop(0, "", MS))
  }

  solve
  out.close
}

object Magnets {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
	  var current = scanner.nextInt();
	  var nbGroups = 1;
		for (i <- 2 to n) {
		  val previous = current
		  current = scanner.nextInt();
		  if (current != previous)
		    nbGroups += 1
		}
		println(nbGroups)
	}
}

object Main {
  def main(args: Array[String]) {
    val num = readInt()
    var groups = 0
    var prev = "00"
    for(_ <- 1 to num) {
      val cur = readLine
      if (cur != prev) {
        groups += 1
        prev = cur
      }
    }
    println(groups)
  }
}

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

object Magnets {

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

   def main(args: Array[String]) {
     val n = readInt
     val magnets = for {
       i <- 1 to n
       m = readLine
     } yield m
     println(magnets.zipWithIndex.foldLeft(0)
      { case (g,(s,i)) => if (i < n -1 && s(1) != magnets(i+1)(0)) g else g + 1})
   }

}


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

object Opposites {

  val scanner = new Scanner(System.in)
  val c = scanner.nextInt();

  val input = (1 to c) map {i => scanner.nextInt()}

  def main(args: Array[String]) {
    var map = Map[Long,Long]()
    for (i <- input) {
      map += (i.toLong -> (1l + ( if (map.contains(i))  map(i).toLong else 0l)))
    }

    var sum:Long = if (map contains(0)) map(0) else 0;
    sum = (0l/:(1l until sum)) {(sum:Long,i:Long) => sum+i}

    map = map.filter({entry => entry._1 != 0})

    sum += ((0l/:map) {(sum,entry)=>
      sum + {if (map.contains(-entry._1)) entry._2 * map(-entry._1) else 0 } }) / 2

      println(sum)
  }

}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toLong
  var zeros = 0l
  val plus = Array.ofDim[Int](10)
  val minus = Array.ofDim[Int](10)
  in.next().split(' ').map(_.toInt).foreach {
    case (0) => zeros += 1
    case i if i < 0 => minus(-i - 1) += 1
    case i => plus(i - 1) += 1
  }
  val r = plus.zip(minus).foldLeft(0l) {
    case (soFar, (0, second)) => soFar
    case (soFar, (first, 0)) => soFar
    case (soFar, (first, second)) => soFar + first.toLong * second
  } + (zeros - 1) * zeros / 2

  println(r)
}

import scala.collection.mutable.HashMap;

object Main {

    def main(args: Array[String]) {
        val n = nextInt
        val a = for (i <- 1 to n) yield nextInt
        val map = HashMap[Int,Long]()
        a.foreach(x => map.put(x, map.getOrElse(x, 0L) + 1L))
        val ans = a.map(x => map.getOrElse(-x, 0L) - (if (x==0) 1 else 0)).sum
        println(ans / 2)
    }

    val in = new java.io.BufferedReader(new java.io.InputStreamReader(System.in));
    var st = new java.util.StringTokenizer("");

    def next() = {
        while (!st.hasMoreTokens())
            st = new java.util.StringTokenizer(in.readLine());
        st.nextToken();
    }

    def nextInt() = java.lang.Integer.parseInt(next());
    def nextDouble() = java.lang.Double.parseDouble(next());
    def nextLong() = java.lang.Long.parseLong(next());
}

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

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

  val N = sc.nextInt
  val ts: Map[Long, Long] = List.fill(N)(sc.nextLong).groupBy(identity[Long]).map(x => (x._1, x._2.length.toLong)).withDefaultValue(0L)

  val n0: Long = ts(0L)
  val answer: Long = ts.keys.filter(_ > 0L).toList.map(x => ts(x) * ts(-x)).sum + n0 * (n0 - 1) / 2

  out.println(answer)
  out.close
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

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

  val n = readInt
  val a = readInts
  val grouped = a.groupBy(x => x).mapValues(_.length)
  def ans = (a.map(x => grouped.getOrElse(-x, 0)).foldLeft(0L)(_ + _) - grouped.getOrElse(0, 0)) / 2

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

object Main {
  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)
    val r = (1 to 10).map(i => map.getOrElse(i, 0).toLong * map.getOrElse(-i, 0).toLong).sum + (map.getOrElse(0, 0).toLong - 1) * map.getOrElse(0, 0).toLong / 2
    println(r)
  }
}

import java.util.Scanner
import scala.collection.mutable.Map
object Opposites {

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

  def main(args: Array[String]) {
    var map = Map[Int,Int]()
    for (i <- input) {
      map += (i -> (1 + ( if (map.contains(i))  map(i) else 0)))
    }

    var sum = if (map contains(0)) map(0) else 0;
    sum = (0/:(1 until sum)) {(sum,i) => sum+i}

    map = map.filter({entry => entry._1 != 0})

    sum += ((0/:map) {(sum,entry)=>
      sum + {if (map.contains(-entry._1)) entry._2 * map(-entry._1) else 0 } }) / 2

      println(sum)

  }

}

import java.util.Scanner
import scala.collection.mutable.Map
object Opposites {

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

  def main(args: Array[String]) {
    var map = Map[Int,Int]()
    for (i <- input) {
      map += (i -> (1 + ( if (map.contains(i))  map(i) else 0)))
    }

    var sum:Long = if (map contains(0)) map(0) else 0;
    sum = (0l/:(1l until sum)) {(sum:Long,i:Long) => sum+i}

    map = map.filter({entry => entry._1 != 0})

    sum += ((0/:map) {(sum,entry)=>
      sum + {if (map.contains(-entry._1)) entry._2 * map(-entry._1) else 0 } }) / 2

      println(sum)

  }

}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toLong
  var zeros = 0
  val plus = Array.ofDim[Int](10)
  val minus = Array.ofDim[Int](10)
  in.next().split(' ').map(_.toInt).foreach {
    case (0) => zeros += 1
    case i if i < 0 => minus(-i - 1) += 1
    case i => plus(i - 1) += 1
  }
  val r = plus.zip(minus).foldLeft(0l) {
    case (soFar, (0, second)) => soFar
    case (soFar, (first, 0)) => soFar
    case (soFar, (first, second)) => soFar + first.toLong * second
  } + (zeros - 1) * zeros / 2

  println(r)
}

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

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

  val N = sc.nextInt
  val ts = List.fill(N)(sc.nextInt).groupBy(identity[Int]).map(x => (x._1, x._2.length)).withDefaultValue(0)

  val n0 = ts(0)

  val answer: Int = ts.keys.filter(_ > 0).map(x => ts(x) * ts(-x)).sum + n0 * (n0 - 1) / 2

  out.println(answer)
  out.close
}

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

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

  val N = sc.nextLong
  val ts: Map[Long, Long] = List.fill(N.toInt)(sc.nextLong).groupBy(identity[Long]).map(x => (x._1, x._2.length.toLong)).withDefaultValue(0L)

  val n0 = ts(0)

  val answer: Long = ts.keys.filter(_ > 0).map(x => ts(x) * ts(-x)).sum + n0 * (n0 - 1) / 2

  out.println(answer)
  out.close
}

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

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

  val N = sc.nextInt
  val ts = List.fill(N)(sc.nextLong).groupBy(identity[Long]).map(x => (x._1, x._2.length)).withDefaultValue(0)

  val n0 = ts(0)

  val answer: Long = ts.keys.filter(_ > 0).map(x => ts(x) * ts(-x)).sum + n0 * (n0 - 1) / 2

  out.println(answer)
  out.close
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

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

  val n = readInt
  val a = readInts
  val grouped = a.groupBy(x => x).mapValues(_.length)
  def ans = (a.map(x => grouped.getOrElse(-x, 0)).sum - grouped.getOrElse(0, 0)) / 2

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

object Main {
  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)
    val r = (1 to 10).map(i => map.getOrElse(i, 0) * map.getOrElse(-i, 0)).sum + (map.getOrElse(0, 0) - 1) * map.getOrElse(0, 0) / 2
    println(r)
  }
}


import java.util.Scanner

object Main {

  def sqr(x: Long) = x * x

  def powmod(x: Long, n: Long, p: Long): Long = {
    if (n == 1) x
    else if (n % 2 == 1) (powmod(x, n - 1, p) * x) % p
    else sqr(powmod(x, n / 2, p)) % p
  }

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

    val n = in.nextInt()

    val t = in.nextInt()

    println("%.9f".format(Math.pow(1.000000011, t) * n))
  }
}

/**
  * Created by octavian on 18/02/2016.
  */
object Moore {

  def main(args: Array[String]) {
    //System.setIn(new FileInputStream("src/moore.in"))
    //System.setOut(new PrintStream(new FileOutputStream("src/moore.out")))

    var Array(n, t): Array[Long] = readLine().split(" ").map(_.toLong)
    var basis: Double = 1.000000011

    println(raise(basis, t) * n)

  }

  def raise(basis: Double, power: Long): Double = {
    var res: Double = 1
    var acc = basis
    var c_power = power
    while(c_power > 0) {
      if(c_power % 2 == 1) {
        c_power -= 1
        res *= acc
      }
      if(c_power > 0) {
        c_power /= 2
        acc = Math.pow(acc, 2)
      }
    }

    return res
  }

}

import scala.io.StdIn

object MooresLaw {

  def main(args: Array[String]) {
    val Array(n, t) = StdIn.readLine().split("\\s+").map(_.toInt)
    print(n * Math.pow(1.000000011, t))
  }

}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
//import java.math.BigDecimal

object Bitz_B {

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

    //COMMENT ME !
//    is = new ByteArrayInputStream(Test.sa1.trim.getBytes("ISO-8859-1"))
//    debugV = true

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val t = line1.int

//    val bd = BigDecimal(1.000000011)
//    val res = bd.pow(t) * n
//
////    val res = Math.pow(pp, t) * n

    def pow(arg:Double, pp:Int):Double = {
      if (pp == 0) return 1
      if (pp == 1) return arg
      val half = pow(arg, pp/2)
      if (pp % 2 == 0) {
        return  half * half
      } else {
        return half * half * arg
      }
    }

    val res = pow(1.000000011, t) * n

    println(res.toDouble)

    //---------------------------- parameters reading end ----------------------

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val tok = new StringTokenizer(br.readLine(), " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
1000 1000000
"""

}

}


object CF611A extends App {

  import scala.io.StdIn

  val t = StdIn.readInt
  for (_ <- 0 until t) {
    val Array(h, m) = StdIn.readLine.split(' ').map(_.toInt)
    println((23-h)*60 + 60-m)
  }
}

case class Trap(l: Int, r: Int, d: Int)

object Main extends App {
  val stdin = scala.io.Source.stdin.getLines()

  val t = stdin.next().toInt
  println(stdin.take(t).map(_.split(" ").map(_.toInt)).map(arr => calc(arr(0), arr(1))).mkString(" "))

  def calc(hours: Int, minutes: Int): Int = (23 - hours) * 60 + (60 - minutes)
}


import scala.annotation.tailrec

/**
 * Created by antonk on 29.09.14.
 */
object TaskA {
  def main(args: Array[String]) {
    val n = readInt
    val handles = {for (_ <- (1 to n)) yield {readLine split ' ' toList}} toArray
    val permutation = readLine split ' ' map(_.toInt - 1)
//    val inverse_permutation = Array.fill(n)(0)
  //  for ((x, i) <- permutation.view.zipWithIndex) inverse_permutation(x) = i
    @tailrec def isContinued(i: Int, max: Int, currentHandle: String = handles(permutation.head) min): String = {
      if (i == max) "YES"
      else ((currentHandle :: handles(permutation(i))) sorted) match {
        case List(x, r, _) if x == currentHandle => isContinued(i + 1, max, r)
        case List(_, x, r) if x == currentHandle => isContinued(i + 1, max, r)
        case _ => "NO"
      }
    }
    println(isContinued(1, n))
//    println(inverse_permutation map(_.toString) reduceLeft(_ + ' ' +  _))
  }
}

import java.util.StringTokenizer

object _472C extends App {
  var token = new StringTokenizer("")

  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }

  val n = next.toInt
  val a = (1 to n).map(i => {
    val s = next; val ss = next; if (s < ss) (s, ss) else (ss, s)
  }).toArray
  val b = (1 to n).map(i => next.toInt - 1).map(i => a(i))

  def doit(i: Int, pre: String): Boolean = {
    if (i >= n) true
    else {
      if (b(i)._1 >= pre) doit(i + 1, b(i)._1)
      else if (b(i)._2 >= pre) doit(i + 1, b(i)._2)
      else return false
    }
  }

  if (doit(1, b(0)._1)) println("YES")
  else println("NO")
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = (1 to n).map(_ => in.next())
  val indices = in.next().split(" ").map(_.toInt - 1)
  val sorted = indices.map(i => data(i))
  if (sorted.foldLeft(("", true)) {
    case ((prev, false), el) => (prev, false)
    case ((prev, true), el) =>
      val Array(a, b) = el.split(" ")
      if (prev > a && prev > b) {
        (prev, false)
      }
      else if (prev < a && prev < b) {
        if (a < b)
          (a, true)
        else
          (b, true)
      } else {
        if (prev > a)
          (b, true)
        else
          (a, true)
        }
      }._2)
    println("YES")
  else
    println("NO")
}

object C472 {
  import IO._
  import collection.{mutable => cu}
  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val names = Array.fill(n)(read.split(" ").sorted)
    val expected = readInts(n)
    def result(): Boolean = {
      var curr = names(expected.head-1).head
      var res = true
      for(i <- 1 until n if res) {
        if(names(expected(i)-1).head > curr) {
          curr = names(expected(i)-1).head
        } else if(names(expected(i)-1).last > curr) {
          curr = names(expected(i)-1).last
        } else {
          res = false
        }
      }
      res
    }
    if(result()) {
      println("YES")
    } else {
      println("NO")
    }
  }

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

import scala.collection._

object C extends App {

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

  val Array(n) = readInts(1)

  val ss = Array.ofDim[(String, String)](n)

  for (i <- 0 until n) {
    val s = readLine.split(" ")
    ss(i) = (s(0), s(1))
  }

  val ps = readInts(n)

  var prev = ""

  for (p <- ps) {
    val (l, r) = ss(p - 1)
    val (min, max) = if (l < r) (l, r) else (r, l)
    if (min > prev) {
      prev = min
    } else if (max > prev) {
      prev = max
    } else {
      //println(min, max, prev)
      println("NO")
      System.exit(0)
    }
  }

  println("YES")
}

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

   def main(args: Array[String]) {
     val Array(n) = READ;
     var w = Array.ofDim[String](n, 2)
     for (i <- 0 until n) w(i) = readLine() split (" ") sorted
     val p = READ;
     w = p.map(x => w(x-1))
     var min = w(0) min;
     for (i <- 1 until n)
       if (min <= w(i)(0)) min = w(i)(0)
       else if (min <= w(i)(1)) min = w(i)(1)
       else {
         println("NO")
         return;
       }
     println("YES")
   }
 }

import scala.annotation.tailrec

/**
 * Created by antonk on 29.09.14.
 */
object TaskA {
  def main(args: Array[String]) {
    val n = readInt
    val handles = {for (_ <- (1 to n)) yield {readLine split ' ' toList}} toArray
    val permutation = readLine split ' ' map(_.toInt - 1)
//    val inverse_permutation = Array.fill(n)(0)
  //  for ((x, i) <- permutation.view.zipWithIndex) inverse_permutation(x) = i
    @tailrec def isContinued(i: Int, max: Int, currentHandle: String = handles(permutation.head) min): String = {
      if (i == max) "YES"
      else ((currentHandle :: handles(i)) sorted) match {
        case List(x, r, _) if x == currentHandle => isContinued(i + 1, max, r)
        case List(_, x, r) if x == currentHandle => isContinued(i + 1, max, r)
        case _ => "NO"
      }
    }
    println(isContinued(1, n))
//    println(inverse_permutation map(_.toString) reduceLeft(_ + ' ' +  _))
  }
}

import scala.annotation.tailrec

object TaskA {
  def main(args: Array[String]) {
    val n = readInt
    val handles = {for (_ <- (1 to n)) yield {readLine split ' ' toList}} toArray
    val permutation = readLine split ' ' map(_.toInt - 1)
    val inverse_permutation = Array.fill(n)(0)
    for ((x, i) <- permutation.view.zipWithIndex) inverse_permutation(x) = i
    @tailrec def isContinued(i: Int, max: Int, currentHandle: String = handles(inverse_permutation.head) min): String = {
      if (i == max) "YES"
      else ((currentHandle :: handles(i)) sorted) match {
        case List(x, r, _) if x == currentHandle => isContinued(i + 1, max, r)
        case List(_, x, r) if x == currentHandle => isContinued(i + 1, max, r)
        case _ => "NO"
      }
    }
    println(isContinued(1, n))
//    println(inverse_permutation map(_.toString) reduceLeft(_ + ' ' +  _))
  }
}


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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)
    val mc2=new Array[Int](2)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }

        loop(n){dp(_)=Long.MinValue/2}

        mc2(0)=n;mc2(1)=n

        loop(n){i=>
          dp(c(i))=
            Math.max(Math.max(dp(c(i)),dp(c(i))+v(i)*a),dp(
              if(mc2(0)!=c(i)) mc2(0) else mc2(1)
            )+v(i)*b)

          //sort
          var tmp=c(i)
          if(dp(c(i))>dp(mc2(1))){
            mc2(1)^=tmp
            tmp^=mc2(1)
            mc2(1)^=tmp
          }
          if(dp(mc2(1))>dp(mc2(0))){
            mc2(0)^=mc2(1)
            mc2(1)^=mc2(0)
            mc2(0)^=mc2(1)
          }
          if(mc2(0)==mc2(1)){
            mc2(1)=tmp
          }
        }

        dp(mc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }

  def loop(n:Int)(f:Int=>Unit){
    var i=0
    while(i<n){
      f(i)
      i+=1
    }
  }

  def getTime(f:()=>Unit):Long={
    val now=System.currentTimeMillis
    f()
    System.currentTimeMillis-now
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)
    val mc2=new Array[Int](2)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        (0 to n-1).foreach{i=>dp(i)=Long.MinValue/2}
        dp(n)=0

        mc2(0)=n;mc2(1)=n

        (0 to n-1).foreach{i=>
          dp(c(i))=
            Math.max(Math.max(dp(c(i)),dp(c(i))+v(i)*a),dp(
              if(mc2(0)!=c(i)) mc2(0) else mc2(1)
            )+v(i)*b)

          //sort
          var tmp=c(i)
          if(dp(c(i))>dp(mc2(1))){
            mc2(1)^=tmp
            tmp^=mc2(1)
            mc2(1)^=tmp
          }
          if(dp(mc2(1))>dp(mc2(0))){
            mc2(0)^=mc2(1)
            mc2(1)^=mc2(0)
            mc2(0)^=mc2(1)
          }
          if(mc2(0)==mc2(1)){
            mc2(1)=tmp
          }
        }

        dp(mc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)
    val mc2=new Array[Int](2)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        {
          var i=0
          while(i<n){
            dp(i)=Long.MinValue/2
            i+=1
          }
          dp(n)=0
        }

        mc2(0)=n;mc2(1)=n

        var i=0
        while(i<n){
          dp(c(i))=
            Math.max(Math.max(dp(c(i)),dp(c(i))+v(i)*a),dp(
              if(mc2(0)!=c(i)) mc2(0) else mc2(1)
            )+v(i)*b)

          //sort
          var tmp=c(i)
          if(dp(c(i))>dp(mc2(1))){
            mc2(1)^=tmp
            tmp^=mc2(1)
            mc2(1)^=tmp
          }
          if(dp(mc2(1))>dp(mc2(0))){
            mc2(0)^=mc2(1)
            mc2(1)^=mc2(0)
            mc2(0)^=mc2(1)
          }
          if(mc2(0)==mc2(1)){
            mc2(1)=tmp
          }
          i+=1
        }

        dp(mc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }

  def loop(n:Int)(f:Int=>Unit){
    var i=0
    while(i<n){
      f(i)
      i+=1
    }
  }

  def getTime(f:()=>Unit):Long={
    val now=System.currentTimeMillis
    f()
    System.currentTimeMillis-now
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        val dp= new Array[Long](n+1).map(i=>Long.MinValue/2)

        val maxc0=
          (0 to n-1).foldLeft(List[Int](n)){(maxc2,i)=>
            dp(c(i))=
              dp(c(i)) max (v(i)*b) max maxc2.map{cm=>
                if(cm==c(i)){
                  dp(cm)+v(i)*a
                }else{
                  dp(cm)+v(i)*b
                }
              }.max

            (c(i)::maxc2).distinct.sortWith{(c1,c2)=>
              dp(c1)>dp(c2)
            }.take(2)//->foldLeft
          }.head//->maxc0

        dp(maxc0)//->map
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        };
        (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        val maxc=Array(n,n);
        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              if(c(i)==maxc(0)) maxc(1) else maxc(0)
            )+v(i)*b

          if(c(i)!=maxc(0)||c(i)!=maxc(1)){
            if(dp(c(i))>dp(maxc(0))){
              maxc(1)=maxc(0)
              maxc(0)=c(i)
            }else if(dp(c(i))>dp(maxc(1))){
              maxc(1)=c(i)
            }
          }else{
            if(dp(maxc(1))>dp(maxc(0))){
              maxc(0)^=maxc(1)
              maxc(1)^=maxc(0)
            }
          }
        }
        dp(maxc(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)

    val ansList=
      (1 to q).map{ii=>
        val (a,b)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        val dp= new Array[Long](n+1)

        val maxc0=
          (0 to n-1).foldLeft(List[Int](n)){(maxc2,i)=>
            dp(c(i))=
              dp(c(i)) max (v(i)*b) max maxc2.map{cm=>
                if(cm==c(i)){
                  dp(cm)+v(i)*a
                }else{
                  dp(cm)+v(i)*b
                }
              }.max

            (c(i)::maxc2).distinct.sortWith{(c1,c2)=>
              dp(c1)>dp(c2)
            }.take(2)//->foldLeft
          }.head//->maxc0

        dp(maxc0)//->map
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)
    val mc2=new Array[Int](2)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        dp.map(i=>Long.MinValue/2)
        dp(n)=0

        mc2(0)=n;mc2(1)=n

        0 to n-1 foreach{i=>
          dp(c(i))=
            Math.max(Math.max(dp(c(i)),dp(c(i))+v(i)*a),dp(
              if(mc2(0)!=c(i)) mc2(0) else mc2(1)
            )+v(i)*b)

          //sort
          var tmp=c(i)
          if(dp(c(i))>dp(mc2(1))){
            mc2(1)^=tmp
            tmp^=mc2(1)
            mc2(1)^=tmp
          }
          if(dp(mc2(1))>dp(mc2(0))){
            mc2(0)^=mc2(1)
            mc2(1)^=mc2(0)
            mc2(0)^=mc2(1)
          }
          if(mc2(0)==mc2(1)){
            mc2(1)=tmp
          }
        }

        dp(mc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        val dp= new Array[Long](n+1).map(i=>Long.MinValue/2)
        dp(n)=0

        val maxc0=
          (0 to n-1).foldLeft(List[Int](n)){(maxc2,i)=>
            dp(c(i))=
              dp(c(i)) max (v(i)*b) max maxc2.map{cm=>
                if(cm==c(i)){
                  dp(cm)+v(i)*a
                }else{
                  dp(cm)+v(i)*b
                }
              }.max

            (c(i)::maxc2).distinct.sortWith{(c1,c2)=>
              dp(c1)>dp(c2)
            }.take(2)//->foldLeft
          }.head//->maxc0

        dp(maxc0)//->map
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        };
        (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        val maxc=Array(n,n);
        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              if(c(i)==maxc(0)) maxc(1) else maxc(0)
            )+v(i)*b

          if(c(i)!=maxc(0)||c(i)!=maxc(1)){
            if(dp(c(i))>dp(maxc(0))){
              maxc(1)=maxc(0)
              maxc(0)=c(i)
            }else if(dp(c(i))>dp(maxc(1))){
              maxc(1)=c(i)
            }
          }else{
            if(dp(maxc(1))>dp(maxc(0))){
              maxc(0)^=maxc(1)
              maxc(1)^=maxc(0)
              maxc(0)^=maxc(1)
            }
          }
        }
        dp(maxc(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        val maxc2=Array[Int](n,n)

        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              maxc2.find(_!=c(i)).get
            )+v(i)*b

          val tmp=Array(c(i),maxc2(0),maxc2(1))
          tmp.sortWith{(c1,c2)=>dp(c1)>dp(c2)}
          maxc2(0)=tmp(0)
          maxc2(1)=tmp.find(_!=maxc2(0)).get
        }

        dp(maxc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toInt)
    val c=readLine.split(" ").map(_.toInt -1)

    val ansList=
      (1 to q).map{ii=>
        val (a,b)={
          val sp=readLine.split(" ")
          (sp(0).toInt,sp(1).toInt)
        }
        val dp= new Array[Long](n+1)

        val maxc0=
          (0 to n-1).foldLeft(List[Int](n)){(maxc2,i)=>
            dp(c(i))=
              dp(c(i)) max (v(i)*b) max maxc2.map{cm=>
                if(cm==c(i)){
                  dp(cm)+v(i)*a
                }else{
                  dp(cm)+v(i)*b
                }
              }.max

            (c(i)::maxc2).distinct.sortWith{(c1,c2)=>
              dp(c1)>dp(c2)
            }.take(2)//->foldLeft
          }.head//->maxc0

        dp(maxc0)//->map
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        val dp= new Array[Long](n+1).map(i=>Long.MinValue/2)
        dp(n)=0

        val maxc0=
          (0 to n-1).foldLeft(List[Int](n)){(maxc2,i)=>
            dp(c(i))=
              dp(c(i)) max maxc2.map{cm=>
                if(cm==c(i)){
                  dp(cm)+v(i)*a
                }else{
                  dp(cm)+v(i)*b
                }
              }.max

            (c(i)::maxc2).distinct.sortWith{(c1,c2)=>
              dp(c1)>dp(c2)
            }.take(2)//->foldLeft
          }.head//->maxc0

        dp.max
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
          (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        val maxc=Array(n,n);
        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              if(c(i)==maxc(0)) maxc(1) else maxc(0)
            )+v(i)*b

          if(c(i)!=maxc(0)||c(i)!=maxc(1)){
            if(dp(c(i))>dp(maxc(0))){
              maxc(1)=maxc(0)
              maxc(0)=c(i)
            }else if(dp(c(i))>dp(maxc(1))){
              maxc(1)=c(i)
            }
          }
        }
        dp(maxc(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)
    val mc2=new Array[Int](2)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        mc2(0)=n;mc2(1)=n

        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              try{
                mc2.find(_!=c(i)).get
              }catch{
                case(e:Exception) =>
                  println(mc2(0)+","+mc2(1)+","+c(i)+","+i)
                  0
              }

            )+v(i)*b

          //sort
          var tmp=c(i)
          if(dp(c(i))>dp(mc2(1))){
            mc2(1)^=tmp
            tmp^=mc2(1)
            mc2(1)^=tmp
          }
          if(dp(mc2(1))>dp(mc2(0))){
            mc2(0)^=mc2(1)
            mc2(1)^=mc2(0)
            mc2(0)^=mc2(1)
          }
          if(mc2(0)==mc2(1)){
            mc2(1)=c(i)
          }

        }

        dp(mc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        val dp= new Array[Long](n+1).map(i=>Long.MinValue/2)
        dp(n)=0

        val maxc0=
          (0 to n-1).foldLeft(List[Int](n)){(maxc2,i)=>
            dp(c(i))=
              dp(c(i)) max (v(i)*b) max maxc2.map{cm=>
                if(cm==c(i)){
                  dp(cm)+v(i)*a
                }else{
                  dp(cm)+v(i)*b
                }
              }.max

            (c(i)::maxc2).distinct.sortWith{(c1,c2)=>
              dp(c1)>dp(c2)
            }.take(2)//->foldLeft
          }.head//->maxc0

        dp.max
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        };
        (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        val maxc=Array(n,n);
        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              if(c(i)==maxc(0)) maxc(1) else maxc(0)
            )+v(i)*b

          if(c(i)!=maxc(0)||c(i)!=maxc(1)){
            if(dp(c(i))>dp(maxc(0))){
              maxc(1)=maxc(0)
              maxc(0)=c(i)
            }else if(dp(c(i))>dp(maxc(1))){
              maxc(1)=c(i)
            }else if(maxc(0)==maxc(1)){
              maxc(1)=c(i)
            }
          }else{
            if(dp(maxc(1))>dp(maxc(0))){
              maxc(0)^=maxc(1)
              maxc(1)^=maxc(0)
              maxc(0)^=maxc(1)
            }
          }
        }
        dp(maxc(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}

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

    val (n,q)={
      val sp=readLine.split(" ")
      (sp(0).toInt,sp(1).toInt)
    }

    val v=readLine.split(" ").map(_.toLong)
    val c=readLine.split(" ").map(_.toInt -1)
    val dp=new Array[Long](n+1)

    val ansList=
      (1 to q).map{ii=>
        val (a:Long,b:Long)={
          val sp=readLine.split(" ")
          (sp(0).toLong,sp(1).toLong)
        }
        (0 to n-1).foreach(dp(_)=Long.MinValue/2)
        dp(n)=0

        val maxc2=Array[Int](n,n)

        (0 to n-1).foreach{i=>
          dp(c(i))=
            dp(c(i)) max dp(c(i))+v(i)*a max dp(
              maxc2.find(_!=c(i)).get
            )+v(i)*b

          val tmp=Array(c(i),maxc2(0),maxc2(1)).sortWith{(c1,c2)=>dp(c1)>dp(c2)}
          maxc2(0)=tmp(0)
          maxc2(1)=tmp.find(_!=maxc2(0)).get

          println(maxc2.mkString(","))
        }

        dp(maxc2(0))
      }//->ansList

    println(ansList.mkString("\n"))
  }
}


object qa {
  def main(args: Array[String]) {
    val n = scala.io.StdIn.readInt()
    for (_ <- 0 until n) {
      val i = scala.io.StdIn.readInt()
      val str = {
        if (i >= 1900) "Division 1"
        else if (i >= 1600) "Division 2"
        else if (i >= 1400) "Division 3"
        else "Division 4"
      }
      println(str)
    }
  }
}

import scala.io.StdIn

/**
 * На Codeforces пользователи разделены на 4 дивизиона по их рейтингу:
 *
 * Для 1-го дивизиона: 1900≤rating
 * Для 2-го ивизиона: 1600≤rating≤1899
 * Для 3-го дивизиона: 1400≤rating≤1599
 * Для 4-го дивизиона: rating≤1399
 * Учитывая rating, выведите, к какому дивизиону относится rating.
 *
 * Входные данные
 * Первая строка ввода содержит целое число 𝑡 (1≤𝑡≤104) — количество наборов входных данных в тесте.
 *
 * Описание каждого набора состоит из одной строки, содержащей одно целое число rating (−5000≤rating≤5000).
 *
 * Выходные данные
 * Для каждого набора входных данных выведите единственную строку, содержащую дивизион в формате «Division X», где 𝑋 — целое число от 1 до 4, представляющее дивизион для соответствующего рейтинга.
 */

object Task1 extends App {
  def getNextNum: Int = StdIn.readLine().toInt

  val inputSize = getNextNum

  for (_ <- 0 until inputSize) {
    val rating = getNextNum

    if (rating <= 1399) {
      println("Division 4")
    } else {
      if (rating <= 1599) {
        println("Division 3")
      } else {
        if (rating <= 1899) {
          println("Division 2")
        } else {
          println("Division 1")
        }
      }
    }
  }

}

import scala.io.StdIn.readLine

object Solution {

  def rsi() = readLine().split("\\s+").map(_.toInt)
  // ======================================

  def solve(n: Int) = {
    "Division " + (n match {
      case i if (i >= 1900) => 1
      case i if (i >= 1600) => 2
      case i if (i >= 1400) => 3
      case i => 4
    })
  }

  def main(args: Array[String]): Unit = {
    val cases = readLine.toInt

    for (
      i <- 0 until cases;
      n = readLine().toInt
    ) println(solve(n))
  }
}