object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M, X, Y = sc.nextInt()
  val x = List.fill(N)(sc.nextInt())
  val y = List.fill(M)(sc.nextInt())
  println(if (x.max < y.min) "No War" else "War")
}

Score : 200 points

Problem Statement

Our world is one-dimensional, and ruled by two empires called Empire A and Empire B.

The capital of Empire A is located at coordinate X, and that of Empire B is located at coordinate Y.

One day, Empire A becomes inclined to put the cities at coordinates x_1, x_2, ..., x_N under its control, and Empire B becomes inclined to put the cities at coordinates y_1, y_2, ..., y_M under its control.

If there exists an integer Z that satisfies all of the following three conditions, they will come to an agreement, but otherwise war will break out.

X < Z \leq Y

x_1, x_2, ..., x_N < Z

y_1, y_2, ..., y_M \geq Z

Determine if war will break out.

Constraints

All values in input are integers.

1 \leq N, M \leq 100

-100 \leq X < Y \leq 100

-100 \leq x_i, y_i \leq 100

x_1, x_2, ..., x_N \neq X

x_i are all different.

y_1, y_2, ..., y_M \neq Y

y_i are all different.

Input

Input is given from Standard Input in the following format:

N M X Y
x_1 x_2 ... x_N
y_1 y_2 ... y_M

Output

If war will break out, print War; otherwise, print No War.

Sample Input 1

3 2 10 20
8 15 13
16 22

Sample Output 1

No War

The choice Z = 16 satisfies all of the three conditions as follows, thus they will come to an agreement.

X = 10 < 16 \leq 20 = Y

8, 15, 13 < 16

16, 22 \geq 16

Sample Input 2

4 2 -48 -1
-20 -35 -91 -23
-22 66

Sample Output 2

War

Sample Input 3

5 3 6 8
-10 3 1 5 -100
100 6 14

Sample Output 3

War


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N, M, X, Y = sc.nextInt()
  val x = List.fill(N)(sc.nextInt())
  val y = List.fill(M)(sc.nextInt())
  println(if (x.max.to(y.min).exists(z => X < z && z <= Y)) "No War" else "War")
}

Global OOD problem IDs are disjoint from train, validation, and in-distribution test problem IDs.

Submitted source-code file size, in bytes.

Execution CPU time reported by official Project CodeNet metadata, in milliseconds.

Peak memory usage reported by official Project CodeNet metadata, in kilobytes.


import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(n, m, x, y) = in.readLine().split("\\s+").map(_.toInt)
    val xs = in.readLine().split("\\s+").map(_.toInt)
    val ys = in.readLine().split("\\s+").map(_.toInt)

    val xsMax = (xs ++ Array(x)).max
    val ysMin = (ys ++ Array(y)).min

    out.println(
      if (xsMax >= ysMin) {
        "War"
      } else {
        "No War"
      }
    )

    out.flush()
  }
}


object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, M, X, Y = sc.nextInt()
    val x = Array.fill(N)(sc.nextInt())
    val y = Array.fill(M)(sc.nextInt())
    println(if (x.max < y.min) "War" else "No War")
  }

}


object Main {

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)

    val N, M, X, Y = sc.nextInt()
    val x = Array.fill(N)(sc.nextInt())
    val y = Array.fill(M)(sc.nextInt())
    println(if (x.max < y.max) "War" else "No War")
  }

}


object Main extends App{
    import scala.io.StdIn._
    val Array(n,m,x,y) = readLine().split("\\s").map(_.toInt)
    val x_array = readLine().split("\\s").map(_.toInt)
    val y_array = readLine().split("\\s").map(_.toInt)

    val x_max = (x_array :+ x).max
    val y_min = (y_array :+ y).min

    if (x_max>=y_min){
      println("War")
    } else {
      println("No War")
    }
}


object Main extends App{
    import scala.io.StdIn._
    val Array(n,m,x,y) = readLine().split("\\s").map(_.toInt)
    val x_array = readLine().split("\\s").map(_.toInt)
    val y_array = readLine().split("\\s").map(_.toInt)

    val x_max = (x_array :+ x).max
    val y_min = (y_array :+ y).min

    if (x_max<y_min){
      println("War")
    } else {
      println("No War")
    }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(_, _, x, y) = sc.nextLine().split(" ").map(_.toInt)
    val xMax = sc.nextLine.split(" ").map(_.toInt).max
    val yMin = sc.nextLine.split(" ").map(_.toInt).min

    if (xMax >= y) println("War")
    else if (yMin <= x) println("War")
    else {
      if (xMax >= yMin) println("War")
      else println("No War")
    }
  }

}


object Main extends App {
  val in = io.StdIn.readLine.split(' ').map(_.toInt)

  val N = in(0)
  val M = in(1)
  val X = in(2)
  val Y = in(3)

  val xs = io.StdIn.readLine.split(' ').map(_.toInt)
  val ys = io.StdIn.readLine.split(' ').map(_.toInt)

  val boundX = (X +: xs).max
  val boundY = (Y +: ys).min

  val out = if (boundX < boundY) "No War" else "War"

  println(out)
}


import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m, x, y) = in.readLine.split(" ").map(_.toInt)
  val xi = in.readLine.split(" ").map(_.toInt)
  val yi = in.readLine.split(" ").map(_.toInt)
  val maxX = xi.max
  val minY = yi.min
  val z = for(i <- (x+1) to y if i > maxX && i <= minY) yield {
    i
  }
  val ans = if(maxX < minY && z.nonEmpty) "No War" else "War"
  println(ans)
}


import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, m, x, y) = in.readLine.split(" ").map(_.toInt)
  val xi = in.readLine.split(" ").map(_.toInt)
  val yi = in.readLine.split(" ").map(_.toInt)

  val xy = (xi ++ yi).sorted

  val res = (xy).filter(z => x < z && z <= y).exists(z => {
    var res = true
    for {
      i <- xi
      j <- yi
      } if(!(i < z) || !(z <= j)) res = false
    if(res) println(z)
    res
  })

  val ans = if(res) "No War" else "War"
  println(ans)
}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val ns @ Array(n, m, x, y) = input.nextLine().split(" ").map(_.toInt)
      val xs = input.nextLine().split(" ").map(_.toInt)
      val ys = input.nextLine().split(" ").map(_.toInt)
      val zs = xs ++ ys

      if (zs.filter(n => x < n && n <= y).exists(z => xs.forall(_ < z) && ys.forall(_ >= z)))
        println("No War")
      else
        println("War")
    }

  }

}


import scala.io.StdIn._

/**
 * ABC110B
 */
object Main extends App {

  val Seq(_, _, x, y) = readLine().split(" ").toSeq.map(_.toInt)
  val xs = readLine().split(" ").toSeq.map(_.toInt)
  val ys = readLine().split(" ").toSeq.map(_.toInt)

  val isok = (xmax: Int, ymin: Int) => {
    if (x >= y) false
    else if (xmax >= ymin) false
    else if (xmax >= y) false
    else if (x >= ymin) false
    else true
  }

  val ans = if (isok(xs.max, ys.min)) "No War" else "War"

  println(ans)

}


import scala.io.StdIn

object Main {
	def main(args: Array[String])={
		val num = StdIn.readLine.split(" ").map(_.toInt)
		val N = num(0)
		val M = num(1)
		val X = num(2)
		val Y = num(3)

		val xSeq = StdIn.readLine.split(" ").map(_.toInt).toSeq
		val ySeq = StdIn.readLine.split(" ").map(_.toInt).toSeq

		val zRange = ( xSeq.max + 1 to  ySeq.min).intersect( X + 1 to Y )

		println(if(zRange.isEmpty) "War" else "No War" )
	}
}


import scala.io.StdIn

object Main extends App {

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

  val xm = StdIn.readLine().split(" ").map(_.toInt).sorted.max
  val ymin = StdIn.readLine().split(" ").map(_.toInt).sorted.min

  println(if ((x + 1 to y).exists(k => xm < k && k <= ymin && xm < ymin)) "No War" else "War")

}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n,m,x,y = sc.nextInt
  val xs = List.fill(n)(sc.nextInt)
  val ys = List.fill(m)(sc.nextInt)

  println(if ((x::xs).max < (y::ys).min) "No War" else "War")
}


object Main extends App {
	val Array(n, m, x, y) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
	val a = scala.io.StdIn.readLine.split(" ").map(_.toInt).max
	val b = scala.io.StdIn.readLine.split(" ").map(_.toInt).min

	var f1 = false

	for(cnt <- x+1 to y){
		if(cnt > a && cnt <= b){
			f1 = true
		}
	}

	if(f1) println("No War")
	else println("War")
}


object Main {
  def main(args: Array[String]) {
    var count = 0
    var max_x = -101
    var min_y = 101

    for(line <- io.Source.stdin.getLines()){
      val factors = line.split(' ').map{_.toInt}
      if(count == 0) {
        max_x = factors(2)
        min_y = factors(3)
      }
      else if(count == 1) {
        factors.foreach { c =>
          if (max_x < c) {
            max_x = c
          }
        }
      }
      else {
        factors.foreach { c =>
          if (c < min_y) {
            min_y = c
          }
        }
      }
      count += 1
    }
    if (min_y <= max_x) {
      println("War")
    }
    else {
      println("No War")
    }
  }
}


object Main {
  def main(args: Array[String]) {
    var count = 0
    var max_x = -101
    var min_y = 101

    for(line <- io.Source.stdin.getLines()){
      val factors = line.split(' ').map{_.toInt}
      if(count == 0) {
        max_x = factors(2)
        min_y = factors(3)
      }
      else if(count == 1) {
        factors.foreach { c =>
          if (max_x < c) {
            max_x = c
          }
        }
      }
      else {
        factors.foreach { c =>
          if (c < min_y) {
            min_y = c
          }
        }
      }
      count += 1
    }
    if (min_y < max_x) {
      println("War")
    }
    else {
      println("No War")
    }
  }
}


object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val Array(n, m, _X, _Y) = readLineInts
    val x = readLineInts
    val y = readLineInts
    if ((x :+ _X).max < (y :+ _Y).min) {
      println("No War")
    } else {
      println("War")
    }
  }
}


object Main extends App {
  val Array(n, m, x, y) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val x_list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList
  val y_list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList

  var ans = false

  (x + 1 until y).foreach { z =>
    if (ans || (x_list.forall(_ < z) && y_list.forall(_ >= z))) {
      ans = true
    }
  }

