Problem:
Score: 300 points

Problem Statement

In the Ancient Kingdom of Snuke, there was a pyramid to strengthen the authority of Takahashi, the president of AtCoder Inc.

The pyramid had center coordinates (C_X, C_Y) and height H. The altitude of coordinates (X, Y) is max(H - |X - C_X| - |Y - C_Y|, 0).

Aoki, an explorer, conducted a survey to identify the center coordinates and height of this pyramid. As a result, he obtained the following information:

C_X, C_Y was integers between 0 and 100 (inclusive), and H was an integer not less than 1.

Additionally, he obtained N pieces of information. The i-th of them is: "the altitude of point (x_i, y_i) is h_i."

This was enough to identify the center coordinates and the height of the pyramid. Find these values with the clues above.

Constraints

N is an integer between 1 and 100 (inclusive).

x_i and y_i are integers between 0 and 100 (inclusive).

h_i is an integer between 0 and 10^9 (inclusive).

The N coordinates (x_1, y_1), (x_2, y_2), (x_3, y_3), ..., (x_N, y_N) are all different.

The center coordinates and the height of the pyramid can be uniquely identified.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1 h_1
x_2 y_2 h_2
x_3 y_3 h_3
:
x_N y_N h_N

Output

Print values C_X, C_Y and H representing the center coordinates and the height of the pyramid in one line, with spaces in between.

Sample Input 1

4
2 3 5
2 1 5
1 2 5
3 2 5

Sample Output 1

2 2 6

In this case, the center coordinates and the height can be identified as (2, 2) and 6.

Sample Input 2

2
0 0 100
1 1 98

Sample Output 2

0 0 100

In this case, the center coordinates and the height can be identified as (0, 0) and 100.

Note that C_X and C_Y are known to be integers between 0 and 100.

Sample Input 3

3
99 1 191
100 1 192
99 0 192

Sample Output 3

100 0 193

In this case, the center coordinates and the height can be identified as (100, 0) and 193.

Solution in Scala (2.11.7) (judge verdict: Runtime Error)


object Main extends App {
  import scala.io.StdIn._

  val n = readLine.trim.toInt
  val info = Array.tabulate(n){_ ⇒
    val Array(x, y, h) = readLine.trim.split(' ').map(_.toInt)
    Info(x, y, h)
  }
  println(
    (0 to 100).flatMap{x ⇒ (0 to 100).map{y ⇒ Coordinate(x, y)}}.find{center ⇒
      info.map(i ⇒ inverseHeight(center, i)).let{a ⇒
        a.find{
          case Equal(_) ⇒ true
          case _ ⇒ false
        } match {
          case Some(Equal(height)) ⇒ a.forall{
            case Equal(h) ⇒ height == h
            case Lower(h) ⇒ height <= h
          }
          case _ ⇒ false
        }
        }
    }.get.let(center ⇒ s"${center.x} ${center.y} ${info.map(inverseHeight(center, _)).find(_.isInstanceOf[Equal]).let(it ⇒ if (it.isDefined) it.get else Equal(1)).asInstanceOf[Equal].height}")
  )
  def inverseHeight(center: Coordinate, info: Info): Either = {
    info match {
      case Info(x, y, 0) ⇒ Lower((center.x - x).abs + (center.y - y))
      case Info(x, y, h) ⇒ Equal(h + (center.x - x).abs + (center.y - y).abs)
    }
  }
  sealed trait Either
  case class Lower(height: Long) extends Either
  case class Equal(height: Long) extends Either
  implicit class RichInt(val value: Long){
    def abs: Long = if (value >= 0) value else -value
  }
  case class Coordinate(x: Int, y: Int)
  case class Info(x:Int, y:Int, h:Long)
  implicit class ScopeFunc[T](value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}