import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn

object CodeForces extends App {

  StdIn.readLine()
  val numbers = StdIn.readLine().split(" ").map(_.toInt)

  val (odd,even) = numbers.partition(_%2==0)
  if (odd.length == 1){
    println(numbers.indexOf(odd.head) + 1)
  }else {
    println(numbers.indexOf(even.head) + 1)
  }

}

object P025A {
  def main(args: Array[String]) = {
    val n = readInt
    val a = readLine.split(' ').map(x => x.toInt).map(x => x % 2)
    val parity = if (a.reduceLeft(_ + _) > 1) 0 else 1
    println(a.indexOf((a.filter(x => x % 2 == parity))(0)) + 1)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val list = readLine().split(" ").map(_.toInt).toList
    val (elist, olist) = list.partition(x => x % 2 == 0)
    if (elist.length <= 1) println(list.indexOf(elist.head) +1) else println(list.indexOf(olist.head) +1)
  }
}

import scala.io.StdIn._

object Main extends App {
  readInt()
  val a = readLine().split(" ").map(_.toInt)
  val (even, odd) = a.zipWithIndex.partition { case (e, _) => e % 2 == 0 }
  val ans = if (even.length == 1) even.head._2 else odd.head._2
  println(ans + 1)
}

object CF0025A extends App {

  val n = readInt()
  val ar = readLine().split(" ").map(_.toInt)

  var pos = 0

  if(ar.filter(_%2 ==0 ).size == n -1) {
    val value = ar.filter(_%2 == 1).head
    (1 to ar.size).foreach(n => {
      if(ar(n-1) == value) {
        pos = n
      }
    })
  } else {
    val value = ar.filter(_%2 == 0).head
    (1 to ar.size).foreach(n => {
      if(ar(n-1) == value) {
        pos = n
      }
    })
  }

  println(pos)

}

object CF025A_IQTest extends App {

  override def main(args: Array[String]): Unit = {
    val in = new java.util.Scanner(System.in)
    val out = new java.io.PrintWriter(System.out)

    def solution(): Unit = {
      val n: Int = in.nextInt()
      var sum: Int = 0
      for (_ <- 0 until 3) {
        sum = (sum << 1) | (in.nextInt() % 2)
      }

      val ind: Int = sum match {
        case sum if (sum == 3 || sum == 4) => 1
        case sum if (sum == 2 || sum == 5) => 2
        case sum if (sum == 1 || sum == 6) => 3
        case _ => {
          val item = sum match {
            case 0 => 1
            case _ => 0
          }

          var t = 0
          for (i <- 4 to n) {
            if (item == (in.nextInt() % 2)) {
              t = i
            }
          }

          t
        }
      }

      out.println(ind)
    }

    try {
      solution()

    } catch {
      case e: Exception => out.println(e.toString)

    } finally {
      out.flush()
      out.close()
    }
  }
}

object CF025A_IQTest extends App {

  class FastReader() {
    val br = new java.io.BufferedReader(
      new java.io.InputStreamReader(System.in))
    var st: java.util.StringTokenizer = null

    def next: String = {
      if (st == null || !st.hasMoreElements) {
        st = new java.util.StringTokenizer(br.readLine)
      }

      st.nextToken
    }

    def nextInt: Int = next.toInt
    def nextLong: Long = next.toLong
    def nextDouble: Double = next.toDouble
    def nextLine: String = br.readLine
  }

  override def main(args: Array[String]): Unit = {
    val in = new FastReader()
    val out = new java.io.PrintWriter(System.out)

    def solution(): Unit = {
      val n = in.nextInt
      var sum = 0
      for (_ <- 0 until 3) {
        sum = (sum << 1) | (in.nextInt % 2)
      }

      val ind = sum match {
        case sum if (sum == 3 || sum == 4) => 1
        case sum if (sum == 2 || sum == 5) => 2
        case sum if (sum == 1 || sum == 6) => 3
        case _ => {
          val item = sum match {
            case 0 => 1
            case _ => 0
          }

          var t = 0
          for (i <- 4 to n) {
            if (item == (in.nextInt % 2)) {
              t = i
            }
          }

          t
        }
      }

      out.println(ind)
    }

    try {
      solution()

    } catch {
      case e: Exception => out.println(e.toString)

    } finally {
      out.flush()
      out.close()
    }
  }
}

import collection.mutable._

object P25A extends App {

    readLine
    val evens, odds = new java.util.LinkedList[(Int,Int)]()

    for (e <- readLine.split(" ").map(_.toInt).zipWithIndex)
        (if(e._1 % 2 == 0) evens else odds).add(e)

    print(Array(evens,odds).minBy(_.size).get(0)._2+1)

}

import java.util.StringTokenizer

