import scala.math._

object Problem extends App {
  import Scanner._

  val n, k = readInt
  val heights = Array.fill(n)(readInt)
  val sums = Array.ofDim[Int](n - k)

  var sum = 0
  for(i <- 0 until k)
    sum += heights(i)
  var (min, idx) = (sum, 0)
  for(i <- 1 to (n-k)) {
    sum += heights(i+k-1) - heights(i-1)
    if(sum < min) {
      min = sum
      idx = i
    }
  }
  println(idx+1)
}

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

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

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

      c = readChar
    }
  }
}

import java.util.Scanner

object Fence {
	def main(args: Array[String]): Unit = {
		val scan: Scanner = new Scanner(System.in)
		val n = scan.nextInt
		val k = scan.nextInt

		val h: Array[Int] = new Array[Int](n)
		for(i <- 0 until n) {
			h(i) = scan.nextInt
		}

		var ans = 0
		var now = 0
		var best = 0x3fffffff
		for((x,i) <- h.view.zipWithIndex) {
			if (i < k) now += x
			else {
				now += x
				now -= h(i - k)
			}
			if (i >= k - 1 && best > now) {
				ans = i
				best = now
			}
		}
		println(ans - k + 2)
	}
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toLong)
  val first = data.take(k).sum
  val res = (k until n).foldLeft(first, first, 0) {
    case((max, soFar, index), i) =>
      val nSoFar = soFar - data(i - k) + data(i)
      if (nSoFar < max)
        (nSoFar, nSoFar, i - k + 1)
      else
        (max, nSoFar, index)
  }
  println(res._3 + 1)
}

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    val input = readInts(n)
    for (i <- 1 until n) {
      input(i) += input(i-1)
    }
    var ret = input(k-1)
    var I = k-1
    for (i <- k until n) {
      if(ret > input(i)-input(i-k)) {
        ret = input(i)-input(i-k)
        I = i
      }
    }
    println(I-k+2)
  }
}

import java.util.Scanner
import java.io.PrintWriter
import java.util.Arrays.binarySearch
import scala.annotation.tailrec
import scala.annotation.switch
import scala.annotation.unchecked
import scala.collection.mutable
import scala.collection.mutable.ListBuffer
import scala.collection.mutable.ArrayBuffer
import scala.collection.immutable.TreeSet
import scala.util.Random
import scala.util.control.Breaks._

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

  // N planks
  // H_i ... hight of the ith plank
  // K consecutive planks to be removed

  def solve(): Long = {
    val N, K = sc.nextInt
    val dp: Array[Long] = Array.fill(N + 1)(0)

    1 to N foreach { i =>
      dp(i) = dp(i - 1) + sc.nextLong
    }

    var min: Long = Long.MaxValue
    var j: Int = 0
    1 to (N - K + 1) foreach { i =>
      val kSum = dp(i + K - 1) - dp(i - 1)
      if (kSum < min) {
        min = kSum
        j = i
      }
    }
    j
  }

  out.println(solve)
  out.close
}

import scala.collection.mutable.ListBuffer

object Main2 {
  def main(args: Array[String]) {
    var ln = readLine()

    val first = ln.split(' ').toList.map(_.toInt).toArray
    ln =  readLine()
    val second = ln.split(' ').toList.map(_.toInt).toArray
    var sum = BigInt(0)
    var minSum = BigInt(0)
    var pos = 0
    for(i <- 0 to first(1)-1) {
      sum += second(i)
    }
    minSum = sum
    for(j <- 1 to first(0) - first(1)){
      sum -= second(j-1)
      sum += second(first(1)+j-1)
      if(sum < minSum ) {
        minSum = sum
        pos = j
      }
    }

    print(pos+1)
  }

}

object Fence extends App {
  val input = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
  val (n :: hole :: Nil) = input.next.toList
  val fence = input.next
  val fencePairs = fence.zip(fence.drop(hole))

  var total = fence.take(hole).sum
  var min = total
  var plank = 1

  (0 until fencePairs.length) foreach { i =>
    val (drop, gain) = fencePairs(i)
    total = total + gain - drop
    if(total < min) {
      min = total
      plank = i + 2
    }
  }

  println(plank)
}

import java.util.Scanner

object FenceApp extends App {
    val scan: Scanner = new Scanner(System.in)
    val n = scan.nextInt
    val k = scan.nextInt

    val h: Array[Int] = new Array[Int](n)
    for(i <- 0 until n) {
        h(i) = scan.nextInt
    }

    var ans = 0
    var now = 0
    var best = 0x3fffffff
    for((x,i) <- h.view.zipWithIndex) {
        if (i < k) now += x
        else {
            now += x
            now -= h(i - k)
        }
        if (i >= k - 1 && best > now) {
            ans = i
            best = now
        }
    }
    println(ans - k + 2)
}

import scala.math._

object Problem extends App {
  import Scanner._

  val n, k = readInt
  val heights = Array.fill(n)(readInt)
  val sums = Array.ofDim[Int](n - k)

  var sum = 0
  for(i <- 0 until k)
    sum += heights(i)
  var min = sum
  for(i <- 1 to (n-k)) {
    sum += heights(i+k-1) - heights(i-1)
    if(sum < min)
      min = sum
  }
  println(min)
}

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

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

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

      c = readChar
    }
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toLong)
  val first = data.take(k).sum
  val res = (k + 1 to n - 1).foldLeft(first, first, 1) {
    case((max, soFar, index), i) =>
      val nSoFar = soFar - data(i - k - 1) + data(k)
      if (nSoFar < max)
        (nSoFar, nSoFar, i - k)
      else
        (max, nSoFar, index)
  }
  println(res._3)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toLong)
  val first = data.take(k).sum
  val res = (k + 1 to n - 1).foldLeft(first, first, 0) {
    case((max, soFar, index), i) =>
      val nSoFar = soFar - data(i - k - 1) + data(k)
      if (nSoFar < max)
        (nSoFar, nSoFar, i - k)
      else
        (max, nSoFar, index)
  }
  println(res._3 + 1)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(" ").map(_.toInt)
  val data = in.next().split(" ").map(_.toLong)
  val first = data.take(k).sum
  val res = (k + 1 to n - 1).foldLeft(first, first) {
    case((max, soFar), i) =>
      val nSoFar = soFar - data(i - k - 1) + data(k)
      (Math.min(nSoFar, max), nSoFar)
  }
  println(res._1)
}

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n, k) = readInts(2)
    val input = readInts(n)
    for (i <- 1 until n) {
      input(i) += input(i-1)
    }
    var ret = input(k-1)
    var I = 0
    for (i <- k until n) {
      if(ret > input(i)-input(i-k)) {
        ret = input(i)-input(i-k)
        I = i
      }
    }
    println(I-k+2)
  }
}

import scala.collection.mutable.ListBuffer

