import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
//    val t = readLine().toInt
//    for (i <- 1 to t) {
     val n = readLine().toInt
   handle(n)
//    }
  }

  def handle(n: Int) = {
    def hat(left: Int, upper: Boolean) = {
      val yl = if (upper) 1 else -1
      val yh = if (upper) 2 else -2
      val mid = left + 1
      val right = left + 2
      println(f"$left $yl")
      println(f"$left $yh")
      println(f"$mid $yh")
      println(f"$right $yh")
      println(f"$right $yl")
    }

    println(2 * n + 3 + 5 * (n + 1))

    // main
    (-2 to 2 * n).foreach(i => println(f"$i 0"))

    (0 to n / 2).foreach(i => hat(-2 + 4 * i, upper = true))
    (0 to (n - 1) / 2).foreach(i => hat(4 * i, upper = false))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}

import scala.collection.mutable.ArrayBuffer

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

    val k = nextInt
    val res = ArrayBuffer.empty[String]
    for (i <- 0 to k) {
      val ii = i
      res += s"${ii} ${ii}"
      res += s"${ii + 1} ${ii}"
      res += s"${ii} ${ii + 1}"
    }
    val ii = k
    res += s"${ii + 1} ${ii + 1}"

    out.println(res.length)
    out.println(res.mkString("\n"))

    out.flush()
  }

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

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
//    val t = readLine().toInt
//    for (i <- 1 to t) {
     val n = readLine().toInt
    println(15 * n)
    (0 until n).foreach(handle)
//    }
  }

  def handle(i: Int) = {
    //center
    println(f"${10*i} 0")
    //neighs
    println(f"${10*i + 1} 0")
    println(f"${10*i + 0} 1")
    println(f"${10*i - 1} 0")
    println(f"${10*i + 0} -1")
    // chains
    println(f"${10*i + 0} 2")
    println(f"${10*i + 1} 2")
    println(f"${10*i + 2} 2")
    println(f"${10*i + 2} 1")
    println(f"${10*i + 2} 0")

    println(f"${10*i + 0} -2")
    println(f"${10*i - 1} -2")
    println(f"${10*i - 2} -2")
    println(f"${10*i - 2} -1")
    println(f"${10*i - 2} 0")
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
//    val t = readLine().toInt
//    for (i <- 1 to t) {
     val n = readLine().toInt
   handle(n)
//    }
  }

  def handle(n: Int) = {
    def hat(left: Int, upper: Boolean) = {
      val yl = if (upper) 1 else -1
      val yh = if (upper) 2 else -2
      val mid = left + 1
      val right = left + 2
      println(f"$left $yl")
      println(f"$left $yh")
      println(f"$mid $yh")
      println(f"$right $yh")
      println(f"$right $yl")
    }

    println(2 * n + 3 + 5 * (n + 1))

    // main
    (-2 to 2 * n).foreach(i => println(f"$i 0"))

    (0 to n / 2).foreach(i => hat(-2 + 4 * i, upper = true))
    (0 to (n - 1) / 2).foreach(i => hat(4 * i, upper = true))
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
//    val t = readLine().toInt
//    for (i <- 1 to t) {
     val n = readLine().toInt
      handle(n)
//    }
  }

  def handle(n: Int) = {
    if (n == 1) {
      println(15)
      //center
      println("0 0")
      //neighs
      println("1 0")
      println("0 1")
      println("-1 0")
      println("0 -1")
      // chains
      println("0 2")
      println("1 2")
      println("2 2")
      println("2 1")
      println("2 0")

      println("0 -2")
      println("-1 -2")
      println("-2 -2")
      println("-2 -1")
      println("-2 0")
    }
    else {
      println(4 * n + 12)
      // core
      (0 until n).foreach(i => {
        println(f"$i 1")
        println(f"$i -1")
        println(f"$i 0")
      })
      //chain
      (-2 to n + 1).foreach(i => {
        println(f"$i 3")
      })
      println("-1 0")
      println("-2 0")
      println("-2 1")
      println("-2 2")
      println(f"$n 0")
      println(f"${n+1} 0")
      println(f"${n+1} 1")
      println(f"${n+1} 2")
    }
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}


import scala.io.StdIn

object Forecast {

  def main(args: Array[String]) {
    val Array(a, b, c) = StdIn.readLine().split("\\s").map(_.toInt)
    val d = Math.sqrt(b * b - 4 * a * c)
    val x1 = -(b + d) / (2 * a)
    val x2 = -(b - d) / (2 * a)
    println(Math.max(x1, x2))
    println(Math.min(x1, x2))
  }

}

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 C(n: Int, k: Int) = {
    var res = BigInt(1)
    for (i <- n - k + 1 to n) {
      res = res * i
    }
    for (i <- 1 to k.toInt) {
      res = res / i
    }
    res
  }

  def fact(n: Int) = {
    var res = BigInt(1)
    for (i <- 1 to n) {
      res = res * i
    }
    res
  }

  def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b)

  def lcm(a: Long, b: Long) = a / gcd(a, b) * b

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

    val Array(a, b, c) = in.nextLine().split(' ').map(_.toDouble)

    val D = b * b - 4 * a * c

    var x1 = (-b + Math.sqrt(D)) / (2 * a)
    var x2 = (-b - Math.sqrt(D)) / (2 * a)

    if (x1 < x2) {
      val c = x1
      x1 = x2
      x2 = c
    }

    println("%.10f\n%.10f".format(x1, x2))
  }
}


import java.io._
import java.util.StringTokenizer
import scala.util.Try

object Sol extends App {
  val (in, out) = Try {(
    new Reader("input.txt"),
    new PrintWriter(new BufferedWriter(new FileWriter("output.txt")))
  )} getOrElse {(
    new Reader(),
    new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
  )}

  val n = in.nextInt
  val a = in.nextLine.split(" ").map(_.toInt)
  val parts = a.partition(_ % 2 == 0)

  out.println(Math.min(parts._1.length, parts._2.length))
  out.flush()
  out.close()

  class Reader() {
    var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    var tok: StringTokenizer = null

    def this(file: String) {
      this()
      br = new BufferedReader(new FileReader(file))
    }

    def next: String = {
      while (tok == null || !tok.hasMoreElements)
        tok = new StringTokenizer(br.readLine)
      tok.nextToken
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    def nextDouble: Double = next.toDouble

    def nextLine: String = br.readLine
  }

}

import scala.io.StdIn

object Main extends App {

  val n: Int = StdIn.readInt()
  val arr: Array[Int] = StdIn.readLine().split(" ").map(_.toInt)

  val odd = arr.filter(item => item%2 == 0).length
  val notOdd = arr.filter(item => item%2 != 0).length

  val res = Math.min(odd, notOdd)

  println(res)

}

//package codeforces.contest1213

object ChipsMoving {

  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()
    val (evens, odds) =
      io.StdIn.readLine.split(" ").map(_.toInt).foldLeft((0, 0)) {
        case ((e, o), i) =>
          if ((i & 1) == 1) (e, o + 1) else (e + 1, o)
      }
    println(evens min odds)
  }

}

import scala.io.StdIn._

object Main {
  def main(args: Array[String]) = {
    val numberChips: Int = readInt()
    val chipsCoord = readLine().split(" ").map(_.toInt).toList
    var oddCoord: Int = 0
    var evenCoord: Int = 0
    for (i <- 0 until numberChips) {
      if (chipsCoord(i) % 2 == 0) {
        evenCoord += 1
      } else {
        oddCoord += 1
      }
    }
    println(s"${Math.min(evenCoord, oddCoord)}")
  }
}

import java.io._
import java.util.StringTokenizer
import scala.util.Try

object Sol extends App {
  val (in, out) = Try {(
    new Reader("input.txt"),
    new PrintWriter(new BufferedWriter(new FileWriter("output.txt")))
  )} getOrElse {(
    new Reader(),
    new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
  )}

  val n = in.nextInt
  val a = in.nextLine.split(" ").map(_.toInt)
  def move(x: Int, y: Int) = if ((x - y).abs % 2 == 1) 1 else 0
  def cost(pos: Int): Int = a.foldLeft(0)((acc, cur) => acc + move(pos, cur))

  out.println(a.map(cost).min)
  out.flush()
  out.close()

  class Reader() {
    var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    var tok: StringTokenizer = null

    def this(file: String) {
      this()
      br = new BufferedReader(new FileReader(file))
    }

    def next: String = {
      while (tok == null || !tok.hasMoreElements)
        tok = new StringTokenizer(br.readLine)
      tok.nextToken
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    def nextDouble: Double = next.toDouble

    def nextLine: String = br.readLine
  }

}

import java.io._
import java.util.StringTokenizer
import scala.util.Try

object Sol extends App {
  val (in, out) = Try {(
    new Reader("input.txt"),
    new PrintWriter(new BufferedWriter(new FileWriter("output.txt")))
  )} getOrElse {(
    new Reader(),
    new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
  )}

  val n = in.nextInt
  val a = in.nextLine.split(" ").map(_.toInt)
  val evens = a.count(_ % 2 == 0)

  out.println(evens min (n - evens))
  out.flush()
  out.close()

