One day Misha and Andrew were playing a very simple game. First, each player chooses an integer in the range from 1 to n. Let's assume that Misha chose number m, and Andrew chose number a.Then, by using a random generator they choose a random integer c in the range between 1 and n (any integer from 1 to n is chosen with the same probability), after which the winner is the player, whose number was closer to c. The boys agreed that if m and a are located on the same distance from c, Misha wins.Andrew wants to win very much, so he asks you to help him. You know the number selected by Misha, and number n. You need to determine which value of a Andrew must choose, so that the probability of his victory is the highest possible.More formally, you need to find such integer a (1 ≤ a ≤ n), that the probability that  is maximal, where c is the equiprobably chosen integer from 1 to n (inclusive).

The first line contains two integers n and m (1 ≤ m ≤ n ≤ 109) — the range of numbers in the game, and the number selected by Misha respectively.

Print a single number — such value a, that probability that Andrew wins is the highest. If there are multiple such values, print the minimum of them.

NoteIn the first sample test: Andrew wins if c is equal to 2 or 3. The probability that Andrew wins is 2 / 3. If Andrew chooses a = 3, the probability of winning will be 1 / 3. If a = 1, the probability of winning is 0.In the second sample test: Andrew wins if c is equal to 1 and 2. The probability that Andrew wins is 1 / 2. For other choices of a the probability of winning is less.

import scala.io.StdIn._
object B extends App{
  val Array(n,m) = readLine().split(" ").map(_.toLong)
  if (2*m-1 >= n){
    println(Math.max(m-1,1))
  }else{
    println(Math.min(n,m+1))
  }
}

object B570 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    var maxAndrew = 0
    var res = n-m+1
    Array(m+1, m-1).foreach{
      case a if a > 0 && a <= n =>
        var andrew = 0
        if(a == m+1) {
          andrew = n - m - 1
        } else {
          andrew = m-1
        }
        if(andrew > maxAndrew) {
          maxAndrew = andrew
          res = a
        }
      case _ =>
    }
    println(res)
  }

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

}

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

import scala.collection.mutable

object B {

  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)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  /**
   * Segment tree for any commutative function
   * @param values Array of Int
   * @param commutative function like min, max, sum
   * @param zero zero value - e.g. 0 for sum, Inf for min, max
   */
  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {
    private val SIZE = 1e5.toInt
    private val n = values.length
    val t = new Array[Int](2 * n)
    Array.copy(values, 0, t, n, n)

    // build segment tree
    def build = {
      for (i <- n - 1 until 0 by -1) {
        t(i) = commutative(t(2 * i), t(2 * i + 1))
      }
    }

    // change value at position p to x
    // TODO beatify
    def modify(p: Int, x: Int) = {
      var pos = p + n
      t(pos) = x
      while (pos > 1) {
        t(pos / 2) = commutative(t(pos), t(pos ^ 1))
        pos /= 2
      }
    }

    // TODO implement me!
    def modify(p: Int, left: Int, right: Int) = ???

    def query(p: Int) = ???

    // sum [l, r)
    // min l = 0
    // max r = n
    // TODO beatify
    def query(left: Int, right: Int): Int = {
      var res = zero
      var r = right + n
      var l = left + n
      while (l < r) {
        if (l % 2 == 1) {
          res = commutative(res, t(l))
          l += 1
        }
        if (r % 2 == 1) {
          r -= 1
          res = commutative(res, t(r))
        }
        l /= 2
        r /= 2
      }
      res
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    if (n == 1) {
      out.println(1)
      return 0
    }
    val abs = n - m
    if (abs > m) {
      out.println(m + 1)
    } else if (abs < m){
      out.println(m - 1)
    } else {
      out.println(m + 1)
    }
    return 0
  }
}

import io.StdIn._
import scala.collection.mutable
import scala.collection.mutable._

object Solution {

  def main(args: Array[String]) {
    val Array(n, m) = readLine().split(" ").map(_.toInt)

    println (if (m <= n/2) Math.min(n,m+1) else Math.max(1,m-1))
  }
}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _570B extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  (n, m) match {
    case (1, _) => 1
    case (_, 1) => 2
    case (_, `n`) => n-1
    case _  => m + (if (m <= n / 2) 1 else -1)
  }
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  import scala.collection.mutable.{Map => Dict}
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0
}

import scala.io.StdIn._

object SomeTest extends App {
  val Array(n, m) = readLine().split(" ").map(_.toLong)

  if (n == 1) println(1)
  else if (n - m > m - 1) {
    println(m + 1)
  } else {
    println(m - 1)
  }
}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object SimpleGame {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def readTuple() : (Int,Int) = {
     val line = readInts
     (line(0),line(1))
   }
   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }

   def main(args: Array[String]) {
     val (n,m) = readTuple()
     if (m <= n/2) println(Math.min(m+1,n)) else println(Math.max(m-1,1))
   }

}

import scala.io.StdIn._
object B extends App{
  val Array(n,m) = readLine().split(" ").map(_.toInt)
  if (2*m-1 >= n){
    println(m-1)
  }else{
    println(m+1)
  }
}

import scala.io.StdIn._
object B extends App{
  val Array(n,m) = readLine().split(" ").map(_.toLong)
  if (2*m-1 >= n){
    println(m-1)
  }else{
    println(m+1)
  }
}

import scala.io.StdIn._
object B extends App{
  val Array(n,m) = readLine().split(" ").map(_.toLong)
  if (2*m-1 >= n){
    println(Math.max(m-1,0))
  }else{
    println(Math.min(n,m+1))
  }
}

import scala.io.StdIn._
object B extends App{
  val Array(n,m) = readLine().split(" ").map(_.toInt)
  if (2*m-1 <= n){
    println(m+1)
  }else{
    println(m-1)
  }
}

