A sequence of non-negative integers a1, a2, ..., an of length n is called a wool sequence if and only if there exists two integers l and r (1 ≤ l ≤ r ≤ n) such that . In other words each wool sequence contains a subsequence of consecutive elements with xor equal to 0.The expression  means applying the operation of a bitwise xor to numbers x and y. The given operation exists in all modern programming languages, for example, in languages C++ and Java it is marked as "^", in Pascal — as "xor".In this problem you are asked to compute the number of sequences made of n integers from 0 to 2m - 1 that are not a wool sequence. You should print this number modulo 1000000009 (109 + 9).

The only line of input contains two space-separated integers n and m (1 ≤ n, m ≤ 105).

Print the required number of sequences modulo 1000000009 (109 + 9) on the only line of output.

NoteSequences of length 3 made of integers 0, 1, 2 and 3 that are not a wool sequence are (1, 3, 1), (1, 2, 1), (2, 1, 2), (2, 3, 2), (3, 1, 3) and (3, 2, 3).

object A {
  val mod = 1000000009L

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

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

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

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

import java.util._

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

  val n, m = sc.nextInt()

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

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

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


One day Kefa found n baloons. For convenience, we denote color of i-th baloon as si — lowercase letter of the Latin alphabet. Also Kefa has k friends. Friend will be upset, If he get two baloons of the same color. Kefa want to give out all baloons to his friends. Help Kefa to find out, can he give out all his baloons, such that no one of his friens will be upset — print «YES», if he can, and «NO», otherwise. Note, that Kefa's friend will not upset, if he doesn't get baloons at all.

The first line contains two integers n and k (1 ≤ n, k ≤ 100) — the number of baloons and friends. Next line contains string s — colors of baloons.

Answer to the task — «YES» or «NO» in a single line. You can choose the case (lower or upper) for each letter arbitrary.

NoteIn the first sample Kefa can give 1-st and 3-rd baloon to the first friend, and 2-nd and 4-th to the second.In the second sample Kefa needs to give to all his friends baloons of color a, but one baloon will stay, thats why answer is «NO».

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

import java.util.Scanner

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

import java.util.Scanner

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

import java.util.Scanner

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

import java.util.Scanner

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


Bob is decorating his kitchen, more precisely, the floor. He has found a prime candidate for the tiles he will use. They come in a simple form factor — a square tile that is diagonally split into white and black part as depicted in the figure below.  The dimension of this tile is perfect for this kitchen, as he will need exactly $$$w \times h$$$ tiles without any scraps. That is, the width of the kitchen is $$$w$$$ tiles, and the height is $$$h$$$ tiles. As each tile can be rotated in one of four ways, he still needs to decide on how exactly he will tile the floor. There is a single aesthetic criterion that he wants to fulfil: two adjacent tiles must not share a colour on the edge — i.e. one of the tiles must have a white colour on the shared border, and the second one must be black.    The picture on the left shows one valid tiling of a $$$3 \times 2$$$ kitchen. The picture on the right shows an invalid arrangement, as the bottom two tiles touch with their white parts. Find the number of possible tilings. As this number may be large, output its remainder when divided by $$$998244353$$$ (a prime number).

The only line contains two space separated integers $$$w$$$, $$$h$$$ ($$$1 \leq w,h \leq 1\,000$$$) — the width and height of the kitchen, measured in tiles.

Output a single integer $$$n$$$ — the remainder of the number of tilings when divided by $$$998244353$$$.

object C extends App {

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

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

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

