import scala.io.StdIn._

object Main extends App {

  val Array(n,w) = readLine().split(" ").map(_.toInt)
  val wv = Array.fill(n)(readLine().split(" ").map(_.toInt))
  def solve() = {
    rec(w, 0)
  }

  def rec(restW: Int, i: Int): Long = {
    if(i == n) 0
    else {
      if(restW >= wv(i)(0)) {
        Math.max(rec(restW, i+1), rec(restW - wv(i)(0), i+1) + wv(i)(1))
      } else rec(restW, i+1)
    }
  }

  println(solve())

}

Score : 100 points

Problem Statement

There are N items, numbered 1, 2, \ldots, N.
For each i (1 \leq i \leq N), Item i has a weight of w_i and a value of v_i.

Taro has decided to choose some of the N items and carry them home in a knapsack.
The capacity of the knapsack is W, which means that the sum of the weights of items taken must be at most W.

Find the maximum possible sum of the values of items that Taro takes home.

Constraints

All values in input are integers.

1 \leq N \leq 100

1 \leq W \leq 10^5

1 \leq w_i \leq W

1 \leq v_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N W
w_1 v_1
w_2 v_2
:
w_N v_N

Output

Print the maximum possible sum of the values of items that Taro takes home.

Sample Input 1

3 8
3 30
4 50
5 60

Sample Output 1

90

Items 1 and 3 should be taken.
Then, the sum of the weights is 3 + 5 = 8, and the sum of the values is 30 + 60 = 90.

Sample Input 2

5 5
1 1000000000
1 1000000000
1 1000000000
1 1000000000
1 1000000000

Sample Output 2

5000000000

The answer may not fit into a 32-bit integer type.

Sample Input 3

6 15
6 5
5 6
6 4
6 6
3 5
7 2

Sample Output 3

17

Items 2, 4 and 5 should be taken.
Then, the sum of the weights is 5 + 6 + 3 = 14, and the sum of the values is 6 + 6 + 5 = 17.


object Main {

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

    val N, W = sc.nextInt()
    val w, v = new Array[Int](N)
    (0 until N) foreach { i =>
      val _w, _v = sc.nextInt()
      w(i) = _w
      v(i) = _v
    }

    val dp = Array.fill(N+1, W+1)(0L)
    var i = 0
    while (i < N) {
      var j = 0
      while (j < W) {
        if (j+1-w(i) >= 0)
          dp(i+1)(j+1) =
            (dp(i)(j+1-w(i)) + v(i)) max dp(i)(j+1)
        else
          dp(i+1)(j+1) = dp(i)(j+1)
        j += 1
      }
      i += 1
    }

    println(dp(N)(W))
  }

}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


object Main extends App {

  import scala.io.StdIn._

  val Array(n, weightMax) = readLine.trim.split(' ').map(_.toInt)
  val maxMemo = Array.tabulate(weightMax + 1){ _ ⇒ Long.MinValue}.also{arr ⇒ arr(0) = 0L}
  var stack = List(0)
  for (_ ← 0 until n){
    val Array(w, v) = readLine.trim.split(' ').map(_.toInt)
    for (prev ← stack.filter(p ⇒ p + w <= weightMax)) {
      if (maxMemo(prev + w) == Long.MinValue){
        stack ::= prev + w
      }
      if (maxMemo(prev + w) < maxMemo(prev) + v) {
        maxMemo(prev + w) = maxMemo(prev) + v
      }
    }
  }
  println(maxMemo.max)
  case class Goods(weights: Long, value: Long)
  implicit class Extend[T](value: T){
    def also(func: T ⇒ Unit): T = {func(value); value}
    def let[A](func: T ⇒ A): A = func(value)
  }
}


object Main {

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

    val S, T = sc.nextLine().toCharArray
    val SL = S.length
    val TL = T.length

    // dp[i][j] := Sのi番目までとTのj番目までの文字列の最長共通部分列の長さ
    // S[i] == T[j] => dp[i][j] = dp[i-1][j-1] + 1
    // i番目とj番目の文字列が異なる場合,
    // S[i] != T[j] => dp[i][j] = max(dp[i][j-1], dp[i-1][j])
    // dp[0][0] = 0
    val dp = Array.fill(SL+1, TL+1)(0)
    // では文字列情報はどのように渡すか? 更新が発生している時, 文字列が結合されている
    // 下から持ち上げられてきたとき, 文字列情報がそのまま持ち上げられている
    // なので, 文字列リテラルを保持しておく(インスタンス共有されるから足りるやろ)
    // ↑ 文字列結合がネックになってTLE
    // 移動情報を使って辿ることにする.
    // その場の文字を使った場合, c[i][j] = 0
    // [i][j-1]の文字を使った場合, c[i][j] = 1
    // [i-1][j]の文字を使った場合, c[i][j] = 2 と記録して c[SL][TL]から辿る
    val c = Array.fill(SL+1, TL+1)(-1)
    for {
      i <- 0 until SL
      j <- 0 until TL
    } if (S(i) == T(j)) {
      dp(i+1)(j+1) = dp(i)(j) + 1
      c(i+1)(j+1) = 0
    } else if (dp(i+1)(j) > dp(i)(j+1)) {
      dp(i+1)(j+1) = dp(i+1)(j)
      c(i+1)(j+1) = 1
    } else {
      dp(i+1)(j+1) = dp(i)(j+1)
      c(i+1)(j+1) = 2
    }