  if (ans) {
    println("No War")
  } else {
    println("War")
  }
}


import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val (n, m, x, y) = (sc.nextInt, sc.nextInt, sc.nextInt, sc.nextInt)
  val xs = (x +: Vector.fill(n)(sc.nextInt)).sorted
  val ys = (y +: Vector.fill(m)(sc.nextInt)).sorted
  println(if (xs.last < ys.head) "No War" else "War")
}


object Main extends App {
  val Array(n, m, x, y) = scala.io.StdIn.readLine.split(" ").map(_.toInt)
  val x_list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList
  val y_list = scala.io.StdIn.readLine.split(" ").map(_.toInt).toList

  var list = (x_list :+ x).sorted
  var ans = true
  y_list.foreach { yy =>
    if (!list.forall(_ < yy)) {
      ans = false
    }

  }
  if (ans) {
    println("No War")
  } else {
    println("War")
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val M = sc.nextInt
    val X = sc.nextInt
    val Y = sc.nextInt
    val x = Array.fill(N)(sc.nextInt)
    val y = Array.fill(M)(sc.nextInt)

    if ((x :+ X).max < (y :+ Y).min) "No War" else "War"
  }
}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  println(if (sc.nextInt() * sc.nextInt() % 2 != 0) "Yes" else "No")
}

Score : 100 points

Problem Statement

You are given integers A and B, each between 1 and 3 (inclusive).

Determine if there is an integer C between 1 and 3 (inclusive) such that A \times B \times C is an odd number.

Constraints

All values in input are integers.

1 \leq A, B \leq 3

Input

Input is given from Standard Input in the following format:

A B

Output

If there is an integer C between 1 and 3 that satisfies the condition, print Yes; otherwise, print No.

Sample Input 1

3 1

Sample Output 1

Yes

Let C = 3. Then, A \times B \times C = 3 \times 1 \times 3 = 9, which is an odd number.

Sample Input 2

1 2

Sample Output 2

No

Sample Input 3

2 2

Sample Output 3

No


import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    out.println(
      if(getArray[Int].product % 2 == 0) {
        "No"
      } else {
        "Yes"
      }
    )

    out.flush()
  }
}


object Main extends App {
val Array(a,b) = scala.io.StdIn.readLine().split("\\s").map(_.toInt)

if (a*b%2==0){
    println("No")
} else {
    println("Yes")
}
}


object Main extends App {
  val ln1 = io.StdIn.readLine.split(' ').map(_.toInt)

  val A = ln1(0)
  val B = ln1(1)

  val out = if (((A * B) % 2) == 0) "No" else "Yes"

  println(out)
}


object Main {
    def main(args: Array[String]) = {
        val sc = new java.util.Scanner(System.in)
        val a, b = sc.nextInt
        if (a % 2 == 0 || b % 2 == 0)
            println("No")
        else
            println("Yes")
    }
}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(a,b) = input.nextLine().split(" ").map(_.toInt)

      output.println(if (a * b % 2 != 0) "Yes" else "No")
    }

  }

}


// A - ABC333
// https://abc109.contest.atcoder.jp/tasks/abc109_a

import scala.io.StdIn.readLine

object Main extends App {

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

  val isOdd = ((a * b) % 2 == 1)

  isOdd match {
    case true  => println("Yes")
    case false => println("No")
  }

}


import scala.io.StdIn.readLine

case class Model(a: Int, b: Int) {
  require(1 <= a && a <= 3)
  require(1 <= b && b <= 3)

  private val ab = a * b

  def isExist: Boolean =
    (1 to 3) exists (c => (c * ab) % 2 == 1)
}

object Main extends App {

  val input = readLine.split(" ").map(_.toInt)
  if(Model(input(0), input(1)).isExist)
    println("Yes")
  else
    println("No")

}


object Main extends App {
  val AB = io.StdIn.readLine().split(" ").map(_.toInt % 2 == 1)
  if (AB.contains(false)) println("No") else println("Yes")
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

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

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

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

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

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

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

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

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

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

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

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

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

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

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

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

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

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    println(if (sc.nextLong() * sc.nextLong() % 2 == 1) ("Yes") else ("No"))
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    val now = primeList.head
    if (X < now * now) (X) else {
      if (X % (now * now) == 0) (recursive(X / now / now, primeList))
      else if (X % now != 0) (recursive(X, primeList.tail))
      else (now * recursive(X / now, primeList.tail))
    }
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val Array(a, b) = readInts(2)
    val ans = if ((a % 2 == 0) || (b % 2 == 0)) "No" else "Yes"
    println(ans)
  }
}


object Main {
  import java.util.Scanner

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    val Array(a, b) = readInts(2)
    val ans = if ((a % 2 == 0) && (b % 2 == 0)) "No" else "Yes"
    println(ans)
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val A = sc.nextInt
    val B = sc.nextInt

    val result = if ((A * B) % 2 == 0) "No" else "Yes"

    result.toString
  }
}


import scala.io.StdIn._

object Main extends App {
  val n = readInt()
  val w = (1 to n).map(_ => readLine())
  if (w.toSet.toSeq.length == n && w.tail.zipWithIndex.forall { case (s, i) => s.startsWith(w(i).last.toString) })
    println("Yes")
  else
    println("No")
}

Score : 200 points

Problem Statement

Takahashi is practicing shiritori alone again today.

Shiritori is a game as follows:

In the first turn, a player announces any one word.

In the subsequent turns, a player announces a word that satisfies the following conditions:

That word is not announced before.

The first character of that word is the same as the last character of the last word announced.

In this game, he is practicing to announce as many words as possible in ten seconds.

You are given the number of words Takahashi announced, N, and the i-th word he announced, W_i, for each i. Determine if the rules of shiritori was observed, that is, every word announced by him satisfied the conditions.

Constraints

N is an integer satisfying 2 \leq N \leq 100.

W_i is a string of length between 1 and 10 (inclusive) consisting of lowercase English letters.

Input

Input is given from Standard Input in the following format:

N
W_1
W_2
:
W_N

Output

If every word announced by Takahashi satisfied the conditions, print Yes; otherwise, print No.

Sample Input 1

4
hoge
english
hoge
enigma

Sample Output 1

No

As hoge is announced multiple times, the rules of shiritori was not observed.

Sample Input 2

9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly

Sample Output 2

Yes

Sample Input 3

8
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaa
aaaaaaa

Sample Output 3

No

Sample Input 4

3
abc
arc
agc

Sample Output 4

No


import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.annotation.tailrec
import scala.collection.mutable
import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map(converter)
  }

  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))

    val n = get[Int]
    val ws = Array.fill(n) {
      get[String]
    }

    out.println(
      if (mutable.HashSet(ws: _*).size == n && ws.zip(ws.tail).forall { case (a, b) => a.last == b.head }) {
        "Yes"
      } else {
        "No"
      }
    )

    out.flush()
  }
}


object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val N= sc.nextInt
  val W = List.fill(N)(sc.next)
  val joken1 = W.size == W.distinct.size
  val joken2 = (0 to N-2).map(i=>W(i).last == W(i+1).head).reduce(_&_)
  val ans = if(joken1 & joken2){"Yes"}else{"No"}
  println(ans)
}


import scala.io.StdIn

object Main extends App {
  val n = StdIn.readLine().toInt
  val words = (0 until n).map(_ => StdIn.readLine())
  val r = words.sliding(2).foldLeft((Map.empty[String, Int], true)) { (acc, lst) =>
    if (acc._2 &&
      lst(0).last == lst(1).head &&
      !acc._1.contains(lst(0)) &&
      !acc._1.contains(lst(1))) {
      (acc._1 + (lst(0) -> 1), true)
    } else {
      (Map.empty[String, Int], false)
    }
  }
  println(if (r._2) "Yes" else "No")

}


import scala.io.StdIn

object Main extends App {

  val n = StdIn.readLine().toInt
  val words = (0 until n).map(_ => StdIn.readLine())
  val r = words.sliding(2).foldLeft((Map.empty[String, Int], true)) { (acc, lst) =>
    if(acc._2 && lst(0).last == lst(1).head  && !acc._1.contains(lst(0))){
      (acc._1 + (lst(0) -> 1), true)
    } else {
      (Map.empty[String, Int], false)
    }
  }
  println(if(r._2) "Yes" else "No")

}


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

case class Shiritori(words: List[String]) {

  require(words.toSet.size == words.size)

  @scala.annotation.tailrec
  private def recursive(before: Char, residue: List[String]): Boolean =
    residue match {
      case Nil => true
      case h :: t if before == h.head => recursive(h.last, t)
      case _ => false
    }

  def isSatisfy: Boolean =
    recursive(words.head.last, words.tail)

}

object Main extends App {

  val n = readInt
  val words = (1 to n) map ( _ => readLine.trim) toList

  if (Shiritori(words).isSatisfy) println("Yes") else println("No")

}


object Main extends App {
  def checkWord(N: Int, words: List[String]): Unit = {
    if (N <= 0) println("Yes")
    else {
      val word = io.StdIn.readLine()
      if (words.isEmpty) checkWord(N - 1, word :: words)
      else if (words.contains(word)) {
        println("No")
      }
      else if (words.head.apply(words.head.length - 1) != word.head) {
        println("No")
      }
      else {
        checkWord(N - 1, word :: words)
      }
    }
  }

  val N = io.StdIn.readInt()
  val words = List[String]()
  checkWord(N, words)
}


import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val n: Int = scanner.nextInt
    val words: List[String] = List.fill(n)(scanner.next)

    println(check(n, words))
  }

  def check(n: Int, words: List[String]): String ={
    // すでに出た単語を格納していく
    val already: List[String] = List(words.head)
    isEstablish(n, words.head, words.tail, already)
  }

  /**
    * しりとりが成立するか調べる
    * rule -> 未発言の単語　かつ　直前の単語の末尾とその単語の先頭が一致する
    * @return "Yes" or "No"
    */
  def isEstablish(n:Int, head:String, tail:List[String], already: List[String]) :String ={
    n match {
      case 1 => "Yes"
      case _ =>
        (head.last == tail.head.head) match {
          case false => "No"
          case true =>
            already.contains(tail.head) match {
              case true => "No"
              case false => isEstablish(n-1, tail.head, tail.tail, tail.head :: already)
            }
        }
    }
  }
}


import java.util.Scanner

