object B554 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = Array.fill(n)(read)
    val map = cu.Map[String, Int]().withDefaultValue(0)
    in.foreach(x => map(x) += 1)
    println(map.values.max)
  }

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

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

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

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

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

}

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

object CF554B {

  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
  val reader=new BufferedReader(new InputStreamReader(stream), 32768);

  def next():String = {
      while (!st.hasMoreTokens()){
        val currentLine = reader.readLine
            st=new StringTokenizer(currentLine)
      }
      return st.nextToken
  }

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

  def nextLong():Long = {
      return next.toLong
  }
  def nextDouble:Double = {
          return next.toDouble
      }
  }

  def main(args: Array[String]): Unit = {
    val in = new InputReader(System.in)
    val m = in.nextInt()
    val a = Array.fill(m){ in.next() }
    val cntEquals = a.map{ s => a.filter { x => x.equals(s) }.size }
    println( maxElem(cntEquals) )
  }

  def maxElem(cntEquals: Array[Int]) : Int= {
    var max = 0
    for( i <- 0 until cntEquals.length ) {
      max = Math.max(max,cntEquals(i))
    }
    return max
  }
}

import java.io.InputStream
import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.StringTokenizer
import java.io.PrintWriter
import java.io.FileInputStream
import java.io.PrintStream
import java.io.FileOutputStream

object CF554B {

  class InputReader(val stream:InputStream ) {
    var st:StringTokenizer=new StringTokenizer("")
  val reader=new BufferedReader(new InputStreamReader(stream), 32768);

  def next():String = {
      while (!st.hasMoreTokens()){
        val currentLine = reader.readLine
            st=new StringTokenizer(currentLine)
      }
      return st.nextToken
  }

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

  def nextLong():Long = {
      return next.toLong
  }
  def nextDouble:Double = {
          return next.toDouble
      }
  }

  def main(args: Array[String]): Unit = {
    val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
    var in = new InputReader(System.in)
    var out = System.out
    if ( !isOnlineJudge ) {
      in = new InputReader(new FileInputStream("input.txt"))
      out = new PrintStream(new FileOutputStream("output.txt"))
    }

    val m = in.nextInt()
    val a = Array.fill(m){ in.next() }
    val eqs = a.map{ s => a.filter { x => x.equals(s) }.size }
    out.println(eqs.foldLeft(0)( (mx,x) => if ( x > mx) x else mx))
  }

}

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

import scala.collection.mutable

object B {

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    def query(p: Int) = ???

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

  def solve: Int = {
    val n = nextInt
    var ans = 0
    val arr = new Array[Array[Char]](n)
    for (i <- 0 until n) {
      arr(i) = next.toCharArray
    }
    for (i <- 0 until n) {
      var cnt = 0
      for (j <- 0 until n) {
        if (arr(i)(j) == '1')
          cnt += 1
      }
      if (cnt == n) {
        ans += 1
      }
    }
    val diff = new MultiHashSet[String]
    for (i <- 0 until n) {
      diff.add(new String(arr(i)))
    }
    val it = diff.map.iterator
    while (it.hasNext) {
      ans = Math.max(ans, it.next()._2)
    }
    out.println(ans)
    return 0
  }
}

object _554B extends CodeForcesApp {
  import scala.annotation.tailrec, scala.collection.mutable

  override type Input = IndexedSeq[IndexedSeq[Boolean]]
  override type Output = Int

  val clean = true
  val dirty = !clean

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    val n = nextInt
    nextLine
    Array.fill(n) {nextLine map {
      case '0' => clean
      case '1' => dirty
    }}
  }

  override def solve(input: Input) = {
    val needed = input map {row =>
      for {
        (room, index) <- row.zipWithIndex if room == dirty
      } yield index
    }
    val collisions = needed.groupBy(_.toSet).mapValues(_.size)
    collisions.values.max
  }

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  import CodeForcesApp._
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
/********************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
}
/**********************************[ lib ]************************************/
object CodeForcesApp {
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = collection.mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type ==>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A) = if (condition) Some(f) else None
/*******************************[ constants ]*********************************/
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus = 1000000007
}

object _554B extends CodeForcesApp {
  import CodeForcesApp._, scala.annotation.tailrec, scala.collection.mutable

  override type Input = List[String]
  override type Output = Int

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    List.fill(nextInt)(next)
  }

  override def solve(input: Input) = input.groupBy(identity).mapValues(_.size).values.max

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  import CodeForcesApp._
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /******************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
}
/********************************[ lib ]************************************/
object CodeForcesApp {
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = collection.mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type ==>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A): Option[A] = if (condition) Some(f) else None
  /********************************[ constants ]************************************/
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus = 1000000007
}

object _554B extends CodeForcesApp {
  import scala.annotation.tailrec, scala.collection.mutable

  override type Input = IndexedSeq[IndexedSeq[Boolean]]
  override type Output = Int

  val clean = true
  val dirty = !clean

  override def read(scanner: java.util.Scanner) = {
    import scanner._
    val n = nextInt
    nextLine
    Array.fill(n) {nextLine.map(_ == '1')}
  }

  override def solve(input: Input) = {
    val needed = input map {row =>
      for {
        (room, index) <- row.zipWithIndex if room == clean
      } yield index
    }
    val collisions = needed.groupBy(_.toSet).mapValues(_.size)
    collisions.values.max
  }

  override def format(result: Output) = super.format(result)
}

/****************************** IGNORE BELOW *********************************/
abstract class CodeForcesApp extends App {
  /********************************[ I/O ]************************************/
  import java.util.Scanner
  import CodeForcesApp._
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  def apply(problem: String): String  = apply(new Scanner(problem))
  def apply(scanner: Scanner): String = format(solve(read(scanner)))
  println(apply(new Scanner(System.in)))
  /******************************[ solution ]*********************************/
  type Input
  type Output
  def read(scanner: Scanner): Input
  def solve(input: Input): Output
  def format(result: Output): String = result.toString
}
/********************************[ lib ]************************************/
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  import scala.collection.mutable
  case class Memo[I <% K, K, O](f: I => O) extends (I => O) {
    val cache = mutable.Map.empty[K, O]
    override def apply(x: I): O = cache.getOrElseUpdate(x, f(x))
  }
  type ==>[I, O] = Memo[I, I, O]
  def when[A](condition: Boolean)(f: => A): Option[A] = if (condition) Some(f) else None
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(" ").groupBy(x => x).map(_._2.length)
  val max = data.max
  if (data.max == 1)
    println("YES")
  else if (n == 2 && data.max == 2)
    println("NO")
  else if (max * 2 > data.sum + 1)
    println("NO")
  else
    println("YES")
}

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

object P296A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextInt)

  def solve(): String = A.groupBy(identity).toSeq.map(_._2.size).sortWith(_ > _).toList match {
      case 1 :: Nil    => "YES"
      case _ :: Nil    => "NO"
      case x :: y :: _ => if (x < N / 2 + N % 2 + 1) "YES"
                          else "NO"
    }

  out.println(solve)
  out.close
}

import java.util.Scanner

object YarPerm {
  def main(args: Array[String]) {
    val scan = new Scanner(System.in)
    val n = scan.nextInt
    val nums = List.fill(n)(scan.nextInt)
    val d = nums.distinct
    val f = d.map(x => nums.count(y => y== x))
    val m = f.max
    println(if (2*m <=n || (n%2==1 && 2*m==n+1))"YES" else "NO")
  }
}

object A {
  def READ: Array[Int] = readLine() split (" ") map (_.toInt);

  def main(args: Array[String]) {
    var Array(n) = READ;
    var a:Array[Int] = READ;
    a = a map(x=>a.count(x==_));
    a = a filter(_ > (n+1)/2);

    println(if (a isEmpty) "YES" else "NO");
  }
}