object _25A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val a = (1 to n).map(i => next.toInt);
  val odd = a.filter(i => i % 2 == 1)
  val even = a.filter(i => i % 2 == 0)
  val ans = if (odd.size == 1) a.indexOf(odd.head) + 1 else a.indexOf(even.head) + 1
  println(ans)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  if (data.count(_ % 2 == 1) == 1)
    println(data.indexOf(data.find(_ % 2 == 1).get) + 1)
  else
    println(data.indexOf(data.find(_ % 2 == 0).get) + 1)
}

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val input = readInts(n).zipWithIndex
    val odd = input.filter(_._1 % 2 == 1)
    val even = input.filter(_._1 % 2 == 0)
    if(odd.length == 1) {
      println(odd.head._2 + 1)
    } else {
      println(even.head._2 + 1)
    }
  }
}

object IQ {
  def main(args: Array[String]) {
    val n = io.StdIn.readLine.toInt
    val arr = io.StdIn.readLine.split(" ").map(_.toInt).zipWithIndex
    val evens = arr.filter(_._1 % 2 == 0)
    val odds = arr.filter(_._1 % 2 != 0)
    if (evens.length == 1) println(evens(0)._2 + 1)
    else println(odds(0)._2 + 1)
  }
}

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

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

  val answer = if (V.count(_ % 2 == 1) == 1) (V takeWhile (_ % 2 == 0)).size + 1
               else (V takeWhile (_ % 2 == 1)).size + 1

  out.println(answer)
  out.close
}

object  IQtest {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
		var previousArity = scanner.nextInt() % 2;
		var currentArity = scanner.nextInt() % 2;
		var index = 2;
		while (index <= n && previousArity == currentArity) {
			previousArity = currentArity;
			currentArity = scanner.nextInt() % 2;
			index += 1
		}
		if (index == 2) {
			val nextArity = scanner.nextInt() % 2
					if (nextArity == previousArity)
						println(2);
					else
						println(1);
		}
		else {
			println(index)
		}
	}
}

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

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var n = readInt;
    var evenCount = 0;
    var oddCount = 0;
    var lastEven = 0;
    var lastOdd = 0;
    var arr = readLine.split(" ").map(_.toInt);
    for (i <- 0 until arr.length) {
      if (arr(i) % 2 == 0) {
        lastEven = i;
        evenCount += 1;
      } else {
        lastOdd = i;
        oddCount += 1;
      }
    }
    if (evenCount > oddCount) {
      println(lastOdd + 1);
    } else {
      println(lastEven + 1);
    }
  }

}

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
  val foo = a.groupBy(_ % 2).mapValues(_.length)
  def ans = (a zip (1 to n)).filter(x => foo(x._1 % 2) == 1).map(_._2)

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

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = a.zipWithIndex.groupBy(_._1 % 2)
    if (map(1).size == 1) println(map(1)(0)._2 + 1)
    else println(map(0)(0)._2 + 1)
  }
}

import scala.io._

object main {

  def solution(n: Int) = {
    val input = StdIn.readLine().split(' ').map(_.toInt)
    val groups = input.groupBy(_ % 2 == 0)

    val (evns, odds) =
      (groups(true), groups(false))

    val number = if (evns.length > odds.length)
      odds.last else evns.last

    var i = 0
    var ans = 0

    while (i < input.length) {
      if (input(i) == number)
        ans = i
      i += 1
    }

    ans + 1
  }

  def run() = {
    val n = StdIn.readInt()
    val ans = solution(n)

    println(ans)
  }

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

}

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

object IQTest {

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

   def readLongs() : Array[Long] =
      readLine.split(' ').map(_.toLong)

   def readTuple() : (Int,Int) = {
     val line = readInts
     (line(0),line(1))
   }
   def readTupleLong() : (Long,Long) = {
     val line = readLongs
     (line(0),line(1))
   }

   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }
   def readQuad() : (Int,Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2),line(3))
   }

   def main(args: Array[String]) {
     val n = readInt
     val as = readInts
     if (as.count { _ % 2 == 0 } > 1) {
       println(as.indexWhere(_ % 2 == 1) + 1)
     } else {
       println(as.indexWhere(_ % 2 == 0) + 1)
     }

   }

}

import java.io._

object Solution extends App {
  val n = readInt

  val a = readLine.split(" ").map(_.toInt)

  if(a.count(_ % 2 == 0) == 1) {
    println(a.indexWhere(_ % 2 == 0) + 1)
  } else {
    println(a.indexWhere(_ % 2 != 0) + 1)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val list = readLine().split(" ").map(_.toInt).toList
    val (elist, olist) = list.partition(x => x % 2 == 0)
    if (elist.length <= 1) println(list.indexOf(elist.head)) else println(list.indexOf(olist.head))
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val n = readLine()
    val list = readLine().split(" ").map(_.toInt).toList
    val (elist, olist) = list.partition(x => x % 2 == 0)
    if (elist.length <= 1) println(elist.head) else println(olist.head)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").map(_.toInt)
  if (data.count(_ % 2 == 1) == 1)
    println(data.find(_ % 2 == 1).get)
  else
    println(data.find(_ % 2 == 0).get)
}

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

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

