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

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 nextLong: Long = return java.lang.Long.parseLong(next)

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

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    val name = next.toCharArray
    val letters = new Array[Char](27)
    val positions = new Array[Int](n)
    for (i <- 0 until n) {
      positions(i) = name(i) - 'a'
      letters(positions(i)) = name(i)
    }
    for (i <- 0 until m) {
      val x = next.toCharArray.apply(0)
      val y = next.toCharArray.apply(0)
      var ind = -1
      for (j <- 0 until 27) {
        if (letters(j) == x) {
          letters(j) = y
          ind = j
        }
      }
      for (j <- 0 until 27) {
        if (letters(j) == y && j != ind) {
          letters(j) = x
        }
      }
    }
    for (i <- 0 until positions.length) {
      out.print(letters(positions(i)))
    }
    return 0
  }
}

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

import CodeForcesApp._

object _591B extends CodeForcesApp {
  override type Result = String

  override def solve(scanner: Scanner) = {
    import scanner._
    val (l, n) = (nextInt(), nextInt())
    val s = nextString()
    var d = Map.empty[Char, Char]
    repeat(n) {
      val (x, y) = (nextChar(), nextChar())
      if (x != y) {
        var (f1, f2) = (false, false)
        d = d map {
          case (i, `x`) =>
            f1 = true
            i -> y
          case (i, `y`) =>
            f2 = true
            i -> x
          case i => i
        }
        if(!f1) d = d + (x -> y)
        if(!f2) d = d + (y -> x)
      }
    }
    s map {i => d.getOrElse(i, i)}
  }

  override def format(result: Result) = super.format(result)
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  final val eps: Double = 1e-9
  @inline final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  @inline final def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)
  @inline final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
  import scala.collection.mutable.{Map => Dict, Set => Bag}
  final def nil[A]: List[A] = List.empty[A]
  final def bag[A]: Bag[A] = Bag.empty[A]
  final def map[A] = new {
    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default
  }
}
/********************************[Scala Scanner]*********************************************/
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
  }

  /**
   * @return Unlike the Java scanner which returns till end of current line, this actually returns the next line
   */
  def nextLine(): String = {
    current = None   // reset
    reader.readLine()
  }
  def lineNumber: Int = reader.getLineNumber
  def nextString(): String = next()
  def nextChar(): Char = next().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 hasNext = tokenizer().exists(_.hasMoreTokens)
  override def next() = tokenizer().get.nextToken()
  override def close() = reader.close()
}

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

import CodeForcesApp._

object _591B extends CodeForcesApp {
  override type Result = String

  override def solve(scanner: Scanner) = {
    import scanner._
    val (l, n) = (nextInt(), nextInt())
    val s = nextString()
    var d = Map.empty[Char, Char]
    repeat(n) {
      val (x, y) = (nextChar(), nextChar())
      if (x != y) {
        var (f1, f2) = (false, false)
        d = d map {
          case (i, `x`) =>
            f1 = true
            i -> y
          case (i, `y`) =>
            f2 = true
            i -> x
          case i => i
        }
        if(!f1) d = d + (x -> y)
        if(!f2) d = d + (y -> x)
        //debug(x, y, f1, f2, d)
      }
    }
    s map {i => d.getOrElse(i, i)}
  }

  override def format(result: Result) = super.format(result)
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  final val eps: Double = 1e-9
  @inline final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  @inline final def repeat(n: Int)(f: => Unit): Unit = (1 to n).foreach(_ => f)
  @inline final def desc[A: Ordering]: Ordering[A] = implicitly[Ordering[A]].reverse
  import scala.collection.mutable.{Map => Dict, Set => Bag}
  final def nil[A]: List[A] = List.empty[A]
  final def bag[A]: Bag[A] = Bag.empty[A]
  final def map[A] = new {
    def to[B](default: B): Dict[A, B] = Dict.empty[A, B] withDefaultValue default
  }
}
/********************************[Scala Scanner]*********************************************/
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))

  val lines: Iterator[String] = Iterator.continually(reader.readLine()).takeWhile(_ != null)

  def tokens: Iterator[String] = for {
    line <- lines
    tokenizer = new StringTokenizer(line)
    _ <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokenizer.nextToken()

  private[this] var current = tokens
  override def hasNext = current.hasNext
  @inline override def next() = current.next()

  /**
   * @return Unlike the Java scanner which returns till end of current line, this actually returns the next line
   */
  def nextLine(): String = {
    current = tokens   // reset
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def nextString(): String = next()
  def nextChar(): Char = next().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 close() = reader.close()
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val str = readLine().toCharArray

  val M = scala.collection.mutable.Map[Char, Char]()
  for (ch <- 'a' to 'z') {
    M(ch) = ch
  }

  def change(from: Char, to: Char) = {
    if (from != to) {
      var curr1 = from
      while (M(curr1) != from) curr1 = M(curr1)

      var curr2 = to
      while (M(curr2) != to) curr2 = M(curr2)

      M(curr1) = to
      M(curr2) = from
    }
  }

  for (i <- 1 to m) {
    val Array(x, y) = readLine().split(" ").map(_.charAt(0))
    change(x, y)
  }

  println(str.map { ch => M(ch)}.mkString(""))
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.util.HashMap
import java.util.HashSet

object B {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

//    class XXX(val number:Int, var x: Int) {
//      override def toString(): String = {
//        return number + "(" + x + ")"
//      }
//    }

    val is = System.in

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

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    val n = line1.nextToken().toInt
    val m = line1.nextToken().toInt

    var name = br.readLine()

//    val actions = new Array[(Char, Char)](m)
//    val
    val map = new HashMap[Char, HashSet[Char]]()
    for (i <- 0 until m) {
      val acL = br.readLine().split(" ")
      val (c1, c2) = (acL(0)(0), acL(1)(0))

      if (c1 != c2) {
        var cur1 = map.get(c1)
        if (cur1 != null) {
          map.remove(c1);
        } else {
          cur1 = new HashSet()
          cur1.add(c1)
        }

        var cur2 = map.get(c2)
        if (cur2 != null) {
          map.remove(c2);
        } else {
          cur2 = new HashSet()
          cur2.add(c2)
        }

        val prev1 = map.get(c2)
        if (prev1 != null) cur1.addAll(prev1)
        map.put(c2, cur1)
//        db(mkMP)
        val prev2 = map.get(c1)
        if (prev2 != null) cur2.addAll(prev2)
        map.put(c1, cur2)
//        db(mkMP)
      }

    }

//    def mkMP(): String = {
//      var res = ""
//      val it = map.entrySet().iterator()
//      while (it.hasNext()) {
//        val entry = it.next()
//        val to = entry.getKey()
//        res += to + "->["
//        val from = entry.getValue()
//        val fromIt = from.iterator()
//        while (fromIt.hasNext()) {
//          res+= fromIt.next() + ", "
//        }
//        res += "]"
//      }
//      res
//    }

    val map2 = new HashMap[Char, Char]()
    val it = map.entrySet().iterator()
    while (it.hasNext()) {
      val entry = it.next()
      val to = entry.getKey()
      val from = entry.getValue()
      val fromIt = from.iterator()
      while (fromIt.hasNext()) {
        map2.put(fromIt.next(), to);
      }
    }

    var res2 = new StringBuffer()
    for(i <- name) {
      if (map2.containsKey(i)) {
        res2.append(map2.get(i))
      } else
        res2.append(i)
    }

    println(res2.toString())

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

  }

//========================= samples ========================
val sa1 = """6 1
police
p m
"""

val sa2 = """
11 6
abacabadaba
a b
b c
a d
e g
f a
b b
"""

//========================= samples end ====================
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val str = in.next()
  var map = ('a' to 'z').map(i => i -> i).toMap
  var backMap = ('a' to 'z').map(i => i -> i).toMap
  val nMap = (1 to m).foreach { _ =>
    val Array(a, b) = in.next().split(' ').map(_.head)
    val fa = backMap(a)
    val fb = backMap(b)
    map += (fa -> b)
    map += (fb -> a)
    backMap += (b -> fa)
    backMap += (a -> fb)
  }
  println(str.map(map).mkString)
}

object B591 {

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

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val name = read.toCharArray
    val map = ('a' to 'z').toArray
    for(_ <- 1 to m) {
      val Array(x, y) = readChars(2)
      for(i <- 0 until 26)
        if(map(i) == x)
          map(i) = y
        else if(map(i) == y)
          map(i) = x
    }
    for(i <- name.indices)
      if(map(name(i)-'a') != -1)
        name(i) = map(name(i)-'a')
    println(name.mkString(""))
  }

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

    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readChars(n: Int): Array[Char] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.head)
    }

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

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

}