    // 辿る
    def printC(S: Array[Char],
               dp: Array[Array[Int]], c: Array[Array[Int]]): String = {
      def loop(i: Int, j: Int, str: List[Char]): List[Char] =
        if (!(i == 0 && j == 0)) {
          c(i)(j) match {
            case 0 => loop(i-1, j-1, S(i-1) :: str)
            case 1 => loop(i,   j-1, str)
            case 2 => loop(i-1, j,   str)
            case _ => str
          }
        } else str
      loop(SL, TL, Nil).mkString
    }

    println(printC(S, dp, c))
  }

}

Score : 100 points

Problem Statement

You are given strings s and t.
Find one longest string that is a subsequence of both s and t.

Notes

A subsequence of a string x is the string obtained by removing zero or more characters from x and concatenating the remaining characters without changing the order.

Constraints

s and t are strings consisting of lowercase English letters.

1 \leq |s|, |t| \leq 3000

Input

Input is given from Standard Input in the following format:

s
t

Output

Print one longest string that is a subsequence of both s and t.
If there are multiple such strings, any of them will be accepted.

Sample Input 1

axyb
abyxb

Sample Output 1

axb

The answer is axb or ayb; either will be accepted.

Sample Input 2

aa
xayaz

Sample Output 2

aa

Sample Input 3

a
z

Sample Output 3

The answer is (an empty string).

Sample Input 4

abracadabra
avadakedavra

Sample Output 4

aaadara


object Main extends App {
  val s = io.StdIn.readLine()
  val t = io.StdIn.readLine()
  val (m, n) = (s.length, t.length)
  val dp = Array.ofDim[Int](m+1, n+1)

  for (i <- 0 until m)
    for (j <- 0 until n) {
      if (s(i) == t(j) && dp(i+1)(j+1) < dp(i)(j) + 1) dp(i+1)(j+1) = dp(i)(j) + 1
      if (dp(i+1)(j+1) < dp(i+1)(j)) dp(i+1)(j+1) = dp(i+1)(j)
      if (dp(i+1)(j+1) < dp(i)(j+1)) dp(i+1)(j+1) = dp(i)(j+1)
    }

  var (i, j) = (m, n)
  val buf = StringBuilder.newBuilder
  while (i > 0 && j > 0) {
    if (dp(i)(j) == dp(i)(j-1)) {j -= 1}
    else if (dp(i)(j) == dp(i-1)(j)) {i -= 1}
    else {i-= 1; j -= 1; buf += s(i)}
  }

  println(buf.reverse)
}


object Main {

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

    val S = sc.nextLine()
    val T = sc.nextLine()

    val dp = Array.fill(S.length+1, T.length+1)(0)
    val dpi = Array.fill(S.length+1, T.length+1)(-1)
    val dpj = Array.fill(S.length+1, T.length+1)(-1)

    var i = 0
    while (i < S.length) {
      var j = 0
      while (j < T.length) {
        if (S(i) == T(j)) {
          if ((dp(i)(j) + 1) > dp(i + 1)(j + 1)) {
            dp(i + 1)(j + 1) = dp(i)(j) + 1
            dpi(i + 1)(j + 1) = i
            dpj(i + 1)(j + 1) = j
          }
        }
        if (dp(i + 1)(j) > dp(i + 1)(j + 1)) {
          dp(i + 1)(j + 1) = dp(i + 1)(j)
          dpi(i + 1)(j + 1) = dpi(i + 1)(j)
          dpj(i + 1)(j + 1) = dpj(i + 1)(j)
        }
        if (dp(i)(j + 1) > dp(i + 1)(j + 1)) {
          dp(i + 1)(j + 1) = dp(i)(j + 1)
          dpi(i + 1)(j + 1) = dpi(i)(j + 1)
          dpj(i + 1)(j + 1) = dpj(i)(j + 1)
        }
        j += 1
      }
      i += 1
    }

    i = dpi(S.length)(T.length)
    var j = dpj(S.length)(T.length)
    var bldr = new StringBuilder
    while (i >= 0 || j >= 0) {
      if (S(i) == T(j))
        bldr.append(S(i))
      val _i = dpi(i)(j)
      val _j = dpj(i)(j)
      i = _i
      j = _j
    }
    println(bldr.result().reverse)
  }

}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S, T = ns()

    val dp = Array.ofDim[(List[Char], Int)](S.length + 1, T.length + 1)

    REP(S.length + 1) { i =>
      REP(T.length + 1) { j =>
        if (i == 0 || j == 0) dp(i)(j) = (Nil, 0)
        else if (S(i - 1) == T(j - 1)) {
          val (chars, cnt) = dp(i - 1)(j - 1)
          dp(i)(j) = (S(i - 1) :: chars, cnt + 1)
        } else {
          val a = dp(i)(j - 1)
          val b = dp(i - 1)(j)
          val res = if (a._2 > b._2) a else b
          assert(res != null)
          dp(i)(j) = res
        }
      }
    }

    val (ans, _) = dp(S.length)(T.length)
    out.println(ans.reverse.mkString)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S, T = ns()

    val dp = Array.fill[List[Char]](S.length + 1, T.length + 1)(null)
    def f(i: Int, j: Int): List[Char] = {
      if (i == 0 || j == 0) Nil
      else {
        if (dp(i)(j) == null) {
          val res = if (S(i - 1) == T(j - 1)) {
            S(i - 1) :: f(i - 1, j - 1)
          } else {
            val a = f(i - 1, j)
            val b = f(i, j - 1)
            if (a.length > b.length) a else b
          }
          dp(i)(j) = res
        }
        dp(i)(j)
      }
    }

    val ans = f(S.length, T.length)
    out.println(ans.reverse.mkString)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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