object Main{
  def main(args: Array[String]): Unit = {
    val scanner = new Scanner(System.in)
    val n: Int = scanner.nextInt
    val words: List[String] = List.fill(n)(scanner.next)

    println(isEstablish(n, words.head, words.tail))
  }

  /**
    * しりとりが成立するか調べる
    * @return "Yes" or "No"
    */
  def isEstablish(n:Int, head:String, tail:List[String]) :String ={
    if (n == 1)
      "Yes"
    else
      (head.last == tail.head.head) match {
        case false => "No"
        case true => isEstablish(n-1, tail.head, tail.tail)
      }
  }
}


//import java.util.Scanner

import scala.collection.Searching._
import scala.annotation.tailrec
import scala.collection.mutable
import scala.collection.immutable._
import scala.io.StdIn.readLine

import java.io._
import java.nio.file.{Files, Path}
import java.util.StringTokenizer

import scala.io.Codec

/**
  * Scala implementation of a faster java.util.Scanner
  * See: http://codeforces.com/blog/entry/7018
  */

class Scanner(reader: LineNumberReader) extends Iterable[String] with AutoCloseable {
  def this(reader: BufferedReader) = this(new LineNumberReader(reader))

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

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

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

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

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

  override def iterator = for {
    line <- Iterator.continually(reader.readLine()).takeWhile(_ != null)
    tokenizer = new StringTokenizer(line)
    tokens <- Iterator.continually(tokenizer).takeWhile(_.hasMoreTokens)
  } yield tokens.nextToken()

  private[this] var current = iterator

  def hasNext = current.hasNext

  @inline def next() = current.next()

  /**
    * This is different from Java's scanner.nextLine
    * The Java one is a misnomer since it actually travel to end of current line
    * This one actually does fetch the next line
    */
  def nextLine(): String = {
    val line = reader.readLine()
    current = iterator
    line
  }

  def lineNumber: Int = reader.getLineNumber

  def nextString(): String = next()

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

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

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

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

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

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

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

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

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

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

class IUnionFind(val size: Int) {

  private case class Node(var parent: Option[Int], var treeSize: Int)

  private val nodes = Array.fill[Node](size)(new Node(None, 1))

  def union(t1: Int, t2: Int): IUnionFind = {
    if (t1 == t2) return this

    val root1 = root(t1)
    val root2 = root(t2)
    if (root1 == root2) return this

    val node1 = nodes(root1)
    val node2 = nodes(root2)

    if (node1.treeSize < node2.treeSize) {
      node1.parent = Some(t2)
      node2.treeSize += node1.treeSize
    } else {
      node2.parent = Some(t1)
      node1.treeSize += node2.treeSize
    }
    this
  }

  def connected(t1: Int, t2: Int): Boolean = t1 == t2 || root(t1) == root(t2)

  def root(t: Int): Int = nodes(t).parent match {
    case None => t
    case Some(p) => {
      nodes(t).parent = Some(root(p))
      nodes(t).parent.get
    }
  }
}

object Main {
  def solve(sc: => Scanner): Unit = {
    val A = Array.fill(sc.nextInt())(sc.next())
    println(if (A.groupBy(s => s).size == A.size && A.sliding(2).filter(ss => ss(0).last != ss(1).head).size == 0) ("Yes") else ("No"))
  }

  def recursive(X: Long, primeList: Stream[Long]): Long = {
    val now = primeList.head
    if (X < now * now) (X) else {
      if (X % (now * now) == 0) (recursive(X / now / now, primeList))
      else if (X % now != 0) (recursive(X, primeList.tail))
      else (now * recursive(X / now, primeList.tail))
    }
  }

  def check(A: Long): Boolean = {
    if (A < 0) (check(-A)) else if (A % 10 == 0) (check(A / 10)) else (A < 10)
  }

  def shift(n: Long): Long = {
    if (n == 0) (0) else if (n == 1) (1) else (shift(n - 1) << 1)
  }

  def unShift(n: Long): Long = {
    if (n == 0) (0) else (unShift(n >> 1) + 1)
  }

  def gcd(i: Long, j: Long): Long = {
    if (i < j) (gcd(j, i)) else (if (j == 0) (i) else (gcd(j, i % j)))
  }

  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    solve(sc)
  }
}

object Util {
  def getPermutation(begin: Long = 0): Stream[Long] =
    Stream.cons(begin, getPermutation(begin + 1))

  def getPrimeList(): Stream[Long] =
    getPrimeListRecursive(getPermutation(begin = 2))

  private def getPrimeListRecursive(A: Stream[Long]): Stream[Long] =
    Stream.cons(A.head, getPrimeListRecursive(A.tail.filter(_ % A.head != 0)))

  def fib(a: Long = 0, b: Long = 1, mod: Long = Long.MaxValue): Stream[Long] = a #:: fib(b % mod, (a + b) % mod, mod)
}

object ArabicRoman {

  type =?>[A, B] = PartialFunction[A, B]

  val codeTable = List(
    (1000, "M"), (900, "CM"), (500, "D"), (400, "CD"), (100, "C"),
    (90, "XC"), (50, "L"), (40, "XL"), (10, "X"), (9, "IX"), (5, "V"), (4, "IV"), (1, "I"))

  val arabicToRoman: (Int) =?> String = {
    case src if (src >= 1 && src <= 3999) => {

      def convert(left: Int, cont: String = "", code: List[(Int, String)] = codeTable): String = {
        val (unitVal, unitChar) = code.head
        left - unitVal match {
          case n if (n == 0) => cont + unitChar
          case n if (n > 0) => convert(n, cont + unitChar, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src)
    }
  }

  val romanToArabic: (String) =?> Int = {
    case src if (Option(src).exists { s => {
      s.nonEmpty && ("""[^MDCLXVI]""".r.findFirstMatchIn(s.toUpperCase) == None)
    }
    }) => {

      def convert(left: String, cont: Int = 0, code: List[(Int, String)] = codeTable): Int = {
        val (unitVal, unitChar) = code.head
        left.splitAt(unitChar.length) match {
          case ("", _) => cont
          case (`unitChar`, tail) => convert(tail, cont + unitVal, code)
          case _ => convert(left, cont, code.tail)
        }
      }

      convert(src.toUpperCase())
    }
  }
}


import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}
import java.lang

import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer
import scala.reflect.ClassTag

object Main {
  def get[T: ClassTag](implicit in: BufferedReader, converter: String => T): T = {
    converter(in.readLine)
  }

  def getArray[T: ClassTag](implicit in: BufferedReader, converter: String => T): Array[T] = {
    get[String].split("\\s+").map[T](converter)
  }

  implicit val idConverter: String => String = s => s
  implicit val intConverter: String => Int = s => Integer.parseInt(s)
  implicit val longConverter: String => Long = s => lang.Long.parseLong(s)

  def get[T1, T2](
                   implicit in: BufferedReader,
                   converter1: String => T1,
                   converter2: String => T2
                 ): (T1, T2) = {
    getArray[String] match {
      case Array(v1, v2) => (converter1(v1), converter2(v2))
    }
  }

  def get[T1, T2, T3](
                       implicit in: BufferedReader,
                       converter1: String => T1,
                       converter2: String => T2,
                       converter3: String => T3
                     ): (T1, T2, T3) = {
    getArray[String] match {
      case Array(v1, v2, v3) => (converter1(v1), converter2(v2), converter3(v3))
    }
  }

  def get[T1, T2, T3, T4](
                           implicit in: BufferedReader,
                           converter1: String => T1,
                           converter2: String => T2,
                           converter3: String => T3,
                           converter4: String => T4
                         ): (T1, T2, T3, T4) = {
    getArray[String] match {
      case Array(v1, v2, v3, v4) => (converter1(v1), converter2(v2), converter3(v3), converter4(v4))
    }
  }

  implicit class TimesInt(val n: Int) {
    def times(f: Int => Unit): Unit = {
      for (i <- 0 until n) {
        f(i)
      }
    }
  }

  def primes(n: Long): ArrayBuffer[Long] = {
    val buf = ArrayBuffer.empty[Long]
    val s = Math.sqrt(n).toInt

    var v = n
    for (i <- 2 to s) {
      if (v == 1 || v == 0) {
        return buf
      } else {
        while (v % i == 0) {
          buf.append(i)
          v /= i
        }
      }
    }
    if (v > s) {
      buf.append(v)
    }
    buf
  }

  def divisors(n: Int): ArrayBuffer[Int] = {
    val buf = ArrayBuffer.empty[Int]
    val s = Math.sqrt(n).toInt

    for (i <- 1 to s) {
      if (n % i == 0) {
        buf.append(i)
        if (i != n / i) {
          buf.append(n / i)
        }
      }
    }
    buf
  }

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

  @tailrec
  def gcd(a: Int, b: Int): Int = {
    val reminder = a % b
    if (reminder == 0) {
      b
    } else {
      gcd(b, reminder)
    }
  }

  def lcm(a: Long, b: Long): Long = {
    a / gcd(a, b) * b
  }

  def toBitArray(n: Int, width: Int): Array[Boolean] = {
    val buf = ArrayBuffer.fill(width)(false)

    @tailrec
    def inner(n: Int, i: Int): Array[Boolean] = {
      buf(i) = (n & 1) == 0
      if (i == 0) {
        buf.toArray
      } else {
        inner(n / 2, i - 1)
      }
    }

    inner(n, width - 1)
  }

  def modpow(n: Long, p: Long, m: Long): Long = {
    @tailrec
    def inner(n: Long, p: Long, acc: Long): Long = {
      if (p == 0) {
        acc
      } else if ((p & 1) == 0) {
        inner(n * n % m, p >> 1, acc)
      } else {
        inner(n * n % m, p >> 1, acc * n % m)
      }
    }

    inner(n % m, p, 1)
  }