object B591 {

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

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val name = read.toCharArray
    val map = ('a' to 'z').toArray
    for(_ <- 1 to m) {
      val Array(x, y) = readChars(2)
      for(i <- 0 until 26)
        if(map(i) == x)
          map(i) = y
        else if(map(i) == y)
          map(i) = x
    }
    println(name.map(a => map(a-'a')).mkString(""))
  }

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

    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readChars(n: Int): Array[Char] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.head)
    }

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

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

}

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

  val to = Array.tabulate('z' + 1)(i => i.toChar)

  for (_ <- 1 to m) {
    val r = readLine
    val x = r(0)
    val y = r(2)
    for (i <- 'a' to 'z') {
      if (to(i) == x) to(i) = y
      else if (to(i) == y) to(i) = x
    }
  }

  val res = s.map(c => to(c)).mkString

  println(res)
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  val str = readLine().toCharArray

  val M = scala.collection.mutable.Map[Char, Char]()
  for (ch <- 'a' to 'z') {
    M(ch) = ch
  }

  def change(from: Char, to: Char) = {
    var curr = from
    while (M(curr) != from) curr = M(curr)
    M(curr) = to

    curr = to
    while (M(curr) != to) curr = M(curr)
    M(curr) = from
  }

  for (i <- 1 to m) {
    val Array(x, y) = readLine().split(" ").map(_.charAt(0))
    change(x, y)
  }

  println(str.map { ch => M(ch)}.mkString(""))
}

import java.io._
import java.util.ArrayList
import java.util.StringTokenizer
import java.util.HashMap
import java.util.HashSet

object B {

  def main(args: Array[String]): Unit = {
    var debugV = false
    def db(x: => String) = if (debugV)  println(x) // nullary function

//    class XXX(val number:Int, var x: Int) {
//      override def toString(): String = {
//        return number + "(" + x + ")"
//      }
//    }

    val is = System.in

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

    val bis = new BufferedInputStream(is);
    val br = new BufferedReader(new InputStreamReader(bis));

    //---------------------------- parameters reading ------------------------------------
    val line1 = new StringTokenizer(br.readLine())
    val n = line1.nextToken().toInt
    val m = line1.nextToken().toInt

    var name = br.readLine()

//    val actions = new Array[(Char, Char)](m)
//    val
    val map = new HashMap[Char, HashSet[Char]]()
    for (i <- 0 until m) {
      val acL = br.readLine().split(" ")
      val (c1, c2) = (acL(0)(0), acL(1)(0))

      if (c1 != c2) {
        var cur1 = map.get(c1)
        if (cur1 != null) {
          map.remove(c1);
        } else {
          cur1 = new HashSet()
          cur1.add(c1)
        }

        var cur2 = map.get(c2)
        if (cur2 != null) {
          map.remove(c2);
        } else {
          cur2 = new HashSet()
          cur2.add(c2)
        }

        val prev1 = map.get(c2)
        if (prev1 != null) cur1.addAll(prev1)
        map.put(c2, cur1)
        db(mkMP)
        val prev2 = map.get(c1)
        if (prev2 != null) cur2.addAll(prev2)
        map.put(c1, cur2)
        db(mkMP)
      }

    }

    def mkMP(): String = {
      var res = ""
      val it = map.entrySet().iterator()
      while (it.hasNext()) {
        val entry = it.next()
        val to = entry.getKey()
        res += to + "->["
        val from = entry.getValue()
        val fromIt = from.iterator()
        while (fromIt.hasNext()) {
          res+= fromIt.next() + ", "
        }
        res += "]"
      }
      res
    }

    val map2 = new HashMap[Char, Char]()
    val it = map.entrySet().iterator()
    while (it.hasNext()) {
      val entry = it.next()
      val to = entry.getKey()
      val from = entry.getValue()
      val fromIt = from.iterator()
      while (fromIt.hasNext()) {
        map2.put(fromIt.next(), to);
      }
    }

    val map2It = map2.entrySet().iterator()
    while (map2It.hasNext()) {
      val couple = map2It.next()
      name = name.replace(couple.getKey(), couple.getValue())
    }
    println(name)

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

  }

//========================= samples ========================
val sa2 = """
11 6
abacabadaba
a b
b c
a d
e g
f a
b b
"""

//========================= samples end ====================
}


object Main extends App {
  class PipedObject[T] private[Main] (value:T)
	{
		def |>[R] (f : T => R) = f(this.value)
	}
	implicit def toPiped[T] (value:T) = new PipedObject[T](value)
	def divisible6(a: Long) = if (a % 6 == 0)  true else false
	def isPrime(n: Int) = (2 to n) |> (r => r.foldLeft(r.toSet)((ps, x) => if (ps(x)) ps -- (x * x to n by x) else ps))
	//println( 5L * 7L |> divisible6)
	//println( isPrime(25))
	def calc(n:Int,p:Int): Int = p + (if( 2*p <= n) calc(n, 2*p) else 0)
	var n = readInt()
	for(i <- 1 to n) {
		var r = readInt()
	  println( (r * 1L * (r+1)) / 2 - 2 * calc(r, 1))
	}
}

import scala.io.StdIn

