import scala.io.StdIn

/** A. Mr. Kitayuta's Gift
  * http://codeforces.com/contest/505/problem/A
  * @author Yuichiroh Matsubayashi
  *         Created on 15/01/19.
  */
object P505A extends App {
  val letters = StdIn.readLine().toList
  val size = letters.size

  def solution = {
    def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = ""): (Int, String) = {
      if (long == Nil) (skipped, char)
      else if (short == Nil) (size - 1, long.mkString)
      else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)
      else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)
      else (-1, "")
    }

    if (size % 2 == 0) {
      val (pre, post) = letters.splitAt(size / 2)
      if (pre == post) pre.mkString + post.head.toString + post.mkString
      else {
        val (skippedPre, cPre) = valid(pre.size, pre.reverse.tail, post)
        if (skippedPre >= 0) {
          val (ppre, ppost) = pre.splitAt(pre.size - skippedPre-1)
          ppre.mkString + cPre + ppost.mkString + post.mkString
        }
        else {
          val (skippedPost, cPost) = valid(post.size, post.tail, pre.reverse)
          if (skippedPost >= 0) {
            val (ppre, ppost) = post.splitAt(skippedPost+1)
            pre.mkString + ppre.mkString + cPost + ppost.mkString
          }
          else "NA"
        }
      }
    }
    else {
      val (pre, b) = letters.splitAt(size / 2)
      val (mid, post) = (b.head, b.tail)

      if (pre == post.reverse) pre.mkString + mid + mid + post.mkString
      else {
        val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)
        if (skippedPre >= 0) {
          val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)
          ppre.mkString + cPre + ppost.mkString + mid + post.mkString
        }
        else {
          val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)
          if (skippedPost >= 0) {
            val (ppre, ppost) = post.splitAt(skippedPost)
            pre.mkString + mid + ppre.mkString + cPost + ppost.mkString
          }
          else "NA"
        }
      }
    }
  }

  println(solution)
}

import scala.io.StdIn

/** A. Mr. Kitayuta's Gift
  * http://codeforces.com/contest/505/problem/A
  * @author Yuichiroh Matsubayashi
  *         Created on 15/01/19.
  */
object P505A extends App {
  val letters = StdIn.readLine().toList
  val size = letters.size

  def solution = {
    def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = ""): (Int, String) = {
      if (long == Nil) (skipped, char)
      else if (short == Nil) {
        if (skipped < 0) (size - 1, long.mkString)
        else {
          new NoSuchElementException
          (size, "")
        }
      }
      else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)
      else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)
      else (-1, "")
    }

    if (size % 2 == 0) {
      val (pre, post) = letters.splitAt(size / 2)
      if (pre == post) pre.mkString + post.head.toString + post.mkString
      else {
        val (skippedPre, cPre) = valid(pre.size, pre.reverse.tail, post)
        if (skippedPre >= 0) {
          val (ppre, ppost) = pre.splitAt(pre.size - skippedPre-1)
          ppre.mkString + cPre + ppost.mkString + post.mkString
        }
        else {
          val (skippedPost, cPost) = valid(post.size, post.tail, pre.reverse)
          if (skippedPost >= 0) {
            val (ppre, ppost) = post.splitAt(skippedPost+1)
            pre.mkString + ppre.mkString + cPost + ppost.mkString
          }
          else "NA"
        }
      }
    }
    else {
      val (a, b) = letters.splitAt(size / 2)
      val (pre, mid, post) = (a.toList, b.head, b.tail)

      if (pre == post.reverse) pre.mkString + mid + mid + post.mkString
      else {

        val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)
        if (skippedPre >= 0) {
          val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)
          ppre.mkString + cPre + ppost.mkString + mid + post.mkString
        }
        else {
          val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)
          if (skippedPost >= 0) {
            val (ppre, ppost) = post.splitAt(skippedPost)
            pre.mkString + mid + ppre.mkString + cPost + ppost.mkString
          }
          else "NA"
        }
      }
    }
  }

  println(solution)
}

object A505 {

  import IO._
  import collection.{mutable => cu}
  def isPalin(str: String): Boolean = {
    (0 until str.length/2).forall(i => str(i) == str(str.length-i-1))
  }
  def main(args: Array[String]): Unit = {
    var str = read
    val n = str.length
    var break = false
    for(i <- 0 to n if !break) {
      for(j <- 'a' to 'z' if !break) {
        val (f, s) = str.splitAt(i)
        if(isPalin(f+j+s)) {
          str = f + j + s
          break = true
        }
      }
    }
    if(!break) {
      out.println("NA")
    } else {
      out.println(str)
    }
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

/**
 * @author pvasilyev
 * @since 01 Aug 2016
 */
object A505 extends App {

  def palindrome(stringToCheck: String): Boolean = {
    for (i <- 0 until stringToCheck.length / 2 + 1) {
      if (stringToCheck.charAt(i) != stringToCheck.charAt(stringToCheck.length() - 1 - i)) {
        return false
      }
    }
    true
  }

  def solve() = {
    var pal: String = null
    val s: String = scala.io.StdIn.readLine()
    for (c <- 0 until 26 ) {
      val ch: Char = ('a'.toInt + c).toChar
      for (i <- 0 until s.length) {
        val stringToCheck = s.substring(0, i) + ch + s.substring(i)
        if (palindrome(stringToCheck)) {
          pal = stringToCheck
        }
      }
      if (palindrome(s + ch)) {
        pal = s + ch
      }
    }
    if (pal != null) {
      println(pal)
    } else {
      println("NA")
    }
  }

  solve()

}

object Main {
  def main(args: Array[String]) {
    val s:String=io.StdIn.readLine()
    println(solve(s))
  }
    def solve(s:String):String = {
      if (s.length==1)
        return s+s
      if (isPal(s))
        if (s.length%2==0) insert(s,'a',s.length/2) else insert(s,s(s.length/2),s.length/2)
      else {
        var i=0
        while (i<s.length/2){
          if (s(i)==s(s.length-i-1))
            i+=1
          else {
            var r=insert(s,s(s.length-i-1),i)
            if (isPal(r))
              return r
            r = insert(s,s(i),s.length-i)
            if (isPal(r))
              return r
            i+=1
          }
        }
        "NA"
      }
    }
    def insert(s:String, c:Char, p:Int) = {
      s.take(p)+c+s.takeRight(s.length-p)
    }
    def isPal(s:String) = {
      s==s.reverse
    }

}

import java.io.InputStream
import java.io.PrintStream
import java.util.Scanner

object A_Mr_Kitayutas_Gift {

  def main(args: Array[String]) {
    parseSolveAndPrint(System.in, System.out)
  }

  def parseSolveAndPrint(in: InputStream, out: PrintStream): Unit = {
    val scanner = new Scanner(in)
    val str = scanner.next()

    def findInsertionPoints(str : String, l : Int, h: Int, acc : Seq[(Int, Char)] = Nil) : Seq[(Int, Char)] = {
      (l, h) match {
        case (l, h) if l > h => acc
        case (l, h) => {
          if (str.charAt(l) == str.charAt(h))
            findInsertionPoints(str, l + 1, h - 1, acc)
          else {
            val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))
            val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))

            if (loResult.size < hiResult.size)
              loResult
            else
              hiResult
          }
        }
      }
    }

    val insertionPoints = findInsertionPoints(str, 0, str.length - 1)

    if (insertionPoints.size == 1) {
      val point = insertionPoints.head
      val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)
      out.println(newStr)
    } else if (insertionPoints.size == 0) {
      if (str.size % 2 == 0) {
        val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)
        out.println(newStr)
      } else {
        val newStr = str.substring(0, str.size / 2) + str.charAt(str.size / 2) + str.charAt(str.size / 2) + str.substring(str.size / 2 + 1)
        out.println(newStr)
      }
    } else {
      out.println("NA")
    }
  }
}

import scala.io.StdIn

object Main {

  val chars = 'a' to 'z'

  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine()
    for (c <- chars) {
      for (pos <- Range(0, s.length + 1)) {
        val splitted = s.splitAt(pos)
        val newS = splitted._1 + c + splitted._2
        if(newS == newS.reverse) {
          println(newS)
          return
        }
      }
    }
    println("NA")
    return
  }
}

object Main extends App {
  val word = readLine
  def morph(s: String): Option[Char] = {
    val d = s.size / 2
    val dir = s take d
    val back = s.reverse take d
    (dir zip back).foldLeft[Option[Char]](Some('*'))({
      case (None, _) => None
      case (_, ('*', c2)) => Some(c2)
      case (_, (c1, '*')) => Some(c1)
      case (acc, (c1, c2)) if c1==c2 => acc
      case _ => None
    })
  }

  (word.inits.toList.zip(word.tails.toList.reverse)).map({
    case (start, end) => {
      val v = List(start, "*", end).mkString
      (v, morph(v))
    }
  }).filter({ case (_, None) => false; case _ => true }).headOption match {
    case None => println("NA")
    case Some((v, Some(r))) => println(v.replace("*", if(r == '*') "a" else r.toString))
  }
}

import scala.io.StdIn._

object Main extends App {
  val s = readLine
  val n = s.length

  def ans: String = {
    var mp = 0
    while (mp < n && s(mp) == s(n - 1 - mp)) {
      mp += 1
    }

    val anyChar = "a"
    val noAns = "NA"

    def getForEven: String = {
      def getLeft: Option[Int] = {
        var mid = n / 2 - 1
        var i = 1
        while (mid - i >= 0 && s(mid - i) == s(mid + i)) {
          i += 1
        }
        mid -= i - 1

        (0 to n / 2 - 1).find(i => i <= mp && i >= mid)
      }

      def getRight: Option[Int] = {
        var mid = n / 2
        var i = 1
        while (mid + i < n && s(mid - i) == s(mid + i)) {
          i += 1
        }
        mid += i - 1

        (n / 2 + 1 to n).find(i => n - i <= mp && i - 1 <= mid)
      }

      val fromLeft = getLeft
      if (fromLeft.isDefined) {
        val pos = fromLeft.get
        return s.substring(0, pos) + s(n - 1 - pos) + s.substring(pos)
      }

      val fromRight = getRight
      if (fromRight.isDefined) {
        val pos = fromRight.get
        return s.substring(0, pos) + s(n - pos) + s.substring(pos)
      }

      if (mp >= n / 2)
        s.substring(0, n / 2) + anyChar + s.substring(n / 2)
      else
        noAns
    }

    def getForOdd: String = {
      def getLeft: Option[Int] = {
        var mid = n / 2 - 1
        if (s(mid) != s(mid + 1)) {
          return Option.empty
        }

        var i = 1
        while (mid - i >= 0 && s(mid - i) == s(mid + 1 + i)) {
          i += 1
        }
        mid -= i - 1

        (0 to n / 2 - 1).find(i => i <= mp && i >= mid)
      }

      def getRight: Option[Int] = {
        var mid = n / 2 + 1
        if (s(mid - 1) != s(mid)) {
          return Option.empty
        }

        var i = 1
        while (mid + i < n && s(mid - 1 - i) == s(mid + i)) {
          i += 1
        }
        mid += i - 1

        (n / 2 + 2 to n).find(i => n - i <= mp && i - 1 <= mid)
      }

      val fromLeft = getLeft
      if (fromLeft.isDefined) {
        val pos = fromLeft.get
        return s.substring(0, pos) + s(n - 1 - pos) + s.substring(pos)
      }

      val fromRight = getRight
      if (fromRight.isDefined) {
        val pos = fromRight.get
        return s.substring(0, pos) + s(n - pos) + s.substring(pos)
      }

      if (mp >= n / 2)
        s.substring(0, n / 2) + s(n / 2) + s.substring(n / 2)
      else
        noAns
    }

    if (n == 1)
      s * 2
    else if (n % 2 == 0)
      getForEven
    else
      getForOdd
  }