  class Reader() {
    var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    var tok: StringTokenizer = null

    def this(file: String) {
      this()
      br = new BufferedReader(new FileReader(file))
    }

    def next: String = {
      while (tok == null || !tok.hasMoreElements)
        tok = new StringTokenizer(br.readLine)
      tok.nextToken
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    def nextDouble: Double = next.toDouble

    def nextLine: String = br.readLine
  }

}

import java.io._
import java.util.StringTokenizer
import scala.util.Try

object Sol extends App {
  val (in, out) = Try {(
    new Reader("input.txt"),
    new PrintWriter(new BufferedWriter(new FileWriter("output.txt")))
  )} getOrElse {(
    new Reader(),
    new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
  )}

  val n = in.nextInt
  val a = in.nextLine.split(" ").map(_.toInt)
  def move(x: Int, y: Int) = if ((x - y).abs == 1) 1 else 0
  def cost(pos: Int): Int = a.foldLeft(0)((acc, cur) => acc + move(pos, cur))
  implicit def ord: Ordering[Int] = (x: Int, y : Int) => cost(x).compareTo(cost(y))

  out.println(a.min)
  out.flush()
  out.close()

  class Reader() {
    var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    var tok: StringTokenizer = null

    def this(file: String) {
      this()
      br = new BufferedReader(new FileReader(file))
    }

    def next: String = {
      while (tok == null || !tok.hasMoreElements)
        tok = new StringTokenizer(br.readLine)
      tok.nextToken
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    def nextDouble: Double = next.toDouble

    def nextLine: String = br.readLine
  }

}

import java.io._
import java.util.StringTokenizer
import scala.util.Try

object Sol extends App {
  val in = Try(new Reader("input.txt")).getOrElse(new Reader())
  val out = Try(new PrintWriter(new BufferedWriter(new FileWriter("output.txt"))))
    .getOrElse(new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out))))

  val n = in.nextInt
  val a = in.nextLine.split(" ").map(_.toInt)
  def move(x: Int, y: Int) = if ((x - y).abs == 1) 1 else 0
  def cost(pos: Int): Int = a.foldLeft(0)((acc, cur) => acc + move(pos, cur))
  implicit def ord: Ordering[Int] = (x: Int, y : Int) => cost(x).compareTo(cost(y))

  out.println(a.min)
  out.flush()
  out.close()

  class Reader() {
    var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    var tok: StringTokenizer = null

    def this(file: String) {
      this()
      br = new BufferedReader(new FileReader(file))
    }

    def next: String = {
      while (tok == null || !tok.hasMoreElements)
        tok = new StringTokenizer(br.readLine)
      tok.nextToken
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    def nextDouble: Double = next.toDouble

    def nextLine: String = br.readLine
  }

}

import java.io._
import java.util.StringTokenizer
import scala.util.Try

object Sol extends App {
  val (in, out) = Try {(
    new Reader("input.txt"),
    new PrintWriter(new BufferedWriter(new FileWriter("output.txt")))
  )} getOrElse {(
    new Reader(),
    new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
  )}

  val n = in.nextInt
  val a = in.nextLine.split(" ").map(_.toInt)
  def move(x: Int, y: Int) = if ((x - y).abs == 1) 1 else 0
  def cost(pos: Int): Int = a.foldLeft(0)((acc, cur) => acc + move(pos, cur))

  out.println(a.map(cost).min)
  out.flush()
  out.close()

  class Reader() {
    var br: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    var tok: StringTokenizer = null

    def this(file: String) {
      this()
      br = new BufferedReader(new FileReader(file))
    }

    def next: String = {
      while (tok == null || !tok.hasMoreElements)
        tok = new StringTokenizer(br.readLine)
      tok.nextToken
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    def nextDouble: Double = next.toDouble

    def nextLine: String = br.readLine
  }

}


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

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

    def main(args: Array[String]): Unit = {
        val max_n = 200010
        var a = new Array[Int](max_n)
        val t = readInt()
        for (tt <- 1 to t) {
            var d = Map[Int, ArrayBuffer[Int]]()
            val n = readInt()
            val k = readInt()
            for (i <- 1 to n) {
                val x = readInt()
                if (! d.contains(x))
                    d(x) = new ArrayBuffer[Int]()
                if (d(x).length < k)
                    d(x).append(i)
            }
            var cnt = 0
            for ((key, value) <- d)
                cnt += value.length
            cnt -= cnt % k
            for ((key, value) <- d) {
                var i = 0
                while (cnt > 0 && i < value.length) {
                    a(value(i)) = if (cnt % k > 0) cnt % k else k
                    cnt -= 1
                    i += 1
                }
            }
            for (i <- 1 to n) {
                writer.print(a(i) + " ")
                a(i) = 0
            }
            writer.println()
            writer.flush()
        }
    }
}

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

  val t = readInt()

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

    val cn = Array.fill(n)(0)

    val in = {
      val ai2is = Array.fill(n + 1)(List.empty[Int])
      (0 until n).foreach { i => ai2is(an(i)) ::= i }
      ai2is.flatMap(_.take(k))
    }

    ((in.length % k) until in.length).foreach { j =>
      val (i, ci) = (in(j), (j % k) + 1)
      cn(i) = ci
    }

    println(cn.mkString(" "))
  }
}

object B2 extends App {
  import scala.reflect._
  import scala.io.StdIn._

  val t = readInt()

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

    val cn = {
      val cn = Array.fill(n)(0)

      val in = {
        val ai2is = Array.fill(n + 1)(List.empty[Int])
        (0 until n).foreach(i => ai2is(an(i)) ::= i)
        ai2is.flatMap(_.take(k))
      }

      ((in.length % k) until in.length).foreach { j =>
        val (i, ci) = (in(j), (j % k) + 1)
        cn(i) = ci
      }

      cn
    }

    println(cn.mkString(" "))
  }
}

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

  val t = readInt()

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

    val cn = {
      val counts = {
        val array = Array.fill(n + 1)(0)
        an.foreach { ai => array(ai) = k min (array(ai) + 1) }
        array.map { c => (c, c == k) }
      }

      var color  = k
      var ignore = counts.foldLeft(0) {
        case (sum, (count, false)) if count > 0 => (sum + count) % k
        case (sum, _)                           => sum
      }

      an.map { ai =>
        counts(ai) match {
          case (ci, true) =>
            counts(ai) = (0 max (ci - 1), true)
            ci
          case (_, false) =>
            if (ignore > 0) {
              ignore -= 1
              0
            } else {
              val ci = color
              color = if (color == 1) k else (color - 1)
              ci
            }
        }
      }
    }

    println(cn.mkString(" "))
  }
}

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

  val t = readInt()

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

    val cn = {
      val counts = {
        val array = Array.fill(n + 1)(0)
        an.foreach { ai => array(ai) = k min (array(ai) + 1) }

        array.map(c => (c, c == k))
      }

      var color    = k
      var composed = counts.foldLeft(0) {
        case (sum, (c, _)) if c < k => sum + c
        case (sum, _)               => sum
      } / k

      an.map { ai =>
        counts(ai) match {
          case (ci, true) if ci > 0                  =>
            counts(ai) = (ci - 1, true)
            ci
          case (ci, false) if ci > 0 && composed > 0 =>
            counts(ai) = (ci - 1, false)
            val cj = color
            if (color == 1) {
              color = k
              composed -= 1
            } else {
              color -= 1
            }
            cj
          case _                                     => 0
        }
      }

    }

    println(cn.mkString(" "))
  }
}


object C1060 {
  def main(args: Array[String]): Unit = {
    val stdin = scala.io.StdIn
    val temp = stdin.readLine.split(" ")
    val (n, m) = (temp(0).toInt, temp(1).toInt)
    val a = stdin.readLine.trim.split(" ").map(_.toLong)
    val b = stdin.readLine.trim.split(" ").map(_.toLong)
    val x = stdin.readInt()

    import scala.util.control.Breaks._
    def sum(array: Array[Long]):Array[Long] ={
      val res = Array.fill[Long](array.length)(Long.MaxValue)
      for (i <- array.indices){
        var temp = 0L
        for (j <- array.indices if i+j < array.length){
          temp = temp + array(i+j)
          res(j) = math.min(res(j), temp)
        }
      }
      res
    }

    val (sa, sb) = (sum(a), sum(b))
    var ans = 0
    for (i <- sa.indices){
      breakable{
        for (j <- sb.indices){
          if (sa(i) * sb(j) <= x){
            ans = math.max(ans, (i+1)*(j+1))
          } else break
        }
      }

    }

    println(ans)
  }
}

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, M = ni()
    val A = na(N)
    val B = na(M)
    val X = ni()

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

    def calcMinLen(n: Int, cum: Array[Int]) = {
      val len = Array.fill[Int](2001)(Integer.MAX_VALUE)
      rep(n) { l =>
        l until n foreach { r =>
          val i = r - l + 1
          len(i) = min(len(i), cum(r + 1) - cum(l))
        }
      }
      len
    }

    val cumA = cum(A)
    val cumB = cum(B)

    val minALen = calcMinLen(N, cumA)
    val minBLen = calcMinLen(M, cumB)

    var ans = 0
    rep(2000, 1) { aLen =>
      rep(2000, 1) { bLen =>
        val v = minALen(aLen).toLong * minBLen(bLen)
        if (v <= X) ans = max(ans, aLen * bLen)
      }
    }

    out.println(ans)
  }

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

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

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

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

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