  val v0 = V takeWhile (_ % 2 == 0)
  val v1 = V dropWhile (_ % 2 == 0) takeWhile(_ % 2 == 1)
  val answer = if (v0.size > 0) v0.size + 1
               else v1.size + 1

  out.println(answer)
  out.close
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = a.groupBy(_ % 2)
    if (map(1).size == 1) println(map(1)(0))
    else println(map(0)(0))
  }
}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = a.groupBy(_ % 2)

    println(a)
    if (map(1).size == 1) println(map(1)(0))
    else println(map(0)(0))
  }
}

object Main extends App {

  val n = Console.readInt()
  Console.println(solution(n))

  def solution(n: Int) = {
    var odd = 0
    var even = 0

    var d = 0
    var fOdd = -1
    var fEvn = -1

    val input: Array[String] =
      Console.readLine().split(' ')

    input
      .map(x => x.toInt)
      .foreach(d => {
        if (d % 2 == 0) {
          even += 1
          if (fEvn == -1) fEvn = d
        } else {
          odd += 1
          if (fOdd == -1) fOdd = d
        }
      })

    val ans = if (odd > even) fOdd else fEvn
    ans + 1
  }

}


object CF_E61_B {
// date: 05/03/2019

  type In  = (Int, Seq[Int], Int, Seq[Int])
  type Out = Seq[Long]

  def solve(in: In): Out = {
    val (n, as, m, qs) = in

    val ss = as.sorted
    val total = ss.foldLeft(0L)(_+_)
    def mincost(q: Int): Long = total - ss(n - q)
    for {
      q <- qs
    } yield mincost(q)
  }

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Specify Input and Output formats on RHS here:

  def formatIn(i: Input): In       = (i.int, {i.nextLine; i.intSeq}, {i.int}, {i.nextLine; i.intSeq})
  def formatOut(out: Out): String  = out.mkString("\n")

//   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//   Boilerplate & utility methods that don't change (so ignore):

  import java.util.Scanner
  import java.io.InputStream
  import language.implicitConversions

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    val resultStr = new Input(System.in).solveStr
    out.println(resultStr)
    out.close()
  }

  class Input(val sc: Scanner) {
    // This class is useful for convenience, and for mock stdin in test scripts
    // Remember to call nextLine to advance past the newline character (if required) before taking a whole line
    def this(i: InputStream)       = this(new Scanner(i))
    def this(s: String)            = this(new Scanner(s.stripMargin))
    def int                        = sc.nextInt()
    def long                       = sc.nextLong()
    def double                     = sc.nextDouble()
    def nextLine                   = sc.nextLine()
    def collect[T](f: String => T) = sc.nextLine().split(" ").toVector.map(f)
    def intSeq                     = collect(_.toInt)
    def doubleSeq                  = collect(_.toDouble)
    def getLines: Vector[String]   = if (!sc.hasNextLine) Vector.empty
                                     else sc.nextLine +: getLines
    def getLines(lineCount: Int)   = {nextLine; (1 to lineCount).map(_ => sc.nextLine)}
    def solveVal: Out              = (solve _).tupled(formatIn(this))
    def solveStr: String           = formatOut(solveVal)
  }

  // Ceiling division for Int & Long
  // `a` MUST be > 0. Incorrect otherwise.
  def divideCeil(a: Int, b: Int)   = (a - 1)/b + 1
  def divideCeil(a: Long, b: Long) = (a - 1)/b + 1

  // A frequently used number in these comps
  val modulo = 1000000007

  // For convenience in test scripts, treat a String as an Input
  implicit def stringToInput(s: String): Input = new Input(s)
  // Required to make `solveVal` work when input has just 1 value (i.e. not a Tuple)
  implicit class makeTupledWorkOnFunction1[-T,+R](f: T => R) {
    def tupled: T => R = x => f(x)
  }
}

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 A = na(N)
    sort(A)
    val M = ni()
    val S = sumL(A)
    REP(M) { _ =>
      val q = ni()
      val ans = S - A(N - q)
      out.println(ans)
    }
  }

  def sort(a: Array[Int]): Array[Int] = {
    val n = a.length
    REP(n) { i =>
      val j = scala.util.Random.nextInt(n - i) + i
      val tmp = a(i)
      a(i) = a(j)
      a(j) = tmp
    }
    Sorting.stableSort(a)
    a
  }

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

  def debug(num: Long): Unit = {
    System.err.println(num)
  }

  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 java.util.Scanner

object E_3_627 extends App {
  var scanner = new Scanner(System.in)

  val sleepCount = scanner.nextInt()
  val hoursInDay = scanner.nextInt()
  val goodHourStart = scanner.nextInt()
  val goodHourEnd = scanner.nextInt()

  val untilSleeps = Array.ofDim[Int](sleepCount)
  untilSleeps.indices.foreach { index =>
    untilSleeps(index) = scanner.nextInt()
  }

  def asDayHour(hour: Int): Int = {
    Math.floorMod(hour, hoursInDay)
  }

