• + 0 comments
    object Solution {
        
        def solve(n: Int, input: Seq[Int]): Unit = {
          implicit val orderingIntSeq: Ordering[Seq[Int]] = (lsa: Seq[Int], lsb: Seq[Int]) =>
            implicitly[Ordering[Int]].compare(lsa.head, lsb.head)
    
          println(
            input.grouped(2).toList.groupBy(_.head)
              .filter(_._2.length == n)
              .view.mapValues(_.minBy(_.tail)).toMap
              .values
              .toList
              .sortBy(_.head)
              .map(_.mkString(" "))
              .reduce(_ + " " + _)
          )
        }
        
        def apply(): Unit = {
          val N: Int = io.StdIn.readLine().trim.toInt
    
          val inputList: Seq[Int] = (1 to N).flatMap { _ =>
            val input: Array[Int] =
              io.StdIn.readLine().trim.split(" ").map(_.toInt)
    
            input
          }
    
          solve(N, inputList)
        }
        
        def main(args: Array[String]) {
            /* Enter your code here. Read input from STDIN. Print output to STDOUT. Your class should be named Solution
    */      Solution.apply()
        }
    }