object Test extends App {
  val ncase = StdIn.readInt()
  for (i <- 0 until ncase) {
    val n = StdIn.readLong()
    val allSum = if (n % 2 == 0) n / 2 * (n + 1) else (n + 1) / 2 * n
    var partialSum: Long = 0
    var pow2: Long = 1
    while (pow2 <= n) {
      partialSum += pow2
      pow2 <<= 1
    }
    println(allSum - partialSum * 2)
  }
}

import scala.io.StdIn

object A {
  def main(args: Array[String]): Unit = {
    val T = StdIn.readInt()
    for (_ <- 1 to T) {
      val n = StdIn.readLong()
      var ans = n * (n + 1) / 2
      var t = 1
      while (t <= n) {
        ans -= 2 * t
        t *= 2
      }
      println(ans)
    }
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val t = in.next().toInt

  def squares(n: Long): Long = {
    var res = 1l
    var sum = 0l
    while (res <= n) {
      sum += res
      res *= 2
    }
    sum
  }

  def sum(n: Long): Long = {
    (n + 1) * n / 2 - 2 * squares(n)
  }

  println((1 to t).map(i => sum(in.next().toInt)).mkString("\n"))
}

object A598 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(t) = readInts(1)
    for(_ <- 1 to t) {
      val Array(n) = readLongs(1)
      val log = (math.log(n)/math.log(2)).toInt

      var ret = (n*(n+1))/2
      for(i <- 0 to log) {
        ret -= math.pow(2, i+1).toLong
      }
      println(ret)
    }
  }

  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.io._
import java.util._

import scala.collection.mutable

object A {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  def solve: Int = {
    val t = nextInt
    for (i <- 0 until t) {
      val n = nextInt
      var firstSumPart = 1L * n * (1L + n) / 2
      var num = 1L
      while (num <= n) {
        firstSumPart -= 2L * num
        num *= 2L
      }
      out.println(firstSumPart)
    }
    return 0
  }
}

object A01TrickySum {
  //import java.io.{InputStream, PrintStream}
  //import java.util.Scanner
  import scala.io.StdIn._
  def solve(/*input: InputStream, output: PrintStream*/): Unit = {
    //val sc = new Scanner(input)
    val t = readInt
    (1 to t).foreach( i => {
      val n = readLong()
      val sumaContinua = (n * (n + 1)) / 2L
      //maximo k tal que 2**k <= n
      val k = (0 until 32).filter( i => (1L << i) <= n).last
      val suma2k_1 = (1L << (k + 1)) - 1L
      val ans = sumaContinua - 2L * suma2k_1
      println(ans)

    })
  }
  def main(args: Array[String]): Unit = {
    solve(/*System.in,System.out*/)
  }

}

object A01TrickySum {
  import java.io.{InputStream, PrintStream}
  import java.util.Scanner
  def solve(input: InputStream, output: PrintStream): Unit = {
    val sc = new Scanner(input)
    val t = sc.nextInt
    (1 to t).foreach( i => {
      val n = sc.nextLong()
      val sumaContinua = (n * (n + 1)) / 2L
      //maximo k tal que 2**k <= n
      val k = (0 until 32).filter( i => (1L << i) <= n).last
      val suma2k_1 = (1L << (k + 1)) - 1L
      val ans = sumaContinua - 2L * suma2k_1
      output.println(ans)

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

}

object Main extends App {
  val ans = (n:Long) => n*(n+1)/2 -Stream.from(0).map(BigInt(0) setBit _ ).dropWhile(_<=n).tail.head+2
  val n = readInt()

  for(a <- 1 to n) {
    val x = readInt()
    println(ans(x))
  }
}

object Main extends App {
  val ans = (n:Long) => n*(n+1)/2 -(0 to 1000).toList.map(BigInt(0) setBit _ ).dropWhile(_<=n).tail.head+2
  val n = readInt()

  for(a <- 1 to n) {
    val x = readInt()
    println(ans(x))
  }
}

object Main extends App {
  val ans = (n:Long) => n*(n+1)/2 -(0 to 1000).map(BigInt(0) setBit _ ).dropWhile(_<=n).tail.head+2
  val n = readInt()

  for(a <- 1 to n) {
    val x = readInt()
    println(ans(x))
  }
}

import scala.io.StdIn

object Test extends App {
  val ncase = StdIn.readInt()
  for (i <- 0 until ncase) {
    val n = StdIn.readLong()
    val allSum = if (n % 2 == 0) n / 2 * (n + 1) else (n + 1) / 2 * n
    var partialSum: Long = 0
    var pow2: Long = 1
    while (pow2 < n) {
      partialSum += pow2
      pow2 <<= 1
    }
    println(allSum - partialSum * 2)
  }
}


object Main extends App {

  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val table = (0 to n-1) map { _ =>
    readLine.split("").filterNot(_ == "")
  } toList

  def isSorted(seq: List[String]): Boolean = {
    seq.isEmpty ||
      0 == (seq zip seq.tail map { case (a1, a2) => a2 >= a1 } count (_ == false))
  }

  def columnAt(index: Int): List[String] = {
    table map { case r => r(index) }
  }

  val init = (Stream.fill(n)("").toList, 0)
  val (_, rem) = (0 to m-1).foldLeft(init)({
    case ((rows, removed), index) =>
      val cs = columnAt(index)
      val next = (rows zip cs) map { case (row, c) => row + c }
      if(isSorted(next)) (next, removed) else (rows, removed+1)
  })

  println(rem)

}

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, m) = readInts(2)
  val ss = Array.fill(n){ readLine }

  var equalToPrev = Array.fill(n){ true }
  equalToPrev(0) = false
  var removedCount = 0

  for (col <- 0 until m) {
    var prev = ss(0)(col)
    val equalToPrev2 = equalToPrev.clone()
    var remove = false
    for (row <- 1 until n) {
      val curr = ss(row)(col)
      if (prev > curr && equalToPrev(row)) {
        remove = true
      } else if (prev < curr) {
        equalToPrev2(row) = false
      }
      prev = curr
    }
    if (remove) removedCount += 1
    else equalToPrev = equalToPrev2
  }

  println(removedCount)
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val marked = Array.ofDim[Boolean](m)
  val data = (1 to n).map(_ => in.next())
  val t = (0 until m).foldLeft((0, List((0, n - 1)))) {
    case(acc@(_, Nil), i) =>
//      println("heere")
      acc
    case((x, list), i) =>
//      println(list)
//      println(i)
//      println(x)
      val remove = list.exists {
        case(first, last) => (first until last).exists(j => data(j)(i) > data(j + 1)(i))
      }
      if (remove)
        (x + 1, list)
      else {
        (x, list.flatMap{
          case(first, last) =>
            val res = (first until last).filter(j => data(j)(i) != data(j + 1)(i))
//            println("res")
//            println(res)
//            println((first until last).toList)
//            println("-----------")
            val ans = res.foldLeft((first, List.empty[(Int, Int)])) {
              case((prev, ll), z) => (z + 1, (prev, z) :: ll)
            }
            ((ans._1, last) :: ans._2).filter(i => i._1 != i._2)
        })
      }
  }
  println(t._1)
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val marked = Array.ofDim[Boolean](m)
  val data = (1 to n).map(_ => in.next())
  val t = (0 until m).foldLeft((0, List((0, n - 1)))) {
    case(acc@(_, Nil), i) =>
//      println("heere")
      acc
    case((x, list), i) =>
//      println(list)
//      println(i)
//      println(x)
      val remove = list.exists {
        case(first, last) => (first until last).exists(j => data(j)(i) > data(j + 1)(i))
      }
      if (remove)
        (x + 1, list)
      else {
        (x, list.flatMap{
          case(first, last) =>
            val res = (first until last).filter(j => data(j)(i) != data(j + 1)(i))
//            println("res")
//            println(res)
//            println((first until last).toList)
//            println("-----------")
            val ans = res.foldLeft((0, List.empty[(Int, Int)])) {
              case((prev, ll), z) => (z + 1, (prev, z) :: ll)
            }
            ((ans._1, last) :: ans._2).filter(i => i._1 != i._2)
        })
      }
  }
  println(t._1)
}

object Main extends App {

  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val table = (0 to n-1) map { _ =>
    readLine.split("").filterNot(_ == "")
  } toList