object B570 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    var maxAndrew = 0
    var res = 0
    Array(m+1, m-1).foreach{
      case a if a > 1 && a <= n =>
        var andrew = 0
        if(a == m+1) {
          andrew = n - (m+1)
        } else {
          andrew = m-1
        }
        if(andrew > maxAndrew) {
          maxAndrew = andrew
          res = a
        }
      case _ =>
    }
    println(res)
  }

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

}

object B570 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    var maxAndrew = 0
    var res = 1
    Array(m+1, m-1).foreach{
      case a if a > 0 && a <= n =>
        var andrew = 0
        if(a == m+1) {
          andrew = n - m
        } else {
          andrew = a
        }
        if(andrew > maxAndrew) {
          maxAndrew = andrew
          res = a
        }
      case _ =>
    }
    println(res)
  }

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

}

object B570 {

  import IO._

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    var maxAndrew = 0
    var res = 1
    Array(m+1, m-1).foreach{
      case a if a > 1 && a <= n =>
        var andrew = 0
        if(a == m+1) {
          andrew = n - (m+1)
        } else {
          andrew = m-1
        }
        if(andrew > maxAndrew) {
          maxAndrew = andrew
          res = a
        }
      case _ =>
    }
    println(res)
  }

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

}

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

import scala.collection.mutable

object B {

  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)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  /**
   * Segment tree for any commutative function
   * @param values Array of Int
   * @param commutative function like min, max, sum
   * @param zero zero value - e.g. 0 for sum, Inf for min, max
   */
  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {
    private val SIZE = 1e5.toInt
    private val n = values.length
    val t = new Array[Int](2 * n)
    Array.copy(values, 0, t, n, n)

    // build segment tree
    def build = {
      for (i <- n - 1 until 0 by -1) {
        t(i) = commutative(t(2 * i), t(2 * i + 1))
      }
    }

    // change value at position p to x
    // TODO beatify
    def modify(p: Int, x: Int) = {
      var pos = p + n
      t(pos) = x
      while (pos > 1) {
        t(pos / 2) = commutative(t(pos), t(pos ^ 1))
        pos /= 2
      }
    }

    // TODO implement me!
    def modify(p: Int, left: Int, right: Int) = ???

    def query(p: Int) = ???

    // sum [l, r)
    // min l = 0
    // max r = n
    // TODO beatify
    def query(left: Int, right: Int): Int = {
      var res = zero
      var r = right + n
      var l = left + n
      while (l < r) {
        if (l % 2 == 1) {
          res = commutative(res, t(l))
          l += 1
        }
        if (r % 2 == 1) {
          r -= 1
          res = commutative(res, t(r))
        }
        l /= 2
        r /= 2
      }
      res
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    if (n == 1) {
      out.println(1)
      return 0
    }
    val abs: Int = Math.abs(n - m)
    if (abs > m) {
      out.println(m + 1)
    } else if (abs < m){
      out.println(m - 1)
    } else {
      out.println(m - 1)
    }
    return 0
  }
}

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

import scala.collection.mutable

object B {

  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)

  class MultiHashSet[T <% Comparable[T]] {
    val map = new mutable.HashMap[T, Int]()

    def count(x: T): Int = {
      return map.getOrElse(x, 0)
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  class MultiTreeSet[T <% Comparable[T]] {
    val map = new TreeMap[T, Int]()

    def count(x: T): Int = {
      val res = map.get(x)
      if (res == null)
        return 0
      return res
    }

    def add(x: T): Unit = map.put(x, count(x) + 1)

    def first(): T = return map.firstKey()

    def last(): T = return map.lastKey()

    def remove(x: T): Boolean = {
      val prev = count(x)
      if (prev == 0)
        return false
      if (prev == 1) {
        map.remove(x)
      } else {
        map.put(x, prev - 1)
      }
      return true
    }
  }

  /**
   * Segment tree for any commutative function
   * @param values Array of Int
   * @param commutative function like min, max, sum
   * @param zero zero value - e.g. 0 for sum, Inf for min, max
   */
  class SegmentTree(values: Array[Int])(commutative: (Int, Int) => Int)(zero: Int) {
    private val SIZE = 1e5.toInt
    private val n = values.length
    val t = new Array[Int](2 * n)
    Array.copy(values, 0, t, n, n)

    // build segment tree
    def build = {
      for (i <- n - 1 until 0 by -1) {
        t(i) = commutative(t(2 * i), t(2 * i + 1))
      }
    }

    // change value at position p to x
    // TODO beatify
    def modify(p: Int, x: Int) = {
      var pos = p + n
      t(pos) = x
      while (pos > 1) {
        t(pos / 2) = commutative(t(pos), t(pos ^ 1))
        pos /= 2
      }
    }

    // TODO implement me!
    def modify(p: Int, left: Int, right: Int) = ???

    def query(p: Int) = ???

    // sum [l, r)
    // min l = 0
    // max r = n
    // TODO beatify
    def query(left: Int, right: Int): Int = {
      var res = zero
      var r = right + n
      var l = left + n
      while (l < r) {
        if (l % 2 == 1) {
          res = commutative(res, t(l))
          l += 1
        }
        if (r % 2 == 1) {
          r -= 1
          res = commutative(res, t(r))
        }
        l /= 2
        r /= 2
      }
      res
    }
  }

  def solve: Int = {
    val n = nextInt
    val m = nextInt
    if (n == 1) {
      out.println(1)
      return 0
    }
    val mid = n / 2 + n % 2
    if (m > mid) {
      out.println(mid)
    } else if (m < mid) {
      out.println(m + 1)
    } else {
      out.println(m - 1)
    }
    return 0
  }
}

import io.StdIn._
import scala.collection.mutable
import scala.collection.mutable._

object Solution {

  def main(args: Array[String]) {
    val Array(n, m) = readLine().split(" ").map(_.toInt)

    println (if (m < (n+1)/2) m+1 else m-1)
  }
}

import io.StdIn._
import scala.collection.mutable
import scala.collection.mutable._

object Solution {

  def main(args: Array[String]) {
    val Array(n, m) = readLine().split(" ").map(_.toInt)

    println (if (m <= n/2) m+1 else m-1)
  }
}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _570B extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  if (m < n/2) {
    m+1
  } else if (m > n/2) {
    m-1
  } else {
    if (n%2 == 1) m+1 else m-1
  }
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  import scala.collection.mutable.{Map => Dict}
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0
}