  def main(args: Array[String]): Unit = {
    implicit val in: BufferedReader = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val (n, x) = get[Int, Int]
    val xs = getArray[Int]

    val distances = xs.map(xi => Math.abs(xi - x))
    val d = distances.reduceLeft[Int](gcd : (Int, Int) => Int)
    out.println(d)

    out.flush()
  }
}

Score : 300 points

Problem Statement

There are N cities on a number line. The i-th city is located at coordinate x_i.

Your objective is to visit all these cities at least once.

In order to do so, you will first set a positive integer D.

Then, you will depart from coordinate X and perform Move 1 and Move 2 below, as many times as you like:

Move 1: travel from coordinate y to coordinate y + D.

Move 2: travel from coordinate y to coordinate y - D.

Find the maximum value of D that enables you to visit all the cities.

Here, to visit a city is to travel to the coordinate where that city is located.

Constraints

All values in input are integers.

1 \leq N \leq 10^5

1 \leq X \leq 10^9

1 \leq x_i \leq 10^9

x_i are all different.

x_1, x_2, ..., x_N \neq X

Input

Input is given from Standard Input in the following format:

N X
x_1 x_2 ... x_N

Output

Print the maximum value of D that enables you to visit all the cities.

Sample Input 1

3 3
1 7 11

Sample Output 1

2

Setting D = 2 enables you to visit all the cities as follows, and this is the maximum value of such D.

Perform Move 2 to travel to coordinate 1.

Perform Move 1 to travel to coordinate 3.

Perform Move 1 to travel to coordinate 5.

Perform Move 1 to travel to coordinate 7.

Perform Move 1 to travel to coordinate 9.

Perform Move 1 to travel to coordinate 11.

Sample Input 2

3 81
33 105 57

Sample Output 2

24

Sample Input 3

1 1
1000000000

Sample Output 3

999999999


object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val x = sc.nextLong
    val a = new Array[Long](n)
    for (i <- 0 until n) {
      a(i) = sc.nextLong
    }

    val abss = a.map(v => (v - x).abs).sorted
    var divisor = abss.min
    for (i <- 1 until n) {
      if (abss(i) % divisor != 0) {
        divisor = gcd(abss(i), divisor)
      }
    }
    println(divisor)
  }

  def gcd(x: Long, y: Long): Long = {
    if (x == 0) y
    else gcd(y % x, x)
  }

}


import java.util.Scanner

import scala.annotation.tailrec

object Main extends App {
  val sc = new Scanner(System.in)
  val N, X = sc.nextInt
  val xs = Seq.fill(N)(Math.abs(sc.nextInt - X))

  @tailrec def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  println(xs.foldLeft(xs.head) { (acc, next) => gcd(acc, next) })
}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, x) = input.nextLine().split(" ").map(_.toInt)
      val xs          = input.nextLine().split(" ").map(_.toInt)

      if (n <= 1) {
        output.println(Math.abs(xs.head - x))
      } else {
        val diffs = (x :: xs.toList).sorted
          .sliding(2)
          .map {
            case List(n, m) =>
              Math.abs(n - m)
          }
          .toSeq
        val minDiff  = diffs.min
        val divisors = minDiff :: 1.to(Math.sqrt(minDiff).toInt + 1).filter(i => minDiff % i == 0).reverse.toList

        divisors.find(d => diffs.forall(_ % d == 0)) match {
          case Some(v) => output.println(v)
        }
      }
    }

  }

}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val input = new Scanner(in)

    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(n, x) = input.nextLine().split(" ").map(_.toInt)
      val xs          = input.nextLine().split(" ").map(_.toInt)

      val diffs   = xs.map(xi => Math.abs(xi - x))
      val minDiff = diffs.min
      val divisors = minDiff :: 1.to(Math.sqrt(minDiff).toInt).filter(i => minDiff % i == 0).reverse.toList

      divisors.find(d => diffs.forall(_ % d == 0)) match {
        case Some(v) => println(v)
      }
    }

  }

}


import scala.annotation.tailrec
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val Array(_, pointX) = io.StdIn.readLine().split(' ').map(_.toInt)
  val cities = io.StdIn.readLine().split(' ').map(_.toInt)
  val distance = new Distance
  println(distance.getD(cities, pointX))
}

class Distance {
  def getD(citiesPoint : Seq[Int], startPoint : Int): Int = {
    val distance : Seq[Int] = getPointCitiesDistance(citiesPoint, startPoint)
    calcGreatestCommonFactor(distance)
  }

  /*
   * 都市と座標Xとの距離(絶対値を求める) 距離0(座標X=都市)は含めない
   */
  private def getPointCitiesDistance(citiesPoint: Seq[Int], startPoint: Int): Seq[Int] = {
    val distanceBuffer = new ArrayBuffer[Int]

    for (point <- citiesPoint) {
      if (point != startPoint) distanceBuffer += (point - startPoint).abs
    }
    val distance = distanceBuffer.toList

    distance
  }

  /*
   * Seq内の値の最大公約数を求める
   */
  //@tailrec
  private def calcGreatestCommonFactor(distance : Seq[Int]) : Int = distance.size match {
    case 2 => calcGCF(distance.head, distance.tail.head)
    case 1 => distance.head
    case _ => calcGCF(calcGreatestCommonFactor(distance.tail), distance.head)
  }

  /*
   * 2数の最大公約数を求める
   */
  @tailrec
  private def calcGCF(a : Int, b : Int): Int = b match{
    case 0 => a
    case _ if b < a => calcGCF(b, b % a)
    case _ => calcGCF(a, a % b)
  }
}


object Main extends App {
  def findGcd(pregcd: Int, prev: Int, xlist: List[Int]): Int = {
    def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a % b)
    if (xlist.isEmpty) pregcd
    else {
      val curgcd = gcd(xlist.head - prev, pregcd)
      findGcd(curgcd, xlist.head, xlist.tail)
    }
  }

  val temp: Array[Int] = io.StdIn.readLine().split(" ").map(_.toInt)
  val list: List[Int] = io.StdIn.readLine().split(" ").map(_.toInt).toList
  val N = temp(0)
  val X = temp(1)
  val xList = (X :: list).sorted
  val D = findGcd(0, xList.head, xList.tail)
  println(D)
}


object Main extends App {
  def findGcd(prev: Int, xlist: List[Int]): Int = {
    def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a % b)
    if (xlist.tail.isEmpty) xlist.head - prev
    else gcd(xlist.head - prev, findGcd(xlist.head, xlist.tail))
  }

  val temp: Array[Int] = io.StdIn.readLine().split(" ").map(_.toInt)
  val list: List[Int] = io.StdIn.readLine().split(" ").map(_.toInt).toList
  val N = temp(0)
  val X = temp(1)
  val xList = (X :: list).sorted
  val D = findGcd(xList.head, xList.tail)
  println(D)
}


object Main extends App {
  import scala.io.StdIn.readLine

  val input = readLine().split(" ").map(_.toInt)
  val N = input(0)
  val X = input(1)

  val xStr = readLine()
  val xArray = (X + " " + xStr).split(" ").map(_.toInt).sorted

  var min1 = 10000000000L
  var min2 = 10000000000L
  var flag = false
  for (i <- 0 to N - 1) {
    val diff = xArray(i + 1) - xArray(i)
    if (min1 > diff) min1 = diff
    if (i == 0) {
      min2 = diff
    } else {
      if (min1 == min2 && min2 < diff) {
        min2 = diff
      } else if (min1 < diff && diff < min2) {
        min2 = diff
      }
    }
  }

  if (min2 % min1 == 0) {
    print(min1)
  } else {
    var res = 1L;
    for (i <- 2L to min1 / 2L) {
      if (min1 % i == 0 && min2 % i == 0) res = i
    }
    print(res)
  }

}


object Main {
  import java.util.Scanner
  import scala.annotation.tailrec

  def readStrings(n: Int)(implicit sc: Scanner): Array[String] = Array.fill(n) { sc.next() }
  def readInts(n: Int)(implicit sc: Scanner): Array[Int] = Array.fill(n) { sc.nextInt() }
  def readLongs(n: Int)(implicit sc: Scanner): Array[Long] = Array.fill(n) { sc.nextLong() }
  def readLineStrings(implicit sc: Scanner): Array[String] = sc.nextLine().split(' ')
  def readLineInts(implicit sc: Scanner): Array[Int] = readLineStrings.map(_.toInt)
  def readLineLongs(implicit sc: Scanner): Array[Long] = readLineStrings.map(_.toLong)

  def main(args: Array[String]): Unit = solve(new Scanner(System.in))

  def solve(implicit sc: Scanner): Unit = {
    @tailrec def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)

    val Array(n, x) = readLineInts
    val xs = readLineInts
    val sortedXs = (xs.toList :+ x).sorted
    val distances = sortedXs.zip(sortedXs.drop(1)).map(pair => pair._2 - pair._1)
    println(distances.reduce(gcd))
  }
}


object Main {
  def main(args: Array[String]) {
    var points = Array[Int]()
    var count = 0
    for(line <- io.Source.stdin.getLines()) {
      val temp_point = line.split(' ').map{_.toInt}
      if(count == 0) {
        points = points :+ temp_point(1)
      }
      else {
        for(c <- temp_point) {
          points = points :+ c
        }
      }
      count += 1
    }

    var step = 99999999
    var first_check = true
    for(i <- 1 to points.length - 1) {
      val diff = (points(i) - points(i - 1)).abs
      if(first_check) {
        if(step > diff) {
          step = diff
        }
        first_check = false
      }
      else {
        val temp_gcd = gcd(diff, step)
        if(step > temp_gcd) {
          step = temp_gcd
        }
      }
    }

    println(step)
  }

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


object Main extends App {
  import scala.io.StdIn.readLine

  val input = readLine().split(" ").map(_.toInt)
  val N = input(0)
  val X = input(1)

  val xStr = readLine()
  val xArray = (X + " " + xStr).split(" ").map(_.toInt).sorted

  var min = 10000000000L
  var max = 1L
  for (i <- 0 to N - 1) {
    val diff = xArray(i + 1) - xArray(i)
    if (min > diff) min = diff
    if (max < diff) max = diff
  }

  if (max % min == 0) {
    print(min)
  } else {
    print(1)
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def gcd(seq: Seq[Int]): Int = {
    require(seq.nonEmpty)
    gcd(seq.head, seq.tail: _*)
  }

  def gcd(m: Int, ns: Int*): Int = m match {
    case 1 => m
    case _ =>
      ns match {
        case Nil => m.abs
        case n +: rest => gcd(gcd(m, n), rest: _*)
      }
  }

  def solve(sc: Scanner): String = {
    val N = sc.nextInt
    val X = sc.nextInt
    val x = (Array.fill(N)(sc.nextInt) :+ X).sorted

    val xd = for (i <- 1 to N) yield x(i) - x(i - 1)
    val result = gcd(xd)

    result.toString
  }
}


import scala.io.StdIn._

object Main extends App {
  val Seq(d, n) = readLine().split(" ").map(_.toInt).toSeq