  def isSorted(seq: List[String]): Boolean = {
    seq.isEmpty ||
      0 == (seq zip seq.tail map { case (a1, a2) => a2 >= a1 } count (_ == false))
  }

  def column(rows: Set[Int], index: Int): List[(String, Int)] = {
    table.zipWithIndex flatMap { case (r, i) => if(rows.contains(i)) List((r(index), i)) else List() }
  }

  def filterEq(column: List[(String, Int)]): Set[Int] = {
    column.groupBy(_._1).flatMap({
      case (v, indices) => if(indices.size > 1) indices.map(_._2) else List()
    }).toSet
  }

  val init = ((0 to n-1).toSet, 0)
  val (_, rem) = (0 to m-1).foldLeft(init)({
    case ((rows, removed), index) =>
      val cs = column(rows, index)
      if(isSorted(cs.map(_._1))) {
        (filterEq(cs), removed)
      } else {
        (rows, removed+1)
      }
  })

  println(rem)

}

object Main extends App {

  val Array(n, m) = readLine.split(" ").map(_.toInt)
  val table = (0 to n-1) map { _ =>
    readLine.split("").filterNot(_ == "")
  } toList

  def isSorted(seq: List[String]): Boolean = {
    0 == (seq zip seq.tail map { case (a1, a2) => a2 >= a1 } count (_ == false))
  }

  def isSortedAt(index: Int): Boolean = {
    isSorted(table map { r => r(index) })
  }

  println((0 to m-1) count (index => !isSortedAt(index)) )

}


import scala.io.StdIn

object StringGame {

  def step(n: List[Char], a: Char): List[Char] = n match {
    case Nil => List(a)
    case x :: xs => if (x == a) xs else a :: n
  }

  def main(args: Array[String]): Unit = {
    val in = StdIn.readLine().toList
    val res = in.foldLeft[List[Char]](List())(step)
    val isFirstWinner = (in.length - res.length) / 2 % 2 == 1
    println(if (isFirstWinner) "YES" else "NO")
  }

//  def main(args: Array[String]): Unit = {
//    val in = StdIn.readLine()
//    var acc = ""
//    in.foreach { ch =>
//      acc = step(acc, ch)
//    }
//
//    val isFirstWinner = (in.length - acc.length) / 2 % 2 == 1
//    println(if (isFirstWinner) "YES" else "NO")
//  }
}

object Main {

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

    val n = std.readLine()

    var stack = List.empty[Char]

    var count = 0

    for (i <- 0 until n.length) {
      if (stack.isEmpty || stack.head != n(i)) {
        stack = n(i) :: stack
      }
      else {
        stack = stack.tail
        count += 1
      }
    }

    if (count % 2 == 0) {
      println("No")
    }
    else {
      println("Yes")
    }
  }
}

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 S = ns()
    val N = S.length
    var cnt = 0

    val stack = mutable.Stack[Char]()
    REP(N) { i =>
      if (stack.nonEmpty && stack.head == S(i)) {
        cnt += 1
        stack.pop()
      } else {
        stack.push(S(i))
      }
    }

    if (cnt % 2 == 0) {
      out.println("No")
    } else {
      out.println("Yes")
    }
  }

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

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

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

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

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

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

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

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

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

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

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 S = ns()
    val N = S.length
    var cnt = 0
    val del = Array.ofDim[Boolean](N)
    REP(N) { i =>
      var j = 0
      while (i + j < N && i - 1 - j >= 0 && S(i + j) == S(i - 1 - j) && !del(i - 1 - j)) {
        cnt += 1
        del(i + j) = true
        del(i - 1 - j) = true
        j += 1
      }
    }

    if (cnt % 2 == 0) {
      out.println("No")
    } else {
      out.println("Yes")
    }
  }

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

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

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

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

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

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

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

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

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

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

import scala.io.StdIn

object StringGame {

  def play(s: String): String = if (s.isEmpty) s else step(s.head, play(s.tail))

  def step(a: Char, n: String): String = if (n.startsWith(a.toString)) n.drop(1) else a + n

  def main(args: Array[String]): Unit = {
    val in = StdIn.readLine()
    val res = play(in)
    val isFirstWinner = (in.length - res.length) / 2 % 2 == 1
    println(isFirstWinner)
  }
}

import scala.io.StdIn

object StringGame {

  def play(s: String): String = if (s.isEmpty) s else step(s.head, play(s.tail))

  def step(a: Char, n: String): String = if (n.startsWith(a.toString)) n.drop(1) else a + n

  def main(args: Array[String]): Unit = {
    val in = StdIn.readLine()
    val res = play(in)
    val isFirstWinner = (in.length - res.length) / 2 % 2 == 1
    println(res)
  }
}


import scala.io.StdIn._

object Main2 extends App {
  val Array(_, lastCoordinate) = readLine().split(" ").map(_.toInt)
  val lanternsCoordinates = readLine().split(" ").map(_.toInt).toVector.sorted
  val maxDistanceBetweenLanterns = lanternsCoordinates
    .foldLeft[(Int, Int)]((0, lanternsCoordinates.head)){ case ((maxDistance, previousCoordinate),  currentCoordinate) =>
      (Math.max(maxDistance, currentCoordinate - previousCoordinate), currentCoordinate)
    }._1
  println(Vector(lanternsCoordinates.head, maxDistanceBetweenLanterns/2.0, lastCoordinate - lanternsCoordinates.last).max)
}

object B {
  def main(args: Array[String]) = {
    val nl = readLine().split(' ').map(t => t.toInt)
    val n = nl(0)
    val l = nl(1)
    val lamps = readLine().split(' ').map(t => t.toInt).sorted
    var ans = 2 * math.max(l - lamps(n - 1), lamps(0))
    for (i <- lamps.indices) {
      if (i + 1 < lamps.length) {
        ans = math.max(ans, lamps(i + 1) - lamps(i))
      }
    }
    println(ans / 2.0)
  }
}

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