import annotation.tailrec, collection.mutable, util._, control.Breaks._, math.Ordering.Implicits._
import CodeForcesApp._
object _570B extends CodeForcesApp[Int]({scanner => import scanner._
  val (n, m) = (nextInt, nextInt)
  (n, m) match {
    case (1, _) => 1
    case (2, 1) => 2
    case (2, 2) => 1
    case (3, 1) => 2
    case (3, 2) => 1
    case (3, 3) => 1
    case _ if m <= n/2 => m+1
    case _ if m > n/2 => m-1
  }
})
import java.util.Scanner
abstract class CodeForcesApp[A](solver: Scanner => A) {
  final def apply(problem: String): String = apply(new Scanner(problem))
  final def apply(scanner: Scanner): String = format(solver(scanner))
  def format(result: A): String = result.toString
  final def main(args: Array[String]): Unit = println(apply(new Scanner(System.in)))
}
object CodeForcesApp {
  import scala.collection.mutable.{Map => Dict}
  final val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  final def debug(x: Any): Unit = if (!isOnlineJudge) println(x)
  final val modulus: Int = 1000000007
  final val eps: Double = 1e-9
  final def when[A](check: Boolean)(f: => A): Option[A] = if (check) Some(f) else None
  final def repeat[A](n: Int)(f: => A): Seq[A] = 1 to n map {_ => f}
  final def newCounter[A]: Dict[A, Int] = Dict.empty[A, Int] withDefaultValue 0
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toLong)
  val Half = Math.ceil(n / 2.0).toLong

  if (m >= Half) {
    println(m - 1)
  } else {
    println(m + 1)
  }
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toLong)
  val Half = Math.ceil(n / 2.0)

  if (m >= Half) {
    println(m - 1)
  } else if (m < Half) {
    println(m + 1)
  }
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toLong)
  val Half = Math.ceil(n / 2.0)

  if (n == 1) println(1)
  else if (m >= Half) {
    println(m - 1)
  } else if (m < Half) {
    println(m + 1)
  }
}

import scala.io.StdIn._

object B extends App {
  val Array(n, m) = readLine().split(" ").map(_.toLong)
  val Half = Math.ceil(n / 2.0).toInt

  if (m >= Half) {
    println(m - 1)
  } else {
    println(m + 1)
  }
}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object SimpleGame {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def readTuple() : (Int,Int) = {
     val line = readInts
     (line(0),line(1))
   }
   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }

   def main(args: Array[String]) {
     val (n,m) = readTuple()
     if (m <= n/2) println(m+1) else println(m-1)
   }

}


Ann has recently started commuting by subway. We know that a one ride subway ticket costs a rubles. Besides, Ann found out that she can buy a special ticket for m rides (she can buy it several times). It costs b rubles. Ann did the math; she will need to use subway n times. Help Ann, tell her what is the minimum sum of money she will have to spend to make n rides?

The single line contains four space-separated integers n, m, a, b (1 ≤ n, m, a, b ≤ 1000) — the number of rides Ann has planned, the number of rides covered by the m ride ticket, the price of a one ride ticket and the price of an m ride ticket.

Print a single integer — the minimum sum in rubles that Ann will need to spend.

NoteIn the first sample one of the optimal solutions is: each time buy a one ride ticket. There are other optimal solutions. For example, buy three m ride tickets.

object Main extends App {
  val in = readLine
  val Array(n, m, a, b) = in.split(" ").map(_.toInt)
  if (m * a <= b)
    println(a * n)
  else
    println((n / m) * b + (if (n % m > 0) Math.min(b, n % m * a) else 0))
}

object Main {
   def main(args: Array[String]): Unit = {
val Array(n,m,a,b) = scala.io.StdIn.readLine().split(' ').map(_.toInt)
println(scala.math.min(n/m*b+scala.math.min(n%m*a, b), n*a))
      }
    }

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, m, a, b) = in.next().split(" ").map(_.toInt)
  if (m * a <= b)
    println(a * n)
  else {
    println((n / m) * b + (if (n % m > 0) Math.min(b, n % m * a) else 0))
  }

}

import scala.collection.JavaConversions._

object Codeforces466A {
    def main(args: Array[String]) {
        val Array(n, m, a, b) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
        if (b.toFloat/m > a) {
            println(n*a)
        }
        else {
            val x = n / m
            val y = n % m
            if (y > 0) {
                if (y*a < b)
                    println(x*b + y*a)
                else
                    println(x*b + b)
            }
            else
                println(x*b)
        }
    }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
import scala.util.Sorting._
import scala.math._
import scala.collection._
import java.util._

object HelloWorld {
  def main(args: Array[String]): Unit = {
    val Array(n, m, a, b) = readLine.split(" ").map(_.toInt)

    var ans = Int.MaxValue
    for(i <- 0 to n){
      var by_one = i
      var by_one_price = by_one * a

      var remained_tickets = n - i
      if(remained_tickets >= 0){
        var by_m = (remained_tickets + (m - 1)) / m
        var by_m_price = by_m * b

        ans = Array(ans, by_one_price + by_m_price).min
      }
    }

    println(ans)
  }
}

object A466 {
  @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))
  }

  def main(args: Array[String]): Unit = {
    val Array(n, m, a, b) = readInts(4)

    var res = n * a
    res = math.min(res, b*(if(n%m == 0) n/m else n/m + 1) )
    res = math.min(res, if(n%m == 0) b*(n/m) else b*(n/m) + a*(n%m))
    println(res)
  }
}

