import scala.io.StdIn.{readInt,readLine}

object Main {
  def scan(h:Array[Long],i:Int):Long = {
    if(h(i)-h(i-1)!=h(i-1)-h(i-2)) h(i)
    else scan(h,i+1)
  }

  def main(args:Array[String]):Unit = {
    println {
      Iterator.continually(readInt).takeWhile(_!=0).map { n=>
        val h = readLine.split(" ").map(_.toLong)
        var diff = 0
        if( h(3)-h(2) != h(2)-h(1) || h(2)-h(1) != h(1)-h(0) || h(3)-h(2) != h(1)-h(0)) {
          if(h(1)-h(0) == h(2)-h(1)) h(3)
          else if(h(3)-h(1) == h(1)-h(0)) h(2)
          else if(h(2)-h(0) == h(3)-h(2)) h(1)
          else if(h(3)-h(2) == h(2)-h(1)) h(0)
          else throw new Exception("unexpected error")
        } else {
          scan(h,3)
        }
      }.mkString("\n")
    }
  }
}