object C1060 {
  def main(args: Array[String]): Unit = {
    val stdin = scala.io.StdIn
    val temp = stdin.readLine.split(" ")
    val (n, m) = (temp(0).toInt, temp(1).toInt)
    val a = stdin.readLine.trim.split(" ").map(_.toLong)
    val b = stdin.readLine.trim.split(" ").map(_.toLong)
    val x = stdin.readInt()

    def sum(array: Array[Long]): Array[Long] = {
      val res = Array.fill[Long](array.length)(Long.MaxValue)
      for (i <- array.indices) {
        var temp = 0L
        for (j <- array.indices if i + j < array.length) {
          temp = temp + array(i + j)
          res(j) = math.min(res(j), temp)
        }
      }
      res
    }

    val (sa, sb) = (sum(a), sum(b))
    var ans = 0
    for (i <- sa.indices) {
      for (j <- sb.indices if sa(i) * sb(j) <= x) {
        ans = math.max(ans, (i + 1) * (j + 1))
      }
    }

    println(ans)
  }
}


object Main extends App {
  val r = new FastScanner(java.lang.System.in)
  val o = new java.io.PrintWriter(java.lang.System.out)
  for(_ <- 1 to r.nextInt()) {
    val s = r.nextToken()
    o.print(s(0))
    for(k <- 1 until s.length by 2) {
      o.print(s(k))
    }
    o.println()
  }
  o.close()
}

import scala.annotation.tailrec
import scala.collection.mutable.StringBuilder

object FastScanner {
  val zero = 0.toByte
  val cr = '\r'.toByte
  val nl = '\n'.toByte
  val BUFFER_SIZE = 0x10000
}

class FastScanner(private val input: java.io.InputStream) {
  private val b = new Array[Byte](FastScanner.BUFFER_SIZE)
  private var n = 0
  private var pos = 0
  private var eof = false
  private def read ():Boolean = {
    if (eof) {
      return false
    }
    pos = 0
    n = input.read(b)
    if (n < 0) {
      eof = true
    }
    n > 0
  }
  private def nextByte(): Byte = {
    if (pos >= n && !read ()) {
      0
    } else {
      val r = b(pos)
      pos += 1
      r
    }
  }
  def nextToken(k: Int = -1): String = {
    val sb = if(k >= 0) new StringBuilder(k) else new StringBuilder()
    var b = skipBlanks()
    assert(b > 0)
    while(b > 32) {
      sb.append(b.toChar)
      b = nextByte()
    }
    sb.toString
  }
  @tailrec
  private def skipBlanks(): Byte = {
    val b = nextByte()
    if(b > 32 || b < 1) b else skipBlanks()
  }
  def nextInt():Int = {
    val b = skipBlanks()
    @tailrec
    def f(t: Int): Int = {
      val b = nextByte ()
      if (b <= 32) t else f(10 * t + (b - 48))
    }
    require(b > 0)
    if (b < 48) -f(0) else f(b - 48)
  }
}

//package codeforces.contests._1367

object _1 {

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {

      val s = io.StdIn.readLine
      println(s.indices.by(2).map(s).mkString + s.last)
    }
  }

}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val b = readLine().toCharArray.toList
      handle(b)
    }
  }

  def handle(list: List[Char]): Unit = {
    print(list.head)
    list.tail.zipWithIndex.foreach(tup => if (tup._2 % 2 == 0) print(tup._1))
    println()
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}

object Solution {
  def main(args: Array[String]): Unit = {
    import scala.io.StdIn
    val n = StdIn.readLine().toInt
    for (_ <- 1 to n) {
      val str = StdIn.readLine()
      var res = "" + str.head
      for (i <- 1 until str.length by 2) {
        res += str(i)
      }
      println(res)
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val b = readLine()
    val a = b.init.zipWithIndex.collect { case (c, i) if i % 2 == 0 => c }.mkString + b.last

    println(a)
  }
}

import scala.io.StdIn._

object A extends App {

  val t = readInt()
  1 to t foreach { _ =>
    val A = readLine().toCharArray
    val a = A(0)
    val b = A(1)

    val rest = 3 until A.length by 2 map { i =>
      A(i)
    }

    println("" + a + b + rest.mkString)
  }

}

object A extends App {

  import java.io.{PrintWriter}
  import java.util.{Locale, Scanner}

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

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

  def solve = {
    var n = nextInt

    1.to(n).foreach(_ => {
      val b = nextString
      val max = b.length
      for (a <- 0 until max by 2){
        print(b(a))
      }
      println(b(max - 1))
    })

//    out.println(a.reduceLeft[Int](_+_))
  }

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


import scala.collection.mutable

object D extends App {

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

  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def pow(n: Long, p: Int): Long = {
    var res = 1L
    var i = 0
    while (i < p) {
      res *= n
      i += 1
    }
    res
  }

  def root(number: Long, p: Int): Long = {
    var n = Math.pow(number, 1d / p).toLong
    while (pow(n + 1, p) <= number) n += 1
    n
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }
  val as0 = as.clone()

  val divisors = mutable.LongMap.empty[Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (i <- as.indices) if (as(i) > 1) {
    val r4 = root(as(i), 4)
    if (as(i) == pow(r4, 4)) {
      add(r4, 4)
      as(i) = 1
    } else {
      val r3 = root(as(i), 3)
      if (as(i) == pow(r3, 3)) {
        add(r3, 3)
        as(i) = 1
      } else {
        val r2 = root(as(i), 2)
        if (as(i) == pow(r2, 2)) {
          add(r2, 2)
          as(i) = 1
        }
      }
    }
  }

  val gcds = mutable.Set.empty[Long]
  gcds ++= divisors.keys

  var i = 0
  while (i < n) {
    if (as(i) > 1) {
      var j = i + 1
      while (j < n) {
        if (as(j) > 1) {}
        val d = gcd(as(i), as(j))
        if (d > 1) gcds += d
        j += 1
      }
    }
    i += 1
  }

  for (g <- gcds) {
    var i = 0
    while (i < n) {
      if (as(i) != g && as(i) % g == 0) {
        add(g, 1)
        as(i) /= g
        if (as(i) > 1) {
          add(as(i), 1)
          as(i) = 1
        }
      }
      i += 1
    }
  }

  val composites = mutable.LongMap.empty[Int].withDefaultValue(0)
  i = 0
  while (i < n) {
    if (as(i) == as0(i)) composites(as(i)) += 1
    i += 1
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for ((_, v) <- composites) {
    res = res * (v + 1) * (v + 1) % MOD
  }

  println(res)
}

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 = 998244353
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = nal(N)
    val f = mutable.Map[Long, Int]() withDefaultValue 0
    val ab = mutable.Map[Long, Int]() withDefaultValue 0

    rep(N) { i =>
      val sqrt = math.sqrt(A(i)).toLong
      val cbrb = math.cbrt(A(i)).toLong
      val quort = math.sqrt(sqrt).toLong
      if (quort * quort * quort * quort == A(i)) {
        f(quort) = f(quort) + 4
      } else if (sqrt * sqrt == A(i)) {
        f(sqrt) = f(sqrt) + 2
      } else if (cbrb * cbrb * cbrb == A(i)) {
        f(cbrb) = f(cbrb) + 3
      } else {
        ab(A(i)) = ab(A(i)) + 1
      }
    }

    val ab_seq = ab.keys.toSeq
    val ab_f = mutable.Set[Long]()
    rep(ab_seq.length) { i =>
      i + 1 until ab_seq.length foreach { j =>
        val g = gcd(ab_seq(i), ab_seq(j))
        if (g > 1) {
          ab_f += g
          ab_f += ab_seq(i) / g
          ab_f += ab_seq(j) / g
        }
      }
    }

    def findFactor(a: Long): Option[Long] = {
      f.keys.find(a % _ == 0) orElse ab_f.find(a % _ == 0)
    }

    var ans = 1L
    ab_seq.zipWithIndex foreach { case (x, i) =>
      val cnt = ab(x)
      findFactor(x) match {
        case Some(a) =>
          val b = x / a
          f(a) = f(a) + cnt
          f(b) = f(b) + cnt

        case None => ans = ans * (cnt + 1) * (cnt + 1) % MOD
      }
    }

    f.foreach { case (_, cnt) =>
      ans = ans * (cnt + 1) % MOD
    }

    out.println(ans)
  }

  def gcd(a: Long, b: Long): Long = {
    if (b == 0) a
    else gcd(b, a % b)
  }

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

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

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

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

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

import scala.collection.mutable

object D extends App {

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

  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def pow(n: Long, p: Int): Long = {
    var res = 1L
    var i = 0
    while (i < p) {
      res *= n
      i += 1
    }
    res
  }