import java.util._
import java.io._
import java.util
import scala.annotation.tailrec

object A {

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

  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 solve: Int = {
    val n = nextInt
    val m = nextInt
    val a = nextInt
    val b = nextInt
    var min = Int.MaxValue
    for (i <- 0 to n / m + 1) {
      var temp = i * b
      val x: Int = n - (i * m)
      if ( x > 0) {
        temp += x * a
      }
      min = Math.min(min, temp)
    }
    out.println(min)
    return 1
  }

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

object CheapTravel {
	def main (args: Array[String]) {
		//Parsing the input
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
		val m = scanner.nextInt();
		val a = scanner.nextInt();
		val b = scanner.nextInt();
		// Check whether it is cheaper to buy m-rides tickets
		if (a*m >= b) {
		  val lastTicket = if ((n%m * a) < b) n%m*a else b
			println(n / m * b + lastTicket)
		}
		else
			println(n * a)
	}
}

object Main {
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val n = cin.nextInt()
    val m = cin.nextInt()
    val a = cin.nextInt()
    val b = cin.nextInt()
    println(Math.min(Math.min(n * a, (n / m) * b + (n % m) * a), ((n + m - 1) / m) * b))
  }
}

//package xubiker.archive

import java.util.Scanner

object Task_466A extends App {

  val sc = new Scanner(System.in)

  val n = sc.nextInt()
  val m = sc.nextInt()
  val a = sc.nextInt()
  val b = sc.nextInt()

  sc.close()

  val price1 = (Math.ceil(n.toDouble / m) * b).toInt
  val price2 = a * n
  val price3 = (n / m) * b + (n % m) * a

  val price = price1.min(price2.min(price3))
  println(price)

}

import scala.io.StdIn.readLine
import scala.io.StdIn.readInt

object CheapTravel {

   def readInts() : Array[Int] =
     readLine.split(' ').map(_.toInt)

   def readLongs() : Array[Long] =
      readLine.split(' ').map(_.toLong)

   def readTuple() : (Int,Int) = {
     val line = readInts
     (line(0),line(1))
   }
   def readTupleLong() : (Long,Long) = {
     val line = readLongs
     (line(0),line(1))
   }

   def readTriple() : (Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2))
   }
   def readQuad() : (Int,Int,Int,Int) = {
     val line = readInts
     (line(0),line(1),line(2),line(3))
   }

   def main(args: Array[String]) {
     val (n,m,a,b) = readQuad()
     val pricePerRide = b.toDouble/m
     if (pricePerRide >= a) println(a*n) // always by single tickets
     else {
       val priceRem = if ( (n%m)*a <= b) (n%m)*a else b
       println( (n/m)*b + priceRem)
     }
   }

}

import scala.io.StdIn._

object Main2 extends App {
  val Array(ridesNumber, subscriptionRidesNumber, ridePrice, subscriptionPrice) = readLine().split(" ").map(_.toInt)
  val ans = if (subscriptionRidesNumber * ridePrice > subscriptionPrice) {
    val priceWithGreedySubscriptions = (ridesNumber/subscriptionRidesNumber) * subscriptionPrice
    val remainingRides = ridesNumber%subscriptionRidesNumber
    if (remainingRides * ridePrice < subscriptionPrice) {
      priceWithGreedySubscriptions + remainingRides * ridePrice
    } else {
      priceWithGreedySubscriptions + subscriptionPrice
    }
  } else {
    ridesNumber * ridePrice
  }
  println(ans)
}

import scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val Array(n,m,a,b) = StdIn.readLine().split(" ").map(_.toInt)

    var ans = 10000000;
    for(i <- 0 to 1000) {
      ans = math.min(ans, b * i + math.max(n - m * i,0) * a)
    }

    println(ans)

  }

}

object Main {
   def main(args: Array[String]): Unit = {
val Array(n,m,a,b) = scala.io.StdIn.readLine().split(' ').map(_.toInt)
println(n/m*b+n%m*a)
      }
    }

import scala.io.StdIn

object Task466A {
	def main(args: Array[String]) {
		val nmab = StdIn.readLine().split(" ").map(_.toInt)
		if (nmab(3).toDouble / nmab(1) < nmab(2))
			println(nmab(0) / nmab(1) * nmab(3) + Math.min(nmab(2), nmab(3)))
		else println(nmab(0) * nmab(2))
	}
}

import scala.io.StdIn

object Task466A {
	def main(args: Array[String]) {
		val nmab = StdIn.readLine().split(" ").map(_.toInt)
		if (nmab(3).toDouble / nmab(1) < nmab(2))
			println(nmab(0) / nmab(1) * nmab(3) + nmab(0) % nmab(1) * Math.min(nmab(2), nmab(3)))
		else println(nmab(0) * nmab(2))
	}
}

import scala.io.StdIn

object Task466A {
	def main(args: Array[String]) {
		val nmab = StdIn.readLine().split(" ").map(_.toInt)
		println(if (nmab(3).toDouble / nmab(1) < nmab(2))
			if (nmab(0).toDouble / nmab(1) < 1) nmab(3)
			else nmab(0) / nmab(1) * nmab(3) + nmab(0) % nmab(1) * Math.min(nmab(2), nmab(3))
		else nmab(0) * nmab(2))
	}
}

