Linear Kingdom has exactly one tram line. It has n stops, numbered from 1 to n in the order of tram's movement. At the i-th stop ai passengers exit the tram, while bi passengers enter it. The tram is empty before it arrives at the first stop. Also, when the tram arrives at the last stop, all passengers exit so that it becomes empty.Your task is to calculate the tram's minimum capacity such that the number of people inside the tram at any time never exceeds this capacity. Note that at each stop all exiting passengers exit before any entering passenger enters the tram.

The first line contains a single number n (2 ≤ n ≤ 1000) — the number of the tram's stops.  Then n lines follow, each contains two integers ai and bi (0 ≤ ai, bi ≤ 1000) — the number of passengers that exits the tram at the i-th stop, and the number of passengers that enter the tram at the i-th stop. The stops are given from the first to the last stop in the order of tram's movement.   The number of people who exit at a given stop does not exceed the total number of people in the tram immediately before it arrives at the stop. More formally, . This particularly means that a1 = 0.  At the last stop, all the passengers exit the tram and it becomes empty. More formally, .  No passenger will enter the train at the last stop. That is, bn = 0.

Print a single integer denoting the minimum possible capacity of the tram (0 is allowed).

NoteFor the first example, a capacity of 6 is sufficient:   At the first stop, the number of passengers inside the tram before arriving is 0. Then, 3 passengers enter the tram, and the number of passengers inside the tram becomes 3.  At the second stop, 2 passengers exit the tram (1 passenger remains inside). Then, 5 passengers enter the tram. There are 6 passengers inside the tram now.  At the third stop, 4 passengers exit the tram (2 passengers remain inside). Then, 2 passengers enter the tram. There are 4 passengers inside the tram now.  Finally, all the remaining passengers inside the tram exit the tram at the last stop. There are no passenger inside the tram now, which is in line with the constraints. Since the number of passengers inside the tram never exceeds 6, a capacity of 6 is sufficient. Furthermore it is not possible for the tram to have a capacity less than 6. Hence, 6 is the correct answer.

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

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

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
}


Something happened in Uzhlyandia again... There are riots on the streets... Famous Uzhlyandian superheroes Shean the Sheep and Stas the Giraffe were called in order to save the situation. Upon the arriving, they found that citizens are worried about maximum values of the Main Uzhlyandian Function f, which is defined as follows:In the above formula, 1 ≤ l < r ≤ n must hold, where n is the size of the Main Uzhlyandian Array a, and |x| means absolute value of x. But the heroes skipped their math lessons in school, so they asked you for help. Help them calculate the maximum value of f among all possible values of l and r for the given array a.

The first line contains single integer n (2 ≤ n ≤ 105) — the size of the array a. The second line contains n integers a1, a2, ..., an (-109 ≤ ai ≤ 109) — the array elements.

Print the only integer — the maximum value of f.

NoteIn the first sample case, the optimal value of f is reached on intervals [1, 2] and [2, 5].In the second case maximal value of f is reachable only on the whole array.

object ProblemA extends App {

    import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
    import java.util.StringTokenizer

  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

  val startTime = System.currentTimeMillis();

  val n = in.nextInt();
  val a = new Array[Int](n)
  for (i <- 0 until n) a(i) = in.nextInt()

  var sums0 = new Array[(Long, Int)](n)
  var sums1 = new Array[(Long, Int)](n)

  sums0(0) = (0, 0)
  sums1(0) = (0, 0)

  for (i <- 1 until n) {
    val delta = Math.abs(a(i) - a(i - 1));
    sums0(i) = (sums0(i - 1)._1 + delta * (if (i % 2 == 0) -1 else 1), i)
    sums1(i) = (sums1(i - 1)._1 + delta * (if (i % 2 == 1) -1 else 1), i)
  }

  var res = Long.MinValue

  sums0 = sums0.sortWith(_._1 < _._1)
  sums1 = sums1.sortWith(_._1 < _._1)

  for(i <- n - 1 to 0 by -1) {
    val del1 = Math.abs(sums0(i)._1 - sums0(0)._1)
    val del2 = Math.abs(sums1(i)._1 - sums1(0)._1)
    if (del1 > res) res = del1
    if (del2 > res) res = del2
  }

  println(res)

}

import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

class  FastScanner(val in: BufferedReader) {

  var st: StringTokenizer = _;

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

  def nextInt(): Integer = {
    Integer.parseInt(nextToken());
  }