object Main extends App {
    var l: String = readLine
    var line = l.toInt

      if(line == 25) {
    println("Christmas")
    }
  if(line == 24) {
    println("Christmas Eve")
    }
  if(line == 23) {
    println("Christmas Eve Eve")
    }
  if(line == 22) {
    println("Christmas Eve Eve Eve")
    }

}

Score : 100 points

Problem Statement

In some other world, today is December D-th.

Write a program that prints Christmas if D = 25, Christmas Eve if D = 24, Christmas Eve Eve if D = 23 and Christmas Eve Eve Eve if D = 22.

Constraints

22 \leq D \leq 25

D is an integer.

Input

Input is given from Standard Input in the following format:

D

Output

Print the specified string (case-sensitive).

Sample Input 1

25

Sample Output 1

Christmas

Sample Input 2

22

Sample Output 2

Christmas Eve Eve Eve

Be sure to print spaces between the words.


object Main extends App {
  val in = new java.util.Scanner(System.in)
  val N = in.nextInt
  val X = in.nextLong

  val ls = (1 to N).scanLeft(1L)((z, i) => z * 2 + 3).toArray
  val ps = (1 to N).scanLeft(1L)((z, i) => z * 2 + 1).toArray

  def count(l: Int, eat: Long): Long = {
    if (l == 0) (if (eat <= 0) 0 else 1)
    else if (eat <= 1 + ls(l - 1)) count(l - 1, eat - 1)
    else ps(l - 1) + 1 + count(l - 1, eat - ls(l - 1) - 2)
  }

  println(count(N, X))
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val D = Integer.parseInt(sc.next)

    println(
      if (D == 25) "Christmas"
      else if (D == 24) "Christmas Eve"
      else if (D == 23) "Christmas Eve Eve"
      else "Christmas Eve Eve Eve"
    )
  }
}


import java.io.{PrintWriter, _}
import java.util
import java.util._

import scala.collection.mutable

object Main {
  def main(args: Array[String]): Unit = {
    val inputStream = System.in
    val outputStream = System.out
    val in = new InputReader(inputStream)
    val out = new PrintWriter(outputStream)
    val solver = new Task
    solver.solve(1, in, out)
    out.close()
  }

  def ?(item: Boolean, first: Object, second: Object): Object = if (item) first else second

  class Task {
    def solve(testNumber: Int, in: InputReader, out: PrintWriter): Unit = {
      val n = in.nextInt
      val map = mutable.HashMap(25 -> "Christmas", 24 -> "Christmas Eve", 23 -> "Christmas Eve Eve",
        22 -> "Christmas Eve Eve Eve")
      out.println(map(n))
    }
  }

  class InputReader(val stream: InputStream) extends AutoCloseable {
    //reader = new BufferedReader(new FileReader(stream), 32768);
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer = new 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 nextLine: String = {
      try
        return reader.readLine
      catch {
        case e: IOException =>
          e.printStackTrace()
      }
      ""
    }

    def nextInt: Int = next.toInt

    def nextLong: Long = next.toLong

    override def close(): Unit = {
    }
  }

}


import scala.io.StdIn.readLine

object Main{
  def main(args: Array[String]): Unit = {
    val d:Int=readLine().toInt
    println("Christmas"+" Eve"*(25-d))
  }
}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val N = input.nextLine().toInt
      println(N match {
        case 22 => "Christmas Eve Eve Eve"
        case 23 => "Christmas Eve Eve"
        case 24 => "Christmas Eve"
        case _ => "Christmas"
      })
    }

  }

}