import scala.collection.JavaConversions._

object Codeforces468A {
    def main(args: Array[String]) {
        val Array(n, m, a, b) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
        if (m.toFloat/b > a) {
            println(n*a)
        }
        else {
            println((n/m)*b + (n%m)*a)
        }
    }
}

import scala.collection.JavaConversions._

object Codeforces466A {
    def main(args: Array[String]) {
        val Array(n, m, a, b) = scala.io.StdIn.readLine().split(" ").map(_.toInt)
        if (m.toFloat/b > a) {
            println(n*a)
        }
        else {
            val x = n / m
            val y = n % m
            if (y*a < b)
                println((n/m)*b + (n%m)*a)
            else
                println((n/m)*b + b)
        }
    }
}

import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn._
import scala.util.Sorting._
import scala.math._
import scala.collection._
import java.util._

object HelloWorld {
  def main(args: Array[String]): Unit = {
    val Array(n, m, a, b) = readLine.split(" ").map(_.toInt)

    var ans = Int.MaxValue
    for(i <- 0 to n){
      var by_one = i
      var by_one_price = by_one * a

      var remained_tickets = n - i
      if(remained_tickets > 0){
        var by_m = (remained_tickets + (m - 1)) / m
        var by_m_price = by_m * b

        ans = Array(ans, by_one_price + by_m_price).min
      }
    }

    println(ans)
  }
}

import java.util._
import java.io._
import java.util
import scala.annotation.tailrec

object A {

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

  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 solve: Int = {
    val n = nextInt
    val m = nextInt
    val a = nextInt
    val b = nextInt
    var min = Int.MaxValue
    for (i <- 0 to n / m) {
      min = Math.min(min, i * b + (n - (i * m)) * a)
    }
    out.println(min)
    return 1
  }

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

import java.util._
import java.io._
import java.util
import scala.annotation.tailrec

object A {

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

  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 solve: Int = {
    val n = nextInt
    val m = nextInt
    val a = nextInt
    val b = nextInt
    out.println(Math.min(n * a, (n / m) * b + (n % m) * a))
    return 1
  }

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

object CheapTravel {
	def main (args: Array[String]) {
		//Parsing the input
		val scanner = new java.util.Scanner(System.in);
		val n = scanner.nextInt();
		val m = scanner.nextInt();
		val a = scanner.nextInt();
		val b = scanner.nextInt();
		// Check whether it is cheaper to buy m-rides tickets
		if (a*m >= b)
			println(n / m * b + n%m * a)
			else
				println(n * a)
	}
}

import scala.io.StdIn._

object Main2 extends App {
  val Array(ridesNumber, subscriptionRidesNumber, ridePrice, subscriptionPrice) = readLine().split(" ").map(_.toInt)
  val ans = if (subscriptionRidesNumber * ridePrice > subscriptionPrice) {
    val subscriptionsPrice = (ridesNumber/subscriptionRidesNumber) * subscriptionPrice
    val remainingRides = (ridesNumber%subscriptionRidesNumber)
    if (remainingRides * ridePrice < subscriptionsPrice) {
      subscriptionsPrice + remainingRides * ridePrice
    } else {
      subscriptionsPrice + subscriptionPrice
    }
  } else {
    ridesNumber * ridePrice
  }
  println(ans)
}

import scala.io.StdIn._

object Main2 extends App {
  val Array(ridesNumber, subscriptionRidesNumber, ridePrice, subscriptionPrice) = readLine().split(" ").map(_.toInt)
  val ans = if (subscriptionRidesNumber * ridePrice > subscriptionPrice) {
    (ridesNumber/subscriptionRidesNumber) * subscriptionPrice + (ridesNumber%subscriptionRidesNumber) * ridePrice
  } else {
    ridesNumber * ridePrice
  }
  println(ans)
}

import scala.util.Sorting
import scala.io.StdIn

object App {

  def main(args: Array[String]) {

    val Array(n,m,a,b) = StdIn.readLine().split(" ").map(_.toInt)

    var ans = 10000;
    for(i <- 0 to 1000) {
      ans = math.min(ans, b * i + math.max(n - m * i,0) * a)
    }

    println(ans)

  }

}


Mad scientist Mike is building a time machine in his spare time. To finish the work, he needs a resistor with a certain resistance value.However, all Mike has is lots of identical resistors with unit resistance R0 = 1. Elements with other resistance can be constructed from these resistors. In this problem, we will consider the following as elements:   one resistor;  an element and one resistor plugged in sequence;  an element and one resistor plugged in parallel.   With the consecutive connection the resistance of the new element equals R = Re + R0. With the parallel connection the resistance of the new element equals . In this case Re equals the resistance of the element being connected.Mike needs to assemble an element with a resistance equal to the fraction . Determine the smallest possible number of resistors he needs to make such an element.

The single input line contains two space-separated integers a and b (1 ≤ a, b ≤ 1018). It is guaranteed that the fraction  is irreducible. It is guaranteed that a solution always exists.

Print a single number — the answer to the problem. Please do not use the %lld specifier to read or write 64-bit integers in С++. It is recommended to use the cin, cout streams or the %I64d specifier.

NoteIn the first sample, one resistor is enough.In the second sample one can connect the resistors in parallel, take the resulting element and connect it to a third resistor consecutively. Then, we get an element with resistance . We cannot make this element using two resistors.

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val data = in.next().split(' ').map(_.toLong)
  var (a, b) = if (data.head % data.last == 0) (data.head /data.last, 1l) else (data.head, data.last)
  var r = 0l
  while (b > 0) {
    r += a / b
    val newB = a % b
    a = b
    b = newB
  }
  println(r)
}

import scala.collection._

object C extends App {

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