  def isGoodHour(hour: Int): Boolean = {
    (hour >= goodHourStart) && (hour <= goodHourEnd)
  }

  val goodDays = Array.ofDim[Int](sleepCount + 1, hoursInDay)
  goodDays(0)(0) = 0

  def calculateGoodDays(sleepIndex: Int, hourIndex: Int, wakeupGoodDays: Int): Int = {
    val newGoodDays = {
      if (isGoodHour(hourIndex)) {
        wakeupGoodDays + 1
      }
      else {
        wakeupGoodDays
      }
    }

    val maxGoodDays = Math.max(goodDays(sleepIndex)(hourIndex), newGoodDays)
    goodDays(sleepIndex)(hourIndex) = maxGoodDays

    maxGoodDays
  }

  var wakeupHours = Set(0)
  untilSleeps.zipWithIndex.foreach { case (untilSleep, sleepIndex) =>
    var newWakeupHours = Set.empty[Int]
    wakeupHours.foreach { wakeupHour =>
      val newWakeupHour = asDayHour(wakeupHour + untilSleep)

      // in time
      calculateGoodDays(sleepIndex + 1, newWakeupHour, goodDays(sleepIndex)(wakeupHour))

      // 1h before
      val improvedNewWakeupHour = asDayHour(newWakeupHour - 1)
      calculateGoodDays(sleepIndex + 1, improvedNewWakeupHour, goodDays(sleepIndex)(wakeupHour))

      newWakeupHours += newWakeupHour
      newWakeupHours += improvedNewWakeupHour
    }
    wakeupHours = newWakeupHours
  }

  val maxGoodDaysHour = wakeupHours.maxBy(goodDays(sleepCount))
  val maxGoodDays = goodDays(sleepCount)(maxGoodDaysHour)
  println(maxGoodDays)
}

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

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C627E(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

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

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

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

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

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

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

class C627E(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val h = ni()
    val l = ni()
    val r = ni()

    val a = na(n)

    val dp = Array.fill[Int](n+1,n+1)(Int.MinValue)
    dp(0)(0) = 0
    var sum = 0L
    REP(n) { i =>
      sum += a(i)
      REP(n+1) { j =>
        dp(i+1)(j) = scala.math.max(dp(i+1)(j), dp(i)(j) + inside((sum - j) % h, l , r))
        if(j < n) dp(i+1)(j+1) = scala.math.max(dp(i+1)(j+1), dp(i)(j) + inside((sum - j - 1) % h, l , r))
      }
    }
    out.println(dp(n).max)
  }

  def inside(v: Long, l: Int, r: Int): Int = {
    if(r >= v && v >= l) 1 else 0
  }
}