import java.io._
import java.util.Locale
import scala.annotation.tailrec

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

  val n = readInt
  val a = readInts
  def ans = if(n - a.groupBy(x => x).values.map(_.size).max < n / 2) "NO" else "YES"

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

object Main {
  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)
    val half = (a.size + 1) / 2
    if (map.values.find(_ > half).isDefined) println("NO")
    else println("YES")
  }
}

object CF179Div2A {
  def main(args:Array[String]){
    val n = readLine.toInt;
    val ar = readLine.split(" ").map(_.toInt);
    val ex = (1 to 1000).map(x=> ar.filter(_ == x).length).forall(_ <= (n+1)/2);
    if(ex) println("YES") else println("NO");
  }
}

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

object P296A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextInt)

  def solve(): String = A.groupBy(identity).toSeq.sortWith(_._1 > _._1).toList match {
      case (1, _) :: Nil => "YES"
      case (x, y) :: _   => if (y.size < N / 2 + N % 1 + 1) "YES"
                            else "NO"
  }

  out.println(solve)
  out.close
}

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

object P296A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextInt)

  def solve(): String = A.groupBy(identity).toSeq.sortWith(_._1 < _._1).toList match {
      case (1, _) :: Nil => "YES"
      case (x, _) :: _   => if (x < N / 2 + N % 1 + 1) "YES"
                            else "NO"
  }

  out.println(solve)
  out.close
}

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

object P296A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextInt)

  def solve(): String = A.groupBy(identity).toSeq.map(_._2.size).sortWith(_ > _).toList match {
      case _ :: Nil    => "YES"
      case x :: y :: _ => if (x < N / 2 + N % 1 + 1) "YES"
                          else "NO"
    }

  out.println(solve)
  out.close
}

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

object P296A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N = sc.nextInt
  val A = Array.fill(N)(sc.nextInt)

  def solve(): String = A.groupBy(identity).toSeq.map(_._2.size).sortWith(_ > _).toList match {
      case _ :: Nil    => "YES"
      case x :: y :: _ => {
        if (x < N / 2 + N % 2 + 1) "YES"
        else "NO"
      }
    }

  out.println(solve)
  out.close
}

object Main {
  def main(args: Array[String]) = {
    val n = readInt()
    val a = readLine().split(" ").map(_.toInt)
    val map = scala.collection.mutable.Map[Int, Int]()
    a.foreach(i => map(i) = map.getOrElse(i, 0) + 1)
    val half = (a.size + 1) / 2
    if (map.values.find(_ > half).isDefined) println("NO")
    else println("NO")
  }
}


/**
  * @author ShankarShastri
  *         Algorithm: DiverseString (http://codeforces.com/contest/1144/problem/A)
  */

import scala.io.StdIn._
import scala.annotation.tailrec

object DiverseString {
  def loop[T](n: Int)(block: => T) = (1 to n).foreach(_ => block)

  def main(args: Array[String]): Unit = {
    val t = readLine.toInt
    val alphaStr = "abcdefghijklmnopqrstuvwxyz"
    loop(t) {
      val s = readLine.sorted
      if (s.length > 26) {
        println("No")
      } else {
        s.headOption match {
          case None => println("No")
          case Some(l) =>
            alphaStr.indexOf(l) match {
              case e if (e + s.length > 26) => println("No")
              case e if (s.diff(alphaStr.substring(e, (e + s.length))).length == 0 && e != -1) => println("Yes")
              case _ => println("No")
            }
        }
      }
    }
  }
}

object A1144Strings extends App {
    import scala.io.StdIn.{readInt, readLine}
  (0 until readInt()).map(_ => readLine.toCharArray.sorted) map{x =>
    x.map(_ - x.head).zipWithIndex.exists(x => x._1 != x._2)
  } foreach {if(_) println("No") else println("Yes")}
}

object a1144 {
  def solve(str: String) : String = {
    val s = str.sorted
    if (s zip s.tail forall(i => i._2 - i._1 == 1))  "Yes" else "No"
  }

  def main(args: Array[String]): Unit = {
    println(scala.io.Source.stdin getLines() drop 1 map solve mkString "\n")
  }
}

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

    for (i <- 0 until n){
      val str = stdin.readLine().sorted
      var res = true
      for (i <- str.indices if i+1 < str.length){
        if (math.abs(str(i) - str(i+1)) > 1) res = false
      }
      if (str.groupBy(identity).map(x => x._2.length).count(_ > 1) > 0 ) res = false
      val ans = if (res) "Yes" else "No"
      println(ans)
    }
  }
}

import java.util.Scanner

import scala.collection.mutable.ListBuffer

object Main {

  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val n = Integer.parseInt(sc.nextLine())
    val list = new ListBuffer[String]

    for(i <- 1 to n ){
      val elem: String = sc .nextLine()
      list += elem
    }

    list.map({s =>
      s.max - s.min == s.length - 1 && s.distinct.length == s.length
    })
      .map(elem => if(elem) println("Yes") else println("No"))
  }
}

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

  override def apply(io: IO): io.type = {
    val strings = io.read[List[String]]

    val ans = strings
      .map({s =>
        s.max - s.min == s.length - 1 &&
        s.distinct.length == s.length
      })
      .map(t => if (t) "Yes" else "No")

    io.writeLines(ans)
  }
}
/****************************[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
      }
    }
  }
}

/**
  * @author ShankarShastri
  *         Algorithm: DiverseString (http://codeforces.com/contest/1144/problem/A)
  */

import scala.io.StdIn._
import scala.annotation.tailrec