object Main2 {
  def main(args: Array[String]) {
    var ln = readLine()

    val first = ln.split(' ').toList.map(_.toInt).toArray
    ln =  readLine()
    val second = ln.split(' ').toList.map(_.toInt).toArray
    var sum = BigInt(0)
    var minSum = BigInt(0)
    var pos = 0
    for(i <- 0 to first(1)-1) {
      sum += second(i)
    }
    minSum = sum
    for(j <- 0 to first(0) - first(1)){
      sum -= second(j)
      sum += second(first(1)-1+j)
      if(sum < minSum ) {
        minSum = sum
        pos = j
      }
    }
    print(pos+1)
  }

}

object Fence extends App {
  val input = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
  val (n :: hole :: Nil) = input.next.toList
  val fence = input.next
  val fencePairs = fence.zip(fence.drop(hole))

  var total = fence.take(hole).sum
  var min = total
  var plank = 0

  (0 until fencePairs.length) foreach { i =>
    val (drop, gain) = fencePairs(i)
    total = total + gain - drop
    if(total < min) {
      min = total
      plank = i + 2
    }
  }

  println(plank)
}

object Fence extends App {
  val input = io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))
  val (n :: hole :: Nil) = input.next.toList
  val fence = input.next
  val fencePairs = fence.zip(fence.drop(hole))

  var total = fence.take(hole).sum
  var min = total
  var plank = 0

  (0 until fencePairs.length) foreach { i =>
    val (drop, gain) = fencePairs(i)
    total = total + gain - drop
    if(total < min) {
      min = total
      plank = i
    }
  }

  println(plank)
}


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 ab = readLongLine()
      val a = ab.head
      val b = ab.last
      if (a == b) println(0)
      if (a > b) {
        if (a % b != 0) println(-1)
        else {
          val div = a / b
          println(num(div, 0))
        }
      }
      if (a < b) {
        if (b % a != 0) println(-1)
        else {
          val div = b / a
          println(num(div, 0))
        }
      }
    }
    //          println(minNum(List[Boolean](false, false, true)))
  }

  def num(d: Long, acc: Long): Long = {
    if (d % 8 == 0) num(d / 8, acc + 1)
    else if (d % 4 == 0) num(d / 4, acc + 1)
    else if (d % 2 == 0) num(d / 2, acc + 1)
    else if (d == 1) acc else -1
  }

  def calcCost(tree: Array[List[Int]], nodes: Array[List[Int]]): Long = {
    def helper(visited: Array[Boolean], ind: Int, min: Int): (Int, Int, Long) = {
      val neighs = tree(ind).filter(n => !visited(n))
      neighs.foreach(visited(_) = true)
      val ourCost = nodes(ind).head
      val newMin = Math.min(min, ourCost)

      val costs = neighs.map(n => {
        helper(visited, n, newMin)
      }).reduce((one, two) => (one._1 + two._1, one._2 + two._2, one._3 + two._3))

      if (min <= ourCost) costs else {
        val posExchanges = Math.min(costs._1, costs._2)
        (costs._1 - posExchanges, costs._2 - posExchanges, costs._3 + posExchanges * ourCost)
      }
    }

    val visitedArr = Array.ofDim[Boolean](nodes.length + 1)
    visitedArr(1) = true
    helper(visitedArr, 1, Int.MaxValue)._3
  }

  def constructTree(nodes: Array[List[Int]], edges: List[List[Int]]): Array[List[Int]] = {
    val edgesNice = Array.ofDim[List[Int]](nodes.length + 1)
    for (i <- edgesNice.indices)
      edgesNice(i) = List[Int]()

    edges.foreach(edge => {
      edgesNice(edge.head) = edge.last :: edgesNice(edge.head)
      edgesNice(edge.last) = edge.head :: edgesNice(edge.last)
    })

    edgesNice.map(_.toList)
  }

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

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

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

}

object A extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(a, b)  = scala.io.StdIn.readLine().split(" ").map(_.toLong.toBinaryString).sortBy(_.length)
    val (alen, blen) = (a.length, b.length)

    val (bl, br) = b.splitAt(alen)

    val ans =
      if (a != bl || br.contains('1')) -1
      else (blen - alen + 2) / 3

    println(ans)
  }
}

object A extends App {
  import java.{util => ju}
  def leftShiftsRequired(from: Long, to: Long, soFar: Long = 0): Long = {
    if (from == to) soFar
    else if (from > to) -1
    else leftShiftsRequired(from << 1, to, soFar + 1)
  }

  val in = new ju.Scanner(System.in)
  (1 to in.nextInt()).foreach { _ =>
    val a = in.nextLong()
    val b = in.nextLong()

    val shifts = leftShiftsRequired(a min b, a max b)
    if (shifts == -1) println(-1) else {
      val threeShifts = shifts / 3
      val remainingAfterThree = shifts % 3
      val twoShifts = remainingAfterThree / 2
      val oneShifts = remainingAfterThree % 2
      println(threeShifts + twoShifts + oneShifts)
    }
  }
}

import scala.io.StdIn.readLine

object A extends App {

  for {_ <- 0 until readLine.toInt} {
    val Seq(a, b) = readLine.split(" ").toSeq.map(_.toLong)
    println(solution(a, b))
  }

  def solution(a0: Long, b0: Long): Long = {
    val a = a0.toBinaryString
    val b = b0.toBinaryString
    if (before0(a) != before0(b)) -1 else {
      val binDiff = math.abs(trailing0(a) - trailing0(b))
      (binDiff + 2) / 3
    }
  }

  def before0(s: String) = s.reverse.dropWhile(_ == '0')
  def trailing0(s: String) = s.reverse.takeWhile(_ == '0').length
}

object A extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val Array(a, b) = scala.io.StdIn.readLine().split(" ").map(_.toLong.toBinaryString).sortBy(_.length)

    val i = b.indexOfSlice(a)

    val ans =
      if (i < 0 || b.indexOfSlice(a, i + 1) > 0) -1
      else (b.length - a.length + 2) / 3

    println(ans)
  }
}


object CF917A extends App{
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val a = Seq.fill[Int](n)(sc.nextInt)
  println(a filter (i => {val d = Math.sqrt(i); d - d.intValue != 0}) max)
}

import java.util.Scanner

object R458A {
  def isSquare(x :Int): Boolean = {
    if(x<0) return false
    if(x==0) return true
    for(i <- 1 to (Math.sqrt(x)+1).toInt) {
      if(i*i==x) {
        return true
      }
    }
    return false
  }
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = new Array[Int](n)
    for(i <- 0 until n) {
      a(i) = sc.nextInt()
    }
    var max = -10000000
    for(i <- 0 until n) {
      if(!isSquare(a(i))) {
        max = Math.max(a(i), max)
      }
    }
    println(max)
  }
}

object PerfectSquare extends App {
  val n = scala.io.StdIn.readLine().toLong
  val as = scala.io.StdIn.readLine().split(" ").map(_.toLong)

  def perfectSquare(x: Long) = {
    if (x < 0) {
      false
    } else {
      Math.sqrt(x).isValidInt
    }
  }

  println(as.filterNot(perfectSquare).max)

}

object A extends App {

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