import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  def next(): String = sc.next()
  def nextInt(): Int = next().toInt
  def nextLong(): Long = next().toLong

  def task(): Unit = {
    val d = nextInt()
    val ans = (Seq("Christmas") ++ Seq.fill(25 - d)("Eve")).mkString(" ")
    println(ans)
  }

  task()
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer
import java.util.Calendar

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close() = reader.close()
}

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    println(sc.nextInt() match {
      case 25 => "Christmas"
      case 24 => "Christmas Eve"
      case 23 => "Christmas Eve Eve"
      case 22 => "Christmas Eve Eve Eve"
    })
  }

  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def calc(N: Long, R: Long, M: Long): Double = {
    math.sqrt(R * R - (R * 2 * ((M * 1.0 / N) - 0.5)) * (R * 2 * ((M * 1.0 / N) - 0.5))) * 2
  }

  def recursive(S: String): Long = {
    if (S.length <= 1) (0) else {
      if (S.charAt(0) != S.charAt(1)) (recursive(S.tail.tail) + 1L) else (recursive(S.tail))
    }
  }

  def check(s: String): Boolean = {
    if (s == "0") (true) else (s(0) != '0' && 0 <= s.toInt && s.toInt <= 255)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


object Main extends App {
  val in = io.Source.stdin.getLines.toIndexedSeq.head.toInt
  //println(in)
  if(in==25)
  	println("Christmas")
  else if(in==24)
    	println("Christmas Eve")
  else if(in==23)
    	println("Christmas Eve Eve")
          else if(in==22)
            	println("Christmas Eve Eve Eve")
  else
            	println("")
}


object Main extends App {

  import scala.io.StdIn._
  import scala.math._

  println(
    readLine.trim.toInt match {
      case 22 ⇒ "Christmas Eve Eve Eve"
      case 23 ⇒ "Christmas Eve Eve"
      case 24 ⇒ "Christmas Eve"
      case 25 ⇒ "Christmas"
      case _ ⇒ ???
    }
  )
  implicit class Extenion[T](val value :T){
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
    def let[R](func: T ⇒ R): R = func(value)
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val D = ni()
    val ans = D match {
      case 22 => "Christmas Eve Eve Eve"
      case 23 => "Christmas Eve Eve"
      case 24 => "Christmas Eve"
      case 25 => "Christmas"
    }

    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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

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


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n = sc.nextInt()
    val points = Array.fill(n) {
      val x, y, h = sc.nextInt()
      (x, y, h)
    }

    var xx = Array[Int]()
    var yy = Array[Int]()
    var hh = Array[Int]()

    for {
      cx <- 0 to 100
      cy <- 0 to 100
    } {
      val p =
        points
          .map {
            case (x, y, h) =>
              h match {
                case 0 => None
                case _ => Option(h + math.abs(x - cx) + math.abs(y - cy))
              }
          }
          .filter(_.isDefined)
          .map(_.get)
      if (p.foldLeft((true, p.head)) { case ((b, i), n) => (b && i == n, n) }
            ._1) {
        xx = xx :+ cx
        yy = yy :+ cy
        hh = hh :+ p.head
      }

    }

    for (i <- xx.indices) {
      if (points.forall {
            case (x, y, h) =>
              h == math.max(
                0,
                hh(i) - math.abs(x - xx(i)) - math.abs(y - yy(i))
              )
          }) println(s"${xx(i)} ${yy(i)} ${hh(i)}")

    }

  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}

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.


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)

    val n = sc.nextInt()
    val points = Array.fill(n) {
      val x, y, h = sc.nextInt()
      (x, y, h)
    }

    var xx = 0
    var yy = 0
    var hh = 0

    for {
      cx <- 0 to 100
      cy <- 0 to 100
    } {
      val p =
        points
          .map {
            case (x, y, h) =>
              h match {
                case 0 => None
                case _ => Option(h + math.abs(x - cx) + math.abs(y - cy))
              }
          }
          .filter(_.isDefined)
          .map(_.get)
      if (p.foldLeft((true, p.head)) { case ((b, i), n) => (b && i == n, n) }
            ._1) {
        xx = cx
        yy = cy
        hh = p.head
      }

    }

    println(s"$xx $yy $hh")
  }

  def debug(args: Any*): Unit = {
    Console.err.println(args.mkString(" "))
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = new Array[Long](n)
    val ys = new Array[Long](n)
    val hs = new Array[Long](n)
    for (i <- 0 until n) {
      xs(i) = sc.nextLong
      ys(i) = sc.nextLong
      hs(i) = sc.nextLong
    }

    var result = (0, 0, 0L)
    for (x <- 0 to 100) {
      for (y <- 0 to 100) {
        val ret = check(x, y, n, xs, ys, hs)
        if (ret._1) {
          println(x + " " + y + " " + ret._2)
          return
        }
      }
    }

  }

  private def check(x: Int, y: Int, n: Int, xs: Array[Long], ys: Array[Long], hs: Array[Long]): (Boolean, Long) = {
    var index = 0
    val notZeroIndex: Int = hs.indexWhere(h => h != 0L)
    val H = hs(notZeroIndex) + ((x - xs(notZeroIndex)).abs + (y - ys(notZeroIndex)).abs)
    while (index < n) {
      val tmpHeight = math.max((H - (((x - xs(index)).abs + (y - ys(index)).abs))), 0) // ここの条件読み間違えてたかも。。
      if (tmpHeight != hs(index)) {
        return (false, -1)
      }
      index += 1
    }

    (true, H)
  }

}


object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = new Array[Long](n)
    val ys = new Array[Long](n)
    val hs = new Array[Long](n)
    for (i <- 0 until n) {
      xs(i) = sc.nextLong
      ys(i) = sc.nextLong
      hs(i) = sc.nextLong
    }

    var result = (0, 0, 0L)
    for (x <- 0 to 100) {
      for (y <- 0 to 100) {
        val ret = check(x, y, n, xs, ys, hs)
        if (ret._1) {
          println(x + " " + y + " " + ret._2)
          return
        }
      }
    }

  }

  private def check(x: Int, y: Int, n: Int, xs: Array[Long], ys: Array[Long], hs: Array[Long]): (Boolean, Long) = {
    var index = 0
    val notZeroIndex: Int = hs.indexWhere(h => h != 0L) match {
      case -1 => 0
      case i => i
    }

    val H = hs(notZeroIndex) + ((x - xs(notZeroIndex)).abs + (y - ys(notZeroIndex)).abs)
    if (H < 1) return (false, -1)

    while (index < n) {
      val tmpHeight = math.max((H - (((x - xs(index)).abs + (y - ys(index)).abs))).abs, 0)
      if (tmpHeight != hs(index)) {
        return (false, -1)
      }
      index += 1
    }

    (true, H)
  }

}


