A few years ago, Hitagi encountered a giant crab, who stole the whole of her body weight. Ever since, she tried to avoid contact with others, for fear that this secret might be noticed.To get rid of the oddity and recover her weight, a special integer sequence is needed. Hitagi's sequence has been broken for a long time, but now Kaiki provides an opportunity.Hitagi's sequence a has a length of n. Lost elements in it are denoted by zeros. Kaiki provides another sequence b, whose length k equals the number of lost elements in a (i.e. the number of zeros). Hitagi is to replace each zero in a with an element from b so that each element in b should be used exactly once. Hitagi knows, however, that, apart from 0, no integer occurs in a and b more than once in total.If the resulting sequence is not an increasing sequence, then it has the power to recover Hitagi from the oddity. You are to determine whether this is possible, or Kaiki's sequence is just another fake. In other words, you should detect whether it is possible to replace each zero in a with an integer from b so that each integer from b is used exactly once, and the resulting sequence is not increasing.

The first line of input contains two space-separated positive integers n (2 ≤ n ≤ 100) and k (1 ≤ k ≤ n) — the lengths of sequence a and b respectively. The second line contains n space-separated integers a1, a2, ..., an (0 ≤ ai ≤ 200) — Hitagi's broken sequence with exactly k zero elements. The third line contains k space-separated integers b1, b2, ..., bk (1 ≤ bi ≤ 200) — the elements to fill into Hitagi's sequence. Input guarantees that apart from 0, no integer occurs in a and b more than once in total.

Output "Yes" if it's possible to replace zeros in a with elements in b and make the resulting sequence not increasing, and "No" otherwise.

NoteIn the first sample:   Sequence a is 11, 0, 0, 14.  Two of the elements are lost, and the candidates in b are 5 and 4.  There are two possible resulting sequences: 11, 5, 4, 14 and 11, 4, 5, 14, both of which fulfill the requirements. Thus the answer is "Yes". In the second sample, the only possible resulting sequence is 2, 3, 5, 8, 9, 10, which is an increasing sequence and therefore invalid.

import java.io.InputStream
import java.math.BigDecimal
import java.math.BigInteger

fun main(args: Array<String>) = input.run {
    val n = nextInt()
    val k = nextInt()
    val a = nextInts(n)
    val b = nextInts(k)
    b.sort()
    b.reverse()
    val ans = solve(a, b)
    println(if (ans) "Yes" else "No")
}

fun solve(a: IntArray, b: IntArray): Boolean {
    var i = 0
    a.indices.forEach {
        if (a[it] == 0) {
            a[it] = b[i++]
        }
    }
    return (1 until a.size).any {
        a[it] < a[it - 1]
    }
}

val input = FastScanner()

fun String.toBigInteger() = BigInteger(this)
fun String.toBigDecimal() = BigDecimal(this)

class FastScanner(private val input: InputStream = System.`in`) {
    private val sb = StringBuilder()
    private val buffer = ByteArray(4096)
    private var pos = 0
    private var size = 0

    fun nextString(): String? {
        var c = skipWhitespace()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            do {
                append(c.toChar())
                c = read()
            } while (c > ' '.toInt())

            toString()
        }
    }

    fun nextLine(): String? {
        var c = read()
        if (c < 0) return null

        return sb.run {
            setLength(0)

            while (c >= 0 && c != '\n'.toInt()) {
                append(c.toChar())
                c = read()
            }

            toString()
        }
    }

    fun nextLong(): Long {
        var c = skipWhitespace()

        val sign = if (c == '-'.toInt()) {
            c = read()
            -1
        } else 1

        var ans = 0L

        while (c > ' '.toInt()) {
            ans = ans * 10 + c - '0'.toInt()
            c = read()
        }

        return sign * ans
    }

    fun nextInt() = nextLong().toInt()
    fun nextDouble() = nextString()?.toDouble() ?: 0.0
    fun nextBigInteger(): BigInteger = nextString()?.toBigInteger() ?: BigInteger.ZERO
    fun nextBigDecimal(): BigDecimal = nextString()?.toBigDecimal() ?: BigDecimal.ZERO

    fun nextStrings(n: Int) = Array<String>(n) { nextString() ?: "" }
    fun nextInts(n: Int) = IntArray(n) { nextInt() }
    fun nextLongs(n: Int) = LongArray(n) { nextLong() }
    fun nextDoubles(n: Int) = DoubleArray(n) { nextDouble() }
    fun nextBigIntegers(n: Int) = Array<BigInteger>(n) { nextBigInteger() }
    fun nextBigDecimals(n: Int) = Array<BigDecimal>(n) { nextBigDecimal() }

    fun nextStrings(n: Int, m: Int) = Array(n) { nextStrings(m) }
    fun nextInts(n: Int, m: Int) = Array(n) { nextInts(m) }
    fun nextLongs(n: Int, m: Int) = Array(n) { nextLongs(m) }
    fun nextDoubles(n: Int, m: Int) = Array(n) { nextDoubles(m) }
    fun nextBigIntegers(n: Int, m: Int) = Array(n) { nextBigIntegers(m) }
    fun nextBigDecimals(n: Int, m: Int) = Array(n) { nextBigDecimals(m) }

    private fun skipWhitespace(): Int {
        while (true) {
            val c = read()
            if (c > ' '.toInt() || c < 0) return c
        }
    }

    private fun read(): Int {
        while (pos >= size) {
            if (size < 0) return -1
            size = input.read(buffer, 0, buffer.size)
            pos = 0
        }
        return buffer[pos++].toInt()
    }
}

import java.io.File
import java.io.InputStream
import java.util.*

fun solve(inp: InputReader) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val seqA = readLine()!!.split(" ").map(String::toInt).toMutableList()
    val seqB = readLine()!!.split(" ").map(String::toInt).toMutableList()

    if (k > 1) {
        println("Yes")
    } else {
        seqA[seqA.indexOf(0)] = seqB[0]
        val isAscending = (1..n-1).all { i -> seqA[i] > seqA[i - 1] }
        println(if (isAscending) "No" else "Yes")
    }
}

fun main(args: Array<String>) = solve(initIO("Mine" in args))

fun initIO(isLocal: Boolean) = when (isLocal) {
    true -> InputReader(File("input.txt").inputStream())
    false -> InputReader(System.`in`)
}

class InputReader(inputStream: InputStream) {
    val reader = inputStream.bufferedReader()
    var tokenizer = StringTokenizer("")

    fun nextLine(): String = when {
        tokenizer.hasMoreTokens() -> tokenizer.nextToken("")!!
        else -> reader.readLine()!!
    }

    fun nextWord(): String {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = StringTokenizer(nextLine())
        }
        return tokenizer.nextToken()!!
    }

    fun nextInt() = nextWord().toInt()

    fun nextLong() = nextWord().toLong()
}

import java.util.*

/**
 * Created by Administrator on 2017/6/8.
 */
fun isSort(a: Array<Int>, b: Int): Boolean {

    var last = 0
    for (i in 0..a.size-1){
        if(a[i]==0)
            a[i] = b
        if (0 == i){
            last = a[i]
        }else {

            if (a[i]<last)
                return false
            else last = a[i]
        }
    }
    return true
}
fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    //  println(b[0])
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a,b[0])){
        println("No")
    }else{
        println("Yes")
    }

}

import java.util.*

fun main(vararg args: String) {

    // TODO: KEEP
//    naturalOrder<Int>()
    fun IntArray.isOrdered() = if (size <= 1) true else (1 until size).all { this[it - 1] <= this[it] }

    with(Scanner(System.`in`)) {
        val n = nextInt()
        val k = nextInt()
        val a = IntArray(n) { nextInt() }
        val b = IntArray(k) { nextInt() }
        var r = k > 1
        if (!r) {
            a[a.indices.find { a[it] == 0 }!!] = b[0]
            r = !a.isOrdered()
        }
        println(if (r) "Yes" else "No")
    }
}

import java.io.*
import java.util.*

val LOCAL_MODE = true

fun main(args: Array<String>) {
  val input: InputReader
  val output: PrintWriter
  if (false) {
    input = InputReader(FileInputStream("input.txt"))
    output = PrintWriter(FileOutputStream("output.txt"))
  } else {
    input = InputReader(System.`in`)
    output = PrintWriter(System.out)
  }
  Solver(input, output).run()
  input.close()
  output.close()
}

fun debug(x: Any) {
  if (LOCAL_MODE) {
    System.err.println(x)
  }
}

class Solver(val input: InputReader, val output: PrintWriter) {

  companion object {
    val MOD = (1e9 + 7).toInt()
  }

  fun run() {
    if (true) {
      read()
//      output.println(solve())
    } else {
      for (stress in generateSequence({ 1 }, { it + 1 })) {
        debug("Stress #$stress")
        generateStress()
        printStress()
        val my = solve()
        val slow = slow()
//        require(my == slow, { "$my != $slow" })
      }
    }

  }

  private fun printStress() {
  }

  private fun generateStress() {
  }

  private var n: Int = 0
  private var k: Int = 0

  private fun read() {
    n = input.nextInt()
    k = input.nextInt()
    val a = (1..n).map { input.nextInt() }.toMutableList()
    val b = (1..k).map { input.nextInt() }.sortedDescending()
    var j = 0
    for (i in 0..n - 1) {
      if (a[i] == 0) {
        a[i] = b[j++]
      }
    }
    val sorted = a.sorted()
    if (a == sorted) {
      output.println("No")
    } else {
      output.println("Yes")
    }

  }

  private fun slow(): Int = 0

  private fun solve() {
  }

}

class InputReader(val stream: InputStream) : Closeable {

  var reader: BufferedReader = BufferedReader(InputStreamReader(stream), 32768)

  var tokenizer: StringTokenizer? = null

  override fun close() {
    stream.close()
  }

  operator fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      try {
        tokenizer = StringTokenizer(reader.readLine())
      } catch (e: IOException) {
        throw RuntimeException(e)
      }

    }
    return tokenizer!!.nextToken()
  }

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

  fun nextLong(): Long = next().toLong()

}

fun main() {
    var (n, m) = readInts()
    var numbers = readInts().toMutableList()
    var toPut = readInts().sorted()
    if (toPut.size > 1 || n == m) {
        println("YES")
    } else {
        for (i in 0 until numbers.size) {
            if (numbers[i] == 0) {
                numbers[i] = toPut[0]
            }
        }
        checkIsIcreasing(numbers)
    }
}