object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

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

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

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

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

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

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

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

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

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def test(): Boolean = {
    val S, T = ns()
    var i, j = 0
    val N = S.length
    val M = T.length

    debug(s"N:$N M:$M")

    debug(S)
    debug(T)

    while(i < N) {
      if (j == M || S(i) != T(j)) return false
      var ii = i
      var jj = j
      while (ii + 1 < N && S(i) == S(ii + 1)) {
        ii += 1
      }
      while (jj + 1 < M && T(j) == T(jj + 1)) {
        jj += 1
      }
      debug(s"i:$i j:$j ii:$ii jj:$jj")
      if (jj - j < ii - i) return false
      i = ii + 1
      j = jj + 1
    }

    j == M
  }

  def solve(): Unit = {
    REP(ni()) { _ =>
      if (test()) out.println("YES")
      else out.println("NO")
    }
  }
}

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

  override def apply(io: IO): io.type = {
    val input = io.read[Seq[(String, String)]]
    val ans = input map { case (a, b) => check(a.toList, b.toList).toEnglish }
    io.writeLines(ans)
  }

  @tailrec
  def check[A](as: List[A], bs: List[A]): Boolean =
    (as, bs) match {
      case (Nil, Nil) => true
      case (a1 :: at, b1 :: bt) if a1 == b1 =>
        val (ad, an) = at.span(_ == a1)
        val (bd, bn) = bt.span(_ == b1)
        bd.length >= ad.length && check(an, bn)
      case _ => false
    }

  implicit class BooleanExtensions(x: Boolean) {
    def toEnglish = if(x) "YES" else "NO"
  }
}
/****************************[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 = this(new IO(System.in, System.out)).close()
}
/***********************************[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
      }
    }
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

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

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

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

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

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

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

case class Entry(ch: Char, cnt: Int)

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

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

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def calc(s: String): ArrayBuffer[Entry] = {
    val n = s.length
    var i = 0
    val res = ArrayBuffer[Entry]()
    while(i < n) {
      var j = i
      while(j + 1 < n && s(i) == s(j + 1)) {
        j += 1
      }
      res += Entry(s(i), j - i + 1)
      i = j + 1
    }
    res
  }

  def test(): Boolean = {
    val S, T = ns()
    val E1 = calc(S)
    val E2 = calc(T)

    debug(E1.mkString(" "))
    debug(E2.mkString(" "))

    E1.length == E2.length && {
      var ok = true
      REP(E1.length) { i =>
        ok &&= E1(i).ch == E2(i).ch && E1(i).cnt <= E2(i).cnt
      }
      ok
    }
  }

  def solve(): Unit = {
    REP(ni()) { _ =>
      if (test()) out.println("YES")
      else out.println("NO")
    }
  }
}

object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

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

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

  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 = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

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

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

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

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

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

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 1000000007

  def test(): Boolean = {
    val S, T = ns()
    var i, j = 0
    val N = S.length
    val M = T.length

    debug(S)
    debug(T)

    while(i < N) {
      if (j == M || S(i) != T(j)) return false
      var ii = i
      var jj = j
      if (ii + 1 < N && S(i) == S(ii + 1)) {
        ii += 1
      }
      if (jj + 1 < M && T(j) == T(jj + 1)) {
        jj += 1
      }
      debug(s"i:$i j:$j ii:$ii jj:$jj")
      if (jj - j < ii - i) return false
      i = ii + 1
      j = jj + 1
    }

    j == M
  }

  def solve(): Unit = {
    REP(ni()) { _ =>
      if (test()) out.println("YES")
      else out.println("NO")
    }
  }
}


object Solution116A extends App {

  def solution() {
    val n = _int
    val result = 1.to(n).map(_ => (_int, _int)).foldLeft((0, 0))((memo, curr) => {
      val next = memo._1 - curr._1 + curr._2
      (next, scala.math.max(next, memo._2))
    })
    println(result._2)
  }

  //////////////////////////////////////////////////
  import java.util.Scanner
  val SC: Scanner = new Scanner(System.in)
  def _line: String = SC.nextLine
  def _int: Int = SC.nextInt
  def _long: Long = SC.nextLong
  def _string: String = SC.next
  solution()
}

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val list = List.fill(n)(-sc.nextInt+sc.nextInt)
    println(list.scanLeft(0)(_ + _).max)
  }
}

import scala.io.StdIn

object  Test {
  def main(args1: Array[String]) {
    //    val args = StdIn.readLine().split(" ")
    //    var (x: Long, y: Long) = (args(0).toLong, args(1).toLong)
    val count = StdIn.readInt
    var ret = 0L

    var in = 0L
    for (i <- 0 until count) {
      val args = StdIn.readLine().split(" ")
      var (x: Long, y: Long) = (args(0).toLong, args(1).toLong)
      in -= x
      in += y
      in = Math.max(in, 0L)
      ret = Math.max(ret, in)
    }
    println(ret)
  }

}

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

object OneOneSixA {
	def main(args : Array[String]) : Unit = {
		var scn=new Scanner(new BufferedReader(new InputStreamReader(System.in)))
		var n=scn.nextInt
		var carry,max=0
		for(i<-0 until n){
			var ai=scn.nextInt
			var bi=scn.nextInt
			carry+=(bi-ai)
			if(carry>max)
				max=carry
		}
		println(max)
		scn.close
	}
}

import scala.io.StdIn._

object Tram {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val passengers =
      for {
        _ <- 0 until n
        a :: b :: _ = readLine().split(" ").map(_.toInt).toList
      } yield (a, b)
    var sum = 0
    val ans = passengers.map {
      case (x, y) =>
        sum = sum - x + y
        sum
    }
    println(ans.max)
  }
}

import scala.io.StdIn._

object Tram {
  def main(args: Array[String]): Unit = {
    val n = readInt()
    val passengers =
      for {
        _ <- 0 until n
        a :: b :: _ = readLine().split(" ").map(_.toInt).toList
      } yield (a, b)
    val ans = passengers.scanLeft(0)((sum, x) => sum - x._1 + x._2)
    println(ans.max)
  }
}

import scala.io.StdIn

/**
  * Created by vladimir on 08.06.17.
  */
object A116 extends App {
  val n = StdIn.readInt()
  var max = -1
  var cur = 0
  for (i <- 1 to n) {
    val s = StdIn.readLine().trim
    val entry = s.split(' ') map (_.toInt)
    cur += entry(1) - entry(0)
    if (cur > max)
      max = cur
  }
  print(max)
}

import scala.collection.mutable.ArrayBuffer
object Tram extends App{
  val stops = scala.io.StdIn.readInt()
  var capacity = 0
  var capacities = ArrayBuffer[Int]()

  for (stop <- 1 until stops){
      val passengerFlow = scala.io.StdIn.readLine().split(" ").map(_.toInt)
      capacity = capacity - passengerFlow(0)
      capacity = capacity + passengerFlow(1)
      capacities.prepend(capacity)
  }

  println(capacities.max)

}

object Main extends App {
  def collectStationsData(number: Int): List[(Int, Int)] = number match {
    case 0 => List()
    case _ =>
      val Array(out, in) = readLine.split(" ").map(_.toInt)
      (out, in) :: collectStationsData(number - 1)
  }