  val Array(n) = readInts(1)
  val as = readInts(n)

  var max = Int.MinValue

  def isSquare(x: Int): Boolean = {
    x >= 0 && {
      val r = Math.sqrt(x).toInt
      r * r == x
    }
  }

  for (a <- as) {
    if (!isSquare(a) && a > max) max = a
  }

  println(max)
}

object A extends App {
  val n = scala.io.StdIn.readInt()
  val a = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val b = a.filter(i => i < 0 || scala.math.sqrt(i) % 1 != 0)
  println(b.max)
}

import java.util.Scanner

object R458A {
  def isSquare(x :Int): Boolean = {
    if(x<=0) return false
    for(i <- 1 to (Math.sqrt(x)+1).toInt) {
      if(i*i==x) {
        return true
      }
    }
    return false
  }
  def main(args: Array[String]): Unit = {
    println(Math.sqrt(-1))
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = new Array[Int](n)
    for(i <- 0 until n) {
      a(i) = sc.nextInt()
    }
    var max = -10000000
    for(i <- 0 until n) {
      if(!isSquare(a(i))) {
        max = Math.max(a(i), max)
      }
    }
    println(max)
  }
}

import java.util.Scanner

object R458A {
  def isSquare(x :Int): Boolean = {
    if(x<=0) return false
    for(i <- 1 to (Math.sqrt(x)+1).toInt) {
      if(i*i==x) {
        return true
      }
    }
    return false
  }
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val a = new Array[Int](n)
    for(i <- 0 until n) {
      a(i) = sc.nextInt()
    }
    var max = -10000000
    for(i <- 0 until n) {
      if(!isSquare(a(i))) {
        max = Math.max(a(i), max)
      }
    }
    println(max)
  }
}

object A extends App {
  val n = scala.io.StdIn.readInt()
  val a = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val b = a.filter(i => i <= 0 || scala.math.sqrt(i) % 1 != 0)
  println(b.max)
}


import scala.io.StdIn

object A extends App {

  val Array(n, m) = StdIn.readLine().split(" ").map(_.toInt)

  val s = StdIn.readLine()
  val t = StdIn.readLine()

  var min = Int.MaxValue
  var index = 0

  (0 to (t.size - s.size)).foreach { i =>
    val sum = (0 to (s.size -1)).map { x =>
      if(t(x + i) != s(x)) 1 else 0
    }.sum
    if(sum < min) {
      min = sum
      index = i
    }
  }

  println(min)
  (0 to (s.size -1)).map { x =>
    if(t(x + index) != s(x)) {
      print((x + 1) + " ")
    }
  }

}

object P822B {

  def diff(s1: String, s2: String): Seq[Int] = (s1 zip s2).zipWithIndex.collect{ case (p, i) if p._1 != p._2 => i+1 }

  def main(args: Array[String]): Unit = {
    val in = new Scanner(System.in)
    in.nextLine() // skip first line
    val s = in.nextLine()
    val t = in.nextLine()
    val idxs = (0 to (t.length - s.length)).map(i => diff(s, t.substring(i))).minBy(_.length)
    println(idxs.length)
    println(idxs.mkString(" "))
  }

  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer

  import scala.io.Codec

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

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

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

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

import scala.collection.mutable.ArrayBuffer

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, m) = readInts(2)
  val s, t = readLine

  var min = Int.MaxValue
  var pos = 0

  for (start <- 0 to t.length - s.length) {
    var diff = 0
    for (i <- 0 until s.length) if (s(i) != t(start + i)) diff += 1
    if (diff < min) {
      min = diff
      pos = start
    }
  }

  val res = ArrayBuffer.empty[Int]
  for (i <- 0 until s.length) if (s(i) != t(pos + i)) res += (i + 1)

  println(min)
  println(res.mkString(" "))
}

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

import scala.collection.mutable

object B {

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

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

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

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

  def nextBoolean: Boolean = next.equalsIgnoreCase("1")

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

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

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

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

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

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

    override def toString = s"MultiHashSet($map)"
  }

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

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

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

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

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

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

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

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

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

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

    def query(p: Int) = ???

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

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

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val s = next.toCharArray
    val t = next.toCharArray
    var min = Int.MaxValue
    var res = new mutable.HashSet[Int]()
    for (i <- 0 to m - n) {
      var diff = 0
      val pos = new mutable.HashSet[Int]()
      for (j <- 0 until n) {
        if (s(j) != t(i + j)) {
          diff += 1
          pos.add(j + 1)
        }
      }
      if (diff < min) {
        min = diff
        res = pos
      }
    }
    out.println(min)
    res.foreach(x => out.print(s"$x "))
    return 0
  }
}

import java.util.Scanner

object test
{
  def main(args: Array[String]): Unit = {
    val s = new Scanner(System.in)
    val n = s.nextInt()
    val m = s.nextInt()
    s.nextLine()
    val str1 = s.nextLine()
    val str2 = s.nextLine()
    var minlist:List[Int]=List()
    var minc=1e8

    for(i<-0 to m-n){
      var c=0
      var chlist:List[Int]=List()
      for(j<-0 to n-1){
        if(str1.charAt(j)!=str2.charAt(i+j)){
          c+=1
          chlist = j::chlist
        }
      }
      if(c<minc){
        minc=c
        minlist=chlist
      }
    }
    println(minlist.length)
    for(ch<-minlist.reverse) printf("%d ",ch+1)
  }
}

import java.util.Scanner

object test
{
  def main(args: Array[String]): Unit = {
    val s = new Scanner(System.in)
    val n = s.nextInt()
    val m = s.nextInt()
    s.nextLine()
    val str1 = s.nextLine()
    val str2 = s.nextLine()
    var minlist:List[Int]=List()

    for(i<-0 to m-n){
      var chlist:List[Int]=List()
      for(j<-0 to n-1){
        if(str1.charAt(j)!=str2.charAt(i+j)){
          chlist = j::chlist
        }
      }
      if(minlist.length==0 || chlist.length<minlist.length) minlist=chlist
    }
    println(minlist.length)
    for(ch<-minlist.reverse) printf("%d ",ch+1)
  }
}


object C479 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = Array.fill(n){readInts(2)}.map(arr => (arr(0), arr(1))).sorted
    var pos = math.min(in(0)._1, in(0)._2)
    for(i <- 1 until n) {
      val min = math.min(in(i)._1, in(i)._2)
      if(min >= pos) {
        pos = min
      } else {
        pos = math.max(in(i)._1, in(i)._2)
      }
    }
    println(pos)
  }

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

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

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

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

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

}

import java.util.StringTokenizer

object _479C extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => (next.toInt, next.toInt)).sorted.toArray

  def doit(i: Int, pre: Int):Int = {
    if (i == n) pre
    else {
      if (pre <= a(i)._2) doit(i + 1, a(i)._2)
      else doit(i + 1, a(i)._1)
    }
  }

  println(doit(0, -1))
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  println((1 to n).map{_ =>
    val Array(a, b) = in.next().split(" ").map(_.toInt)
    (a, b)
  }.sorted.foldLeft(0) {
    case(acc, (a, b)) if b < acc =>
      a
    case(acc, (a, b)) =>
      b
  })

}