  def nextLong(): Long = {
    nextToken().toLong;
  }

  def nextDouble(): Double = {
    nextToken().toDouble;
  }
}

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

  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}
    val array = read[Vector[Long]]
    val diffs = array
      .zip(array.tail)
      .zipWithIndex
      .map({case ((a, b), i) =>
        val d = (a - b).abs
        val isEven = i%2 == 0
        (if (isEven) d else -d, if (isEven) -d else d)
      })
      .unzip
      .toSeq

    val ans = diffs.map(maxSubArraySum)

    write(ans.max)
  }

  def maxSubArraySum(s: Seq[Long]): Long = s.scanLeft(0L){_ + _ max 0L}.max

}
/****************************[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()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: A =:= B): Seq[A] = Seq(p._1, p._2.asInstanceOf[A])
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    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)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    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 {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[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
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of 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 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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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 _789C extends CodeForcesApp {
  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._

  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}
    val array = read[Vector[Long]]
    val diffs = array.view
      .zip(array.tail)
      .zipWithIndex
      .map({case ((a, b), i) =>
        val d = (a - b).abs
        val isEven = i%2 == 0
        (if (isEven) d else -d, if (isEven) -d else d)
      })
      .force
      .unzip
      .toSeq

    val ans = diffs.map(maxSubArraySum)
    write(ans.max)
  }

  def maxSubArraySum(s: Seq[Long]): Long = s.scanLeft(0L){_ + _ max 0L}.max
}
/****************************[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()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: A =:= B): Seq[A] = Seq(p._1, p._2.asInstanceOf[A])
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    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)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    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 {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[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
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of 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 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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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
      }
    }
  }
}

/**
  * Created by ruslan on 3/29/17.
  */
object ProblemA extends App {
    import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Random
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

class  FastScanner(val in: BufferedReader) {
  var st: StringTokenizer = _;

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

  def nextInt(): Integer = {
    Integer.parseInt(nextToken());
  }

  def nextLong(): Long = {
    nextToken().toLong;
  }

  def nextDouble(): Double = {
    nextToken().toDouble;
  }
}

  val startTime = System.currentTimeMillis();

  val n = in.nextInt();
  val a = new Array[Int](n)
  for (i <- 0 until n) a(i) = in.nextInt()

  var sums0 = new Array[(Long, Int)](n)
  var sums1 = new Array[(Long, Int)](n)

  sums0(0) = (0, 0)
  sums1(0) = (0, 0)

  for (i <- 1 until n) {
    val delta = Math.abs(a(i) - a(i - 1));
    sums0(i) = (sums0(i - 1)._1 + delta * (if (i % 2 == 0) -1 else 1), i)
    sums1(i) = (sums1(i - 1)._1 + delta * (if (i % 2 == 1) -1 else 1), i)
  }

  var res = Long.MinValue

  sums0 = sums0.sortWith(_._1 < _._1)
  sums1 = sums1.sortWith(_._1 < _._1)

  for(i <- n - 1 to 0 by -1) {
    val del1 = Math.abs(sums0(i)._1 - sums0(0)._1)
    val del2 = Math.abs(sums1(i)._1 - sums1(0)._1)
    if (del1 > res) res = del1
    if (del2 > res) res = del2
  }

  println(res)

}

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

  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}
    val array = read[Vector[Long]]
    val diffs = array
      .zip(array.tail)
      .map({case (a, b) => (a - b, b - a)})
    val (c1, c2) = diffs.unzip
    val ans = maxSubArraySum(c1) max maxSubArraySum(c2)
    write(ans)
  }

  def maxSubArraySum(s: Seq[Long]): Long = s.scanLeft(0L){_ + _ max 0L}.max

}
/****************************[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()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int, until: Int)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C])
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    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)}
    def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    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 {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def testBit(i: Int): Boolean = ((x >> i) & 1) == 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative getOrElse f   //e.g. students indexOf "Greg" whenNegative Int.MaxValue
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new java.awt.geom.Point2D.Double(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[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
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

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()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of 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 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: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    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
      }
    }
  }
}

/**
  * Created by ruslan on 3/29/17.
  */
object ProblemA extends App {
    import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Random
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

class  FastScanner(val in: BufferedReader) {
  var st: StringTokenizer = _;

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

  def nextInt(): Integer = {
    Integer.parseInt(nextToken());
  }

  def nextLong(): Long = {
    nextToken().toLong;
  }