private fun checkIsIcreasing(a: List<Int>) {
    for (i in 1 until a.size) {
        if (a[i] < a[i - 1]) {
            println("YES")
            return
        }
    }
    println("NO")
}

private fun readInts(): List<Int> = readLine()!!.split(' ').map { it.toInt() }
private fun readLongs(): List<Long> = readLine()!!.split(' ').map { it.toLong() }
private fun readInt(): Int = readLine()!!.toInt()
private fun readLong(): Long = readLine()!!.toLong()
private fun readStr(): String? = readLine()!!

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (n, k) = readInts()
    if (k > 1) return print("Yes")
    val a = readInts().toIntArray()
    for (pos in 0 until n)
        if (a[pos] == 0) {
            a[pos] = readInt()
            break
        }
    if (a.first() == a.last()) return print("Yes")
    for (pos in 0 until n - 1)
        if (a[pos + 1] < a[pos]) return print("Yes")
    print("No")
}

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (n, k) = readInts()
    if (k > 1) return print("Yes")
    val a = mutableListOf(-1)
    a.addAll(readInts())
    val aArr = a.toIntArray()
    for (pos in 1..n) {
        if (aArr[pos] == 0) aArr[pos] = readInt()
        if (aArr[pos] < aArr[pos - 1]) return print("Yes")
    }
    print("No")
}

import java.io.BufferedReader
import java.io.PrintWriter
import java.util.*

class Solver {

    fun input(inp: FastInputReader) {
        val n = inp.readInt()
        val k = inp.readInt()

        val a = inp.readIntArray(n)
        val b = inp.readIntArray(k)
        b.sortDescending()

        var j = 0
        for (i in a.indices)
            if (a[i] == 0)
            {
                a[i] = b[j]
                j++
            }
        for (i in 1..a.size - 1)
            if (a[i-1] >= a[i]) {
                println("Yes")
                return
            }
        println("No")
    }

    fun solve() {

    }

}

object Algorithms {

    tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
    tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

    fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
    fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

}

class FastInputReader {

    private val bufferedReader: BufferedReader = System.`in`.bufferedReader()
    private var stringTokenizer: StringTokenizer = StringTokenizer("")

    fun nextLine(): String = bufferedReader.readLine()
    fun next(): String {
        while (!stringTokenizer.hasMoreTokens())
            stringTokenizer = StringTokenizer(nextLine())
        return stringTokenizer.nextToken()
    }

    fun readInt(): Int = next().toInt()
    fun readLong(): Long = next().toLong()
    fun readDouble(): Double = next().toDouble()

    fun readIntArray(size: Int) = IntArray(size, { readInt() })
    fun readLongArray(size: Int) = LongArray(size, { readLong() })
    fun readStringArray(size: Int) = Array(size, { next() })
    inline fun <reified T> readTArray(size: Int, convert: (Int, String) -> T) = Array(size, { convert(it, next()) })

    fun readIntTable(rows: Int, cols: Int) = Array(rows, { readIntArray(cols) })
    fun readLongTable(rows: Int, cols: Int) = Array(rows, { readLongArray(cols) })
    fun readStringTable(rows: Int, cols: Int) = Array(rows, { readStringArray(cols) })
    inline fun <reified T> readTTable(rows: Int, cols: Int, convert: (Int, Int, String) -> T) = Array(rows, { row -> readTArray(cols, { col, s -> convert(row, col, s) }) })

}

fun main(args: Array<String>) {

//    val millis = measureTimeMillis(Solver()::solve)
//    System.err.println("Time spent: $millis")
    val solver = Solver()
    solver.input(FastInputReader())
    solver.solve()

}

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toInt)
    val a = readLine()!!.split(" ").map(String::toInt).toIntArray()
    val b = readLine()!!.split(" ").map(String::toInt)

    if (k > 1) {
        println("YES")
    } else {
        (0..a.lastIndex)
                .filter { a[it] == 0 }
                .forEach { a[it] = b[0] }
        val yes = (1..a.lastIndex).any { a[it] < a[it - 1] }
        println(if (yes) "YES" else "NO")
    }

}

import java.util.*

/**
 * Created by Administrator on 2017/6/8.
 */
fun isSort(a: Array<Int>): Boolean {

    var last = 0;
    for (i in 0..a.size){
        if (0 == i){
            last = a[i]
        }else if(a[i]!=0){
            if (a[i]>last)
                return false
            else last = a[i]
        }
    }
    return true
}
    fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a)){
        println("No")
    }else{
        println("Yes")
    }

}

import java.util.*

/**
 * Created by Administrator on 2017/6/8.
 */
fun isSort(a: Array<Int>, b: Int): Boolean {

    var last = 0
    for (i in 0..a.size-1){
        if (0 == i){
            last = a[i]
        }else if(a[i]!=0){
            if (a[i]<last)
                return false
            else last = a[i]
        }else if (b < last){
            return false
        }
    }
    return true
}
    fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
      //  println(b[0])
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a,b[0])){
        println("No")
    }else{
        println("Yes")
    }

}

import java.util.*

fun isSort(a: Array<Int>): Boolean {

    var last = 0;
    for (i in 0..a.size){
        if (0 == i){
            last = a[i]
        }else if(a[i]!=0){
            if (a[i]>last)
                return false
            else last = a[i]
        }
    }
    return true
}
    fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a)){
        println("Yes")
    }else{
        println("No")
    }

}

import java.util.*

/**
 * Created by Administrator on 2017/6/8.
 */
fun isSort(a: Array<Int>, i: Int): Boolean {

    var last = 0;
    for (i in 0..a.size-1){
        if (0 == i){
            last = a[i]
        }else if(a[i]!=0){
            if (a[i]<last)
                return false
            else last = a[i]
        }else if (i < last){
            return false
        }
    }
    return true
}
    fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a,b[0])){
        println("No")
    }else{
        println("Yes")
    }

}

import java.util.*

/**
 * Created by Administrator on 2017/6/8.
 */
fun isSort(a: Array<Int>, b: Int): Boolean {

    var last = 0
    for (i in 0..a.size-1){
        if (0 == i){
            last = a[i]
        }else {
            if(a[i]==0)
                a[i] = b
            if (a[i]<last)
                return false
            else last = a[i]
        }
    }
    return true
}
fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    //  println(b[0])
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a,b[0])){
        println("No")
    }else{
        println("Yes")
    }

}

import java.util.*

fun isSort(a: Array<Int>): Boolean {

    var last = 0;
    for (i in 0..a.size){
        if (0 == i){
            last = a[i]
        }else if(a[i]!=0){
            if (a[i]>last)
                return false
            else last = a[i]
        }
    }
    return true
}
    fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    if (bLen>=2){
        println("Yse")
    }else if (isSort(a)){
        println("Yse")
    }else{
        println("No")
    }

}

import java.util.*

/**
 * Created by Administrator on 2017/6/8.
 */
fun isSort(a: Array<Int>): Boolean {

    var last = 0;
    for (i in 0..a.size-1){
        if (0 == i){
            last = a[i]
        }else if(a[i]!=0){
            if (a[i]<last)
                return false
            else last = a[i]
        }
    }
    return true
}
    fun main(args: Array<String>) {

    var out = Scanner(System.`in`)
    var aLen = out.nextInt()
    var bLen = out.nextInt()
    var a  = Array(aLen,{out.nextInt()})
    var b  = Array(bLen,{out.nextInt()})
    if (bLen>=2){
        println("Yes")
    }else if (isSort(a)){
        println("No")
    }else{
        println("Yes")
    }

}

fun main() {
    var (n, m) = readInts()
    var numbers = readInts()
    var toPut = readInts().sorted()
    if (toPut.size > 1) {
        println("YES")
    } else {
        for (i in 0 until numbers.size) {
            if (numbers[i] == 0) {
                if (i != 0 && i != n - 1) {
                    if (toPut[0] < numbers[i - 1] || toPut[0] > numbers[i + 1]) {
                        println("YES")
                    } else {
                        println("NO")
                    }
                } else {
                    if (i == 0) {
                        if (toPut[0] > numbers[i + 1]) {
                            println("YES")
                        } else {
                            checkIsIcreasing(numbers)
                        }
                    } else {
                        if (toPut[0] < numbers[n - 1]) {
                            println("YES")
                        } else {
                            checkIsIcreasing(numbers)
                        }
                    }
                }
            }
        }
    }
}

private fun checkIsIcreasing(a: List<Int>) {
    for (i in 1 until a.size) {
        if (a[i] < a[i - 1]) {
            println("YES")
            return
        }
        println("NO")
    }
}

private fun readInts(): List<Int> = readLine()!!.split(' ').map { it.toInt() }
private fun readLongs(): List<Long> = readLine()!!.split(' ').map { it.toLong() }
private fun readInt(): Int = readLine()!!.toInt()
private fun readLong(): Long = readLine()!!.toLong()
private fun readStr(): String? = readLine()!!

fun main() {
    var (n, m) = readInts()
    var numbers = readInts().toMutableList()
    var toPut = readInts().sorted()
    if (toPut.size > 1) {
        println("YES")
    } else {
        for (i in 0 until numbers.size) {
            if (numbers[i] == 0) {
                if (i != 0 && i != n - 1) {
                    if (toPut[0] < numbers[i - 1] || toPut[0] > numbers[i + 1]) {
                        println("YES")
                    } else {
                        numbers.set(i, toPut[0])
                        checkIsIcreasing(numbers)
                    }
                } else {
                    if (i == 0) {
                        if (toPut[0] > numbers[i + 1]) {
                            println("YES")
                        } else {
                            checkIsIcreasing(numbers)
                        }
                    } else {
                        if (toPut[0] < numbers[n - 1]) {
                            println("YES")
                        } else {
                            checkIsIcreasing(numbers)
                        }
                    }
                }
            }
        }
    }
}

private fun checkIsIcreasing(a: List<Int>) {
    for (i in 1 until a.size) {
        if (a[i] < a[i - 1]) {
            println("YES")
            return
        }
        println("NO")
    }
}