import scala.collection.mutable.ListBuffer

object P479C {
	def convert(a: Array[Int]) : (Int, Int) = (a(0), a(1))

	def choose(last: Int, choices: (Int, Int)) : Int = {
		if (choices._2 >= last) choices._2 else choices._1
	}

	def main(args: Array[String]) {
		val lines = scala.io.Source.stdin.getLines.toList
		val exams = lines.tail.map(_.split(" ").map(_.toInt))
		println(exams.map(convert).sorted.foldLeft(0)(choose))
	}
}

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

        var n : Int = readLine.toInt
        var exams : Array[(Int,Int)] = new Array[(Int,Int)](n)
        var lastExam : Int = 0

        for(i <- 0 to n-1){
            exams(i) = (readLine.split(" ").map(_.toInt)) match {case Array(x,y) => (x,y)}
        }

        exams = exams.sortWith((x, y) => {if (x._1 != y._1) x._1 < y._1 else x._2 < y._2} )
        // exams = exams.sortBy(_._1)

        exams.foreach(exam => {lastExam = if ( exam._2 >= lastExam ) exam._2 else exam._1})

        println(lastExam)
    }
}

object Main {

  val in =  {
    val lines = scala.io.Source.stdin.getLines
    lines map (_ split ' ') filter (_.nonEmpty) flatten
  }

  def nextInt = in.next.toInt

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

    val N = nextInt
    val vals = Array.fill(N){
      val a, b = nextInt
      (a, b)
    }.sorted

    var best = 0
    for ((a, b) <- vals) {
      if (b >= best) best = b
      else best = a
    }

    println(best)
  }
}

import scala.collection._

object A extends App {

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

  val Array(n) = readInts(1)

  val abs = Array.ofDim[(Int, Int)](n)

  for (i <- 0 until n) {
    val Array(a, b) = readInts(2)
    abs(i) = (a, b)
  }

  val maxA = abs.map(_._1).max
  val maxB = abs.map(_._2).max

  val sorted = abs.sorted

  var current = 0
  for ((a, b) <- sorted) {
    if (a > current) {
      if (b >= current) current = b
      else current = a
    }
  }

  println(current)
}

import scala.collection._

object A extends App {

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

  val Array(n) = readInts(1)

  val abs = Array.ofDim[(Int, Int)](n)

  for (i <- 0 until n) {
    val Array(a, b) = readInts(2)
    abs(i) = (a, b)
  }

  val maxA = abs.map(_._1).max
  val maxB = abs.map(_._2).max

  if (abs.filter(_._1 == maxA).forall(_._2 >= maxB))
    println(maxB)
  else println(maxA)
}

import scala.collection._

object A extends App {

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

  val Array(n) = readInts(1)

  val abs = Array.ofDim[(Int, Int)](n)

  for (i <- 0 until n) {
    val Array(a, b) = readInts(2)
    abs(i) = (a, b)
  }

  val maxA = abs.map(_._1).max
  val maxB = abs.map(_._2).max

  val sorted = abs.sortBy(_._1)

  var current = 0
  for ((a, b) <- sorted) {
    if (a > current) {
      if (b >= current) current = b
      else current = a
    }
  }

  println(current)
}

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

        var n : Int = readLine.toInt
        var exams : Array[(Int,Int)] = new Array[(Int,Int)](n)
        var lastExam : Int = 0

        for(i <- 0 to n-1){
            exams(i) = (readLine.split(" ").map(_.toInt)) match {case Array(x,y) => (x,y)}
        }

        exams = exams.sortBy(_._1)

        exams.foreach(exam => {lastExam = if ( exam._2 >= lastExam ) exam._2 else exam._1})

        println(lastExam)
    }
}


object tmp extends App {

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

  class MyScanner(br: BufferedReader) {
    var st = new StringTokenizer("")

    def this(is: InputStream) = this(new BufferedReader(new InputStreamReader(is)))

    private def next() = {

      while (!st.hasMoreElements) {
        st = new StringTokenizer(br.readLine())
      }
      st.nextToken()
    }

    def nextInt() = java.lang.Integer.parseInt(next())

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

    def nextLine() = br.readLine()
  }

  val sc = new MyScanner(System.in)
  val in = sc.nextLine().foldLeft(mutable.Map[Char, Int]().withDefaultValue(0)) {
    (acc, cur) => {acc(cur) += 1; acc}
  }
  val out = sc.nextLine().foldLeft(mutable.Map[Char, Int]().withDefaultValue(0)) {
    (acc, cur) => {acc(cur) += 1; acc}
  }
  var result = 0
  for (k <- out.keys) {
    if (in(k) >= out(k)) {
      result += out(k)
    } else if (in(k) == 0) {
      println(-1)
      System.exit(0)
    } else {
      result += in(k)
    }
  }
  println(result)
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val have = in.next().groupBy(i => i).map(i => i._1 -> i._2.length)
  val need = in.next().groupBy(i => i).map(i => i._1 -> i._2.length)
  println(need.keys.foldLeft(0) {
    case(-1, _) => -1
    case(acc, el) if have.get(el).isEmpty => -1
    case(acc, el) if have(el) > need(el) => acc + need(el)
    case(acc, el) => acc + have(el)
  })
}

object B extends App {
  val a, b = readLine();
  val ct = (s: String, c: Char) => { s.count(_ == c) }
  val ctm = (l: String) => { l map (ct(l, _: Char)) }
  val am = a.zip(ctm(a)).toMap
  val bm = b.zip(ctm(b)).toMap
  var impossible = false;
  var sum = 0;
  for ((k, n) <- bm)
  {
    if (am.contains(k) == false) {
      impossible = true;
    }
    else {
      sum += n min am(k)
    }
  }
  if (impossible) sum = -1;
  println(sum);
}