  def nextDouble(): Double = {
    nextToken().toDouble;
  }
}

  val startTime = System.currentTimeMillis();

  val n = in.nextInt();
  val a = new Array[Int](n)
  for (i <- 0 until n) a(i) = in.nextInt()

  var sums0 = new Array[(Long, Int)](n)
  var sums1 = new Array[(Long, Int)](n)

  sums0(0) = (0, 0)
  sums1(0) = (0, 0)

  for (i <- 1 until n) {
    val delta = Math.abs(a(i) - a(i - 1));
    sums0(i) = (sums0(i - 1)._1 + delta * (if (i % 2 == 0) -1 else 1), i)
    sums1(i) = (sums1(i - 1)._1 + delta * (if (i % 2 == 1) -1 else 1), i)
  }

  var res = Long.MinValue

  sums0 = sums0.sortBy(_._1)
  sums1 = sums1.sortBy(_._1)

/*  println(sums0.mkString(", "))
  println(sums1.mkString(", "))*/

  def findMin(a: Array[(Long, Int)], index: Int): Long = {
    var res = 0;
    while (res < n && a(res)._2 >= index) res += 1;
    if (res < n) a(res)._1
    else Long.MaxValue
  }

  for(i <- n - 1 to 1 by -1) {
    val del1 = sums0(i)._1 - findMin(sums0, sums0(i)._2)
    val del2 = sums1(i)._1 - findMin(sums1, sums0(i)._2)
    if (del1 > res) res = del1
    if (del2 > res) res = del2
  }

  println(res)

}

/**
  * Created by ruslan on 3/29/17.
  */
object ProblemA extends App {
    import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Random
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

class  FastScanner(val in: BufferedReader) {
  var st: StringTokenizer = _;

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

  def nextInt(): Integer = {
    Integer.parseInt(nextToken());
  }

  def nextLong(): Long = {
    nextToken().toLong;
  }

  def nextDouble(): Double = {
    nextToken().toDouble;
  }
}

  val startTime = System.currentTimeMillis();

  val n = in.nextInt();
  val a = new Array[Int](n)
  for (i <- 0 until n) a(i) = in.nextInt()

  val sums0 = new Array[(Long, Int)](n)
  val sums1 = new Array[(Long, Int)](n)

  sums0(0) = (0, 0)
  sums1(0) = (0, 0)

  for (i <- 1 until n) {
    val delta = Math.abs(a(i) - a(i - 1));
    sums0(i) = (sums0(i - 1)._1 + delta * (if (i % 2 == 0) -1 else 1), i)
    sums1(i) = (sums1(i - 1)._1 + delta * (if (i % 2 == 1) -1 else 1), i)
  }

  var res = Long.MinValue

  sums0.sortBy(_._1)
  sums1.sortBy(_._1)

  def findMin(a: Array[(Long, Int)], index: Int): Long = {
    var res = 0;
    while (res < n && a(res)._2 >= index) res += 1;
    if (res < n) a(res)._1
    else Long.MaxValue
  }

  for(i <- n - 1 to 0 by -1) {
    val del1 = sums0(i)._1 - findMin(sums0, sums0(i)._2)
    val del2 = sums1(i)._1 - findMin(sums1, sums0(i)._2)
    if (del1 > res) res = del1
    if (del2 > res) res = del2
  }

  println(res)

}

/**
  * Created by ruslan on 3/29/17.
  */
object ProblemA extends App {
    import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Random
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

class  FastScanner(val in: BufferedReader) {
  var st: StringTokenizer = _;

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

  def nextInt(): Integer = {
    Integer.parseInt(nextToken());
  }

  def nextLong(): Long = {
    nextToken().toLong;
  }

  def nextDouble(): Double = {
    nextToken().toDouble;
  }
}

  val startTime = System.currentTimeMillis();

  val n = in.nextInt();
  val a = new Array[Int](n)
  for (i <- 0 until n) a(i) = in.nextInt()

  var sums0 = new Array[(Long, Int)](n)

  sums0(0) = (0, 0)

  for (i <- 1 until n) {
    val delta = Math.abs(a(i) - a(i - 1));
    sums0(i) = (sums0(i - 1)._1 + delta * (if (i % 2 == 0) -1 else 1), i)
  }

  var res = Long.MinValue

  sums0 = sums0.sortWith(_._1 < _._1)