object Solution {
  def solve(in: FastScanner, out: PrintWriter): Unit = {
    val n = in.nextInt()
    val l = in.nextInt()
    val a = new Array[Int](n)
    for (i <- 0 until n)
      a(i) = in.nextInt()
    Arrays.sort(a)
    var res: Double = Math.max(a(0), l - a(n - 1))
    for (i <- 1 until n)
      res = Math.max(res, (a(i) - a(i - 1)) / 2.0)
    println(res)
  }

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

  class FastScanner(val in: InputStream) {
    var st: StringTokenizer = null
    var br = new BufferedReader(new InputStreamReader(in))

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

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

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

    def close(): Unit = {
      br.close()
    }
  }

}

import scala.math.Ordering._

object Main extends App {
  val Array(n, l) = readLine.split(" ").map(_.toInt)
  val fs: List[Int] = readLine.split(" ").map(_.toInt).toList
  val row: List[Int] = fs.sorted
  val dm: List[Int] = (row zip row.tail).map({
     case (a, b) => b - a
  })
  val d = if(dm.isEmpty) 0 else dm.max
  println("%.9f".format(List(d/2.0, row.head - 0.0, l - row.last).max))
}

import scala.io.StdIn._

object TaskA extends App {
  val (n, l) = readLine.split(" ").map(_.toInt).toList match {
    case x :: y :: Nil => (x, y)
  }

  val lanterns = readLine.split(" ").map(_.toInt).toList.sorted
  val dists = (lanterns.head * 2) :: ((l - lanterns.reverse.head) * 2) :: lanterns.zip(lanterns.tail).map { case (l1, l2) => (l2 - l1) }

  println(dists.sorted.reverse.head / 2.0)
}

import java.util.StringTokenizer

import scala.Array.canBuildFrom

object _492B extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val l = next.toLong
  val a = (1 to n).map(i => next.toLong).sorted.toArray
  val b = (a :+ (-a(0)) :+ (2 * l - a.last)).sorted
  val c = (1 until b.length).map(i => (b(i) - b(i - 1)) / 2.0)
  val ans = c.max
  println("%.14f".format(ans))
}

object B492 {
  @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, l) = readLongs(2)
    val input = readLongs(n.toInt).sortBy(identity)
    var res = math.max(2*input.head, 2*(l-input.last))
    for(i <- 1 until input.length) {
      res = math.max(res, input(i)-input(i-1))
    }
    println(res/2.0)
  }
}

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, l) = readInts(2)
  val as = readInts(n).distinct.sorted

  var prev = 0
  var max = as(0).toDouble

  for (a <- as) {
    max = math.max(max, (a - prev) / 2.0)
    prev = a
  }
  max = math.max(max, l - as.last)

  println(max)
}

import scala.io.StdIn

object A extends App {

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

  val arr = StdIn.readLine().split(" ").map(_.toDouble).sortWith(_ < _)

  val result  = if (arr.length == 1) 0 else arr.iterator.sliding(2).withPartial(false).map { x =>
    (x(1) - x.head)/2
  }.max

  var max = Math.max(arr.head, n - arr.last)

  println(Math.max(result, max))

}

object B492 {
  @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, l) = readLongs(2)
    val input = readLongs(n.toInt).sortBy(identity)
    var res = math.max(2*input.head, 2*(n-input.last))
    for(i <- 1 until input.length) {
      res = math.max(res, input(i)-input(i-1))
    }
    println(res/2.0)
  }
}

import scala.io.StdIn

object A extends App {

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

  val arr = StdIn.readLine().split(" ").map(_.toDouble)

  val result = arr.iterator.sliding(2).withPartial(false).map { x =>
    (x(1) - x.head)/2
  }.max

  var max = Math.max(arr.head, n - arr.last)

  println(Math.max(result, max))

}

import scala.io.StdIn

object A extends App {

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

  val arr = StdIn.readLine().split(" ").map(_.toDouble).sortWith(_ < _)

  val result = arr.iterator.sliding(2).withPartial(false).map { x =>
    (x(1) - x.head)/2
  }.max

  var max = Math.max(arr.head, n - arr.last)

  println(Math.max(result, max))

}

import scala.math.Ordering._

object Main extends App {
  val Array(n, l) = readLine.split(" ").map(_.toInt)
  val fs: List[Int] = readLine.split(" ").map(_.toInt).toList
  val row: List[Int] = fs.sorted :+ l
  val d: Int = (row zip row.tail).map({
     case (a, b) => b - a
  }).max
  println("%.9f".format(d/2.0))
}

import scala.math.Ordering._

object Main extends App {
  val Array(n, l) = readLine.split(" ").map(_.toInt)
  val fs: List[Int] = readLine.split(" ").map(_.toInt).toList
  val row: List[Int] = 0 :: fs.sorted
  val d: Int = (row zip row.tail).map({
     case (a, b) => b - a
  }).max
  println("%.9f".format(List(d/2.0, row.head - 0.0, l - row.last).max))
}


object Main {
  def main(args: Array[String]) {
    val n = readInt
    val s = readLine
    val t = s.split(" ").map(i => i.toInt)

    println( ((2 until n/2).filter(m => n%m == 0).map(step => {
      (0 until step).map(start =>
        (start until n by step).map(t).sum
      ).max
    }) :+ t.sum).max )
  }
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val divs = (2 to n / 3).filter(i => n % i == 0)
  val data = in.next().split(" ").map(_.toLong)
  var max = data.sum
  divs.foreach { i =>
    var j = 0
    while (j < i) {
      var k = j
      var candidate = 0l
      while (k < n) {
        candidate += data(k)
        k += i
      }
      max = Math.max(candidate, max)
      j += 1
    }
  }
  println(max)
}

object D158 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    var res = in.sum
    val div = divisors(n).filter(n/_ > 2)
    for(d <- div) {
      for(i <- 0 until d) {
        var curr = 0
        for(j <- 0 until n/d) {
          curr += in((i+d*j)%n)
        }
        res = math.max(res, curr)
      }
    }
    println(res)
  }

  def divisors(n: Int): Array[Int] = {
    (1 to n/2).filter(i => n % i == 0).toArray
  }

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

//        private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

object D158 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    var res = in.sum
    val div = divisors(n).filter(n/_ > 2)
    for(d <- div) {
      for(i <- 0 until d) {
        var curr = 0
        for(j <- 0 until n/d) {
          curr += in((i+d*j)%n)
        }
        res = math.max(res, curr)
      }
    }
    println(res)
  }

  def divisors(n: Int): Array[Int] = {
    val ret = cu.ArrayBuffer.empty[Int]
    var i = 1
    while(i*i <= n) {
      if(n%i == 0)
        ret.append(i, n/i)
      i += 1
    }
    ret.toArray
  }

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