  println(res)
}

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

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

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

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

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

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

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

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

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

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

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

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


Eighth-grader Vova is on duty today in the class. After classes, he went into the office to wash the board, and found on it the number n. He asked what is this number and the teacher of mathematics Inna Petrovna answered Vova that n is the answer to the arithmetic task for first-graders. In the textbook, a certain positive integer x was given. The task was to add x to the sum of the digits of the number x written in decimal numeral system.Since the number n on the board was small, Vova quickly guessed which x could be in the textbook. Now he wants to get a program which will search for arbitrary values of the number n for all suitable values of x or determine that such x does not exist. Write such a program for Vova.

The first line contains integer n (1 ≤ n ≤ 109).

In the first line print one integer k — number of different values of x satisfying the condition.  In next k lines print these values in ascending order.

NoteIn the first test case x = 15 there is only one variant: 15 + 1 + 5 = 21.In the second test case there are no such x.

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

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

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

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

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

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

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

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

    outLn(res)
    finish
  }

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

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

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

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

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

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

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

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

val sa1 = """
21
"""

val sa2 = """
20
"""

val sa3 = """
100
"""
}

}

import scala.collection.mutable.ListBuffer

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

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

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

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

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

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

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

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

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

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

    outLn(res)
    finish
  }

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

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

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

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

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

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

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

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

val sa1 = """
21
"""

val sa2 = """
20
"""

val sa3 = """
100
"""
}

}


In Berland a money reform is being prepared. New coins are being introduced. After long economic calculations was decided that the most expensive coin should possess the denomination of exactly n Berland dollars. Also the following restriction has been introduced for comfort: the denomination of each coin should be divisible by the denomination of any cheaper coin. It is known that among all the possible variants the variant with the largest number of new coins will be chosen. Find this variant. Print in the order of decreasing of the coins' denominations.

The first and only line contains an integer n (1 ≤ n ≤ 106) which represents the denomination of the most expensive coin.

Print the denominations of all the coins in the order of decreasing. The number of coins must be the largest possible (with the given denomination n of the most expensive coin). Also, the denomination of every coin must be divisible by the denomination of any cheaper coin. Naturally, the denominations of all the coins should be different. If there are several solutins to that problem, print any of them.

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

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

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

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

import scala.io.Source

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

  println(res.mkString(" "))
}

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

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

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

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

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

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

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

}

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

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

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

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

}

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

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

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


Your friend has recently learned about coprime numbers. A pair of numbers {a, b} is called coprime if the maximum number that divides both a and b is equal to one. Your friend often comes up with different statements. He has recently supposed that if the pair (a, b) is coprime and the pair (b, c) is coprime, then the pair (a, c) is coprime. You want to find a counterexample for your friend's statement. Therefore, your task is to find three distinct numbers (a, b, c), for which the statement is false, and the numbers meet the condition l ≤ a < b < c ≤ r. More specifically, you need to find three numbers (a, b, c), such that l ≤ a < b < c ≤ r, pairs (a, b) and (b, c) are coprime, and pair (a, c) is not coprime.

The single line contains two positive space-separated integers l, r (1 ≤ l ≤ r ≤ 1018; r - l ≤ 50).

Print three positive space-separated integers a, b, c — three distinct numbers (a, b, c) that form the counterexample. If there are several solutions, you are allowed to print any of them. The numbers must be printed in ascending order.  If the counterexample does not exist, print the single number -1.

NoteIn the first sample pair (2, 4) is not coprime and pairs (2, 3) and (3, 4) are. In the second sample you cannot form a group of three distinct integers, so the answer is -1. In the third sample it is easy to see that numbers 900000000000000009 and 900000000000000021 are divisible by three.

import java.util.StringTokenizer

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

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

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

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

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

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

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

}

object A483 {

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

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

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

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

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

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

}

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

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

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

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

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

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

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

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

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

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

  }

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

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

def main(args: Array[String]) {

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

}

}

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

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

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

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

  }

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

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

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

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

  }

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

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

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

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

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

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

  }

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

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

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

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

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

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

  }

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

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

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

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

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

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

  }