object DiverseString {
  def loop[T](n: Int)(block: => T) = (1 to n).foreach(_ => block)
  def main(args: Array[String]): Unit = {
    val t = readLine.toInt
    val alphaStr = "abcdefghijklmnopqrstuvwxyz"
    loop(t) {
      val s = readLine.sorted
      if (s.length > 26) {
        println("Yes")
      } else {
        s.headOption match {
          case None => println("No")
          case Some(l) =>
            alphaStr.indexOf(l) match {
              case e if (s.diff(alphaStr.substring(e, (e + s.length))).length == 0 && e != -1) => println("Yes")
              case _ => println("No")
            }
        }
      }
    }
  }
}

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

  override def apply(io: IO): io.type = {
    val strings = io.read[List[String]]

    val ans = strings
      .map(s => s.max - s.min == s.length - 1)
      .map(t => if (t) "Yes" else "No")

    io.writeLines(ans)
  }
}
/****************************[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
      }
    }
  }
}


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 B619(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 B619(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val t = ni()
    REP(t) { _ =>
      val n = ni()
      val a = na(n)
      var l = 0L
      var h = 1e10.toLong
      while (h - l > 2) {
        val m1 = l + (h - l) / 3
        val m2 = l + ((h - l) * 2) / 3

        if(checker(m1, a, n) > checker(m2, a , n)) {
          l = m1 + 1
        } else h = m2
      }
      var m = Long.MaxValue
      var id = l
      for(i <- l to h) {
        val x = checker(i, a, n)
        if(x < m) {
          m = x; id = i
        }
      }
      out.println(s"$m $id")
    }
  }

  def checker(k: Long, a: Array[Int], n: Int): Long = {
    var mx = -1L
    REP(n) { i =>
      if(i > 0) {
        val x = if(a(i-1) != -1) a(i-1) else k
        val y = if(a(i) != -1) a(i) else k
        mx = Math.max(mx, Math.abs(x - y))
      }
    }
    mx
  }
}

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

  import scala.collection.mutable
  import scala.collection.mutable.ListBuffer
  def main(args: Array[String]): Unit = {
    solve(System.in,System.out)
  }
  def solve(inputStream: InputStream, out: PrintStream): Unit = {
    val in = new InputReader(inputStream)
    val numCases = in.nextInt()
    (1 to numCases).foreach{_ =>
      val n = in.nextInt()
      val a = (1 to n).map(_ => in.nextInt()).toArray
      val mm0 = a.indices.foldLeft((Int.MaxValue,Int.MinValue)){ case ((min,max), i) =>
        if(a(i) == -1){
            if(i>0 && a(i-1) != -1)
              (Math.min(min,a(i-1)),Math.max(max,a(i-1)))
            else
              (min,max)
        }else{
          (min,max)
        }

      }
      val mm1 = a.indices.foldLeft(mm0){ case ((min,max), i) =>
        if(a(i) == -1){
          if(i+1<n && a(i+1) != -1)
            (Math.min(min,a(i+1)),Math.max(max,a(i+1)))
          else
            (min,max)
        }else{
          (min,max)
        }

      }

      val (min,max) = mm1
      val (bestM,bestK) = if(min == Int.MaxValue){
        (0,0)
      }else{
        val m = ((max-min)+1)/2
        val k = min + m

        val acualM = a.zip(a.tail).foldLeft(m){case (currentValue,(p,q)) => {
          val (preal,qreal) = (if(p == -1) k else p,if(q == -1) k else q)
          Math.max(currentValue,Math.abs(preal-qreal))
        }}

        (acualM,k)
      }
      out.println(s"$bestM $bestK")

    }
  }
  class InputReader(stream: InputStream){
    val reader: BufferedReader = new BufferedReader(new InputStreamReader(stream),32768)
    var tokenizer: StringTokenizer = _
    def next(): String = {
      while(tokenizer == null || !tokenizer.hasMoreTokens){
        try{
          tokenizer = new StringTokenizer(reader.readLine())
        }catch {
          case e: IOException => throw new RuntimeException(e)
        }
      }
      tokenizer.nextToken()
    }
    def nextInt(): Int =  next().toInt
    def nextLong(): Long =  next().toLong
  }
}


object Main extends App {

  val letters = (97 to 122).map(_.toChar).map(_.toString)

  def counter[A](seq: Seq[A]): Map[A, Int] = {
    seq.foldLeft(Map[A, Int]())({
      (acc, n) => acc.get(n) match {
        case None => acc + (n -> 1)
        case Some(m) => acc + (n -> (m+1))
      }
    })
  }

  val s = readLine.map(_.toString).toList
  val t = readLine.map(_.toString).toList
  val s1 = counter(s)
  val t1 = counter(t)

  val init = (0, 0)
  val (pos, neg) = letters.foldLeft(init)({
    case ((pos, neg), letter) =>
      val sLower = s1.getOrElse(letter, 0)
      val sUpper = s1.getOrElse(letter.toUpperCase, 0)
      val tLower = t1.getOrElse(letter, 0)
      val tUpper = t1.getOrElse(letter.toUpperCase, 0)
      val usedLower = Math.min(sLower, tLower)
      val usedUpper = Math.min(sUpper, tUpper)
      val pos2 = usedLower + usedUpper
      val neg2 = Math.min((sLower-usedLower), (tUpper - usedUpper)) + Math.min((sUpper-usedUpper), (tLower - usedLower))
      (pos + pos2, neg + neg2)
  })

  println("%d %d".format(pos, neg))
}

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

object B {

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

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

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

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

  def solve: Int = {
    val s = next.toCharArray
    val t = next.toCharArray
    val m = new scala.collection.mutable.HashMap[Char, Int]()
    for (i <- 0 until t.length) {
      val x = m.getOrElse(t(i), 0)
      m.put(t(i), x + 1)
    }
    var u = 0
    var o = 0
    val missed = new util.ArrayList[Char]()
    for (i <- 0 until s.length) {
      val symb = s(i)
      val x = m.getOrElse(symb, 0)
      if (x > 0) {
        u += 1
        m.put(symb, x - 1)
      } else {
        missed.add(symb)
      }
    }
    for (i <- 0 until missed.size()) {
      val symb = missed.get(i)
      if (Character.isUpperCase(symb)) {
        val lowerCase: Char = Character.toLowerCase(symb)
        val y = m.getOrElse(lowerCase, 0)
        if (y > 0) {
          o += 1
          m.put(lowerCase, y - 1)
        }
      } else {
        val upCase: Char = Character.toUpperCase(symb)
        val y = m.getOrElse(upCase, 0)
        if (y > 0) {
          o += 1
          m.put(upCase, y - 1)
        }
      }

    }
    out.println(u + " " + o)
    return 1
  }

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

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val need = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val haveO = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val res = need.foldLeft((haveO, Map.empty[Char, Int], 0)) {
    case((have, newNeed, yes), (el, count)) =>
      val newYes = Math.min(have.getOrElse(el, 0), count)
      (have + (el -> (have.getOrElse(el, 0) - newYes)),
        newNeed + (el -> (count - newYes)),
        yes + newYes)
  }
  val res2 = res._2.foldLeft(0) {
    case(no, (el, count)) =>
      val diffSymbol = if (el.isLower) el.toUpper else el.toLower
      no + Math.min(res._1.getOrElse(diffSymbol, 0), count)
  }

  println(s"${res._3} $res2")
}

import scala.collection.mutable

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var postMap: mutable.Map[Char, Int] = mutable.Map.empty[Char, Int]
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          postMap += (e._1 -> (-txtMap.get(e._1).get + e._2))
          txtMap -= e._1
        }
      } else {
        postMap += (e._1 -> e._2)
      }
    })
    postMap.foreach(e => {
      if (Character.isUpperCase(e._1)) {
        val chLower = Character.toLowerCase(e._1)
        if (txtMap.contains(chLower)) {
          if (e._2 <= txtMap.get(chLower).get) {
            opa += e._2
            txtMap += (chLower -> (txtMap.get(chLower).get - e._2))
          } else {
            opa += txtMap.get(chLower).get
            txtMap -= chLower
          }
        }
      } else {
        val chUpper = Character.toUpperCase(e._1)
        if (txtMap.contains(chUpper)) {
          if (e._2 <= txtMap.get(chUpper).get) {
            opa += e._2
            txtMap += (chUpper -> (txtMap.get(chUpper).get - e._2))
          } else {
            opa += txtMap.get(chUpper).get
            txtMap -= chUpper
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val need = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val have = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val res = need.foldLeft((have, 0, 0)) {
    case((have, yes, no), (el, count)) =>
      val newYes = Math.min(have.getOrElse(el, 0), count)
      val diffSymbol = if (el.isLower) el.toUpper else el.toLower
      if (newYes == count) {
        (have + (el -> (have.getOrElse(el, 0) - newYes)), yes + newYes, no)
      }
      else {
        val newNo = Math.min(count - newYes, have.getOrElse(diffSymbol, 0))
        (have + (el -> (have.getOrElse(el, 0) - newYes)) +
          (diffSymbol -> (have.getOrElse(diffSymbol, 0) - newNo))
          , yes + newYes, no + newNo)
      }
  }

  println(s"${res._2} ${res._3}")
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val need = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val haveO = in.next().groupBy(t => t).map(t => t._1 -> t._2.length)
  val res = need.foldLeft((haveO, 0, 0)) {
    case((have, yes, no), (el, count)) =>
      val newYes = Math.min(have.getOrElse(el, 0), count)
      val diffSymbol = if (el.isLower) el.toUpper else el.toLower
      val newNo = Math.min(count - newYes, have.getOrElse(diffSymbol, 0))
      (have + (el -> (have.getOrElse(el, 0) - newYes)) +
        (diffSymbol -> (have.getOrElse(diffSymbol, 0) - newNo))
        , yes + newYes, no + newNo)
  }

  println(s"${res._2} ${res._3}")
}

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          txtMap -= e._1
        }
      }
      if (Character.isUpperCase(e._1)) {
        if (txtMap.contains(Character.toLowerCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toLowerCase(e._1)).get
            txtMap -= Character.toLowerCase(e._1)
          }
        }
      } else {
        if (txtMap.contains(Character.toUpperCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toUpperCase(e._1)).get
            txtMap -= Character.toUpperCase(e._1)
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

import scala.collection.mutable

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var postMap: mutable.Map[Char, Int] = mutable.Map.empty[Char, Int]
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          txtMap -= e._1
          postMap += (e._1 -> e._2)
        }
      } else {
        postMap += (e._1 -> e._2)
      }
    })
    postMap.foreach(e => {
      if (Character.isUpperCase(e._1)) {
        if (txtMap.contains(Character.toLowerCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toLowerCase(e._1)).get
            txtMap -= Character.toLowerCase(e._1)
          }
        }
      } else {
        if (txtMap.contains(Character.toUpperCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toUpperCase(e._1)).get
            txtMap -= Character.toUpperCase(e._1)
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object B518 extends App {

  def solve() = {
    val str: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val txt: Array[Char] = scala.io.StdIn.readLine().toCharArray
    val strMap: Map[Char, Int] = str.groupBy(s => s).map(e => e._1 -> e._2.length)
    var txtMap: Map[Char, Int] = txt.groupBy(s => s).map(e => e._1 -> e._2.length)
    var hooray = 0
    var opa = 0
    strMap.foreach(e => {
      if (txtMap.contains(e._1)) {
        if (e._2 <= txtMap.get(e._1).get) {
          hooray += e._2
          txtMap += (e._1 -> (txtMap.get(e._1).get - e._2))
        } else {
          hooray += txtMap.get(e._1).get
          txtMap -= e._1
          if (Character.isUpperCase(e._1)) {
            if (txtMap.contains(Character.toLowerCase(e._1))) {
              if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
                opa += e._2
                txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
              } else {
                opa += txtMap.get(Character.toLowerCase(e._1)).get
                txtMap -= Character.toLowerCase(e._1)
              }
            }
          } else {
            if (txtMap.contains(Character.toUpperCase(e._1))) {
              if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
                opa += e._2
                txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
              } else {
                opa += txtMap.get(Character.toUpperCase(e._1)).get
                txtMap -= Character.toUpperCase(e._1)
              }
            }
          }
        }
      }
      if (Character.isUpperCase(e._1)) {
        if (txtMap.contains(Character.toLowerCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toLowerCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toLowerCase(e._1) -> (txtMap.get(Character.toLowerCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toLowerCase(e._1)).get
            txtMap -= Character.toLowerCase(e._1)
          }
        }
      } else {
        if (txtMap.contains(Character.toUpperCase(e._1))) {
          if (e._2 <= txtMap.get(Character.toUpperCase(e._1)).get) {
            opa += e._2
            txtMap += (Character.toUpperCase(e._1) -> (txtMap.get(Character.toUpperCase(e._1)).get - e._2))
          } else {
            opa += txtMap.get(Character.toUpperCase(e._1)).get
            txtMap -= Character.toUpperCase(e._1)
          }
        }
      }
    })
    println(hooray + " " + opa)
  }

  solve()

}

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

object B {

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

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

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

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

  def solve: Int = {
    val s = next.toCharArray
    val t = next.toCharArray
    val m = new scala.collection.mutable.HashMap[Char, Int]()
    for (i <- 0 until t.length) {
      val x = m.getOrElse(t(i), 0)
      m.put(t(i), x + 1)
    }
    var u = 0
    var o = 0
    for (i <- 0 until s.length) {
      val symb = s(i)
      val x = m.getOrElse(symb, 0)
      if (x > 0) {
        u += 1
        m.put(symb, x - 1)
      } else {
        if (Character.isUpperCase(symb)) {
          val lowerCase: Char = Character.toLowerCase(symb)
          val y = m.getOrElse(lowerCase, 0)
          if (y > 0) {
            o += 1
            m.put(lowerCase, y - 1)
          }
        } else {
          val upCase: Char = Character.toUpperCase(symb)
          val y = m.getOrElse(upCase, 0)
          if (y > 0) {
            o += 1
            m.put(upCase, y - 1)
          }
        }
      }
    }
    out.println(u + " " + o)
    return 1
  }

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

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

object B {

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

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

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

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

  def solve: Int = {
    val s = next
    val t = next.toCharArray
    val m = new scala.collection.mutable.HashMap[Char, Int]()
    for (i <- 0 until t.length) {
      val x = m.getOrElse(t(i), 0)
      m.put(t(i), x + 1)
    }
    var u = 0
    var o = 0
    for (i <- 0 until s.length) {
      val x = m.getOrElse(s(i), 0)
      if (x > 0) {
        u += 1
        m.put(s(i), x - 1)
      } else {
        if (Character.isUpperCase(s(i))) {
          val lowerCase: Char = Character.toLowerCase(s(i))
          val y = m.getOrElse(lowerCase, 0)
          if (y > 0) {
            o += 1
            m.put(lowerCase, y - 1)
          }
        }
        else {
          val upCase: Char = Character.toUpperCase(s(i))
          val y = m.getOrElse(upCase, 0)
          if (y > 0) {
            o += 1
            m.put(upCase, y - 1)
          }
        }
      }
    }
    out.println(u + " " + o)
    return 1
  }

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


object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        print("7")
        n = n - 3
    }
    while (n >= 2) {
        print("1")
        n = n - 2
    }
    println("")
}

object HelloWorld {
    def main(args: Array[String])
    {
        var n = readInt;
        var i = 0;
        if(n%2==0) print(1);
        else print(7);
        for(i <- 2 to n/2)
        {
            print(1);
        }
    }
}

object Main extends App {
    val n = readInt
    if (n % 2 == 1)
    {
        print(7);
        for (i <- 1 to (n - 3) / 2)
            print(1);
    }
    else
    {
        for (i <- 1 to n / 2)
            print(1);
    }
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        n = n - 3;
        print(7)
    }
    while (n >= 2) {
        n = n - 2;
        print(1)
    }
}

object X extends App {
  val n = scala.io.StdIn.readLine.toInt
  if (n < 2)
    println(0)
  else {
    var res = 1
    if (n % 2 == 1) res = 7
    print(res)
    for (i <- 2 to n/2) {
        print(1);
    }
    println()
  }
}

object TEST extends App{
    var n = readInt
    if(n%2==1)
    {
        print(7)
        n-=3
    }
    for(i <- 1 to n/2) print(1)
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1)
    {
        print(7)
        n = n - 3
    }
    for (i <- 1 to n / 2) print(1)
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        print("7")
        n = n - 3
    }

    for (i <- 1 to n / 2) {
        print("1")
    }
}

object Main extends App {
    var n = readInt
    if (n % 2 == 1) {
        print(7)
        n = n - 3
    }
    n = n / 2
    for (i <- 1 to n) {
        print(1)
        //println(if (k <= 10) s else s(0) + (k - 2).toString + s(k-1))
    }
}

object c {
    def main(args: Array[String]) {
      val n = readInt()
      var seven = 0
      var one = 0
      if (n % 2 == 1) {
          one = n / 2 - 1
          seven = 1
      } else {
          one = n / 2
      }

      for (i <- 1 to seven) {
          print(7)
      }
      for (i <- 1 to one) {
          print(1)
      }
   }
}

object Main extends App {
	var n = readInt
	if (n % 2 == 1) {
		print(7)
		n = n - 3
	}
	while( n > 0 ) {
		print(1)
		n = n - 2
	}
}

object Main extends App {
	// your code goes here
	var n = readInt
	while (n > 0) {
		if (n % 2 == 1) {
			n -= 3;
			print(7);
		}
		else {
			n -= 2;
			print(1);
		}
	}
}

object Main extends App {
    val n = readInt
    var a = 0
    if (n % 2 == 0) {
        for ( a <- 1 to n / 2) {
            print(1);
        }
    } else {
        print(7);
        for ( a <- 1 to n / 2 - 1) {
            print(1);
        }
    }
}

import java.util.Scanner
object Main extends App {
	val in = new Scanner(System.in)
	var n = in.nextInt()
	if (n % 2 == 1) {
		print(7)
		n = n - 3
	}
	n = n / 2
	var a = 0
	for(a <- 1 to n)
	    print(1)
}

object Main extends App {
    val n = readInt
	val k = n / 2 - 1
	val t = n % 2
	print(if (t == 1) '7' else '1')
	for (i <- 1 to k) {
		print('1')
	}
}

object Main extends App {
    val n = readInt
    print(if (n % 2 == 0) 1 else 7)
    for (i <- 1 to (n - 2) / 2) print(1)
}

object Main extends App {
    var ans :String = ""
    val n = readInt

    if (n % 2 == 0) {
      for (i <- 1 to n / 2) {
        print(1)
      }
    }
   else {
     print(7)
     for (i <- 1 to (n - 3) / 2) {
       print(1)
     }
   }

    println()

}

object Main extends App {
    val n = readInt
   if(n%2==0){
        for (i <- 1 to n/2) {
         print(1)
        }
   }
   else{
       print(7)
        for (i <- 1 to (n-3)/2) {
         print(1)
        }

   }
}

object Main extends App {
    var n = readInt
    if(n%2==1){
        print(7)
        n=n-3
    }
    n/=2
    for (i <- 1 to n) {
        print(1)
    }
}

object Main extends App {
    var n = readInt;
    var num = 0;
    if(n % 2 == 1 && n > 1){
        print(7);
        n -= 3;
    }
    while(n > 1){
        n -= 2;
        print(1);
    }
}

object Main extends App {
  val cost = Array( 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 )
  var N = readInt // keyword val seems to work like const, in contrast to var
  if( N % 2 == 1 ) {
    print( 7 )
    N -= 3
  }
  while( N > 0 ) {
    print( 1 )
    N -= 2
  }
  println()
}

object Main extends App {
    var n = readInt
    if(n%2==1){
        println(7)
        n=n-3
    }
    n/=2
    for (i <- 1 to n) {
        println(1)
    }
}

object Main extends App {
  val cost = Array( 6, 2, 5, 5, 4, 5, 6, 3, 7, 6 )
  var N = readInt // keyword val seems to work like const, in contrast to var
  while( N >= 2 ) {
    // for に break のキーワードはないらしい...
    var i = 9
    while( i >= 0 ) {
      if( N >= cost( i ) ) { // [] ではなく () なんですね...
        print( i )
        N -= cost( i )
        i = -1 // break とする
      }
      i -= 1
    }
  }
  println()
}

object HelloWorld {
    def main(args: Array[String])
    {
        var n = readInt;
        var i = 0;
        if(n%2==0) print(1);
        else print(7);
        for(i <- 1 to n/2)
        {
            print(1);
        }
    }
}

object X extends App {
  val n = scala.io.StdIn.readLine.toInt
  if (n < 2)
    println(0)
  else {
    var res = 1
    if (n % 2 == 1) res = 7
    for (i <- 2 to n/2) {
        res = res * 10 + 1;
    }
    println(res)
  }
}

object c {
    def main(args: Array[String]) {
      val n = readInt()
      var seven = 0
      var one = 0
      if (n % 3 == 1) {
          seven = n / 3 - 1
          one = 2
      } else if (n % 3 == 2) {
          seven = n / 3
          one = 1
      } else {
          seven = n / 3
      }

      for (i <- 1 to seven) {
          print(7)
      }
      for (i <- 1 to one) {
          print(1)
      }
   }
}

object Main extends App {
	var n = readInt
	while( n > 3 ) {
		print(1)
		n = n - 2
	}
	if (n == 3)
		print(7)
	else
		print(1)
}

import java.util.Scanner
object Main extends App {
	val in = new Scanner(System.in)
	var n = in.nextInt()
	if (n % 2 == 1) {
		print(7)
		n = n - 1
	}
	n = n / 2
	var a = 0
	for(a <- 1 to n)
	    print(1)
}


object Solution {
   def main(args: Array[String]) {
      val sc = new java.util.Scanner(System.in);
      val n: Int = sc.nextInt();
      var i = 0;
      var t = new Array[Boolean](1440);

      for (i <- 0 to 1439) t(i) = false;

      for (i <- 0 to n-1) {
          var s = sc.next();
          var arr = s.split(":");

          var x = arr(0).toInt * 60 + arr(1).toInt;
          t(x) = true;
      }

      var res = 0;
      var cnt = 0;
      for (i <- 0 to 3000) {
          if (t(i % 1440) == false) cnt += 1; else cnt = 0;
          if (cnt > res) res = cnt;
      }

      var h = res / 60;
      var m = res % 60;

      println(f"$h%02d:$m%02d");
   }
}


object Interview extends App {
  //println((1 to 1000).mkString(" "))
  val n = scala.io.StdIn.readLine().toInt
  val array1 = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array2 = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def fSum(x1: Array[Int], x2: Array[Int], l: Int, r: Int): Int = {
    var sum1 = x1(l)
    var sum2 = x2(l)
    var i = l + 1
    while (i <= r) {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
      i += 1
    }
    sum1 + sum2
  }

  var max = fSum(array1, array2, 0, 0)
  var l = 0
  while (l < n - 1) {
    var r = l
    while (r < n) {
      val candidate = fSum(array1, array2, l, r)
      if (candidate > max) max = candidate
      r += 1
    }
    l += 1
  }

  println(max)
}

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

import scala.collection.mutable.ListBuffer

object Solution extends ConsoleIO {
  def main(args: Array[String]) = {
    withIO {(reader, writer) =>
      val n = reader.nextInt()
      val a = ListBuffer.empty[Int]
      (1 to n).foreach { _ =>
        a.append(reader.nextInt())
      }
      val b = ListBuffer.empty[Int]
      (1 to n).foreach { _ =>
        b.append(reader.nextInt())
      }
      val result = a.reduce( _ | _)  + b.reduce(_ | _)
      writer.print(result)
    }
  }
}

trait ConsoleIO {
  def withIO(task: (Scanner, PrintWriter) => Unit) = {
    val reader = new Scanner(new BufferedReader(new InputStreamReader(System.in)))
    val writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)))
    task(reader, writer)
    reader.close()
    writer.close()
  }
}

trait FileIO {
  def withIO(task: (Scanner, PrintWriter) => Unit) = {
    val reader = new Scanner(new BufferedReader(new InputStreamReader(new FileInputStream("input.txt"))))
    val writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(new FileOutputStream("output.txt"))))
    task(reader, writer)
    reader.close()
    writer.close()
  }
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val data = in.next().split(' ').map(_.toInt).zip(in.next().split(' ').map(_.toInt))
  println((0 until n).foldLeft(0) {
    case (acc, i) =>
      val drop1 = data.drop(i)
      val head = drop1.head
      drop1.tail.foldLeft(head, Math.max(acc, head._1 + head._2)) {
        case (((fSoFar, sSoFar), max), (first, second)) =>
          val nfSoFar = fSoFar | first
          val nsSoFar = sSoFar | second
          ((nfSoFar, nsSoFar), Math.max(max, nfSoFar + nsSoFar))
      }._2
  })
}

object A631 {

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

  def main(args: Array[String]): Unit = {
    val Array(num) = readInts(1)
    val a = readInts(num).foldLeft(0L){case (sum, n) => sum|n}
    val b = readInts(num).foldLeft(0L){case (sum, n) => sum|n}
    println(a+b)
  }

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

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

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

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

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

}

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

object _631A extends CodeForcesApp {
  override type Result = Long

  override def solve(read: InputReader) = {
    val n = read[Int]
    val a, b = read[IndexedSeq, Long](n).foldLeft(0L){case (i, j) => i | j}
    a + b
  }

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

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

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

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

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

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

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

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

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

/**
 * Created by aborisenko on 21.02.16.
 */