object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = new Array[Long](n)
    val ys = new Array[Long](n)
    val hs = new Array[Long](n)
    for (i <- 0 until n) {
      xs(i) = sc.nextLong
      ys(i) = sc.nextLong
      hs(i) = sc.nextLong
    }

    var result = (0, 0, 0L)
    for (x <- 0 to 100) {
      for (y <- 0 to 100) {
        val ret = check(x, y, n, xs, ys, hs)
        if (ret._1) {
          println(x + " " + y + " " + ret._2)
          return
        }
      }
    }

  }

  private def check(x: Int, y: Int, n: Int, xs: Array[Long], ys: Array[Long], hs: Array[Long]): (Boolean, Long) = {
    var index = 0
    val notZeroIndex: Int = hs.indexWhere(h => h != 0L)
    val H = hs(notZeroIndex) + ((x - xs(notZeroIndex)).abs + (y - ys(notZeroIndex)).abs)
    if (H < 1) return (false, -1)

    while (index < n) {
      val tmpHeight = math.max((H - (((x - xs(index)).abs + (y - ys(index)).abs))).abs, 0)
      if (tmpHeight != hs(index)) {
        return (false, -1)
      }
      index += 1
    }

    (true, H)
  }

}


object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val xs = new Array[Long](n)
    val ys = new Array[Long](n)
    val hs = new Array[Long](n)
    for (i <- 0 until n) {
      xs(i) = sc.nextLong
      ys(i) = sc.nextLong
      hs(i) = sc.nextLong
    }

    var result = (0, 0, 0L)
    for (x <- 0 to 100) {
      for (y <- 0 to 100) {
        val ret = check(x, y, n, xs, ys, hs)
        if (ret._1) {
          println(x + " " + y + " " + ret._2)
          return
        }
      }
    }

  }

  private def check(x: Int, y: Int, n: Int, xs: Array[Long], ys: Array[Long], hs: Array[Long]): (Boolean, Long) = {
    var index = 0
    val notZeroIndex: Int = hs.indexWhere(h => h != 0L)
    val H = hs(notZeroIndex) + ((x - xs(notZeroIndex)).abs + (y - ys(notZeroIndex)).abs)
    while (index < n) {
      val tmpHeight = math.max((H - (((x - xs(index)).abs + (y - ys(index)).abs))).abs, 0)
      if (tmpHeight != hs(index)) {
        return (false, -1)
      }
      index += 1
    }

    (true, H)
  }

}


object Main {

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

    val N = sc.nextInt()
    val X = new Array[Int](N)
    val Y = new Array[Int](N)
    val H = new Array[Int](N)

    (0 until N) foreach { i =>
      val x, y, h = sc.nextInt()
      X(i) = x
      Y(i) = y
      H(i) = h
    }

    val valid = (0 until N) filter (i => H(i) >= 1)

    def solve(): Option[(Int, Int, Int)] = {
      var px = 0
      while (px <= 100) {
        var py = 0
        while (py <= 100) {
          var i = 0
          val candidates = valid. map { i =>
            H(i) + Math.abs(X(i) - px) + Math.abs(Y(i) - py)
          }
          if (candidates.forall(_ == candidates.head))
            return Some(px, py, candidates.head)
          py += 1
        }
        px += 1
      }
      None
    }

    solve() map (r => s"${r._1} ${r._2} ${r._3}") foreach println
  }

}


import scala.math._
object Main {
  def main(args:Array[String]):Unit={
    val N = readInt
    var hP = 0
    var x:Array[Int] = Array()
    var y:Array[Int] = Array()
    var h:Array[Int] = Array()
    for(i <- 0 until N){
      val tmp = readLine.split(" ").map(x => x.toInt)
      x = x:+tmp(0)
      y = y:+tmp(1)
      h = h:+tmp(2)
      if(tmp(2)>0) hP = i
    }
    var flag = true
    for(i <- 0 until N if flag){
      var H = abs(x(i)-x(hP))+abs(y(i)-y(hP)) + h(hP)
      for(a <- 0 until 100 if flag){
        for(b <- 0 until 100 if flag){
          var HH = H-abs(x(i)-a)-abs(y(i)-b)
          HH = max(HH,0)
          if(HH==h(N)) flag = false

          if(flag) println(a+" "+b+" "+HH)
        }
      }
    }

  }
}


object Main {
  println( (new java.util.Scanner(System.in).nextFloat()/111).ceil.toInt*111 )
}


object Main extends App {
	import scala.math._
	val N = scala.io.StdIn.readInt
	val a = new Array[(Int, Int, Int)](N)

	for(i<-0 until N){
		val Array(t1, t2, t3) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
		a(i) = (t1, t2, t3)
	}

