object Main {

  def main(args: Array[String]) {

    val std = scala.io.StdIn
    val line1 = std.readLine()
    val line2 = std.readLine()

    val vowels = "aeiou"
    if (line1.length == line2.length) {
      if (line1.zip(line2).exists(x => vowels.contains(x._1) != vowels.contains(x._2))) {
        println("No")
      }
      else {
        println("Yes")
      }
    }
    else {
      println("No")
    }
  }
}

object Problem_1111A {

  def main(args: Array[String]) {
    val scan = scala.io.StdIn
    val s1: String = scan.readLine()
    val s2: String = scan.readLine()

    if(s1.length != s2.length){
      print("No")
      return
    }

    var areSame= true;
    for (i <- 0 until s1.length) {
      if(isVowel(s1(i)) != isVowel(s2(i))){
        areSame =false
      }
    }

    if(areSame){
      print("Yes")
    }
    else{
      print("No")
    }

  }

  def isVowel(x : Char) ={
    val vowels: Array[Char] = Array('a','e','i','o','u')
    vowels.contains(x)
  }

}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S, T = ns()

    def tpe(c: Char) = c match {
      case 'a' | 'i' | 'u' | 'e' | 'o' => 1
      case _ => 2
    }

    if (S.length != T.length) {
      out.println("No")
    } else {
      var ok = true
      REP(S.length) { i =>
        ok &&= tpe(S(i)) == tpe(T(i))
      }
      if (ok) out.println("Yes")
      else out.println("No")
    }
  }

  def debug(as: Array[Boolean]): Unit = {
    System.err.println(as.map(x => if(x) "1" else "0").mkString)
  }

  def debug(as: Array[Int]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(as: Array[Long]): Unit = {
    System.err.println(as.mkString(" "))
  }

  def debug(s: String): Unit = {
    System.err.println(s)
  }

  def debug(num: Long): Unit = {
    System.err.println(num)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

object A extends App {

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

  val Array(s) = readStrings(1)
  val Array(t) = readStrings(1)

  val cos = Seq('a', 'e', 'i', 'o', 'u')

  val matchCase = for {
    (cs, ct) <- s.zip(t)
    matches = cos.contains(cs) == cos.contains(ct)
  } yield matches

  if (matchCase.forall(_ == true) && s.length == t.length)
    println("yes")
  else
    print("no")

  Console.flush
}

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

  override def apply(io: IO): io.type = {
    val s, t = io.read[String]
    val vowels = "aeiou"
    val ans = s.length == t.length && s.zip(t).forall({case (a, b) => vowels.contains(a) == vowels.contains(b)})
    io.write(if (ans) "Yes" else "No" +
      "")
  }
}
/****************************[Ignore Template Below]****************************************/
trait CodeForcesApp {
  lazy val isOnlineJudge: Boolean = sys.props.get("ONLINE_JUDGE").exists(_.toBoolean)
  def debug(x: => Any): Unit = if (!isOnlineJudge) println(x)
  def apply(io: IO): io.type
  def main(args: Array[String]): Unit = this(new IO(System.in, System.out)).close()
}
/***********************************[Scala I/O]*********************************************/
import java.io._, java.util.StringTokenizer
import scala.collection.generic.CanBuild

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

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

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

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

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

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

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

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

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

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

object A extends App {

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

  val Array(s) = readStrings(1)
  val Array(t) = readStrings(1)

  val cos = Seq('a', 'e', 'i', 'o', 'u')

  val matchCase = !s.zip(t).forall {
    case (c1, c2) => cos.contains(c1) ^ cos.contains(c2)
  }

  if (matchCase && s.length == t.length)
    println("yes")
  else
    print("no")

  Console.flush
}


object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val S, T = ns()

    val N = min(S.length, T.length)
    var i = 0
    var continue = true
    while(i < N && continue) {
      if (S(S.length - 1 - i) == T(T.length - 1 - i))
        i += 1
      else
        continue = false
    }
    out.println(S.length + T.length - 2 * i)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
  def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
    val A1, A2 = Array.ofDim[Int](n)
    REP(n) { i =>
      A1(i) = ni() + offset
      A2(i) = ni() + offset
    }
    (A1, A2)
  }
  def nm(n: Int, m: Int): Array[Array[Int]] = {
    val A = Array.ofDim[Int](n, m)
    REP(n) { i =>
      REP(m) { j =>
        A(i)(j) = ni()
      }
    }
    A
  }
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]) = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

import scala.io.StdIn

object Codeforces1005B {

  def getFewestMove(s: String, t: String): Int = {
    var totalMatched = 0
    var misMatched = false
    while (!misMatched) {
      if (totalMatched >= s.length || totalMatched >= t.length) {
        misMatched = true
      } else if (s(s.length - 1 - totalMatched) == t(t.length - 1 - totalMatched)) {
        totalMatched += 1
      } else {
        misMatched = true
      }
    }

    s.length + t.length - 2 * totalMatched
  }

  def main(args: Array[String]): Unit = {
    val s = StdIn.readLine()
    val t = StdIn.readLine()
    val fewestMove = getFewestMove(s, t)
    println(fewestMove)
  }
}

object StrCut {
  def main(args: Array[String]): Unit = {
    val s1: String = scala.io.StdIn.readLine()
    val s2: String = scala.io.StdIn.readLine()
    var u = 0
    while ( {
      u < Math.min(s1.length, s2.length) && s1.charAt(s1.length - u - 1) == s2.charAt(s2.length - u - 1)
    }) {
      u += 1; u
    }
    println(s1.length - u + s2.length - u)
  }
}

object CF496B extends App {

  import java.io.PrintWriter
  import java.util.Scanner

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def solve = {
    val w1 = in.next
    val w2 = in.next

    val sameCount = w1.reverse.zipWithIndex
      .takeWhile(x => w2.length - 1 - x._2 >= 0 && w2.charAt(w2.length - 1 - x._2) == x._1)
      .length

    out.println(w1.length + w2.length - sameCount*2)
  }

  solve
  out.flush
  out.close
}

import scala.collection.mutable._

object Solution {
  def main(args: Array[String]) {
    val s = scala.io.StdIn.readLine.trim
    val t = scala.io.StdIn.readLine.trim
    println(solve(s, t))
  }

  def solve(s: String, t: String): Int = {
    var i = s.length
    var j = t.length
    var flag = true
    while (i > 0 && j > 0 && flag) {
      if (s(i-1) != t(j-1)) flag = false
      else {
        i -= 1
        j -= 1
      }
    }
    (i + j)
  }

}

import scala.collection.mutable._

object Solution {
  def main(args: Array[String]) {
    val s = scala.io.StdIn.readLine.trim
    val t = scala.io.StdIn.readLine.trim
    println(solve(s, t))
  }

  def solve(s: String, t: String) {
    var i = s.length
    var j = t.length
    var flag = true
    while (i > 0 && j > 0 && flag) {
      if (s(i-1) != t(j-1)) flag = false
      else {
        i -= 1
        j -= 1
      }
    }
    (i + j)
  }

}

import scala.collection.mutable._

object Solution {
  def main(args: Array[String]) {
    val s = scala.io.StdIn.readLine.trim
    val t = scala.io.StdIn.readLine.trim
    println(solve(s, t))
  }

  def solve(s: String, t: String): Int = {
    var i = s.length - 1
    var j = t.length - 1
    var flag = true
    while (i > 0 && j > 0 && flag) {
      if (s(i) != t(j)) flag = false
      else {
        i -= 1
        j -= 1
      }
    }
    (i + j + 2)
  }

}


object CF511B extends App {

  import scala.io.StdIn

  val n = StdIn.readInt
  val points = new Array[Int](n).map(_ => StdIn.readLine.split(' ').map(_.toInt))
  println(points.map(point => point(0)+point(1)).max)
  // y-y1=-(x-x1)
  // y=-(x-x1)+y1 | evaluated at x=0
  // y=x1+y1
}

object Main {
  def main(args: Array[String]): Unit = {
    val s = new Main()
    s.solve()
    s.out.flush()
  }
}

class Main {
  import java.io._
  import java.util.StringTokenizer

  import scala.collection.mutable
  import scala.util.Sorting
  import math.{abs, max, min}
  import mutable.{ArrayBuffer, ListBuffer}
  import scala.reflect.ClassTag

  val MOD = 1000000007
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val N = ni()
    val A = Array.ofDim[Int](N)
    rep(N) { i =>
      A(i) = ni() + ni()
    }
    val ans = A.max
    out.println(ans)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

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

    def nextInt(): Int = next().toInt
    def nextLong(): Long = next().toLong
    def nextChar(): Char = next().charAt(0)
  }
  val sc = new InputReader(System.in)
  def ni(): Int = sc.nextInt()
  def nl(): Long = sc.nextLong()
  def nc(): Char = sc.nextChar()
  def ns(): String = sc.next()
  def ns(n: Int): Array[Char] = ns().toCharArray
  def na(n: Int): Array[Int] = map(n)(_ => ni())
  def nal(n: Int): Array[Long] = map(n)(_ => nl())
  def nm(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  def rep(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def rep_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }

  def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    rep(n)(i => res(i) = f(i))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    rep(as.length)(i => s += as(i))
    s
  }
}

import scala.io.StdIn

object CoverPoints {
  def main(args: Array[String]): Unit ={
    val n = StdIn.readInt()
    var ans = 0
    for( i <- 1 to n){
      val xy = StdIn.readLine().split(" ").map(_.toInt)
      val x = xy(0)
      val y = xy(1)
      ans  = math.max(ans,x + y)
    }
    print(ans)
  }

}

object b1047 {
  def main(args: Array[String]): Unit = {
    println(scala.io.Source.stdin getLines() drop 1  map(_.split(" ").map(_.toInt).sum)  reduce scala.math.max)
  }
}

import scala.io.StdIn

object Codeforces1047B {
  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()
    val result = (1 to n).map(_ => StdIn.readLine.trim.split(" ").map(_.toInt)).map(a => a.sum).max

    print(result)
  }
}

import scala.io.StdIn

object Codeforces1047B {

  def getCoverPoint(n: Int, points: Seq[Point]): Int =
    points.map(a => a.x + a.y).max

  def main(args: Array[String]): Unit = {
    val n = StdIn.readInt()

    val points = (1 to n).map(_ => StdIn.readLine.trim.split(" ").map(_.toInt)).map(a => Point(a(0), a(1)))

    val result = getCoverPoint(n, points)

    print(result)
  }

  case class Point(x: Int, y: Int)

}