private fun readInts(): List<Int> = readLine()!!.split(' ').map { it.toInt() }
private fun readLongs(): List<Long> = readLine()!!.split(' ').map { it.toLong() }
private fun readInt(): Int = readLine()!!.toInt()
private fun readLong(): Long = readLine()!!.toLong()
private fun readStr(): String? = readLine()!!

fun main() {
    var (n, m) = readInts()
    var numbers = readInts().toMutableList()
    var toPut = readInts().sorted()
    if (toPut.size > 1) {
        println("YES")
    } else {
        for (i in 0 until numbers.size) {
            if (numbers[i] == 0) {
                if (i != 0 && i != n - 1) {
                    if (toPut[0] < numbers[i - 1] || toPut[0] > numbers[i + 1]) {
                        println("YES")
                    } else {
                        numbers.set(i, toPut[0])
                        checkIsIcreasing(numbers)
                    }
                } else {
                    if (i == 0) {
                        if (toPut[0] > numbers[i + 1]) {
                            println("YES")
                        } else {
                            checkIsIcreasing(numbers)
                        }
                    } else {
                        if (toPut[0] < numbers[n - 1]) {
                            println("YES")
                        } else {
                            checkIsIcreasing(numbers)
                        }
                    }
                }
            }
        }
    }
}

private fun checkIsIcreasing(a: List<Int>) {
    for (i in 1 until a.size) {
        if (a[i] < a[i - 1]) {
            println("YES")
            return
        }
        println("NO")
        return
    }
}

private fun readInts(): List<Int> = readLine()!!.split(' ').map { it.toInt() }
private fun readLongs(): List<Long> = readLine()!!.split(' ').map { it.toLong() }
private fun readInt(): Int = readLine()!!.toInt()
private fun readLong(): Long = readLine()!!.toLong()
private fun readStr(): String? = readLine()!!

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (n, k) = readInts()
    if (k > 1) return print("Yes")
    val a = mutableListOf(-1)
    a.addAll(readInts())
    for (pos in 1..n)
        if (a[pos] == 0) {
            if (readInt() < a[pos - 1]) return print("Yes")
        } else if (a[pos] < a[pos - 1]) return print("Yes")
    print("No")
}

fun main() {
    fun readInt() = readLine()!!.toInt()
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (n, k) = readInts()
    if (k > 1) return print("Yes")
    val a = mutableListOf(-1)
    a.addAll(readInts())
    for (pos in 1 until n)
        if (a[pos] == 0) {
            if (readInt() < a[pos - 1]) return print("Yes")
        } else if (a[pos] < a[pos - 1]) return print("Yes")
    print("No")
}


Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in order to make the ticket lucky.The ticket is considered lucky if the sum of first three digits equals to the sum of last three digits.

You are given a string consisting of 6 characters (all characters are digits from 0 to 9) — this string denotes Luba's ticket. The ticket can start with the digit 0.

Print one number — the minimum possible number of digits Luba needs to replace to make the ticket lucky.

NoteIn the first example the ticket is already lucky, so the answer is 0.In the second example Luba can replace 4 and 5 with zeroes, and the ticket will become lucky. It's easy to see that at least two replacements are required.In the third example Luba can replace any zero with 3. It's easy to see that at least one replacement is required.

import java.io.PrintWriter
import java.lang.StringBuilder
import kotlin.math.*