  def calculateMaxCapacity(stationData: List[(Int, Int)],
    prevStationCapacity: Int, maxCapacity: Int): Int = stationData match {
    case List() => maxCapacity
    case rest =>
      val stationCapacity = prevStationCapacity - rest.head._1 + rest.head._2
      if (stationCapacity > maxCapacity) calculateMaxCapacity(rest.tail, stationCapacity, stationCapacity)
      else calculateMaxCapacity(rest.tail, stationCapacity, maxCapacity)
  }

  val numberOfStations = readLine.toInt
  val stationsData = collectStationsData(numberOfStations)
  println(calculateMaxCapacity(stationsData, 0, 0))
}

object Main extends App {
  val n = readLine().toInt
  var max = 0
  var cur = 0

  for (_ <- 1 to n) {
    val str = readLine().split(" ").map(_.toInt)

    cur = cur - str(0) + str(1)
    if (cur > max) max = cur
  }

  println(max)
}

import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val n = readLine().toInt

  var ab = ArrayBuffer[(Int, Int)]()

  for (_ <- 1 to n) {
    val str = readLine().split(" ").map(_.toInt)
    ab += ((str.head, str.last))
  }

  var max = 0
  var cur = 0

  for (i <- 0 to n - 1) {
    cur = cur - ab(i)._1 + ab(i)._2
    if (cur > max) max = cur
  }

  println(max)
}

object CF0116A extends App {

  val n = readInt()

  var max = 0
  var people = 0

  (1 to n).foreach(number => {
    val Array(minus, plus) = readLine().split(" ").map(_.toInt)

    people -= minus
    people += plus

    if(max <= people) {
      max = people
    }

  })

  println(max)
}

object task116A {
  def main(args:Array[String]) {
    var rv:Int=0;
    var c:Int=0;
    for (l <- io.Source.stdin.getLines.toList.drop(1)) {
      val Array(o,i)=l.split(" ").map(_.toInt)
      c=c-o+i;
      if (c>rv) { rv=c; }
    }
    println(rv)
  }
}

object pratise {
    def main(args : Array[String]) {
        var res = 0
        var sum = 0
        var n = readInt
        for(i <- 1 to n) {
            val Array(x,y) = readLine().split(" ").map(_.toInt)
            sum += y - x
            res = math.max(sum,res)
        }
        println(res)
    }
}

import scala.collection.mutable.ListBuffer

object Tram extends App {
  val inPassengers = ListBuffer[Int]()
  val outPassengers = ListBuffer[Int]()

  def process(s: String): Unit = {
    val split: Array[String] = s.split(" ")
    outPassengers.append(split(0).toInt)
    inPassengers.append(split(1).toInt)
  }

  val numStations = readInt()

  (1 to numStations).map(line => process(readLine()))

  var minCapacity = 0
  var currentCapacity = 0

  for (i <- 0 to inPassengers.size - 1) {
    currentCapacity = currentCapacity + (inPassengers(i) - outPassengers(i))
    if (currentCapacity > minCapacity) {
      minCapacity = currentCapacity
    }
  }
  println(minCapacity)
}

import scala.io.StdIn

/**
  * @author traff
  */

object Main extends App {
  val n = StdIn.readLine().toInt

  var bus = 0
  var max = 0

  for (i <- 1 to n) {
    val Array(b, a) = StdIn.readLine().split(" ").map(_.toInt)
    bus += a
    bus -= b

    max = Math.max(bus, max)
  }

  println(max)
}

object Solution extends App{
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  var count = 0
  var max = 0
  Range(0, n).foreach {_ =>
    val Array(out, inn) = in.next().split(" ").map(_.toInt)
    count = count - out + inn
    max = Math.max(count, max)
    }
  println(max)
}

object Main {
	import java.{util=>ju}
	import scala.math._

	def main(args:Array[String]) =
	{
		val sc = new ju.Scanner(System.in)
		val i = sc.nextInt();

		val arr = (1 to i*2).map(_ => sc.nextInt())
		val a = arr.indices.filter(v => v % 2 == 0).map(w => arr.apply(w)).toArray
		val b = arr.indices.filter(v => v % 2 == 1).map(w => arr.apply(w)).toArray

		println(calc(a, b, 0, 0, 0))

	}

	def calc(a:Array[Int], b:Array[Int], i:Int, sum:Int, max:Int):Int =
	{
		if(i >= a.length) return max
		calc(a, b, i+1, sum - a(i) + b(i), math.max(sum,max))
	}
}

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

    val n = std.readInt()
    var result = 0
    var currentCapacity = 0
    for (i <- 0 until n) {
      val values = std.readLine().split(" ").map(_.toInt)
      currentCapacity += - values(0) + values(1)
      result = currentCapacity.max(result)
    }
    println(result)
  }
}

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

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

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

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    var min = 0
    var curr = 0
    for(i <- 0 until n) {
      val Array(exit, in) = readInts(2)
      curr += (in-exit)
      min = math.max(min, curr)
    }
    println(min)
  }
}

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

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

  val N = sc.nextInt

  def solve: Int = {
    @tailrec
    def loop(acc: Int, p: Int, i: Int): Int = {
      if (i == N) acc
      else {
        val a, b = sc.nextInt
        val tmp = p - a + b
        loop(acc max tmp, tmp, i + 1)
      }
    }
    loop(0, 0, 0)
  }

  out.println(solve)
  out.close
}