object b1047 {
  def main(args: Array[String]): Unit = {
    //val n = scala.io.StdIn.readInt()
    val r : Array[Array[Int]] = scala.io.Source.stdin getLines() drop 1  map(_.split(" ").map(_.toInt)) toArray
    val s = r.sortBy {i => (-i(0),-i(1))}
    println(s.head(0)+s.head(1))
  }
}


import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(c1, c2, c3, c4) = in.next().split(' ').map(_.toInt)
  in.next()
  val a = in.next().split(' ').map(_.toInt).sorted.reverse
  val b = in.next().split(' ').map(_.toInt).sorted.reverse
  println(Math.min(
    c4,
    Math.min(a.map(i => Math.min(i * c1, c2)).sum, c3) + Math.min(b.map(i => Math.min(i * c1, c2)).sum, c3)
  ))
}

object Main {
  def main(args: Array[String]) {
    val Array(c1, c2, c3, c4) = readLine().split(" ").map(_.toInt)
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    val ns = readLine().split(" ").map(_.toInt)
    val ms = readLine().split(" ").map(_.toInt)

    val nsum = ns.map(count => c2.min(count * c1)).sum
    val nmin = nsum.min(c3)

    val msum = ms.map(count => c2.min(count * c1)).sum
    val mmin = msum.min(c3)

    println(c4.min(nmin + mmin))
  }
}


object C{
  def main(args:Array[String]){

    val a:Array[Double]={
      val n=readLine.toInt
      val alist=
        (1 to n).toList.foldLeft(List[Double]()){(list,i)=>
          val (x, y)={
            val sp=readLine.split(" ").map(_.toInt)
            (sp(0),sp(1))
          }
          if(x==0 && y==0){
            list
          }else{
            val next=Math.toDegrees(Math.atan2(y,x))
            next::list
          }
        }

      alist.toArray.sorted
    }

    val n=a.length

    val max= (0 until n).toList.foldLeft(0.0){(max,i)=>
      var m= a((i+1)%n) -a(i)
      if(i==n-1) m+=360
      Math.max(m,max)
    }

    println(360-max)
  }
}

import scala.util.Sorting._
import math._

object Contest extends App {
  val n = readInt()
  val arcs = new Array[Double](n+1);
  arcs(n) = 3 * Pi
  for (i <- 0 until n){
    val Array(x, y) = readLine().split(" ").map(_.toDouble)
    arcs(i) = atan2(y, x)
  }
  stableSort(arcs, (a: Double, b: Double) => {a < b})
  arcs(n) = arcs(0) + 2 * Pi
  var maxArc = 0.0
  for (i <- 0 until n){
    maxArc = max(maxArc, arcs(i+1) - arcs(i))
  }
  println(360 - maxArc * 180 / Pi)
}

object C{
  def main(args:Array[String]){

    val a:Array[Double]={
      val n=readLine.toInt
      val alist=
        (1 to n).toList.foldLeft(List[Double]()){(list,i)=>
          val (x, y)={
            val sp=readLine.split(" ").map(_.toInt)
            (sp(0),sp(1))
          }
          if(x==0 && y==0){
            list
          }else{
            val next=Math.toDegrees(Math.atan2(y,x))
            next::list
          }
        }

      alist.toArray.sorted
    }

    val n=a.length

    val max= (0 until n).toList.foldLeft(0.0){(max,i)=>
      var m= a((i+1)%n) -a(i)
      if(m<0) m+=360
      Math.max(m,max)
    }

    if(n==1){
      println(0)
    }else{
      println(360-max)
    }
  }
}

object C{
  def main(args:Array[String]){

    val a:Array[Double]={
      val n=readLine.toInt
      val alist=
        (1 to n).toList.foldLeft(List[Double]()){(list,i)=>
          val (x, y)={
            val sp=readLine.split(" ").map(_.toInt)
            (sp(0),sp(1))
          }
          if(x==0 && y==0){
            list
          }else{
            val next=Math.toDegrees(Math.atan2(y,x))
            next::list
          }
        }

      alist.toArray.sorted
    }

    val n=a.length

    val max= (0 until n).toList.foldLeft(0.0){(max,i)=>
      var m= a((i+1)%n) -a(i)
      if(m<0) m+=360
      Math.max(m,max)
    }

    println(360-max)

  }
}


import scala.collection.mutable.ListBuffer

object P479B {
	def transfer(values: Vector[Int], src: (Int, Int), dst: (Int, Int)) : Vector[Int] = {
		values.updated(src._2, src._1 - 1).updated(dst._2, dst._1 + 1)
	}

	def iterate(k: Int, values: Vector[Int]) : (ListBuffer[(Int, Int)], Vector[Int]) = {
		val max = values.zipWithIndex.maxBy(_._1)
		val min = values.zipWithIndex.minBy(_._1)

		val accumulator = ListBuffer[(Int, Int)]()
		if (max._1 - min._1 > 1 && k > 0) {
			val (results, updated) = iterate(k - 1, transfer(values, max, min))
			(accumulator ++= ((max._2 + 1, min._2 + 1) +=: results), updated)
		} else {
			(accumulator, values)
		}
	}

	def main(args: Array[String]) {
		val read = () => scala.io.StdIn.readLine.split(" ").map(_.toInt)
		val (Array(n, k), a) = (read(), read().to[Vector])
		val (results, values) = iterate(k, a)

		printf("%d %d\n", values.max - values.min, results.length)
		results.foreach(x => printf("%d %d\n", x._1, x._2))
	}
}

import scala.collection.mutable.ListBuffer

object P479B {
	def iterate(k: Int, values: Vector[Int]) : (ListBuffer[(Int, Int)], Vector[Int]) = {
		val results = ListBuffer[(Int, Int)]()
		val max = values.zipWithIndex.maxBy(_._1)
		val min = values.zipWithIndex.minBy(_._1)
		if (max._1 > min._1 + 1 && k > 0) {
			val updated = values.updated(max._2, max._1 - 1).updated(min._2, min._1 + 1)
			val (rresults, rupdated) = iterate(k - 1, updated)
			(results ++= ((max._2 + 1, min._2 + 1) +=: rresults), rupdated)
		} else {
			(results, values)
		}
	}

	def main(args: Array[String]) {
		val read = () => scala.io.StdIn.readLine.split(" ").map(_.toInt)
		val Array(n, k) = read()
		val (results, values) = iterate(k, read().to[Vector])
		printf("%d %d\n", values.max - values.min, results.length)
		results.foreach(x => printf("%d %d\n", x._1, x._2))
	}
}

import Console._
import scala.io.Source

object Main extends App {

  val in = Source.fromInputStream(System.in)
  val n = nextInt(in).get
  val k = nextInt(in).get
  val arr = Array.ofDim[Int](n)

  for (i <- 1 to n) {
    arr(i - 1) = nextInt(in).get
  }
  val sumAll = arr.foldLeft(0)(_ + _)
  val minInstability = (sumAll / n.toDouble).ceil.toInt - sumAll / n
  val arrIndexed = arr.zipWithIndex
  val initialInstability = arrIndexed(findMaxIdx(arrIndexed))._1 - arrIndexed(findMinIdx(arrIndexed))._1

  val (instability, opCount, allOps) =
    findMinInstability(initialInstability, 0, Array[(Int, Int)](), arrIndexed)

  print(s"$instability $opCount")

  for (i <- 1 to opCount) {
    val op = allOps(i - 1)
    print(s"\n${op._1} ${op._2}")
  }

  def findMinInstability(instability: Int, nOps: Int, ops: Array[(Int, Int)], arrIndexed: Array[(Int, Int)]):
        (Int, Int, Array[(Int, Int)]) = {

    if (instability == minInstability || nOps == k) {
      (instability, nOps, ops)
    } else {
      val maxIdx = findMaxIdx(arrIndexed)
      val minIdx = findMinIdx(arrIndexed)
      arrIndexed(maxIdx) = (arrIndexed(maxIdx)._1 - 1, arrIndexed(maxIdx)._2)
      arrIndexed(minIdx) = (arrIndexed(minIdx)._1 + 1, arrIndexed(minIdx)._2)
      val newInstability = arrIndexed(findMaxIdx(arrIndexed))._1 - arrIndexed(findMinIdx(arrIndexed))._1

      findMinInstability(newInstability, nOps + 1, ops :+ (maxIdx + 1, minIdx + 1), arrIndexed)
    }
  }

  def findMaxIdx(arrIndexed: Array[(Int, Int)]) = {
    arrIndexed.max._2
  }

  def findMinIdx(arrIndexed: Array[(Int, Int)]) = {
    arrIndexed.min._2
  }

  def nextInt(src: Iterator[Char]): Option[Int] = {
    val (ignored, tail) = src.span(!_.isDigit)
    val (nbr, _) = tail.span(_.isDigit)
    if (!nbr.isEmpty) {
        Some(nbr.mkString.toInt)
    } else {
      None
    }
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, k) = in.next().split(' ').map(_.toInt)
  val data = in.next().split(' ').map(_.toInt)
  val arr = Array.fill(10001){List.empty[Int]}
  data.indices.foreach { i => arr(data(i)) ::= i + 1 }
  var nk = k
  var left = arr.indices.find(i => arr(i).nonEmpty).get
  var right = arr.indices.reverse.find(i => arr(i).nonEmpty).get
  var res = List.empty[(Int, Int)]
  while (nk > 0 && left + 1 < right) {
    val lIndex = arr(left).head
    val rIndex = arr(right).head
    res ::= (rIndex, lIndex)
    nk -= 1
    arr(left) = arr(left).tail
    arr(left + 1) ::= lIndex
    arr(right) = arr(right).tail
    arr(right - 1) ::= rIndex
    if (arr(left).isEmpty)
      left += 1
    if (arr(right).isEmpty)
      right -= 1
  }
  println(s"${right - left} ${k - nk}")
  println(res.map{case(a, b) => s"$a $b"}.mkString("\n"))
}


object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  if (n <= 3) println("NO")
  else if (n % 2 == 0) {
    println("YES")
    println("1 * 2 = 2")
    println("2 * 3 = 6")
    println("6 * 4 = 24")
    (5 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
      println("24 * 1 = 24")
    }

  } else {
    println("YES")
    println("2 - 1 = 1")
    println("1 + 3 = 4")
    println("4 * 5 = 20")
    println("20 + 4 = 24")
    (6 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
      println("24 * 1 = 24")
    }
  }
}

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

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C268A(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class C268A(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()

    val notPossible = Array(1, 2, 3)
    if(notPossible.contains(n)) {
      out.println("NO")
    } else if(n == 4) {
      out.println("YES")
      out.println("4 * 3 = 12")
      out.println("12 * 2 = 24")
      out.println("24 * 1 = 24")
    } else if(n==5) {
      out.println("YES")
      out.println("5 - 3 = 2")
      out.println("4 * 2 = 8")
      out.println("2 + 1 = 3")
      out.println("8 * 3 = 24")
    } else {
      out.println("YES")
      out.println("6 * 4 = 24")
      out.println("1 + 2 = 3")
      out.println("3 - 3 = 0")
      out.println("0 * 5 = 0")
      REP(n + 1) { i =>
        if(i > 6) {
          out.println(s"$i * 0 = 0")
        }
      }
      out.println("24 + 0 = 24")
    }
  }
}