/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF522A extends App {
  import scala.collection.mutable.{HashMap, HashSet}
  import java.util.{Scanner}
  import java.io.{PrintWriter}

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

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

  def solve = {
    val n = nextInt

    val graph = HashMap[String, HashSet[String]]()
    (1 to n).foreach { i =>
      val toName = nextString.toLowerCase
      val edge = nextString
      val fromName = nextString.toLowerCase
      if (graph.contains(fromName)) {
        graph(fromName) += toName
      } else {
        graph += (fromName -> HashSet(toName))
      }
    }

    def dfs(node: String): Int = {
      if (!graph.contains(node)) 1 else graph(node).map(dfs(_)).max + 1
    }

    out.println(dfs("Polycarp".toLowerCase))
  }

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

import scala.collection.mutable._

object Reposts {
  def main(args: Array[String]): Unit = {
     val in =scala.io.StdIn
    var n=in.readInt()
    val arr=Array.fill[Int](n+1)(-1)
    arr(0)= -1
    val hm=HashMap[String,Int]()
    hm.put("polycarp",0)
    for(i<-1 to n){
      var name=in.readLine().split(" reposted ")
      hm.put(name(0).toLowerCase(),i)
      val p=hm.get(name(1).toLowerCase()).get
      arr(i)=p
    }
    var chainSize=2
    for(i<- 1 to n){
      var j=i
      var c=1
      while (arr(j)!= -1){
        c+=1
        j=arr(j)
      }
      chainSize=math.max(chainSize,c)
    }
    println(chainSize)
  }
}

import scala.collection.mutable._

object Reposts {
  def main(args: Array[String]): Unit = {
    //Intuition: here post and re-post hold a parent child relation
    val in =scala.io.StdIn
    var n=in.readInt()
    val cs=HashMap[String,Int]()
    cs.put("polycarp",1)
    var chainSize=0
    for(i<-1 to n){
      var name=in.readLine().split(" reposted ")
      val t=cs.get(name(1).toLowerCase()).get+1
      cs.put(name(0).toLowerCase(),t)
      chainSize=math.max(chainSize,t)
    }
    println(chainSize)
  }
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer

object Main3 extends App with IOUtils {
  val n = nextInt
  val pairs = (1 to n).map { i =>
    val to = nextToken
    nextToken
    val from = nextToken
    (from.toLowerCase, to.toLowerCase)
  }
  val descendants = pairs.groupBy(_._1).mapValues(_.map(_._2))

  def deepest(handle: String): Int = descendants.get(handle) match {
    case Some(further) => further.map(deepest).max + 1
    case _ => 0
  }

  println(deepest("polycarp") + 1)
}

trait IOUtils {
  var in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
  var tok: StringTokenizer = null

  def nextInt: Int = nextToken.toInt

  def nextLong: Long = nextToken.toLong

  def nextIntPair: (Int, Int) = (nextInt, nextInt)

  def nextToken: String = {
    if (tok == null || !tok.hasMoreTokens) {
      tok = new StringTokenizer(in.readLine)
    }

    tok.nextToken
  }
}

import scala.collection.mutable.Map

object A522 extends App {

  type Graph = Map[String, List[String]]
  val rep = Map[String, List[String]]()
  val n   = readInt

  (1 to n)
    .map(_ => readLine.toLowerCase.split(" "))
    .foreach(x => if(!rep.contains(x(2))) rep(x(2)) = x(0) :: Nil else rep(x(2)) ::= x(0))

  def BFS(startVertex : String, rep : Graph) = {

    def BFS0(v : String, visited : List[(String, Int)], level : Int = 1) : List[(String, Int)] = {
      if(visited.map(_._1).contains(v) || !rep.contains(v))
        visited
      else {
        val neigh = rep(v).filterNot(x => visited.map(_._1).contains(x))
        neigh.foldLeft((v, level) :: visited)((res, v) => BFS0(v, res, level + 1))
      }
    }

    BFS0(startVertex, List()).map(_._2).max
  }

 println(rep.keys.toList.map(x => BFS(x, rep)).max + 1)
}

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

import scala.collection.mutable

object A {

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

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

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

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

  def solve: Int = {
    val n = nextInt
    val g = new Array[Array[Boolean]](500)
    val map = new mutable.HashMap[String, Int]()
    for (i <- 0 until n) {
      val name1 = next.toLowerCase
      next
      val name2 = next.toLowerCase
      val a = map.getOrElse(name2, 0)
      val b = map.getOrElse(name1, 0)
      map.put(name1, Math.max(a + 1, b))
    }
    var max = 0
    map.keySet.foreach(key => {
      max = Math.max(max, map.get(key).get)
    })
    out.println(max + 1)
    return 1
  }

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


object _635D extends CodeForcesApp {
  override type Result = Seq[Int]

  override def solve(read: InputReader) = {
    val n, k, a, b, q = read[Int]
    val fixed, broken = new UpdateableFenwickTree(n + 1)
    val demand = Array.ofDim[Int](n + 1)
    var ans = Vector.empty[Int]
    repeat(q) {
      if(read[Int] == 1) {
        val i, d = read[Int]
        demand(i) += d
        fixed(i) = demand(i) min a
        broken(i) = demand(i) min b
      } else {
        val d = read[Int]
        val (r1, r2) = (broken.sum(1, d - 1), fixed.sum(d + k, n))
        ans = ans :+ (r1 + r2)
      }
    }
    ans
  }

  trait BitIndexTree {
    def prefixSum(i: Int): Int
    def sum(start: Int, end: Int): Int = prefixSum(end) - prefixSum(start - 1)
    def +=(i: Int, delta: Int): Unit
  }

  class FenwickTree(n: Int) extends BitIndexTree {
    private[this] val tree = Array.ofDim[Int](n)

    override def prefixSum(i: Int) = if (i < 0) 0 else tree(i) + prefixSum((i & (i + 1)) - 1)

    override def +=(i: Int, delta: Int) = if (i < n) {
      tree(i) += delta
      this += (i | (i + 1), delta)
    }
  }

  class UpdateableFenwickTree(n: Int) extends FenwickTree(n) {
    private[this] val data = Array.ofDim[Int](n)

    def update(i: Int, value: Int) = {
      this += (i, value - data(i))
      data(i) = value
    }
  }

  @inline def repeat(n: Int)(f: => Unit): Unit = for {_ <- 1 to n} f

  override def format(result: Result) = result mkString "\n"
}
/****************************[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.collection._
import scala.collection.mutable.ArrayBuffer

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

  object BIT {

    def query(t: Array[Long], r: Int, acc: Long = 0): Long =
      if (r < 0) acc else query(t, (r & (r + 1)) - 1, acc + t(r))

    def rangeQuery(t: Array[Long], l: Int, r: Int) = query(t, r) - query(t, l - 1)

    def update(t: Array[Long], i: Int, delta: Long): Unit =
      if (i < t.length) {
        t(i) += delta
        update(t, i | (i + 1), delta)
      }

    def apply(src: Array[Long]): Array[Long] = {
      val t = Array.fill(src.length) { 0L }
      for (i <- src.indices) update(t, i, src(i))
      t
    }

  }

  val Array(n, k, a, b, q) = readInts(5)

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

  val demands = Array.fill(n)(0L)
  val onA = BIT(demands)
  val onB = BIT(demands)
  val res = ArrayBuffer.empty[Long]

  var quer = 0
  while (quer < q) {
    val query = readLine.split(" ").map(_.toInt)
    query match {
      case Array(1, _d, x) =>
        val d = _d - 1
        val newDemand = demands(d) + x
        if (demands(d) < a) {
          BIT.update(onA, d, x.toLong min (a.toLong - demands(d)))
        }
        if (demands(d) < b) {
          BIT.update(onB, d, x.toLong min (b - demands(d)))
        }
        demands(d) = newDemand
      case Array(2, _p) =>
        val p0 = _p - 1
        val p1 = p0 + k
        val r1 = BIT.rangeQuery(onB, 0, p0 - 1)
        val r3 = BIT.rangeQuery(onA, p1, n - 1)
        res += r1 + r3
    }
    quer += 1
  }

  println(res.mkString("\n"))
  Console.flush
}

object _635D extends CodeForcesApp {
  override type Result = Seq[Long]

  override def solve(read: InputReader) = {
    val (n, k, a, b, q) = read[(Int, Int, Int, Int, Int)]
    val (fixed, broken, demand) = (new FenwickTree(n + 1), new FenwickTree(n + 1), Array.ofDim[Long](n))
    var ans = Vector.empty[Long]
    repeat(q) {
      if(read[Int] == 1) {
        val (d, x) = read[(Int, Long)]
        if (demand(d-1) < a) fixed(d-1) = x min (a - demand(d-1))
        if (demand(d-1) < b) broken(d-1) = x min (b - demand(d-1))
        demand(d-1) += x
      } else {
        val d = read[Int]
        val r1 = broken(0, d - 2)
        val r2 = fixed(d + k - 1, n - 1)
        ans = ans :+ (r1 + r2)
      }
    }

    ans
  }

  @inline def repeat(n: Int)(f: => Unit): Unit = for {_ <- 1 to n} f

  class FenwickTree(n: Int) {
    private[this] val tree = Array.ofDim[Long](n)

    def apply(i: Int): Long = if (i < 0) 0 else tree(i) + apply((i & (i + 1)) - 1)

    def apply(start: Int, end: Int): Long = this(end) - this(start - 1)

    def update(i: Int, v: Long): Unit = if (i < n) {
      tree(i) += v
      this(i | (i + 1)) = v
    }

    override def toString = tree.indices map apply mkString ", "
  }

  override def format(result: Result) = result mkString "\n"
}
/****************************[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]))
}

object _635D extends CodeForcesApp {
  override type Result = Seq[Int]

  override def solve(read: InputReader) = {
    val (n, k, a, b, q) = read[(Int, Int, Int, Int, Int)]
    val fixed, broken = new UpdateableFenwickTree(n + 1)
    val demand = Array.ofDim[Int](n + 1)
    var ans = Vector.empty[Int]
    repeat(q) {
      if(read[Int] == 1) {
        val (i, d) = read[(Int, Int)]
        demand(i) += d
        fixed(i) = demand(i) min a
        broken(i) = demand(i) min b
      } else {
        val d = read[Int]
        val r1 = broken.sum(1, d - 1)
        val r2 = fixed.sum(d + k, n)
        ans = ans :+ (r1 + r2)
      }
    }
    ans
  }

  trait BitIndexTree {
    def prefixSum(i: Int): Int
    def sum(start: Int, end: Int): Int = prefixSum(end) - prefixSum(start - 1)
    def +=(i: Int, delta: Int): Unit
  }

  class FenwickTree(n: Int) extends BitIndexTree {
    private[this] val tree = Array.ofDim[Int](n)

    override def prefixSum(i: Int) = if (i < 0) 0 else tree(i) + prefixSum((i & (i + 1)) - 1)

    override def +=(i: Int, delta: Int) = if (i < n) {
      tree(i) += delta
      this += (i | (i + 1), delta)
    }
  }

  class UpdateableFenwickTree(n: Int) extends FenwickTree(n) {
    private[this] val data = Array.ofDim[Int](n)

    def update(i: Int, value: Int) = {
      this += (i, value - data(i))
      data(i) = value
    }
  }

  @inline def repeat(n: Int)(f: => Unit): Unit = for {_ <- 1 to n} f

  override def format(result: Result) = result mkString "\n"
}
/****************************[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]))
}

object _635D extends CodeForcesApp {
  override type Result = Seq[Int]

  override def solve(read: InputReader) = {
    val (n, k, a, b, q) = read[(Int, Int, Int, Int, Int)]
    val fixed = new UpdateableFenwickTree(n + 1)
    val broken = new UpdateableFenwickTree(n + 1)
    val demand = Array.ofDim[Int](n + 1)
    var ans = Vector.empty[Int]
    repeat(q) {
      if(read[Int] == 1) {
        val (i, d) = read[(Int, Int)]
        demand(i) += d
        fixed(i) = demand(i) min a
        broken(i) = demand(i) min b
      } else {
        val d = read[Int]
        val r1 = broken(1, d - 1)
        val r2 = fixed(d + k, n)
        ans = ans :+ (r1 + r2)
      }
    }
    ans
  }

  trait BitIndexTree {
    def apply(i: Int): Int
    def apply(start: Int, end: Int): Int = this(end) - this(start - 1)
    def +=(i: Int, delta: Int): Unit
  }

  class FenwickTree(n: Int) extends BitIndexTree {
    private[this] val tree = Array.ofDim[Int](n)

    override def apply(i: Int) = if (i < 0) 0 else tree(i) + apply((i & (i + 1)) - 1)

    override def +=(i: Int, delta: Int) = if (i < n) {
      tree(i) += delta
      this += (i | (i + 1), delta)
    }
  }

  class UpdateableFenwickTree(n: Int) extends FenwickTree(n) {
    private[this] val data = Array.ofDim[Int](n)

    def update(i: Int, value: Int) = {
      this += (i, value - data(i))
      data(i) = value
    }
  }

  @inline def repeat(n: Int)(f: => Unit): Unit = for {_ <- 1 to n} f

  override def format(result: Result) = result mkString "\n"
}
/****************************[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]))
}

object _635D extends CodeForcesApp {
  override type Result = Seq[Long]

  override def solve(read: InputReader) = {
    val (n, k, a, b, q) = read[(Int, Int, Int, Int, Int)]
    val (fixed, broken, demand) = (new FenwickTree(n + 1), new FenwickTree(n + 1), Array.ofDim[Long](n + 1))
    var ans = Vector.empty[Long]
    repeat(q) {
      if(read[Int] == 1) {
        val (i, d) = read[(Int, Long)]
        if (demand(i) < a)  fixed(i) = d min (a - demand(i))
        if (demand(i) < b) broken(i) = d min (b - demand(i))
        demand(i) += d
      } else {
        val d = read[Int]
        val r1 = broken(1, d - 1)
        val r2 = fixed(d + k, n)
        ans = ans :+ (r1 + r2)
      }
    }
    ans
  }

  class FenwickTree(n: Int) {
    private[this] val tree = Array.ofDim[Long](n)

    def apply(i: Int): Long = if (i < 0) 0 else tree(i) + apply((i & (i + 1)) - 1)

    def apply(start: Int, end: Int): Long = this(end) - this(start - 1)

    def update(i: Int, v: Long): Unit = if (i < n) {
      tree(i) += v
      this(i | (i + 1)) = v
    }
  }

  @inline def repeat(n: Int)(f: => Unit): Unit = for {_ <- 1 to n} f

  override def format(result: Result) = result mkString "\n"
}
/****************************[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 annotation.tailrec
import java.io._

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

  val n = readInt
  def ans = if(n % 2 == 0) (n to 1) by -1 else Iterable(-1)

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

import java.util.StringTokenizer

object _233A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  if (n % 2 == 1) println(-1)
  else {
    val a = (1 to n).toArray
    for (i <- 0 until(n, 2)) {
      val cb = a(i)
      a(i) = a(i + 1)
      a(i + 1) = cb
    }
    println(a.mkString(" "))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  if (n % 2 == 1)
    println("-1")
  else
    println(Range(1, n + 1).map{i =>
      if (i % 2 == 0) i - 1
      else i + 1
      }.mkString(" "))
}

object A233 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    if(n%2 == 1) {
      println("-1")
    } else {
      println((2 to n by 2).flatMap(x => Array(x, x-1)).mkString(" "))
    }
  }

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

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

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

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

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

}

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

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

  val N = sc.nextInt

  val answer =
    if (N % 2 == 1) "-1"
    else {
      for (i <- 0 until N) yield {
        if (i % 2 == 0) i + 2
        else i
      }
    }.mkString(" ")

  out.println(answer)
  out.close
}

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

  val n = readInt()

  val ans =
    if (n % 2 == 0)
      (1 to n).map(i => if (i % 2 == 0) i - 1 else i + 1)
    else
      IndexedSeq(-1)

  println(ans.mkString(" "))
}

object test5 extends App {
    val n=readLine.toInt
    if(n%2==1)
    	println(-1)
    else
    {
        val arr=new Array[Int](n)
        for(i<-0 until n) arr(i)=i+1
        for(i<-0 until n by 2)
        {
        	val tmp=arr(i)
        	arr(i)=arr(i+1)
        	arr(i+1)=tmp
        }

        println(arr.mkString(" "))
    }
}

object test5 extends App {
    val n=readLine.toInt
    if(n%2==1)
    	println(-1)
    else
    {
        val arr=new Array[Int](n)
        for(i<-0 until n by 2)
        {
        	arr(i)=i+2
        	arr(i+1)=i+1
        }

        println(arr.mkString(" "))
    }
}

object Main {
  def main(args: Array[String]) {
    val n= readInt()
    if (n % 2 == 0) {
      val a = (1 to n).map{
        case i: Int if i % 2 == 0 => i - 1
        case i: Int if i % 2 == 1 => i + 1
      }
      println(a.mkString(" "))
    } else println("-1")
  }
}

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

object Main {
  var tokenizer = new util.StringTokenizer("")

  def readToken = {
    while (!tokenizer.hasMoreTokens) tokenizer = new util.StringTokenizer(readLine)
    tokenizer.nextToken
  }

  def readInt = readToken.toInt

  // >>>
  // >>>

  def main(args: Array[String]) {
    val n = readInt
    if (n % 2 == 1) {
      print(-1)
    } else {
      (1 to n).foreach(i => printf("%d ", if (i % 2 == 1) i + 1 else i - 1))
    }
  }
}

import java.util.Scanner

object PerfectPermutation {
  def main(args: Array[String]) = {
    val sc = new Scanner(System.in)
    val size = sc.nextInt()
    val res = perfectPermutation(size)
    res match {
      case None => println(-1)
      case Some(list) => list.foreach { i => print(s"$i ") }
    }
  }

  def perfectPermutation(size: Int): Option[List[Int]] = {
    if (size % 2 == 1) None
    else Some((1 to size).map(i => if (i % 2 == 0) i - 1 else i + 1).toList)
  }
}

import java.util._
import scala.io._
import java.lang.System._

object Main {
  def main(args: Array[String]) {
    val sc = new Scanner(in)
    val n = sc.nextInt
    if (n % 2 == 1) println(-1)
    else{
      (1 to n) map {
        case i if i % 2 == 0 => i-1
        case i               => i+1
      } foreach {
          e => print(e+" ")
      }
    }
  }
}

import java.util.Scanner
object A extends App {
  val sc= new Scanner(System.in)
  val n = sc.nextInt
  if (n % 2 == 0) {
    println((1 to n).map{x => x + (x % 2) * 2 - 1}.mkString(" "))
  } else {
    println(-1)
  }
}

import scala.io.StdIn

object A233 {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    println(n match {
      case x if x % 2 != 0 => -1
      case x => (1 to n).grouped(2). map(_.reverse).flatten.mkString(" ")
    })
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  if (n % 2 == 1)
    println("-1")
  else
    println(Range(1, n + 1).map{i =>
      if (i % 2 == 0) i + 1
      else i - 1
      }.mkString(" "))
}

object test5 extends App {
    val n=readLine.toInt
    if(n==1)
    	println(-1)
    else
    {
        val arr=new Array[Int](n)
        for(i<-0 until n) arr(i)=i
        arr(0)=n
        println(arr.mkString(" "))
    }
}


import scala.io.StdIn._

object Solution {
  def main(args: Array[String]): Unit = {
    def go(n: Int, lower: Int, upper: Int): (Int, Int) = {
      if (n == 0) {
        (lower, upper)
      } else {
        val Array(change, div) = readLine.split(" ").map(_.toInt)
        if (div == 1) go(n - 1, Math.max(lower + change, 1900 + change), upper + change)
        else go(n - 1, lower + change, Math.min(upper + change, 1899 + change))
      }
    }
    val (lower, upper) = go(readInt, -200000000, 200000000)
    println(if (lower > upper) "Impossible" else if (upper > 100000000) "Infinity" else upper)
  }
}

object C extends App {

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

  val Array(n) = readInts(1)
  val cs, ds = Array.ofDim[Int](n)

  for (i <- 0 until n) {
    val Array(c, d) = readInts(2)
    cs(i) = c
    ds(i) = d
  }

  if (ds.forall(_ == 1)) println("Infinity")
  else {

    var max: Long = if (ds.last == 2) 1899L else Int.MaxValue
    var min: Long = if (ds.last == 2) Int.MinValue else 1900L
    var ok = true

    for (i <- n - 2 to 0 by -1) {
      if (ds(i) == 2) {
        max = Math.min(max - cs(i), 1899L)
        min = min - cs(i)
      } else {
        max = max - cs(i)
        min = Math.max(min - cs(i), 1900L)
      }
      if (min > max) ok = false
    }

    for (i <- 0 until n) max += cs(i)

    if (ok) println(max)
    else println("Impossible")
  }
}

import scala.io.StdIn._

object Solution {
  def main(args: Array[String]): Unit = {
    def go(n: Int, lower: Int, upper: Int): (Int, Int) = {
      if (n == 0) {
        (lower, upper)
      } else {
        val Array(change, div) = readLine.split(" ").map(_.toInt)
        if (div == 1) go(n - 1, Math.max(lower + change, 1900 + change), upper + change)
        else go(n - 1, lower + change, Math.min(upper + change, 1899 + change))
      }
    }
    val (lower, upper) = go(readInt, -200000000, 200000000)
    println(if (lower > upper) "Impossible" else if (upper > 20000000) "Infinity" else upper)
  }
}


object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

//  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val n = in.nextInt()

    n.times {
      val item = in.nextInt()
      val col  = in.nextInt()

      var ans = 0L

      if (item <= col) {
        val r = (item - 1).toLong
        ans = ans + ((r * (r + 1)) / 2)
      } else if (item > col) {
        val r2 = col.toLong
        ans = ans + ((r2 * (r2 + 1)) / 2)
      }

      if (item <= col) {
        ans = ans + 1
      }

      println(ans)
    }
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {

    def this(reader: BufferedReader) = this(new LineNumberReader(reader))

    def this(reader: Reader) = this(new BufferedReader(reader))

    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

    def this(str: String) = this(new StringReader(str))

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

    private[this] var current: Option[StringTokenizer] = None

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

    /**
      * Unlike Java's scanner which returns till end of current line, this actually returns the next line
      * @see line() if you want the Java behaviour
      */
    def nextLine(): String = {
      current = None // reset
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextString(): String = next()

    def nextChar(): Char = next().ensuring(_.length == 1).head

    def nextBoolean(): Boolean = next().toBoolean

    def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

    def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

    def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

    def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

    def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

    def nextFloat(): Float = next().toFloat

    def nextDouble(): Double = next().toDouble

    def nextBigDecimal(): BigDecimal = BigDecimal(next())

    override def next(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

import scala.io.StdIn._

object B extends App {

  val t = readInt()
  1 to t foreach { _ =>
    val Array(n, r) = readLine().split(" ").map(_.toInt)

    val answer =
      if (n <= r) {
        (n - 1).toLong * (n) / 2 + 1
      } else {
        r.toLong * (r + 1) / 2
      }
    println(answer)
  }
}

object B extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

//  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val n = in.nextInt()

    n.times {
      val item = in.nextInt()
      val col  = in.nextInt()

      var ans = 0L

      if (item < col) {
        val r = (item - 1).toLong
        ans = ans + ((r * (r + 1)) / 2)
      } else if (item > col) {
        val r2 = col.toLong
        ans = ans + ((r2 * (r2 + 1)) / 2)
      }

      if (item <= col) {
        ans = ans + 1
      }

      println(ans)
    }
  }

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

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {

    def this(reader: BufferedReader) = this(new LineNumberReader(reader))

    def this(reader: Reader) = this(new BufferedReader(reader))

    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

    def this(str: String) = this(new StringReader(str))

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

    private[this] var current: Option[StringTokenizer] = None

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

    /**
      * Unlike Java's scanner which returns till end of current line, this actually returns the next line
      * @see line() if you want the Java behaviour
      */
    def nextLine(): String = {
      current = None // reset
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextString(): String = next()

    def nextChar(): Char = next().ensuring(_.length == 1).head

    def nextBoolean(): Boolean = next().toBoolean

    def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

    def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

    def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

    def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

    def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

    def nextFloat(): Float = next().toFloat

    def nextDouble(): Double = next().toDouble

    def nextBigDecimal(): BigDecimal = BigDecimal(next())

    override def next(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}


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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    val anm         = Array.fill(n)(readLine().toCharArray)

    val ans = (0 until n).foldLeft((0, 0), (0, 0)) { case ((r, w), i) =>
      (0 until m).foldLeft(r, w) { case ((r, w), j) =>
        anm(i)(j) match {
          case 'R' => if ((i + j) % 2 == 0) ((1, r._2), w) else ((r._1, 1), w)
          case 'W' => if ((i + j) % 2 == 0) (r, (1, w._2)) else (r, (w._1, 1))
          case _   => (r, w)
        }
      }
    }

    ans match {
      case ((0 | 1, 0), (0, 0 | 1)) =>
        println("YES")
        (0 until n).foreach { i =>
          val l = (0 until m).map(j => if ((i + j) % 2 == 0) 'R' else 'W')
          println(l.mkString(""))
        }
      case ((0, 0 | 1), (0 | 1, 0)) =>
        println("YES")
        (0 until n).foreach { i =>
          val l = (0 until m).map(j => if ((i + j) % 2 == 0) 'W' else 'R')
          println(l.mkString(""))
        }
      case _                => println("NO")
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    val anm         = Array.fill(n)(readLine().toCharArray)

    val ans = anm.zipWithIndex
      .foldLeft[(Boolean, Option[Int])]((true, None)) {
        case (state @ (true, _), (am, i)) =>
          am.zipWithIndex.foldLeft(state) {
            case ((true, t), (c @ ('R' | 'W'), j)) =>
              val e = (i + j + c) % 2
              (t.getOrElse(e) == e, Some(e))
            case (state, _)                        => state
          }
        case (state, _)                   => state
      }

    ans match {
      case (true, t) =>
        println("YES")
        (0 until n).foreach { i =>
          val l = (0 until m).map(j => if ((i + j) % 2 == t.getOrElse(0)) 'R' else 'W')
          println(l.mkString(""))
        }
      case _         => println("NO")
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    val anm         = Array.fill(n)(readLine().toCharArray)

    val ans = (0 until n).foldLeft((0, 0), (0, 0)) { case ((r, w), i) =>
      (0 until m).foldLeft(r, w) { case ((r, w), j) =>
        anm(i)(j) match {
          case 'R' => if ((i + j) % 2 == 0) ((1, r._2), w) else ((r._1, 1), w)
          case 'W' => if ((i + j) % 2 == 0) (r, (1, w._2)) else (r, (w._1, 1))
          case _   => (r, w)
        }
      }
    }

    ans match {
      case ((1, 0), (0, 1)) =>
        println("YES")
        (0 until n).foreach { i =>
          val l = (0 until m).map(j => if ((i + j) % 2 == 0) 'R' else 'W')
          println(l.mkString(""))
        }
      case ((0, 1), (1, 0)) =>
        println("YES")
        (0 until n).foreach { i =>
          val l = (0 until m).map(j => if ((i + j) % 2 == 0) 'W' else 'R')
          println(l.mkString(""))
        }
      case _                => println("NO")
    }
  }
}

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

  val t = readInt()

  (0 until t).foreach { _ =>
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    val anm         = Array.fill(n)(readLine().toCharArray)

    val ans = anm.zipWithIndex
      .foldLeft[(Boolean, Option[Int], Option[Int])]((true, None, None)) {
        case (state @ (true, _, _), (am, i)) =>
          am.zipWithIndex.foldLeft(state) {
            case ((_, None, None), ('R', j)) => (true, Some((i + j) % 2), Some((i + j + 1) % 2))
            case ((_, None, None), ('W', j)) => (true, Some((i + j + 1) % 2), Some((i + j) % 2))
            case ((_, Some(r), _), ('R', j)) if (i + j) % 2 != r => (false, None, None)
            case ((_, _, Some(w)), ('W', j)) if (i + j) % 2 != w => (false, None, None)
            case (state, _) => state
          }
        case (state, _)                      => state
      }

    ans match {
      case (true, Some(r), Some(w)) =>
        println("YES")
        (0 until n).foreach { i =>
          val l = (0 until m).map(j => if ((i + j) % 2 == r) 'R' else 'W')
          println(l.mkString(""))
        }
      case _                        => println("NO")
    }
  }
}