  def root(number: Long, p: Int): Long = {
    var n = Math.pow(number, 1d / p).toLong
    while (pow(n + 1, p) <= number) n += 1
    n
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }

  val divisors = mutable.LongMap.empty[Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (i <- as.indices) if (as(i) > 1) {
    val r4 = root(as(i), 4)
    if (as(i) == pow(r4, 4)) {
      add(r4, 4)
      as(i) = 1
    } else {
      val r3 = root(as(i), 3)
      if (as(i) == pow(r3, 3)) {
        add(r3, 3)
        as(i) = 1
      } else {
        val r2 = root(as(i), 2)
        if (as(i) == pow(r2, 2)) {
          add(r2, 2)
          as(i) = 1
        }
      }
    }
  }

  val gcds = mutable.Set.empty[Long]
  gcds ++= divisors.keys

  for {
    i <- 0 until n
    if as(i) > 1
    j <- i + 1 until n
    if as(j) > 1
    d = gcd(as(i), as(j))
    if d > 1
  } gcds += d

  for {
    g <- gcds.toSeq.sorted
    i <- 0 until n
    if as(i) != g && as(i) % g == 0
  } {
    add(g, 1)
    as(i) /= g
    if (as(i) > 1) {
      add(as(i), 1)
      as(i) = 1
    }
  }

  val composites = mutable.LongMap.empty[Int].withDefaultValue(0)
  for (a <- as) if (a > 1) composites(a) += 1

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for ((_, v) <- composites) {
    res = res * (v + 1) * (v + 1) % MOD
  }

  println(res)
}

import scala.collection.mutable

object D 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)) }

  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def sqrt(number: Long): Long = {
    def next(n: Long, i: Long): Long = (n + i / n) >> 1

    val one = 1L

    var n = one
    var n1 = next(n, number)

    while ((n1 - n).abs > one) {
      n = n1
      n1 = next(n, number)
    }

    while (n1 * n1 > number) {
      n1 -= one
    }

    n1
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }

  val LIMIT = 1259929
  val LIMIT_SQRT = Math.sqrt(LIMIT).toInt + 1
  val isPrime = Array.fill(LIMIT)(true)
  val primesBuilder = new mutable.ArrayBuilder.ofInt
  primesBuilder += 2
  isPrime(0) = false
  isPrime(1) = false

  var i = 4
  while (i < LIMIT) {
    isPrime(i) = false
    i += 2
  }
  i = 3
  while (i <= LIMIT_SQRT) {
    if (isPrime(i)) {
      primesBuilder += i
      var j = i * i
      val ii = i + i
      while (j < LIMIT) {
        isPrime(j) = false
        j += ii
      }
    }
    i += 2
  }

  val primes = primesBuilder.result()

  val divisors = mutable.Map.empty[Long, Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (j <- as.indices) {
    var aa = as(j)
    var i = 0
    while (i < primes.length && aa >= primes(i)) {
      val p = primes(i)
      if (aa % p == 0) {
        aa /= p
        add(p, 1)
      } else i += 1
    }
    as(j) = aa
  }

  val gcdsBuilder = new mutable.ArrayBuilder.ofLong
  val haveGcd = mutable.Set.empty[Long]

  i = 0
  while (i < n) {
    if (as(i) > 1) {
      var j = i + 1
      while (j < n) {
        if (as(j) > 1) {
          val d = gcd(as(i), as(j))
          if (d > 1 && !haveGcd(d)) {
            gcdsBuilder += d
            haveGcd += d
          }
        }
        j += 1
      }
    }
    i += 1
  }

  val gcds = gcdsBuilder.result()
  var j = 0
  while (j < gcds.length) {
    val g = gcds(j)
    var i = 0
    while (i < as.length) {
      if (as(i) % g == 0) {
        as(i) /= g
        add(g, 1)
      }
      i += 1
    }
    j += 1
  }

  var unknownDivisors = 0
  for (i <- as.indices) if (as(i) > 1) {
    val r = sqrt(as(i))
    if (as(i) == r * r) add(r, 2)
    else {
      if ((as(i) < isPrime.length && isPrime(as(i).toInt))
        || BigInt(as(i)).isProbablePrime(20)) add(as(i), 1)
      else unknownDivisors += 2
    }
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for (_ <- 1 to unknownDivisors) res = res * 2 % MOD

  println(res)
}

import scala.collection.mutable

object D 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 gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def next(n: Long, i: Long): Long = (n + i / n) >> 1

  def pow(n: Long, p: Int): Long = {
    var res = 1L
    for (_ <- 1 to p) res *= n
    res
  }

  def root(number: Long, p: Int): Long = {

    var n = 1L
    var n1 = next(n, number)

    while ((n1 - n).abs > 1) {
      n = n1
      n1 = next(n, number)
    }

    while (pow(n1, p) > number) n1 -= 1

    n1
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }
  val as0 = as.clone()

  val divisors = mutable.Map.empty[Long, Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (i <- as.indices) if (as(i) > 1) {
    val r4 = root(as(i), 4)
    if (as(i) == pow(r4, 4)) {
      add(r4, 3)
      as(i) = r4
    } else {
      val r3 = root(as(i), 3)
      if (as(i) == pow(r3, 3)) {
        add(r3, 2)
        as(i) = r3
      } else {
        val r2 = root(as(i), 2)
        if (as(i) == pow(r2, 2)) {
          add(r2, 1)
          as(i) = r2
        }
      }
    }
  }

  val gcds = mutable.Set.empty[Long]
  for {
    i <- 0 until n
    if as(i) > 1
    j <- i + 1 until n
    if as(j) > 1
    d = gcd(as(i), as(j))
    if d > 1
  } gcds += d

  for {
    g <- gcds
    i <- 0 until n
    if as(i) % g == 0
  } {
    as(i) /= g
    add(g, 1)
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for (i <- 0 until n) {
    if (as(i) > 1) {
      res = if (as(i) == as0(i)) res * 4 % MOD else res * 2 % MOD
    }
  }

  println(res)
}

import scala.collection.mutable

object D 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 gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def next(n: Long, i: Long): Long = (n + i / n) >> 1

  def pow(n: Long, p: Int): Long = {
    var res = 1L
    for (_ <- 1 to p) res *= n
    res
  }

  def root(number: Long, p: Int): Long = {

    var n = 1L
    var n1 = next(n, number)

    while ((n1 - n).abs > 1) {
      n = n1
      n1 = next(n, number)
    }

    while (pow(n1, p) > number) n1 -= 1

    n1
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }
  val as0 = as.clone()

  val divisors = mutable.Map.empty[Long, Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (i <- as.indices) if (as(i) > 1) {
    val r4 = root(as(i), 4)
    if (as(i) == pow(r4, 4)) {
      add(r4, 3)
      as(i) = r4
    } else {
      val r3 = root(as(i), 3)
      if (as(i) == pow(r3, 3)) {
        add(r3, 2)
        as(i) = r3
      } else {
        val r2 = root(as(i), 2)
        if (as(i) == pow(r2, 2)) {
          add(r2, 1)
          as(i) = r2
        }
      }
    }
  }

  val gcds = mutable.Set.empty[Long]
  for {
    i <- 0 until n
    if as(i) > 1
    j <- i + 1 until n
    if as(j) > 1
    d = gcd(as(i), as(j))
    if d > 1
  } gcds += d

  for {
    g <- gcds
    i <- 0 until n
    if as(i) % g == 0
  } {
    as(i) /= g
    add(g, 1)
  }

  var unknownDivisors = 0
  for (i <- 0 until n) {
    if (as(i) > 1) {
      if (divisors.contains(as(i))) add(as(i), 1)
      else if (as(i) == as0(i)) unknownDivisors += 2
      else unknownDivisors += 1
    }
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for (_ <- 1 to unknownDivisors) res = res * 2 % MOD

  println(res)
}

import scala.collection.mutable

object D 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)) }

  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def sqrt(number: Long): Long = {
    def next(n: Long, i: Long): Long = (n + i / n) >> 1

    val one = 1L

    var n = one
    var n1 = next(n, number)

    while ((n1 - n).abs > one) {
      n = n1
      n1 = next(n, number)
    }

    while (n1 * n1 > number) {
      n1 -= one
    }

    n1
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }

  val LIMIT = 1259929
  val isPrime = Array.fill(LIMIT)(true)
  isPrime(0) = false
  isPrime(1) = false

  var i = 2
  while (i * i < LIMIT) {
    if (isPrime(i)) {
      var j = i * i
      val ii = i + i
      while (j < LIMIT) {
        isPrime(j) = false
        j += ii
      }
    }
    i += 1
  }

  val primes = Array.ofDim[Int](97178)
  i = 0
  var j = 0
  while (i < LIMIT) {
    if (isPrime(i)) {
      primes(j) = i
      j += 1
    }
    i += 1
  }