  println(ans)
}

import scala.io.StdIn

/** A. Mr. Kitayuta's Gift
  * http://codeforces.com/contest/505/problem/A
  * @author Yuichiroh Matsubayashi
  *         Created on 15/01/19.
  */
object P505A extends App {
  val letters = StdIn.readLine().toList
  val size = letters.size

//  println(letters, size)

  def valid(s1: List[Char], s2: List[Char], skippedA: Int = -1, skippedB: Int = -1, skippedLetter: Char = ' '): String = {
//    println(s1, s2, skippedLetter)
    if (s1 == Nil || s2 == Nil) {
//      println(skippedA, skippedB)
      if (skippedA >= 0) {
        val (pre, post) = letters.splitAt(size - skippedA)
        pre.mkString + skippedLetter + post.mkString
      }
      else if (skippedB >= 0) {
        val (pre, post) = letters.splitAt(skippedB)
        pre.mkString + skippedLetter + post.mkString
      }
      else if (size % 2 == 0) {
        val (pre, post) = letters.splitAt(size / 2)
        pre.mkString + "a" + post.mkString
      }
      else {
        val (pre, post) = letters.splitAt(size / 2)
        pre.mkString + post.head + post.mkString
      }
    }
    else if (s1.head == s2.head) valid(s1.tail, s2.tail, skippedA, skippedB, skippedLetter)
    else {
      val a = if (skippedA < 0) valid(s1.tail, s2, skippedA = size / 2 - s1.size, skippedB, s1.head) else "NA"
      if (a != "NA") a
      else if (skippedB < 0) valid(s1, s2.tail, skippedA, skippedB = size / 2 - s2.size, s2.head)
      else "NA"
    }
  }

  def solution = valid(letters.slice(0, size / 2), letters.reverse.slice(0, size / 2))

  println(solution)
}

import scala.io.StdIn

/** A. Mr. Kitayuta's Gift
  * http://codeforces.com/contest/505/problem/A
  * @author Yuichiroh Matsubayashi
  *         Created on 15/01/19.
  */
object P505A extends App {
  val letters = StdIn.readLine().toList
  val size = letters.size

  def solution = {
    if (size % 2 == 0) {
      val (pre, post) = letters.splitAt(size / 2)
      if (pre.toList == post.reverse) pre.mkString + post.head.toString + post.mkString
      else {
        if (pre.toList == pre.head :: post.tail.reverse) (letters.head :: letters.reverse).reverse.mkString
        else if ((post.last :: pre).reverse.tail == post.toList) (post.last :: letters).mkString
        else "NA"
      }
    }
    else {
      val (a, b) = letters.splitAt(size / 2)
      val (pre, mid, post) = (a.toList, b.head, b.tail)

      if (pre == post.reverse) pre.mkString + mid + mid + post.mkString
      else {
        def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = ""): (Int, String) = {
          if (long == Nil) (skipped, char)
          else if (short == Nil) {
            if (skipped < 0) (size - 1, long.mkString)
            else {
              new NoSuchElementException
              (size, "")
            }
          }
          else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)
          else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)
          else (-1, "")
        }

        val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)
        if (skippedPre >= 0) {
          val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)
          ppre.mkString + cPre + ppost.mkString + mid + post.mkString
        }
        else {
          val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)
          if (skippedPost >= 0) {
            val (ppre, ppost) = post.splitAt(skippedPost)
            pre.mkString + mid + ppre.mkString + cPost + ppost.mkString
          }
          else "NA"
        }
      }
    }
  }

  println(solution)
}

import scala.io.StdIn

/** A. Mr. Kitayuta's Gift
  * http://codeforces.com/contest/505/problem/A
  * @author Yuichiroh Matsubayashi
  *         Created on 15/01/19.
  */
object P505A extends App {
  val letters = StdIn.readLine().toList
  val size = letters.size

  println(letters, size)

  def valid(s1: List[Char], s2: List[Char], size: Int, skippedA: Int = -1, skippedB: Int = -1, skippedLetter: Char = ' '): String = {
    println(s1, s2, size, skippedA, skippedB, skippedLetter)
    if (s1 == Nil || s2 == Nil) {
      println(skippedA, skippedB)
      if (skippedA >= 0) {
        val (pre, post) = letters.splitAt(size - skippedA)
        pre.mkString + skippedLetter + post.mkString
      }
      else if (skippedB >= 0) {
        val (pre, post) = letters.splitAt(skippedB)
        pre.mkString + skippedLetter + post.mkString
      }
      else if (size % 2 == 0) {
        val (pre, post) = letters.splitAt(size / 2)
        pre.mkString + "a" + post.mkString
      }
      else {
        val (pre, post) = letters.splitAt(size / 2)
        pre.mkString + post.head + post.mkString
      }
    }
    else if (s1.head == s2.head) valid(s1.tail, s2.tail, size, skippedA, skippedB, skippedLetter)
    else {
      val a = if (skippedA < 0) valid(s1.tail, s2, size, size - s1.size, skippedB, s1.head) else "NA"
      if (a != "NA") a
      else if (skippedA < 0 && skippedB < 0) valid(s1, s2.tail, size, skippedA, size - s2.size, s2.head)
      else "NA"
    }
  }

  def solution = valid(letters.slice(0, (size / 2.0).ceil.toInt), letters.reverse.slice(0, (size / 2.0).ceil.toInt), (size / 2.0).ceil.toInt)

  println(solution)
}

import scala.io.StdIn

/** A. Mr. Kitayuta's Gift
  * http://codeforces.com/contest/505/problem/A
  * @author Yuichiroh Matsubayashi
  *         Created on 15/01/19.
  */
object P505A extends App {
  val letters = StdIn.readLine().toList
  val size = letters.size

  def solution = {
    if (size % 2 == 0) {
      val (pre, post) = letters.splitAt(size / 2)
      if (pre.toList == post.reverse) pre + post.head.toString + post
      else {
        if (pre.toList == pre.head :: post.tail.reverse) (letters.head :: letters.reverse).reverse.mkString
        else if ((post.last :: pre).reverse.tail == post.toList) (post.last :: letters).mkString
        else "NA"
      }
    }
    else {
      val (a, b) = letters.splitAt(size / 2)
      val (pre, mid, post) = (a.toList, b.head, b.tail)

      if (pre == post.reverse) pre.mkString + mid + mid + post.mkString
      else {
        def valid(size: Int, short: List[Char], long: List[Char], skipped: Int = -1, char: String = ""): (Int, String) = {
          if (long == Nil) (skipped, char)
          else if (short == Nil) {
            if (skipped < 0) (size - 1, long.mkString)
            else {
              new NoSuchElementException
              (size, "")
            }
          }
          else if (short.head == long.head) valid(size, short.tail, long.tail, skipped, char)
          else if (skipped < 0) valid(size, short, long.tail, size - long.size, long.head.toString)
          else (-1, "")
        }

        val (skippedPre, cPre) = valid(pre.size + 1, pre.reverse, mid :: post)
        if (skippedPre >= 0) {
          val (ppre, ppost) = pre.splitAt(pre.size - skippedPre)
          ppre.mkString + cPre + ppost.mkString + mid + post.mkString
        }
        else {
          val (skippedPost, cPost) = valid(post.size + 1, post, mid :: pre.reverse)
          if (skippedPost >= 0) {
            val (ppre, ppost) = post.splitAt(skippedPost)
            pre.mkString + mid + ppre.mkString + cPost + ppost.mkString
          }
          else "NA"
        }
      }
    }
  }

  println(solution)
}

object Main {
  def main(args: Array[String]) {
    val s:String=io.StdIn.readLine()
    println(solve(s))
  }
    def solve(s:String):String = {
      if (isPal(s))
        if (s.length%2==0) insert(s,'a',s.length/2) else "NA"
      else {
        var i=0
        while (i<s.length/2){
          if (s(i)==s(s.length-i-1))
            i+=1
          else {
            var r=insert(s,s(s.length-i-1),i)
            if (isPal(r))
              return r
            r = insert(s,s(i),s.length-i)
            if (isPal(r))
              return r
            i+=1
          }
        }
        "NA"
      }
    }
    def insert(s:String, c:Char, p:Int) = {
      s.take(p)+c+s.takeRight(s.length-p)
    }
    def isPal(s:String) = {
      s==s.reverse
    }

}

object Main {
  def main(args: Array[String]) {
    val s:String=io.StdIn.readLine()
    println(solve(s))
  }
    def solve(s:String):String = {
      if (s.length==1)
        return s+s
      if (isPal(s))
        if (s.length%2==0) insert(s,'a',s.length/2) else "NA"
      else {
        var i=0
        while (i<s.length/2){
          if (s(i)==s(s.length-i-1))
            i+=1
          else {
            var r=insert(s,s(s.length-i-1),i)
            if (isPal(r))
              return r
            r = insert(s,s(i),s.length-i)
            if (isPal(r))
              return r
            i+=1
          }
        }
        "NA"
      }
    }
    def insert(s:String, c:Char, p:Int) = {
      s.take(p)+c+s.takeRight(s.length-p)
    }
    def isPal(s:String) = {
      s==s.reverse
    }

}

import java.io.InputStream
import java.io.PrintStream
import java.util.Scanner

object A_Mr_Kitayutas_Gift {

  def main(args: Array[String]) {
    parseSolveAndPrint(System.in, System.out)
  }

  def parseSolveAndPrint(in: InputStream, out: PrintStream): Unit = {
    val scanner = new Scanner(in)
    val str = scanner.next()

    def findInsertionPoints(str : String, l : Int, h: Int, acc : Seq[(Int, Char)] = Nil) : Seq[(Int, Char)] = {
      (l, h) match {
        case (l, h) if l > h => acc
        case (l, h) => {
          if (str.charAt(l) == str.charAt(h))
            findInsertionPoints(str, l + 1, h - 1, acc)
          else {
            val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))
            val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))

            if (loResult.size < hiResult.size)
              loResult
            else
              hiResult
          }
        }
      }
    }

    val insertionPoints = findInsertionPoints(str, 0, str.length - 1)

    if (insertionPoints.size == 1) {
      val point = insertionPoints.head
      val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)
      out.println(newStr)
    } else if (insertionPoints.size == 0) {
      if (str.size % 2 == 0) {
        val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)
        out.println(newStr)
      } else if (str.size == 1) {
        out.println(str + str)
      } else {
        out.println("NA")
      }
    } else {
      out.println("NA")
    }
  }
}