import io.StdIn._

object Main extends App {
  def a631 (){

    val n = readInt()
    val a: Array[Long] = readLine().split(" ").map(_.toLong)
    val b: Array[Long] = readLine().split(" ").map(_.toLong)

    var result1: Long = 0
    for( i <- 0 to n-1)
      result1 |= a(i)
    var result2: Long = 0

    for( i <- 0 to n-1)
      result2 |= b(i)

    println(result1 + result2)
  }

  a631()
}

import scala.io.StdIn

/**
  * http://codeforces.com/problemset/problem/631/A
  * */
object AInterview {

  private def orValues(values: Seq[Long]): Long = {
    values.foldLeft(0L)(_ | _)
  }

  def main(args: Array[String]): Unit = {
    StdIn.readLine()
    val fstValues = StdIn.readLine().split(" ").map(_.toLong)
    val scdValues = StdIn.readLine().split(" ").map(_.toLong)
    val result = orValues(fstValues) + orValues(scdValues)
    println(result)
  }
}

object Interview extends App {
  //println((1 to 1000).mkString(" "))
  val n = scala.io.StdIn.readLine().toInt
  val array1 = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array2 = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def fSum(x1: Array[Int], x2: Array[Int], l: Int, r: Int): Int = {
    var sum1 = x1(l)
    var sum2 = x2(l)
    var i = l + 1
    while (i < r) {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
      i = i + 1
    }
    sum1 + sum2
  }