import scala.annotation.tailrec

object A extends App {

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

  val Array(n) = readInts(1)

  Console.setOut(new java.io.BufferedOutputStream(Console.out))

  if (n < 4) println("NO")
  else {
    println("YES")
    solve(n)
  }

  Console.flush

  @tailrec
  def solve(n: Int): Unit = {
    if (n == 4) {
      println("1 * 2 = 2")
      println("2 * 3 = 6")
      println("6 * 4 = 24")
    } else if (n == 5) {
      println("5 - 3 = 2")
      println("2 + 1 = 3")
      println("3 * 2 = 6")
      println("6 * 4 = 24")
    } else {
      println(s"$n - ${n - 1} = 1")
      println("1 * 1 = 1")
      solve(n - 2)
    }
  }

}

object TwentyFour extends App {
  sealed trait Op {
    def apply(a: Int, b: Int): Int
  }
  case object Times extends Op {
    override def apply(a: Int, b: Int) = a * b
    override def toString = "*"
  }
  case object Plus extends Op {
    override def apply(a: Int, b: Int) = a + b
    override def toString = "+"
  }
  case object Minus extends Op {
    override def apply(a: Int, b: Int) = a - b
    override def toString = "-"
  }

  case class Equation(l: Int, op: Op, r: Int) {
    val res = op(l, r)
    override def toString = s"$l $op $r = $res"
  }

  object EquationBuilder {
    implicit def intToEquationBuilder(i: Int) = EquationBuilder(i)
  }
  case class EquationBuilder(i: Int) {
    def plus(j: Int) = Equation(i, Plus, j)
    def times(j: Int) = Equation(i, Times, j)
    def minus(j: Int) = Equation(i, Minus, j)
  }

  // The work
  val n = io.Source.stdin.getLines.next.toInt
  if(n < 4) println("NO")
  else {
    import EquationBuilder._
    val fourSolution = Vector(
      4 times 2, // = 8
      8 times 3, // = 24
      24 times 1)
    val fiveSolution = Vector(
      5 minus 2, // = 3
      3 plus 3, // = 6
      4 times 6, // = 24
      24 times 1)
    def incSolution(i: Int) = Vector(
      // assume we have collapsed all i-2 into a single 24
      i minus (i - 1), // = 1
      24 times 1)
    def solution(i: Int) = {
      if(i % 2 == 0) {
        fourSolution ++ ((3 to i/2) map (_ * 2) flatMap incSolution)
      } else {
        fiveSolution ++ ((3 to i/2) map (_ * 2 + 1) flatMap incSolution)
      }
    }
    println("YES")
    println(solution(n).mkString("\n"))
  }
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  if (n <= 3) println("NO")
  else if (n % 2 == 0) {
    println("YES")
    println("1 * 2 = 2")
    println("2 * 3 == 6")
    println("6 * 4 = 24")
    (5 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
    }
    println("24 * 1 = 24")
  } else {
    println("YES")
    println("2 - 1 = 1")
    println("1 + 3 = 4")
    println("4 * 5 = 20")
    (6 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
    }
    println("24 * 1 = 24")
  }
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  if (n <= 3) println("NO")
  else if (n % 2 == 0) {
    println("YES")
    println("1 * 2 = 2")
    println("2 * 3 = 6")
    println("6 * 4 = 24")
    (5 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
    }
    println("24 * 1 = 24")
  } else {
    println("YES")
    println("2 - 1 = 1")
    println("1 + 3 = 4")
    println("4 * 5 = 20")
    (6 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
    }
    println("24 * 1 = 24")
  }
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val n = in.next().toInt
  if (n <= 3) println("NO")
  else if (n % 2 == 0) {
    println("YES")
    println("1 * 2 = 2")
    println("2 * 3 = 6")
    println("6 * 4 = 24")
    (5 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
      println("24 * 1 = 24")
    }

  } else {
    println("YES")
    println("2 - 1 = 1")
    println("1 + 3 = 4")
    println("4 * 5 = 20")
    (6 to n by 2).foreach { i =>
      println(s"${i + 1} - $i = 1")
      println("24 * 1 = 24")
    }
  }
}

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

import scala.reflect.ClassTag

object Main {
  def main(args: Array[String]): Unit = {
    try {
      val (in, out) =
        if (isOnlineJudge) {
          (
            new FastScanner(new InputStreamReader(System.in)),
            new PrintWriter(System.out)
          )
        } else {
          (
            new FastScanner(new FileReader(new File("src/resource/problem.in"))),
            new PrintWriter(new File("src/resource/problem.out"))
          )
        }
      new C268A(in, out).solve()
      out.flush()
      out.close()
    } catch {
      case e: IOException => e.printStackTrace()
    }
  }

  private[this] val isOnlineJudge = true

  class FastScanner(val streamReader: InputStreamReader) {
    private[this] val reader = new BufferedReader(streamReader, 32768)
    private[this] var tokenizer: StringTokenizer = _

    @inline private[this] final def next(): String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

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

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

    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()

    def nl(): Long = nextLong()

    def nc(): Char = nextChar()

    def ns(): String = next()

    def ns(n: Int): Array[Char] = ns().toCharArray

    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)

    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }

    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }

    def nal(n: Int): Array[Long] = map(n)(_ => nl())

    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n)(_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while (i < N) {
      f(i);
      i += 1
    }
  }

  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while (i >= offset) {
      f(i);
      i -= 1
    }
  }

  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from)(f)
  }

  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }

  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class C268A(fScanner: Main.FastScanner, out: java.io.PrintWriter) {

  import Main._
  import fScanner._

  def solve(): Unit = {
    val n = ni()

    val notPossible = Array(1, 2, 3, 5)
    if(notPossible.contains(n)) {
      out.println("NO")
    } else if(n == 4) {
      out.println("YES")
      out.println("4 * 3 = 12")
      out.println("12 * 2 = 24")
      out.println("24 * 1 = 24")
    } else {
      out.println("YES")
      out.println("6 * 4 = 24")
      out.println("1 + 2 = 3")
      out.println("3 - 3 = 0")
      out.println("0 * 5 = 0")
      REP(n + 1) { i =>
        if(i > 6) {
          out.println(s"$i * 0 = 0")
        }
      }
      out.println("24 + 0 = 24")
    }
  }
}

object TwentyFour extends App {
  sealed trait Op {
    def apply(a: Int, b: Int): Int
  }
  case object Times extends Op {
    override def apply(a: Int, b: Int) = a * b
    override def toString = "*"
  }
  case object Plus extends Op {
    override def apply(a: Int, b: Int) = a + b
    override def toString = "+"
  }
  case object Minus extends Op {
    override def apply(a: Int, b: Int) = a - b
    override def toString = "-"
  }

  case class Equation(l: Int, op: Op, r: Int) {
    val res = op(l, r)
    override def toString = s"$l $op $r = $res"
  }

  object EquationBuilder {
    implicit def intToEquationBuilder(i: Int) = EquationBuilder(i)
  }
  case class EquationBuilder(i: Int) {
    def plus(j: Int) = Equation(i, Plus, j)
    def times(j: Int) = Equation(i, Times, j)
    def minus(j: Int) = Equation(i, Minus, j)
  }

  // The work
  val n = io.Source.stdin.getLines.next.toInt
  if(n < 4) println("NO")
  else {
    import EquationBuilder._
    val fourSolution = Vector(
      4 times 2, // = 8
      8 times 3, // = 24
      24 times 1)
    val fiveSolution = Vector(
      5 minus 2, // = 3
      3 plus 3, // = 6
      4 times 6, // = 24
      24 times 1)
    def incSolution(i: Int) = Vector(
      // assume we have collapsed all i-2 into a single 24
      i minus (i - 1), // = 1
      24 times 1)
    def solution(i: Int) = {
      if(i % 2 == 0) {
        fourSolution ++ ((2 to i/2) map (_ * 2) flatMap incSolution)
      } else {
        fiveSolution ++ ((3 to i/2) map (_ * 2 + 1) flatMap incSolution)
      }
    }
    println("YES")
    println(solution(n).mkString("\n"))
  }
}


object Main {
  import java.io.{BufferedReader, InputStream, InputStreamReader}
  import java.util.StringTokenizer
  import scala.reflect.ClassTag

  def main(args: Array[String]): Unit = {
    val out = new java.io.PrintWriter(System.out)
    new Main(out, new InputReader(System.in)).solve()
    out.flush()
  }

  private val oj = System.getenv("ATCODER_DEBUG") == null
  def DEBUG(f: => Unit): Unit = {
    if (!oj){ f }
  }
  def debug(as: Array[Boolean]): Unit = if (!oj){ debug(as.map(x => if(x) "1" else "0").mkString) }
  def debug(as: Array[Int]): Unit = if (!oj){ debug(as.mkString(" ")) }
  def debug(as: Array[Long]): Unit =if (!oj){ debug(as.mkString(" ")) }
  def debugDim(m: Array[Array[Int]]): Unit = if (!oj){
    REP(m.length) { i =>
      debug(m(i))
    }
  }
  def debugDimFlip(m: Array[Array[Long]]): Unit = if (!oj){
    REP(m(0).length) { j =>
      REP(m.length) { i =>
        System.err.print(m(i)(j))
        System.err.print(" ")
      }
      System.err.println()
    }
  }
  def debug(s: => String): Unit = DEBUG {
    System.err.println(s)
  }
  def debugL(num: => Long): Unit = DEBUG {
    System.err.println(num)
  }

  class InputReader(val stream: InputStream) {
    private val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    private var tokenizer: StringTokenizer = _

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

    def nextInt(): Int = Integer.parseInt(next())
    def nextLong(): Long = java.lang.Long.parseLong(next())
    def nextChar(): Char = next().charAt(0)