import java.io.InputStream
import java.io.PrintStream
import java.util.Scanner

object A_Mr_Kitayutas_Gift {

  def main(args: Array[String]) {
    parseSolveAndPrint(System.in, System.out)
  }

  def parseSolveAndPrint(in: InputStream, out: PrintStream): Unit = {
    val scanner = new Scanner(in)
    val str = scanner.next()

    def findInsertionPoints(str : String, l : Int, h: Int, acc : Seq[(Int, Char)] = Nil) : Seq[(Int, Char)] = {
      (l, h) match {
        case (l, h) if l > h => acc
        case (l, h) => {
          if (str.charAt(l) == str.charAt(h))
            findInsertionPoints(str, l + 1, h - 1, acc)
          else {
            val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))
            val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))

            if (loResult.size < hiResult.size)
              loResult
            else
              hiResult
          }
        }
      }
    }

    val insertionPoints = findInsertionPoints(str, 0, str.length - 1)

    if (insertionPoints.size == 1) {
      val point = insertionPoints.head
      val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)
      out.println(newStr)
    } else if (insertionPoints.size == 0) {
      if (str.size % 2 == 0) {
        val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)
        out.println(newStr)
      } else {
        out.println("NA")
      }
    } else {
      out.println("NA")
    }
  }
}

import java.io.InputStream
import java.io.PrintStream
import java.util.Scanner

object A_Mr_Kitayutas_Gift {

  def main(args: Array[String]) {
    parseSolveAndPrint(System.in, System.out)
  }

  def parseSolveAndPrint(in: InputStream, out: PrintStream): Unit = {
    val scanner = new Scanner(in)
    val str = scanner.next()

    def findInsertionPoints(str : String, l : Int, h: Int, acc : Seq[(Int, Char)] = Nil) : Seq[(Int, Char)] = {
      (l, h) match {
        case (l, h) if l > h => acc
        case (l, h) => {
          if (str.charAt(l) == str.charAt(h))
            findInsertionPoints(str, l + 1, h - 1, acc)
          else {
            val loResult = findInsertionPoints(str, l, h - 1, acc :+ (l, str.charAt(h)))
            val hiResult = findInsertionPoints(str, l + 1, h, acc :+ (h + 1, str.charAt(l)))

            if (loResult.size < hiResult.size)
              loResult
            else
              hiResult
          }
        }
      }
    }

    val insertionPoints = findInsertionPoints(str, 0, str.length - 1)

    if (insertionPoints.size == 1) {
      val point = insertionPoints.head
      val newStr = str.substring(0, point._1) + point._2 + str.substring(point._1)
      out.println(newStr)
    } else if (insertionPoints.size == 0) {
      if (str.size % 2 == 0) {
        val newStr = str.substring(0, str.size / 2) + 'a' + str.substring(str.size / 2)
        out.println(newStr)
      } else {
        out.println("NA")
      }
    } else {
      out.println("NA")
    }

    println(insertionPoints.toString())
  }
}


object A {
  val mod = 1000000009L

  def main(args: Array[String]) {
    val (n, m) = {
      val sp = readLine.split(" ")
      (sp(0).toInt, sp(1).toInt)
    }

    if (m < 60 && (1L << m) - n < 0) {
      println(0)
      return
    }

    val m2 = (1 to m).foldLeft(1L) { (v: Long, i) =>
      v * 2 % mod
    }

    val ans = (1 to n).foldLeft(1L) { (v: Long, i) =>
      v * (m2 - i + mod) % mod
    }
    println(ans)
  }
}

import java.util._

object Main extends App {
  val sc = new Scanner(System.in)
  val mod = 1000000009L

  val n, m = sc.nextInt()

  def power(x: Long, p: Long, res: Long = 1L): Long =
    if (p == 0) res else power(x, p - 1, res * x % mod)

  def solve(p: Long, n: Long, res: Long = 1L): Long =
    if (n == 0) res else solve(p - 1, n - 1, res * p % mod)

  println(solve(power(2, m) - 1, n))
}


/**
  * Created by mettu.r on 20/08/17.
  */
object Demo extends App {
  override def main(args: Array[String]): Unit = {
    var a = readLine().split(" ").map(x => x.toInt);
    var n = a(0);
    var k = a(1);
    var s = readLine();
    var map = scala.collection.mutable.Map[Char,Int]();
    s.foreach(x => {
      map.put(x , map.getOrElse(x,0) + 1 );
    });
    var ans = true;
    map.foreach( x => if( x._2 > k ) ans = false );
    if( ans )
      printf("Yes\n");
    else
      printf("No\n");
  }
}

import java.util.Scanner

object Try1 {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    var len, m, k, n, j, i: Int = 0
    var a = new Array[Int](26)
    n = in.nextInt()
    m = in.nextInt()
    k=0
    var line = in.nextLine()
    line = in.nextLine()
    for (i <- 0 to 25) a(i)=0
    for (i <- 0 until  n)
      a(line(i)-'a')+=1
//    len = line.length()
    for (i <- 0 to 25)
      if (a(i)>m) k=1
    if (k==0) println("YES")
    else println("NO")
  }
}

import java.util.Scanner

object Try1 {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    var len, w, ans, m, x, c, k, n, j, i: Int = 0
    var a = new Array[Int](26)
    n = in.nextInt()
    m = in.nextInt()
    k=0
    var line = in.nextLine()
    line = in.nextLine()
    for (i <- 0 to 25) a(i)=0
    for (i <- 0 until  n)
      a(line(i)-'a')+=1
//    len = line.length()
    if (n<m+m) x = n/2
    else x=m
    i=0
    while (i<m)
      {
        j=0
        while (j<26 && a(j)==0) j+=1
        if (j<26) {
          a(j)-=1
          j+=1
          while (j<26 && a(j)==0) j+=1
          if (j<26) {
            a(j)-=1
            k+=1
          }
        }
        i+=1
      }
    if (k==m) println("YES")
    else println("NO")
  }
}

import java.util.Scanner

object Try1 {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    var len, w, ans, m, x, c, k, n, j, i: Int = 0
    var a = new Array[Int](26)
    n = in.nextInt()
    m = in.nextInt()
    k=1
    var line = in.nextLine()
    line = in.nextLine()
    for (i <- 0 to 25) a(i)=0
    for (i <- 0 until  n)
      a(line(i)-'a')+=1
//    len = line.length()
    for (i <- 0 to 25)
      if (a(i)>m) k=1
    if (k==0) println("YES")
    else println("NO")
  }
}

import java.util.Scanner

object Try1 {
  def main(args: Array[String]) {
    val in = new Scanner(System.in)
    var len, w, ans, m, x, c, k, n, j, i: Int = 0
    var a = new Array[Int](26)
    n = in.nextInt()
    m = in.nextInt()
    k=0
    var line = in.nextLine()
    line = in.nextLine()
    for (i <- 0 to 25) a(i)=0
    for (i <- 0 until  n)
      a(line(i)-'a')+=1
//    len = line.length()
    if (n<m+m) x = n/2
    else x=m
    i=0
    while (i<x)
      {
        j=0
        while (j<26 && a(j)==0) j+=1
        if (j<26) {
          a(j)-=1
          j+=1
          while (j<26 && a(j)==0) j+=1
          if (j<26) {
            a(j)-=1
            k+=1
          }
        }
        i+=1
      }
    if (k==x) println("YES")
    else println("NO")
  }
}


object _1178C extends CodeForcesApp {
  import annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def apply(io: IO): io.type = {
    val w, h = io.read[Int]
    val ans = BigInt(2).modPow(w+h, 998244353)
    io.write(ans)
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    tokenizers.headOption
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: CanBuild[A, C[A]]): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeLines(obj: Traversable[Any]): this.type = writeAll(obj, separator = "\n")
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }

  object Read {
    implicit def collection[C[_], A: Read](implicit b: CanBuild[A, C[A]]) : Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                                   : Read[String]       = new Read(_.next())
    implicit val int                                                      : Read[Int]          = string.map(_.toInt)
    implicit val long                                                     : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                                   : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                                   : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                               : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                                 : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]                        : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]               : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                                  : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object C extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(scala.io.StdIn.readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(w, h) = readInts(2)
  val MOD = BigInt(998244353L)

  val res = BigInt(2).modPow(w + h, MOD)

  println(res)
}