A monster is attacking the Cyberland!Master Yang, a braver, is going to beat the monster. Yang and the monster each have 3 attributes: hitpoints (HP), offensive power (ATK) and defensive power (DEF).During the battle, every second the monster's HP decrease by max(0, ATKY - DEFM), while Yang's HP decreases by max(0, ATKM - DEFY), where index Y denotes Master Yang and index M denotes monster. Both decreases happen simultaneously Once monster's HP ≤ 0 and the same time Master Yang's HP > 0, Master Yang wins.Master Yang can buy attributes from the magic shop of Cyberland: h bitcoins per HP, a bitcoins per ATK, and d bitcoins per DEF.Now Master Yang wants to know the minimum number of bitcoins he can spend in order to win.

The first line contains three integers HPY, ATKY, DEFY, separated by a space, denoting the initial HP, ATK and DEF of Master Yang. The second line contains three integers HPM, ATKM, DEFM, separated by a space, denoting the HP, ATK and DEF of the monster. The third line contains three integers h, a, d, separated by a space, denoting the price of 1 HP, 1 ATK and 1 DEF. All numbers in input are integer and lie between 1 and 100 inclusively.

The only output line should contain an integer, denoting the minimum bitcoins Master Yang should spend in order to win.

NoteFor the first sample, prices for ATK and DEF are extremely high. Master Yang can buy 99 HP, then he can beat the monster with 1 HP left.For the second sample, Master Yang is strong enough to beat the monster, so he doesn't need to buy anything.

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

}

import scala.collection._

object A extends App {

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

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

  var min = Long.MaxValue

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

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

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

      val h = binSearch(0, 100000000L)

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

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

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

  println(min)
}

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

}

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

}

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

}

import scala.collection._

object A extends App {

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

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

  var min = Long.MaxValue

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

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

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

      val h = binSearch(0, 100000000L)

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

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

  println(min)
}

import scala.collection._

object A extends App {

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

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

  var min = Long.MaxValue

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

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

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

      val h = binSearch(0, 100000000L)

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

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

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

  println(min)
}

import scala.collection._

object A extends App {

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

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

  var min = Long.MaxValue

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

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

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

      val h = binSearch(0, 100000000L)

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

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

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

  println(min)
}

import scala.collection._

object A extends App {

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

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

  var min = Long.MaxValue

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

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

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

      val h = binSearch(0, 100000000L)

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

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

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

  println(min)
}

import scala.collection._

object A extends App {

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

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

  var min = Long.MaxValue

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

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

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

      val h = binSearch(0, 100000000L)

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

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

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

  println(min)
}


Dima loves representing an odd number as the sum of multiple primes, and Lisa loves it when there are at most three primes. Help them to represent the given number as the sum of at most than three primes.More formally, you are given an odd numer n. Find a set of numbers pi (1 ≤ i ≤ k), such that 1 ≤ k ≤ 3 pi is a prime The numbers pi do not necessarily have to be distinct. It is guaranteed that at least one possible solution exists.

The single line contains an odd number n (3 ≤ n < 109).

In the first line print k (1 ≤ k ≤ 3), showing how many numbers are in the representation you found. In the second line print numbers pi in any order. If there are multiple possible solutions, you can print any of them.

NoteA prime is an integer strictly larger than one that is divisible only by one and by itself.

/**
 * @author netman
 */

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

object HelloWorld {

  class InputReader(reader: BufferedReader) {

    var tokenizer: StringTokenizer = null;

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

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

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

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

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

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

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

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

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

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

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

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

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

    var primes = ArrayBuffer.empty[Int]

    primes += 0

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

    primes
  }

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

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

    val x = in.nextInt

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

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

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

          out.close

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

    out.close
  }
}

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

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

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

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