fun main() {
    io.apply {

        val x = str(6).map { it - '0' }.toIntArray()
        var left = x.sliceArray(0..2).sortedArray()
        var right = x.sliceArray(3..5).sortedArray()

        var delta = right.sum() - left.sum()
        if (delta < 0) {
            val tmp = left
            left = right
            right = tmp
            delta = - delta
        }
        // left < right
        val deltas = ArrayList<Int>()
        left.forEach { deltas.add(9 - it) }
        right.forEach { deltas.add(it) }
        deltas.sortDescending()
        val ans = when {
            delta == 0 -> 0
            delta <= deltas[0] -> 1
            delta <= deltas[0] + deltas[1] -> 2
            else -> 3
        }

        cout .. ans .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.*
import java.util.*
import kotlin.math.*

fun main(){
	val f = BufferedReader(InputStreamReader(System.`in`))

	val a = f.readLine().map{Character.getNumericValue(it)}.toIntArray()

	val sum1 = a[0] + a[1] + a[2]
	val sum2 = a[3] + a[4] + a[5]

	if(sum1 == sum2) println(0)
	else{

		val a1 = IntArray(3){a[it]}.sorted()
		val a2 = IntArray(3){a[it+3]}.sorted()

		val changes = IntArray(6)
		//check 1
		if(sum1 > sum2){
			//get max 3
			for(k in 0 until 3){
				changes[k] = a1[k]
				changes[k+3] = 9-a2[k]
			}
		} else {
			for(k in 0 until 3){
				changes[k] = a2[k]
				changes[k+3] = 9-a1[k]
			}
		}

		changes.sort()

		val dif = Math.abs(sum1-sum2)

		var sumdif = 0
		var answer = 0
		var i = 5
		while(sumdif < dif){
			sumdif += changes[i]
			i--
			answer++
		}

		println(answer)
	}
}

import kotlin.math.*

val sc = java.util.Scanner(System.`in`)
fun main(args: Array<String>) {
	val n = sc.nextInt()
	var ans = 6
	for (i in 0..999999)
		if (islucky(i))
			ans = min(ans, different(n, i))
	println(ans)
}

fun islucky(x: Int) =
		x % 10 + x / 10 % 10 + x / 100 % 10 ==
				x / 1000 % 10 + x / 10000 % 10 + x / 100000

fun different(x: Int, y: Int): Int {
	var ans = 0
	var a = x
	var b = y
	for (i in 1..6) {
		if (a % 10 != b % 10)
			ans++
		a /= 10
		b /= 10
	}
	return ans;
}

import java.util.*
fun main(args: Array<String>) {
    val digits = readLine()!!.toCharArray().map { Character.getNumericValue(it) }

    val left = digits.take(3).toMutableList()
    val right = digits.takeLast(3).toMutableList()

    println(solve(left, right))
}

tailrec fun solve(left: MutableList<Int>, right: MutableList<Int>, steps: Int = 0): Int {
    val leftSum = left.sum()
    val rightSum = right.sum()
    if (leftSum == rightSum) return steps

    val delta = leftSum - rightSum
    var larger = if (delta>0) left else right
    val smaller = if (delta>0) right else left

    val largerDecreases = larger.sortedDescending()
    val smallerIncreases = smaller.map { 9-it }

    val maxDecrease = largerDecreases.max()!!
    val maxIncrease = smallerIncreases.max()!!

    if(Math.max(maxDecrease, maxIncrease) >= Math.abs(delta)) {
        return steps+1
    }

    fun getIndex(list: List<Int>, number: Int?): Int = if (number == null) 0 else list.indexOf(number)

    if (maxIncrease>maxDecrease) {
        smaller[getIndex(smaller, smaller.min())] = 9
        return solve(smaller, larger, steps+1)
    }
    larger[getIndex(larger, larger.max())] = 0
    return solve(smaller, larger, steps+1)
}

import kotlin.math.*

val sc = java.util.Scanner(System.`in`)
fun main(args: Array<String>) {
	val n = sc.nextInt()
	var ans = 6
	for (i in 0..999999)
		if (islucky(i))
			ans = min(ans, different(n, i))
	println(ans)
}

fun islucky(x: Int) =
		x % 1000 == x / 1000 % 10 + x / 10000 % 10 + x / 100000

fun different(x: Int, y: Int): Int {
	var ans = 0
	var a = x
	var b = y
	for (i in 1..6) {
		if (a % 10 != b % 10)
			ans++
		a /= 10
		b /= 10
	}
	return ans;
}


Limak and Radewoosh are going to compete against each other in the upcoming algorithmic contest. They are equally skilled but they won't solve problems in the same order.There will be n problems. The i-th problem has initial score pi and it takes exactly ti minutes to solve it. Problems are sorted by difficulty — it's guaranteed that pi < pi + 1 and ti < ti + 1.A constant c is given too, representing the speed of loosing points. Then, submitting the i-th problem at time x (x minutes after the start of the contest) gives max(0,  pi - c·x) points.Limak is going to solve problems in order 1, 2, ..., n (sorted increasingly by pi). Radewoosh is going to solve them in order n, n - 1, ..., 1 (sorted decreasingly by pi). Your task is to predict the outcome — print the name of the winner (person who gets more points at the end) or a word "Tie" in case of a tie.You may assume that the duration of the competition is greater or equal than the sum of all ti. That means both Limak and Radewoosh will accept all n problems.

The first line contains two integers n and c (1 ≤ n ≤ 50, 1 ≤ c ≤ 1000) — the number of problems and the constant representing the speed of loosing points. The second line contains n integers p1, p2, ..., pn (1 ≤ pi ≤ 1000, pi < pi + 1) — initial scores. The third line contains n integers t1, t2, ..., tn (1 ≤ ti ≤ 1000, ti < ti + 1) where ti denotes the number of minutes one needs to solve the i-th problem.

Print "Limak" (without quotes) if Limak will get more points in total. Print "Radewoosh" (without quotes) if Radewoosh will get more points in total. Print "Tie" (without quotes) if Limak and Radewoosh will get the same total number of points.

NoteIn the first sample, there are 3 problems. Limak solves them as follows:  Limak spends 10 minutes on the 1-st problem and he gets 50 - c·10 = 50 - 2·10 = 30 points.  Limak spends 15 minutes on the 2-nd problem so he submits it 10 + 15 = 25 minutes after the start of the contest. For the 2-nd problem he gets 85 - 2·25 = 35 points.  He spends 25 minutes on the 3-rd problem so he submits it 10 + 15 + 25 = 50 minutes after the start. For this problem he gets 250 - 2·50 = 150 points. So, Limak got 30 + 35 + 150 = 215 points.Radewoosh solves problem in the reversed order:  Radewoosh solves 3-rd problem after 25 minutes so he gets 250 - 2·25 = 200 points.  He spends 15 minutes on the 2-nd problem so he submits it 25 + 15 = 40 minutes after the start. He gets 85 - 2·40 = 5 points for this problem.  He spends 10 minutes on the 1-st problem so he submits it 25 + 15 + 10 = 50 minutes after the start. He gets max(0, 50 - 2·50) = max(0,  - 50) = 0 points. Radewoosh got 200 + 5 + 0 = 205 points in total. Limak has 215 points so Limak wins.In the second sample, Limak will get 0 points for each problem and Radewoosh will first solve the hardest problem and he will get 250 - 6·25 = 100 points for that. Radewoosh will get 0 points for other two problems but he is the winner anyway.In the third sample, Limak will get 2 points for the 1-st problem and 2 points for the 2-nd problem. Radewoosh will get 4 points for the 8-th problem. They won't get points for other problems and thus there is a tie because 2 + 2 = 4.

import kotlin.math.max

/* http://codeforces.com/problemset/problem/658/A */

fun main() {
    val (_, losingRate) = readLine()!!.split(" ").map { it.toInt() }
    val scores = readLine()!!.split(" ").map { it.toInt() }
    val times = readLine()!!.split(" ").map { it.toInt() }
    val timesPassed = times.sumPrefixes()
    val scoresReversed = scores.asReversed()
    val timesReversed = times.asReversed()
    val timesReversedPassed = timesReversed.sumPrefixes()
    val limakScore = scores.mapIndexed { index, score -> max(0, score - losingRate * timesPassed[index]) }.sum()
    val radewooshScore = scoresReversed.mapIndexed { index, score -> max(0, score - losingRate * timesReversedPassed[index]) }.sum()
    when {
        limakScore > radewooshScore -> println("Limak")
        radewooshScore > limakScore -> println("Radewoosh")
        else -> println("Tie")
    }
}

private fun List<Int>.sumPrefixes(): List<Int> {
    if (this.isEmpty()) {
        return emptyList()
    }
    val resultList = ArrayList<Int>(this.size)
    resultList.add(this[0])
    for (i in 1 until this.size) {
        resultList.add(resultList[i - 1] + this[i])
    }
    return resultList
}

fun main(args: Array<String>) {
    val reader = java.util.Scanner(System.`in`)
    val n = reader.nextInt()
    val c = reader.nextInt()
    val ps = ArrayList<Int>(n)
    val pssum = ArrayList<Int>(n)
    val pssumrev = ArrayList<Int>(n)

    val ts = ArrayList<Int>(n)
    for (i in 1..n) {
        ps.add(reader.nextInt())
        pssum.add(0)
        pssumrev.add(0)
    }

    for (i in 1..n)
        ts.add(reader.nextInt())

    var sum : Int=0
    var sumrev : Int = 0
    for (i in ts.indices) {
        sum += ts[i]
        sumrev += ts[n-i-1]
        pssum[i]=sum
        pssumrev[n-i-1]=sumrev
    }

    val a= ps.zip(pssum){a, b -> if (a<c*b) 0 else a-c*b}.sum()
    val b= ps.zip(pssumrev){a, b -> if (a<c*b) 0 else a-c*b}.sum()
    val r = if (a == b) "Tie" else if (a>b) "Limak" else "Radewoosh"
    println(r)
    //println("Limak=$a Radewoosh=$b")

}

import kotlin.math.max

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val (_, constant) = readInts()
    val scores = readInts()
    val minutes = readInts()
    var limak = 0
    var radewoosh = 0
    var spentMinutes = 0
    for (pos in scores.indices) {
        spentMinutes += minutes[pos]
        limak += max(0, scores[pos] - constant * spentMinutes)
    }
    spentMinutes = 0
    for (pos in scores.indices.reversed()) {
        spentMinutes += minutes[pos]
        radewoosh += max(0, scores[pos] - constant * spentMinutes)
    }
    print(
        when {
            limak > radewoosh -> "Limak"
            limak == radewoosh -> "Tie"
            else -> "Radewoosh"
        }
    )
}

fun main(args: Array<String>){
	var tmpTime = 0
	var Limak = 0
	var Radewoosh = 0

	val (N,c) = readLine()!!.split(' ')

	val points = readLine()!!.split(' ').map { it.toInt() }
	val time = readLine()!!.split(' ').map { it.toInt() }

	for(i in 0 until N.toInt()){
		tmpTime += time[i]
		if(points[i]-tmpTime*c.toInt() < 0){
			continue
		}else{
			Limak += points[i]-tmpTime*c.toInt()
		}
	}
	tmpTime = 0
	for(i in N.toInt()-1 downTo 0){
		tmpTime += time[i]
		if(points[i]-tmpTime*c.toInt() < 0){
			continue
		}else{
			Radewoosh += points[i]-tmpTime*c.toInt()
		}
	}
	when {
		Limak > Radewoosh -> println("Limak")
		Limak < Radewoosh -> println("Radewoosh")
		else -> println("Tie")
	}

}

import kotlin.math.max

fun score(p: Int, c: Int, x: Int) : Int {
  return max(0, p-c*x)
}

fun main(args: Array<String>) {
  val (n, c) = readLine()!!.split(" ").map(String::toInt)
  val p = readLine()!!.split(" ").map(String::toInt)
  val t = readLine()!!.split(" ").map(String::toInt)
  var (score_limak, score_radewoosh) = listOf(0, 0)
  var (time_limak, time_radewoosh) = listOf(0, 0)
  for(i in 0..n-1) {
    time_limak += t[i]
    score_limak += score(p[i], c, time_limak)
  }
  for(i in n-1 downTo 0) {
    time_radewoosh += t[i]
    score_radewoosh += score(p[i], c, time_radewoosh)
  }
  if(score_radewoosh == score_limak) println("Tie")
  else if(score_radewoosh > score_limak) println("Radewoosh")
  else println("Limak")
}

fun main(args: Array<String>) {
    val reader = java.util.Scanner(System.`in`)
    val n = reader.nextInt()
    val c = reader.nextInt()
    val ps = ArrayList<Int>(n)
    val pssum = ArrayList<Int>(n)
    val pssumrev = ArrayList<Int>(n)

    val ts = ArrayList<Int>(n)
    for (i in 1..n) {
        ps.add(reader.nextInt())
        pssum.add(0)
        pssumrev.add(0)
    }

    for (i in 1..n)
        ts.add(reader.nextInt())

    var sum : Int=0
    var sumrev : Int = 0
    for (i in ts.indices) {
        sum += ts[i]
        sumrev += ts[n-i-1]
        pssum[i]=sum
        pssumrev[n-i-1]=sumrev
    }

    val a= ps.zip(pssum){a, b -> if (a<c*b) 0 else a-c*b}.sum()
    val b= ps.zip(pssumrev){a, b -> if (a<c*b) 0 else a-c*b}.sum()
    val r = if (a == b) "Tie" else if (a<b) "Limak" else "Radewoosh"
    println(r)

}


Every summer Vitya comes to visit his grandmother in the countryside. This summer, he got a huge wart. Every grandma knows that one should treat warts when the moon goes down. Thus, Vitya has to catch the moment when the moon is down.Moon cycle lasts 30 days. The size of the visible part of the moon (in Vitya's units) for each day is 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 14, 13, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 1, and then cycle repeats, thus after the second 1 again goes 0.As there is no internet in the countryside, Vitya has been watching the moon for n consecutive days and for each of these days he wrote down the size of the visible part of the moon. Help him find out whether the moon will be up or down next day, or this cannot be determined by the data he has.

The first line of the input contains a single integer n (1 ≤ n ≤ 92) — the number of consecutive days Vitya was watching the size of the visible part of the moon.  The second line contains n integers ai (0 ≤ ai ≤ 15) — Vitya's records. It's guaranteed that the input data is consistent.

If Vitya can be sure that the size of visible part of the moon on day n + 1 will be less than the size of the visible part on day n, then print "DOWN" at the only line of the output. If he might be sure that the size of the visible part will increase, then print "UP". If it's impossible to determine what exactly will happen with the moon, print -1.

NoteIn the first sample, the size of the moon on the next day will be equal to 8, thus the answer is "UP".In the second sample, the size of the moon on the next day will be 11, thus the answer is "DOWN".In the third sample, there is no way to determine whether the size of the moon on the next day will be 7 or 9, thus the answer is -1.

import java.io.*
import java.util.*

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    companion object {
        fun console() = ProblemIO(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))
        fun files(inputFilename: String, outputFilename: String) =
                ProblemIO(BufferedReader(FileReader(File(inputFilename))), PrintWriter(File(outputFilename)))
    }

    var tok = StringTokenizer("")

    fun close() { rd.close(); wr.close() }
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun readToken(): String {
        while (!tok.hasMoreTokens()) tok = StringTokenizer(rd.readLine())
        return tok.nextToken()
    }
    fun readLine(): String {
        tok = StringTokenizer("")
        return rd.readLine()
    }
    fun readInt(): Int = readToken().toInt()
    fun readLong(): Long = readToken().toLong()
}

fun main(args: Array<String>) {
    Thread({ val io = ProblemIO.console(); solve(io); io.close() }).start()
}

fun solve(io: ProblemIO) {
    val n = io.readInt()
    val a = IntArray(n, { io.readInt() })
    val l = a.last()
    val res = when {
        l == 15 -> "DOWN"
        l == 0 -> "UP"
        else -> when {
            a.size == 1 -> "-1"
            l > a[a.lastIndex - 1] -> "UP"
            l < a[a.lastIndex - 1] -> "DOWN"
            else -> "-1"
        }
    }
    io.println(res)
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    val v = r.readLine()!!.split(" ").map { it.toInt() }
    if (n == 1) {
        when {
            v[0] == 0 -> println("UP")
            v[0] == 15 -> println("DOWN")
            else -> println(-1)
        }
    } else {
        val before = v[n - 2]
        val mid = v[n - 1]
        when {
            mid == 15 -> println("DOWN")
            mid == 0 -> println("UP")
            mid > before -> println("UP")
            mid < before -> println("DOWN")
        }
    }
}

import java.io.*

val stdout = System.out;
val stdin = FastScanner(System.`in`);

fun solve() {
    val n = nextInt()
    val arr = nextIntArray(n)
    when {
        arr.last() == 15 -> print("DOWN")
        arr.last() == 0 -> print("UP")
        arr.size < 2 -> print("-1")
        else -> if (arr[n - 1] > arr[n - 2]) print("UP") else print("DOWN")
    }
}

