import scala.io.StdIn.readLine import scala.collection.mutable.PriorityQueue import scala.annotation.tailrec import scala.util.control.Breaks object Main { // def insert(s : String, c : Char, n : Int) : String = { // val (head,tail) = s.splitAt(n) // head + c + tail // } def solve(s : String) : Option[String] = { val n = s.length val b = new Breaks def check(s : String,c : Char) : Boolean = { val n = s.length (0 until s.length).forall((i) => { val j = n - i - 1 s(i) == c || s(j) == c || s(i) == s(j) }) } if(check(s,'?')){ Some(s.take(n/2) + s(n/2) + s.drop(n/2)) }else{ var ans : Option[String] = None b.breakable { for(i <- 0 until n){ val j = n - i - 1 if(s(i) != s(j)){ val checking = Vector((s.take(i) + "?" + s.drop(i)), (s.take(j+1) + "?" + s.drop(j+1))) checking.foreach((i) => if(check(i,'?')){ val r = i.indexOf('?') ans = Some(i.updated(r,i(n-r))) }) b.break } } } ans } } def main(args : Array[String]) : Unit = { val s = readLine val ret = solve(s) match { case Some(j) => j case None => "NA" } println(ret) } }