object D {

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

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

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

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

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

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

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

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

import scala.collection.mutable

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

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

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

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

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


You have two variables a and b. Consider the following sequence of actions performed with these variables: If a = 0 or b = 0, end the process. Otherwise, go to step 2; If a ≥ 2·b, then set the value of a to a - 2·b, and repeat step 1. Otherwise, go to step 3; If b ≥ 2·a, then set the value of b to b - 2·a, and repeat step 1. Otherwise, end the process.Initially the values of a and b are positive integers, and so the process will be finite.You have to determine the values of a and b after the process ends.

The only line of the input contains two integers n and m (1 ≤ n, m ≤ 1018). n is the initial value of variable a, and m is the initial value of variable b.

Print two integers — the values of a and b after the end of the process.

NoteExplanations to the samples: a = 12, b = 5  a = 2, b = 5  a = 2, b = 1  a = 0, b = 1; a = 31, b = 12  a = 7, b = 12.

object B extends App {

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

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

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

  println(s"$a $b")
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

object B extends App {

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

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

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

  println(s"$a $b")
}


Dima and his friends have been playing hide and seek at Dima's place all night. As a result, Dima's place got messy. In the morning they decided that they need to clean the place.To decide who exactly would clean the apartment, the friends want to play a counting-out game. First, all the guys stand in a circle, and then each of them shows some number of fingers on one hand (one to five), and then the boys count in a circle, starting from Dima, the number of people, respective to the total number of fingers shown. The person on who the countdown stops will clean the apartment.For example, if Dima and one of his friends played hide and seek, and 7 fingers were shown during the counting-out, then Dima would clean the place. If there were 2 or say, 8 fingers shown, then his friend would clean the place.Dima knows how many fingers each of his friends will show during the counting-out. Now he is interested in the number of ways to show some number of fingers on one hand (one to five), so that he did not have to clean the place. Help Dima.

The first line contains integer n (1 ≤ n ≤ 100) — the number of Dima's friends. Dima himself isn't considered to be his own friend. The second line contains n positive integers, not exceeding 5, representing, how many fingers the Dima's friends will show.  The numbers in the lines are separated by a single space.

In a single line print the answer to the problem.

NoteIn the first sample Dima can show 1, 3 or 5 fingers. If Dima shows 3 fingers, then the counting-out will go like that: Dima, his friend, Dima, his friend.In the second sample Dima can show 2 or 4 fingers.

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

import java.util.StringTokenizer

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

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

object A272 {

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

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

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

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

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

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

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

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

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

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

  out.println(answer)
  out.close
}

import java.util._

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

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

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

import annotation.tailrec
import java.io._

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

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

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

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

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

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

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

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