  val divisors = mutable.Map.empty[Long, Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (j <- as.indices) {
    var aa = as(j)
    var i = 0
    while (i < primes.length && aa >= primes(i)) {
      val p = primes(i)
      if (aa % p == 0) {
        aa /= p
        add(p, 1)
      } else i += 1
    }
    as(j) = aa
  }

  val gcdsBuilder = new mutable.ArrayBuilder.ofLong
  val haveGcd = mutable.Set.empty[Long]

  i = 0
  while (i < n) {
    if (as(i) > 1) {
      var j = i + 1
      while (j < n) {
        if (as(j) > 1) {
          val d = gcd(as(i), as(j))
          if (d > 1 && !haveGcd(d)) {
            gcdsBuilder += d
            haveGcd += d
          }
        }
        j += 1
      }
    }
    i += 1
  }

  val gcds = gcdsBuilder.result()
  j = 0
  while (j < gcds.length) {
    val g = gcds(j)
    var i = 0
    while (i < as.length) {
      if (as(i) % g == 0) {
        as(i) /= g
        add(g, 1)
      }
      i += 1
    }
    j += 1
  }

  var unknownDivisors = 0
  for (i <- as.indices) if (as(i) > 1) {
    val r = sqrt(as(i))
    if (as(i) == r * r) add(r, 2)
    else {
      if ((as(i) < isPrime.length && isPrime(as(i).toInt))
        || BigInt(as(i)).isProbablePrime(20)) add(as(i), 1)
      else unknownDivisors += 2
    }
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for (_ <- 1 to unknownDivisors) res = res * 2 % MOD

  println(res)
}

import scala.collection.mutable

object D 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)) }

  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def sqrt(number: Long): Long = {
    def next(n: Long, i: Long): Long = (n + i / n) >> 1

    val one = 1L

    var n = one
    var n1 = next(n, number)

    while ((n1 - n).abs > one) {
      n = n1
      n1 = next(n, number)
    }

    while (n1 * n1 > number) {
      n1 -= one
    }

    n1
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }

  val LIMIT = 1259929
  val LIMIT_SQRT = Math.sqrt(LIMIT).toInt + 1
  val isPrime = Array.fill(LIMIT)(true)
  val primesBuilder = new mutable.ArrayBuilder.ofInt
  primesBuilder += 2
  isPrime(0) = false
  isPrime(1) = false

  var i = 4
  while (i < LIMIT) {
    isPrime(i) = false
    i += 2
  }
  i = 3
  while (i * i < LIMIT_SQRT) {
    if (isPrime(i)) {
      primesBuilder += i
      var j = i * i
      val ii = i + i
      while (j < LIMIT) {
        isPrime(j) = false
        j += ii
      }
    }
    i += 2
  }

  val primes = primesBuilder.result()

  val divisors = mutable.Map.empty[Long, Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (j <- as.indices) {
    var aa = as(j)
    var i = 0
    while (i < primes.length && aa >= primes(i)) {
      val p = primes(i)
      if (aa % p == 0) {
        aa /= p
        add(p, 1)
      } else i += 1
    }
    as(j) = aa
  }

  val gcdsBuilder = new mutable.ArrayBuilder.ofLong
  val haveGcd = mutable.Set.empty[Long]

  i = 0
  while (i < n) {
    if (as(i) > 1) {
      var j = i + 1
      while (j < n) {
        if (as(j) > 1) {
          val d = gcd(as(i), as(j))
          if (d > 1 && !haveGcd(d)) {
            gcdsBuilder += d
            haveGcd += d
          }
        }
        j += 1
      }
    }
    i += 1
  }

  val gcds = gcdsBuilder.result()
  var j = 0
  while (j < gcds.length) {
    val g = gcds(j)
    var i = 0
    while (i < as.length) {
      if (as(i) % g == 0) {
        as(i) /= g
        add(g, 1)
      }
      i += 1
    }
    j += 1
  }

  var unknownDivisors = 0
  for (i <- as.indices) if (as(i) > 1) {
    val r = sqrt(as(i))
    if (as(i) == r * r) add(r, 2)
    else {
      if ((as(i) < isPrime.length && isPrime(as(i).toInt))
        || BigInt(as(i)).isProbablePrime(20)) add(as(i), 1)
      else unknownDivisors += 2
    }
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for (_ <- 1 to unknownDivisors) res = res * 2 % MOD

  println(res)
}

import scala.collection.mutable

object D 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)) }

  def gcd(x: Long, y: Long): Long = if (y == 0) x else gcd(y, x % y)

  def sqrt(number: Long): Long = {
    def next(n: Long, i: Long): Long = (n + i / n) >> 1

    val one = 1L

    var n = one
    var n1 = next(n, number)

    while ((n1 - n).abs > one) {
      n = n1
      n1 = next(n, number)
    }

    while (n1 * n1 > number) {
      n1 -= one
    }

    n1
  }

  val Array(n) = readInts(1)
  val as = Array.fill(n){ readLine.toLong }

  val LIMIT = 1259929
  val LIMIT_SQRT = Math.sqrt(LIMIT).toInt + 1
  val isPrime = Array.fill(LIMIT)(true)
  val primesBuilder = new mutable.ArrayBuilder.ofInt
  isPrime(0) = false
  isPrime(1) = false

  var i = 4
  while (i < LIMIT) {
    isPrime(i) = false
    i += 2
  }
  i = 3
  while (i * i < LIMIT_SQRT) {
    if (isPrime(i)) {
      primesBuilder += i
      var j = i * i
      val ii = i + i
      while (j < LIMIT) {
        isPrime(j) = false
        j += ii
      }
    }
    i += 2
  }

  val primes = primesBuilder.result()

  val divisors = mutable.Map.empty[Long, Int].withDefaultValue(0)

  def add(p: Long, cnt: Int): Unit = {
    divisors(p) += cnt
  }

  for (j <- as.indices) {
    var aa = as(j)
    var i = 0
    while (i < primes.length && aa >= primes(i)) {
      val p = primes(i)
      if (aa % p == 0) {
        aa /= p
        add(p, 1)
      } else i += 1
    }
    as(j) = aa
  }

  val gcdsBuilder = new mutable.ArrayBuilder.ofLong
  val haveGcd = mutable.Set.empty[Long]

  i = 0
  while (i < n) {
    if (as(i) > 1) {
      var j = i + 1
      while (j < n) {
        if (as(j) > 1) {
          val d = gcd(as(i), as(j))
          if (d > 1 && !haveGcd(d)) {
            gcdsBuilder += d
            haveGcd += d
          }
        }
        j += 1
      }
    }
    i += 1
  }

  val gcds = gcdsBuilder.result()
  var j = 0
  while (j < gcds.length) {
    val g = gcds(j)
    var i = 0
    while (i < as.length) {
      if (as(i) % g == 0) {
        as(i) /= g
        add(g, 1)
      }
      i += 1
    }
    j += 1
  }

  var unknownDivisors = 0
  for (i <- as.indices) if (as(i) > 1) {
    val r = sqrt(as(i))
    if (as(i) == r * r) add(r, 2)
    else {
      if ((as(i) < isPrime.length && isPrime(as(i).toInt))
        || BigInt(as(i)).isProbablePrime(20)) add(as(i), 1)
      else unknownDivisors += 2
    }
  }

  val MOD = 998244353L
  var res = 1L
  for ((_, v) <- divisors) {
    res = res * (v + 1) % MOD
  }
  for (_ <- 1 to unknownDivisors) res = res * 2 % MOD

  println(res)
}


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, q) = readLongs(2)

  val res = Array.ofDim[Long](q.toInt)
  val half = n * n / 2

  for (i <- 0 until q.toInt) {
    val Array(x, y) = readLongs(2)
    val xy = (x - 1) * n + y - 1
    res(i) = if ((x + y) % 2 == 0) xy / 2 + 1 else half + xy / 2 + 1 + n % 2
  }

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

  println(res.mkString("\n"))

  Console.flush
}

