import java.util.Scanner object Problem282 { val sc = new Scanner(System.in) def question(s: Seq[Int]) = { println("? " + s.mkString(" ")) val answer = Seq.fill(s.length / 2)(sc.next()) answer } def fillSeq(s: Seq[Int], n: Int) = { s ++ Seq.fill(n * 2 - s.length)(0) } def swapSeqByAnswer(s: Seq[Int], answer: Seq[String]): Seq[Int] = { val z = s.grouped(2).toSeq.zip(answer) z flatMap { v => v._2 match { case ">" => v._1.reverse case _ => v._1 } } } def nonZeroFilter(swapped: Seq[Int]): Seq[Int] = { swapped.filter(_ != 0) } def main(args: Array[String]) { val N = sc.nextInt() def proc(raw: Seq[Int]): Seq[Int] = { def subProc(raw: Seq[Int]): Seq[Int] = { val filledSeq = fillSeq(raw, N) val answer = question(filledSeq) val swapped = swapSeqByAnswer(filledSeq, answer) nonZeroFilter(swapped) } val res1 = subProc(raw) val res2 = subProc(0 +: res1) if (res1 == res2) { res2 } else { proc(res2) } } val result = proc((1 to N).toSeq) println("! " + result.mkString(" ")) } }