  def findMin(a: Array[(Long, Int)], index: Int): Long = {
    var res = 0;
    while (res < n && a(res)._2 >= index) res += 1;
    if (res < n) a(res)._1
    else Long.MaxValue
  }

  for(i <- n - 1 to 0 by -1) {
    val del1 = sums0(i)._1 - findMin(sums0, sums0(i)._2)
    if (del1 > res) res = del1
  }

  println(res)

}

/**
  * Created by ruslan on 3/29/17.
  */
object ProblemA extends App {
    import java.io.{BufferedReader, IOException, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Random
  val in = new FastScanner(new BufferedReader(new InputStreamReader(System.in)))
  val out = new PrintWriter(System.out)

class  FastScanner(val in: BufferedReader) {
  var st: StringTokenizer = _;

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

  def nextInt(): Integer = {
    Integer.parseInt(nextToken());
  }

  def nextLong(): Long = {
    nextToken().toLong;
  }

  def nextDouble(): Double = {
    nextToken().toDouble;
  }
}

  val startTime = System.currentTimeMillis();

  val n = in.nextInt();
  val a = new Array[Int](n)
  for (i <- 0 until n) a(i) = in.nextInt()

  var sums0 = new Array[(Long, Int)](n)
  var sums1 = new Array[(Long, Int)](n)

  sums0(0) = (0, 0)
  sums1(0) = (0, 0)

  for (i <- 1 until n) {
    val delta = Math.abs(a(i) - a(i - 1));
    sums0(i) = (sums0(i - 1)._1 + delta * (if (i % 2 == 0) -1 else 1), i)
    sums1(i) = (sums1(i - 1)._1 + delta * (if (i % 2 == 1) -1 else 1), i)
  }

  var res = Long.MinValue

  sums0 = sums0.sortBy(_._1)
  sums1 = sums1.sortBy(_._1)

/*  println(sums0.mkString(", "))
  println(sums1.mkString(", "))*/

  def findMin(a: Array[(Long, Int)], index: Int): Long = {
    var res = 0;
    while (res < n && a(res)._2 >= index) res += 1;
    if (res < n) a(res)._1
    else Long.MaxValue
  }

  for(i <- n - 1 to 0 by -1) {
    val del1 = sums0(i)._1 - findMin(sums0, sums0(i)._2)
    val del2 = sums1(i)._1 - findMin(sums1, sums0(i)._2)
    if (del1 > res) res = del1
    if (del2 > res) res = del2
  }

  println(res)

}


One day, Yuhao came across a problem about checking if some bracket sequences are correct bracket sequences.A bracket sequence is any non-empty sequence of opening and closing parentheses. A bracket sequence is called a correct bracket sequence if it's possible to obtain a correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, the sequences "(())()", "()" and "(()(()))" are correct, while the bracket sequences ")(", "(()" and "(()))(" are not correct.Yuhao found this problem too simple for him so he decided to make the problem harder. You are given many (not necessarily correct) bracket sequences. The task is to connect some of them into ordered pairs so that each bracket sequence occurs in at most one pair and the concatenation of the bracket sequences in each pair is a correct bracket sequence. The goal is to create as many pairs as possible.This problem unfortunately turned out to be too difficult for Yuhao. Can you help him and solve it?

The first line contains one integer $$$n$$$ ($$$1 \leq n \leq 10^5$$$) — the number of bracket sequences. Each of the following $$$n$$$ lines contains one bracket sequence — a non-empty string which consists only of characters "(" and ")". The sum of lengths of all bracket sequences in the input is at most $$$5 \cdot 10^5$$$. Note that a bracket sequence may appear in the input multiple times. In this case, you can use each copy of the sequence separately. Also note that the order in which strings appear in the input doesn't matter.

Print a single integer — the maximum number of pairs which can be made, adhering to the conditions in the statement.

NoteIn the first example, it's optimal to construct two pairs: "((     )())" and "(     )".

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)

  case class BS(i: Int, rank: Int, cap: Int)

  def solve(): Unit = {
    import java.util
    val N = ni()
    val S = map(N)(_ => ns())

    def read(s: String, i: Int): BS = {
      var rank = 0
      var cap = 0
      REP(s.length) { i =>
        if (s(i) == '(') {
          rank += 1
        } else {
          rank -= 1
        }
        cap = min(cap, rank)
      }

      BS(i, rank, cap)
    }

    val L = S.zipWithIndex.map((read _).tupled).filter(_.cap >= 0) // capが少ないとrankも少ない
    val R = mutable.Map[Int, util.TreeMap[Integer, mutable.Queue[Int]]]() // rank => cap => [id]
    S.zipWithIndex.map((read _).tupled) foreach { r0 =>
      if (r0.rank <= 0) {
        val r = BS(r0.i, -r0.rank, -r0.cap)
        if (!R.contains(r.rank)) R(r.rank) = new util.TreeMap()
        if (!R(r.rank).containsKey(r.cap)) R(r.rank).put(r.cap, mutable.Queue())
        R(r.rank).get(r.cap) += r.i
      }
    }

    val used = Array.ofDim[Boolean](N)

    // L == Rになっちゃだめ
    def selectR(ids: mutable.Queue[Int], l: Int): Option[Int] = {
      val id1 = ids.dequeue()
      if (id1 == l) {
        if (ids.nonEmpty) {
          val selected = ids.dequeue()
          ids += id1
          Some(selected)
        } else {
          None
        }
      } else {
        Some(id1)
      }
    }

    var ans = 0
    L.foreach { l =>
      if (!used(l.i)) {
        if (R.contains(l.rank)) {
          val byCaps = R(l.rank)
          val capR = byCaps.lowerKey(l.rank + 1) // cap <= rank なので <で比較するときは+1しないといけない
          if (capR != null) {
            val rs = byCaps.get(capR)
            selectR(rs, l.i) match {
              case None =>
              case Some(selected) =>
                // ここでfalseになるはずはないんだけど
                if (!used(selected)) {
                  ans += 1
                  if (rs.isEmpty) byCaps.remove(capR)
                  // Rからremoveするのはコスト高いのでやらない
                  used(l.i) = true
                  used(selected) = true
                }
            }
          }
        }
      }
    }

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

import scala.collection.mutable

object C extends App {

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

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

  def eval(b: String, sign: Int): Int = {
    var cur = 0
    var close = 0
    for (c <- b) {
      c match {
        case '(' => cur += sign
        case ')' => cur -= sign
      }
      if (cur > close) close = cur
    }
    close
  }

  val (left, right) = bs.map(b => (eval(b, -1), eval(b.reverse, 1))).partition(_._2 == 0)
  val rightCounts = mutable.Map.empty ++ (right.groupBy(identity).map {
    case (k, v) => k -> v.length
  })

  val z = (0, 0)
  var res = left.count(_ == z) / 2
  for ((l, _) <- left) {
    val rr = (0, l)
    if (rightCounts.getOrElse(rr, 0) > 0) {
      rightCounts(rr) -= 1
      res += 1
    }
  }

  println(res)
}


This is an interactive problem.After getting AC after 13 Time Limit Exceeded verdicts on a geometry problem, Kuroni went to an Italian restaurant to celebrate this holy achievement. Unfortunately, the excess sauce disoriented him, and he's now lost!The United States of America can be modeled as a tree (why though) with $$$n$$$ vertices. The tree is rooted at vertex $$$r$$$, wherein lies Kuroni's hotel.Kuroni has a phone app designed to help him in such emergency cases. To use the app, he has to input two vertices $$$u$$$ and $$$v$$$, and it'll return a vertex $$$w$$$, which is the lowest common ancestor of those two vertices.However, since the phone's battery has been almost drained out from live-streaming Kuroni's celebration party, he could only use the app at most $$$\lfloor \frac{n}{2} \rfloor$$$ times. After that, the phone would die and there will be nothing left to help our dear friend! :(As the night is cold and dark, Kuroni needs to get back, so that he can reunite with his comfy bed and pillow(s). Can you help him figure out his hotel's location?

NoteNote that the example interaction contains extra empty lines so that it's easier to read. The real interaction doesn't contain any empty lines and you shouldn't print any extra empty lines as well.The image below demonstrates the tree in the sample test:

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

import scala.collection.mutable.ListBuffer
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 DivD(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 DivD(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val adj = Array.fill[ListBuffer[Int]](n + 1)(new ListBuffer[Int])
    REP(n-1) { _ =>
      val x = ni()
      val y = ni()

      adj(x) += y
      adj(y) += x
    }

    var toRun = true
    var z = -1
    while (toRun) {
      var x = -1
//      REP(n, 1) { i =>
//        out.println(s"$i  ${adj(i).length}")
//      }
      REP(n, 1) { i =>
        if(adj(i).length == 1) x = i
      }

      var y = -1
      REP(n, 1) { i =>
        if(adj(i).length == 1 && i != x) y = i
      }
      if(x == -1 && y == -1) {
        out.println(s"! $z")
        toRun = false
      } else {
        out.println(s"? $x $y")
        out.flush()
        z = ni()
        if (z == x || z == y) {
          out.println(s"! $z")
          toRun = false
        } else {
          for (i <- adj(x)) {
            adj(i) = adj(i).filter(p => p != x)
          }
          adj(x) = new ListBuffer[Int]
          for (i <- adj(y)) {
            adj(i) = adj(i).filter(p => p != y)
          }
          adj(y) = new ListBuffer[Int]
        }
      }
    }
  }
}

import collection.mutable.HashMap
import collection.mutable.HashSet
object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt
    val d = HashMap[Int, HashSet[Int]]()
    for(i <- 0 until n) d(i + 1) = HashSet[Int]()
    for(_ <- 0 until n - 1) {
      val Array(x, y) = readLine.split(" ").map(_.toInt)
      d(x) += y
      d(y) += x
    }
    var flag = true
    while (d.keySet.size != 1 && flag) {
      val (x, y) = getV(d)
      println(s"? ${x} ${y}")
      System.out.flush

      val v = readInt
      if (v == x) {
        println(s"! $x")
        System.out.flush
        flag = false
      }
      else if (v == y) {
        println(s"! $y")
        System.out.flush
        flag = false
      }
      else {
        removeV(d, x)
        removeV(d, y)
      }
    }
    if (flag) {
      println(s"! ${d.keySet.head}")
      System.out.flush
    }
  }

  def getV(d: HashMap[Int, HashSet[Int]]): (Int, Int) = d.filter{
    case (i, s) => s.size == 1
  }.keys.take(2).toList match {
    case x :: y :: _ => (x, y)
    case _ => ???
  }

  def removeV(d: HashMap[Int, HashSet[Int]], i: Int): Unit = {
    d(d(i).head) -= i
    d -= i
  }
}

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