    def ni(): Int = nextInt()
    def nl(): Long = nextLong()
    def nc(): Char = nextChar()
    def ns(): String = next()
    def ns(n: Int): Array[Char] = ns().toCharArray
    def na(n: Int, offset: Int = 0): Array[Int] = map(n)(_ => ni() + offset)
    def na2(n: Int, offset: Int = 0): (Array[Int], Array[Int]) = {
      val A1, A2 = Array.ofDim[Int](n)
      REP(n) { i =>
        A1(i) = ni() + offset
        A2(i) = ni() + offset
      }
      (A1, A2)
    }
    def nm(n: Int, m: Int): Array[Array[Int]] = {
      val A = Array.ofDim[Int](n, m)
      REP(n) { i =>
        REP(m) { j =>
          A(i)(j) = ni()
        }
      }
      A
    }
    def nal(n: Int): Array[Long] = map(n)(_ => nl())
    def nm_c(n: Int, m: Int): Array[Array[Char]] = map(n) (_ => ns(m))
  }

  def REP(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = offset
    val N = n + offset
    while(i < N) { f(i); i += 1 }
  }
  def REP_r(n: Int, offset: Int = 0)(f: Int => Unit): Unit = {
    var i = n - 1 + offset
    while(i >= offset) { f(i); i -= 1 }
  }
  def TO(from: Int, to: Int)(f: Int => Unit): Unit = {
    REP(to - from + 1, from) { i =>
      f(i)
    }
  }
  def map[@specialized A: ClassTag](n: Int, offset: Int = 0)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    REP(n)(i => res(i) = f(i + offset))
    res
  }

  def sumL(as: Array[Int]): Long = {
    var s = 0L
    REP(as.length)(i => s += as(i))
    s
  }
  def cumSum(as: Array[Int]): Array[Long] = {
    val cum = Array.ofDim[Long](as.length + 1)
    REP(as.length) { i =>
      cum(i + 1) = cum(i) + as(i)
    }
    cum
  }
}

class Main(out: java.io.PrintWriter, sc: Main.InputReader) {
  import sc._
  import Main._
  import java.util.Arrays.sort

  import scala.collection.mutable
  import math.{abs, max, min}
  import mutable.ArrayBuffer

  // toIntとか+7とかするならvalにしろ
  @inline private def MOD = 998244353

  /*
    * 10^18までのpowを配列で用意しておく
    */
  val pow10 = Array.ofDim[Long](30)
  pow10(0) = 1
  REP(pow10.length - 1)(i => pow10(i + 1) = pow10(i) * 10 % MOD)

  def solve(): Unit = {
    val N = ni()
    val A = na(N)
    val MAX = 10
    val D = Array.ofDim[Int](MAX)
    REP(N) { i =>
      D(log10(A(i))) += 1
    }
    debug(D)

    var ans = 0L
    def contributeX(x: Int): Unit = {
      var a = x
      REP(MAX) { i =>
        val d = a % 10
        REP(MAX) { j =>
          val k = i + (min(i, j) + 1)
          ans += pow10(k) * d % MOD * D(j) % MOD
          debug(s"contributeX i:$i j:$j k:$k d:$d Dj:${D(j)} ans:$ans")
        }
        a /= 10
      }
      ans %= MOD
    }

    def contributeY(y: Int): Unit = {
      var a = y
      REP(MAX) { i =>
        val d = a % 10
        REP(MAX) { j =>
          val k = i + min(i - 1, j) + 1
          ans += pow10(k) * d % MOD * D(j) % MOD
          debug(s"contributeY i:$i j:$j k:$k d:$d Dj:${D(j)} ans:$ans")
        }
        a /= 10
      }
      ans %= MOD
    }

    REP(N) { i =>
      contributeX(A(i))
      contributeY(A(i))
    }

    out.println(ans)
  }

  /**
    * @return log10の整数値
    */
  def log10(x: Long): Int = {
    var a = x
    var i = 0
    while(a >= 10) {
      a /= 10
      i += 1
    }
    i
  }
}

import java.io.FileInputStream
import scala.collection.mutable.TreeSet

object HelloWorld {

    import scala.io.StdIn.{readInt, readLine}

    private val MOD = 998244353
    private val pow10: Array[Long] = new Array[Long](31)
    pow10(0) = 1
    for (i <- 1 until 31) {
        pow10(i) = mult(pow10(i - 1), 10)
    }

    def add(a: Long, b: Long): Long = {
        var tmp = a + b
        if (tmp >= MOD) tmp -= MOD
        if (tmp < 0) tmp += MOD
        tmp
    }

    def mult(a: Long, b: Long): Long = (a * b) % MOD

    def f(aOrig: Long): Long = {
        var deg = 0
        var ans: Long = 0
        var a = aOrig
        while (a > 0) {
            val digit = a % 10L
            ans = add(ans, mult(digit, pow10(deg)))
            ans = add(ans, mult(digit, pow10(deg + 1)))
            deg += 2
            a /= 10L
        }
        ans
    }

    def main(args: Array[String]): Unit = {
        val n = readInt()
        val arr: Array[Long] = readLine().split(" ").map(_.toLong)
        val result = arr.map(x => mult(n, f(x)))
            .reduceLeft((acc: Long, x:Long) => add(acc, x))
        println(result)
    }
}


object Main extends App {

  import io.StdIn

  val n = StdIn.readInt

  val cnt = new Array[Int](10)
  val notZero = new Array[Boolean](10)

  for (i <- 0 until n) {
    val s = StdIn.readLine()
    val l = s.length
    notZero(s.charAt(0) - 'a') = true
    var d = 1
    for (i <- 0 to l-1) {
      val ch = s(l - i - 1)
      cnt(ch - 'a') += d
      d *= 10
    }
  }

  var cur = 1
  var usedZero = false
  var ans = 0

  for (i <- 0 to 9) {

    var mx = 0
    for (j <- 0 to 9)
      if (cnt(j) > cnt(mx)) mx = j
    if (!usedZero && !notZero(mx)) {
      usedZero = true
    }
    else {
      ans += cnt(mx) * cur
      cur += 1
    }

    cnt(mx) = 0
  }

  println(ans)

}

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

object MinimumSum extends App {
  val cantBeZero: mutable.Set[Char] = mutable.Set.empty
  val counts: mutable.ArrayBuffer[(Char, Int)] = mutable.ArrayBuffer()
  for (c <- 'a' to 'j') counts.append((c, 0))
  (for (_ <- 0 until StdIn.readLine().toInt) yield StdIn.readLine())
    .foreach(str => {
      cantBeZero += str.charAt(0)
      for (
        offset <- str.length - 1 to(0, -1)
      ) {
        val char: Char = str.charAt(offset)
        val sum = math.pow(10, str.length - 1 - offset).toInt
        counts(char - 'a') = (char, counts(char - 'a')._2 + sum)
      }
    })
  val availableChars: mutable.ListBuffer[Int] = mutable.ListBuffer()
  availableChars.appendAll(0 to 9)
  var totalSum = 0
  counts.sortBy(-_._2).foreach { case (char, sum) =>
    var digit = availableChars.head
    if (digit == 0 && cantBeZero.contains(char)) {
      digit = availableChars.remove(1)
    } else {
      availableChars.remove(0)
    }
    totalSum = totalSum + digit * sum
  }
  println(totalSum)
}

object Main extends App {

  import io.StdIn

  val n = StdIn.readInt

  val cnt = new Array[Int](10)
  val notZero = new Array[Boolean](10)

  for (i <- 0 until n) {
    val s = StdIn.readLine()
    val l = s.length
    if (l > 1) notZero(s.charAt(0) - 'a') = true
    var d = 1
    for (i <- 0 to l-1) {
      val ch = s(l - i - 1)
      cnt(ch - 'a') += d
      d *= 10
    }
  }

  var cur = 1
  var usedZero = false
  var ans = 0

  for (i <- 0 to 9) {

    var mx = 0
    for (j <- 0 to 9)
      if (cnt(j) > cnt(mx)) mx = j
    if (!usedZero && !notZero(mx)) {
      usedZero = true
    }
    else {
      ans += cnt(mx) * cur
      cur += 1
    }

    cnt(mx) = 0
  }

  println(ans)

}


object main extends App with fastIO {

  var num = 0

  def writestr(str: String, n: Int) {
    var need = n - str.length
    var add =
    if ((need & 1) == 1 && num == 1)
      need - (need >> 1); else
      need >> 1

    num ^= need & 1

    print("*")
    for (i <- 1 to add) print(" ")
    print(str)
    for (i <- 1 to need - add) print(" ")
    println("*");
  }

  var lines = Stream.continually(readLine).takeWhile(_ != null)
  val maxLen = lines.reduceLeft((x, y) => if (x.length > y.length) x else y).length

  var str = ""
  for (i <- 1 to maxLen + 2)
    str += "*"

  println(str)
  for (line <- lines) writestr(line, maxLen)
  println(str)

  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile)new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken()
    in.sval
  }

  def nextInt: Int = {
    in.nextToken()
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken()
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken()
    in.nval
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush() = out.flush()
}

import java.util.Scanner

object BCentering extends App {

  val scanner = new Scanner(System.in)

  val input = scala.collection.mutable.ArrayBuffer.empty[String]

  //(0 until 12) foreach {
    //i =>
    while (scanner.hasNextLine) {
      input += scanner.nextLine()
  }

  val max = input.maxBy(_.length).length

  def solve(marginLeft: Boolean, rest: List[String]): List[String] = {
    rest match {
      case Nil => Nil
      case x :: xs =>
        if (same(x)) normalize(x) :: solve(marginLeft, xs)
        else if (marginLeft) normalize(" " + x) :: solve(!marginLeft, xs)
        else normalize(x + " ") :: solve(!marginLeft, xs)
    }
  }

  println("*" * (max + 2))
  println(solve(false, input.toList).mkString("\n"))
  println("*" * (max + 2))

  def same(s: String): Boolean = max % 2 == s.length % 2

  def normalize(s: String): String = {
    val diff = (max - s.length) / 2
    "*" + " " * diff + s + " " * diff + "*"
  }

}

object B5 {

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

  def main(args: Array[String]): Unit = {
    var arr = cu.ArrayBuffer.empty[String]
    var in = read
    while(in != null) {
      arr.append(in)
      in = read
    }
    val len = arr.map(_.length).max
    val res = Array.fill(arr.length+2)(Array.fill(len+2)(' '))
    for(j <- 0 until len+2) {
      res(0)(j) = '*'
      res.last(j) = '*'
    }
    for(i <- res.indices) {
      res(i)(0) = '*'
      res(i)(len+1) = '*'
    }
    var d = 0
    for(i <- arr.indices) {
      val frontPadding = 1 + (len-arr(i).length+d)/2
      for(j <- frontPadding until frontPadding+arr(i).length)
        res(i+1)(j) = arr(i)(j-frontPadding)
      if(arr(i).length%2 != len%2)
        d = 1-d
    }
    println(res.map(_.mkString("")).mkString("\n"))
  }

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

}