object 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 sc = new InputReader(System.in)
    val N = sc.nextLong()
    val Q = sc.nextInt()
    rep(Q) { i =>
      var x, y = sc.nextInt() - 1
      if ((x + y) % 2 == 1) x += N.toInt
      val ans =
        x / 2 * N +
          (if(x % 2 == 1) (N - 1) / 2 + 1 else 0) +
          y / 2 +
          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 B extends App {

  def solve(in: InputReader): Unit = {
    val sb = StringBuilder.newBuilder
    val n = in.nextLong
    val q = in.nextInt

    for (_ <- 1 to q) {
      val y = in.nextLong
      val x = in.nextLong
      val r = if (x % 2 == 1 && y % 2 == 1)
        y / 2 * n + (x + 1) / 2
      else if (x % 2 == 0 && y % 2 == 1)
        (n * n + 1) / 2 + y / 2 * n + x / 2
      else if (x % 2 == 1 && y % 2 == 0)
        (n + 1) * n / 2 + (y - 1) / 2 * n + (x + 1) / 2
      else
        (y / 2 * n) - (n - x) / 2
      sb.append(r)
      sb.append('\n')
    }
    print(sb.toString())
  }

  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 nextLong: Long = {
      next.toLong
    }

    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 B extends App {

  def solve(in: InputReader): Unit = {
    val sb = StringBuilder.newBuilder
    val n = in.nextInt
    val q = in.nextInt

    for (i <- 1 to q) {
      val y = in.nextInt.toLong
      val x = in.nextInt.toLong
      val r = if (x % 2 == 1 && y % 2 == 1)
        y / 2 * n + (x + 1) / 2
      else if (x % 2 == 0 && y % 2 == 1)
        (n * n + 1) / 2 + y / 2 * n + x / 2
      else if (x % 2 == 1 && y % 2 == 0)
        (n + 1) * n / 2 + (y - 1) / 2 * n + (x + 1) / 2
      else
        (y / 2 * n) - (n - x) / 2
      sb.append(r)
      if (i != q)
        sb.append('\n')
    }
    println(sb.toString())
  }

  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 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 B extends App {

  def solve(in: InputReader): Unit = {
    val out = new PrintWriter(System.out)
    val n = in.nextInt
    val q = in.nextInt

    for (_ <- 1 to q) {
      val y = in.nextInt.toLong
      val x = in.nextInt.toLong
      val r = if (x % 2 == 1 && y % 2 == 1)
        y / 2 * n + (x + 1) / 2
      else if (x % 2 == 0 && y % 2 == 1)
        (n * n + 1) / 2 + y / 2 * n + x / 2
      else if (x % 2 == 1 && y % 2 == 0)
        (n + 1) * n / 2 + (y - 1) / 2 * n + (x + 1) / 2
      else
        (y / 2 * n) - (n - x) / 2
      out.println(r)
    }
  }

  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 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 B extends App {

  def solve(in: InputReader): Unit = {
    val out = new PrintWriter(System.out)
    val n = in.nextInt
    val q = in.nextInt

    for (_ <- 1 to q) {
      val x = in.nextInt.toLong
      val y = in.nextInt.toLong
      val r = if (x % 2 == 1 && y % 2 == 1)
        y / 2 * n + (x + 1) / 2
      else if (x % 2 == 0 && y % 2 == 1)
        (n * n + 1) / 2 + y / 2 * n + x / 2
      else if (x % 2 == 1 && y % 2 == 0)
        (n + 1) * n / 2 + (y - 1) / 2 * n + (x + 1) / 2
      else
        (y / 2 * n) - (n - x) / 2
      out.println(r)
    }
  }

  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 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.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

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

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

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

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

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

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

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

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

object Workspace {
  import Main._
}

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

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

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

  def solve(): Unit = {
    val n = ni()
    val s = ns(n)
    var bal = 0

    val bals = Array.ofDim[Int](n)
    val cum = cumSum(s.map {
      case '(' => 1
      case ')' => -1
      case '?' => 0
    })
    val cumQ = cumSum(s.map {
      case '?' => 1
      case _ => 0
    })

    REP(n) { i =>
      if (s(i) == '(') {
        bal += 1
      } else if (s(i) == ')') {
        bal -= 1
      } else {
        if (bal + 1 + cum(n) - cum(i + 1) <= cumQ(n) - cumQ(i + 1)) {
          s(i) = '('
          bal += 1
        } else {
          s(i) = ')'
          bal -= 1
        }
      }
      bals(i) = bal
    }

    debug(bals)
    val ok = bal == 0 && bals.dropRight(1).forall(a => a > 0)

    if (ok) out.println(s.mkString)
    else out.println(":(")
  }
}

import java.io.FileInputStream
import scala.collection.mutable.TreeSet

object HelloWorld {

    import scala.io.StdIn.{readInt, readLine}

    def main(args: Array[String]): Unit = {
        val n = readInt
        val str = readLine

        val ls = str.count(p => p == '(')

        var newLs = n / 2 - ls
        val newStr = str.map(c => {
            if (c == '?') {
                if (newLs > 0) {
                    newLs -= 1
                    '('
                }
                else ')'
            } else c
        })

        var st = 0
        for ((c, i) <- newStr.zipWithIndex) {
            if (c == '(') st += 1
            else {
                st -= 1
                if (st <= 0 && i < n-1) {
                    println(":(")
                    System.exit(0)
                }
            }
        }

        if (st == 0) println(newStr)
        else println(":(")

    }
}


import scala.io.StdIn
import java.util.Scanner

object Main {
    def sort2(a: Array[Int], i: Int, j: Int) = {
        if(a(i) > a(j)){
            val tmp = a(i)
            a(i) = a(j)
            a(j) = tmp
        }
    }

    def solve() = {
        var a = new Array[Int](3)
        val inp = StdIn.readLine()
        val line = new Scanner(inp)
        for (i <- 0 to 2){
            a(i) = line.nextInt()
        }
        // sort
        sort2(a, 0, 1)
        sort2(a, 1, 2)
        sort2(a, 0, 1)

        if(a(0) + a(1) == a(2)
                || (a(0) == a(1) && 0 == (a(2) % 2))
                || (a(1) == a(2) && 0 == (a(0) % 2))){
            println("YES")
        }else{
            println("NO")
        }
    }

    def main(args: Array[String]) = {
        val tc = StdIn.readInt()
        for (i <- 1 to tc) {
            solve()
        }
    }
}

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

    for (_ <- 1 to nextInt) {
      val ls = nextInts(3).sorted
      val ok = (ls(0) + ls(1) == ls(2)) || (ls(0) == ls(1) && ls(2) % 2 == 0) ||
        (ls(0) == ls(2) && ls(1) % 2 == 0) || (ls(2) == ls(1) && ls(0) % 2 == 0)

      out.println(if(ok) "YES" else "NO")
    }

    out.flush()
  }

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


//package codeforces

/*

http://codeforces.com/problemset/problem/839/C

 */
object Journeyy {

  type Graph = Map[Int, Set[Int]]

  def update(graph: Graph, x: Int, y: Int): Graph = {
    val setX: Set[Int] = graph.withDefaultValue(Set())(x)
    val setY: Set[Int] = graph.withDefaultValue(Set())(y)
    graph + (x -> (setX + y)) + (y -> (setY + x))
  }

  def main(args: Array[String]): Unit = {
    val n = io.StdIn.readInt()

    val graph: Graph = (1 until n).foldLeft[Graph](Map[Int, Set[Int]](1 -> Set(0)))((acc, _) => {
      val Array(x, y) = io.StdIn.readLine.split(" ").map(_.toInt)
      update(acc, x, y)
    })

    println(calculateExpectedValue(1, 0, 0, 1.0))

    def calculateExpectedValue(me: Int, parent: Int, distance: Int, probability: Double): Double = {
      if (graph(me).size == 1) {
        probability * distance
      } else {
        val count = graph(me).size - 1
        val updatedProbability = probability * (1.0/count)

        graph(me).filter(_ != parent)
          .foldLeft[Double](0.0)((acc, child) => acc + calculateExpectedValue(child, parent = me, distance + 1, updatedProbability))
      }
    }
  }

}

import scala.collection.mutable.ArrayBuffer

object Journey {
  var res=0D
  var graph:Array[ArrayBuffer[Int]]=null
  var vis:Array[Boolean]=null
  def main(args: Array[String]): Unit = {
    val in =scala.io.StdIn
    var n=in.readInt()
    graph=Array.fill[ArrayBuffer[Int]](n)(ArrayBuffer[Int]())
    for(_<- 0 until n-1){
      val edges=in.readLine().split(" ").map(_.toInt-1)
      graph(edges(0))+=edges(1)
      graph(edges(1))+=edges(0)
    }
    vis=Array.fill[Boolean](n)(false)
    dfs(0,1.0,0.0)
    println(res)
  }
  def dfs(u:Int,prob:Double,depth:Double):Unit={
    if(!vis(u)){
      vis(u)=true
      if(graph(u).length==1)
        res += depth * prob

      for(v<- 0 until graph(u).length){
        if(u==0)
          dfs(graph(u)(v),prob/(graph(u).length+0.0),depth+1)
        else
          dfs(graph(u)(v),prob/(graph(u).length-1.0),depth+1)
      }
    }
  }
}


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

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

    case class fenwick(n: Int) {
        val tree = new Array[Long](n+1)
        def query(ind: Int): Long = {
            var idx = ind
            var ans = 0L
            while (idx > 0) {
                ans += tree(idx)
                idx -= (idx & -idx)
            }
            return ans
        }
        def update(ind: Int, value: Long): Unit = {
            var idx = ind
            while (idx <= n) {
                tree(idx) += value
                idx += (idx & -idx)
            }
        }
    }

    case class pair(val a: Int, val b:  Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return a.compareTo(that.a)
        }
    }

    def gcd(a: Int, b: Int): Int = b match {
        case 0 => a
        case n => gcd(b, a % b)
    }
    val rem = 1000000007
    val mp = mutable.Map[Char, Int]()

    val t = readInt()
    for (tt <- 1 to t) {
        var n = readInt()
        var a = new Array[Int](n)
        var b = new Array[Int](n)
        for (i <- 1 to n)
            a(i-1) = readInt()
        for (i <- 1 to n)
            b(i-1) = readInt()
        quickSort(a)
        quickSort(b)
        var ans  = "YES"
        for (i <- 0 until n) {
            if (b(i) < a(i) || b(i) > a(i) + 1)
                ans = "NO"
            //writer.println(b(i) + " " + a(i))
        }
        writer.println(ans)
    }
    writer.flush()
}

import scala.io.StdIn

object ProblemC extends App {
  type TestCase = (Array[Int], Array[Int])
  type Result = String

  start()

  def start() = {
    println(parseInput(testCases).map(s => solve(s).mkString).mkString("\n"))
  }

  def testCases = StdIn.readLine.stripLineEnd.toInt

  def parseInput(testCases: Int): List[TestCase] = {
    var result: List[TestCase] = Nil
    for (_ <- 0.until(testCases)) {
      StdIn.readLine()
      val a = StdIn.readLine().split(" ").map(_.stripLineEnd.trim.toInt).toArray
      val b = StdIn.readLine().split(" ").map(_.stripLineEnd.trim.toInt).toArray
      result = (a,b) :: result
    }
    result.reverse
  }

  def solve(testCase: TestCase): Result = {
    (testCase._1.sorted zip testCase._2.sorted).map(ab => ab._1 - ab._2).forall(d => d == 0 || d == -1) match {
      case true => "YES"
      case false => "NO"
    }
  }

}

import scala.io.StdIn

object ProblemC extends App {
  type TestCase = (Array[Int], Array[Int])
  type Result = String

  start()

  def start() = {
    println(parseInput(testCases).map(s => solve(s).mkString).mkString("\n"))
  }

  def testCases = StdIn.readLine.stripLineEnd.toInt

  def parseInput(testCases: Int): List[TestCase] = {
    var result: List[TestCase] = Nil
    for (_ <- 0.until(testCases)) {
      StdIn.readLine()
      val a = StdIn.readLine().split(" ").map(_.stripLineEnd.trim.toInt).toArray
      val b = StdIn.readLine().split(" ").map(_.stripLineEnd.trim.toInt).toArray
      result = (a,b) :: result
    }
    result.reverse
  }

  def solve(testCase: TestCase): Result = {
    (testCase._1.sorted zip testCase._2.sorted).map(ab => ab._1 - ab._2).forall(diff => math.abs(diff) <= 1) match {
      case true => "YES"
      case false => "NO"
    }
  }

}


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

object _635B extends CodeForcesApp {
  override type Result = Boolean

  override def solve(read: InputReader) = {
    val n = read[Int]
    val a, b = read[IndexedSeq, Int](n).filter(_ != 0)
    (a ++: a) containsSlice b
  }

  override def format(result: Result) = if (result) "YES" else "NO"
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

  private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

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

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

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

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

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt - 1
  val data = in.next().split(' ').map(_.toInt).filter(_ > 0)
  val data1 = in.next().split(' ').map(_.toInt).filter(_ > 0)
  val index = data1.indexOf(data.head)
  if (data.take(n - index).mkString(" ") == data1.drop(index).mkString(" ") &&
      data.drop(n - index).mkString(" ") == data1.take(index).mkString(" "))
    println("YES")
  else
    println("NO")
}

/**
  * Created by octavian on 28/02/2016.
  */
object Island {

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

    //System.setIn(new FileInputStream("./src/island.in"))
    //System.setOut(new PrintStream(new FileOutputStream("./src/island.out")))

    var n = readInt()
    var a = readLine.split(" ").map(_.toInt).filter(_ != 0)
    var b = readLine.split(" ").map(_.toInt).filter(_ != 0)

    if(a.length != n - 1 || b.length != n - 1) {
      println("NO")
    }
    else {
      println(checkRotation(a, b, n))
    }
  }

  def checkRotation(a: Array[Int], b: Array[Int], n: Int): String = {
    val pos = posFirstElem(a(0), b)
    //println("pos is: " + pos)
    for(i <- 0 until n - 1) {
      //println("pos + i mod n: " + ((pos + i)%(n-1)))
      if(a(i) != b((pos + i)%(n - 1))) {
        return "NO"
      }
    }
    return "YES"
  }

  def posFirstElem(a0: Int, b: Array[Int]): Int = {
    for(i <- 0 until b.length) {
      if(a0 == b(i)) {
        return i
      }
    }
    return 0
  }

}