//        private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

import java.util.Scanner

object D {
  val in = new Scanner(System.in)

  def main(args: Array[String]) {
    val n = in.nextInt
    val s = Array.fill[Int](n)(in.nextInt())
    var max = Int.MinValue
    for (d <- 1 to n / 3 if n % d == 0) {
      val sum = Array.ofDim[Int](d)
      for (i <- 0 until s.length) {
        sum(i % d) += s(i)
      }
      max = max max sum.max
    }
    println(max)
  }
}

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

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

  val N = sc.nextInt
  val t = Array.fill(N)(sc.nextInt)

  val divisors = (1 to N / 3).filter(N % _ == 0)

  def svalue(d: Int, r: Int) = {
    @tailrec
    def loop(acc: Int, i: Int): Int =
      if (i >= N) acc
      else loop(acc + t(i), i + d)
    loop(0, r)
  }

  val answer = {
    for {
      d <- divisors
      r <- 0 until d
    } yield svalue(d, r)
  }.max

  out.println(answer)
  out.close
}

object IceSculptures extends App {
  import java.io._
  import java.util.{Scanner => Input}

  val in = new Input(new BufferedReader(new InputStreamReader(System.in)))
  val n = in.nextInt
  val a = new Array[Int](n + 1)
  for (i <- 1 to n) a(i) = in nextInt

  val s = new Array[Int](n + 1)
  var ans = Int.MinValue
  for (l <- 1 to n)
    if (n % l == 0 && n / l >= 3) {
      for (i <- n to (1, -1)) {
        s(i) = a(i) + (if (i + l <= n) s(i + l) else 0)
        if (i <= l && s(i) > ans)
          ans = s(i)
      }
    }
  println(ans)
}

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

object TaskD {
  def main(args: Array[String]) {
    val in = new InputReader(System.in)
    val n = in.nextInt
    val s = Array.fill[Int](n)(in.nextInt)
    var max = Int.MinValue
    for (d <- 1 to n / 3 if n % d == 0) {
      val sum = Array.ofDim[Int](d)
      for (i <- 0 until s.length) {
        sum(i % d) += s(i)
      }
      max = max max sum.max
    }
    println(max)
  }

  class InputReader {
    def this(f: File) {
      this()
      try {
        br = new BufferedReader(new FileReader(f))
      }
    }

    def this(f: InputStream) {
      this()
      br = new BufferedReader(new InputStreamReader(f))
    }

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

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

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

    def nextLine: String = {
      try {
        return br.readLine
      }
      return null
    }

    private var br: BufferedReader = null
    private var st: StringTokenizer = null
  }

}

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
  val a = readInts zip (0 until n)
  def ans = (3 to n).filter(n % _ == 0).map { x =>
    val groups = a.groupBy(_._2 % (n / x))
    groups.values.map { y: Array[(Int, Int)] =>
      y.map(_._1).sum
    }.max
  }.max

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

object Main {
  def main(args: Array[String]) {
    val num = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val sums = (3 to num).flatMap{ i =>
      if ( num % i == 0) {
        val counts = num / i
        val sums = new Array[Int](counts)
        for(j <- 0 until a.size) {
          sums(j % counts) += a(j)
        }
        sums
      } else Nil
    }
    println(sums.max)
  }
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val divs = (2 to Math.sqrt(n).toInt).filter(i => n % i == 0 && n / i > 3)
  val data = in.next().split(" ").map(_.toInt)
  var max = data.sum
  val indexed = data.zipWithIndex
  divs.foreach { i =>
    var j = 0
    while (j < i) {
      max = Math.max(indexed.foldLeft(0) { case(acc, (el, index)) => if (index % i == j) acc + el else acc}, max)
      j += 1
    }
  }
  println(max)
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val divs = (1 to Math.sqrt(n).toInt).filter(n % _ == 0)
  val data = in.next().split(" ").map(_.toInt)
  var max = 0
  val indexed = data.zipWithIndex
  divs.foreach { i =>
    var j = 0
    while (j < i) {
      max = Math.max(indexed.foldLeft(0) { case(acc, (el, index)) => if (index % i == j) acc + el else acc}, max)
      j += 1
    }
  }
  println(max)
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val divs = (2 to Math.sqrt(n).toInt + 1).filter(i => n % i == 0 && n / i > 2)
  val data = in.next().split(" ").map(_.toLong)
  var max = data.sum
  val indexed = data.zipWithIndex
  divs.foreach { i =>
    var j = 0
    while (j < i) {
      max = Math.max(indexed.foldLeft(0l) { case(acc, (el, index)) => if (index % i == j) acc + el else acc}, max)
      j += 1
    }
  }
  println(max)
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val divs = (2 to Math.sqrt(n).toInt).filter(i => n % i == 0 && n / i > 2)
  val data = in.next().split(" ").map(_.toInt)
  var max = data.sum
  val indexed = data.zipWithIndex
  divs.foreach { i =>
    var j = 0
    while (j < i) {
      max = Math.max(indexed.foldLeft(0) { case(acc, (el, index)) => if (index % i == j) acc + el else acc}, max)
      j += 1
    }
  }
  println(max)
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val divs = (2 to Math.sqrt(n).toInt + 1).filter(i => n % i == 0 && n / i > 2)
  if (n == 13860)
    println(divs)
  val data = in.next().split(" ").map(_.toLong)
  var max = data.sum
  val indexed = data.zipWithIndex
  divs.foreach { i =>
    var j = 0
    while (j < i) {
      max = Math.max(indexed.foldLeft(0l) { case(acc, (el, index)) => if (index % i == j) acc + el else acc}, max)
      j += 1
    }
  }
  println(max)
}


import scala.io.StdIn

object SubstringRemoval extends App {

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

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first: Long = takeSimilar(s.zipWithIndex).length.toLong
  val second: Long = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * (first + second) + (first - 1) * (second - 1)) % 998244353)

  } else {
    println((first + second + 1) % 998244353)
  }
}

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 S = ns(N)
    def countL() = {
      var l = 0
      while(l < N && S(l) == S(0)) {
        l += 1
      }
      l
    }

    def countR() = {
      var r = 0
      while (r < N && S(N - 1 - r) == S(N - 1)) {
        r += 1
      }
      r
    }

    val ans = if (S.forall(_ == S(0))) {
      // 全部一緒
      (N.toLong * (N + 1) / 2 - 1) % MOD

    } else if (S(0) == S(N - 1)) {
      // 左右が一緒
      val l = countL()
      val r = countR()
      (l + 1).toLong * (r + 1) % MOD
    } else {
      // 左右で違う
      val l = countL()
      val r = countR()
      l + r + 1
    }

    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, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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

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

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

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

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

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

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

  def solve(): Unit = {
    val N = ni()
    val S = ns(N)
    def countL() = {
      var l = 0
      while(l < N && S(l) == S(0)) {
        l += 1
      }
      l
    }

    def countR() = {
      var r = 0
      while (r < N && S(N - 1 - r) == S(N - 1)) {
        r += 1
      }
      r
    }

    val ans = if (S.forall(_ == S(0))) {
      // 全部一緒
      N.toLong * (N + 1) / 2

    } else if (S(0) == S(N - 1)) {
      // 左右が一緒
      val l = countL()
      val r = countR()
      (l + 1).toLong * (r + 1)
    } else {
      // 左右で違う
      val l = countL()
      val r = countR()
      l + r + 1
    }

    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, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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

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

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

import scala.io.StdIn

object SubstringRemoval extends App {

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

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first = takeSimilar(s.zipWithIndex).length.toLong
  val second = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * (first + second) % 998244353) % 998244353)
  } else {
    println((first + second + 1) % 998244353)
  }

}