    println(ans)
}

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

object A272 {

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

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

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

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

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

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

object A272 {

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

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

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

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

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

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

object A272 {

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

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

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

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

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

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}


Little Petya wanted to give an April Fools Day present to some scientists. After some hesitation he decided to give them the array that he got as a present in Codeforces Round #153 (Div.2). The scientists rejoiced at the gift and decided to put some important facts to this array. Here are the first few of the facts: The highest mountain above sea level in the world is Mount Everest. Its peak rises to 8848 m.  The largest board game tournament consisted of 958 participants playing chapaev. The largest online maths competition consisted of 12766 participants. The Nile is credited as the longest river in the world. From its farthest stream in Burundi, it extends 6695 km in length. While not in flood, the main stretches of the Amazon river in South America can reach widths of up to 1100 km at its widest points. Angel Falls is the highest waterfall. Its greatest single drop measures 807 m. The Hotel Everest View above Namche, Nepal — the village closest to Everest base camp – is at a record height of 31962 m Uranium is the heaviest of all the naturally occurring elements. Its most common isotope has a nucleus containing 146 neutrons. The coldest permanently inhabited place is the Siberian village of Oymyakon, where the temperature of -68°C was registered in the twentieth century. The longest snake held in captivity is over 25 feet long. Its name is Medusa. Colonel Meow holds the world record for longest fur on a cat — almost 134 centimeters. Sea otters can have up to 10000 hairs per square inch. This is the most dense fur in the animal kingdom. The largest state of USA is Alaska; its area is 663268 square miles Alaska has a longer coastline than all of the other 49 U.S. States put together: it is 154103 miles long. Lake Baikal is the largest freshwater lake in the world. It reaches 1642 meters in depth and contains around one-fifth of the world’s unfrozen fresh water. The most colorful national flag is the one of Turkmenistan, with 106 colors.

The input will contain a single integer between 1 and 16.


Furik loves math lessons very much, so he doesn't attend them, unlike Rubik. But now Furik wants to get a good mark for math. For that Ms. Ivanova, his math teacher, gave him a new task. Furik solved the task immediately. Can you?You are given a system of equations:   You should count, how many there are pairs of integers (a, b) (0 ≤ a, b) which satisfy the system.

A single line contains two integers n, m (1 ≤ n, m ≤ 1000) — the parameters of the system. The numbers on the line are separated by a space.

On a single line print the answer to the problem.

NoteIn the first sample the suitable pair is integers (3, 0). In the second sample the suitable pair is integers (3, 5). In the third sample there is no suitable pair.

object Round131A2 {

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    var res = 0
    for (a <- 0 to 1000)
      for (b <- 0 to 1000)
        if (a * a + b == n && a + b * b == m)
          res = res + 1
    println(res)
  }

}

import java.util.StringTokenizer

object _214A extends App {
  var token = new StringTokenizer("")
  def next = {
    while (!token.hasMoreTokens()) token = new StringTokenizer(readLine)
    token.nextToken()
  }
  val n = next.toInt
  val m = next.toInt
  val ans = for {
    a <- 0 to m
    val b = n - a * a
    if (b >= 0 && a + b * b == m)
  } yield 1
  println(ans.sum)
}

object Solution extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  println(Range(0, 1000).flatMap(i => Range(0, 1000).map(t => (i, t))).count{
    case(a, b) => a * a + b == n && a + b * b == m
  })

}

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

object P214A extends App {
  val sc = new Scanner(System.in)
  val out = new PrintWriter(System.out)
  val N, M = sc.nextInt

  val answer = {
    for {
      i <- 0 until 32
      j <- 0 until 32
      if i * i + j == N && i + j * j == M
    } yield 1
  }.sum

  out.println(answer)
  out.close
}

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

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

  val Array(n, m) = readInts
  def sqr(x: Int) = x * x
  def ans = (0 to n).filter(n - sqr(_) >= 0).count(a => a + sqr(n - sqr(a)) == m)

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

object Main {
  def main(args: Array[String]) {
    val mn = readLine().split(" ").map(_.toInt)
    val m = mn(0)
    val n = mn(1)
    var count = 0
    val s = for {
      a <- 0 to (Math.sqrt(m).toInt + 1)
      b <- 0 to (Math.sqrt(n).toInt + 1)
      if a * a + b == m && a + b * b == n
    } yield (1)
    println(s.size)
  }
}

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

    val (n,m)={
      val sp=readLine.split(" ")
      (sp(0).toInt, sp(1).toInt)
    }

    println(
      0 to 1000 count{a=>
        val b= n-a*a
        b>=0 && a+b*b==m
      }
    )
  }
}

import scala.io.StdIn

object Main {
  def main(args: Array[String]): Unit = {
    val Array(n, m) = StdIn.readLine().split(" ").map(_.toInt)
    println(f(n, m))
  }

  def f(n: Int, m: Int): Int = {
    var r = 0
    for {
      a <- 0 to 100
      b <- 0 to 100
      if a * a + b == n && a + b * b == m
    } yield {
      r += 1
    }
    r
  }
}

object Round131A2 {

  def main(args: Array[String]): Unit = {
    val Array(n, m) = readLine().split(" ").map(_.toInt)
    var res = 0
    for (a <- 1 to 1000)
      for (b <- 1 to 1000)
        if (a * a + b == n && a + b * b == m)
          res = res + 1
    println(res)
  }

}