import java.util

import scala.collection._

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 = readInts(n).filter(_ != 0)
  val bs = readInts(n).filter(_ != 0)

  val ai = as.indexWhere(_ == 1)
  val bi = bs.indexWhere(_ == 1)

  val a2 = as.drop(ai) ++ as.take(ai)
  val b2 = bs.drop(bi) ++ bs.take(bi)

  val res = util.Arrays.equals(a2, b2)
  //println(a2.mkString(" "))
  //println(b2.mkString(" "))

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

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

object _635B extends CodeForcesApp {
  override type Result = Boolean

  override def solve(read: InputReader) = {
    val n = read[Int]
    val a = read[IndexedSeq, Int](n).filter(_ != 0)
    val b = read[IndexedSeq, Int](n).filter(_ != 0)
    (a ++: a) containsSlice b
  }

  override def format(result: Result) = if (result) "YES" else "NO"
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  type Result
  def solve(scanner: InputReader): Result
  def format(result: Result): String
  def apply(scanner: InputReader): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new InputReader(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
import java.io.{BufferedReader, Reader, InputStreamReader, StringReader, InputStream}
import java.util.StringTokenizer

class InputReader(reader: BufferedReader) extends Iterator[String] with AutoCloseable {
  def this(reader: Reader) = this(new BufferedReader(reader))
  def this(inputStream: InputStream) = this(new InputStreamReader(inputStream))
  def this(str: String) = this(new StringReader(str))

  private[this] val tokenizers = Iterator.continually(reader.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered

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

  def apply[A: Parser]: A = implicitly[Parser[A]].apply(this)

  def apply[C[_], A: Parser](n: Int)(implicit cbf: Parser.Collection[C, A]): C[A] = {
    val builder = cbf()
    for {_ <- 1 to n} builder += apply[A]
    builder.result()
  }

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

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

class Parser[A](val apply: InputReader => A) {
  def map[B](f: A => B): Parser[B] = new Parser(apply andThen f)
}
object Parser {
  type Collection[C[_], A] = scala.collection.generic.CanBuildFrom[C[A], A, C[A]]
  implicit def collection[C[_], A: Parser](implicit cbf: Collection[C, A])   : Parser[C[A]]            = new Parser(r => r[C, A](r[Int]))
  implicit val string                                                        : Parser[String]          = new Parser(_.next())
  implicit val char                                                          : Parser[Char]            = string.map(s => s.ensuring(_.length == 1, s"Expected Char; found $s").head)
  implicit val boolean                                                       : Parser[Boolean]         = string.map(_.toBoolean)
  implicit val int                                                           : Parser[Int]             = string.map(_.toInt)
  implicit val long                                                          : Parser[Long]            = string.map(_.toLong)
  implicit val bigInt                                                        : Parser[BigInt]          = string.map(BigInt(_))
  implicit val double                                                        : Parser[Double]          = string.map(_.toDouble)
  implicit val bigDecimal                                                    : Parser[BigDecimal]      = string.map(BigDecimal(_))
  implicit def tuple2[A: Parser, B: Parser]                                  : Parser[(A, B)]          = new Parser(r => (r[A], r[B]))
  implicit def tuple3[A: Parser, B: Parser, C: Parser]                       : Parser[(A, B, C)]       = new Parser(r => (r[A], r[B], r[C]))
  implicit def tuple4[A: Parser, B: Parser, C: Parser, D: Parser]            : Parser[(A, B, C, D)]    = new Parser(r => (r[A], r[B], r[C], r[D]))
  implicit def tuple5[A: Parser, B: Parser, C: Parser, D: Parser, E: Parser] : Parser[(A, B, C, D, E)] = new Parser(r => (r[A], r[B], r[C], r[D], r[E]))
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt).filter(_ > 0)
  val data1 = in.next().split(' ').map(_.toInt).filter(_ > 0)
  val index = data1.indexOf(data.head)
  println(index)
  if (data.take(n - index).mkString(" ") == data1.drop(index).mkString(" ") &&
      data.drop(n - index).mkString(" ") == data1.take(index).mkString(" "))
    println("YES")
  else
    println("NO")
}


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

import collection.mutable.HashMap
import scala.collection.{SortedSet, mutable}
import scala.util.Random
  protected val EPS = 1e-11

  private def default = (
    new StreamTokenizer(new InputStreamReader(System.in)),
    new Scanner(System.in),
    new PrintWriter(System.out)
  )

  val (in, ins, out) = {
    try {
      if (sys.props.contains("xDx")) {
        (
          new StreamTokenizer(new FileReader("input.txt")),
          new Scanner(new FileReader("input.txt")),
          new PrintWriter(new FileWriter("output.txt"))
        )
      } else {
        default
      }
    } catch {
      case _: Throwable => default
    }
  }

  private def nextInt = {
    in.nextToken
    in.nval.toInt
  }

  private def nextLong = {
    in.nextToken
    in.nval.toLong
  }

  private def nextDouble = {
    in.nextToken
    in.nval
  }

  private def nextString = {
    in.nextToken
    in.sval
  }

  private def nextChar = {
    in.nextToken
    in.ttype.toChar
  }

  def main(args: Array[String]): Unit = {
    try {
      new Run().run()
    } catch {
      case e: Throwable =>
        throw new RuntimeException(e)
    } finally out.close()
  }

  class Run {
    import collection.breakOut
    def run(): Unit = {
        val n = nextInt
        val m = nextInt
        val q = nextInt
        val start = Array.ofDim[Int](n)
        val end = Array.ofDim[Int](n)
        val s = nextString
        val t = nextString
        var is = 0
        var ie = 0
        var cur_s = 0
        var cur_e = 0

        while(is < n) {
            var idx = s.indexOf(t, is)
            if(idx == -1) idx = n
            while(is < n && is <= idx) {
                if(is == idx) cur_s += 1
                start(is) = cur_s
                is += 1
            }

            while(ie < n && ie < idx + m) {
                if(ie == idx + m - 1) cur_e += 1
                end(ie) = cur_e
                ie += 1
            }
        }

        for(i <- 1 to q) {
            val l = nextInt - 1
            val r = nextInt - 1
            val res = math.max(end(r) - (if(l == 0) 0 else start(l - 1)), 0)
            println(res)
        }
    }

  }

}

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, M, Q = ni()
    val S = ns()
    val T = ns()
    val cum = Array.ofDim[Int](N + 1) // 1-index

    if (N >= M) {
      rep(N - M + 1) { i =>
        cum(i + 1) = cum(i)
        if (S.substring(i, i + M) == T) cum(i + 1) += 1
      }
    }

    rep(Q) { _ =>
      val l, r = ni()
      val ri = r - M + 1
      val li = l - 1
      val ans = if (ri >= li) cum(ri) - cum(li) else 0
      out.println(ans)
    }
  }

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

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

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

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

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

object Main {