/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF5B extends App {
  import scala.collection.mutable.ArrayBuffer
  import java.util.{Scanner}
  import java.io.{PrintWriter}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next
  def nextLine = in.nextLine

  def solve = {
    val lines = ArrayBuffer[String]()
    var maxLength = 0
    while (in.hasNextLine) {
      val s = nextLine
      lines += s
      maxLength = if (s.length > maxLength) s.length else maxLength
    }

    val startAndEnd = (1 to (maxLength + 2)).map(x => "*").mkString("")
    out.println(startAndEnd)

    var isLeft = true
    lines.foreach { line =>
      if (line.length > 0) {
        var leftLen = (maxLength - line.length) / 2
        var rightLen = maxLength - line.length - leftLen

        if (leftLen != rightLen) {
          if (!isLeft) {
            val temp = leftLen
            leftLen = rightLen
            rightLen = temp
          }

          isLeft = !isLeft
        }
        val left = (1 to leftLen).map(x => " ").mkString("")
        val right = (1 to rightLen).map(x => " ").mkString("")
        out.println(s"*${left}${line}${right}*")
      } else {
        out.println(s"*${(1 to maxLength).map(x => " ").mkString("")}*")
      }
    }

    out.println(startAndEnd)
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }
}

object main extends App with fastIO {

  var num = 0

  def writestr(str: String, n: Int) {
    var need = n - str.length
    var add =
    if ((need & 1) == 1 && num == 1)
      need - (need >> 1); else
      need >> 1

    num ^= need & 1

    println("*" + " " * add + str + " " * (need - add) + "*")
  }

  var lines = Stream.continually(readLine).takeWhile(_ != null)
  val maxLen = lines.map(_.length).max

  val str = "*" * (maxLen + 2)

  println(str)
  for (line <- lines) writestr(line, maxLen)
  println(str)

  flush
}

trait fastIO {
  import java.io._

  val isFile = false
  val input = "io.in"
  val output = "io.out"

  val bf = new BufferedReader(if(isFile) new FileReader(input) else new InputStreamReader(System.in))
  val in = new StreamTokenizer(bf)
  val out = new PrintWriter(if(isFile)new FileWriter(output) else new OutputStreamWriter(System.out))

  def next: String = {
    in.ordinaryChars('0', '9')
    in.wordChars('0', '9')
    in.nextToken()
    in.sval
  }

  def nextInt: Int = {
    in.nextToken()
    in.nval.toInt
  }

  def nextLong:Long ={
    in.nextToken()
    in.nval.toLong
  }

  def nextDouble: Double = {
    in.nextToken()
    in.nval
  }

  def readLine: String = bf.readLine()
  def println(o:Any) = out.println(o)
  def print(o:Any) = out.print(o)
  def printf(s:String,o:Any*) = out.printf(s,o)
  def flush() = out.flush()
}

object P5B {
    def main(args: Array[String]) {
        val b = io.Source.stdin.getLines.toBuffer
        val w = b.map{_.size}.max
        println("*" * (w + 2))
        var alt = 0
        for (i <- b) {
            val s = w - i.size
            val s0 = s >> 1
            val s1 = s - s0
            def print(sLeft : Int, sRight : Int) {
                println("*" + " " * sLeft + i + " " * sRight + "*")
            }
            alt match {
                case _ if s0 == s1 => print(s0, s0)
                case 0 => {alt = 1; print(s0, s1)}
                case 1 => {alt = 0; print(s1, s0)}
            }
        }
        println("*" * (w + 2))
    }
}

object Main {
  def repeat(n: Int)(char: Char): String = (0 until n).map(_=>char).mkString
  def main(args: Array[String]) = {
    val strings = io.Source.stdin.getLines.toVector
    val lengths = strings map (s => s.length)
    val maxLens = lengths.max
    lazy val leftOrRight = lengths.map(l => (maxLens - l) % 2 != 0)
      .foldLeft((true, Vector.empty[Boolean])){case (accu, bool) => if(!bool) (accu._1, accu._2 :+ bool)
                                                                    else (accu._1 ^ bool, accu._2 :+ (accu._1 ^ bool))}._2

    lazy val outputs = for ( i <- 0 until strings.length ) yield {
      val left = if(leftOrRight(i)) (maxLens - lengths(i)) / 2 + 1
                 else (maxLens - lengths(i)) / 2
      val right = maxLens - lengths(i) - left
      "*" + repeat(left)(' ') + strings(i) + repeat(right)(' ') + "*"
    }
    println(repeat(maxLens+2)('*'))
    for (str <- outputs) println(str)
    println(repeat(maxLens+2)('*'))
  }
}

object Main {
  def repeat(n: Int)(char: Char): String = (0 until n).map(_=>char).mkString
  def main(args: Array[String]) = {
    val strings = io.Source.stdin.getLines.toVector
    val lengths = strings map (s => s.length)
    val maxLens = lengths.max
    val leftOrRight = lengths.map(l => (maxLens - l) % 2 != 0)
      .foldLeft((true, Vector.empty[Boolean])){case (accu, bool) => if(!bool) (accu._1, accu._2 :+ bool)
                                                                    else (accu._1 ^ bool, accu._2 :+ (accu._1 ^ bool))}._2

    val outputs = for ( i <- 0 until strings.length ) yield {
      val left = if(leftOrRight(i)) (maxLens - lengths(i)) / 2 + 1
                 else (maxLens - lengths(i)) / 2
      val right = maxLens - lengths(i) - left
      "*" + repeat(left)(' ') + strings(i) + repeat(right)(' ') + "*"
    }
    for (b <- leftOrRight) println(b)
    println(repeat(maxLens+2)('*'))
    for (str <- outputs) println(str)
    println(repeat(maxLens+2)('*'))
  }
}

import java.util.Scanner

object BCentering extends App {

  val scanner = new Scanner(System.in)

  val input = scala.collection.mutable.ArrayBuffer.empty[String]

  while (scanner.hasNext) {
    input += scanner.nextLine()
  }

  val max = input.maxBy(_.length).length

  def solve(marginLeft: Boolean, rest: List[String]): List[String] = {
    rest match {
      case Nil => Nil
      case x :: xs =>
        if (same(x)) normalize(x) :: solve(marginLeft, xs)
        else if (marginLeft) normalize(" " + x) :: solve(!marginLeft, xs)
        else normalize(x + " ") :: solve(!marginLeft, xs)
    }
  }

  println("*" * (max + 2))
  println(solve(false, input.toList).mkString("\n"))
  println("*" * (max + 2))

  def same(s: String): Boolean = max % 2 == s.length % 2

  def normalize(s: String): String = {
    val diff = (max - s.length) / 2
    "*" + " " * diff + s + " " * diff + "*"
  }

}

object B5 {

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

  def main(args: Array[String]): Unit = {
    var arr = cu.ArrayBuffer.empty[String]
    var in = read
    while(in != null) {
      arr.append(in)
      in = read
    }
    val len = arr.map(_.length).max
    val res = Array.fill(arr.length+2)(Array.fill(len+2)(' '))
    for(j <- 0 until len+2) {
      res(0)(j) = '*'
      res.last(j) = '*'
    }
    for(i <- res.indices) {
      res(i)(0) = '*'
      res(i)(len+1) = '*'
    }
    var d = 0
    for(i <- arr.indices) {
      val frontPadding = 1 + (len-arr(i).length+d)/2
      for(j <- frontPadding until frontPadding+arr(i).length)
        res(i+1)(j) = arr(i)(j-frontPadding)
      d = 1-d
    }
    println(res.map(_.mkString("")).mkString("\n"))
  }

  object IO {
    private val input = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))

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

}

/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF5B extends App {
  import scala.collection.mutable.ArrayBuffer
  import java.util.{Scanner}
  import java.io.{PrintWriter}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next
  def nextLine = in.nextLine

  def solve = {
    val lines = ArrayBuffer[String]()
    var maxLength = 0
    while (in.hasNext) {
      val s = nextLine
      lines += s
      maxLength = if (s.length > maxLength) s.length else maxLength
    }

    val startAndEnd = (1 to (maxLength + 2)).map(x => "*").mkString("")
    out.println(startAndEnd)
    lines.foreach { line =>
      if (line.length > 0) {
        val leftLen = (maxLength - line.length) / 2
        val rightLen = maxLength - line.length - leftLen
        val left = (1 to leftLen).map(x => " ").mkString("")
        val right = (1 to rightLen).map(x => " ").mkString("")
        out.println(s"*${left}${line}${right}*")
      } else {
        out.println(s"*${(1 to maxLength).map(x => " ").mkString("")}*")
      }
    }

    out.println(startAndEnd)
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }

}

/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF5B extends App {
  import scala.collection.mutable.ArrayBuffer
  import java.util.{Scanner}
  import java.io.{PrintWriter}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next
  def nextLine = in.nextLine

  def solve = {
    val lines = ArrayBuffer[String]()
    var maxLength = 0
    while (in.hasNext) {
      val s = nextLine
      lines += s
      maxLength = if (s.length > maxLength) s.length else maxLength
    }

    val startAndEnd = (1 to (maxLength + 2)).map(x => "*").mkString("")
    out.println(startAndEnd)
    lines.foreach { line =>
      val supp = if (line.length > 0) {
        (1 to (maxLength - line.length) / 2).map(x => " ")
      } else {
        (1 to maxLength).map(x => " ")
      }
      out.println(s"*${supp}${line}${supp}*")
    }

    out.println(startAndEnd)
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }

}

/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF5B extends App {
  import scala.collection.mutable.ArrayBuffer
  import java.util.{Scanner}
  import java.io.{PrintWriter}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next
  def nextLine = in.nextLine

  def solve = {
    val lines = ArrayBuffer[String]()
    var maxLength = 0
    while (in.hasNext) {
      val s = nextLine
      lines += s
      maxLength = if (s.length > maxLength) s.length else maxLength
    }

    val startAndEnd = (1 to (maxLength + 2)).map(x => "*").mkString("")
    out.println(startAndEnd)
    lines.foreach { line =>
      val supp = if (line.length > 0) {
        (1 to (maxLength - line.length) / 2).map(x => " ").mkString("")
      } else {
        (1 to maxLength).map(x => " ").mkString("")
      }
      out.println(s"*${supp}${line}${supp}*")
    }

    out.println(startAndEnd)
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }

}