  def cnt(a: Long, b: Long): Long = {
    //println(a, b)
    if (a == 0L || b == 0L) 0L
    else if (a == 1L) b
    else if (b == a) 1L
    else if (b == 1L) a
    else if (a > b) a / b + cnt(a % b, b)
    else b / a + cnt(b % a, a)
  }

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

  println(cnt(a, b))
}

object C344 {
  @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))
  }

  def main(args: Array[String]): Unit = {
    val Array(a, b) = readLongs(2)
    println(rec(a, b))
  }
  def rec(a: Long, b: Long): Long = {
    if(a == 1 || b == 1) {
      a+b-1
    } else {
      if (a > b) {
        (a / b) + rec(b, a%b)
      } else {
        rec(b, a)
      }
    }
  }
}

object C extends App {

  def readString = Console.readLine
  def tokenizeLine = new java.util.StringTokenizer(readString)
  def readLongs(n: Int) = { val t = tokenizeLine; Array.fill(n)(t.nextToken.toLong) }

  def cnt(a: Long, b: Long): Long = {
    if (a == 1L) b
    else if (a > b) a / b + cnt(a % b, b)
    else cnt(b, a)
  }

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

  println(cnt(a, b))
}

import scala.collection._

object C extends App {

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

  def cnt(a: Long, b: Long): Long = {
    //println(a, b)
    if (a == 0L || b == 0L) 0L
    //else if (a == 1L) b
    else if (b == a) 1L
    else if (b == 1L) a
    else if (a > b) (a - b) + cnt(a % b, b)
    else (b - a) + cnt(b % a, a)
  }

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

  println(cnt(a, b))
}

import scala.collection._

object C extends App {

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

  def cnt(a: Long, b: Long): Long = {
    //println(a, b)
    if (a == 0L || b == 0L) 0L
    else if (a == 1L) b
    else if (b == a) 1L
    else if (b == 1L) a
    else if (a > b) (a - b) + cnt(a % b, b)
    else (b - a) + cnt(b % a, a)
  }

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

  println(cnt(a, b))
}

import scala.collection._

object C extends App {

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

  def cnt(a: Long, b: Long): Long = {
    //println(a, b)
    if (a == 0L || b == 0L) 0L
    else if (a == 1L) b
    else if (b == a) 1L
    else if (a > b) (a - b) + cnt(a % b, b)
    else (b - a) + cnt(b % a, a)
  }

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

  println(cnt(a, b))
}

import scala.collection._

object C extends App {

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

  def cnt(a: Long, b: Long): Long = {
    //println(a, b)
    /*if (a == 1L) b
    else*/ if (b == 1L) 1L
    else if (a > b) (a - b) + cnt(a % b, b)
    else (b - a) + cnt(b % a, a)
  }

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

  println(cnt(a, b))
}

import scala.collection._

object C extends App {

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

  def cnt(a: Long, b: Long): Long = {
    //println(a, b)
    if (a == 1L) b
    else if (b == 1L) 1L
    else if (a > b) (a - b) + cnt(a % b, b)
    else cnt(b, a)
  }

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

  println(cnt(a, b))
}


Some country is populated by wizards. They want to organize a demonstration.There are n people living in the city, x of them are the wizards who will surely go to the demonstration. Other city people (n - x people) do not support the wizards and aren't going to go to the demonstration. We know that the city administration will react only to the demonstration involving at least y percent of the city people. Having considered the matter, the wizards decided to create clone puppets which can substitute the city people on the demonstration. So all in all, the demonstration will involve only the wizards and their puppets. The city administration cannot tell the difference between a puppet and a person, so, as they calculate the percentage, the administration will consider the city to be consisting of only n people and not containing any clone puppets. Help the wizards and find the minimum number of clones to create to that the demonstration had no less than y percent of the city people.

The first line contains three space-separated integers, n, x, y (1 ≤ n, x, y ≤ 104, x ≤ n) — the number of citizens in the city, the number of wizards and the percentage the administration needs, correspondingly. Please note that y can exceed 100 percent, that is, the administration wants to see on a demonstration more people that actually live in the city ( > n).

Print a single integer — the answer to the problem, the minimum number of clones to create, so that the demonstration involved no less than y percent of n (the real total city population).

NoteIn the first sample it is necessary that at least 14% of 10 people came to the demonstration. As the number of people should be integer, then at least two people should come. There is only one wizard living in the city and he is going to come. That isn't enough, so he needs to create one clone. In the second sample 10 people should come to the demonstration. The city has 10 wizards. They will all come to the demonstration, so nobody has to create any clones.

object Solver {
  def main(args: Array[String]) {
    var input = Console.readLine.split(" ").map(x => x.toInt)
    var n = input(0); var x = input(1); var y = input(2);

    var required = Math.ceil(n * y / 100.0).toInt
    var clones = if (required > x) required - x else 0
    println(clones)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, x, y) = in.next().split(" ").map(_.toInt)
  println(Range(0, 1000 * 1000 + 1).find(i => (i + x) * 100 / n >= y).get)
}

import scala.math
object Main
{
	def up(a:Double):Int =
	{
		if(a.floor == a)
			return a.floor.toInt
		return (a.floor.toInt + 1)
	}

	def main(args:Array[String])
	{
		val rd = readLine.split(" ").map(i => i.toInt);
		val n = rd(0)
		val x = rd(1)
		val y = rd(2)

		val cl = up((n / 100.0) * y - x)
		if (cl < 0)
			println(0)
		else
			println(cl)
	}
}