  var max = fSum(array1, array2, 0, 0)
  var l = 0
  while (l < n - 1) {
    var r = l
    while (r < n) {
      val candidate = fSum(array1, array2, l, r)
      if (candidate > max) max = candidate
      r = r + 1
    }
    l = l + 1
  }

  println(max)
}

object Interview extends App {
  //println((1 to 1000).mkString(" "))
  val n = scala.io.StdIn.readLine().toInt
  val array1 = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val array2 = scala.io.StdIn.readLine().split(" ").map(_.toInt)

  def fSum(x1: Array[Int], x2: Array[Int], l: Int, r: Int): Int = {
    var sum1 = x1(l)
    var sum2 = x2(l)
    var i = l + 1
    while(i < r) {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
      i = i + 1
    }
    /*for {
      i <- (l + 1) until r
    } {
      sum1 = sum1 | x1(i)
      sum2 = sum2 | x2(i)
    }*/
    sum1 + sum2
  }

  var max = 0L
  var l = 0
  while(l < n -1) {
    var r = l + 1
    while(r < n) {
      val candidate = fSum(array1, array2, l, r)
      if (candidate > max) max = candidate
      r = r + 1
    }
    l = l + 1
  }
  /*for {
    l <- 0 until n - 1
    r <- l + 1 until n
  } {
    val candidate = fSum(array1, array2, l, r)
    if (candidate > max) max = candidate
  }*/