import java.util.Scanner
import scala.math._

object R116_A extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val nums = (0 until n) map ( _ => {
    val a = sc.nextInt()
    val b = sc.nextInt()
    b-a
  })

  println(answer(nums))

  def answer(nums:Seq[Int]):Int = {
    var m = 0
    var sum = 0
    nums.foreach(n => {
      m = max(m, (sum+n))
      sum += n
    })
    m
  }
}

object Tram {
	def main (args: Array[String]) {
		val scanner = new java.util.Scanner(System.in)
		val n = scanner.nextInt
		var maxCapacity = 0
		var current = 0
		for (_ <- 1 to n) {
		  val b = scanner.nextInt
		  val a = scanner.nextInt
		  val diff = (a - b)
		  current += diff
		  maxCapacity = Math.max(maxCapacity, current)
		}
		println(maxCapacity)
	}
}

import java.io._

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

  def dx = for(_ <- 1 to readInt) yield -readInts.reduce(_-_)
  def x = dx.foldLeft(List(0)) { case (list @ head :: _, a) =>
    head + a :: list
  }
  def ans = x.reduce(_ max _)

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

object CF116A extends App {

  import java.util.Scanner

  val in = new Scanner(System.in)

  def nextInt = in.nextInt

  def solve {
    var curr = 0
    var max = 0
    for (n <- 1 to nextInt) {
      curr -= nextInt
      curr += nextInt
      if (curr > max) max = curr
    }
    println(max)
  }
  solve
}

object Codeforces116A extends App{

  def TrainCapacity(len:Int):Int={
    var ans:Int=0
    var temp:Int=0
    for (i <- 1 to len){
      val k:Array[Int]=scala.io.StdIn.readLine.split(" ").map(_.toInt)
      temp-=k(0)
      temp+=k(1)
      if (temp>ans){
        ans=temp
      }
    }
    return ans
  }

  val s:Int=scala.io.StdIn.readInt
  println(TrainCapacity(s))

}

/**
 * Created by vol on 9/18/14.
 */
object A116 extends App{
  val n = readInt()

  def loop(n:Int, i:Int, max:Int, insideBus:Int):Int = {
    if (n == i)  max
    else {
      val Array(out, in) = readLine().split(" ").map(_.toInt)
      loop(n, i + 1, max.max(insideBus - out + in), insideBus -out + in)
    }
  }

  println(loop(n, 0 , 0 , 0))

}

object Main {
  def main(args: Array[String]) {
    val n = readInt()
    val arr = (1 to n).map { unused =>
      val b = readLine().split(" ").map(_.toInt)
      (b(0), b(1))
    }
    val t = arr.foldLeft((0, 0)) { (c, t) =>
      val cur = c._1 - t._1 + t._2
      val max = if (cur < c._2) c._2
      else cur
      (cur, max)
    }
    println(t._2)
  }
}

// Codeforces 116A

object _116A extends App {
  val scanner = new java.util.Scanner(System.in)
  val n = scanner.nextInt()
  val increace = List.fill(n)(-scanner.nextInt()+scanner.nextInt())
  println(
    increace.
      foldLeft(List(0))((accm, i) => (i+accm.head) :: accm).max
  )
}

// Codeforces 116A

object _116A extends App {
  val scanner = new java.util.Scanner(System.in)
  val n = scanner.nextInt()
  val increace = List.fill(n)(-scanner.nextInt()+scanner.nextInt())
  println(increace.scanLeft(0)((accm, i) => accm + i).max)
}

import scala.io.StdIn._

object A_116 extends App {
  val n = readInt()
  var total = 0
  var capacity = 0
  1 to n foreach { _ =>
    val Array(a, b) = readLine().split(" ").map(_.toInt)
    total += b - a
//    println(total)
    capacity = Math.max(capacity, total)
  }

  println(capacity)
}

object examples{
    def main(args:Array[String]){
      val n = readLine().toInt
      var s = 0
      var m = 0
      for(_ <- 1 to n){
        val r = readLine().split(' ').map(_.toInt)
        s = s - r(0) + r(1)
        m = Math.max(m , s)
      }
      println(m)
        }

}