/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF5B extends App {
  import scala.collection.mutable.ArrayBuffer
  import java.util.{Scanner}
  import java.io.{PrintWriter}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next
  def nextLine = in.nextLine

  def solve = {
    val lines = ArrayBuffer[String]()
    var maxLength = 0
    while (in.hasNext) {
      val s = nextLine
      lines += s
      maxLength = if (s.length > maxLength) s.length else maxLength
    }

    val startAndEnd = (1 to (maxLength + 2)).map(x => "*").mkString("")
    out.println(startAndEnd)
    lines.foreach { line =>
      if (line.length > 0) {
        val leftLen = (maxLength - line.length) / 2
        val rightLen = maxLength - leftLen
        val left = (1 to leftLen).map(x => " ").mkString("")
        val right = (1 to rightLen).map(x => " ").mkString("")
        out.println(s"*${left}${line}${right}*")
      } else {
        out.println(s"*${(1 to maxLength).map(x => " ").mkString("")}*")
      }
    }

    out.println(startAndEnd)
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }

}

/**
 * Created by yangchaozhong on 3/10/15.
 */
object CF5B extends App {
  import scala.collection.mutable.ArrayBuffer
  import java.util.{Scanner}
  import java.io.{PrintWriter}

  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next
  def nextLine = in.nextLine

  def solve = {
    val lines = ArrayBuffer[String]()
    var maxLength = 0
    while (in.hasNext) {
      val s = nextLine
      lines += s
      maxLength = if (s.length > maxLength) s.length else maxLength
    }

    val startAndEnd = (1 to (maxLength + 2)).map(x => "*").mkString("")
    out.println(startAndEnd)

    var isLeft = true
    lines.foreach { line =>
      if (line.length > 0) {
        var leftLen = (maxLength - line.length) / 2
        var rightLen = maxLength - line.length - leftLen

        if (leftLen != rightLen) {
          if (!isLeft) {
            val temp = leftLen
            leftLen = rightLen
            rightLen = temp
          }

          isLeft = !isLeft
        }
        val left = (1 to leftLen).map(x => " ").mkString("")
        val right = (1 to rightLen).map(x => " ").mkString("")
        out.println(s"*${left}${line}${right}*")
      } else {
        out.println(s"*${(1 to maxLength).map(x => " ").mkString("")}*")
      }
    }

    out.println(startAndEnd)
  }

  try {
    solve
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush
    out.close
  }
}


import java.io.PrintWriter
import java.util.Scanner

/**
 * Created by arseny on 30.08.14.
 */
object A extends App {
  val in = new Scanner(System.in)
  val out = new PrintWriter(System.out)

  def nextInt = in.nextInt
  def nextLong = in.nextLong
  def nextDouble = in.nextDouble
  def nextString = in.next

  def solve() = {
    val n = nextInt
    val s = nextInt
    var max = -1
    for(i <- 0 until n) {
      val x = nextInt
      val y = nextInt
      if(y == 0) {
        if(s >= x) {
          max = math.max(max, 0)
        }
      } else {
        if(s >= x + 1) {
          max = math.max(max, 100 - y)
        }
      }
    }
    out.print(max)
  }

  try {
    solve()
  } catch {
    case _: Exception => sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }
}

object Codeforces extends App {
  val in = new java.util.Scanner(System.in)
  var n = in.nextInt()
  var s = in.nextInt() * 100
  var res = -1
  for (i <- 1 to n) {
    var cur = in.nextInt() * 100 + in.nextInt()
    if (s >= cur)
      res = math.max(res, (s - cur) % 100)
  }
  println(res)
}

import java.util.StringTokenizer

object _463A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val s = next.toInt
  val ans = for {
    i <- 1 to n
    val a = next.toInt
    val b = next.toInt
    if (a < s || (a == s && b == 0))
  } yield (100 - b) % 100
  if (ans.length == 0) println(-1)
  else println(ans.max)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, s) = in.next().split(" ").map(_.toInt)
  val r = Range(0, n).map{_ =>
    val d = in.next().split(" ").map(_.toInt)
    s * 100 - (d(0) * 100 + d(1))
  }.filter(_ >= 0).map(_ % 100)
  if (r.isEmpty)
    println(-1)
  else
    println(r.max)
}

object A463 {

  import IO._