	for(x <- 0 to 100){
		for(y <- 0 to 100){
			val k = a.map{case (t1, t2, t3) => abs(t1 - x) + abs(t2 - y) + t3}.toSet
			if(k.size == 1){
				println(x + " " + y + " " + k.head)
			}
		}
	}
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close() = reader.close()
}

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(sc.nextInt())((sc.nextLong(), sc.nextLong(), sc.nextLong()))
    for {
      x <- (0L to 100L)
      y <- (0L to 100L)
    } {
      val ok = A.filter(a => a._3 != 0).head
      val h = math.abs(ok._1 - x) + math.abs(ok._2 - y) + ok._3
      if (A.filter(a => !(math.abs(a._1 - x) + math.abs(a._2 - y) + a._3 == h || (math.abs(a._1 - x) + math.abs(a._2 - y) + a._3 > h && a._3 == 0))).size == 0) {
        println(x + " " + y + " " + h)
      }
    }
  }

  def calc(N: Long, R: Long, M: Long): Double = {
    math.sqrt(R * R - (R * 2 * ((M * 1.0 / N) - 0.5)) * (R * 2 * ((M * 1.0 / N) - 0.5))) * 2
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    0
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close() = reader.close()
}

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(sc.nextInt())((sc.nextLong(), sc.nextLong(), sc.nextLong()))
    for {
      x <- (0L to 100L)
      y <- (0L to 100L)
    } {
      val ok = A.filter(a => a._3 != 0).head: (Long, Long, Long)
      val h = math.abs(ok._1 - x) + math.abs(ok._2 - y) + ok._3
      if (A.filter(a => math.abs(a._1 - x) + math.abs(a._2 - y) + a._3 < h).size == 0) {
        println(x + " " + y + " " + h)
      }
    }
  }

  def calc(N: Long, R: Long, M: Long): Double = {
    math.sqrt(R * R - (R * 2 * ((M * 1.0 / N) - 0.5)) * (R * 2 * ((M * 1.0 / N) - 0.5))) * 2
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    0
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close() = reader.close()
}

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(sc.nextInt())((sc.nextLong(), sc.nextLong(), sc.nextLong())).filter(a => a._3 != 0)
    for {
      x <- (0L to 100L)
      y <- (0L to 100L)
    } {
      val S = A.map(a => math.abs(x - a._1) + math.abs(y - a._2) + a._3).groupBy(i => i)
      if (
        S.size == 1 && S.head._1 > 0
      ) {
        println(x + " " + y + " " + S.head._1)
      }
    }
  }

  def calc(N: Long, R: Long, M: Long): Double = {
    math.sqrt(R * R - (R * 2 * ((M * 1.0 / N) - 0.5)) * (R * 2 * ((M * 1.0 / N) - 0.5))) * 2
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    0
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close() = reader.close()
}

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(sc.nextInt())((sc.nextLong(), sc.nextLong(), sc.nextLong()))
    for {
      x <- (0L to 100L)
      y <- (0L to 100L)
    } {
      val S = A.map(a => math.abs(x - a._1) + math.abs(y - a._2) + a._3).groupBy(i => i)
      if (
        S.size == 1
      ) {
        println(x + " " + y + " " + S.head._1)
      }
    }
  }

  def calc(N: Long, R: Long, M: Long): Double = {
    math.sqrt(R * R - (R * 2 * ((M * 1.0 / N) - 0.5)) * (R * 2 * ((M * 1.0 / N) - 0.5))) * 2
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    0
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


import scala.io.StdIn._
object Main extends App {
  readLine.toInt
  val Array(x1, y1, h1) = readLine.split(" ").map{_.toInt}

  val (cx, cy, ch) = eliminate(for {
    xi <- 0 to 100
    yi <- 0 to 100
    hi = h1 + Math.abs(x1 - xi) + Math.abs(y1 - yi)
  } yield (xi, yi, hi))

  println(s"$cx $cy $ch")

  def eliminate(candidates: Seq[(Int, Int, Int)]): (Int, Int, Int) = {
    if (candidates.tail.isEmpty) candidates.head
    else {
      val Array(x, y, h) = readLine.split(" ").map{_.toInt}
      eliminate(candidates.filter(c => h + Math.abs(c._1 - x) + Math.abs(c._2 - y) == c._3))
    }
  }
}


import scala.io.StdIn
object Main extends App {
  val Seq(n, t) : Seq[Int] = StdIn.readLine.split(" ").map(_.toInt)
  val cts = Range(0, n)
    .map(_ => (StdIn.readLine.split(" ").map(_.toInt)))
    .map(s => (s(0), s(1)))
  println(cts.sorted.find(_._2 <= t).map(_._1.toString).getOrElse("TLE"))
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val X, Y, H = Array.ofDim[Int](N)
    rep(N) { i =>
      X(i) = ni()
      Y(i) = ni()
      H(i) = ni()
    }

    sealed trait Height
    case class Range(to: Int) extends Height // inclusive
    case class Just(num: Int) extends Height
    def intersect(h1: Height, h2: Height): Option[Height] = {
      (h1, h2) match {
        case (Just(a), Just(b)) if a == b => Some(Just(a))
        case (Range(a), Range(b)) => Some(Range(min(a, b)))
        case (Just(a), Range(b)) if a <= b => Some(Just(a))
        case (Range(b), Just(a)) if a <= b => Some(Just(a))
        case _ => None
      }
    }

    def calcH(x: Int, y: Int): Option[Int] = {
      var height: Height = Range(1e9.toInt + 200)

      rep(N) { i =>
        val d = abs(X(i) - x) + abs(Y(i) - y)
        val cur = if (H(i) == 0){
          Range(d)
        } else {
          Just(H(i) + d)
        }

        intersect(height, cur) match {
          case Some(next) => height = next
          case None => return None
        }
      }

      height match {
        case Just(a) => Some(a)
        case Range(a) if a > 0 => Some(1)
        case Range(a) if a == 0 => None
      }
    }

    rep(101) { x =>
      rep(101) { y =>
        calcH(x, y) match {
          case None =>
          case Some(h) =>
            out.println(s"$x $y $h")
            return
        }
      }
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val X, Y, H = Array.ofDim[Int](N)
    rep(N) { i =>
      X(i) = ni()
      Y(i) = ni()
      H(i) = ni()
    }

    if (H forall (_ == 0)) {
      rep(101) { x =>
        rep(101) { y =>
          val b = 0 until N forall { i =>
            X(i) != x || Y(i) != y
          }
          if (b) {
            out.println(s"$x $y 1")
            return
          }
        }
      }
    }

    sealed trait Height
    case class Range(to: Int) extends Height // inclusive
    case class Just(num: Int) extends Height
    def intersect(h1: Height, h2: Height): Option[Height] = {
      (h1, h2) match {
        case (Just(a), Just(b)) if a == b => Some(Just(a))
        case (Range(a), Range(b)) => Some(Range(min(a, b)))
        case (Just(a), Range(b)) if a <= b => Some(Just(a))
        case (Range(b), Just(a)) if a <= b => Some(Just(a))
        case _ => None
      }
    }

    def calcH(x: Int, y: Int): Option[Int] = {
      var height: Height = Range(1e9.toInt)

      rep(N) { i =>
        val d = abs(X(i) - x) + abs(Y(i) - y)
        val cur = if (H(i) == 0){
          Range(d)
        } else {
          Just(H(i) + d)
        }

        intersect(height, cur) match {
          case Some(next) => height = next
          case None => return None
        }
      }

      height match {
        case Just(a) => Some(a)
        case Range(a) if a > 0 => Some(1)
        case Range(a) if a == 0 => None
      }
    }

    rep(101) { x =>
      rep(101) { y =>
        calcH(x, y) match {
          case None =>
          case Some(h) =>
            out.println(s"$x $y $h")
            return
        }
      }
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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


import java.util.Scanner

import scala.collection.mutable

object Main extends App {
  val sc = new Scanner(System.in)
  val n = sc.nextInt
  val xyhs = Seq.fill(n)((sc.nextInt, sc.nextInt, sc.nextInt))
  val h_xys = mutable.Map.empty[(Int, Int), Int]
  xyhs.foreach { case (x, y, h) =>
    for {
      xx <- 0 to 100
      yy <- 0 to 100
    } {
      val hh = Math.abs(x - xx) + Math.abs(y - yy) + h
      val already = h_xys.get((xx, yy))
      if (already.isEmpty) {
        h_xys.update((xx, yy), hh)
      } else if (already.exists(_ != hh)) {
        h_xys.update((xx, yy), -1)
      }
    }
  }
  val center = h_xys.maxBy { case (_, h) => h }
  println(s"${center._1._1} ${center._1._2} ${center._2}")
}


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)}}.flatMap { center ⇒
      val suspect = info.map(inverseHeight(center, _))
      suspect.find{
        case Equal(_) ⇒ true
        case _ ⇒ false
      } match {
        case Some(Equal(h)) ⇒ if (suspect.forall{
          case Equal(height) ⇒ h == height
          case Lower(height) ⇒ h <= height
        }) Some(center, h) else None
        case _ ⇒ if(suspect.forall{
          case Equal(height) ⇒ height == 1
          case Lower(height) ⇒ 1 <= height
        }) Some(center, 1) else None
      }
    }.head.let{case (Coordinate(x, y), h) ⇒ s"$x $y $h"}
  )
  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
    }
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val X, Y, H = Array.ofDim[Int](N)
    rep(N) { i =>
      X(i) = ni()
      Y(i) = ni()
      H(i) = ni()
    }

    sealed trait Height
    case class Range(to: Int) extends Height // inclusive
    case class Just(num: Int) extends Height
    def intersect(h1: Height, h2: Height): Option[Height] = {
      (h1, h2) match {
        case (Just(a), Just(b)) if a == b => Some(Just(a))
        case (Range(a), Range(b)) => Some(Range(min(a, b)))
        case (Just(a), Range(b)) if a <= b => Some(Just(a))
        case (Range(b), Just(a)) if a <= b => Some(Just(a))
        case _ => None
      }
    }

    def calcH(x: Int, y: Int): Option[Int] = {
      var height: Height = Range(1e9.toInt)

      rep(N) { i =>
        val d = abs(X(i) - x) + abs(Y(i) - y)
        val cur = if (H(i) == 0){
          Range(d)
        } else {
          Just(H(i) + d)
        }

        intersect(height, cur) match {
          case Some(next) => height = next
          case None => return None
        }
      }

      height match {
        case Just(a) => Some(a)
        case Range(a) if a > 0 => Some(1)
        case Range(a) if a == 0 => None
      }
    }

    rep(101) { x =>
      rep(101) { y =>
        calcH(x, y) match {
          case None =>
          case Some(h) =>
            out.println(s"$x $y $h")
            return
        }
      }
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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


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 _ ⇒ a.forall{
            case Lower(h) ⇒ 1 <= 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
    }
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val X, Y, H = Array.ofDim[Int](N)
    rep(N) { i =>
      X(i) = ni()
      Y(i) = ni()
      H(i) = ni()
    }

    sealed trait Height
    case class Range(to: Int) extends Height // inclusive
    case class Just(num: Int) extends Height
    def intersect(h1: Height, h2: Height): Option[Height] = {
      (h1, h2) match {
        case (Just(a), Just(b)) if a == b => Some(Just(a))
        case (Range(a), Range(b)) => Some(Range(min(a, b)))
        case (Just(a), Range(b)) if a <= b => Some(Just(a))
        case (Range(b), Just(a)) if a <= b => Some(Just(a))
        case _ => None
      }
    }

    def calcH(x: Int, y: Int): Option[Int] = {
      var height: Height = Range(1e9.toInt)

      rep(N) { i =>
        val d = abs(X(i) - x) + abs(Y(i) - y)
        val cur = if (H(i) == 0){
          Range(d)
        } else {
          Just(H(i) + d)
        }

        intersect(height, cur) match {
          case Some(next) => height = next
          case None => return None
        }
      }

      Some(height match {
        case Just(a) => a
        case Range(a) => a
      })
    }

    rep(101) { x =>
      rep(101) { y =>
        calcH(x, y) match {
          case None =>
          case Some(h) =>
            out.println(s"$x $y $h")
            return
        }
      }
    }
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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


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


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


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.flatMap(i ⇒ inverseHeight(center, i)).let(a ⇒ if (a.nonEmpty) a.forall(_ == a.head) else false)
    }.get.let(center ⇒ s"${center.x} ${center.y} ${info.flatMap(inverseHeight(center, _)).head}")
  )
  def inverseHeight(center: Coordinate, info: Info): Option[Long] = {
    ((center.x - info.x).abs + (center.y - info.y).abs + info.h).let(h ⇒ if (h > 0) Some(h) else None)
  }
  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
    }
  }
}