import scala.io.StdIn
object problem {
  def main(args: Array[String]) {
    val n = StdIn.readInt()
    var s = 0
    var max = 0
    for(i<- 1 until n){
      val A =  StdIn.readLine.split(' ').map(_.toInt)
      s = s + A(1) - A(0)
//      println(s)
      max = math.max(max , s)
    }
    println(max)
  }
}

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

    import java.util.Scanner
    import java.io.{BufferedReader, InputStreamReader}

    val streamReader: InputStreamReader = new InputStreamReader(System.in)
    val scanner: Scanner = new Scanner(new BufferedReader(streamReader))

    val n: Int = Integer.parseInt(scanner.nextLine())
    var count: Int = 0
    var capability: Int = 0

    var exit: Int = 0
    var enter: Int = 0

    for (i <- 0 until n){
      exit = scanner.nextInt()
      enter = scanner.nextInt()

      count = count - exit + enter
      if (capability < count){
        capability = count
      }
    }

    println(capability)

  }
}

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

object Tram {
   def main(args: Array[String]) {
     val n = readInt
     val stops = for {
       i <- 1 to n
       val line = readLine.split(' ').map(_.toInt)
     } yield (line(0),line(1))
     println(stops.foldLeft((0,0)){ case ((cap, cur),(a,b)) =>
       ( if (cap <= cur - a + b) cur - a + b else cap ,cur -a + b)}._1)

   }

}

object Tram extends App {
  val sc = new java.util.Scanner(System.in);
  val n = sc.nextInt;
  val list = List.fill(n)(-sc.nextInt+sc.nextInt)
  println(list.scanLeft(0)(_+_).max)
}

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

object App {

  def main(args: Array[String]) {

    val n = StdIn.readLine().toInt
    var ans = 0
    var cur = 0
    for(i<-0 to n-1) {
      val Array(a,b) = StdIn.readLine().split(" ").map(_.toInt)
      cur = cur + (b - a)
      ans = math.max(cur, ans)
    }
    println(ans)
  }

}

import scala.io.StdIn

object Tram_116A {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    val maxInside = (0 until n)
      .map(_ => StdIn.readLine().split(" "))
      .map(l => (l(0).toInt, l(1).toInt))
      .foldLeft(0 :: Nil){ case (inside, (out, in)) => inside.head - out + in :: inside }
      .max
    println(maxInside)
  }
}

import scala.io.StdIn._
object cf extends App
{
    val scanner = new java.util.Scanner(System.in)
    val n = scanner.nextInt()
    val t = List.fill(n)(-scanner.nextInt()+scanner.nextInt())
    print (t.scanLeft(0)((sum,x)=>sum+x).max)
}

object Main {

  def main(args: Array[String]): Unit = {
    val n = readInt()
    var sum = 0
    var res = 0
    for(i <- 1 to n){
      val Array(a,b) = readLine().split(" ").map(_.toInt)
      sum += b-a
      res = Math.max(res,sum)
    }
    println(res)
  }

}

import scala.io.StdIn._

object Solution {

	var n = readInt
	var stops = Array.fill[Array[Int]](n)(Array(0,0))
	for(i <- 0 until n) {
		stops(i) = readLine.split(" ").map(_.toInt)
	}

	def main(args:Array[String]):Unit = {
		var min = 0
		var onBus = 0
		for(i <- 0 until n) {
			var Array(a,b) = stops(i)

			onBus -= a
			onBus += b

			if(onBus > min) min = onBus
		}
		println(min)
	}

}

object main extends App{
    val n = readInt
    var cnt = 0
    var max = 0
    for(i<-1 to n){
        val t = readLine.split(" ").map(_.toInt)
        cnt+= t(1)-t(0)
        if(cnt > max) max = cnt
    }
    println(max)
}

object A00116 extends App {
  def parseInt(str: String, count: Int): Seq[Int] = {
    val scanner = new java.util.Scanner(str)
    val res = (1 to count) map (_ => scanner.nextInt())
    scanner.close()
    res
  }
  def scanInts(count: Int): Seq[Int] = parseInt(Console.readLine, count)

  def oneIntLine = {
    val Seq(count) = parseInt(Console.readLine(), 1);
    count
  }

  def readMatrix(row: Int, col: Int) = {
    (1 to row) map (x => scanInts(col))
  }

  val stops = oneIntLine
  val passengerChange = readMatrix(stops, 2)
  val additions = passengerChange map (x => x(1) - x(0))
  val reductions = additions.foldLeft(List(0)) { (acc, x) =>
    (acc.head + x) :: acc
  }
  println(reductions.max)
}

import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val n = readLine().toInt

  var ab = ArrayBuffer[(Int, Int)]()

  for (_ <- 1 to n) {
    val str = readLine().split(" ").map(_.toInt)
    ab += ((str.head, str.last))
  }

  var max = 0

  for (i <- 0 to n - 1) {
    val temp = max - ab(i)._1 + ab(i)._2
    if (temp > max) max = temp
  }

  println(max)
}

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

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

  val N = sc.nextInt

  def solve: Int = {
    @tailrec
    def loop(acc: Int, i: Int): Int = {
      if (i == N) acc
      else {
        val a, b = sc.nextInt
        loop(acc max acc - a + b, i + 1)
      }
    }
    loop(0, 0)
  }

  out.println(solve)
  out.close
}