import java.util.ArrayList
import java.util.StringTokenizer
//import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object C_441 {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.sa1)
//    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val n = readLine.int

    //---------------------------- parameters reading :end

    var continue = true
    var variants = List[Int]()
    var x = n
    val maxDif = n.toString().length() * 9
    while (continue) {
      val sum = sumDig(x) + x
      continue = x > 0 && x + maxDif >= n
      if (sum == n) variants ::= x
      x -= 1
    }

    def sumDig(x: Int) = {
      x.toString.map(c => (c+"").toInt).sum
    }

    val res = if (variants.size > 0) {
      variants.size + "\n" + variants.sorted.mkString(" ")
    } else {
      "0"
    }

    outLn(res)
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
21
"""

val sa2 = """
20
"""

val sa3 = """
100
"""
}

}

import scala.collection.mutable.ListBuffer

object test {
  def digits(a: Int): Int =
    if (a == 0) 0
    else 1 + digits(a/10)
  def sumDigits(a: Int): Int =
    if (a == 0) 0
    else (a % 10) + sumDigits(a/10)
  def main(args: Array[String]) {
    val a = scala.io.StdIn.readInt
    var l = ListBuffer[Int]()
    for(x <- math.max(a-9*digits(a)-5, 0) to a) {
      if(sumDigits(x)+x == a) l += x
    }
    println(l.length)
    for(x <- l) {
      println(x)
    }
  }
}

import java.util.ArrayList
import java.util.StringTokenizer
//import scala.reflect.io.File
import java.io.BufferedReader
import java.io.BufferedInputStream
import java.io.InputStreamReader
import java.io.ByteArrayInputStream
import java.io.InputStream

object C_441 {   var br = createBufferedReader(); var debugV = false

    //COMMENT ME !
//    runTest(Test.sa1)
//    debugV = true
//    file = File("C:\\temp\\google cj\\2014q\\c-small.res")

  def main(args: Array[String]): Unit = {
    //---------------------------- parameters reading
    val n = readLine.int

    var continue = true
    var variants = List[Int]()
    var x = n
    while (continue) {
      val sum = sumDig(x) + x
      continue = sum > n
      if (sum == n) variants ::= x
      x -= 1
    }

    def sumDig(x: Int) = {
      x.toString.map(c => (c+"").toInt).sum
    }

//    val max = groups.values.reduce((a,b) => if (a.size > b.size) a else b)
//    debug("max = " + max.mkString(" "))

    //---------------------------- parameters reading :end

    val res = if (variants.size > 0) {
      variants.size + "\n" + variants.sorted.mkString(" ")
    } else {
      "0"
    }

    outLn(res)
    finish
  }

  //============================ service code ======================

//  var file:File = null
  val resultStr = new StringBuilder
  def outLn(str:String) = resultStr.append(str).append("\n")
  def outLn(number:Integer) = resultStr.append(number+"").append("\n")
  def finish() {
//    if (file == null || !devEnv) {
      println(resultStr.toString())
//    } else {
//      file.writeAll(resultStr.toString())
//    }
  }

  def readLine() = new Line
  class Line {
    val fullLine = br.readLine()
    val tok = new StringTokenizer(fullLine, " ")
    def int = tok.nextToken().toInt
    def long = tok.nextToken().toLong
    def double = tok.nextToken().toDouble
    def string = tok.nextToken()
  }

  def createBufferedReader(inst:InputStream = System.in): BufferedReader = {
    val bis = if (inst == null) new BufferedInputStream(System.in) else new BufferedInputStream(inst);
    new BufferedReader(new InputStreamReader(bis));
  }

  def runTest(str:String) = if (devEnv) {
    br = createBufferedReader(new ByteArrayInputStream(str.trim.getBytes("ISO-8859-1")))
  }

  def debug(x: => String) = if (debugV && devEnv) println(x) // nullary function

  lazy val devEnv = this.getClass.getCanonicalName.contains(".")

//============================================================================================
object Test {

val sa1 = """
21
"""

val sa2 = """
20
"""

val sa3 = """
100
"""
}

}


object Main {
  val primes: Stream[Int] = 2 #:: 3 #::
    Stream.from(5, 2).filter(i => primes.takeWhile(_ < Math.sqrt(i)).forall(i % _ != 0))

  def split(n: Int): List[Int] = {
    primes.takeWhile(_ <= Math.sqrt(n)).find(n % _ == 0) match {
      case Some(div) => div :: split(n / div)
      case None => List(n)
    }
  }

  def main(args: Array[String]) {
    val n = readInt()
    val divs = split(n)
    if (n == 1) println("1")
    else println(divs.scanLeft(1)(_ * _).reverse.mkString(" "))
  }
}

import scala.collection.mutable.ListBuffer
object P58B extends App {

  val n = readLine.toInt
  val cache = new Array[List[Int]](n)
  cache(0) = List(1)

  def f(n: Int): List[Int] = {
    if (cache(n - 1) != null) cache(n - 1)
    else {
      var factors = ListBuffer[Int](1)
      for (e <- 2 to math.sqrt(n).toInt) if (n % e == 0) factors ++= Set(e, n / e)
      cache(n - 1) = List(n) ++ factors.map(f(_)).maxBy(_.size)
      cache(n - 1)
    }
  }

  for (e <- f(n)) print(e+" ")
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val n = in.next().toInt
  val res = (2 to n).foldLeft(List(1)) {
    case(list, el) if n % el == 0 && el % list.head == 0 => el :: list
    case(list, el) => list
  }

  println(res.mkString(" "))
}

import scala.collection.mutable.ListBuffer
object P58B extends App {

  val n = readLine.toInt
  var factors = ListBuffer[Int]()
  for (e <- 2 to math.sqrt(n).toInt) if (n % e == 0) factors ++= Set(e, n / e)

  val evens = factors.filter(_ % 2 == 0)
  val odds = factors.filter(_ % 2 == 1)
  factors = List(evens, odds).maxBy(_.size) + n + 1

  for (e <- factors.toSet.toList.sortWith(_ > _)) print(e+" ")

}

import scala.collection.mutable.ListBuffer
object P58B extends App {

  val n = readLine.toInt
  var factors = ListBuffer[Int]()
  for (e <- 2 to math.sqrt(n).toInt) if (n % e == 0) factors ++= Set(e, n / e)

  val evens = factors.filter(_ % 2 == 0)
  val odds = factors.filter(_ % 2 == 1)
  factors = List(evens, odds).maxBy(_.size) + n + 1

  for (e <- factors.toList.sortWith(_ > _)) print(e+" ")

}

object Main {
  val primes: Stream[Int] = 2 #:: 3 #::
    Stream.from(5, 2).filter(i => primes.takeWhile(_ < Math.sqrt(i)).forall(i % _ != 0))

  def split(n: Int): List[Int] = {
    primes.takeWhile(_ <= Math.sqrt(n)).find(n % _ == 0) match {
      case Some(div) => div :: split(n / div)
      case None => List(n)
    }
  }

  def main(args: Array[String]) {
    val n = readInt()
    val divs = split(n)
    println(divs.scanLeft(1)(_ * _).reverse.mkString(" "))
  }
}


object main {
import scala.io.StdIn._
import scala.collection.mutable.{HashMap,HashSet}

def gcd(a: Long, b: Long): Long = {
	if (a == 0) b else gcd(b % a, a)
}

def main(args: Array[String]) {

val input = readLine.trim.split(" +")
val left = input(0).toLong
val right = input(1).toLong
val coprimes = HashMap[Long, HashSet[Long]]()
for (x <- left to right) {
	val temp = HashSet[Long]()
	for (y <- left to right) {
		if (x != y && gcd(x,y) == 1) temp += y
	}
	coprimes += x -> temp
}
def findIt: (Long, Long, Long) = {
	for (a <- coprimes.keys) {
		for (b <- coprimes(a)) {
			if (b > a) {
				for (c <- coprimes(b)) {
					if (c > a && c > b && !coprimes(a).contains(c)) return (a,b,c)
				}
			}
		}
	}
	return null
}
val res = findIt
println(if (res != null) { res._1 + " "  + res._2 + " " + res._3 } else -1)

}

}

object Solution extends App {
  def simple(a: Long, b: Long): Boolean = {
    if (b == 0) a == 1
    else simple(b, a % b)
  }

  val in = scala.io.Source.stdin.getLines()
  val Array(a, b) = in.next().split(" ").map(_.toLong)
  val options = (a to b - 2).flatMap(a1 => (a1 + 1 to b - 1).flatMap(b1 => (b1 + 1 to b).map(c1 => (a1, b1, c1))))
  println(options.find{
    case(a, b, c) => simple(a, b) && simple(b, c) && !simple(a, c)
  }.map(t => s"${t._1} ${t._2} ${t._3}").getOrElse("-1"))

}

object A483 {

  import IO._
  def gcd(a: Long, b: Long): Long = {
    if(b == 0) a else gcd(b, a%b)
  }
  def main(args: Array[String]): Unit = {
    val Array(l, r) = readLongs(2)
    var break = false
    for(a <- l to r-2; b <- a+1 to r-1; c <- b+1 to r if !break) {
      if(gcd(a, b) == 1 && gcd(b, c) == 1 && gcd(a, c) != 1) {
        println(s"$a $b $c")
        break = true
      }
    }
    if(!break) {
      println("-1")
    }
  }

  object IO {
    @inline def read: String = scala.io.StdIn.readLine

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine;
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine;
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

  /**
   * Created by SchmAn4 on 26.10.2014.
   */
  object Counterexample {
    def main(s: Array[String]): Unit = {
      val start = System.currentTimeMillis
      val scanner = new java.util.Scanner(System.in)
      val x = scanner.nextLong()
      val y = scanner.nextLong()
      val list = (x to y)

/*
      val triples = for(x <- list; y <- list; z <- list) yield (x,y,z)
      println(triples.filter {
        case (x, y, z) => x < y && y < z && x != y && y != z && x != z && ggT(x, y) == 1 && ggT(y, z) == 1 && ggT(x, z) != 1
      })
      */
      // 380ms

      /*
      val seven = (for (
        x <- list; y <- list; z <- list
        if x < y && y < z && x != y && y != z && x != z && ggT(x, y) == 1 && ggT(y, z) == 1 && ggT(x, z) != 1
      ) yield (x,y,z)).headOption
      // 340ms
*/
      val iter = (for {
        x <- list.toIterator; y <- list.toIterator; z <- list.toIterator
        if x < y && y < z && x != y && y != z && x != z && ggT(x, y) == 1 && ggT(y, z) == 1 && ggT(x, z) != 1
      } yield (x,y,z))

      if (iter.hasNext) {
        val triple = iter.next
        println(triple._1+" "+triple._2+" "+triple._3)
      } else
        println(-1)
      // 300ms

//      println((System.currentTimeMillis-start)+"ms")
    }

    /*
    def perform(a: Long, b: Long): String = (a,b) match {
      //case (p,q) if ggT(p,q) == 1 => "-1"
      case (p,q) => perform2(p,q,p+1,p+1)
    }

    def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if b >= c && ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+" "+c+" "+b
      case (_,b,c,d) if b <= c => "-1"
      case (a,b,c,d) => perform2(a,b,c+1,d+1)
    }

    def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if b >= d && ggT(c,d) == 1 && ggT(a,d) != 1 => a+" "+c+" "+d
      case (_,b,c,d) if b <= d => "-1"
      case (a,b,c,d) => perform2(a,b,c,d+1)
    }
    */

    def ggT(a: Long, b: Long): Long = (a,b) match {
      case (_,0) => a
      case (p,q) if p == q => a
      case (p,q) => ggT(b,a%b)
    }

    /*
    Input
    900000000000000009 900000000000000029
    Output
    900000000000000009 900000000000000010 900000000000000029
    Answer
    900000000000000009 900000000000000010 900000000000000021
    */

  }

import java.util.StringTokenizer

object _483A extends App {
  var token = new StringTokenizer("")

  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }

  val l = next.toLong
  val r = next.toLong

  def gcd(a: Long, b: Long): Long = if (b == 0) a else gcd(b, a % b)
  val ans = for {
    a <- l to r
    b <- a + 1 to r
    c <- b +1 to r
    if (gcd(a, b) == 1 && gcd(b, c) == 1 && gcd(a, c) > 1)
  } yield (a, b, c)

  if (ans.size == 0) println(-1)
  else println(ans.head._1 + " " + ans.head._2 + " " + ans.head._3)
}

  /**
   * Created by SchmAn4 on 26.10.2014.
   */
  object Counterexample {
    def main(s: Array[String]): Unit = {
      val scanner = new java.util.Scanner(System.in)
      val x = scanner.nextLong()
      val y = scanner.nextLong()
      println(perform(x,y))
    }

    def perform(a: Long, b: Long): String = (a,b) match {
      //case (p,q) if ggT(p,q) == 1 => "-1"
      case (p,q) => perform2(p,q,p+1)
    }

    def perform2(a: Long, b: Long, c: Long): String = (a,b,c) match {
      case (_,b,c) if b == c => "-1"
      case (a,b,c) if ggT(a,c) == 1 && ggT(b,c) == 1 => a+" "+c+" "+b
      case (a,b,c) => perform2(a,b,c+1)
    }

    def ggT(a: Long, b: Long): Long = (a,b) match {
      case (_,0) => a
      case (p,q) if p == q => a
      case (p,q) => ggT(b,a%b)
    }

  }

  /**
   * Created by SchmAn4 on 26.10.2014.
   */
  object Counterexample {
    def main(s: Array[String]): Unit = {
      val scanner = new java.util.Scanner(System.in)
      val x = scanner.nextLong()
      val y = scanner.nextLong()
      println(perform(x,y))
    }

    def perform(a: Long, b: Long): String = (a,b) match {
      case (p,q) if ggT(p,q) == 1 => "-1"
      case (p,q) => perform2(p,q,p+1)
    }

    def perform2(a: Long, b: Long, c: Long): String = (a,b,c) match {
      case (_,b,c) if b == c => "-1"
      case (a,b,c) if ggT(a,c) == 1 && ggT(b,c) == 1 => a+" "+c+" "+b
      case (a,b,c) => perform2(a,b,c+1)
    }

    def ggT(a: Long, b: Long): Long = (a,b) match {
      case (_,0) => a
      case (p,q) if p == q => a
      case (p,q) => ggT(b,a%b)
    }

  }

  /**
   * Created by SchmAn4 on 26.10.2014.
   */
  object Counterexample {
    def main(s: Array[String]): Unit = {
      val scanner = new java.util.Scanner(System.in)
      val x = scanner.nextLong()
      val y = scanner.nextLong()
      println(perform(x,y))
    }

    def perform(a: Long, b: Long): String = (a,b) match {
      //case (p,q) if ggT(p,q) == 1 => "-1"
      case (p,q) => perform2(p,q,p+1,p+1)
    }

    def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+" "+c+" "+b
      case (_,b,c,d) if b <= c => "-1"
      case (a,b,c,d) => perform2(a,b,c+1,d+1)
    }

    def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if ggT(c,d) == 1 && ggT(a,d) != 1 => a+" "+c+" "+d
      case (_,b,c,d) if b <= d => "-1"
      case (a,b,c,d) => perform2(a,b,c,d+1)
    }

    def ggT(a: Long, b: Long): Long = (a,b) match {
      case (_,0) => a
      case (p,q) if p == q => a
      case (p,q) => ggT(b,a%b)
    }

    /*
    Input
    900000000000000009 900000000000000029
    Output
    900000000000000009 900000000000000010 900000000000000029
    Answer
    900000000000000009 900000000000000010 900000000000000021
    */

  }

  /**
   * Created by SchmAn4 on 26.10.2014.
   */
  object Counterexample {
    def main(s: Array[String]): Unit = {
      val scanner = new java.util.Scanner(System.in)
      val x = scanner.nextLong()
      val y = scanner.nextLong()
      println(perform(x,y))
    }

    def perform(a: Long, b: Long): String = (a,b) match {
      //case (p,q) if ggT(p,q) == 1 => "-1"
      case (p,q) => perform2(p,q,p+1,p+1)
    }

    def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if b >= c && ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+" "+c+" "+b
      case (_,b,c,d) if b <= c => "-1"
      case (a,b,c,d) => perform2(a,b,c+1,d+1)
    }

    def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if b >= d && ggT(c,d) == 1 && ggT(a,d) != 1 => a+" "+c+" "+d
      case (_,b,c,d) if b <= d => "-1"
      case (a,b,c,d) => perform2(a,b,c,d+1)
    }

    def ggT(a: Long, b: Long): Long = (a,b) match {
      case (_,0) => a
      case (p,q) if p == q => a
      case (p,q) => ggT(b,a%b)
    }

    /*
    Input
    900000000000000009 900000000000000029
    Output
    900000000000000009 900000000000000010 900000000000000029
    Answer
    900000000000000009 900000000000000010 900000000000000021
    */

  }

  /**
   * Created by SchmAn4 on 26.10.2014.
   */
  object Counterexample {
    def main(s: Array[String]): Unit = {
      val scanner = new java.util.Scanner(System.in)
      val x = scanner.nextLong()
      val y = scanner.nextLong()
      println(perform(x,y))
    }

    def perform(a: Long, b: Long): String = (a,b) match {
      //case (p,q) if ggT(p,q) == 1 => "-1"
      case (p,q) => perform2(p,q,p+1,p+1)
    }

    def perform2(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if ggT(a,c) == 1 => perform3(a,b,c,d+1) //a+" "+c+" "+b
      case (_,b,c,d) if b == c => "-1"
      case (a,b,c,d) => perform2(a,b,c+1,d+1)
    }

    def perform3(a: Long, b: Long, c: Long, d: Long): String = (a,b,c,d) match {
      case (a,b,c,d) if ggT(c,d) == 1 && ggT(a,d) != 1 => a+" "+c+" "+d
      case (_,b,c,d) if b == d => "-1"
      case (a,b,c,d) => perform2(a,b,c,d+1)
    }

    def ggT(a: Long, b: Long): Long = (a,b) match {
      case (_,0) => a
      case (p,q) if p == q => a
      case (p,q) => ggT(b,a%b)
    }

    /*
    Input
    900000000000000009 900000000000000029
    Output
    900000000000000009 900000000000000010 900000000000000029
    Answer
    900000000000000009 900000000000000010 900000000000000021
    */

  }


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(hpy, atky, defy) = in.next().split(" ").map(_.toLong)
  val Array(hpm, atkm, defm) = in.next().split(" ").map(_.toLong)
  val Array(hpcost, atkcost, defcost) = in.next().split(" ").map(_.toLong)
  var atkmin = if (atky > defm) atky else defm + 1
  var cost = -1l
  (atkmin to (hpm + defm)).foreach { atk =>
    if (cost == -1l || (atk - atky) * atkcost < cost)
      if (atkm > defy)
        (defy to atkm).foreach { defend =>
          if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {
            val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)
            val damage = win * (atkm - defend)
            val hp = if (damage >= hpy) damage - hpy + 1 else 0
            if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))
              cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost
          }
        }
      else {
        cost = (atk - atky) * atkcost
      }
  }
  if (cost == -1l)
    println(0)
  else
    println(cost)

}

import scala.collection._

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(hy, ay, dy) = readLongs(3)
  val Array(hm, am, dm) = readLongs(3)
  val Array(ch, ca, cd) = readLongs(3)

  var min = Long.MaxValue

  for (a <- 0 to 1000) {
    for (d <- 0 to 100) {

      def can(h: Long) = {
        //(hy + h) * (ay + a - dm) > hm * (am - dy - d)
        val x = (ay + a - dm)
        if (am - dy - d <= 0 && x > 0) true
        else {
          if (x <= 0) false
          else {
            val steps = (hm + x - 1) / x
            if ((am - dy - d) * steps < hy + h) true
            else false
          }
        }
      }

      @annotation.tailrec
      def binSearch(low: Long, hi: Long): Long = {
        if (hi < low) low
        else {
          val mid = (low + hi) >>> 1
          if (can(mid)) binSearch(low, mid - 1)
          else binSearch(mid + 1, hi)
        }
      }

      val h = binSearch(0, 100000000L)

      //if (d == 0 && a == 0) println(h)

      val cost = a * ca + d * cd + h * ch

      min = Math.min(min, cost)
    }
  }

  println(min)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(hpy, atky, defy) = in.next().split(" ").map(_.toLong)
  val Array(hpm, atkm, defm) = in.next().split(" ").map(_.toLong)
  val Array(hpcost, atkcost, defcost) = in.next().split(" ").map(_.toLong)
  var atkmin = if (atky > defm) atky else defm + 1
  var cost = -1l
  (atkmin to (hpm + defm)).foreach { atk =>
    if (cost == -1l || (atk - atky) * atkcost < cost)
      if (atkm > defm)
        (defy to atkm).foreach { defend =>
          println("andhere")
          if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {
            val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)
            val damage = win * (atkm - defend)
            val hp = if (damage >= hpy) damage - hpy + 1 else 0
            if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))
              cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost
          }
        }
      else cost = (atk - atky) * atkcost
  }
  if (cost == -1l)
    println(0)
  else
    println(cost)

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(hpy, atky, defy) = in.next().split(" ").map(_.toLong)
  val Array(hpm, atkm, defm) = in.next().split(" ").map(_.toLong)
  val Array(hpcost, atkcost, defcost) = in.next().split(" ").map(_.toLong)
  var atkmin = if (atky > defm) atky else defm + 1
  var cost = -1l
  (atkmin to (hpm + defm)).foreach { atk =>
    if (cost == -1l || (atk - atky) * atkcost < cost)
      if (atkm > defm)
        (defy to atkm).foreach { defend =>
          if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {
            val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)
            val damage = win * (atkm - defend)
            val hp = if (damage >= hpy) damage - hpy + 1 else 0
            if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))
              cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost
          }
        }
      else cost = (atk - atky) * atkcost
  }
  if (cost == -1l)
    println(0)
  else
    println(cost)

}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(hpy, atky, defy) = in.next().split(" ").map(_.toLong)
  val Array(hpm, atkm, defm) = in.next().split(" ").map(_.toLong)
  val Array(hpcost, atkcost, defcost) = in.next().split(" ").map(_.toLong)
  var atkmin = if (atky > defm) atky else defm + 1
  var cost = -1l
  (atkmin to (hpm + defm)).foreach { atk =>
    if (cost == -1l || (atk - atky) * atkcost < cost)
      (defy to atkm).foreach { defend =>
        if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost < cost)) {
          val win = hpm / (atk - defm) + (if (hpm % (atk - defm) > 0) 1 else 0)
          val damage = win * (atkm - defend)
          val hp = if (damage >= hpy) damage - hpy + 1 else 0
          if (cost == -1l || ((atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost < cost))
            cost = (atk - atky) * atkcost + (defend - defy) * defcost + hp * hpcost
        }
      }
  }
  if (cost == -1l)
    println(0)
  else
    println(cost)

}

import scala.collection._

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(hy, ay, dy) = readLongs(3)
  val Array(hm, am, dm) = readLongs(3)
  val Array(ch, ca, cd) = readLongs(3)

  var min = Long.MaxValue

  for (a <- 0 to 100) {
    for (d <- 0 to 100) {

      def can(h: Long) = {
        (hy + h) * (ay + a - dm) > hm * (am - dy - d)
      }

      @annotation.tailrec
      def binSearch(low: Long, hi: Long): Long = {
        if (hi < low) low
        else {
          val mid = (low + hi) >>> 1
          if (can(mid)) binSearch(low, mid - 1)
          else binSearch(mid + 1, hi)
        }
      }

      val h = binSearch(0, 100000000L)

      val cost = a * ca + d * cd + h * ch

      min = Math.min(min, cost)
    }
  }

  println(min)
}

import scala.collection._

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(hy, ay, dy) = readLongs(3)
  val Array(hm, am, dm) = readLongs(3)
  val Array(ch, ca, cd) = readLongs(3)

  var min = Long.MaxValue

  for (a <- 0 to 1000) {
    for (d <- 0 to 100) {

      def can(h: Long) = {
        //(hy + h) * (ay + a - dm) > hm * (am - dy - d)
        if (am - dy - d <= 0) true
        else {
          val x = (ay + a - dm)
          if (x <= 0) false
          else {
            val steps = (hm + x - 1) / x
            if ((am - dy - d) * steps < hy + h) true
            else false
          }
        }
      }

      @annotation.tailrec
      def binSearch(low: Long, hi: Long): Long = {
        if (hi < low) low
        else {
          val mid = (low + hi) >>> 1
          if (can(mid)) binSearch(low, mid - 1)
          else binSearch(mid + 1, hi)
        }
      }

      val h = binSearch(0, 100000000L)

      //if (d == 0 && a == 0) println(h)

      val cost = a * ca + d * cd + h * ch

      min = Math.min(min, cost)
    }
  }

  println(min)
}

import scala.collection._

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(hy, ay, dy) = readLongs(3)
  val Array(hm, am, dm) = readLongs(3)
  val Array(ch, ca, cd) = readLongs(3)

  var min = Long.MaxValue

  for (a <- 0 to 100) {
    for (d <- 0 to 100) {

      def can(h: Long) = {
        //(hy + h) * (ay + a - dm) > hm * (am - dy - d)
        if (am - dy - d <= 0) true
        else {
          val x = (ay + a - dm)
          if (x <= 0) false
          else {
            val steps = (hm + x - 1) / x
            if ((am - dy - d) * steps < hy + h) true
            else false
          }
        }
      }

      @annotation.tailrec
      def binSearch(low: Long, hi: Long): Long = {
        if (hi < low) low
        else {
          val mid = (low + hi) >>> 1
          if (can(mid)) binSearch(low, mid - 1)
          else binSearch(mid + 1, hi)
        }
      }

      val h = binSearch(0, 100000000L)

      //if (d == 0 && a == 0) println(h)

      val cost = a * ca + d * cd + h * ch

      min = Math.min(min, cost)
    }
  }

  println(min)
}

import scala.collection._

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(hy, ay, dy) = readLongs(3)
  val Array(hm, am, dm) = readLongs(3)
  val Array(ch, ca, cd) = readLongs(3)

  var min = Long.MaxValue

  for (a <- 0 to 1000) {
    for (d <- 0 to 100) {

      def can(h: Long) = {
        //(hy + h) * (ay + a - dm) > hm * (am - dy - d)
        if (am - dy - d <= 0) true
        else {
          val x = (ay + a - dm)
          if (x <= 0) false
          else {
            (hy + h) * (ay + a - dm) > hm * (am - dy - d)
            /*val steps = (hm + x) * 1f / x
            if ((am - dy - d) * steps < hy + h) true
            else false*/
          }
        }
      }

      @annotation.tailrec
      def binSearch(low: Long, hi: Long): Long = {
        if (hi < low) low
        else {
          val mid = (low + hi) >>> 1
          if (can(mid)) binSearch(low, mid - 1)
          else binSearch(mid + 1, hi)
        }
      }

      val h = binSearch(0, 100000000L)

      //if (d == 0 && a == 0) println(h)

      val cost = a * ca + d * cd + h * ch

      min = Math.min(min, cost)
    }
  }

  println(min)
}

import scala.collection._

object A extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  val Array(hy, ay, dy) = readLongs(3)
  val Array(hm, am, dm) = readLongs(3)
  val Array(ch, ca, cd) = readLongs(3)

  var min = Long.MaxValue

  for (a <- 0 to 1000) {
    for (d <- 0 to 100) {

      def can(h: Long) = {
        //(hy + h) * (ay + a - dm) > hm * (am - dy - d)
        if (am - dy - d <= 0) true
        else {
          val x = (ay + a - dm)
          if (x <= 0) false
          else {
            val steps = 1d * hm / x
            if ((am - dy - d) * steps < hy + h) true
            else false
          }
        }
      }

      @annotation.tailrec
      def binSearch(low: Long, hi: Long): Long = {
        if (hi < low) low
        else {
          val mid = (low + hi) >>> 1
          if (can(mid)) binSearch(low, mid - 1)
          else binSearch(mid + 1, hi)
        }
      }

      val h = binSearch(0, 100000000L)

      //if (d == 0 && a == 0) println(h)

      val cost = a * ca + d * cd + h * ch

      min = Math.min(min, cost)
    }
  }

  println(min)
}


import java.io._
import java.util.StringTokenizer

object D {

  var out: PrintWriter = null
  var br: BufferedReader = null
  var st: StringTokenizer = null

  def main(args: Array[String]): Unit = {
    br = new BufferedReader(new InputStreamReader(System.in))
    out = new PrintWriter(new BufferedOutputStream(System.out))
    solve
    out.close
  }

  def next: String = {
    while (st == null || !st.hasMoreTokens) {
      st = new StringTokenizer(br.readLine)
    }
    return st.nextToken
  }

  def nextInt: Int = return Integer.parseInt(next)

  def nextLong: Long = return java.lang.Long.parseLong(next)

  def nextDouble: Double = return java.lang.Double.parseDouble(next)

  def checkPrime(n: Int): Boolean = {
    if (n == 1)
      return false
    var ind = 2
    var flag = false
    while (!flag && ind <= Math.sqrt(n).toInt) {
      if (n % ind == 0) {
        flag = true
      }
      ind += 1
    }
    !flag
  }

  def solve: Int = {
    val n = nextInt
    var ind = 2
    var flag = false
    if (n == 4) {
      out.println(2)
      out.println("2 2")
      return 0
    }
    while (!flag && ind <= Math.sqrt(n).toInt) {
      if (n % ind == 0) {
        flag = true
      }
      ind += 1
    }
    if (flag) {
      if (checkPrime(n - 3)) {
        out.println(2)
        out.println("3 " + (n - 3))
        return 0
      }
      out.println(3)
      out.print("3 ")
      for (i <- 2 to 1e6.toInt) {
        if (checkPrime(i) && checkPrime(n - i - 3) && n - i - 3 > 0) {
          out.println(i + " " + (n - i - 3))
          return 0
        }
      }
    } else {
      out.println(1)
      out.println(n)
    }
    return 0
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n1 = in.next().toInt
  val first = 3
  val n = n1 - first

  def isPrime(n: Int) =
    if (n == 1) false
    else if (n == 2) true
    else if (n % 2 == 0) false
    else !(3 to Math.sqrt(n).toInt + 1 by 2).exists(i => n % i == 0)

  if (n == 0) {
    println(1)
    println(3)
  } else if (isPrime(n)) {
    println(2)
    println("3 " + n)
  } else {
    val second = (2 until n).find(i => isPrime(i) && isPrime(n - i)).get
    println(3)
    println(s"3 $second ${n - second}")
  }
}

/**
 * @author netman
 */

import java.io._
import scala._
import scala.Array._
import java.util.ArrayList
import scala.collection.mutable._
import java.util.StringTokenizer

object HelloWorld {

  class InputReader(reader: BufferedReader) {

    var tokenizer: StringTokenizer = null;

    def this(stream: InputStream) = {
      this(new BufferedReader(new InputStreamReader(stream), (1 << 20)));
    }

    def this(f: File) = {
      this(new BufferedReader(new FileReader(f), (1 << 20)));
    }

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

    def nextInt(): Int = next().toInt

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

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

  class OutputWriter(writer: PrintWriter) {
    def this(stream: OutputStream) {
      this(new PrintWriter(new BufferedWriter(new OutputStreamWriter(stream))));
    }

    def this(f: File) = {
      this(new PrintWriter(new BufferedWriter(new FileWriter(f))));
    }

    def print(x: Any) = writer.print(x);

    def println(x: Any) = writer.println(x);

    def close() = writer.close();
  }

  val in = new InputReader(System.in)
  val out = new OutputWriter(System.out)

  def sieve = {
    val MAX_P = 2000
    var _isPrime = Array.fill[Boolean](MAX_P)(true)
    _isPrime(1) = false
    for (i <- 2 until MAX_P) {
      if (_isPrime(i)) {
        for (j <- i + i until MAX_P by i) {
          _isPrime(j) = false
        }
      }
    }

    var primes = ArrayBuffer.empty[Int]

    primes += 0

    for (i <- 1 until MAX_P) {
      if (_isPrime(i)) primes += i
    }

    primes
  }

  def isPrime(x: Int): Boolean = {
    if (x == 0) return true
    if (x == 1) return false
    val sqrtX = math.ceil(math.sqrt(x)).toInt
    for (i <- 2 to sqrtX) {
      if (x % i == 0) return false
    }
    return true
  }

  def main(args: Array[String]): Unit = {
    val primes = sieve

    val x = in.nextInt

    var i = 0
    while (primes(i) <= 1000 && primes(i) <= x) {
      var j = 0
      while (primes(j) <= 1000 && primes(i) + primes(j) <= x) {
        if (isPrime(x - primes(i) - primes(j))) {
          var res = ArrayBuffer.empty[Int]
          res += primes(i)
          res += primes(j)
          res += x - primes(i) - primes(j)

          while (res.indexOf(0) != -1) res.remove(res.indexOf(0))

          out.println(res.length)
          for (x <- res) {
            out.print(x + " ")
          }
          out.println("")

          out.close

          return
        }
        j += 1
      }
      i += 1
    }

    out.close
  }
}

import scala.collection.mutable

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n1 = in.next().toInt
  val first = 3
  val n = n1 - first

  def isPrime(n: Int) =
    if (n == 1) false
    else if (n == 2) true
    else !(3 to Math.sqrt(n).toInt + 1 by 2).exists(i => n % i == 0)

  if (n == 0) {
    println(1)
    println(3)
  } else {
    val set = mutable.Set(2)
    val notPrime = Array.ofDim[Boolean](n + 1)
    notPrime(1) = true
    notPrime(0) = true

    (4 to n by 2).foreach { i => notPrime(i) = true }
    (3 to n by 2).foreach { i =>
      if (!notPrime(i)) {
        set += i
        (2 * i to n by i).foreach { j => notPrime(j) = true }
      }
    }

    if (set.contains(n)) {
      println(2)
      println("3 " + n)
    } else {
      val second = set.find(i => isPrime(i) && isPrime(n - i)).get
      println(3)
      println(s"3 $second ${n - second}")
    }
  }
}


object _946B extends CodeForcesApp {
  import Utils._, annotation._, collection.{mutable, Searching}, util._, control._, math.Ordering.Implicits._, Searching._, Math._

  override def apply(io: IO): io.type = {
    var a, b = io.read[Long]

    while(a > 0 && b > 0 && (a >= 2*b || b >= 2*a)) {
      if (a >= 2*b) {
        val ka = (a - 2*b)/(2*b) max 1L
        a -= ka*(2*b)
      } else {
        val kb = (b - 2*a)/(2*a) max 1L
        b -= kb*(2*a)
      }
    }

    io.writeAll(Seq(a, b))
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
object Utils {
  import scala.collection.mutable, mutable.{Map => Dict}
  type Point = java.awt.geom.Point2D.Double
  implicit class GenericExtensions[A](val a: A) extends AnyVal {
    def in(set: collection.Set[A]): Boolean = set(a)
    def some: Option[A] = Some(a)
    def partialMatch[B](f: PartialFunction[A, B]): Option[B] = f lift a
  }
  implicit class TraversableExtensions[A, C[X] <: Traversable[X]](val t: C[A]) extends AnyVal {
    def onlyElement: A = assuming(t.size == 1)(t.head)
    def groupByIdentifier[K](f: A => K): Map[K, A] = t.groupBy(f).mapValues(_.onlyElement)
    def duplicates(implicit b: C of A): C[A] = {
      val elems = mutable.Set.empty[A]
      (t collect {case i if !elems.add(i) => i}).to[C]
    }
    def sumWith[B](f: A => B)(implicit n: Numeric[B]): B = t.foldLeft(n.zero) {case (p, i) => n.plus(p, f(i))}
    def maxWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.max)
    def minWith[B](f: A => B)(implicit ord: Ordering[B]): Option[B] = t.view.map(f).reduceOption(ord.min)
    def zipWith[B](f: A => B)(implicit b: C of (A, B)): C[(A, B)] = (t map {i => i -> f(i)}).to[C]
    def mapTo[B](f: A => B)(implicit b: C of (A, B)): Map[A, B] = zipWith(f).toUniqueMap
    def whenNonEmpty[B](f: t.type => B): Option[B] = when(t.nonEmpty)(f(t))  // e.g. grades.whenNonEmpty(_.max)
    def collectFirst[B](f: PartialFunction[A, Option[B]]): Option[B] = t.view collect f collectFirst {case Some(x) => x}
    def toMutableMultiSet: Dict[A, Int] = {
      val c = map[A] to 0
      t.foreach(i => c(i) += 1)
      c
    }
    def toMultiSet: Map[A, Int] = toMutableMultiSet.toMap withDefaultValue 0
    def X[B](s: Traversable[B]): Iterator[(A, B)] = for {a <- t.toIterator; b <- s} yield (a, b)
  }
  implicit class ArrayExtensions[A <: AnyRef](val a: Array[A]) extends AnyVal {
    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = java.util.Arrays.sort(a, from, until, cmp) //sort [from, until)
  }
  implicit class ArrayExtensions2[A](val a: Array[A]) extends AnyVal {
    def sort(from: Int = 0, until: Int = a.length)(implicit cmp: Ordering[A]): Unit = a.view(from, until).sorted.copyToArray(a, from)
  }
  implicit class SeqExtensions[A, C[X] <: Seq[X]](val s: C[A]) extends AnyVal {
    def isRotationOf(t: Seq[A]): Boolean = s ++ s containsSlice t
  }
  implicit class PairExtensions[A, B](val p: (A, B)) extends AnyVal {
    def key = p._1
    def value = p._2
    def toSeq(implicit ev: B =:= A): Seq[A] = Seq(p._1, ev(p._2))
  }
  implicit class PairsExtensions[A, B, C[X] <: Traversable[X]](t: C[(A, B)]) {
    def toUniqueMap: Map[A, B] = t.groupByIdentifier(_.key).mapValues(_.value)
    def toMultiMap(implicit b: C of B): Map[A, C[B]] = t.groupBy(_.key).mapValues(_.map(_.value).to[C]).withDefaultValue(b().result())
    def swap(implicit b: C of (B, A)): C[(B, A)] = t.map(_.swap).to[C]
  }
  implicit class MapExtensions[K, V, C[X, Y] <: Map[X, Y]](val m: C[K, V]) extends AnyVal {
    def lastKeyOption: Option[K] = m.lastOption.map(_.key)
    def firstKeyOption: Option[K] = m.headOption.map(_.key)
    def invert: Map[V, Set[K]] = m.toSet[(K, V)].swap.toMultiMap
    def mapKeys[K2](f: K => K2): Map[K2, V] = m map {case (k, v) => f(k) -> v}
    def toMutable: Dict[K, V] = Dict.empty[K, V] ++ m
    def mapValuesSafely[V2](f: V => V2): Map[K, V2] = m.mapValues(f).view.force //Hack to get around https://issues.scala-lang.org/browse/SI-4776
  }
  implicit class MutableMapExtensions[K, V](val m: mutable.Map[K, V]) extends AnyVal {
    def removeLast(): Option[(K, V)] = m.lastOption.map(removeNode)
    def removeFirst(): Option[(K, V)] = m.headOption.map(removeNode)
    private def removeNode(kv: (K, V)): (K, V) = {
      m -= kv.key
      kv
    }
  }
  implicit class SetExtensions[A, C[A] <: Set[A]](val s: C[A]) extends AnyVal {
    def notContains(x: A): Boolean = !(s contains x)
    def toMutable = mutable.Set.empty[A] ++ s
  }
  implicit class IterableExtensions[A, C[A] <: Seq[A]](val s: C[A]) extends AnyVal {
    def indicesWhere(f: A => Boolean): Seq[Int] = s.zipWithIndex.collect {case (a, i) if f(a) => i}
    def deleteAtIndex(i: Int, howMany: Int = 1) = s.patch(i, Nil, howMany)
    def insertAtIndex(i: Int, items: Seq[A]) = s.patch(i, items, 0)
    def findWithIndex(f: A => Boolean): Option[(A, Int)] = s.zipWithIndex find {case (a, _) => f(a)}
    //def foldUntil[B](z: B)(f: (B, A) => B)(c: B => Boolean): Option[(B, Int)] = s.view.scanLeft(z)(f).findWithIndex(c)
  }
  implicit class BooleanExtensions(val x: Boolean) extends AnyVal {
    def to[A](implicit n: Numeric[A]) = if(x) n.one else n.zero
    def toEnglish = if(x) "Yes" else "No"
  }
  implicit class IntExtensions(val x: Int) extends AnyVal {
    import java.lang.{Integer => JInt}
    def withHighestOneBit: Int = JInt.highestOneBit(x)
    def withLowestOneBit: Int = JInt.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JInt.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JInt.numberOfTrailingZeros(x)
    def bitCount: Int = JInt.bitCount(x)
    def setLowestBits(n: Int): Int = x | (left(n) - 1)
    def clearLowestBits(n: Int): Int = x & left(n, ~0)
    def setBit(i: Int, set: Boolean): Int = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Int = x | left(i)
    def clearBit(i: Int): Int = x & ~left(i)
    def toggleBit(i: Int): Int = x ^ left(i)
    def getBit(i: Int): Int = (x >> i) & 1
    private def left(bits: Int, num: Int = 1) = assuming(bits >= 0 && bits < JInt.SIZE)(num << bits)
    def X(y: Int): Iterator[(Int, Int)] = until(x) X until(y)
  }
  implicit class LongExtensions(val x: Long) extends AnyVal {
    import java.lang.{Long => JLong}
    def withHighestOneBitSet: Long = JLong.highestOneBit(x)
    def withLowestOneBitSet: Long = JLong.lowestOneBit(x)
    def numberOfLeadingZeroes: Int = JLong.numberOfLeadingZeros(x)
    def numberOfTrailingZeroes: Int = JLong.numberOfTrailingZeros(x)
    def bitCount: Int = JLong.bitCount(x)
    def setLowestBits(n: Int): Long = x | (left(n) - 1)
    def clearLowestBits(n: Int): Long = x & left(n, ~0L)
    def setBit(i: Int, set: Boolean): Long = if (set) setBit(i) else clearBit(i)
    def setBit(i: Int): Long = x | left(i)
    def clearBit(i: Int): Long = x & ~left(i)
    def toggleBit(i: Int): Long = x ^ left(i)
    def getBit(i: Int): Long = (x >> i) & 1
    private def left(bits: Int, num: Long = 1L) = assuming(bits >= 0 && bits < JLong.SIZE)(num << bits)
  }
  implicit class NumericExtensions[A](val x: A)(implicit n: Numeric[A]) {
    import Numeric.Implicits._
    def **(i: Int): A = if (i == 0) n.one else {
      val h = x ** (i/2)
      if (i%2 == 0) h * h else h * h * x
    }
    def distance(y: A) = (x - y).abs()
    def nonNegative: Option[A] = when(n.gteq(x, n.zero))(x)
    def whenNegative(f: => A): A = nonNegative.getOrElse(f)   //e.g. students.indexOf("Greg").whenNegative(Int.MaxValue)
  }
  implicit class IntegralExtensions[A](val x: A)(implicit n: Integral[A]) {
    import scala.collection.immutable.NumericRange, Integral.Implicits._
    def mod(y: A): A = x - ((x / y) * y) //(x/y)*y + (x mod y) == x
    def -->(y: A): NumericRange.Inclusive[A] = NumericRange.inclusive(x, y, if (n.lteq(x, y)) n.one else -n.one)
    def ceilDiv(y: A): A = if (mod(y) == n.zero) x/y else n.one + (x/y)
  }
  implicit def toPoint[A](p: (A, A))(implicit n: Numeric[A]) = new Point(n.toDouble(p._1), n.toDouble(p._2))
  def desc[A: Ordering]: Ordering[A] = asc[A].reverse  //e.g. students.sortBy(_.height)(desc)
  def asc[A](implicit order: Ordering[A]): Ordering[A] = order
  def map[K] = new {
    def to[V](default: => V): Dict[K, V] = using(_ => default)
    def using[V](f: K => V): Dict[K, V] = new mutable.HashMap[K, V]() {
      override def apply(key: K) = getOrElseUpdate(key, f(key))
    }
  }
  def newMultiMap[K, V] = map[K] to mutable.Set.empty[V]
  def memoize[A, B](f: A => B): A ==> B = map[A] using f
  implicit class FuzzyDouble(val x: Double) extends AnyVal {
    def  >~(y: Double) = x > y + eps
    def >=~(y: Double) = x >= y + eps
    def  ~<(y: Double) = y >=~ x
    def ~=<(y: Double) = y >~ x
    def  ~=(y: Double) = (x distance y) <= eps
  }
  def toPolygon(points: Traversable[(Int, Int)]): java.awt.Polygon = {
    val (xs, ys) = points.unzip
    new java.awt.Polygon(xs.toArray, ys.toArray, points.size)
  }
  def toShape(points: Traversable[(Double, Double)]): java.awt.geom.GeneralPath = {
    val shape = new java.awt.geom.GeneralPath()
    points.headOption foreach {case (x, y) => shape.moveTo(x, y)}
    points.tail foreach {case (x, y) => shape.lineTo(x, y)}
    shape.closePath()
    shape
  }
  def isPrime(n: Int): Boolean = BigInt(n).isProbablePrime(31)
  def until(until: Int): Range = 0 until until
  def not[A](f: A => Boolean): A => Boolean = {x: A => !f(x)}
  def assuming[A](cond: => Boolean)(f: => A): A = {require(cond); f}
  @inline def when[A](check: Boolean)(f: => A): Option[A] = if (check) f.some else None
  def repeat[U](n: Int)(f: => U): Unit = (1 to n).foreach(_ => f)
  type of[C[_], A] = scala.collection.generic.CanBuild[A, C[A]]
  type ==>[A, B] = collection.Map[A, B]
  val mod: Int = (1e9 + 7).toInt
  val eps: Double = 1e-9
}
/***********************************[Scala I/O]*********************************************/
import Utils._, java.io._, java.util.StringTokenizer

class IO(in: BufferedReader, out: BufferedWriter) extends Iterator[String] with AutoCloseable with Flushable {
  def this(reader: Reader, writer: Writer) = this(new BufferedReader(reader), new BufferedWriter(writer))
  def this(in: InputStream, out: OutputStream) = this(new InputStreamReader(in), new OutputStreamWriter(out))

  private[this] val tokenizers = Iterator.continually(in.readLine()).takeWhile(_ != null).map(new StringTokenizer(_)).buffered
  val printer = new PrintWriter(out, true)

  @inline private[this] def tokenizer() = {
    while(tokenizers.nonEmpty && !tokenizers.head.hasMoreTokens) tokenizers.next()
    when(tokenizers.nonEmpty)(tokenizers.head)
  }

  def read[A](implicit read: IO.Read[A]): A = read.apply(this)
  def read[C[_], A: IO.Read](n: Int)(implicit b: C of A): C[A] = Iterator.fill(n)(read).to[C]

  def readTill(delim: String): String = tokenizer().get.nextToken(delim)
  def readTillEndOfLine(): String = readTill("\n\r")

  def readAll[A: IO.Read]: (Int, Vector[A]) = {
    val data = read[Vector[A]]
    (data.length, data)
  }

  override def next() = tokenizer().get.nextToken()
  override def hasNext = tokenizer().nonEmpty

  def write(obj: Any): this.type = {
    printer.print(obj)
    this
  }
  def writeLine(): this.type = {
    printer.println()
    this
  }
  def writeLine(obj: Any): this.type = {
    printer.println(obj)
    this
  }
  def writeAll(obj: Traversable[Any], separator: String = " "): this.type = write(obj mkString separator)
  def query[A: IO.Read](question: Any): A = writeLine(question).read

  override def flush() = printer.flush()
  def close() = {
    flush()
    in.close()
    printer.close()
  }
}
object IO {
  class Read[A](val apply: IO => A) {
    def map[B](f: A => B): Read[B] = new Read(apply andThen f)
  }
  object Read {
    implicit def collection[C[_], A: Read](implicit b: C of A): Read[C[A]]         = new Read(r => r.read[C, A](r.read[Int]))
    implicit val string                                       : Read[String]       = new Read(_.next())
    implicit val char                                         : Read[Char]         = string.map(_.toTraversable.onlyElement)
    implicit val int                                          : Read[Int]          = string.map(_.toInt)
    implicit val long                                         : Read[Long]         = string.map(_.toLong)
    implicit val bigInt                                       : Read[BigInt]       = string.map(BigInt(_))
    implicit val double                                       : Read[Double]       = string.map(_.toDouble)
    implicit val bigDecimal                                   : Read[BigDecimal]   = string.map(BigDecimal(_))
    implicit def tuple2[A: Read, B: Read]                     : Read[(A, B)]       = new Read(r => (r.read[A], r.read[B]))
    implicit def tuple3[A: Read, B: Read, C: Read]            : Read[(A, B, C)]    = new Read(r => (r.read[A], r.read[B], r.read[C]))
    implicit def tuple4[A: Read, B: Read, C: Read, D: Read]   : Read[(A, B, C, D)] = new Read(r => (r.read[A], r.read[B], r.read[C], r.read[D]))
    implicit val boolean                                      : Read[Boolean]      = string map {s =>
      s.toLowerCase match {
        case "yes" | "true" | "1" => true
        case "no" | "false" | "0" => false
        case _ => s.toBoolean
      }
    }
  }
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }

  var Array(a, b) = readLongs(2)

  var changed = true
  while (a != 0 && b != 0 && changed) {
    if (a >= 2 * b) {
      var bb = b
      while (2 * bb <= a) bb *= 2
      a -= bb
    } else if (b >= 2 * a) {
      var aa = a
      while (2 * aa <= b) aa *= 2
      b -= aa
    } else changed = false
  }

  println(s"$a $b")
}

object B extends App {
  val Array(n, m) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

  def weird(a: Long, b: Long): (Long, Long) =
    if (a == 0 || b == 0) (a, b)
    else {
      val ra = a % (2 * b)
      if (ra != a) weird(ra, b)
      else {
        val rb = b % (2 * a)
        if (rb != b) weird(a, rb)
        else (a, b)
      }
    }

  val (a, b) = weird(n, m)
  println(a + " " + b)
}

object BWeirdSubtractionProcess extends App {
  val Array(n, m) = scala.io.StdIn.readLine().split(" ").map(_.toLong)

  def weird(a: Long, b: Long): (Long, Long) =
    if (a == 0 || b == 0) (a, b)
    else {
      val _b = 2 * b
      if (a >= _b) weird(a % _b, b)
      else {
        val _a = 2 * a
        if (b >= _a) weird(a, b % _a)
        else (a, b)
      }
    }

  val (a, b) = weird(n, m)
  println(a + " " + b)
}

object B extends App {

  @inline def tokenizeLine = new java.util.StringTokenizer(readLine)
  def readInts(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toInt) }
  def readLongs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(tl.nextToken.toLong) }
  def readBigs(n: Int) = { val tl = tokenizeLine; Array.fill(n)(BigInt(tl.nextToken)) }

  var Array(a, b) = readLongs(2)

  var changed = true
  while (a * b != 0 && changed) {
    if (a >= 2 * b) {
      changed = true
      var bb = b
      while (2 * bb <= a) bb *= 2
      a -= bb
    } else if (b >= 2 * a) {
      changed = true
      var aa = a
      while (2 * aa <= b) aa *= 2
      b -= aa
    } else changed = false
  }

  println(s"$a $b")
}


object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  val sum = in.next().split(" ").map(_.toInt).sum
  println((1 to 5).count(i => (i + sum - 1) % (n + 1) != 0))
}

object CF272A {
    def main(argv: Array[String]) {
        val n = readInt
        val str = readLine.split(" ")
        def readSum(i: Int, acc: Int): Int = {
            if (i == n) acc
            else readSum(i + 1, acc + str(i).toInt)
        }
        val sum = readSum(0, 0)
        def findAns(i: Int, acc: Int): Int = {
            if (i == 6) acc
            else {
                if ((sum + i) % (n + 1) != 1) findAns(i + 1, acc + 1)
                else findAns(i + 1, acc)
            }
        }
        println(findAns(1, 0))
    }
}

import java.util.StringTokenizer

object _272A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val sum = (1 to n).map(i => next.toInt).sum
  val cb = (1 to 5).filter(i => (i + sum) % (n + 1) != 1)
  println(cb.size)
}

object A272 {

  import IO._
  import collection.{mutable => cu}

  def solve(arr: Array[Int], fing: Int): Boolean = {
    (arr.sum + fing)%(arr.length+1) != 1
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    out.println((1 to 5).count(fing => solve(in, fing)))
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

import java.util.Scanner
import java.io.PrintWriter
import scala.annotation.tailrec
import scala.collection.mutable
import scala.util.Random

object P272A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  val N = sc.nextInt
  val fs = List.fill(N)(sc.nextInt).sum

  val answer: Int = {
    for {
      i <- 1 to 5
      if ((fs + i - 1) % (N + 1) > 0)
    }
    yield 1
  }.sum

  out.println(answer)
  out.close
}

import java.util._

object Main {
    def main(args: Array[String]) {
        val in = new Scanner(System.in)
        val n = in.nextInt
        var s = 0
        for (i <- 0 to n - 1) {
            s += in.nextInt
        }

        var cnt = 0
        for (i <- 1 to 5) {
           if ((s + i) % (n + 1) != 1) {
               cnt += 1
           }
        }
        println(cnt)
    }
}

object Fuck {
  def main(args: Array[String]) {
    var n = readInt()+1
    var a = readLine().split(" ").toList map (_.toInt) sum;
    println(Range(1,6) count (x => (x+a) % n != 1))
  }
}

import annotation.tailrec
import java.io._

object Easy {
  val reader = new BufferedReader(new InputStreamReader(System.in))
  def readInts = reader.readLine().split(" ").map(_.toInt)
  def readInt = reader.readLine().toInt

  val n = readInt
  val fingers = readInts.sum
  def ans = (1 to 5).count(x => (x + fingers) % (n + 1) != 1)

  def main(args: Array[String]) {
    println(ans)
  }
}

object A
{
    def main(args: Array[String])
    {
        val n = readLine.toInt
        val fingers= readLine.split(" ").map(_.toInt).sum
        println((1 to 5) map(_+fingers) filter(_%(n+1)!=1) length)
    }
}

object A
{
    def main(args: Array[String])
    {
        val n = readLine.toInt
        val fingers= readLine.split(" ").map(_.toInt).sum
        println((1 to 5) filter{x=>(x+fingers)%(n+1)!=1} length)
    }
}

import collection.mutable.Map
import collection.mutable.ArrayBuffer

object test6 extends App {
    val n=readInt
    val total=readLine.split(" ").map(_.toInt).sum

    val ans=(for(i<-1 to 5) yield {
        if((total+i)%(n+1)==1) 0 else 1
    }) sum

    println(ans)
}

object Main {
  def main(args: Array[String]) {
    val n = readInt
    val sum = readLine().split(" ").map(_.toInt).sum
    val r = (1 to 5).foldLeft(0) { (acc, i) =>
      if ((sum + i) % (n + 1) == 1) acc
      else acc + 1
    }
    println(r)
  }
}

object A272 {

  import IO._
  import collection.{mutable => cu}

  def solve(arr: Array[Int], fing: Int): Boolean = {
    (arr.sum + fing)%(arr.length+1) != 1
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    var break = false
    for(fing <- 2 to 5 if !break) {
      if(solve(in, fing)) {
        out.println(fing)
        break = true
      }
    }
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object A272 {

  import IO._
  import collection.{mutable => cu}

  def solve(arr: Array[Int], fing: Int): Boolean = {
    (arr.sum + fing)%(arr.length+1) == 0
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    var break = false
    for(fing <- 1 to 5 if !break) {
      if(solve(in, fing)) {
        out.println(fing)
        break = true
      }
    }
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}

object A272 {

  import IO._
  import collection.{mutable => cu}

  def solve(arr: Array[Int], fing: Int): Boolean = {
    (arr.sum + fing)%(arr.length+1) == 0
  }

  def main(args: Array[String]): Unit = {
    val Array(n) = readInts(1)
    val in = readInts(n)
    var break = false
    for(fing <- 2 to 5 if !break) {
      if(solve(in, fing)) {
        out.println(fing)
        break = true
      }
    }
    out.close()
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))
    //    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(new java.io.FileInputStream("src/input")))
    val out = new java.io.PrintWriter(System.out)

    @inline def read: String = input.readLine()

    @inline def tokenizeLine = new java.util.StringTokenizer(read)

    def readInt: Int = tokenizeLine.nextToken.toInt

    def readInts(n: Int): Array[Int] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toInt)
    }

    def readLongs(n: Int): Array[Long] = {
      val tl = tokenizeLine
      Array.fill(n)(tl.nextToken.toLong)
    }

    def readBigs(n: Int): Array[BigInt] = {
      val tl = tokenizeLine
      Array.fill(n)(BigInt(tl.nextToken))
    }
  }

}