  import java.io.{BufferedReader, InputStreamReader}

  val mod = (1e9 + 7).toLong

  var d = new Array[Long](1005)

  var powResult = new Array[Long](1005)

  var answer = new Array[Long](1005)

  var strMod: Long = 0

  /*
  快速幂
   */
  def power(a: Long, b: Int): Long = {
    val ans = if (b == 0) 1 else {
      var res = 1.toLong
      var x = a
      var y = b
      while (y != 0) {
        if ((y & 1) == 1) {
          res *= x
          res %= mod
        }
        x *= x
        x %= mod
        y >>= 1
      }
      res
    }
    ans
  }

  def getPowerResult(): Unit = {
    (0 to 1000).foreach(i => {
      powResult(i) = power(131, i)
    })
  }

  def getHash(str: String): Unit = {
    (0 until str.length).foreach(index => {
      strMod *= 131
      strMod += str.charAt(index).toInt
      strMod %= mod
    })
  }

  def getMoroHashSum(str: String): Unit = {
    d(0) = 0.toLong
    (0 until str.length).foreach(i => {
      d(i + 1) = (d(i) + powResult(i) * str.charAt(i).toInt % mod) % mod
    })
  }

  def result(x: Int, y: Int, z: Int): Int = {
    var ans = 0
    (x to y - z + 1).foreach(i => {
      val temp1 = (d(i + z - 1) - d(i - 1) + mod) % mod
      val temp2 = (strMod * powResult(i - 1) % mod) % mod
      if (temp1 == temp2) ans += 1
    })
    ans
  }

  def getResultInit(x: Int, y: Int): Unit = {
    (1 to x - y + 1).foreach(i => {
      val temp1 = (d(i + y - 1) - d(i - 1) + mod) % mod
      val temp2 = (strMod * powResult(i - 1) % mod) % mod
      if (temp1 == temp2) answer(i) = answer(i - 1) + 1
      else answer(i) = answer(i - 1)
    })
  }

  def main(args: Array[String]): Unit = {
    val br = new BufferedReader(new InputStreamReader(System.in))
    val line = br.readLine().split(" ")
    val x = line(0).toInt
    val y = line(1).toInt
    val z = line(2).toInt
    val str1 = br.readLine()
    val str2 = br.readLine()
    getPowerResult()
    getHash(str2.reverse)
    getMoroHashSum(str1)
    getResultInit(x, y)
    var a = 0
    for (a <- 1 to z) {
      val line = br.readLine().split(" ")
      val p = line(0).toInt - 1
      val q = line(1).toInt - y + 1
      if (p > q) println("0")
      else println(answer(q) - answer(p))
    }
    br.close()
  }
}

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

import collection.mutable.HashMap
import scala.collection.{SortedSet, mutable}
import scala.util.Random
  protected val EPS = 1e-11

  private def default = (
    new StreamTokenizer(new InputStreamReader(System.in)),
    new Scanner(System.in),
    new PrintWriter(System.out)
  )

  val (in, ins, out) = {
    try {
      if (sys.props.contains("xDx")) {
        (
          new StreamTokenizer(new FileReader("input.txt")),
          new Scanner(new FileReader("input.txt")),
          new PrintWriter(new FileWriter("output.txt"))
        )
      } else {
        default
      }
    } catch {
      case _: Throwable => default
    }
  }

  private def nextInt = {
    in.nextToken
    in.nval.toInt
  }

  private def nextLong = {
    in.nextToken
    in.nval.toLong
  }

  private def nextDouble = {
    in.nextToken
    in.nval
  }

  private def nextString = {
    in.nextToken
    in.sval
  }

  private def nextChar = {
    in.nextToken
    in.ttype.toChar
  }

  def main(args: Array[String]): Unit = {
    try {
      new Run().run()
    } catch {
      case e: Throwable =>
        throw new RuntimeException(e)
    } finally out.close()
  }

  class Run {
    import collection.breakOut
    def run(): Unit = {
        val n = nextInt
        val m = nextInt
        val q = nextInt
        val start = Array.ofDim[Int](n)
        val end = Array.ofDim[Int](n)
        val s = nextString
        val t = nextString
        var i = 0
        var cur_s = 0
        var cur_e = 0
        while(i < n) {
            var idx = s.indexOf(t, i)
            if(idx == -1) idx = n
            while(i < n && i < idx + m) {
                if(i == idx) cur_s += 1
                if(i == idx + m - 1) cur_e += 1
                start(i) = cur_s
                end(i) = cur_e
                i += 1
            }
        }

        for(i <- 1 to q) {
            val l = nextInt - 1
            val r = nextInt - 1
            val res = math.max(end(r) - (if(l == 0) 0 else start(l - 1)), 0)
            println(res)
        }
    }

  }

}


object C extends App {
  import InOut._

  val t = nextInt()

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

    s.augend(a) match {
      case Some(b) => out.println(b)
      case _       => out.println(-1)
    }
  }

  out.flush()

  implicit final class LongOps(private val sum: Long) extends AnyVal {
    def digits: List[Byte] = sum.toString().split("").map(_.toByte).toList

    def augend(addend: Long): Option[Long] = {

      @annotation.tailrec
      def go(sumDigits: List[Byte], addendDigits: List[Byte], augendDigits: List[Byte]): Option[List[Byte]] =
        (sumDigits, addendDigits) match {
          case (sumHead :: sumTail, addendHead :: addendTail) if addendHead <= sumHead =>
            go(sumTail, addendTail, (sumHead - addendHead).toByte :: augendDigits)
          case (sumFirst :: sumSecond :: sumTail, addendHead :: addendTail)            =>
            val sumHead = sumSecond * 10 + sumFirst
            if (sumHead > 18 || addendHead > sumHead) None
            else go(sumTail, addendTail, (sumHead - addendHead).toByte :: augendDigits)
          case (sumHead :: sumTail, _)                                                 =>
            go(sumTail, addendDigits, sumHead :: augendDigits)
          case _                                                                       =>
            if (addendDigits.isEmpty) Some(augendDigits) else None
        }

      go(sum.digits.reverse, addend.digits.reverse, List.empty[Byte]).map(_.mkString("").toLong)
    }
  }

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

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

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

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

    def nextLine() = in.readLine()

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

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

object C extends App {

  val digits: Long => List[Int] = _.toString().split("").map(_.toInt).reverse.toList

  def wrongAddition(s: Long, a: Long): Option[Long] = {

    @annotation.tailrec
    def go(s: List[Int], a: List[Int], b: List[Int]): Option[List[Int]] = (s, a) match {
      case (shead :: stail, ahead :: atail) if ahead <= shead => go(stail, atail, (shead - ahead) :: b)
      case (sfirst :: ssecond :: stail, ahead :: atail)       =>
        val shead = ssecond * 10 + sfirst
        if (shead > 18 || ahead > shead) None else go(stail, atail, (shead - ahead) :: b)
      case (shead :: stail, Nil)                              => go(stail, a, shead :: b)
      case (Nil, Nil)                                         => Some(b)
      case _                                                  => None
    }

    go(digits(s), digits(a), List.empty[Int]).map(_.mkString("").toLong)
  }

  import InOut._

  val t = nextInt()

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

    wrongAddition(s, a) match {
      case Some(b) => out.println(b)
      case _       => out.println(-1)
    }
  }

  out.flush()

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

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

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

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

    def nextLine() = in.readLine()

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

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