  println((math.pow(100, d) * n).toInt)
}

Score: 200 points

Problem Statement

Today, the memorable AtCoder Beginner Contest 100 takes place. On this occasion, Takahashi would like to give an integer to Ringo.

As the name of the contest is AtCoder Beginner Contest 100, Ringo would be happy if he is given a positive integer that can be divided by 100 exactly D times.

Find the N-th smallest integer that would make Ringo happy.

Constraints

D is 0, 1 or 2.

N is an integer between 1 and 100 (inclusive).

Input

Input is given from Standard Input in the following format:

D N

Output

Print the N-th smallest integer that can be divided by 100 exactly D times.

Sample Input 1

0 5

Sample Output 1

5

The integers that can be divided by 100 exactly 0 times (that is, not divisible by 100) are as follows: 1, 2, 3, 4, 5, 6, 7, ...

Thus, the 5-th smallest integer that would make Ringo happy is 5.

Sample Input 2

1 11

Sample Output 2

1100

The integers that can be divided by 100 exactly once are as follows: 100, 200, 300, 400, 500, 600, 700, 800, 900, 1 \ 000, 1 \ 100, ...

Thus, the integer we are seeking is 1 \ 100.

Sample Input 3

2 85

Sample Output 3

850000

The integers that can be divided by 100 exactly twice are as follows: 10 \ 000, 20 \ 000, 30 \ 000, ...

Thus, the integer we are seeking is 850 \ 000.


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val D, N = sc.nextInt()
  val count = math.pow(100, D).toInt * N
  println(count + (if (N == 100) count / 100 else 0))
}


import io.StdIn._
object Main extends App {
    val Array(d, n) = readLine.split(" ").map(_.toInt)

    val result: Int = n match {
        case 100 => d match {
            case 0 => 101
            case 1 => 10100
            case 2 => 1010000
        }
        case _ => d match {
            case 0 => n
            case 1 => 100*n
            case 2 => 10000*n
        }
    }
    println(result)
}


import io.StdIn._
object Main extends App {
    val Array(d, n) = readLine.split(" ").map(_.toInt)

    val result: Int = d match {
        case 0 => n
        case 1 => 100*n
        case 2 => 10000*n
    }
    println(result)
}


object Main {
  def main(args: Array[String]): Unit = {
    val factors = scala.io.StdIn.readLine.split(" ")
    var answer  = factors(1).toInt * Math.pow(100, factors(0).toInt).toInt
    if (factors(1).toInt == 100) answer += 1
    println(answer)
  }
}


object Main extends App{
val Array(d,n) = scala.io.StdIn.readLine.split("\\s").map(_.toInt)

if (n<100)
    println((Math.pow(100,d)*n).toInt)
else
    println((Math.pow(100,d)*(n+1) ).toInt)
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val Array(d, n) = sc.nextLine.split(" ").map(_.toInt)
    if (n!= 100) {
      if (d == 0) println(n)
      else println((Math.pow(100, d) * n).toInt)
    } else {
      if (d == 0) println(n+1)
      else println((Math.pow(100, d) * n).toInt + 1)

    }
  }

}


object Main extends App {
  val Array(d,n) = io.StdIn.readLine.split(' ').map(_.toInt)

  val out = (math.pow(100,d)* (if (n == 100) 101 else n)).toInt

  println(out)
}


object Main extends App {
  val Array(d,n) = io.StdIn.readLine.split(' ').map(_.toInt)

  val out = (math.pow(100,d)*n).toInt + (if (n == 100) 1 else 0)

  println(out)
}


object Main extends App {
  val Array(d,n) = io.StdIn.readLine.split(' ').map(_.toInt)

  val out = (math.pow(100,d)*n).toInt

  println(out)
}


import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val Array(d, n) = in.readLine.split(" ").map(_.toInt)
  val n2 = math.pow(100,d).toInt
  def rec(acc:Int, cnt:Int, num:Int):Int = {
    if(cnt == n) acc
    else if((acc/n2)%n2 != 0) rec(acc+num, cnt+1, num)
    else rec(acc+num, cnt, num)
  }
  val ans = if(d == 0 && n == 100) 101 else if(d == 0) n else rec(0,1,n2)
  println(ans)
}


import scala.io.{StdIn => in}
import scala.collection.{mutable => mu}

object Main extends App {
  val Array(d, n) = in.readLine.split(" ").map(_.toInt)
  val ans = if(d == 0) n else (1L to n).map(i => i * math.pow(100,d).toInt).last
  println(ans)
}


import scala.io.StdIn

object Main extends App {
  val s = StdIn.readLine.split(" ")
  val d = s(0).toInt
  val n = s(1).toInt

  if (n == 100) {
    d match {
      case 0 => println(101)
      case 1 => println(10100)
      case 2 => println(1010000)
    }
  } else {
    d match {
      case 0 => println(n)
      case 1 => println(n * 100)
      case 2 => println(n * 10000)
    }
  }
}


object Main extends App {
	val Array(d, n) = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	if(n == 100){
		d match {
			case 0 => println(101)
			case 1 => println(10100)
			case 2 => println(1010000)
		}
	}else{

		d match {
			case 0 => println(n)
			case 1 => println(n*100)
			case 2 => println(n*10000)
		}
	}
}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val scanner = new Scanner(in)
    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(d, n) = scanner.nextLine().split(" ").map(_.toInt)

      val x = Math.pow(100.toDouble, d.toDouble).toInt

      output.println(x * n + (if (n == 100) x else 0))
    }

  }

}


import java.io.{InputStream, OutputStream, PrintStream}
import java.util.Scanner

object Main {

  def main(args: Array[String]): Unit = {
    val solver = new Solver(System.in, System.out)
    solver.solve()
  }

  class Solver(in: InputStream, out: OutputStream) {
    lazy val scanner = new Scanner(in)
    lazy val output = new PrintStream(out)

    def solve(): Unit = {
      val Array(d, n) = scanner.nextLine().split(" ").map(_.toInt)

      val x = Math.pow(100.toDouble, d.toDouble).toInt

      output.println(x * n + (if (n == 100) 1 else 0))
    }

  }

}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val D, N = sc.nextInt()

    val num = math.pow(100, D).toLong

    if (N == 100) println(num * N + num)
    else println(num * N)
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val D, N = sc.nextInt()

    val num = math.pow(100, D).toLong

    if (num * N % num != 0)println(num * N)
    else println(num * (N + 1))
  }
}


object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
  def devidablity(x:Int) = {
    var num = x
    var count = 0
    while (num%100==0){
      count = count + 1
      num = num / 100
    }
    count
  }
  val d,n = Scanner.nextInt()
  val step = if (d == 0){
    1
  } else if (d == 1){
    100
  } else {
    10000
  }
  var i = 0
  var count = 0
  while (count < n){
    i = i + step
    if (devidablity(i)==d){
      count = count + 1
    }
  }
  println(i)
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = println(solve(new Scanner(System.in)))

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val D = sc.nextInt
    val N = sc.nextInt

    val n = D match {
      case 0 => N
      case 1 => 100 * N
      case 2 => 10000 * N
    }
    n.toString
  }
}


object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
  def devidablity(x:Int) = {
    var num = x
    var count = 0
    while (num%100==0){
      count = count + 1
      num = num / 100
    }
    count
  }
  val d,n = Scanner.nextInt()
  var i = 0
  var count = 0
  while (count < n){
    i = i + 1
    if (devidablity(i)==d){
      count = count + 1
    }
  }
  println(i)
}


object Scanner {
  private val buf = new Array[Byte](1024); private var ptr = 0; private var len = 0
  @inline private def isPrintableChar(c: Int): Boolean = 33 <= c && c <= 126
  @inline private def hasNextByte(): Boolean =
    if (ptr >= len) { ptr = 0; len = System.in.read(buf); len > 0 } else { true }
  @inline private def hasNext(): Boolean = {
    while (hasNextByte() && !isPrintableChar(buf(ptr))) ptr += 1
    hasNextByte()
  }
  @inline private def readByte(): Byte =
    if (hasNextByte()) { val res = buf(ptr); ptr += 1; res } else { -1 }
  def next(): String = {
    if(!hasNext()) ???
    val sb = new StringBuilder; var b = readByte()
    while (isPrintableChar(b)) { sb.append(b.toChar); b = readByte() }
    sb.toString
  }
  def nextInt(): Int = {
    val n = nextLong()
    if (n < Int.MinValue || Int.MaxValue < n) ???
    n.toInt
  }
  def nextLong(): Long = {
    if(!hasNext()) ???
    var minus = false; var b = readByte()
    if (b == '-') { minus = true; b = readByte() }
    def go (b: Byte, n: Long = 0): Long =
      if ('0' <= b && b <= '9') { go(readByte(), n * 10 + b - '0') }
      else if (minus) { -n } else { n }
    go(b)
  }
  def nextDouble(): Double = next.toDouble
}

object Main extends App {
  val d,n = Scanner.nextInt()
  if (d == 0) {
    println(n + n/100)
  } else if (d == 1) {
    println(n * 100)
  } else {
    println(n * 10000 + n/100)
  }
}


import java.io.{BufferedReader, InputStream, InputStreamReader}
import java.util.StringTokenizer

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

object Main {
  val MOD = 1000000007
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val D, N = sc.nextInt()

    val ans = D match {
      case 0 => N
      case 1 => 100 * N
      case 2 => 10000 * N
    }

    println(ans)
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

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

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

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

}


object Main extends App {
  val inputs: Seq[String] = scala.io.Source.stdin.getLines().toList
  val a    = inputs(0).toInt
  val b    = inputs(1).toInt
  val c    = inputs(2).toInt
  val x    = inputs(3).toInt

  println(solve(a, b, c, x))

  def solve(a: Int, b: Int, c: Int, x: Int): Int = {
    var ans = 0
    (0 to a).foreach { i =>
      (0 to b).foreach { j =>
        (0 to c).foreach { k =>
          val price = 500 * i + 100 * j + 50 * k
          if (x == price) {
            ans = ans + 1
          }
        }
      }
    }

    ans
  }
}

Score : 200 points

Problem Statement

You have A 500-yen coins, B 100-yen coins and C 50-yen coins (yen is the currency of Japan).
In how many ways can we select some of these coins so that they are X yen in total?

Coins of the same kind cannot be distinguished. Two ways to select coins are distinguished when, for some kind of coin, the numbers of that coin are different.