object Solution extends App {
  val Array(n, m) = readLine().split(" ").map(_.toInt)
  println(Range(0, 1000).flatMap(i => Range(0, i).map(t => (i, t))).count{
    case(a, b) => a * a + b == n && a + b * b == m
  })

}

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

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

  val N, M = sc.nextInt

  out.println(List(N, M).mkString(" "))

  val answer = {
    for {
      a <- 0 to math.sqrt(N).floor.toInt
      b = math.sqrt(M - a).floor.toInt
      if a + b * b == M && a * a + b == N
    } yield 1
  }.size

  out.println(answer)
  out.close
}

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

    val (n,m)={
      val sp=readLine.split(" ")
      (sp(0).toInt, sp(1).toInt)
    }

    println(
      0 to 1000 count{a=>
        val b= n-a*a
        a+b*b==m
      }
    )
  }
}


George woke up and saw the current time s on the digital clock. Besides, George knows that he has slept for time t. Help George! Write a program that will, given time s and t, determine the time p when George went to bed. Note that George could have gone to bed yesterday relatively to the current time (see the second test sample).

The first line contains current time s as a string in the format "hh:mm". The second line contains time t in the format "hh:mm" — the duration of George's sleep. It is guaranteed that the input contains the correct time in the 24-hour format, that is, 00 ≤ hh ≤ 23, 00 ≤ mm ≤ 59.

In the single line print time p — the time George went to bed in the format similar to the format of the time in the input.

NoteIn the first sample George went to bed at "00:06". Note that you should print the time only in the format "00:06". That's why answers "0:06", "00:6" and others will be considered incorrect. In the second sample, George went to bed yesterday.In the third sample, George didn't do to bed at all.

object ThreeEightSevenA {

	def main(args: Array[String]): Unit = {
		var to=readLine.split(':').map(_.toInt)
		var from=readLine.split(':').map(_.toInt)

		if(to(0)==from(0) && to(1)==from(1)){
			println("00:00")
			return
		}

		if(to(0)==0 && to(1)==0){
			to(0)=24
		}

		var h=to(0)-from(0)
		var min=to(1)-from(1)

		if(min<0)
		{
			h=h-1
			min+=60
		}
		if(h<0){
			h+=24
		}
		if(h<10)
			print("0"+h)
		else
			print(h)

		print(":")

		if(min<10)
			println("0"+min)
		else
			println(min)

	}
}

import java.util.StringTokenizer

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

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

  val cb = next.split(":").map(s => s.toInt)
  val wb = next.split(":").map(s => s.toInt)

  var h = cb(0)
  var m = cb(1)
  val h1 = wb(0)
  val m1 = wb(1)

  if (h < h1 || h == h1 && m < m1) h += 24

  if (m < m1) {
    m += 60
    h -= 1
  }

  println("%02d:%02d".format(h - h1, m - m1))
}

object Solution extends App {

  val in = scala.io.Source.stdin.getLines()
  val k = in.next()
  val t = in.next()
  var hourNow = k.take(2).toInt
  var minutesNow = k.drop(3).toInt
  val hours = t.take(2).toInt
  val minutes = t.drop(3).toInt
  if (minutesNow < minutes) {
    minutesNow += 60
    hourNow -= 1
  }
  if (hourNow < hours)
    hourNow += 24
  hourNow -= hours
  minutesNow -= minutes
  println(f"$hourNow%02d:$minutesNow%02d")

}

import java.util.Scanner

object P387A {
    class Time(timeString: String) {
        val splitTime = timeString.split(":")
        val hour = splitTime(0).toInt
        val minute = splitTime(1).toInt
        val totalMinute = hour * 60 + minute
        def -(that: Time): Time = {
            val t = (this.totalMinute - that.totalMinute + 60 * 24) % (60 * 24)
            new Time(t / 60 + ":" + t % 60)
        }
        override def toString =
            "0" * (2 - hour.toString.length) + hour + ":" + "0" * (2 - minute.toString.length) + minute
    }

    def main(args: Array[String]) {
        val scanner = new Scanner(System.in)
        val wakeUpTime = new Time(scanner.next())
        val sleepTime = new Time(scanner.next())
        val bedInTime = wakeUpTime - sleepTime
        println(bedInTime)
    }
}