import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(a, b, c) = in.readLine().split("\\s+").map(_.toInt)

    out.println(
      List(a, b, c).max * 10 + List(a, b, c).min + List(a, b, c).sorted.tail.head
    )

    out.flush()
  }
}

Score : 100 points

Problem Statement

You have decided to give an allowance to your child depending on the outcome of the game that he will play now.

The game is played as follows:

There are three "integer panels", each with a digit between 1 and 9 (inclusive) printed on it, and one "operator panel" with a + printed on it.

The player should construct a formula of the form X + Y, by arranging the four panels from left to right. (The operator panel should not be placed at either end of the formula.)

Then, the amount of the allowance will be equal to the resulting value of the formula.

Given the values A, B and C printed on the integer panels used in the game, find the maximum possible amount of the allowance.

Constraints

All values in input are integers.

1 \leq A, B, C \leq 9

Input

Input is given from Standard Input in the following format:

A B C

Output

Print the maximum possible amount of the allowance.

Sample Input 1

1 5 2

Sample Output 1

53

The amount of the allowance will be 53 when the panels are arranged as 52+1, and this is the maximum possible amount.

Sample Input 2

9 9 9

Sample Output 2

108

Sample Input 3

6 6 7

Sample Output 3

82


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val l = List.fill(3)(sc.nextInt)
//  val a, b, c = sc.nextInt

  val sorted = l.sorted
  val ans = sorted.last * 10 + sorted(1) + sorted(0)

  println(ans)
}