inline fun print(message: Any?) = stdout.print(message)
inline fun print(message: Int) = stdout.print(message)
inline fun print(message: Long) = stdout.print(message)
inline fun print(message: Byte) = stdout.print(message)
inline fun print(message: Short) = stdout.print(message)
inline fun print(message: Char) = stdout.print(message)
inline fun print(message: Boolean) = stdout.print(message)
inline fun print(message: Float) = stdout.print(message)
inline fun print(message: Double) = stdout.print(message)
inline fun print(message: CharArray) = stdout.print(message)
inline fun println(message: Any?) = stdout.println(message)
inline fun println(message: Int) = stdout.println(message)
inline fun println(message: Long) = stdout.println(message)
inline fun println(message: Byte) = stdout.println(message)
inline fun println(message: Short) = stdout.println(message)
inline fun println(message: Char) = stdout.println(message)
inline fun println(message: Boolean) = stdout.println(message)
inline fun println(message: Float) = stdout.println(message)
inline fun println(message: Double) = stdout.println(message)
inline fun println(message: CharArray) = stdout.println(message)
inline fun println() = stdout.println()

inline fun nextInt() = stdin.nextInt()
inline fun nextLong() = stdin.nextLong()
inline fun nextChar() = stdin.nextChar()
inline fun next() = stdin.next()
inline fun nextLine() = stdin.nextLine()
inline fun nextIntArray(n: Int) = IntArray(n, { nextInt() })

class FastScanner(ins: InputStream): Closeable {
    val BUFFER_SIZE = 65536;
    val br: BufferedReader
    var end = false

    var len: Int = 0
    val buffer = CharArray(BUFFER_SIZE)
    var it: Int = 0

    init {
        br = BufferedReader(InputStreamReader(ins), BUFFER_SIZE)
    }

    constructor(file: String): this(FileInputStream(file))

    inline fun isLineBreaker(c: Char) = c == '\n'
    inline fun isDelimiter(c: Char) = c == ' ' || c == '\n' || c == '\r'

    inline fun ensureBuffer() {
        if (it == len) {
            it = 0
            len = br.read(buffer)
            if (len == -1) end = true
        }
    }

    inline fun moveNext() {
        while (!end) {
            ensureBuffer()
            if (!isDelimiter(buffer[it])) return
            while (it < len && isDelimiter(buffer[it])) it++;
        }
    }

    inline fun nextChar(): Char {
        moveNext()
        if (end) return (-1).toChar()
        return buffer[it++]
    }

    inline fun next(): String {
        moveNext()
        val sb = StringBuilder()
        while (!end) {
            val l = it
            while (++it < len && !isDelimiter(buffer[it]));
            sb.append(buffer, l, it - l)
            ensureBuffer()
            if (end || isDelimiter(buffer[it])) break;
        }
        return sb.toString()
    }

    inline fun nextInt(): Int {
        moveNext()
        var minus = true
        if (buffer[it] == '-') {
            it++
            minus = false
        }
        var result: Int = 0
        while (!end) {
            while (it < len && !isDelimiter(buffer[it])) {
                result *= 10
                result += (buffer[it] - '0').toInt()
                it++
            }
            ensureBuffer()
            if (end || isDelimiter(buffer[it])) break
        }
        return if (minus) result else -result
    }

    inline fun nextLong(): Long {
        moveNext()
        var minus = true
        if (buffer[it] == '-') {
            it++
            minus = false
        }
        var result: Long = 0
        while (!end) {
            while (it < len && !isDelimiter(buffer[it])) {
                result *= 10
                result += (buffer[it] - '0').toLong()
                it++
            }
            ensureBuffer()
            if (end || isDelimiter(buffer[it])) break
        }
        return if (minus) result else -result
    }

    inline fun nextLine(): String {
        moveNext()
        val sb = StringBuilder()
        while (!end) {
            val l = it
            while (++it < len && !isLineBreaker(buffer[it]));
            sb.append(buffer, l, it - l)
            ensureBuffer()
            if (end || isLineBreaker(buffer[it])) break;
        }
        return sb.toString()
    }

    override fun close() {
        br.close()
    }
}

fun main(args: Array<String>) {
    solve()
    stdin.close()
    stdout.close();
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    readLine()
    val sizes = readInts()
    print(
        when {
            sizes.last() == 0 -> "UP"
            sizes.last() == 15 -> "DOWN"
            sizes.size == 1 -> "-1"
            sizes.last() > sizes[sizes.lastIndex - 1] -> "UP"
            else -> "DOWN"
        }
    )
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    val v = r.readLine()!!.split(" ").map { it.toInt() }
    if (n == 1) {
        println(-1)
    } else {
        val before = v[n - 2]
        val mid = v[n - 1]
        when {
            mid in (before + 1)..14 -> println("UP")
            mid > before && mid == 15 -> println("DOWN")
            mid in 1 until before -> println("DOWN")
            mid < before && mid == 0 -> println("UP")
        }
    }
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    val v = r.readLine()!!.split(" ").map { it.toInt() }
    if (n==1) {
        println(-1)
    } else{
        val before = v[n-2]
        val mid = v[n-1]
        when{
            mid in (before + 1)..14 -> println("UP")
            mid<before&&mid==15 -> println("DOWN")
            mid in 1 until before -> println("DOWN")
            mid<before &&mid==0 -> println("UP")
        }
    }
}


Mancala is a game famous in the Middle East. It is played on a board that consists of 14 holes.   Initially, each hole has $$$a_i$$$ stones. When a player makes a move, he chooses a hole which contains a positive number of stones. He takes all the stones inside it and then redistributes these stones one by one in the next holes in a counter-clockwise direction.Note that the counter-clockwise order means if the player takes the stones from hole $$$i$$$, he will put one stone in the $$$(i+1)$$$-th hole, then in the $$$(i+2)$$$-th, etc. If he puts a stone in the $$$14$$$-th hole, the next one will be put in the first hole.After the move, the player collects all the stones from holes that contain even number of stones. The number of stones collected by player is the score, according to Resli.Resli is a famous Mancala player. He wants to know the maximum score he can obtain after one move.

The only line contains 14 integers $$$a_1, a_2, \ldots, a_{14}$$$ ($$$0 \leq a_i \leq 10^9$$$) — the number of stones in each hole. It is guaranteed that for any $$$i$$$ ($$$1\leq i \leq 14$$$) $$$a_i$$$ is either zero or odd, and there is at least one stone in the board.

Output one integer, the maximum possible score after one move.

NoteIn the first test case the board after the move from the hole with $$$7$$$ stones will look like 1 2 2 0 0 0 0 0 0 0 1 1 1 1. Then the player collects the even numbers and ends up with a score equal to $$$4$$$.

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val numStones = readInts()
    var bestSol = 0L
    for (hole in 0 until 14) {
        val initialStonesInHole = numStones[hole]
        val stonesEach = initialStonesInHole / 14
        val extraStones = initialStonesInHole % 14
        var sol = 0L
        for (otherHole in hole + 1..hole + extraStones) {
            val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach + 1
            if (stonesInHole and 1 == 0L) sol += stonesInHole
        }
        for (otherHole in hole + extraStones + 1..hole + 13) {
            val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach
            if (stonesInHole and 1 == 0L) sol += stonesInHole
        }
        if (stonesEach and 1 == 0) sol += stonesEach
        if (sol > bestSol) bestSol = sol
    }
    print(bestSol)
}

fun main(args: Array<String>) {
    val a = System.`in`.reader().readText().trim().split(' ').map(String::toLong)
    println(a.mapIndexed { i, l ->
        a.mapIndexed { j, m ->
            if (i == j) m / 14
            else m + (l + (i - j + 14).rem(14)) / 14
        }.filter { it.rem(2) == 0L }.sum()
    }.max())
}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    val numStones = readInts()
    var bestSol = 0L
    for (hole in 0 until 14) {
        val initialStonesInHole = numStones[hole]
        val stonesEach = initialStonesInHole / 14
        val extraStones = initialStonesInHole % 14
        var sol = 0L
        for (otherHole in hole + 1..hole + extraStones) {
            val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach + 1
            if (stonesInHole and 1 == 0L) sol += stonesInHole
        }
        for (otherHole in hole + extraStones..hole + 13) {
            val stonesInHole = numStones[otherHole % 14].toLong() + stonesEach
            if (stonesInHole and 1 == 0L) sol += stonesInHole
        }
        if (stonesEach and 1 == 0) sol += stonesEach
        if (sol > bestSol) bestSol = sol
    }
    print(bestSol)
}


You are at a water bowling training. There are l people who play with their left hand, r people, who play with their right hand, and a ambidexters, who can play with left or right hand.The coach decided to form a team of even number of players, exactly half of the players should play with their right hand, and exactly half of the players should play with their left hand. One player should use only on of his hands.Ambidexters play as well with their right hand as with their left hand. In the team, an ambidexter can play with their left hand, or with their right hand.Please find the maximum possible size of the team, where equal number of players use their left and right hands, respectively.

The only line contains three integers l, r and a (0 ≤ l, r, a ≤ 100) — the number of left-handers, the number of right-handers and the number of ambidexters at the training.

Print a single even integer — the maximum number of players in the team. It is possible that the team can only have zero number of players.

NoteIn the first example you can form a team of 6 players. You should take the only left-hander and two ambidexters to play with left hand, and three right-handers to play with right hand. The only person left can't be taken into the team.In the second example you can form a team of 14 people. You have to take all five left-handers, all five right-handers, two ambidexters to play with left hand and two ambidexters to play with right hand.

import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    val min = min(array[0], array[1])

    if(min + array[2] <= max(array[0], array[1])) println((min + array[2]).times(2))
    else println(max(array[0], array[1]).plus(array[2] - abs(array[0] - array[1]) shr 1).times(2))
}

import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()

    val min = min(array[0], array[1])
    val max = max(array[0], array[1])

    if(min + array[2] <= max){
        println((min + array[2]).times(2))
    } else {
        var ambOut = array[2] - abs(array[0] - array[1])
        println(if ((array[0] == 0 || array[1] == 0) && array[2] == 0) 0 else max(array[0], array[1]).plus(ambOut shr 1).times(2))
    }
}

import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    val min = min(array[0], array[1])

    if((array[0] == 0 || array[1] == 0) && array[2] == 0) println(0)
    else if(min + array[2] <= max(array[0], array[1])) println((min + array[2]).times(2))
    else println(max(array[0], array[1]).plus(array[2] - abs(array[0] - array[1]) shr 1).times(2))
}