  def main(args: Array[String]): Unit = {
    var Array(n, s) = readInts(2)
    s *= 100
    val in = Array.fill(n)(readInts(2)).map{
      arr => s"${arr(0)}${if(arr(1)<10)"0" else ""}${arr(1)}".toInt
    }
    var res = 0
    for(i <- 0 until n) {
      if(s >= in(i)) {
        res = math.max(res, (s - in(i))%100)
      }
    }
    if(in.forall(_ > s)) {
      println("-1")
    } else {
      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 Main {
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val n = cin.nextInt()
    val s = cin.nextInt()
    def solve(n: Int, mx: Int): Int =
      if (n == 0) mx
      else {
        val x = cin.nextInt()
        val y = cin.nextInt()
        if (x < s && y > 0) solve(n - 1, Math.max(mx, 100 - y))
        else if (x <= s && y == 0) solve(n - 1, Math.max(mx, 0))
        else solve(n - 1, mx)
      }
    println(solve(n, -1))
  }
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-28.
 */
object A463 extends App {
  val sc = new Scanner(System.in)
  val n, s = sc.nextInt()
  val allMoney = new Money(s, 0)
  var i = 0
  var maxSweets = -1

  while (i < n) {
    val m = new Money(sc.nextInt(), sc.nextInt())
    var j = 1

    while (m * j <= allMoney) {
      val spend = m * j
      val restMoney = allMoney - spend
      maxSweets = Math.max(restMoney.cent, maxSweets)
      j += 1
    }

    i += 1
  }

  print(maxSweets)
}

class Money(val dollar: Int, val cent: Int) {
  def * (that: Int): Money = {
    var up = 0
    var newCent = 0
    var newDollar = 0

    if (cent * that < 100) {
      newCent = cent
    } else {
      up = cent / 100
      newCent = cent % 100
    }

    newDollar = dollar * that + up
    new Money(newDollar, newCent)
  }

  def <= (that: Money): Boolean = {
    if (this.dollar < that.dollar) {
      true
    } else if (this.dollar == that.dollar){
      if (this.cent <= that.cent) {
        true
      } else {
        false
      }
    } else {
      false
    }
  }

  def - (that: Money): Money = {
    var newCent = 0
    var down = 0

    if (this.cent >= that.cent) {
      newCent = this.cent - that.cent
    } else {
      down = 1
      newCent = this.cent + 100 - that.cent
    }

    new Money(this.dollar - down - that.dollar, newCent)
  }
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, s) = in.next().split(" ").map(_.toInt)
  val r = Range(0, n).map{_ =>
    val d = in.next().split(" ").map(_.toInt)
    d(0) * 100 + d(1)
  }.filter(_ < s).map(_ % 100)
  if (r.isEmpty)
    println(-1)
  else
    println(r.max)
}

object Solution extends App {
  val in = scala.io.Source.stdin.getLines()
  val Array(n, s) = in.next().split(" ").map(_.toInt)
  val r = Range(0, n).map{_ =>
    val d = in.next().split(" ").map(_.toInt)
    d(0) * 100 + d(1)
  }.filter(_ < s).map(99 - _ % 100)
  if (r.isEmpty)
    println(-1)
  else
    println(r.max)
}

object A463 {

  import IO._

  def main(args: Array[String]): Unit = {
    var Array(n, s) = readInts(2)
    s *= 100
    val in = Array.fill(n)(readInts(2)).map{
      arr => (s"${arr(0)}.${arr(1)}".toDouble * 100).toInt
    }
    var res = 0
    for(i <- 0 until n) {
      if(s >= in(i) && in(i)%100 != 0) {
        res = math.max(res, 100 - (in(i)%100))
      }
    }
    if(in.forall(_ > s)) {
      println("-1")
    } else {
      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 A463 {

  import IO._

  def main(args: Array[String]): Unit = {
    var Array(n, s) = readInts(2)
    s *= 100
    val in = Array.fill(n)(readInts(2)).map{
      arr => (s"${arr(0)}.${if(arr(1)<10)"0" else ""}${arr(1)}".toDouble * 100).toInt
    }
    var res = 0
    for(i <- 0 until n) {
      if(s >= in(i)) {
        res = math.max(res, (s - in(i))%100)
      }
    }
    if(in.forall(_ > s)) {
      println("-1")
    } else {
      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 Main {
  def main(args: Array[String]) = {
    val cin = new java.util.Scanner(System.in)
    val n = cin.nextInt()
    val s = cin.nextInt()
    def solve(n: Int, mx: Int): Int =
      if (n == 0) mx
      else {
        val x = cin.nextInt()
        val y = cin.nextInt()
        if (x < s && y > 0) solve(n - 1, Math.max(mx, 100 - y))
        else if (x == s && y == 0) solve(n - 1, Math.max(mx, 0))
        else solve(n - 1, mx)
      }
    println(solve(n, -1))
  }
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-9-28.
 */
object A463 extends App {
  val sc = new Scanner(System.in)
  val n, s = sc.nextInt()
  var i = 0
  var maxSweets: Double = -1

  while (i < n) {
    val x, y = sc.nextInt()
    val d = x + y / 100.0
    var j = 1

    while (d * j <= s) {
      maxSweets = Math.max(((s - d * j) % 1) * 100, maxSweets)
      j += 1
    }

    i += 1
  }

  print(maxSweets.toInt)
}


import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val a = readLine().toCharArray
      val m = readLine()
      val b = readIntLine()
      handle(a, b.toArray)
    }
  }

  def handle(arr: Array[Char], list: Array[Int]): Unit = {
    def findLetter(length: Int, list: List[(Char, Int)]): (Char, List[(Char, Int)]) = list match {
      case Nil => throw new IllegalStateException()
      case (c, r) :: rest => if (r >= length) (c, rest) else findLetter(length, rest)
    }

    var gr = arr.groupBy(i => i).map(tup => (tup._1, tup._2.length)).toList.sortBy(tup => tup._1).reverse

    var containsZero = true
    val t = Array.ofDim[Char](list.length)

    while (containsZero) {
      containsZero = false
      var l = List[Int]()
      for (i <- list.indices) {
        if (list(i) == 0)
          l = i :: l
      }
      if (l.nonEmpty) {
        containsZero = true
        val tup = findLetter(l.length, gr)
        val letter = tup._1
        gr = tup._2
        l.foreach(i => t(i) = letter)
        l.foreach(j => {
          list(j) = list(j) - 1
          for (i <- list.indices) {
            list(i) = list(i) - Math.abs(i - j)
          }
        })
      }
    }

    t.foreach(print)
    println()
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}

object D extends App {
  import scala.io.StdIn._

  val q = readInt()

  (0 until q).foreach { _ =>
    val s  = readLine()
    val m  = readInt()
    var bm = readLine().split(" ").map(_.toInt)

    var t  = Array.ofDim[Char](m)
    val o  = s.distinct.sorted(Ordering.Char.reverse).map(c => (c, s.count(c == _)))

    (0 until m).foldLeft(0) {
      case (prev, _) =>
        val is   = bm.zipWithIndex.collect { case (b, i) if b == 0 => i }
        val curr = o.indexWhere(_._2 >= is.length, prev)

        is.foreach(t(_) = o(curr)._1)

        (0 until m).foreach { j =>
          bm(j) = bm(j) match {
            case 0 | -1 => -1
            case b      => is.foldLeft(b)((b, i) => b - (i - j).abs)
          }
        }

        curr + 1
    }

    println(t.mkString)
  }
}

object Main extends App {
  val r = new FastScanner(java.lang.System.in)
  val o = new java.io.PrintWriter(java.lang.System.out)
  for(_ <- 1 to r.nextInt()) {
    val s = r.nextToken()
    val m = r.nextInt()
    val b = Array.fill(m)(r.nextInt())
    val c = Array.ofDim[Int](26)
    //val x = Array.ofDim[Int](m)
    for(k <- 0 until s.length) c(s(k).toInt - 97) += 1
    val used = Array.fill[Int](m)(-1)
    def loop(k: Int): Unit = {
      if(used.count { _ >= 0 } != m) {
        val l = (for(j <- 0 until m if (used(j) < 0) && b(j) == 0) yield j).toList
        for(j <- 0 until m if (used(j) < 0 && b(j) > 0); i <- l) {
          b(j) -= (j - i).abs
          require(b(j) >= 0)
        }
        for(i <- l) {
          used(i) = k
        }
        loop(k + 1)
      }
    }
    loop(0)
    val d = Array.ofDim[Int](m)
    for(i <- used) d(i) += 1
    val x = Array.ofDim[Char](m)
    var j = 25
    for(i <- 0 until m if (d(i) > 0)) {
      while(j >= 0 && c(j) < d(i)) j -= 1
      for(o <- 0 until m if used(o) == i) x(o) = (j + 97).toChar
      j -= 1
    }
    for(i <- x) o.print(i)
    o.println()
  }
  o.close()
}

import scala.annotation.tailrec
import scala.collection.mutable.StringBuilder

object FastScanner {
  val zero = 0.toByte
  val cr = '\r'.toByte
  val nl = '\n'.toByte
  val BUFFER_SIZE = 0x10000
}

class FastScanner(private val input: java.io.InputStream) {
  private val b = new Array[Byte](FastScanner.BUFFER_SIZE)
  private var n = 0
  private var pos = 0
  private var eof = false
  private def read ():Boolean = {
    if (eof) {
      return false
    }
    pos = 0
    n = input.read(b)
    if (n < 0) {
      eof = true
    }
    n > 0
  }
  private def nextByte(): Byte = {
    if (pos >= n && !read ()) {
      0
    } else {
      val r = b(pos)
      pos += 1
      r
    }
  }
  def nextToken(k: Int = -1): String = {
    val sb = if(k >= 0) new StringBuilder(k) else new StringBuilder()
    var b = skipBlanks()
    assert(b > 0)
    while(b > 32) {
      sb.append(b.toChar)
      b = nextByte()
    }
    sb.toString
  }
  @tailrec
  private def skipBlanks(): Byte = {
    val b = nextByte()
    if(b > 32 || b < 1) b else skipBlanks()
  }
  def nextInt():Int = {
    val b = skipBlanks()
    @tailrec
    def f(t: Int): Int = {
      val b = nextByte ()
      if (b <= 32) t else f(10 * t + (b - 48))
    }
    require(b > 0)
    if (b < 48) -f(0) else f(b - 48)
  }
}

//package codeforces.contests._1367

object _4 {

  def main(args: Array[String]): Unit = {
    for (_ <- 1 to io.StdIn.readInt) {
      val chars: List[(Char, Int)] = {
        val freq = new Array[Int](26)
        io.StdIn.readLine.foreach { c => freq(c - 'a') += 1 }

        freq.indices.map(i => ('a' + i).toChar -> freq(i)).reverse.toList
      }

      val m = io.StdIn.readInt

      val result = new Array[Char](m)

      val ms: Array[Int] = io.StdIn.readLine.split(" ").map(_.toInt)

      @scala.annotation.tailrec
      def loop(chars: List[(Char, Int)]): Unit = {
        val zeroIndexes = ms.indices.filter(ms(_) == 0)

        if (zeroIndexes.nonEmpty) {
          val (c, count) :: tail = chars

          if (count >= zeroIndexes.length) {

            zeroIndexes.foreach { i => ms(i) = -1; result(i) = c }

            zeroIndexes.foreach { z =>
              (z + 1 until m).foreach { r =>
                if (ms(r) > 0) {
                  ms(r) -= r - z
                }
              }

              (z - 1 to 0 by -1).foreach { l =>
                if (ms(l) > 0) {
                  ms(l) -= z - l
                }
              }
            }
          }
          loop(tail)
        }
      }

      loop(chars)

      println(result.mkString(""))
    }
  }

}

object D extends App {
  import scala.io.StdIn._

  val q = readInt()

  (0 until q).foreach { _ =>
    val s  = readLine()
    val m  = readInt()
    val bm = readLine().split(" ").map(_.toInt)

    var t = Array.ofDim[Char](m)

    val o = s.distinct.sorted(Ordering.Char.reverse).map(c => (c, s.count(c == _)))

    (0 until m).foldLeft((bm, 0)) {
      case ((bm, shift), k) =>
        val is = bm.zipWithIndex.collect { case (b, i) if b == 0 => i }

        val tfihs = o.indexWhere({ case (c, l) => l >= is.length }, shift)
        is.foreach(i => t(i) = o(tfihs)._1)

        (bm.zipWithIndex.map {
          case (0, _) | (-1, _) => -1
          case (b, j)           => is.foldLeft(b)((b, i) => b - (i - j).abs)
        }, tfihs + 1)
    }

    println(t.mkString)
  }
}

import scala.io.StdIn.readLine

object Solution {
  val mod: Int = Math.pow(10, 9).toInt + 7

  def main(args: Array[String]): Unit = {
    //    val src = io.Source.fromFile("/usr/share/dict/words")
    //    val lines = src.getLines()
    //    src.close()
    val t = readLine().toInt
    for (i <- 1 to t) {
      val a = readLine().toCharArray
      val m = readLine()
      val b = readIntLine()
      handle(a, b.toArray)
    }
  }

  def handle(arr: Array[Char], list: Array[Int]): Unit = {
    def findLetter(length: Int, list: List[(Char, Int)]): (Char, List[(Char, Int)]) = list match {
      case Nil => throw new IllegalStateException()
      case (c, r) :: rest => if (r >= length) (c, rest) else findLetter(length, rest)
    }

    var gr = arr.groupBy(i => i).map(tup => (tup._1, tup._2.length)).toList.sortBy(tup => tup._1).reverse

    var containsZero = true
    val t = Array.ofDim[Char](list.length)

    while (containsZero) {
      containsZero = false
      var l = List[Int]()
      for (i <- list.indices) {
        if (list(i) == 0)
          l = i :: l
      }
      if (l.nonEmpty) {
        containsZero = true
        val tup = findLetter(l.length, gr)
        val letter = tup._1
        gr = tup._2
        l.foreach(i => t(i) = letter)
        l.foreach(j => {
          list(j) = list(j) - 1
          for (i <- list.indices) {
            list(i) = list(i) - Math.abs(i - j)
          }
        })
      }
    }

    printArray(t)
  }

  def readIntLine(): List[Int] = {
    readLine().split(" ").map(_.toInt).toList
  }

  def printArray[T](arr: Array[T]): Unit = {
    print(arr(0))
    for (i <- 1 until arr.length) {
      print(" " + arr(i))
    }
    println()
  }

  def readLongLine(): List[Long] = {
    readLine().split(" ").map(_.toLong).toList
  }

}


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

object A {

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

  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 Long.parseLong(next)
  }

  def solve = {
    val n = nextInt
    val m = nextInt
    val f = new Array[Array[Char]](n)
    for (i <- 0 until n) {
      f(i) = new Array[Char](m)
      f(i) = next.toCharArray
    }
    var left1 = (-1, -1)
    var right1 = (-1, -1)
    for (i <- 0 until n) {
      for (j <- 0 until m) {
        if (f(i)(j) == '*' && left1._1 == -1) {
          left1 = (i, j)
        }
        if (f(i)(j) == '*') {
          right1 = (i, j)
        }
      }
    }
    var left2 = (-1, -1)
    var right2 = (-1, -1)
    for (j <- 0 until m) {
      for (i <- 0 until n) {
        if (f(i)(j) == '*' && left2._1 == -1) {
          left2 = (i, j)
        }
        if (f(i)(j) == '*') {
          right2 = (i, j)
        }
      }
    }
    for (i <- Math.min(left1._1, left2._1) to Math.max(right1._1, right2._1)) {
      for (j <- Math.min(left1._2, left2._2) to Math.max(right1._2, right2._2)) {
        out.print(f(i)(j))
      }
      out.println
    }
  }

  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.io._
import java.util.StringTokenizer

object ALetter extends App {

  val in = new InputReader(System.in)
  val n = in.nextInt
  val m = in.nextInt
  var arr = Array.ofDim[Char](n, m)
  var (minx, miny) = (Integer.MAX_VALUE, Integer.MAX_VALUE)
  var (maxx, maxy) = (-1, -1)
  for {
    i <- (0 until n)
    s = in.next
    j <- (0 until m)
  } {
    val cur = s(j)
    arr(i)(j) = cur
    if (cur == '.') {

    } else {
      if (i < miny) {
        miny = i
      }
      if (i >= maxy) {
        maxy = i
      }
      if (j < minx) {
        minx = j
      }
      if (j >= maxx) {
        maxx = j;
      }
    }

  }

  var i = miny;
  while (i <= maxy) {
    var j = minx;
    while (j <= maxx) {
      print(arr(i)(j))
      j += 1
    }
    println()
    i += 1
  }

  class InputReader {
    var reader: BufferedReader = null
    var tokenizer: StringTokenizer = null

    def this(stream: InputStream) {
      this()
      reader = new BufferedReader(new InputStreamReader(stream), 32768)
      tokenizer = null
    }

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        try {
          tokenizer = new StringTokenizer(reader.readLine)
        }
        catch {
          case e: IOException => {
            throw new RuntimeException(e)
          }
        }
      }
      return tokenizer.nextToken
    }

    def nextInt: Int = {
      return next.toInt
    }
  }

}

object A14 {

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

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readInts(2)
    val in = Array.fill(n)(read)
    val x1 = in.indexWhere(_.contains('*'))
    val x2 = in.lastIndexWhere(_.contains('*'))
    val y1 = in.map(_.indexWhere(_ == '*')).filter(_ != -1).min
    val y2 = in.map(_.lastIndexWhere(_ == '*')).filter(_ != -1).max

    for(i <- x1 to x2) {
      val buff = cu.ArrayBuffer.empty[Char]
      for(j <- y1 to y2) {
        buff.append(in(i)(j))
      }
      println(buff.mkString(""))
    }
  }

  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")))
    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val res = (1 to n)
    .map(_ => in.next())
    .dropWhile(!_.contains('*'))
    .reverse
    .dropWhile(!_.contains('*'))
    .reverse
  val (left, right) = res.foldLeft(m - 1, 0) {
    case (acc, line) if !line.contains('*') => acc
    case ((l, r), line) => (Math.min(l, line.indexOf('*')), Math.max(r, line.lastIndexOf('*')))
  }

  println(res.map(_.substring(left, right + 1)).mkString("\n"))
}

import scala.io.Source

object Solution extends App {
  val in = Source.stdin.getLines()
  val Array(n, m) = in.next().split(' ').map(_.toInt)
  val res = (1 to n)
    .map(_ => in.next())
    .dropWhile(!_.contains('*'))
    .reverse
    .dropWhile(!_.contains('*'))
    .reverse
  val (left, right) = res.foldLeft(n - 1, 0) {
    case (acc, line) if !line.contains('*') => acc
    case ((l, r), line) => (Math.min(l, line.indexOf('*')), Math.max(r, line.lastIndexOf('*')))
  }

  println(res.map(_.substring(left, right + 1)).mkString("\n"))
}

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

object ALetter extends App {

  val in = new InputReader(System.in)
  val n = in.nextInt
  val m = in.nextInt
  var arr = Array.ofDim[Char](n, m)
  var min = (Integer.MAX_VALUE, Integer.MAX_VALUE)
  var max = (-1, -1)
  for {
    i <- (0 until n)
    s = in.next
    j <- (0 until m)
  } {
    val cur = s(j)
    arr(i)(j) = cur
    if (cur == '.') {

    } else {
      if (i < min._1 && j < min._2) {
        min = (i, j)
      }
      if (i >= max._1 && j >= max._2) {
        max = (i, j)
      }
    }

  }

  for {
    i <- ((min._1) to (max._1)).iterator.map { x => println(); x }
    j <- (min._2) to (max._2)
  } {
    print(arr(i)(j))
  }

  class InputReader {
    var reader: BufferedReader = null
    var tokenizer: StringTokenizer = null

    def this(stream: InputStream) {
      this()
      reader = new BufferedReader(new InputStreamReader(stream), 32768)
      tokenizer = null
    }

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        try {
          tokenizer = new StringTokenizer(reader.readLine)
        }
        catch {
          case e: IOException => {
            throw new RuntimeException(e)
          }
        }
      }
      return tokenizer.nextToken
    }

    def nextInt: Int = {
      return next.toInt
    }
  }

}

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

object ALetter extends App {

  val in = new InputReader(System.in)
  val n = in.nextInt
  val m = in.nextInt
  var arr = Array.ofDim[Char](n, m)
  var min = (Integer.MAX_VALUE, Integer.MAX_VALUE)
  var max = (-1, -1)
  for {
    i <- (0 until n)
    s = in.next
    j <- (0 until m)
  } {
    val cur = s(j)
    arr(i)(j) = cur
    if (cur == '.') {

    } else {
      if (i < min._1 && j < min._2) {
        min = (i, j)
      }
      if (i >= max._1 && j >= max._2) {
        max = (i, j)
      }
    }

  }

  var i = min._1;
  while (i <= max._1) {
    var j = min._2;
    while (j <= max._2) {
      print(arr(i)(j))
      j += 1
    }
    println()
    i += 1
  }

  class InputReader {
    var reader: BufferedReader = null
    var tokenizer: StringTokenizer = null

    def this(stream: InputStream) {
      this()
      reader = new BufferedReader(new InputStreamReader(stream), 32768)
      tokenizer = null
    }

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens) {
        try {
          tokenizer = new StringTokenizer(reader.readLine)
        }
        catch {
          case e: IOException => {
            throw new RuntimeException(e)
          }
        }
      }
      return tokenizer.nextToken
    }

    def nextInt: Int = {
      return next.toInt
    }
  }

}

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