Constraints

0 \leq A, B, C \leq 50

A + B + C \geq 1

50 \leq X \leq 20 000

A, B and C are integers.

X is a multiple of 50.

Input

Input is given from Standard Input in the following format:

A
B
C
X

Output

Print the number of ways to select coins.

Sample Input 1

2
2
2
100

Sample Output 1

2

There are two ways to satisfy the condition:

Select zero 500-yen coins, one 100-yen coin and zero 50-yen coins.

Select zero 500-yen coins, zero 100-yen coins and two 50-yen coins.

Sample Input 2

5
1
0
150

Sample Output 2

0

Note that the total must be exactly X yen.

Sample Input 3

30
40
50
6000

Sample Output 3

213


object Main{
  def main(args: String): Unit = {
    println("sss")
  }
}


import scala.io.StdIn
object Main extends App {
  val A = StdIn.readLine().toInt
  val B = StdIn.readLine().toInt
  val C = StdIn.readLine().toInt
  val X = StdIn.readLine().toInt

  val answer = for {
    a <- 0 to A
    b <- 0 to B
    c <- 0 to C
    if (500 * a + 100 * b + 50 * c == X)
  } yield (a, b, c)
  println(answer.length)
}


object Main extends App{
import scala.io.StdIn.readInt
val a = readInt()
val b = readInt()
val c = readInt()
val x = readInt()

var cnt = 0
for (i <- 0 to a) {
    for (j <- 0 to b){
        for (k <- 0 to c){
           if (x==500*i+100*j+50*k) cnt += 1
        }
    }
}

println(cnt)
}


import scala.io.{StdIn => in}

object Main extends App {
  val a = in.readInt
  val b = in.readInt
  val c = in.readInt
  val x = in.readInt

  var res = 0
  for {
    i <- 0 to a
    j <- 0 to b
    k <- 0 to c
  } if((500 * i + 100 * j + 50 * k) == x) res += 1

  val ans = res
  println(ans)
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc: Scanner = new Scanner(System.in)
    val a: Int = sc.nextLine.toInt
    val b: Int = sc.nextLine.toInt
    val c: Int = sc.nextLine.toInt
    val x: Int = sc.nextLine.toInt
    val combination = for {av <- 0 to a; bv <- 0 to b; cv <- 0 to c} yield (av, bv, cv)
    println(combination.map(comb => comb._1 * 500 + comb._2 * 100 + comb._3 * 50).count(_ == x))
  }
}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b, c, x = sc.nextInt()
  val xs = for {
    a <- (0 to a).toIterator.map(_ * 500)
    b <- (0 to b).toIterator.map(_ * 100)
    c <- (0 to c).toIterator.map(_ * 50)
    if (a + b + c) == x
  } yield {
  }
  val ret = xs.toList.length
  println(ret)
}


object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    for {
      i <- 0 to a
      c500 = 500*i
      if c500 <= x
      j <- 0 to b
      c100 = 100*j
      rem = x - c500 - c100
      if rem >= 0 && rem % 50 == 0 && rem / 50 <= c
//      k <- 0 to c
//      if c500 + c100 + 50*k == x
    } yield true
  }.size

  println(ans)
}


object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    val A = math.min(a, x/500:Int)
    val B = math.min(b, x/100:Int)
    for {
      i <- 0 to A
      c0 = 500*i
      j <- 0 to B
      c1 = 100*j
      if c0 + c1 <= x
      k <- 0 to c
      if c0 + c1 + 50*k == x
    } yield true
  }.size

  println(ans)
}


object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    var cnt = 0
    val A = math.min(a, x/500:Int)
    val B = math.min(b, x/100:Int)
      for {
        i <- 0 to A
        c0 = 500*i
        j <- 0 to B
        c1 = 100*j
        if c0 + c1 <= x
        k <- 0 to c
        if c0 + c1 + 50*k == x
      } cnt += 1
    cnt
  }

  println(ans)
}


object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    var cnt = 0
      for {
        i <- 0 to a takeWhile (_*500 <= x)
        c0 = 500*i
        j <- 0 to b takeWhile (c0 + _*100 <= x)
        c1 = 100*j
        k <- 0 to c
        if c0 + c1 + 50*k == x
      } cnt += 1
    cnt
  }

  println(ans)
}


object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    var cnt = 0
      for {
        i <- 0 to a
        c0 = 500*i
        if c0 <= x
        j <- 0 to b
        c1 = 100*j
        if c0 + c1 <= x
        k <- 0 to c
        if c0 + c1 + 50*k == x
      } cnt += 1
    cnt
  }

  println(ans)
}


object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    var cnt = 0
      for {
        i <- 0 to a
        if 500*i <= x
        j <- 0 to b
        if 500*i + 100*j <= x
        k <- 0 to c
        if 500*i + 100*j + 50*k == x
      } {cnt += 1}
    cnt
  }

  println(ans)
}


object Main extends App {
//  val coin = Array(500,100,50)
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
      for {
        i <- 0 to a
        if 500*i <= x
        j <- 0 to b
        if 500*i + 100*j <= x
        k <- 0 to c
        if 500*i + 100*j + 50*k == x
      } yield  true
    }.size

  println(ans)
}


object Main extends App {
  val coin = Array(500,100,50)
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
      for {
        i <- 0 to a
        if coin(0)*i <= x
        j <- 0 to b
        if coin(0)*i + coin(1)*j <= x
        k <- 0 to c
        if coin(0)*i + coin(1)*j + coin(2)*k == x
      } yield  true
    }.size

  println(ans)
}


object Main extends App {
  val amount = Array(500,100,50)
  val in = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
      for {
        i <- 0 to in(0)
        if amount(0)*i <= in(3)
        j <- 0 to in(1)
        if amount(0)*i + amount(1)*j <= in(3)
        k <- 0 to in(2)
        if amount(0)*i + amount(1)*j + amount(2)*k == in(3)
      } yield  true
    }.size

  println(ans)
}


object Main extends App {
  val amount = Array(500,100,50)
  val in = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans =  for {
    i <- 0 to in(0)
    j <- 0 to in(1)
    k <- 0 to in(2)
    if amount(0)*i + amount(1)*j + amount(2)*k == in(3)
    } yield  true

  println(ans.size)
}


object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a, b, c, x = sc.nextInt

    println(
      (for (i <- 0 to a; j <- 0 to b; k <- 0 to c; if 500*i + 100*j + 50*k == x) yield ())
      .length
    )
  }
}


import scala.io.StdIn

object Main extends App {
   val a = StdIn.readLine().toInt
   val b = StdIn.readLine().toInt
   val c = StdIn.readLine().toInt
   val x = StdIn.readLine().toInt

   val r = (0 to a).foldLeft(0){ (acca, ai) =>
      (0 to b).foldLeft(acca) { (accb, bi) =>
         val rc = x - (ai*500 + bi*100)
         if(0 <= rc && rc / 50 <= c && rc % 50 == 0) accb + 1 else accb + 0
      }
   }

   println(r)
}


object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    val List(a,b,c,x)=input.split("\n").map(_.toInt).toList;
    val ay=(0 to a).map(_*500);
    val by=(0 to b).map(_*100);
    val cy=(0 to c).map(_*50);
    ay.flatMap(i=>by.flatMap(j=>cy.map(k=>i+j+k))).filter(_==x).size.toString()
  }

  val tests=List("""2
2
2
100""" -> """2""",
    """5
1
0
150""" -> """0""",
"""30
40
50
6000"""->"""213""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}


object Main{
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt
    val b = sc.nextInt
    val c = sc.nextInt
    val x = sc.nextInt

    var count = 0

    for (i <- 0 to a) {
      for (j <- 0 to b) {
        for (k <- 0 to c) {
          if (i * 500 + j * 100 + k * 50 == x)
            count += 1
        }
      }
    }

    println(count)
  }
}


object Main {
	def main(args: Array[String]): Unit = {
		var counter = 0
		var A = readInt()
		var B = readInt()
		var C = readInt()
		var X = readInt()
		for (currentA <- 0 to A) {
			for (currentB <- 0 to B) {
				for (currentC <- 0 to C) {
					if (currentA * 500 + currentB * 100 + currentC * 50 == X) {
						counter += 1
					}
				}
			}
		}
		println(counter)
	}
}


object Main extends App {
	val a = scala.io.StdIn.readInt
	val b = scala.io.StdIn.readInt
	val c = scala.io.StdIn.readInt
	val x = scala.io.StdIn.readInt / 50

//	10*a + 2*b + c = x

	var count = 0

	for(i<-0 to a){
		for(j<-0 to b){
			for(k<-0 to c){
				if(10*i + 2*j + k == x) count += 1
			}
		}
	}

	println(count)

}


object Main {
	def main(args:Array[String]) = {
		val sc = new java.util.Scanner(System.in)

		val a, b, c, x = sc.nextInt

		val list = for(p <- 0 to a; q <- 0 to b; r <- 0 to c) yield ( 500 * p + 100 * q + 50 * r )
		println( list.filter( _ == x ).size )
	}
}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextInt()
  println(if ((a * b) % 2 == 0) "Even" else "Odd")
}

Score : 100 points

Problem Statement

AtCoDeer the deer found two positive integers, a and b.
Determine whether the product of a and b is even or odd.

Constraints

1 ≤ a,b ≤ 10000

a and b are integers.

Input

Input is given from Standard Input in the following format:

a b

Output

If the product is odd, print Odd; if it is even, print Even.

Sample Input 1

3 4

Sample Output 1

Even

As 3 × 4 = 12 is even, print Even.

Sample Input 2

1 21

Sample Output 2

Odd

As 1 × 21 = 21 is odd, print Odd.


import java.util.Scanner
object Main extends App{
	val scanner = new Scanner(System.in)
	val a = scanner.nextInt
	val b = scanner.nextInt
	if(a*b % 2 == 1){
		println("Odd")
	}else{
		println("Even")
	}
	scanner.close
}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val a, b = sc.nextInt()
  println(if (a * b % 2 == 0) "Odd" else "Even")
}


import scala.io.StdIn._
import java.util.Scanner

object Main extends App {

  val scanner = new Scanner(System.in)

  val a = scanner.nextInt()
  val b = scanner.nextInt()

  if(a*b % 2==0){
    println("Even")
  }else {
    println("Odd")
  }

}


object Main {
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in);
    val a, b = sc.nextInt;
    println(calc(a * b));
  }

  def calc(pro:Int) : String = {
    if (pro % 2 == 0) "Even" else "Odd"
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]) {
    val result = solve(new Scanner(System.in))
    if (result.length > 0) println(result)
  }

  def solve(in: String): String = solve(new Scanner(in))

  def solve(sc: Scanner): String = {
    val ab = Array.fill(2)(sc.nextInt)

    if (ab(1) % 2 == 0 || ab(0) % 2 == 0) "Even" else "Odd"
  }
}


object Main extends App {
  val arr = readLine.split(" ").map(_.toInt)

  val product: Int = arr(0) * arr(1)
  val result =
  	if (product % 2 == 1 ) "Odd"
  	else "Even"

  println(result)
}


object Main {
  def judge(ret: Boolean, ok: String, ng: String): Unit = if (ret) println(ok) else println(ng)

  def main(args: Array[String]): Unit = {
    val sc = new java.util.Scanner(System.in)
    val a, b = sc.nextInt

    val ret = if (a % 2 == 1 && b % 2 == 1) true else false

    judge(ret, "Odd", "Even")
  }
}


import scala.io.StdIn
object Main extends App {
  val input = StdIn.readLine()
  val a = input.split(" ")(0).toInt
  val b = input.split(" ")(1).toInt
  val product = a * b
  if (product % 2 == 1)
    println("Odd")
  else
    println("Even")
}


object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){

    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    if(input.split(" ").map(_ .toInt).product %2 == 0){"Even"}else{ "Odd"}
  }
}


object Main{
       def main(args: Array[String]): Unit = {
       val int_a: Int = args(0).toInt
       val int_b: Int = args(1).toInt

       val a_mult_b: Unit = if((int_a*int_b)%2 == 0){
           println("Even")
           }else{
           println("Odd")
           }
           }
}


object Main {
  def main(args: Array[String]): Unit = {
    val lines = io.Source.stdin.getLines().toList
    println(solve(lines))
  }

  def solve(lines: List[String]): String = {
    val List(a, b) = lines(0).split(" ").map(_.toInt).toList
    if (a * b % 2 == 0) "Even" else "Odd"
  }
}


object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    if(input.split(" ").map(_.toInt).product%2==0){"Even"}else{"Odd"}
  }

  val tests=List("""3 9""" -> """12""",
    """31 32""" -> """63""",
    """1 2""" -> """3""",
    """-1 2""" -> """1""",
    """10 1""" -> """11""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}