object A387 {

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

  def main(args: Array[String]): Unit = {
    val curr = read.split(":").map(_.toInt)
    val time = read.split(":").map(_.toInt)

    val start = Array(((if(curr(1)-time(1) < 0) -1 else 0) + 24+curr(0)-time(0))%24, (60+curr(1)-time(1))%60)

    out.println(s"${"%02d".format(start(0))}:${"%02d".format(start(1))}")
    out.close()
  }

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

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

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

    def readInt: Int = tokenizeLine.nextToken.toInt

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

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

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

}

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

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

  object Clock {
    def apply(m: Int): String = {
      val hour = m / 60
      val min  = m % 60
      f"$hour%02d:$min%02d"
    }

    def unapply(s: String): Option[Int] = {
      val parts = s split ":"
      if (parts.length == 2) Some(parts(0).toInt * 60 + parts(1).toInt)
      else None
    }
  }

  def solve(): String = {
    val Clock(t0) = sc.nextLine
    val Clock(t1) = sc.nextLine
    if (t0 >= t1) Clock(t0 - t1)
    else Clock(t0 - t1 + 1440)
  }

  out.println(solve)
  out.close
}

import java.util.Scanner

/**
 * Created by Kuang.Ru on 14-10-10.
 */
object A387 {
  def main(args: Array[String]) {
    val sc = new Scanner(System.in)
    val s, t = sc.next()
    var st = s.split(":").map(_.toInt)
    val tt = t.split(":").map(_.toInt)
    var goBedMin = st(1) - tt(1)

    if (goBedMin < 0) {
      st(0) -= 1
      goBedMin = 60 + goBedMin
    }

    var goBedHour = st(0) - tt(0)

    if (goBedHour < 0) {
      goBedHour = 24 + goBedHour
    }

    printf("%02d:%02d", goBedHour, goBedMin)
  }
}

import scala.util.matching.Regex

object A extends App {
  def ms2s(ms: (Int, Int)) = { ms._1*60 + ms._2 }
  def s2ms(s: Int) = { (s/60, s%60) }
  def str2ms(s: String): (Int, Int) = {
    val p: Regex = """([0-9][0-9]):([0-9][0-9])""".r
    val m: Regex.Match = p.findFirstMatchIn(s).get
    return (m.group(1).toInt, m.group(2).toInt)
  }

  val a = readLine()
  val b = readLine()

  var ta = ms2s(str2ms(a))
  val tb = ms2s(str2ms(b))

  if (ta < tb) ta += 24*60
  val ans = s2ms(ta - tb)
  println("%02d:%02d".format(ans._1, ans._2))
}

import scala.util.matching.Regex

object A extends App {
  def ms2s(ms: (Int, Int)) = { ms._1*60 + ms._2 }
  def s2ms(s: Int) = { (s/60, s%60) }
  def str2ms(s: String): (Int, Int) = {
    val p: Regex = """([0-9][0-9]):([0-9][0-9])""".r
    val m: Regex.Match = p.findFirstMatchIn(s).get
    return (m.group(1).toInt, m.group(2).toInt)
  }

  var ta, tb = ms2s(str2ms(readLine()))
  val ans = s2ms(ta+(if (ta < tb) 24*60 else 0) - tb)
  println("%02d:%02d".format(ans._1, ans._2))
}

object ThreeEightSevenA {

	def main(args: Array[String]): Unit = {
		var to=readLine.split(':').map(_.toInt)
		var from=readLine.split(':').map(_.toInt)
		if(to(0)==from(0) && to(1)==from(1)){
			println("00:00")
			return
		}
		if(to(0)==0 && to(1)==0){
			to(0)=24
		}
		var h=to(0)-from(0)
		var min=to(1)-from(1)

		if(min<0)
		{
			h=h-1
			min=min+60
		}

		if(h<10)
			print("0"+h)
		else
			print(h)
		print(":")
		if(min<10)
			println("0"+min)
		else
			println(min)

	}
}