import scala.io.StdIn

object SubstringRemoval extends App {

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

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first = takeSimilar(s.zipWithIndex).length.toLong
  val second = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * ((first + second) % 998244353)) % 998244353)
  } else {
    println((first + second + 1) % 998244353)
  }

}

import scala.io.StdIn

object SubstringRemoval extends App {

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

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first = takeSimilar(s.zipWithIndex).length.toLong
  val second = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    println((2 * (first + second)) % 998244353)
  } else {
    println((first + second + 1) % 998244353)
  }

}

import scala.io.StdIn

object SubstringRemoval extends App {

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

  val takeSimilar = (xs: IndexedSeq[(Char, Int)]) =>
    xs.takeWhile { case (c, i) =>
      if (i == 0) true
      else xs(i - 1)._1 == c
    }

  val first: Long = takeSimilar(s.zipWithIndex).length.toLong
  val second: Long = takeSimilar(s.reverse.zipWithIndex).length.toLong

  if (s.head == s.last) {
    val res: Long = (2 * ((first + second) % 998244353)) % 998244353
    println(res)
  } else {
    val res: Long = (first + second + 1) % 998244353
    println(res)
  }
}


object Main {
  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val a =
      if (m == 0) Array.empty[Int]
      else readLine().split(" ").map(_.toInt).sorted

    var p1 = 0
    var p2 = 0
    var inc = false
    for (i <- 0 until m) {
      val e = a(i)
      if (p1 == e - 2 && p2 == e - 1) inc = true
      p1 = p2
      p2 = e
    }

    if (a.headOption == Some(1) || p2 == n || inc) println("NO")
    else println("YES")
  }
}

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B362 extends App {

  def solve() = {
    val Array(n, m): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    if (m == 0) {
      println("YES")
    } else {
      val d: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
      val sorted = d.sorted
      var can = sorted(0) != 1 && sorted(m - 1) != n
      var biggestConsecutive = 0
      if (can) {
        var currentConsecutive = 0
        for (i <- 1 until m) {
          if (sorted(i) == sorted(i - 1) + 1) {
            currentConsecutive += 1
            biggestConsecutive = Math.max(biggestConsecutive, currentConsecutive)
          } else {
            currentConsecutive = 0
          }
        }
      }

      if (can && biggestConsecutive < 2) {
        println("YES")
      } else {
        println("NO")
      }
    }
  }

  solve()

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m) = in.next().split(" ").map(_.toInt)
  if (m == 0)
    println("YES")
  else {
    val dirty = in.next().split(" ").map(_.toInt).sorted
    if (dirty.head == 1 || dirty.last == n)
      println("NO")
    else {
      if ((2 until m).forall{j =>
        val first = dirty(j - 2)
        (dirty(j - 1) != first + 1) || (dirty(j) != first + 2)
      })
        println("YES")
      else
        println("NO")
    }
  }
}

object B extends App {

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

  val Array(n, m) = readInts(2)
  val dirty = if (m > 0) readInts(m).sorted else Array.ofDim[Int](0)
  val can = m == 0 || (dirty.head != 1 && dirty.last != n && !(0 until m - 2).exists(i => dirty(i + 1) == dirty(i) + 1 && dirty(i + 2) == dirty(i) + 2))

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

/**
 * @author pvasilyev
 * @since 18 Jun 2016
 */
object B362 extends App {

  def solve() = {
    val Array(n, m): Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
    if (m == 0) {
      println("YES")
    } else {
      val d: Array[Int] = scala.io.StdIn.readLine().split(" ").map(_.toInt)
      val sorted = d.sorted
      var can = sorted(0) != 1 && sorted(m - 1) != n
      var biggestConsecutive = 0
      if (can) {
        var currentConsecutive = 0
        for (i <- 1 until m) {
          if (sorted(i) == sorted(i - 1) + 1) {
            currentConsecutive += 1
          } else {
            biggestConsecutive = Math.max(biggestConsecutive, currentConsecutive)
            currentConsecutive = 0
          }
        }
      }

      if (can && biggestConsecutive < 2) {
        println("YES")
      } else {
        println("NO")
      }
    }
  }

  solve()

}

object Main {
  def main(args: Array[String]) {
    val nm = readLine().split(" ").map(_.toInt)
    val n = nm(0)
    val m = nm(1)
    val a = readLine().split(" ").map(_.toInt).sorted

    var p1 = 0
    var p2 = 0
    var inc = false
    for (i <- 0 until m) {
      val e = a(i)
      if (p1 == e - 2 && p2 == e - 1) inc = true
      p1 = p2
      p2 = e
    }

    if (a.head == 1 || p2 == m || inc) println("NO")
    else println("YES")
  }
}


import scala.io.StdIn._

object B extends App {
  val n = readInt()
  val A = readLine().split(" ").map(_.toLong)

  var offset = 0L
  var moves = 0L
  for (i <- 0 until A.length) {
    moves += Math.abs(A(i) - offset)
    offset += A(i) - offset
//    println(s"$i -> $offset ($moves)")
  }

  println(moves)
}

object B596 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val b = readInts(n)
    var curr = 0
    var res = 0L
    for(i <- 0 until n) {
      res += math.abs(curr - b(i))
      curr = b(i)
    }
    println(res)
  }

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

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

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

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

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

}

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

object _596B extends CodeForcesApp {
  override type Result = Long

  override def solve(scanner: Scanner) = {
    import scanner._
    val n = nextInt()
    val bs = List.fill(n)(nextLong())
    (0L :: bs).sliding(2).collect{case a :: b :: Nil => (a - b).abs}.sum
  }

  override def format(result: Result) = super.format(result)
}
/****************************[Ignore Template Below]****************************************/
abstract class CodeForcesApp {
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val mod: Int = 1000000007
  type Result
  def solve(scanner: Scanner): Result
  def format(result: Result): String = result.toString
  def apply(scanner: Scanner): String = format(solve(scanner))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
/*********************************[Scala Scanner]*******************************************/
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/21125
 * All next methods throw NoSuchElementException when !hasNext
 */
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))

  val lines = Iterator.continually(reader.readLine()).takeWhile(_ != null) //TODO: In Java 8 reader.lines().iterator

  private[this] val tokenizers = lines.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
    lines.next()
  }
  def lineNumber: Int = reader.getLineNumber
  def line(): String = tokenizer().get.nextToken("\n\r")
  def nextString(): String = next()
  def nextChar(): Char = next().ensuring(_.length == 1).head
  def nextBoolean(): Boolean = next().toBoolean
  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)
  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)
  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)
  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)
  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)
  def nextFloat(): Float = next().toFloat
  def nextDouble(): Double = next().toDouble
  def nextBigDecimal(): BigDecimal = BigDecimal(next())
  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty
  override def close() = reader.close()
}