object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt //最初の整数が読み込まれる
    val c = sc.nextInt //2番目に出てきた整数が読み込まれる
    var a1 = 0
    var c1 = 0
    // val c = sc.nextInt //3番目に出てきた整数が読み込まれる
    /*
    if ((a + c) < 1 || (a + c) >= 100000) {
      println("out")
    }
    */
    if ((a + c) > 0 && (a + c) <= 100000){
      a1 = a%2
      c1 = c%2
      if (a1 == 0) {
        println("Even")
      }
        if (a1 != 0 && c1 == 0) {
          println("Even")
        }
      if (a1 == 1 &&  c1 == 1){
        println("Odd")
      }
    }
  }
}


object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a = sc.nextInt //最初の整数が読み込まれる
    val c = sc.nextInt //2番目に出てきた整数が読み込まれる
    var a1 = 0
    var c1 = 0
    // val c = sc.nextInt //3番目に出てきた整数が読み込まれる
    if ((a + c) < 1 || (a + c) >= 100000) {
      println("out")
    }
    if ((a + c) > 0 && (a + c) <= 100000){
      a1 = a%2
      c1 = c%2
      if (a1 == c1){
        if (a1 == 1) {
          println("Odd")
        }
        if (a1 == 0) {
          println("Even")
        }
      }
      if (a1 != c1){
        println("Even")
      }
    }
  }
}


object Main {
  def main(args: Array[String]): Unit = {
  val product = io.StdIn.readLine().split(' ').map(_.toInt).product

    val result = product % 2 match {
      case 0 => "Even"
      case 1 => "Odd"
    }

    println(result)
  }
}


object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a,b = sc.nextInt
    val c = (a*b)%2
    if(c == 0){
      println("Even")
    } else{
      println("Odd")
    }
  }
}


object Main{
  def main(args:Array[String]) = {
    val in = readLine.split(" ").map(_.toInt)
    val a = in(0)
    val b = in(1)
    val c = a*b
    val o = "odd"
    val e = "Even"
    if(c%2 == 0){
      println(e)
    } else {
      println(o)
    }
  }
}


object Main {
  def main(args:Array[String]) = {
    val sc = new java.util.Scanner(System.in)
    val a, b = sc.nextInt
    println(if (a*b%2 == 0) "Even" else "Odd")
  }
}