object A {

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

  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 Long.parseLong(next)
  }

  def solve = {
    val n = nextInt
    val m = nextInt
    val f = new Array[Array[Char]](n)
    for (i <- 0 until n) {
      f(i) = new Array[Char](m)
      f(i) = next.toCharArray
    }
    var left = (-1, -1)
    var right = (-1, -1)
    for (i <- 0 until n) {
      for (j <- 0 until m) {
        if (f(i)(j) == '*' && left._1 == -1) {
          left = (i, j)
        }
        if (f(i)(j) == '*') {
          right = (i, j)
        }
      }
    }
    for (i <- left._1 to right._1) {
      for (j <- left._2 to right._2) {
        out.print(f(i)(j))
      }
      out.println
    }
  }

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


object A extends App {
  val t = scala.io.StdIn.readInt()

  (0 until t).foreach { _ =>
    val n = scala.io.StdIn.readInt()

    println(n)
  }
}

object A extends App {
  import java.io._
  import java.nio.file.{Files, Path}
  import java.util.StringTokenizer
  import scala.io.Source
  import scala.io.Codec

  /* Implicit methods */
  implicit def intWithTimes(n: Int) = {
    new {
      def times(f: => Unit): Unit = 1.to(n).foreach { _ => f }
    }
  }
  /* Implicit methods */

  //  val in = new CustomScanner(Source.fromResource("input.txt").mkString)
  val in  = new CustomScanner(System.in)
  val out = new PrintWriter(System.out)

  def solve(): Unit = {
    val inputLines = in.nextInt()

    inputLines.times {
      val m = in.nextInt()
      println(m)
    }
  }

  try {
    solve()
  } catch {
    case ex: Exception =>
      println(ex)
      sys.exit(9999)
  } finally {
    out.flush()
    out.close()
  }

  /**
    * Util methods
    */

  def printArr[T](in: Array[T]) = {
    in.foreach(print)
    println()
  }

  /**
    * Scala implementation of a faster java.util.Scanner
    * See: http://codeforces.com/blog/entry/7018
    */
  class CustomScanner(reader: LineNumberReader) extends Iterator[String] with AutoCloseable {

    def this(reader: BufferedReader) = this(new LineNumberReader(reader))

    def this(reader: Reader) = this(new BufferedReader(reader))

    def this(inputStream: InputStream)(implicit codec: Codec) = this(new InputStreamReader(inputStream, codec.charSet))

    def this(path: Path)(implicit codec: Codec) = this(Files.newBufferedReader(path, codec.charSet))

    def this(file: File)(implicit codec: Codec) = this(file.toPath)(codec)

    def this(str: String) = this(new StringReader(str))

    private[this] val tokenizers = {
      Iterator
        .continually(reader.readLine())
        .takeWhile(_ != null)
        .map(new StringTokenizer(_))
        .filter(_.hasMoreTokens)
    }

    private[this] var current: Option[StringTokenizer] = None

    @inline private[this] def tokenizer(): Option[StringTokenizer] =
      current.find(_.hasMoreTokens) orElse {
        current = if (tokenizers.hasNext) Some(tokenizers.next()) else None
        current
      }

    /**
      * Unlike Java's scanner which returns till end of current line, this actually returns the next line
      * @see line() if you want the Java behaviour
      */
    def nextLine(): String = {
      current = None // reset
      reader.readLine()
    }

    def lineNumber: Int = reader.getLineNumber

    def line(): String = tokenizer().get.nextToken("\n\r")

    def nextString(): String = next()

    def nextChar(): Char = next().ensuring(_.length == 1).head

    def nextBoolean(): Boolean = next().toBoolean

    def nextByte(radix: Int = 10): Byte = java.lang.Byte.parseByte(next(), radix)

    def nextShort(radix: Int = 10): Short = java.lang.Short.parseShort(next(), radix)

    def nextInt(radix: Int = 10): Int = java.lang.Integer.parseInt(next(), radix)

    def nextLong(radix: Int = 10): Long = java.lang.Long.parseLong(next(), radix)

    def nextBigInt(radix: Int = 10): BigInt = BigInt(next(), radix)

    def nextFloat(): Float = next().toFloat

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

    def nextBigDecimal(): BigDecimal = BigDecimal(next())

    override def next(): String = tokenizer().get.nextToken()

    override def hasNext: Boolean = tokenizer().nonEmpty

    override def close(): Unit = reader.close()
  }
}

import scala.io.StdIn.readInt

object Example extends App {
  val t = readInt()

  for (i <- 1 to t) {
    val n = readInt()
    println(n)
  }
}

import scala.io.StdIn

object Solution {

  def main(args: Array[String]): Unit = {
    val t = StdIn.readInt()
    for (_ <- 1 to t) {
      val n = StdIn.readLong()
      println(n)
    }
  }
}

import scala.io.StdIn

object Solution {

  def main(args: Array[String]): Unit = {
    val t = StdIn.readInt()
    for (_ <- 1 to t) {
      val n = StdIn.readInt()
      val result= math.pow(2, n-1).toLong
      println(s"$result")
      Console.flush()
    }
  }
}

import scala.io.StdIn

object Solution {

  def main(args: Array[String]): Unit = {
    val t = StdIn.readInt()
    for (_ <- 1 to t) {
      val n = StdIn.readInt()
      val result= math.pow(2, n-1).toLong
      println(s"$result")
    }
  }
}

import scala.io.StdIn

object Solution {

  def main(args: Array[String]): Unit = {
    val t = StdIn.readInt()
    for (_ <- 1 to t) {
      val n = StdIn.readInt()
      val result= math.pow(2, n-1)
      println(s"$result")
      Console.flush()
    }
  }
}


object C743 {

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

  def main(args: Array[String]): Unit = {
    val Array(n) = readLongs(1)
    if(n == 1)
      println("-1")
    else {
      println(s"${n} ${n+1} ${n*(n+1)}")
    }
  }

  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")))
    @inline def read: String = input.readLine()

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

import scala.annotation.tailrec

object C extends App {
  def readInts = readLine().split(" ").map(_.toInt)

  val n = readInt()

  if (n == 1) println("-1")
  else println(Seq(n, n+1, n*(n+1)).mkString(" "))
}