/**
  * Created by MZKL7315 on 4/12/2016.
  */

object Main {

  def solve(s: List[Long], cur: Long): Long = s match {
    case Nil => 0
    case h :: t => math.abs(cur - h) + solve(t, h)
  }

  def main(args: Array[String]) = {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next().toInt
    println(solve(in.next().split(' ').toList map (_.toLong), 0))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  println(data.foldLeft((0l, 0)) {
    case ((soFar, prev), el) =>
      val diff = Math.abs(prev - el)
      (soFar + diff, el)
  }._1)

}

/**
  * Created by MZKL7315 on 4/12/2016.
  */

object Main {

  def solve(s: List[Int], cur: Int): Int = s match {
    case Nil => 0
    case h :: t => math.abs(cur - h) + solve(t, h)
  }

  def main(args: Array[String]) = {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next().toInt
    println(solve(in.next().split(' ').toList map (_.toInt), 0))
  }
}

/**
  * Created by MZKL7315 on 4/12/2016.
  */

object Main {

  def solve(s: List[Int], cur: Int): Int = s match {
    case Nil => 0
    case h :: t => math.abs(cur - h) + solve(t, math.max(cur, h))
  }

  def main(args: Array[String]) = {
    val in = scala.io.Source.stdin.getLines()
    val n = in.next().toInt
    println(solve(in.next().split(' ').toList map (_.toInt), 0))
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt)
  println(data.foldLeft((0, 0)) {
    case ((soFar, prev), el) =>
      val diff = Math.abs(prev - el)
      (soFar + diff, el)
  }._1)

}


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

  override def apply(io: IO): io.type = {
    // val q = io.read[Int]
    val q = io.read[Int]
    repeat(q) {
      val arr = io.read[Array, Long](4)
      io.writeLine(if(arr(1) >= arr(3) % arr(2) && arr(1) + arr(0) * arr(2) >= arr(3)) { "YES" } else { "NO" })
    }
    io
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = apply(new IO(System.in, System.out)).close()
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

import scala.io.StdIn

object Main extends App{

    val q = StdIn.readLine.toInt
    for (i <- 0 to q-1) {
        val Array(a, b, n, s) = StdIn.readLine().split(" ").map(_.toInt)
        val div = s / n
        if ((div min a) * n + b * 1 >= s)
            println("YES")
        else
            println("NO")
    }

}

//package codeforces.contest1256

object PaymentWithoutChange {
  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt()) {
      val Array(a, b, n, s) = io.StdIn.readLine().split(" ").map(_.toLong)

      println {
        if (b + (n * (s / n) min a * n) >= s) "YES" else "NO"
      }
    }
  }

}

import scala.math.min

object Main {
  def main(args: Array[String]) = {
    val q = readInt
    (0 until q).foreach((x) => f1)
  }

  def f1: Unit = {
    val Array(a, b, n, s) = readLine.split(" ").map(_.toLong)
    println(if (s - n * (min(s / n, a)) <= b) "YES" else "NO")
  }
}

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

  override def apply(implicit io: IO): io.type = repeat {
    val a, b, n, s = io.read[Int]
    val withA = ((s/n) min a)*n
    val remaining = s - withA
    debug(a, b, n, s, withA, remaining)
    val ans = remaining <= b
    io.write(ans.toEnglish.toUpperCase)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(implicit io: IO): io.type
  def repeat(f: => Unit)(implicit io: IO): io.type = {Utils.repeat(io.read[Int]){f; io.writeLine()}; io}
  def main(args: Array[String]): Unit = apply(new IO(System.in, System.out)).close()
}
/****************************[Scala Collection Utils]****************************************/
object Utils {
  import scala.collection.mutable

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

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

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

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

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

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

    def toMultiSet(withDefaultZero: Boolean): Map[A, Int] = {
      val freqTable = t.groupBy(identity).mapValues(_.size)
      if (withDefaultZero) freqTable.withDefaultValue(0) else freqTable
    }
  }

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

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

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

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

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

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

  implicit class IntExtensions(val x: Int) extends AnyVal {
    @inline def isEven = x%2 == 0
    @inline def isOdd = x%2 == 1
  }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

import java.util.Scanner

import scala.language.postfixOps
import scala.math.min

object TaskA extends App {
  val sc = new Scanner(System.in)
  val q = sc.nextInt

  val out = 1 to q map { _ =>
    val (a, b, n, s) = (sc.nextInt, sc.nextInt, sc.nextInt, sc.nextInt)
    if (min(s / n, a) * n + b >= s) "YES" else "NO"
  } mkString "\n"

  println(out)
}


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

    case class R(l: Int, r: Int)

    for (_ <- 1 to nextInt) {
      val n = nextInt
      val rs = Array.fill(n) {
        val l, r = nextInt
        R(l, r)
      }.sortBy {
        r => (r.l, -r.r)
      }

      val ds = Array.ofDim[Int](n)
      for (i <- rs.indices) {
        val r = rs(i)
        if (r.r == r.l) ds(i) = r.l
        else {
          val next = rs(i + 1)
          if (next.l == r.l) ds(i) = next.r + 1
          else ds(i) = next.l - 1
        }
      }

      for (i <- rs.indices) {
        out.println(s"${rs(i).l} ${rs(i).r} ${ds(i)}")
      }
    }

    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 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 l: Int, val r: Int)extends Ordered[pair] {
        override def compare(that: pair): Int = {
            return (r-l).compareTo(that.r-that.l)
        }
    }

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

    val t = readInt()

    for (tt <- 1 to t) {
        val n = readInt()
        var q = Vector[pair]()
        val mark = new Array[Boolean](n+1)
        var l = 0
        var r = 0
        for (i <- 1 to n) {
            l = readInt()
            r = readInt()
            q :+= pair(l, r)
        }
        q = q.sorted
        for (qq <- q) {
            for (i <- qq.l to qq.r) {
                if (!mark(i)) {
                    writer.println(qq.l + " " + qq.r + " " + i)
                    mark(i) = true
                }
            }
        }
        writer.println()

        def check(kk: Long): Boolean = {
            return false
        }
        def bs(st:Long, en:Long): Long = {
            if (en - st <= 1L) {
                if (check(st))
                    return st
                else
                    return en
            }
            val mid = (st + en) / 2L
            if (check(mid))
                return bs(st, mid)
            else
                return bs(mid, en)
        }
    }
    writer.flush()
}