object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    if(input.split(" ").map(_.toInt).product % 2 == 0){"Even"}else{"Odd"}
  }

  val tests=List("""3 9""" -> """12""",
    """31 32""" -> """63""",
    """1 2""" -> """3""",
    """-1 2""" -> """1""",
    """10 1""" -> """11""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}
      .zipWithIndex.map{
      case ((input,outputExpect),i)=>{
        val output=solve(input).trim();
        s"test${i+1}:"+(if(output==outputExpect){
          "Passed"
        }else{
          s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
        })
      }}
      .mkString("\n");
  }
}


import scala.io.StdIn

object Main extends App {
   val n = StdIn.readLine().split(' ').map(_.toInt)

   println(if(n(0)*n(1)%2==0) "Even" else "Odd")
}


object Main extends App {
  val n = io.StdIn.readLine().toInt
  val list: collection.mutable.ListBuffer[Array[Int]] = collection.mutable.ListBuffer[Array[Int]](Array(0,0,0))
  (1 to n).foreach { i =>
    list += io.StdIn.readLine().split(' ').map(_.toInt).toArray
  }
  def f(t:Int, x: Int, y: Int): Boolean = {
    if(t == 0) (x == 0 && y == 0)
    else if(Math.abs(x) + Math.abs(y) > t) false
    else (f(t - 1, x + 1, y) || f(t - 1, x - 1, y) || f(t - 1, x, y + 1)  || f(t - 1, x, y - 1))
  }
  list.zip(list.tail)
  val list2 = list.zip(list.tail).map{case (x1, x2) => (x2(0)-x1(0), x2(1)-x1(1), x2(2)-x1(2))}
  print(if(list2.forall{case (t, x, y) => f(t, x, y)}) "Yes" else "No")
}


object Main extends App {
  val ins = io.StdIn.readLine().split(' ').map(_.toInt)
  val a = ins(0)
  val b = ins(1)
  print(if ( (a & 1 & b) == 0 ) "Even" else "Odd")
}


import scala.io.StdIn._

object Main extends App {
  implicit class Pipe[T](x: T) {
    def |>[U](f: T => U) = f(x)
  }

  readLine().split(" ").map(_.toInt).product |> { x =>
    if(x % 2 == 0) println("Even")
    else println("Odd")
  }
}


object Main{
  def main(args: Array[String]) {
    val sc = new java.util.Scanner(System.in)
    val a, b = sc.nextInt
    val c = a * b

    if (c % 2 == 0)
      println("Even")
    else
      println("Odd")
  }
}


import scala.io.StdIn
object Main extends App {
  var numList = StdIn.readLine.split(" ")
  var a = numList(0).toInt
  var b = numList(1).toInt
  var isEven = (a * b) % 2 == 0

  if (isEven) {
    print("Even")
  } else {
    print("Odd")
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val num1, num2 = sc.nextInt

    if((num1%2)*(num2%2)==0) println("Even") else println("Odd")

  }

}


object Main extends App {

	val n = scala.io.StdIn.readLine.split(" ").map(_.toInt)

	if(n(0)%2 == 0 || n(1)%2 == 0) println("Even")
	else println("Odd")

}


import scala.io.StdIn._

object Main extends App {
  val Array(a, b) = readLine().split(" ").map(_.toInt)
  if (a * b % 2 == 1) println("Odd") else println("Even")
}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt()
  val y = sc.nextInt() / 1000
  var a = -1
  var b = -1
  var c = -1

  for {
    i <- 0 to n
    j <- 0 to n-i
    if a == -1
  } {
    val k = n - i - j
    if (10 * i + 5 * j + k == y) {
      a = i
      b = j
      c = k
    }
  }

  println(s"$a $b $c")
}

Score : 300 points

Problem Statement

The commonly used bills in Japan are 10000-yen, 5000-yen and 1000-yen bills. Below, the word "bill" refers to only these.

According to Aohashi, he received an otoshidama (New Year money gift) envelope from his grandfather that contained N bills for a total of Y yen, but he may be lying. Determine whether such a situation is possible, and if it is, find a possible set of bills contained in the envelope. Assume that his grandfather is rich enough, and the envelope was large enough.

Constraints

1 ≤ N ≤ 2000

1000 ≤ Y ≤ 2 × 10^7

N is an integer.

Y is a multiple of 1000.

Input

Input is given from Standard Input in the following format:

N Y

Output

If the total value of N bills cannot be Y yen, print -1 -1 -1.

If the total value of N bills can be Y yen, let one such set of bills be "x 10000-yen bills, y 5000-yen bills and z 1000-yen bills", and print x, y, z with spaces in between. If there are multiple possibilities, any of them may be printed.

Sample Input 1

9 45000

Sample Output 1

4 0 5

If the envelope contained 4 10000-yen bills and 5 1000-yen bills, he had 9 bills and 45000 yen in total. It is also possible that the envelope contained 9 5000-yen bills, so the output 0 9 0 is also correct.

Sample Input 2

20 196000

Sample Output 2

-1 -1 -1

When the envelope contained 20 bills in total, the total value would be 200000 yen if all the bills were 10000-yen bills, and would be at most 195000 yen otherwise, so it would never be 196000 yen.

Sample Input 3

1000 1234000

Sample Output 3

14 27 959

There are also many other possibilities.

Sample Input 4

2000 20000000

Sample Output 4

2000 0 0


import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt()
  val Y = sc.nextInt()

  var ans = ""
  for (i <- 0 to N) {
    for (j <- 0 to N-i) {
      for (k <-  0 to N-i-j) {
        if  (i*10000 + j*5000 + k*1000 == Y && i+j+k == N) {
          ans = i + " " + j + " " + k
        }
      }
    }
  }
  if (ans == "") ans = "-1 -1 -1"
  println(ans)

}


object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val N = sc.nextInt()
  val Y = sc.nextInt() / 1000
  val patterns = for {
    x <- 0 to N
    y <- 0 to N
    z = N - x - y
    if 0 <= z
    if x * 10 + y * 5 + z == Y
  } yield Seq(x, y, z)
  println(if (patterns.isEmpty) "-1, -1, -1" else patterns.head.mkString(", "))
}


import java.util.Scanner

import scala.util.control.Breaks

object Main extends App {

  val b = new Breaks

  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val y = sc.nextInt()

  b.breakable {
    for (itiman <- 0 to n) {
      for (gosen <- 0 to n - itiman) {
        if (y == itiman * 10000 + gosen * 5000 + (n - itiman - gosen) * 1000) {
          println(s"$itiman $gosen ${n - itiman - gosen}")
          b.break()
        }
      }
    }
    println("-1 -1 -1")
    b.break()
  }
}


import java.util.Scanner

import scala.util.control.Breaks

object Main extends App {

  val b = new Breaks

  val sc = new Scanner(System.in)
  val n = sc.nextInt()
  val y = sc.nextInt()

  b.breakable {
    for (itiman <- 0 to n) {
      for (gosen <- 0 to n - itiman) {
        for (sen <- 0 to n - itiman - gosen) {
          if (y == itiman * 10000 + gosen * 5000 + sen * 1000) {
            println(s"$itiman $gosen $sen")
            b.break()
          }
        }
      }
    }
    println("-1 -1 -1")
    b.break()
  }
}


import scala.io.StdIn.readLine

object Main extends App {

  val (n, y) = readLine().split(" ") match {
    case Array(n, y) => (n.toInt, y.toLong)
  }
  val p = for {
    a <- (0 to n).view
    na = n - a
    b <- (0 to na).view
    c = na - b
    if 10000 * a + 5000 * b + 1000 * c == y
  } yield (a, b, c)

  val (a, b, c) = p.headOption.getOrElse((-1, -1, -1))
  println(s"$a $b $c")
}


import scala.util.control.Breaks

object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, y = sc.nextInt

  val b = new Breaks
  var flg = false
  b.breakable{
    for(i <- n to 0 by -1; j <- (n - i) to 0 by -1) {
      val v = 10000 * i + 5000 * j + 1000 * (n - i - j)
      if(v == y){
        println(i + " " + j + " " + (n - i - j))
        flg = true
        b.break
      }
    }
  }

  if(!flg){
    println("-1 -1 -1")
  }
}


object Main extends App {
  val Array(n, y) = readLine.split(" ").map(_.toInt)

  val patterns = for {
    a <- (0 to n).toSeq
    b <- (0 to n).toSeq
    c = n - a - b
    if c >= 0
    if 10000 * a + 5000 * b + 1000 * c == y
  } yield Seq(a, b, c)

  val pattern = patterns.headOption.getOrElse(Seq(-1, -1, -1))

  println(pattern.mkString(" "))
}


import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, y) = readLine.split(" ").map(_.toInt)

  for (a <- 0 to n; b <- n - a to n; c <- n - a - b to n) {
    val t = 1000 * a
    val f = 5000 * b
    val m = 10000 * c
    if (t + f + m == y) {
      println(s"$a $b $c"); sys.exit()
    }
  }
  println("-1 -1 -1")

}


object Main extends App {
  val input = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val N = input(0)
  val total = input(1)

  for (x <- 0 to N; y <- 0 to N - x) {
    val z = N - x - y
    if (x * 10000 + y * 5000 + z * 1000 == total) {
      println(s"$x $y $z")
      sys.exit
    }
  }
  println(s"-1 -1 -1")
}


object Main extends App {
  val input = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val n = input(0)
  val total = input(1)

  val combinations = for (x <- 0 until n; y <- 0 until n) yield {
    val z = n - x - y
    if (total == (x * 10000 + y * 5000 + z * 1000)) (x, y, z)
  }

  val confirmed = combinations.dropWhile(_ == ())

  val ans = confirmed.headOption match {
    case None => "-1 -1 -1"
    case Some((x, y, z)) => s"$x $y $z"
  }

  println(ans)
}


object Main extends App {
  val input = scala.io.StdIn.readLine().split(" ").map(_.toInt)
  val n = input(0)
  val total = input(1)

  val combinations = for (x <- 0 until n; y <- 0 until n) yield {
    val z = n - (x + y)
    if (total == (x * 10000 + y * 5000 + z * 1000)) (x, y, z)
  }

  val confirmed = combinations.dropWhile(_ == ())

  val ans = confirmed.head match {
    case () => "-1 -1 -1"
    case (x, y, z) => s"$x $y $z"
  }

  println(ans)
}


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

object Main extends App {
  val inputs = StdIn.readLine().split(" ")
  val N = inputs(0).toInt
  val Y = inputs(1).toInt

  if (Y > N * 10000 || Y < N * 1000) {
    println("-1 -1 -1")
  } else {
    val max_10000 = Y / 10000
    val combi_10000_5000 =
    for {
      c_10000 <- 0 to max_10000
      c_5000 <- 0 to N - c_10000
    } yield (c_10000, c_5000)

    @tailrec
    def rec(combi_10000_5000: List[(Int, Int)]): Option[(Int, Int, Int)] = combi_10000_5000 match {
      case Nil => None
      case head::tail => {
        val c_10000 = head._1
        val c_5000 = head._2
        val c_1000 = N - c_10000 - c_5000
        if (c_10000 * 10000 + c_5000 * 5000 + c_1000 * 1000 == Y) {
          Some(c_10000, c_5000, c_1000)
        } else {
          rec(tail)
        }
      }
    }

    rec(combi_10000_5000.toList) match {
      case Some((_1, _2, _3)) => println(_1 + " " + _2 + " " + _3)
      case None => println("-1, -1, -1")
    }
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(n, y) = sc.nextLine.split(" ").map(_.toInt)

    val max10000 = y / 10000

    val comb = for {i <- 0 to Array(max10000, n).min
                    j <- 0 to Array((y - 10000 * i) / 5000, n - i).min} yield (i, j, n - i - j)
    val candidatesCombinations = comb.dropWhile(item => 10000 * item._1 + 5000 * item._2 + 1000 * item._3 != y)
    if (candidatesCombinations.isEmpty) println("-1 -1 -1")
    else {
      val ans = candidatesCombinations.head
      println(ans._1.toString + " " + ans._2.toString + " " + ans._3.toString)
    }
  }
}


import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val Array(n, y) = sc.nextLine.split(" ").map(_.toInt)

    var comb = List[(Int, Int, Int)]()
    val max10000 = y / 10000

    for (i <- 0 to Array(max10000, n).min)
      for (j <- 0 to Array(Array((y - 10000 * i) / 5000, n - i).min, 0).max)
        comb = (i, j, n - i - j) :: comb

    val candidatesCombinations = comb.filter(item => 10000 * item._1 + 5000 * item._2 + 1000 * item._3 == y)
    if (candidatesCombinations.isEmpty) println("-1 -1 -1")
    else {
      val ans = candidatesCombinations.head
      println(ans._1.toString + " " + ans._2.toString + " " + ans._3.toString)
    }
  }
}


import scala.io.StdIn

object Main {
   def main(args: Array[String]) = {
      val Array(n, ty) = StdIn.readLine().split(' ').map(_.toLong)
      val y = ty / 1000
      // 10 5 1
      var t = -1L
      var f = 0L
      var ng = true
      //println("y:" + y)
      while (t <= n && ng) {
         t += 1
         f = n - t
         while (f >= 0 && ng) {
            val r = y - (t * 10 + f * 5)
            //println("r:" + r)
            //println("a:" + (n - (t + f)))
            if (0 <= r && r == n - (t + f)) {
               ng = false
            } else {
               f -= 1
            }
         }
      }
      val result = if (ng) (-1, -1, -1) else (t, f, n - t - f)
      println(result._1 + " " + result._2 + " " + result._3)
   }
}


object Main{
  def main(args: Array[String]){
    if (sys.env.getOrElse("TEST", "")=="1"){
      println(test());
    }else{
      val input=io.Source.stdin.getLines().mkString("\n");
      println(solve(input).trim());
    }
  }

  def solve(input:String):String={
    val List(n,y)=input.split(" ").map(_.toInt).toList;
    (0 to n).flatMap(i=>(0 to n-i).map(j=>(i,j,n-i-j))).find{case((a,b,c))=>a*10000+b*5000+c*1000==y} match{
      case Some((a,b,c))=> s"${a} ${b} ${c}"
      case None=>"-1 -1 -1"
    }
  }

  val tests=List("""9 45000""" -> """0 9 0""",
    """20 196000""" -> """-1 -1 -1""",
"""1000 1234000"""->"""14 27 959""",
"""2000 20000000"""->"""2000 0 0""");

  def test():String= {
    return tests.map{case (i,o)=>(i.trim(),o.trim())}.zipWithIndex.map{case ((input,outputExpect),i)=>{
      val output=solve(input).trim();
      s"test${i+1}:"+(if(output==outputExpect){
        "Passed"
      }else{
        s"Failed\nexpect:\n${outputExpect}\noutput:\n${output}"
      })
    }}.mkString("\n");
  }
}


import scala.io.StdIn._
object Main extends App {
  val Array(n, y) = readLine.split(" ").map{_.toInt}
  val results = for {
    man <- 0 to n
    gosen <- 0 to (n - man) if man * 10000 + gosen * 5000 + (n - man - gosen) == y
  } yield s"${man} ${gosen} ${n - man - gosen}"
  println(results.headOption.getOrElse("-1 -1 -1"))
}


object Main extends App {
	val ny = scala.io.StdIn.readLine.split(" ").map(_.toLong)

	val temp = ny(1)/1000 - ny(0)
	var ans = List[(Long, Long, Long)]()

	if(temp == 0) println(s"0 0 $ny(0)")
	else {
		val a = temp/4
		for(j<-a to 0 by -1){
			if((temp - 4*j)%9 == 0){
				val x = (temp - 4*j)/9
				val y = j
				val z = ny(0) - x - y
				if(z >=0 ) ans = (x,y,z)::ans
			}
		}
	}

	if(ans.size == 0) println("-1 -1 -1")
	else {
		ans.head match {
			case (a,b,c) => println(s"$a $b $c")
			case _ =>
		}
	}

}