import scala.collection.mutable.ListBuffer
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 DivD(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 DivD(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()
    val adj = Array.fill[ListBuffer[Int]](n + 1)(new ListBuffer[Int])
    REP(n-1) { _ =>
      val x = ni()
      val y = ni()

      adj(x) += y
      adj(y) += x
    }

    var toRun = true
    while (toRun) {
      var x = -1
      REP(n, 1) { i =>
        if(adj(i).length == 1) x = i
      }

      var y = -1
      REP(n, 1) { i =>
        if(adj(i).length == 1 && i != x) y = i
      }
      out.println(s"? $x $y")
      out.flush()
      val z = ni()
      if(z == x || z == y) {
        out.println(s"! $z")
        toRun = false
      } else {
        for(i <- adj(x)) {
          adj(i) = adj(i).filter(p => p != x)
        }
        adj(x) = new ListBuffer[Int]
        for(i <- adj(y)) {
          adj(i) = adj(i).filter(p => p != y)
        }
        adj(y) = new ListBuffer[Int]
      }
    }
  }
}

import collection.mutable.HashMap
import collection.mutable.HashSet
object Main {
  def main(args: Array[String]): Unit = {
    val n = readInt
    val d = HashMap[Int, HashSet[Int]]()
    for(i <- 0 until n) d(i + 1) = HashSet[Int]()
    for(_ <- 0 until n - 1) {
      val Array(x, y) = readLine.split(" ").map(_.toInt)
      d(x) += y
      d(y) += x
    }
    while (d.keySet.size != 1) {
      val li = getV(d)
      println(s"? ${li.head} ${li.last}")
      System.out.flush

      val v = readInt
      for(i <- li) {
        if (i != v)
        removeV(d, i, v)
      }
    }
    println(s"! ${d.keySet.head}")
    System.out.flush
  }

  def getV(d: HashMap[Int, HashSet[Int]]): List[Int] = d.map{
    case (i, s) => (i, s.find((j) => d(j).size > 1))
  }.find{
    case (i, Some(j)) => true
    case (_, _) => false
  }.get match {
    case (i, jo) => List(i, jo.get, d(jo.get).find(_ != i).get)
  }
  def removeV(d: HashMap[Int, HashSet[Int]], i: Int, v: Int): Unit = {
    if (d.contains(i)) {
    d(i).foreach((j) => if (j != v) {
      removeV(d, j, i)
    })
    d -= i
  }
  d(v) -= i

  }
}