import java.lang.Math.abs
import java.util.*

/**
 * Created by SitaoLiao on 3/11/18.
 */
fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`);

    val user_input = scanner.nextLine().split(" ").map{ it.toInt() };

    var diff = user_input[0] - user_input[1];

    val ans: Int

    if( diff > 0 ){
        if( diff >= user_input[2] ){
            ans = user_input[1] + user_input[2]
        } else {
            ans = user_input[0] + (user_input[2]-diff)/2
        }
    } else {
        diff = abs(diff)
        if( diff >= user_input[2] ){
            ans = user_input[0] + user_input[2]
        } else {
            ans = user_input[1] + (user_input[2]-diff)/2
        }
    }

    println(ans*2)
}

import java.io.*
import java.util.*
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
}

val MAX_N = (1e6 + 10).toInt()
val INF = (1e9 + 7).toInt()
val MOD = (1e9 + 7).toInt()

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val l = reader.nextInt()
    val r = reader.nextInt()
    val a = reader.nextInt()

    var ans = 0

    for (i in 0..a) {
        val t = min(l + i, r + a - i)
        ans = max(ans, t)
    }
    writer.println(2 * ans)
}

class InputReader(stream: InputStream) {
    val reader: BufferedReader
    var tokenizer: StringTokenizer? = null

    init {
        reader = BufferedReader(InputStreamReader(stream), 32768)
        tokenizer = null
    }

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        for (i in 0 until count) {
            a[i] = nextLong()
        }
        return a
    }
}

fun min(a: Int, b:Int): Int{
    return if (a > b) b else a
}
fun main(args: Array<String>){

    var (l,p,a) = readLine().toString().split(" ").map{x -> x.toInt()}

    while(l!=p&&a>0){

        if(l<p){
            l++
            a--
        } else {
            p++
            a--
        }
    }
    while(a>1){
        l++
        p++
        a-=2
    }

    print(min(l,p)*2)

}

fun main() {
    fun readInts() = readLine()!!.split(" ").map(String::toInt)

    var (l, r, a) = readInts()
    var (min, max) = if (l <= r) l to r else r to l
    if (min + a < max) {
        min += a
        a = 0
    } else {
        val diff = max - min
        min = max
        a -= diff
    }
    print((kotlin.math.min(min, max) + a / 2) * 2)
}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val line = BufferedReader(InputStreamReader(System.`in`)).readLine().split(' ')

    var l = line[0].toInt()
    var r = line[1].toInt()
    var a = line[2].toInt()

    while (a > 0 && r != l) {
        a--
        when {
            r > l -> l++
            l > r -> r++
        }
    }

    if (r == l) {
        while (a > 0) {
            a--
            if (a % 2 == 0) r++ else l++
        }
    }
    if (l == 0 || r == 0) return println(0)

    while (l != r) {
        when {
            l > r -> l--
            l < r -> r--
        }
    }

    println(l + r)
}

fun main(arg: Array<String>){
	var (L, R, A) = readLine().toString().split(" ").map {x -> x.toInt()}
	var teamN = 0
	val pmaxL = L + A
	val pmaxR = R + A
	val maxTeam = if (pmaxR > pmaxL) pmaxL else pmaxR
	if (maxTeam == 0){
		println(0)
		return
	}
//	println("Max team is: $maxTeam")
	var teamL: Int = 0
	var teamR: Int = 0

	while((R+A>0) and (L+A>0)){
//		println("Before. R:$R, L:$L, A:$A, TL: $teamL, TR: $teamR")
		if(L>R){
			if (R>0){
				teamR+=1
				R-=1
			}else{
				teamR+=1
				A-=1
			}

			if (L>0){
				teamL+=1
				L-=1
			}else{
				teamL+=1
				A-=1
			}

		}else{
			if (L>0){
				teamL+=1
				L-=1
			}else{
				teamL+=1
				A-=1
			}

			if (R>0){
				teamR+=1
				R-=1
			}else{
				teamR+=1
				A-=1
			}

		}

		if(A < 0){
			teamR -= 1
			teamL -= 1
			break
		}

//		println("Before. R:$R, L:$L, A:$A, TL: $teamL, TR: $teamR")

	}

	println(teamL + teamR)
}

import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

fun main(args: Array<String>) {

    val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    val min = min(array[0], array[1])

    if(array[0] == 0 || array[1] == 0 && array[2] == 0) println(0)
    else if(min + array[2] <= max(array[0], array[1])) println((min + array[2]).times(2))
    else println(max(array[0], array[1]).plus(array[2] - abs(array[0] - array[1]) shr 1).times(2))

}

import kotlin.math.abs
import kotlin.math.max

fun main(args: Array<String>) {
    val array: IntArray = readLine()!!.split(' ').map { it.toInt() }.toIntArray()
    var ambOut = array[2] - abs(array[0] - array[1])
    println(if((array[0] == 0 || array[1] == 0) && array[2] == 0) 0 else max(array[0], array[1]).plus(ambOut shr 1).times(2))
}

import java.io.BufferedReader
import java.io.InputStreamReader

fun main(args: Array<String>) {
    val line = BufferedReader(InputStreamReader(System.`in`)).readLine().split(' ')

    var l = line[0].toInt()
    var r = line[1].toInt()
    var a = line[2].toInt()

    while (a > 0 && r != l) {
        a--
        if (r > l) l++ else if (l > r) r++
    }

    if (r == l) {
        while (a > 0) {
            a--
            if (a % 2 == 0) r++ else l++
        }
    }
    if (l == 0 || r == 0) return println(0)

    var result = l + r
    if (result % 2 != 0) result--
    println(result)
}


You are given a sequence a consisting of n integers. You may partition this sequence into two sequences b and c in such a way that every element belongs exactly to one of these sequences. Let B be the sum of elements belonging to b, and C be the sum of elements belonging to c (if some of these sequences is empty, then its sum is 0). What is the maximum possible value of B - C?

The first line contains one integer n (1 ≤ n ≤ 100) — the number of elements in a. The second line contains n integers a1, a2, ..., an ( - 100 ≤ ai ≤ 100) — the elements of sequence a.

Print the maximum possible value of B - C, where B is the sum of elements of sequence b, and C is the sum of elements of sequence c.

NoteIn the first example we may choose b = {1, 0}, c = { - 2}. Then B = 1, C =  - 2, B - C = 3.In the second example we choose b = {16, 23, 16, 15, 42, 8}, c = {} (an empty sequence). Then B = 120, C = 0, B - C = 120.

fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    val n = r.readLine()!!.toInt()
    //val (m, n) = r.readLine()!!.split(" ").map { it.toInt() }
    val v = r.readLine()!!.split(" ").map { it.toInt() }.map { if (it<0) -it else it }.sum()
    println(v)

}

fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var a = readLine()!!.split(' ')
    var B = 0
    var C = 0
    for (i in 0 until a.size){
        if (a[i].toInt() >= 0) {
            B += a[i].toInt()
        }
        else{
            C += a[i].toInt()
        }
    }
    print(B-C)
}

import java.io.PrintWriter
import kotlin.math.*

fun main() {
    io.apply {

        val n = int
        val d = ints(n)
        val ans = d.map { abs(it) }.sum()
        cout .. ans .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.*
import java.util.*

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
}

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val a = reader.nextArrayInt(n)
    val ans = a.filter { it > 0 }.sum() - a.filter { it < 0 }.sum()
    writer.println(ans)
}

class InputReader(stream: InputStream) {
    val reader: BufferedReader
    var tokenizer: StringTokenizer? = null

    init {
        reader = BufferedReader(InputStreamReader(stream), 32768)
        tokenizer = null
    }

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        for (i in 0 until count) {
            a[i] = nextLong()
        }
        return a
    }
}

import java.io.*
import java.util.*

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
}

fun solve(input: InputStream, output: OutputStream) {
    val reader = InputReader(BufferedInputStream(input))
    val writer = PrintWriter(BufferedOutputStream(output))

    solve(reader, writer)
    writer.close()
}

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val a = reader.nextArrayInt(n)
    val ans = a.map {
        if (it < 0) {
            -it
        } else {
            it
        }
    }.sum()
//            a.filter { it > 0 }.sum() - a.filter { it < 0 }.sum()
    writer.println(ans)
}

class InputReader(stream: InputStream) {
    val reader: BufferedReader
    var tokenizer: StringTokenizer? = null

    init {
        reader = BufferedReader(InputStreamReader(stream), 32768)
        tokenizer = null
    }

    operator fun next(): String {
        while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
            try {
                tokenizer = StringTokenizer(reader.readLine())
            } catch (e: IOException) {
                throw RuntimeException(e)
            }

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return Integer.parseInt(next())
    }

    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }

    fun nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

    fun nextArrayInt(start: Int, count: Int): IntArray {
        val a = IntArray(start + count)
        for (i in start until start + count) {
            a[i] = nextInt()
        }
        return a
    }

    fun nextArrayLong(count: Int): LongArray {
        val a = LongArray(count)
        for (i in 0 until count) {
            a[i] = nextLong()
        }
        return a
    }
}

import kotlin.math.abs

fun main(args: Array<String>) {
    val z = java.util.Scanner(System.`in`)
    val n = z.nextInt()
    var sum = 0
    var a = 0
    for (i in 1..n)
        sum+=abs(z.nextInt())
    println(sum)
}

import java.io.*
import java.util.*
import java.lang.Math.*

fun PrintWriter.solve() {
    val n = nextInt()
    println((1..n).map { abs(nextInt()) }.sum())
}

fun main(args: Array<String>) {
    PrintWriter(System.out, false).use { it.solve() }
}

val br = BufferedReader(InputStreamReader(System.`in`))
var stok = StringTokenizer("")

fun nextToken(): String? {
    while (!stok.hasMoreTokens()) {
        val s = br.readLine() ?: return null
        stok = StringTokenizer(s)
    }
    return stok.nextToken()
}

fun nextInt(): Int {
    return nextToken()!!.toInt()
}

fun nextLong(): Long {
    return nextToken()!!.toLong()
}

fun nextDouble(): Double {
    return nextToken()!!.toDouble()
}

fun main(args: Array<String>) {
    System.`in`.bufferedReader().use {
        val n = it.readLine().toInt()
        val parts = it.readLine().split(' ')
        val a = IntArray(n, { i -> parts[i].toInt() })

        a.sort()

        var b = 0
        var c = 0
        var i = 0
        while (i < n && a[i] < 0)
            c += a[i++]
        while (i < n)
            b += a[i++]

        println(b - c)
    }
}

fun main(args: Array<String>)
{
    val n = readLine()!!.toInt()
    val inp = readLine()!!.split(' ').map(String::toInt)
    val sneg = inp.filter({i -> i < 0}).sum()
    val spos = inp.filter({i -> i > 0}).sum()
    println(spos - sneg)
}

import java.util.*
fun main(args: Array<String>) {

    var count  = readLine()!!.toInt()
    var arr = readLine()!!.split(' ')
    var B = 0
    var C = 0
    var i = 0
    repeat(count)
    {
        val X = arr[i].toInt()
        if(X > 0) B += X
        else C += X
        i++
    }
     println(B - C)

}

import kotlin.math.absoluteValue

fun main() {
    readLine()
    print(readLine()!!.split(" ").map { it.toInt().absoluteValue }.sum())
}

fun main(args:Array<String>) {
  val n = readLine()!!
  val (A,B) = (0..1).map { mutableListOf<Int>() }

  readLine()!!.split(" ").map(String::toInt).map {
    if( it > 0 ) A.add(it) else B.add(it)
  }
  println( A.sum() - B.sum() )
}

import java.util.*

class A {
    fun run(scan: Scanner) {
        val count = scan.nextInt()
        var sumB = 0
        var sumC = 0
        repeat(count){
            val cur = scan.nextInt()
            if(cur > 0)
                sumB += cur
            else sumC += cur
        }
        println(sumB - sumC)
    }
}

fun main(args: Array<String>) {
    A().run(Scanner(System.`in`))
}

import java.util.Scanner
import kotlin.math.abs
import kotlin.math.max

fun main() {
    val reader = Scanner(System.`in`)

    val n = reader.nextInt()
    var arr = Array(n) {0}
    var sum = 0

    for(i in 0..n-1) {
        arr[i] = reader.nextInt()
        sum += abs(arr[i])
    }
    println(sum)
}

import java.io.PrintWriter
import kotlin.math.*

fun main() {
    io.apply {

        val n = int
        val d = ints(n)
        var cur = d.sum()
        var mx = abs(cur)
        for (i in n - 1 downTo 0) {
            cur -= d[i] * 2
            mx = max(abs(cur), mx)
        }

        cout .. mx .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.PrintWriter
import kotlin.math.*

fun main() {
    io.apply {

        val n = int
        val d = ints(n)
        var cur = d.sum()
        var mx = cur
        for (i in n - 1 downTo 0) {
            cur -= d[i] * 2
            mx = max(cur, mx)
        }

        cout .. mx .. nl

    }.cout.flush()
}

// @formatter:off
private val io = object {
    private val `in` = System.`in`
    private fun ll(): Long {
        var x: Int; var q = false; var n = 0L; do x = `in`.read() while (x < 33); if (x == 45) { q = true; x = `in`.read() }
        do { n = n * 10 - x + 48; x = `in`.read() } while (x > 32); return if (q) n else -n
    }
    val int get() = ll().toInt(); val long get() = ll()
    fun ints(n: Int = int): IntArray { return IntArray(n) { int } }
    fun ints1(n: Int = int): IntArray { return IntArray(n) { int - 1 } }
    val cout = PrintWriter(System.out); val nl = "\n"
    private var buf = CharArray(32)
    private var bufSize = 32
    fun str(expect: Int = 32): String {
        var ix = 0
        var x: Int
        if (bufSize < expect)
            buf = CharArray(expect)
        do x = `in`.read() while (x < 33)
        do {
            if (ix == bufSize) { bufSize *= 2; buf = buf.copyOf(bufSize) }
            buf[ix++] = x.toChar()
            x = `in`.read()
        } while (x > 32)
        return java.lang.String.copyValueOf(buf, 0, ix)
    }
    operator fun PrintWriter.rangeTo(a: Int): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: Long): PrintWriter { print(a); print(" "); return this }
    operator fun PrintWriter.rangeTo(a: IntArray): PrintWriter { a.forEach { print(it); print(" ") }; return this }
    operator fun PrintWriter.rangeTo(a: String): PrintWriter { write(a); return this }
} // @formatter:on

/* ----------- */

import java.io.*
import java.util.*
import java.lang.Math.*

fun PrintWriter.solve() {
    val n = nextInt()
    println((1..n).map { nextInt() }.sum())
}

fun main(args: Array<String>) {
    PrintWriter(System.out, false).use { it.solve() }
}

val br = BufferedReader(InputStreamReader(System.`in`))
var stok = StringTokenizer("")

fun nextToken(): String? {
    while (!stok.hasMoreTokens()) {
        val s = br.readLine() ?: return null
        stok = StringTokenizer(s)
    }
    return stok.nextToken()
}

fun nextInt(): Int {
    return nextToken()!!.toInt()
}

fun nextLong(): Long {
    return nextToken()!!.toLong()
}

fun nextDouble(): Double {
    return nextToken()!!.toDouble()
}


Nowadays, most of the internet advertisements are not statically linked to a web page. Instead, what will be shown to the person opening a web page is determined within 100 milliseconds after the web page is opened. Usually, multiple companies compete for each ad slot on the web page in an auction. Each of them receives a request with details about the user, web page and ad slot and they have to respond within those 100 milliseconds with a bid they would pay for putting an advertisement on that ad slot. The company that suggests the highest bid wins the auction and gets to place its advertisement. If there are several companies tied for the highest bid, the winner gets picked at random.However, the company that won the auction does not have to pay the exact amount of its bid. In most of the cases, a second-price auction is used. This means that the amount paid by the company is equal to the maximum of all the other bids placed for this ad slot.Let's consider one such bidding. There are n companies competing for placing an ad. The i-th of these companies will bid an integer number of microdollars equiprobably randomly chosen from the range between Li and Ri, inclusive. In the other words, the value of the i-th company bid can be any integer from the range [Li, Ri] with the same probability. Determine the expected value that the winner will have to pay in a second-price auction.

The first line of input contains an integer number n (2 ≤ n ≤ 5). n lines follow, the i-th of them containing two numbers Li and Ri (1 ≤ Li ≤ Ri ≤ 10000) describing the i-th company's bid preferences. This problem doesn't have subproblems. You will get 8 points for the correct submission.

Output the answer with absolute or relative error no more than 1e - 9.

NoteConsider the first example. The first company bids a random integer number of microdollars in range [4, 7]; the second company bids between 8 and 10, and the third company bids 5 microdollars. The second company will win regardless of the exact value it bids, however the price it will pay depends on the value of first company's bid. With probability 0.5 the first company will bid at most 5 microdollars, and the second-highest price of the whole auction will be 5. With probability 0.25 it will bid 6 microdollars, and with probability 0.25 it will bid 7 microdollars. Thus, the expected value the second company will have to pay is 0.5·5 + 0.25·6 + 0.25·7 = 5.75.

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.math.abs
import kotlin.math.max
import kotlin.math.min

val MOD = 1_000_000_007L

class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = ni()
    val (L, R) = na2(N)

    var ans = 0.0

    for (i in 0 until N) {
      for (j in 0 until N) {
        if (i == j) continue
        for (x in L[j] .. R[j]) {
          var prob = 1.0
          for (k in 0 until N) {
            if (k == j) continue

            prob *= if (k == i) {
              val l = max(if (i < j) x else x + 1, L[i])
              val r = R[i]
              max(0, r - l + 1)
            } else {
              val l = L[k]
              val r = min(if (j < k) x else x - 1, R[k])
              max(0, r - l + 1)
            }
          }
          ans += prob * x
        }
      }
    }

    debug{"ans:$ans"}
    for (i in 0 until N) {
      ans /= (R[i] - L[i] + 1)
    }

    out.println("%.10f".format(ans))
  }

  private val isDebug = try {
    // なんか本番でエラーでる
    System.getenv("MY_DEBUG") != null
  } catch (t: Throwable) {
    false
  }

  private var tokenizer: StringTokenizer? = null
  private val reader = BufferedReader(InputStreamReader(stream), 32768)
  private fun next(): String {
    while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
      tokenizer = StringTokenizer(reader.readLine())
    }
    return tokenizer!!.nextToken()
  }

  private fun ni() = next().toInt()
  private fun nl() = next().toLong()
  private fun ns() = next()
  private fun na(n: Int, offset: Int = 0): IntArray {
    return map(n) { ni() + offset }
  }
  private fun nal(n: Int, offset: Int = 0): LongArray {
    val res = LongArray(n)
    for (i in 0 until n) {
      res[i] = nl() + offset
    }
    return res
  }

  private fun na2(n: Int, offset: Int = 0): Array<IntArray> {
    val a  = Array(2){IntArray(n)}
    for (i in 0 until n) {
      for (e in a) {
        e[i] = ni() + offset
      }
    }
    return a
  }

  private inline fun map(n: Int, f: (Int) -> Int): IntArray {
    val res = IntArray(n)
    for (i in 0 until n) {
      res[i] = f(i)
    }
    return res
  }

  private inline fun debug(msg: () -> String) {
    if (isDebug) System.err.println(msg())
  }

  private fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: IntArray) {
    debug { a.joinToString(" ") }
  }

  private fun debug(a: BooleanArray) {
    debug { a.map { if (it) 1 else 0 }.joinToString("") }
  }

  private fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private fun debugDim(A: Array<IntArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }

  /**
   * 勝手にimport消されるのを防ぎたい
   */
  private fun hoge() {
    min(1, 2)
    max(1, 2)
    abs(-10)
  }
}

fun main() {
  val out = java.io.PrintWriter(System.out)
  Solver(System.`in`, out).solve()
  out.flush()
}


Dreamoon is standing at the position 0 on a number line. Drazil is sending a list of commands through Wi-Fi to Dreamoon's smartphone and Dreamoon follows them.Each command is one of the following two types:   Go 1 unit towards the positive direction, denoted as '+'  Go 1 unit towards the negative direction, denoted as '-' But the Wi-Fi condition is so poor that Dreamoon's smartphone reports some of the commands can't be recognized and Dreamoon knows that some of them might even be wrong though successfully recognized. Dreamoon decides to follow every recognized command and toss a fair coin to decide those unrecognized ones (that means, he moves to the 1 unit to the negative or positive direction with the same probability 0.5). You are given an original list of commands sent by Drazil and list received by Dreamoon. What is the probability that Dreamoon ends in the position originally supposed to be final by Drazil's commands?

The first line contains a string s1 — the commands Drazil sends to Dreamoon, this string consists of only the characters in the set {'+', '-'}.  The second line contains a string s2 — the commands Dreamoon's smartphone recognizes, this string consists of only the characters in the set {'+', '-', '?'}. '?' denotes an unrecognized command. Lengths of two strings are equal and do not exceed 10.

Output a single real number corresponding to the probability. The answer will be considered correct if its relative or absolute error doesn't exceed 10 - 9.

NoteFor the first sample, both s1 and s2 will lead Dreamoon to finish at the same position  + 1. For the second sample, s1 will lead Dreamoon to finish at position 0, while there are four possibilites for s2: {"+-++", "+-+-", "+--+", "+---"} with ending position {+2, 0, 0, -2} respectively. So there are 2 correct cases out of 4, so the probability of finishing at the correct position is 0.5. For the third sample, s2 could only lead us to finish at positions {+1, -1, -3}, so the probability to finish at the correct position  + 3 is 0.

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s2.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        unk == 0 -> println(if (pos1==pos2) 1.0 else 0.0)
        pos2+unk<pos1||pos2-unk>pos1-> println(0.0)
        else -> {
            val choose = (unk-abs(pos1-pos2))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
            //println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })
        }
    }
}

fun getAllFinalDestinations(receivedPath: String) = arrayListOf<Int>().apply {

    fun checkFinalDestination(currentPosition: Int, index: Int) {
        if (index == receivedPath.length) {
            add(currentPosition)
            return
        }
        when(receivedPath[index]) {
            '+' -> checkFinalDestination(currentPosition + 1, index + 1)
            '-' -> checkFinalDestination(currentPosition - 1, index + 1)
            '?' -> {
                checkFinalDestination(currentPosition + 1, index + 1)
                checkFinalDestination(currentPosition - 1, index + 1)
            }
        }
    }

    checkFinalDestination(0, 0)
}

fun main() = readLine()!!
    .map { ch -> if (ch == '+') 1 else -1 }
    .sum()
    .let { destination -> Pair(destination, readLine()!!) }
    .let { (destination, receivedPath) -> Pair(destination, receivedPath.run(::getAllFinalDestinations)) }
    .let { (destination, allFinalDestinations) ->
        allFinalDestinations.count(destination::equals).toDouble() / allFinalDestinations.size.toDouble()
    }
    .let { percentage -> "%.12f".format(percentage) }
    .run(::println)

import java.util.Scanner;

fun final_location(cmds : String) : Pair<Int, Int> {
    var loc = 0
    var num_unrecognized_cmds = 0
    for (cmd in cmds) {
        if (cmd == '+') {
            loc = loc + 1
        } else if (cmd == '-') {
            loc = loc - 1
        } else if (cmd == '?') {
            num_unrecognized_cmds = num_unrecognized_cmds + 1
        } else {
            throw Exception("Unknown input!")
        }
    }
    return Pair(loc, num_unrecognized_cmds)
}

fun factorial(x : Int) : Int {
    var f = 1;
    for (i in 1 .. x) {
        f = f * i
    }
    return f
}

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    val sent_command = scanner.next()
    val recognized_command = scanner.next()
    // println("sent_command : ${sent_command}")
    // println("recognized_command : ${recognized_command}")
    val (loc_sent_cmd, _) = final_location(sent_command)
    val (loc_recognized_cmd, num_unrecognized_cmds) = final_location(recognized_command)
    // println("loc_sent_cmd : ${loc_sent_cmd}")
    // println("loc_recognized_cmd : ${loc_recognized_cmd}")
    // println("num_unrecognized_cmds : ${num_unrecognized_cmds}")
    // p + m = num_unrecognized_cmds
    // p - m = loc_sent_cmd - loc_recognized_cmd
    val two_p = loc_sent_cmd - loc_recognized_cmd + num_unrecognized_cmds
    if ((two_p % 2) == 1) {
        println("0")
    } else {
        val p = two_p / 2
        val m = num_unrecognized_cmds - p
        if ((p >= 0) && (m >= 0)) {
            val f_s = factorial(num_unrecognized_cmds).toDouble()
            val f_p = factorial(p).toDouble()
            val f_m = factorial(m).toDouble()
            val two : Double = 2.0
            val result = (f_s / (f_p * f_m)) * (1.0 / Math.pow(two, num_unrecognized_cmds.toDouble()))
            println("${result}")
        } else {
            println("0")
        }
    }
}

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s2.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        unk == 0 -> println(1.0)
        abs(unk+pos2-pos1)%2==1 -> println(0.0)
        else -> {
            val choose = (unk-abs(pos1))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
        }
    }
}

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s2.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        unk == 0 -> println(1.0)
        pos2+unk<pos1||pos2-unk>pos1-> println(0.0)
        else -> {
            val choose = (unk-abs(pos1))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
        }
    }
}

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s1.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        abs(unk-pos1)%2==1 -> println(0.0)
        else -> {
            val choose = (unk-abs(pos1))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
            /*println((unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i })
            println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })
            println(unk)*/
        }
    }
}

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s2.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        unk == 0 -> println(if (pos1==pos2) 1.0 else 0.0)
        pos2+unk<pos1||pos2-unk>pos1-> println(0.0)
        else -> {
            val choose = (unk-abs(pos1))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
        }
    }
}

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s1.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        unk == 0 -> println(1.0)
        abs(unk+pos2-pos1)%2==1 -> println(0.0)
        else -> {
            val choose = (unk-abs(pos1))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
            /*println((unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i })
            println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })
            println(unk)*/
        }
    }
}

import kotlin.math.abs
import kotlin.math.pow

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!.toInt()
    //val (n, time) = r.readLine()!!.split(" ").map { it.toInt() }
    //val v = r.readLine()!!.split(" ").map { it.toInt() }
    val s1 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos1 = s1.count { it == "+" } * 2 - s1.size
    val s2 = r.readLine()!!.split("").filter { it.length > 0 }
    val pos2 = s2.count { it == "+" } - s1.count { it == "-" }
    val unk = s2.count { it == "?" }
    when{
        unk == 0 -> println(1.0)
        abs(unk-pos1)%2==1 -> println(0.0)
        else -> {
            val choose = (unk-abs(pos1))/2
            val ans = (unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i }/2.0.pow(unk)
            println(ans)
            /*println((unk-choose+1..unk).fold(1L){acc, i -> acc*i }/(1..choose).fold(1L){acc, i -> acc*i })
            println((unk-choose+1..unk).fold(1L){acc, i -> acc*i })
            println(unk)*/
        }
    }
}


Count the number of distinct sequences a1, a2, ..., an (1 ≤ ai) consisting of positive integers such that gcd(a1, a2, ..., an) = x and . As this number could be large, print the answer modulo 109 + 7.gcd here means the greatest common divisor.

The only line contains two positive integers x and y (1 ≤ x, y ≤ 109).

Print the number of such sequences modulo 109 + 7.

NoteThere are three suitable sequences in the first test: (3, 3, 3), (3, 6), (6, 3).There are no suitable sequences in the second test.

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val x = sc.nextLong()
    val y = sc.nextLong()

    println(solve(x, y))
}

val mod = (1e9 + 7).toLong()

val res = mutableMapOf<par, Long>()

data class par(val t: Long)

private fun solve(x: Long, y: Long): Long {
    if (y % x != 0L) return 0L
    if (y < x) return 0L

    val t = y / x
    if (res.containsKey(par(t))) return res[par(t)] ?: throw Exception()

    var sum = 2L pow (t - 1)

    if (x != y) sum = (sum - 1 + mod) % mod

    var i = 2L
    while (i * i <= t) {
        if (t % i == 0L) {
            sum = (sum - solve(i, t) + mod) % mod

            if (t / i != i) {
                sum = (sum - solve(t / i, t) + mod) % mod
            }
        }
        i += 1
    }

    res[par(t)] = sum
    return sum
}

private infix fun Long.pow(n: Long): Long {
    var a = this
    var n = n % (mod - 1)
    var res = 1L
    while (n > 0) {
        if (n % 2 == 1L) res = res * a % mod
        a = a * a % mod
        n /= 2
    }
    return res
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val x = sc.nextLong()
    val y = sc.nextLong()

    println(solve(x, y))
}

val mod = (1e9 + 7).toLong()

private fun solve(x: Long, y: Long): Long {
    if (y % x != 0L) return 0L

    val t = y / x

    var sum = 2L pow (t - 1)

    if (x != y) sum = (sum - 1 + mod) % mod

    var i = 2L
    while (i * i <= t) {
        if (t % i == 0L) sum = (sum - solve(i, t) + mod) % mod
        i += 1
    }

    return sum
}

private infix fun Long.pow(n: Long): Long {
    var a = this
    var n = n % (mod - 1)
    var res = 1L
    while (n > 0) {
        if (n % 2 == 1L) res = res * a % mod
        a = a * a % mod
        n /= 2
    }
    return res
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.StringTokenizer

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)

    val x = sc.nextLong()
    val y = sc.nextLong()

    println(solve(x, y))
}

val mod = (1e9 + 7).toLong()

private fun solve(x: Long, y: Long): Long {
    if (y % x != 0L) return 0L
    if( y < x) return 0L

    val t = y / x

    var sum = 2L pow (t - 1)

    if (x != y) sum = (sum - 1 + mod) % mod

    var i = 2L
    while (i * i <= t) {
        if (t % i == 0L) sum = (sum - solve(i, t) + mod) % mod
        i += 1
    }

    return sum
}

private infix fun Long.pow(n: Long): Long {
    var a = this
    var n = n % (mod - 1)
    var res = 1L
    while (n > 0) {
        if (n % 2 == 1L) res = res * a % mod
        a = a * a % mod
        n /= 2
    }
    return res
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}