import java.util.Scanner

object A {
    def main(args: Array[String]) {
        val sc = new java.util.Scanner(System.in)
        val n, x, y = sc.nextInt()
        println(math.max(0, (n*y+99)/100-x))
    }
}

import java.util.Scanner
object A {
    def main(args: Array[String]) {
        val sc = new java.util.Scanner(System.in)
        val n, x, y = sc.nextInt()
        val s = n * y - x * 100
        if (s <= 0) println(0)
        else if(s % 100 == 0) println(s / 100)
        else println((s + 100) / 100)
    }
}

import java.util.Scanner

object A extends App {
    val sc = new java.util.Scanner(System.in)
    val n, x, y = sc.nextInt()
    println(math.max(0, (n*y+99)/100-x))
}

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

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

  val N, X, Y = sc.nextInt

  val p = math.ceil(N * Y / 100.0).toInt - X

  out.println(if (p < 0) 0 else p)
  out.close
}

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 Array(n, x, y) = readInts
  def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)
//  def ans = ceil(n * y - 100 * x, 100) max 0
  def ans = (0.01 * n * y - 0.000001 - x).ceil.toInt max 0

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

object Main {
  def main(args: Array[String]) {
    val nxy = readLine().split(" ").map(_.toInt)
    val n = nxy(0)
    val x = nxy(1)
    val y = nxy(2)
    println((((n * y + 99) / 100) - x).max(0))
  }
}

import java.util.Scanner
object A {
    def main(args: Array[String]) {
        val sc = new java.util.Scanner(System.in)
        val n, x, y = sc.nextInt()
        if ((n * y - x * 100) <= 0) println(0)
        else println(((n * y - x * 100) / 100).ceil)
    }
}

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

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

  val N, X, Y = sc.nextInt

  val answer = math.ceil(N * Y / 100.0).toInt - X

  out.println(answer)
  out.close
}

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 Array(n, x, y) = readInts
  def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)
//  def ans = ceil(n * y - 100 * x, 100) max 0
  def ans = (0.01 * n * y - 0.1 - x).ceil.toInt max 0

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

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 Array(n, x, y) = readInts
  def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)
//  def ans = ceil(n * y - 100 * x, 100) max 0
  def ans = (0.01 * n * y - x).ceil.toInt max 0

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

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 Array(n, x, y) = readInts
  def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)
//  def ans = ceil(n * y - 100 * x, 100) max 0
  def ans = (1.0 * n * y - x).ceil.toInt max 0

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

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 Array(n, x, y) = readInts
  def ceil(a: Int, b: Int) = a / b + (if(a % b == 0) 0 else 1)
  def ans = ceil(n * y - 100 * x, 100) max 0

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


You found a mysterious function f. The function takes two strings s1 and s2. These strings must consist only of lowercase English letters, and must be the same length.The output of the function f is another string of the same length. The i-th character of the output is equal to the minimum of the i-th character of s1 and the i-th character of s2.For example, f("ab", "ba") = "aa", and f("nzwzl", "zizez") = "niwel".You found two strings x and y of the same length and consisting of only lowercase English letters. Find any string z such that f(x, z) = y, or print -1 if no such string z exists.

The first line of input contains the string x. The second line of input contains the string y. Both x and y consist only of lowercase English letters, x and y have same length and this length is between 1 and 100.

If there is no string z such that f(x, z) = y, print -1. Otherwise, print a string z such that f(x, z) = y. If there are multiple possible answers, print any of them. The string z should be the same length as x and y and consist only of lowercase English letters.

NoteThe first case is from the statement.Another solution for the second case is "zizez"There is no solution for the third case. That is, there is no z such that f("ab", z) =  "ba".

/**
  * Created by moiseev on 21.04.2017.
  */
object Task2 extends App {

  import java.util.{Scanner}

  val in = new Scanner(System.in)

  val X = in.next
  val Y = in.next

  def middleChar( charLeft: Char, charRes: Char ): (Boolean,Char) = {
    if ( charLeft < charRes ) (false,' ')
    else  {
      // a - 92 z - 122
      // charLeft - between 92 and 122
      // result should be between charLeft and 122 inclusive
      (
        true,if ( charLeft == charRes ) {
        val randRandge: Int = 122 - charLeft
        (charLeft.toInt + (if (randRandge > 0)scala.util.Random.nextInt(randRandge) else 0) ).toChar
      }
      else charRes
      )
    }
  }

  def findSecondString( strLeft:String, strRes: String ): (Boolean, String) = {
    if ( strLeft.size == 0 ) (true,"") // Finishing the recursion
    else if (strLeft.size != strRes.size )
      (false,"") // Strings are of different size - false definetly
    else {
      val (res, ch) = middleChar(strLeft.head, strRes.head)

      if (!res)
        (false, "") // Some i chars says they are not from our F()
      else {
        val (recRes, strRec) = findSecondString(strLeft.tail, strRes.tail)

        if (!recRes)
          (false, "") // Just to recursevly inform about failure
        else (true, ch + strRec)
      }
    }
  }