object ThreeEightSevenA {

	def main(args: Array[String]): Unit = {
		var to=readLine.split(':').map(_.toInt)
		var from=readLine.split(':').map(_.toInt)
		if(to(0)==0 && to(1)==0){
			to(0)=24
		}
		var h=to(0)-from(0)
		var min=to(1)-from(1)
		if(min<0)
		{
			h=h-1
			min=min+60
		}
		if(h<10)
			print("0"+h)
		else
			print(h)
		print(":")
		if(min<10)
			println("0"+min)
		else
			println(min)
	}

}

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

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

  object Clock {
    def apply(m: Int): String = {
      val hour = m / 60
      val min  = m % 60
      f"$hour%02d:$min%02d"
    }

    def unapply(s: String): Option[Int] = {
      val parts = s split ":"
      if (parts.length == 2) Some(parts(0).toInt * 60 + parts(1).toInt)
      else None
    }
  }

  def solve(): String = {
    val Clock(t0) = sc.nextLine
    val Clock(t1) = sc.nextLine
    if (t0 > t1) Clock(t0 - t1)
    else Clock(t0 - t1 + 1440)
  }

  out.println(solve)
  out.close
}


Ternary numeric notation is quite popular in Berland. To telegraph the ternary number the Borze alphabet is used. Digit 0 is transmitted as «.», 1 as «-.» and 2 as «--». You are to decode the Borze code, i.e. to find out the ternary number given its representation in Borze alphabet.

The first line contains a number in Borze code. The length of the string is between 1 and 200 characters. It's guaranteed that the given string is a valid Borze code of some ternary number (this number can have leading zeroes).

Output the decoded ternary number. It can have leading zeroes.

object P032B extends App {
  def f(a: List[Char]):Unit = a match {
    case '.'::tail => print(0); f(tail)
    case '-'::'.'::tail => print(1); f(tail)
    case '-'::'-'::tail => print(2); f(tail)
    case Nil =>
  }
  f(readLine.toList)
}

object Solution extends App {
  val in = io.Source.stdin.getLines()
  val text = in.next().foldLeft(None: Option[Char], List.empty[Int]) {
    case((None, list), '.') => (None, 0 :: list)
    case((None, list), '-') => (Some('-'), list)
    case((Some('-'), list), '-') => (None, 2 :: list)
    case((Some('-'), list), '.') => (None, 1 :: list)
  }

  println(text._2.reverse.mkString)

}

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

  val ans = readLine()
    .foldLeft((List.empty[Int], "")) {
      case ((codes, code), part) =>
        code + part match {
          case "."  => (0 :: codes, "")
          case "-." => (1 :: codes, "")
          case "--" => (2 :: codes, "")
          case _    => (codes, part.toString)
        }
    }
    ._1
    .reverse

  println(ans.mkString(""))
}

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

  val ans = readLine().replace("--", "2").replace("-.", "1").replace(".", "0")

  println(ans.mkString(""))
}

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

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var s = readLine;
    var result = "";
    while (s.length > 0) {
      if (s.startsWith(".")) {
        result += "0";
        s = s.replaceFirst(".", "");
      } else if (s.startsWith("-.")) {
        result += "1";
        s = s.replaceFirst("-.", "");
      } else if (s.startsWith("--")) {
        result += "2";
        s = s.replaceFirst("--", "");
      }
    }
    println(result);
  }

}

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

object HelloWorld {

  def main(args: Array[String]): Unit = {
    var s = readLine;
    var result = "";
    var ind = 0;
    while (ind < s.length) {
      if (s.startsWith(".", ind)) {
        result += "0";
        ind += 1;
      } else if (s.startsWith("-.", ind)) {
        result += "1";
        ind += 2;
      } else if (s.startsWith("--", ind)) {
        result += "2";
        ind += 2;
      }
    }
    println(result);
  }

}