  println(max)
}


import scala.collection.mutable.HashMap

object B extends App {
 val n = readInt
 val str = readLine.split(" ").map(_.toInt).zipWithIndex
 val mp = new HashMap[Int, (Int, Int, Int)]()
 for((i, j) <- str) {
 val k = mp.getOrElse(i, (0, 0, 0))
 if(k._1 == 0)
  mp(i) = (1, j, j)
 else
  mp(i) = (k._1 + 1, k._2, j)
 }

 val res = mp.toList.sortWith((i, j) => i._2._1 > j._2._1 || i._2._1 == j._2._1 && (i._2._3 - i._2._2) < (j._2._3 - j._2._2))(0)
 print(res._2._2 + 1 + " " + (res._2._3 + 1))
}

//package c558.b

object Solution extends App {
  case class C3(counter: Int, left: Int, right: Int)
  case object C3 { def empty(i: Int) = C3(1, i, i) }
  def solve(n: Int, array: Seq[Int]) = {
    import scala.collection.mutable
    val indexedArray = array.zip(1 to n)
    val beautyMap = mutable.Map.empty[Int, C3]
    indexedArray.foreach(xi ⇒ {
      val (x, i) = xi._1 → xi._2
      val elem = beautyMap.getOrElse(x, C3.empty(i))
      beautyMap.put(x, elem.copy(counter = elem.counter + 1, right = i))
    })
    val maxElem = beautyMap.maxBy(kv ⇒ kv._2.counter)
    val best = beautyMap
      .filter(_._2.counter == maxElem._2.counter)
      .minBy(kv ⇒ kv._2.right - kv._2.left)._2
    s"${best.left} ${best.right}"
  }
  import scala.io.StdIn
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  println(solve(n, array))
}

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec

object Main {
  case class LR(left : Int, right : Int, cnt : Int)
  object EnRich {
    implicit class AString(val self : String) extends AnyVal {
      def splitToIntArray = self.split(" ").map(_.toInt)
    }
  }
  import EnRich._

  def main(args : Array[String]) : Unit = {
    val n = readLine.toInt
    val a = readLine.splitToIntArray
    val h = scala.collection.mutable.HashMap[Int,LR]()
    (a.zipWithIndex).foreach({case (a,i) => h.get(a) match {
                                case None => h(a) = LR(i,i,1)
                                case Some(LR(l,r,k)) => h(a) = LR(l,i,k+1)
                              }})
    val m = h.toList.map({case (_,LR(_,_,k)) => k}).max
    val f = h.toList.filter({case (_,LR(_,_,k)) => k == m}).
                     sortBy(({case (_,LR(l,r,_)) => r-l}))
    val l = f.head._2.left+1
    val r = f.head._2.right+1
    println(s"$l $r")
  }
}

import annotation.tailrec, collection.mutable, util.control.Breaks._, math.Ordering.Implicits._
object _558B extends CodeForcesApp[(Int, Int)]({scanner => import scanner._
  val array = List.fill(nextInt)(nextInt)
  val start = mutable.Map.empty[Int, Int] withDefaultValue Integer.MAX_VALUE
  val end = mutable.Map.empty[Int, Int] withDefaultValue Integer.MIN_VALUE
  val counter = mutable.Map.empty[Int, Int] withDefaultValue 0
  for {(n, p) <- array.zipWithIndex} {
    start(n) = start(n) min p
    end(n) = end(n) max p
    counter(n) += 1
  }
  val (_, maxRepeat) = counter.maxBy(_._2)

  val answers = for {
    (n, count) <- counter if count == maxRepeat
  } yield start(n) -> end(n)

  answers minBy {case (x, y) => (y - x, x)}
}) {
  override def format(result: (Int, Int)) = result match {
    case (x, y) => s"${x+1} ${y+1}"
  }
}
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[B](x: Boolean)(f: => B): Option[B] = if (x) Some(f) else None
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}

import scala.io.StdIn.readLine

object AmrAndTheLargeArray{
  case class Triplet( left : Int, right : Int, count : Int)
  def main(args : Array[String]) : Unit = {
      readLine()
      val a = readLine().split("\\s+").map( _.toInt )
      val map = scala.collection.mutable.HashMap[Int, Triplet]()
      (a.zipWithIndex).foreach({
        case (a,i) => map.get(a) match {
          case None => map(a) = Triplet(i,i,1)
          case Some(Triplet(l,r,k)) => map(a) = Triplet(l,i,k+1)
        }
      })

      val ans = map.valuesIterator.reduceLeft( (thiz, that) => {
         if(thiz.count != that.count)
          if(thiz.count >= that.count) thiz else that
        else if ((thiz.right - thiz.left) <= (that.right - that.left)) thiz else that
      })

      val l = ans.left + 1
      val r = ans.right + 1
      println(l + " " + r)
  }
}

import scala.io.StdIn.readLine