  val (resBool,resStr) = findSecondString(X,Y)
  if (resBool) {
    println(resStr)
  } else {
    println(-1)
  }
}

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

  override def apply(io: IO) = {import io.{read, readAll, write, writeAll, writeLine}
    val x, z = read[String]

    val ans = Try{x.zip(z).map({case (a, b) => b.ensuring(b <= a)})}

    write(ans.map(_.mkString).getOrElse("-1"))
  }
}
/****************************[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}
  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, until: Int)(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, until: Int)(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
  }
  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])
    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 testBit(i: Int): Boolean = ((x >> i) & 1) == 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 testBit(i: Int): Boolean = ((x >> i) & 1) == 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 java.awt.geom.Point2D.Double(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 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
      }
    }
  }
}


You are locked in a room with a door that has a keypad with 10 keys corresponding to digits from 0 to 9. To escape from the room, you need to enter a correct code. You also have a sequence of digits.Some keys on the keypad have fingerprints. You believe the correct code is the longest not necessarily contiguous subsequence of the sequence you have that only contains digits with fingerprints on the corresponding keys. Find such code.

The first line contains two integers $$$n$$$ and $$$m$$$ ($$$1 \le n, m \le 10$$$) representing the number of digits in the sequence you have and the number of keys on the keypad that have fingerprints. The next line contains $$$n$$$ distinct space-separated integers $$$x_1, x_2, \ldots, x_n$$$ ($$$0 \le x_i \le 9$$$) representing the sequence. The next line contains $$$m$$$ distinct space-separated integers $$$y_1, y_2, \ldots, y_m$$$ ($$$0 \le y_i \le 9$$$) — the keys with fingerprints.

In a single line print a space-separated sequence of integers representing the code. If the resulting sequence is empty, both printing nothing and printing a single line break is acceptable.

NoteIn the first example, the only digits with fingerprints are $$$1$$$, $$$2$$$ and $$$7$$$. All three of them appear in the sequence you know, $$$7$$$ first, then $$$1$$$ and then $$$2$$$. Therefore the output is 7 1 2. Note that the order is important, and shall be the same as the order in the original sequence.In the second example digits $$$0$$$, $$$1$$$, $$$7$$$ and $$$9$$$ have fingerprints, however only $$$0$$$ and $$$1$$$ appear in the original sequence. $$$1$$$ appears earlier, so the output is 1 0. Again, the order is important.

import scala.collection.mutable._
import scala.io.StdIn

object Main {
    def main(arg: Array[String]) {
        var z = readLine().split(" ")
        var n = z(0).toInt
        var m = z(1).toInt

        var x = readLine.split(" ").map(_.toInt).toArray
        var y = readLine.split(" ").map(_.toInt).toArray

        for(ele <- x){
            if(y contains ele) {
                print(ele + " ")
            }
        }
    }
}

/**
  * @author ShankarShastri
  *         Algorithm: ProblemA (http://codeforces.com/contest/994/problem/A)
  */

import scala.io.StdIn._
import scala.annotation.tailrec

object ProblemA {
  def main(args: Array[String]): Unit = {
    readLine
    val list = readLine.split(" ").map(_.toInt).toList
    val keys = readLine.split(" ").map(_.toInt).toList
    val res = keys.map(x => (x, list.indexOf(x))).filter(_._2 != -1).sortBy(_._2).map(_._1)
    println(res.mkString(" "))
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    StdIn.readLine()
    val a = StdIn.readLine().split(" ")
    val b = StdIn.readLine().split(" ")
    val c = a.filter(item => b.contains(item))
    c.foreach(item => print(item + " "))
  }
}


Vasily has a number a, which he wants to turn into a number b. For this purpose, he can do two types of operations:  multiply the current number by 2 (that is, replace the number x by 2·x);  append the digit 1 to the right of current number (that is, replace the number x by 10·x + 1). You need to help Vasily to transform the number a into the number b using only the operations described above, or find that it is impossible.Note that in this task you are not required to minimize the number of operations. It suffices to find any way to transform a into b.

The first line contains two positive integers a and b (1 ≤ a < b ≤ 109) — the number which Vasily has and the number he wants to have.

If there is no way to get b from a, print "NO" (without quotes). Otherwise print three lines. On the first line print "YES" (without quotes). The second line should contain single integer k — the length of the transformation sequence. On the third line print the sequence of transformations x1, x2, ..., xk, where:   x1 should be equal to a,  xk should be equal to b,  xi should be obtained from xi - 1 using any of two described operations (1 < i ≤ k).  If there are multiple answers, print any of them.

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val Array(a, b) = in.next().split(' ').map(_.toLong)

  def solution(current: Long): List[Long] = {
    if (current == b)
      List(current)
    else if (current > b)
      List.empty
    else {
      val candidate = solution(current * 2)
      if (candidate.nonEmpty)
        current :: candidate
      else {
        val candidate2 = solution(current * 10 + 1)
        if (candidate2.isEmpty)
          List.empty
        else
          current :: candidate2
      }
    }
  }

  solution(a) match {
    case Nil => println("NO")
    case list =>
      println("YES")
      println(list.length)
      println(list.mkString(" "))
  }
}


Mr. Kitayuta has kindly given you a string s consisting of lowercase English letters. You are asked to insert exactly one lowercase English letter into s to make it a palindrome. A palindrome is a string that reads the same forward and backward. For example, "noon", "testset" and "a" are all palindromes, while "test" and "kitayuta" are not.You can choose any lowercase English letter, and insert it to any position of s, possibly to the beginning or the end of s. You have to insert a letter even if the given string is already a palindrome.If it is possible to insert one lowercase English letter into s so that the resulting string will be a palindrome, print the string after the insertion. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one palindrome that can be obtained, you are allowed to print any of them.

The only line of the input contains a string s (1 ≤ |s| ≤ 10). Each character in s is a lowercase English letter.

If it is possible to turn s into a palindrome by inserting one lowercase English letter, print the resulting string in a single line. Otherwise, print "NA" (without quotes, case-sensitive). In case there is more than one solution, any of them will be accepted.

NoteFor the first sample, insert 'r' to the end of "revive" to obtain a palindrome "reviver".For the second sample, there is more than one solution. For example, "eve" will also be accepted.For the third sample, it is not possible to turn "kitayuta" into a palindrome by just inserting one letter.

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