object Main extends App {
    val Array(a,b,c) = scala.io.StdIn.readLine().split("\\s").map(_.toInt)
    println(List(a*10+b+c,a+b*10+2).max)
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val sortedNumbers = sc.nextLine.split(" ").map(_.toInt).sorted.reverse
    println((sortedNumbers.head.toString + sortedNumbers(1)).toInt + sortedNumbers(2))
  }

}


object Main extends App {
  val line1 = io.StdIn.readLine.split(' ').map(_.toInt).sorted

  val out = line1.last*10 + line1.init.sum

  println(out)
}


object Main extends App {
  val line1 = io.StdIn.readLine.split(' ').map(_.toInt)
  val A = line1(0)
  val B = line1(1)
  val C = line1(2)

  val out = math.max(10*A+B+C,A+10*B+C)

  println(out)
}


import java.util._

object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt
    val b = sc.nextInt
    val c = sc.nextInt
    val list = Array(a, b, c)
    val max = list.max
    var ans = max * 9
    for(v <- list) {
      ans += v
    }
    println(ans)
  }
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

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

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val A, B, C = ni()
    val ms = max(max(A, B), C)
    val ans = ms * 10 + A + B + C - ms
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

    def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

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

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


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val d = Vector.fill(3)(sc.nextInt).sorted.reverse
  println(10 * d(0) + d(1) + d(2))
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

  def this(reader: Reader) = this(new BufferedReader(reader))

  def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

  def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

  def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

  def this(str: String) = this(new StringReader(str))

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

  def nextBoolean(): Boolean = next().toBoolean

  def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

  def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

  def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

  def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

  def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

  def nextFloat(): Float = next().toFloat

  def nextDouble(): Double = next().toDouble

  def nextBigDecimal(): BigDecimal = BigDecimal(next())

  override def close() = reader.close()
}

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(3)(sc.nextLong()).sorted
    println(A.sum + A(2) * 9)
  }

  def calc(N: Long, R: Long, M: Long): Double = {
    math.sqrt(R * R - (R * 2 * ((M * 1.0 / N) - 0.5)) * (R * 2 * ((M * 1.0 / N) - 0.5))) * 2
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    0
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


object Main extends App {

  import scala.io.StdIn._

  val num = readLine.trim.split(' ').map(_.toInt).sorted(Ordering[Int].reverse)
  println(
    num(0) * 10 + num(1) + num(2)
  )
}


object Main {
  def main(args: Array[String]) {
    val factors = scala.io.StdIn.readLine().split(' ').map{_.toInt}.sorted

    println(factors(2)*10 + factors(1) + factors(0))
  }
}


import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val ax = Vector.fill(3)(sc.nextInt).sorted.reverse
  println(ax(0) * 10 + ax(1) + ax(2))
}


object Main extends App {
  val list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList.sorted
  println(list(2) * 10 + list(1) + list(0))
}


import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val ABC = Array.fill(3)(sc.nextInt).sorted

    (ABC(2) * 10 + ABC(1) + ABC(0)).toString
  }
}


object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val x = readLineInts
    val Array(a, b, c) = x.sorted.reverse
    println(a * 10 + b + c)
  }
}