object AmrAndTheLargeArray{
  case class Triplet( left : Int, right : Int, count : Int)
  def main(args : Array[String]) : Unit = {
      readLine()
      val a = readLine().split("\\s+").map( _.toInt )
      val map = scala.collection.mutable.HashMap[Int, Triplet]()
      (a.zipWithIndex).foreach({
        case (a,i) => map.get(a) match {
          case None => map(a) = Triplet(i,i,1)
          case Some(Triplet(l,r,k)) => map(a) = Triplet(l,i,k+1)
        }
      })
      val ans = map.reduceLeft( (thiz, that) => {
        if(thiz._2.count != that._2.count)
          if(thiz._2.count >= that._2.count) thiz else that
        else if ((thiz._2.right - thiz._2.left) <= (that._2.right - that._2.left)) thiz else that
      })

      val l = ans._2.left + 1
      val r = ans._2.right + 1
      println(l + " " + r)
  }
}

//package c558.b

object Solution extends App {
  case class C3(counter: Int, left: Int, right: Int)
  case object C3 { def empty(i: Int) = C3(1, i, i) }
  def solve(n: Int, array: Seq[Int]) = {
    import scala.collection.mutable
    val indexedArray = array.zip(1 to n)
    val beautyMap = mutable.Map.empty[Int, C3]
    indexedArray.foreach(xi ⇒ {
      val (x, i) = xi._1 → xi._2
      val elem = beautyMap.getOrElse(x, C3.empty(i))
      beautyMap.put(x, elem.copy(counter = elem.counter + 1, right = i))
    })
    val maxElem = beautyMap.maxBy(kv ⇒ kv._2.counter)
    val best = beautyMap.filter(_._2 == maxElem._2).maxBy(kv ⇒ kv._2.right - kv._2.left)._2
    s"${best.left} ${best.right}"
  }
  import scala.io.StdIn
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  println(solve(n, array))
}

//package c558.b

object Solution extends App {
  def solve(n: Int, array: Seq[Int]) = {
    import scala.collection.mutable
    val indexedArray = array.zip(1 to n)
    val beautyMap = mutable.Map.empty[Int, Int]
    indexedArray.foreach(xi ⇒ {
      val x = xi._1
      val elem = beautyMap.getOrElse(x, 0)
      beautyMap.put(x, elem + 1)
    })
    val maxElem = beautyMap.maxBy(kv ⇒ kv._2)
    val left = array.indexOf(maxElem._1) + 1
    val right = array.lastIndexOf(maxElem._1) + 1
    s"$left $right"
  }
  import scala.io.StdIn
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  println(solve(n, array))
}

//package c558.b

object Solution extends App {
  import scala.io.StdIn
  import scala.collection.mutable
  val n = StdIn.readInt()
  val array = StdIn.readLine().split(" ").map(_.toInt)
  val indexedArray = array.zip(0 until n)
  case class C3(counter: Int, left: Int, right: Int)
  case object C3 { def empty = C3(0, 0, 0) }
  val beautyMap = mutable.Map.empty[Int, C3]
  indexedArray.foreach(xi ⇒ {
    val (x, i) = xi._1 → xi._2
    val elem = beautyMap.getOrElse(x, C3.empty.copy(left = i))
    beautyMap.put(x, elem.copy(counter = elem.counter + 1, right = i))
  })
  val maxElem = beautyMap.maxBy(kv ⇒ kv._2.counter)
  println(s"${maxElem._2.left + 1} ${maxElem._2.right + 1}")
}

import scala.io.StdIn.readLine
import scala.collection.mutable.PriorityQueue
import scala.annotation.tailrec

object Main {
  case class LR(left : Int, right : Int, cnt : Int)
  object EnRich {
    implicit class AString(val self : String) extends AnyVal {
      def splitToIntArray = self.split(" ").map(_.toInt)
    }
  }
  import EnRich._

  def main(args : Array[String]) : Unit = {
    val n = readLine.toInt
    val a = readLine.splitToIntArray
    val h = scala.collection.mutable.HashMap[Int,LR]()
    (a.zipWithIndex).foreach({case (a,i) => h.get(a) match {
                                case None => h(a) = LR(i,i,1)
                                case Some(LR(l,r,k)) => h(a) = LR(l,i,k+1)
                              }})
    val m = h.toList.map({case (_,LR(_,_,k)) => k}).max
    val f = h.toList.filter({case (_,LR(_,_,k)) => k == m})
    val l = f.head._2.left+1
    val r = f.head._2.right+1
    println(s"$l $r")
  }
}

import scala.collection.mutable.HashMap

object B extends App {
 val n = readInt
 val str = readLine.split(" ").map(_.toInt).zipWithIndex
 val mp = new HashMap[Int, (Int, Int, Int)]()
 for((i, j) <- str) {
 val k = mp.getOrElse(i, (0, 0, 0))
 if(k._1 == 0)
  mp(i) = (1, j, j)
 else
  mp(i) = (k._1 + 1, k._2, j)
 }

 val res = mp.toList.sortWith((i, j) => i._2._1 > j._2._1 || i._2._1 == j._2._1 && (i._2._3 - i._2._1) < (j._2._3 - j._2._1))(0)
 print(res._2._2 + 1 + " " + (res._2._3 + 1))
}


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

object B_311 {

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

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

    //---------------------------- parameters reading --------------------------
    br = setupInputOutput();
    val line1 = readLine
    val n = line1.int
    val w = line1.long
    var cups = new Array[Long](2*n)
    val capasLine = readLine()
    for (i<-0 until 2*n) {
      cups(i) = capasLine.long
    }
    cups = cups.sortWith(_<_)
    val girlsCap = cups(0)
    val boysCap = cups(n)
    val min = Math.min(girlsCap, boysCap/2d)
    val possibleVol = min*n*3

    val res = Math.min(possibleVol, w)
    println(res)

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

  }

  //---------------------------- service code ----------------------------------

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()

  }

  var debugV = false
  var is = System.in
  var br = setupInputOutput();
  def db(x: => String) = if (debugV) println(x) // nullary function
  def setupInputOutput(): BufferedReader = {
    val devEnv = this.getClass.getCanonicalName.contains(".")
    if (!devEnv) {
      is = System.in
      debugV = false
    }
    val bis = new BufferedInputStream(is);
    new BufferedReader(new InputStreamReader(bis));
  }

//============================================================================================
object Test {

val sa1 = """
3 18
4 4 4 2 2 2
"""

}

}

import scala.io.StdIn._
import scala.math.min
import scala.language.postfixOps

object B {
  def main(args: Array[String]) {
    val n :: w :: _ = readLine split " " map (_.toDouble) toList
    val arr = readLine split " " map (_.toDouble) sorted
    var boy = arr(arr.length / 2)
    var girl = boy / 2
    if (girl > arr(0)) {
      girl = arr(0)
      boy = girl * 2
    }
    val sum = boy * n + girl * n
    println(min(sum, w))
  }
}

import scala.annotation.tailrec, scala.collection.mutable
import CodeForcesApp._
object _557B extends CodeForcesApp[Double]({scanner => import scanner._
  val (n, w) = (nextInt, nextInt)
  val cups = IndexedSeq.fill(2*n)(nextInt).sorted
  val (x, y) = (cups(n).toDouble, cups(0).toDouble)
  val g = y min (x/2)
  3*g*n min w
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val (modulus: Int, eps: Double) = (1000000007, 1e-9)
  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
}

import scala.annotation.tailrec, scala.collection.mutable
import CodeForcesApp._
object _557B extends CodeForcesApp[Double]({scanner => import scanner._
  val (n, w) = (nextInt, nextInt)
  val cups = IndexedSeq.fill(2*n)(nextInt).sorted
  val (x, y) = (cups(n).toDouble, cups(0).toDouble)
  val g = y min (x/2)
  val ans = 3*g*n
  ans min w
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus: Int = 1000000007
  val eps: Double = 1e-9
  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
}

import scala.annotation.tailrec, scala.collection.mutable
import CodeForcesApp._
object _557B extends CodeForcesApp[Double]({scanner => import scanner._
  val (n, w) = (nextInt, nextInt)
  val cups = List.fill(2*n)(nextInt)
  val (girls, boys) = cups.sorted.splitAt(n)
  val (x, y) = (boys.last.toDouble, girls.last.toDouble)
  debug(x, y, y >= x/2)
  val ans = if (y >= x/2) {
    x*n + (x/2)*n
  } else {
    y*n + 2*y*n
  }
  ans min w
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  val modulus: Int = 1000000007
  val eps: Double = 1e-9
  def when[A](x: Boolean)(f: => A): Option[A] = if (x) Some(f) else None
  def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
}


object Main extends App {
	var i = 0
	var k1 = 0
	var k2 = 0
	var flag = 1
    val Token = readLine().split(" ").map(_.toLong)
    var n = Token(0).toInt
    var l = Token(1).toInt - 1
    var r = Token(2).toInt - 1
    val arr1 = readLine().split(" ").map(_.toLong)
    val arr2 = readLine().split(" ").map(_.toLong)

    while (i < n) {
        k1 = arr1(i).toInt
        k2 = arr2(i).toInt
        if ((i < l || i > r) && k1 != k2) {flag = 0}
        i += 1
    }
    if (flag == 1) {print("TRUTH")}
    else {print("LIE")}
}

import scala.io.StdIn._

import scala.collection.mutable

import scala.collection.mutable._

object CF795D {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val l = sc.nextInt
    val r = sc.nextInt
    val a = new Array[Int](n)
    val b = new Array[Int](n)
    for (i <- a.indices) a(i) = sc.nextInt
    for (j <- b.indices) b(j) = sc.nextInt
    if (!a.slice(0, l-1).sameElements(b.slice(0, l-1)) ||
        !a.slice(r, n).sameElements(b.slice(r, n))) {
      println("LIE")
    } else if (!a.slice(l-1, r).sorted.sameElements(b.slice(l-1, r).sorted)) {
      println("LIE")
    } else {
      println("TRUTH")
    }
  }
}

object Main extends App {
	val Array(n, l,r) = readLine().split(" ").map(_.toInt)
	var array1 = Array.fill[Int](n+5)(0)
	var array2 = Array.fill[Int](n+5)(0)

	val s = readLine
	val a: Array[Int] = s.split(" ").map(_.toInt)
    for (i <- 0 until a.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array1(a(i)) = array1(a(i))+1
    	}
	}

	val s1 = readLine
	val a1: Array[Int] = s1.split(" ").map(_.toInt)
    for (i <- 0 until a1.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array2(a1(i)) = array2(a1(i))+1
    	}
	}
	var flag = true
	for (i <- 0 until array1.length) {
		if(array1(i)!=array2(i))
			flag = false
    }
    for (i <- 0 until a1.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		// array2(a1(i)) = array2(a1(i))+1
    	}
    	else {
    		if(a(i)!=a1(i))
    			flag = false
    	}
	}
    if(flag) print("TRUTH")
    else print("LIE")
}

object D {
    def shuffle[T](array: Array[T]): Array[T] = {
        val rnd = new java.util.Random
        for (n <- Iterator.range(array.length - 1, 0, -1)) {
            val k = rnd.nextInt(n + 1)
            val t = array(k); array(k) = array(n); array(n) = t
        }
        return array
    }

	def main(args: Array[String]) = {
		val scanner = new java.util.Scanner(System.in)
		val n, l, r = scanner.nextInt()
		var a, b = new Array[Int](n)
		for (i <- 0 to n-1) {
			a(i) = scanner.nextInt()
		}
		for (i <- 0 to n-1) {
			b(i) = scanner.nextInt()
		}
		var i = 0
		var lie = false
		for (i <- 1 to n) {
			if (a(i-1) != b(i-1) && (i < l || r < i)) {
				lie = true
			}
		}
		shuffle(a)
		scala.util.Sorting.quickSort(a)
		shuffle(b)
		scala.util.Sorting.quickSort(b)
		for (i <- 1 to n) {
			if (a(i-1) != b(i-1)) {
				lie = true
			}
		}
		if (lie) {
			println("LIE")
		} else {
			println("TRUTH")
		}
	}
}

object Main extends App {
    var Array(n,l,r) = readLine.split(" ").map(_.toInt)
    var a:Array[Int] = readLine.split(" ").map(_.toInt)
    var b:Array[Int] = readLine.split(" ").map(_.toInt)

    var lo:Int = 0
    var ro:Int = n - 1
   while(lo < n && (a(lo) equals b(lo))){
       lo = lo + 1
   }
   while(ro >= 0 && (a(ro) equals b(ro))){
       ro = ro - 1
   }
   l = l - 1
   r = r - 1
   if(lo >= l & ro <= r){
        println("TRUTH")
   }
   else{
       println("LIE")
   }

}

object tmp {
   def main(args: Array[String]) {
        val Array(n,l,r) = readLine.split(" ").map(_.toInt)
        val s1 = readLine
        val a: Array[Int] = s1.split(" ").map(_.toInt)
        val s2 = readLine
        val b: Array[Int] = s2.split(" ").map(_.toInt)
        var i = 0;
        var can = 1;
        for (i <- 0 to n-1){
            if (i < l-1 || i > r-1) {
                if (a(i) != b(i)) {
                    can = 0;
                }
            }
        }
        var l1 = Array.fill[Int](100001)(0);
        var l2 = Array.fill[Int](100001)(0);
        for (i <- l-1 to r-1){
            l1(a(i)) = l1(a(i)) + 1;
            l2(b(i)) = l2(b(i)) + 1;
        }
        for (i <- 0 to 100000){
            if (l1(i) != l2(i))
                can = 0;
        }
        if (can == 1) {
            println("TRUTH");
        } else {
            println("LIE");
        }
   }
}

object CF {
  def main(args: Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt()
    val l = sc.nextInt()-2
    val r = sc.nextInt()
    val a = Array.tabulate(n)(_ => sc.nextInt())
    val b = Array.tabulate(n)(_ => sc.nextInt())
    var fl = 1
    val i = 0
    for( i <- 0 to l){
        if(a(i) != b(i)) fl = 0
    }
    for( i <- r to n-1){
        if(a(i) != b(i)) fl = 0
    }
    if(fl > 0){
        println("TRUTH")
    }else{
        println("LIE")
    }
  }
}

object Main extends App {
	val Array(n, l,r) = readLine().split(" ").map(_.toInt)
	var array1 = Array(0)
	var array2 = Array(0)
	val s = readLine
	val a: Array[Int] = s.split(" ").map(_.toInt)
    for (i <- 0 until a.length) {
    	if(l<=i && i<=r)
	    	array1 :+= a(i)
	}

	val s1 = readLine
	val a1: Array[Int] = s1.split(" ").map(_.toInt)
    for (i <- 0 until a1.length) {
    	if(l<=i && i<=r)
	    	array2 :+= a1(i)
	}
	scala.util.Sorting.quickSort(array1)
	scala.util.Sorting.quickSort(array2)
	var flag = true
	for (i <- 0 until array1.length) {
		// println(array1(i))
		// println(array2(i))
		if(array1(i)!=array2(i))
			flag = false
    }
    // print(flag)
    if(flag) print("TRUTH")
    else print("LIE")
}

object Main extends App {
	val Array(n, l,r) = readLine().split(" ").map(_.toInt)
	var array1 = Array.fill[Int](n+5)(0)
	var array2 = Array.fill[Int](n+5)(0)
	val s = readLine
	val a: Array[Int] = s.split(" ").map(_.toInt)
    for (i <- 0 until a.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array1(a(i)) = array1(a(i))+1
    	}
	}

	val s1 = readLine
	val a1: Array[Int] = s1.split(" ").map(_.toInt)
    for (i <- 0 until a1.length) {
    	if(l-1<=i && i<=r-1){
    		// println(a(i))
    		array2(a1(i)) = array2(a1(i))+1
    	}
	}
	var flag = true
	for (i <- 0 until array1.length) {
		if(array1(i)!=array2(i))
			flag = false
    }
    if(flag) print("TRUTH")
    else print("LIE")
}