Let's introduce some definitions that will be needed later.Let $$$prime(x)$$$ be the set of prime divisors of $$$x$$$. For example, $$$prime(140) = \{ 2, 5, 7 \}$$$, $$$prime(169) = \{ 13 \}$$$.Let $$$g(x, p)$$$ be the maximum possible integer $$$p^k$$$ where $$$k$$$ is an integer such that $$$x$$$ is divisible by $$$p^k$$$. For example:  $$$g(45, 3) = 9$$$ ($$$45$$$ is divisible by $$$3^2=9$$$ but not divisible by $$$3^3=27$$$),  $$$g(63, 7) = 7$$$ ($$$63$$$ is divisible by $$$7^1=7$$$ but not divisible by $$$7^2=49$$$). Let $$$f(x, y)$$$ be the product of $$$g(y, p)$$$ for all $$$p$$$ in $$$prime(x)$$$. For example:  $$$f(30, 70) = g(70, 2) \cdot g(70, 3) \cdot g(70, 5) = 2^1 \cdot 3^0 \cdot 5^1 = 10$$$,  $$$f(525, 63) = g(63, 3) \cdot g(63, 5) \cdot g(63, 7) = 3^2 \cdot 5^0 \cdot 7^1 = 63$$$. You have integers $$$x$$$ and $$$n$$$. Calculate $$$f(x, 1) \cdot f(x, 2) \cdot \ldots \cdot f(x, n) \bmod{(10^{9} + 7)}$$$.

The only line contains integers $$$x$$$ and $$$n$$$ ($$$2 \le x \le 10^{9}$$$, $$$1 \le n \le 10^{18}$$$) — the numbers used in formula.

NoteIn the first example, $$$f(10, 1) = g(1, 2) \cdot g(1, 5) = 1$$$, $$$f(10, 2) = g(2, 2) \cdot g(2, 5) = 2$$$.In the second example, actual value of formula is approximately $$$1.597 \cdot 10^{171}$$$. Make sure you print the answer modulo $$$(10^{9} + 7)$$$.In the third example, be careful about overflow issue.

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_007
fun factorize(a: Int): MutableMap<Int, Int> {
  val res = mutableMapOf<Int, Int>()
  var x = a
  loop@while(x > 1) {
    var i = 2
    while(i * i <= x) {
      if (x % i == 0) {
        res.merge(i, 1, Int::plus)
        x /= i
        continue@loop
      }
      i++
    }
    res.merge(x, 1, Int::plus)
    x = 0
  }
  return res
}
fun powMod(a: Int, n: Long, mod: Int): Long {
  if (n == 0L) return 1
  val res = powMod((a.toLong() * a % mod).toInt(), n / 2, mod)
  return if (n % 2 == 1L) res * a % mod else res
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val X = ni()
    val N = nl()

    val fs = factorize(X)
    var ans = 1L
    for ((p, _) in fs) {
      var n = N
      while(n >= p) {
        n /= p
        ans = ans * powMod(p, n, MOD) % MOD
      }
    }

    out.println(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<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()
}

import java.util.*
import kotlin.math.sqrt

const val mod = 1000000007L

fun main() {
    val s = Scanner(System.`in`)
    val x = s.nextLong()
    val n = s.nextLong()

    var ans = 1L
    val primes = getPrimes(x)
    primes.forEach {
        var itt = it
        var cnt = 0L
        while (true) {
            cnt += n / itt
            if (itt <= n / it) // 如果直接itt*=it再判断itt<=n会爆Long
                itt *= it
            else
                break
        }
        ans = ans * fpow(it, cnt) % mod
    }
    print(ans)
}

fun getPrimes(x: Long): Set<Long> {
    val primes = MutableList(0) { 0L }

    val sqrtx = sqrt(x.toDouble()).toLong() + 5
    var xx = x
    var i = 2L
    while (xx > 1) {
        if (xx % i == 0L)
            primes.add(i)
        while (xx % i == 0L)
            xx /= i
        if (++i > sqrtx)
            break
    }
    if (xx > 1)
        primes.add(xx)

    return primes.toSet()
}
fun fpow(x: Long, n: Long, m: Long = mod): Long {
    if (n == 0L)
        return 1
    var ans = 1L
    var xx = x % mod
    var nn = n
    while (nn > 1) {
        if (nn % 2 == 1L)
            ans = ans * xx % mod
        nn /= 2
        xx = xx * xx % mod
    }
    return ans * xx % mod
}

import java.io.PrintWriter
import java.util.StringTokenizer

fun main() {
    output {
        val x = readInt()
        val n = readLong()

        val primes = x.factorize().distinct().toList()

        var ans = ModInt(1)

        for(p in primes) {
            var k = 0L
            var nn = n
            while(nn > 0) {
                nn /= p
                k += nn
            }
            ans *= ModInt(p).pow(k)
        }

        println(ans)
    }
}

fun Int.factorize() = sequence {
    var n = this@factorize

    for(p in 2..Int.MAX_VALUE) {
        if(p * p > n) break
        while(n % p == 0) {
            yield(p)
            n /= p
        }
    }

    if(n > 1) yield(n)
}

const val BILLION7 = 1e9.toInt() + 7
const val MODINT_BASE = BILLION7

inline infix fun Int.umod(base: Int) = Math.floorMod(this, base)
inline infix fun Long.umod(base: Long) = Math.floorMod(this, base)
inline infix fun Long.umod(base: Int) = Math.floorMod(this, base.toLong()).toInt()

fun Int.mulMod(other: Int, mod: Int) = (toLong() * other).umod(mod)

fun Int.powMod(exponent: Int, mod: Int): Int {
    var res = 1L
    var e = exponent
    var b = umod(mod).toLong()

    while(e > 0) {
        if(e and 1 == 1) {
            res = res * b % mod
        }
        e = e shr 1
        b = b * b % mod
    }
    return res.toInt()
}

inline fun Int.toModInt() = ModInt(this umod MODINT_BASE)
inline fun Long.toModInt() = ModInt(this umod MODINT_BASE)

/** note: Only use constructor for int within modulo range, otherwise use toModInt **/
inline class ModInt(val int: Int) {
    companion object {
        /** can't seem to make these private or inlined without causing compiler issues */
        @JvmField val _invMemo = HashMap<ModInt, ModInt>()
        fun _invMemoized(m: ModInt) = _invMemo.getOrPut(m) { m.inv_unmemoized() }
    }

    inline operator fun plus(other: ModInt) = plus(other.int) // MODINT_BASE < 2^30
    inline operator fun plus(other: Int) =  (int + other).toModInt() // careful of possible overflow
    inline operator fun inc() = plus(1)

    inline operator fun minus(other: ModInt) = minus(other.int)
    inline operator fun minus(other: Int) = (int - other).toModInt()
    inline operator fun dec() = minus(1)
    operator fun unaryMinus() = if(int == 0) this else ModInt(MODINT_BASE - int)

    inline operator fun times(other: ModInt) = times(other.int)
    inline operator fun times(other: Int) = ModInt(int.mulMod(other, MODINT_BASE))

    fun pow(exponent: Int): ModInt {
        val e = if(exponent < 0) exponent umod MODINT_BASE - 1 else exponent // assumes MODINT_BASE is prime
        return ModInt(int.powMod(e, MODINT_BASE))
    }

    fun pow(exponent: Long) = pow(exponent umod MODINT_BASE - 1) // assumes MODINT_BASE is prime

    inline fun inverse() = inv_memoized() /** NOTE: Change if necessary */

    fun inv_unmemoized(): ModInt {
        require(int != 0) { "Can't invert/divide by 0" }
        return pow(MODINT_BASE - 2) // assumes MODINT_BASE is prime
    }
    inline fun inv_memoized() = _invMemoized(this)

    operator fun div(other: ModInt) = times(other.inverse())
    inline operator fun div(other: Int) = div(other.toModInt())

    override fun toString() = int.toString()
}

inline class ModIntArray(val intArray: IntArray): Collection<ModInt> {
    inline operator fun get(i: Int) = ModInt(intArray[i])
    inline operator fun set(i: Int, v: ModInt) { intArray[i] = v.int }

    override val size: Int get() = intArray.size
    inline val lastIndex get() = intArray.lastIndex

    override fun contains(element: ModInt): Boolean = any { it == element }

    override fun containsAll(elements: Collection<ModInt>): Boolean = elements.all(::contains)

    override fun isEmpty(): Boolean = intArray.isEmpty()

    override fun iterator(): Iterator<ModInt> = object: Iterator<ModInt> {
        var index = 0
        override fun hasNext(): Boolean = index < size
        override fun next(): ModInt = get(index++)
    }
}
fun ModIntArray(capacity: Int) = ModIntArray(IntArray(capacity))
inline fun ModIntArray(capacity: Int, init: (Int) -> ModInt) =
    ModIntArray(IntArray(capacity) { init(it).int })

/** IO code start */
@JvmField val _reader = System.`in`.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }

@JvmField val _writer = PrintWriter(System.out, false)
inline fun output(block: PrintWriter.()->Unit) { _writer.apply(block).flush() }
fun iprintln(o: Any?) { println(o) } // immediate println for interactive, bypasses output{} blocks

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    fun isPrime(k: Int): Boolean {
        if (k == 1) return false
        if (k == 2 || k == 3) return true
        for (i in 2..sqrt(k.toDouble()).toInt()) {
            if (k % i == 0) {
                return false
            }
        }
        return true

    }

    for (i in 2..sqrt(x.toDouble()).toInt()) {
        if (x % i == 0) {
            if (isPrime(i) && !primes.contains(x / i))
                primes += i
            if (isPrime(x / i) && !primes.contains(x / i))
                primes += x / i
        }
    }
    if (isPrime(x)) primes += x

    //primes.forEach { println(it) }

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        var curP = p.toLong()
        while (n / curP > 0) {
            //println(curP)
            ans = (ans * power(p.toLong(), n / curP)) % mod
            if ((curP * p) / p != curP) break
            curP *= p
        }
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

import java.util.*
import kotlin.collections.HashSet
import kotlin.math.max

fun readInts() = readLine()!!.split(" ").map { it.toInt() }
fun readLongs() = readLine()!!.split(" ").map { it.toLong() }
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readLenAndInts() = readLine()!!.split(" ").drop(1).map { it.toInt() }

fun divisors(xx : Int) : List<Int> {
    var x = xx
    val res = mutableListOf<Int>()
    fun tryDiv(div : Int) {
        if (x % div == 0) {
            res.add(div)
            do {
                x /= div
            } while (x % div == 0)
        }
    }
    tryDiv(2)
    var div = 3
    while(div * div <= x) {
        tryDiv(div)
        div += 2
    }
    if (x != 1) {
        res.add(x)
    }
    return res
}

val mod = 1000000007L
fun fastExp(a : Long, b : Long) : Long {
    //(a ^ b) % mod
    var res = 1L
    var x   = a
    var e   = b
    while(e > 0) {
        if (e % 2L == 1L) {
            res *= x
            res %= mod
        }
        x *= x
        x %= mod
        e /= 2
    }
    return res
}

fun main() {
    var (x,n) = readLongs()
    var res = 1L
    for(div in divisors(x.toInt())) {
        var times = 0L
        var nn = n
        while (nn > 0) {
            nn /= div
            times += nn
        }
        res *= fastExp(div.toLong(),times)
        res %= mod
    }
    println(res)
}

import kotlin.math.sqrt

fun main() {
    val (x, n) = readLongs()
    val primes = primes(x.toInt())
    var result = 1L
    for (prime in primes) {
        var num = n
        var count = 0L
        while (num >= prime) {
            count += num / prime
            num /= prime
        }
        result = (result * pow(prime.toLong(), count)) % 1000000007
    }
    println(result)
}

fun primes(x: Int): IntArray {
    var num = x
    val result = mutableListOf<Int>()
    for (i in 2..sqrt(x.toDouble()).toInt()) {
        if (num % i == 0) {
            result.add(i)
            num /= i
            while (num % i == 0) {
                num /= i
            }
        }
    }
    if (num != 1) {
        result.add(num)
    }
    return result.toIntArray()
}

fun pow(x: Long, n: Long): Long {
    var num = x
    var count = n
    var result = 1L
    while (count > 0) {
        if (count and 1L == 1L) {
            result = (result * num) % 1000000007
        }
        num = (num * num) % 1000000007
        count = count shr 1
    }
    return result
}

private fun readString() = readLine()!!

private fun readInt() = readString().toInt()

private fun readInts() = readString().split(" ").map { it.toInt() }

private fun readLong() = readString().toLong()

private fun readLongs() = readString().split(" ").map { it.toLong() }

import java.util.*
import kotlin.math.sqrt

const val mod = 1000000007L

fun main() {
    val s = Scanner(System.`in`)
    val x = s.nextLong()
    val n = s.nextLong()

    var ans = 1L
    val primes = getPrimes(x)
    primes.forEach {
        var itt = it
        var cnt = 0L
        while (true) {
            cnt += n / itt
            if (itt <= n / it) // 如果直接itt*=it再判断itt<=n会爆Long
                itt *= it
            else
                break
        }
        ans = ans * fpow(it, cnt) % mod
    }
    print(ans)
}

fun getPrimes(x: Long): Set<Long> {
    val primes = MutableList(0) { 0L }

    val sqrtx = sqrt(x.toDouble()).toLong()
    var xx = x
    var i = 2L
    while (xx in 2..sqrtx + 10) {
        if (xx % i == 0L)
            primes.add(i)
        while (xx % i == 0L)
            xx /= i
        i++
    }
    if (xx > 1)
        primes.add(xx)

    return primes.toSet()
}
fun fpow(x: Long, n: Long, m: Long = mod): Long {
    if (n == 0L)
        return 1
    var ans = 1L
    var xx = x % mod
    var nn = n
    while (nn > 1) {
        if (nn % 2 == 1L)
            ans = ans * xx % mod
        nn /= 2
        xx = xx * xx % mod
    }
    return ans * xx % mod
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    for (i in 2..sqrt(x.toDouble()).toInt() + 10) {
        if (x % i == 0) {
            var isPrime = true
            primes.forEach { if (i % it == 0) isPrime = false }
            if (isPrime)
                primes += i
        }
    }
    if (primes.isEmpty()) primes += x

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        //println(p)
        var num = 0L
        var curP = p.toLong()
        while (n / curP > 0) {
            //println(curP)
            num += n / curP
            if (curP * p / p != curP) break
            curP *= p
        }
        ans = ans * power(p.toLong(), num) % 1000000007
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    for (i in 2..sqrt(x.toDouble()).toInt() + 1) {
        if (x % i == 0) {
            var isPrime = true
            primes.forEach { if (i % it == 0) isPrime = false }
            if (isPrime)
                primes += i
        }
    }
    if (primes.isEmpty()) primes += x

    //primes.forEach { println(it) }

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        var curP = p.toLong()
        while (n / curP > 0) {
            ans = (ans * power(p.toLong(), n / curP)) % mod
            if ((curP * p) / p != curP) break
            curP *= p
        }
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    for (i in 2..sqrt(x.toDouble()).toInt() + 10) {
        if (x % i == 0) {
            var isPrime = true
            primes.forEach { if (i % it == 0) isPrime = false }
            if (isPrime)
                primes += i
        }
    }
    if (primes.isEmpty()) primes += x

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        //println(p)
        var num = 0L
        var curP = p.toLong()
        while (n / curP > 0) {
            println(curP)
            num += n / curP
            if (curP * p / p != curP) break
            curP *= p
        }
        ans = ans * power(p.toLong(), num) % 1000000007
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    fun isPrime(k: Int): Boolean {
        if (k == 1) return false
        if (k == 2 || k == 3) return true
        for (i in 2..sqrt(k.toDouble()).toInt() + 1) {
            if (k % i == 0) {
                return false
            }
        }
        return true

    }

    for (i in 2..sqrt(x.toDouble()).toInt() + 1) {
        if (x % i == 0) {
            if (isPrime(i))
                primes += i
            if (isPrime(x / i))
                primes += x / i
        }
    }
    //if (isPrime(x)) primes += x

    primes.forEach { println(it) }

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        var curP = p.toLong()
        while (n / curP > 0) {
            //println(curP)
            ans = (ans * power(p.toLong(), n / curP)) % mod
            if ((curP * p) / p != curP) break
            curP *= p
        }
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    fun isPrime(k: Int): Boolean {
        if (k == 1) return false
        if (k == 2 || k == 3) return true
        for (i in 2..sqrt(k.toDouble()).toInt() + 1) {
            if (k % i == 0) {
                return false
            }
        }
        return true

    }

    for (i in 2..sqrt(x.toDouble()).toInt() + 1) {
        if (x % i == 0) {
            if (isPrime(i))
                primes += i
            if (isPrime(x / i))
                primes += x / i
        }
    }
    if (isPrime(x)) primes += x

    //primes.forEach { println(it) }

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        var curP = p.toLong()
        while (n / curP > 0) {
            //println(curP)
            ans = (ans * power(p.toLong(), n / curP)) % mod
            if ((curP * p) / p != curP) break
            curP *= p
        }
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.sqrt

fun main() {
    val sc = Scanner.sysIn

    val x = sc.nextInt()
    val n = sc.nextLong()

    val primes = ArrayList<Int>()

    for (i in 2..sqrt(x.toDouble()).toInt() + 10) {
        if (x % i == 0) {
            var isPrime = true
            primes.forEach { if (i % it == 0) isPrime = false }
            if (isPrime)
                primes += i
        }
    }
    if (primes.isEmpty()) primes += x

    val mod = 1000000007
    fun power(x: Long, p: Long): Long = when {
        p == 0L -> 1
        p == 1L -> x % mod
        p % 2 == 0L -> {
            val cur = power(x, p / 2)
            (cur * cur) % mod
        }
        else -> (power(x, p - 1) * x) % mod
    }

    var ans = 1L

    for (p in primes) {
        //println(p)
        var curP = p.toLong()
        while (n / curP > 0) {
            //println(curP)
            ans = ans * power(p.toLong(), n / curP) % 1000000007
            if (curP * p / p != curP) break
            curP *= p
        }
    }

    println(ans)
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    val br: BufferedReader = BufferedReader(InputStreamReader(s))

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

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

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

    fun nextLine(): String {
        return br.readLine()
    }

    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }

    companion object {
        val sysIn = Scanner(System.`in`)
    }

}

val rnd = Random()
fun IntArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}

fun LongArray.sort() {
    val n = this.size
    for (i in 0 until n - 1) {
        val randomPos = i + rnd.nextInt(n - i - 1) + 1
        this[i] = this[i] xor this[randomPos]
        this[randomPos] = this[randomPos] xor this[i]
        this[i] = this[i] xor this[randomPos]
    }
    Arrays.sort(this)
}


A word or a sentence in some language is called a pangram if all the characters of the alphabet of this language appear in it at least once. Pangrams are often used to demonstrate fonts in printing or test the output devices.You are given a string consisting of lowercase and uppercase Latin letters. Check whether this string is a pangram. We say that the string contains a letter of the Latin alphabet if this letter occurs in the string in uppercase or lowercase.

The first line contains a single integer n (1 ≤ n ≤ 100) — the number of characters in the string. The second line contains the string. The string consists only of uppercase and lowercase Latin letters.

Output "YES", if the string is a pangram and "NO" otherwise.

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readDouble() = readLn().toDouble()
fun readLong() = readLn().toLong()
fun readStrings() = readLn().split(' ')
fun readInts() = readStrings().map { it.toInt() }
fun readDoubles() = readStrings().map { it.toDouble() }
fun readLongs() = readStrings().map { it.toLong() }

fun main(args: Array<String>) {
    val n = readInt()
    val s = readLn()

    for (ch in 'a'..'z') {
        if (!s.contains(ch) && !s.contains(ch.toUpperCase())) {
            println("NO")
            return
        }
    }

    println("YES")
}

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

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    var tok = StringTokenizer("")

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

    fun readToken(): String {
        while (!tok.hasMoreTokens()) {
            tok = StringTokenizer(rd.readLine())
        }
        return tok.nextToken()
    }

    fun readInt(): Int = readToken().toInt()
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun close() {
        rd.close()
        wr.close()
    }
}

fun solve() {
    val io = ProblemIO.console()
    val n = io.readInt()
    val t = io.readToken()
    val res = (t.toLowerCase().toSet().size == 26)
    io.println(if (res) "YES" else "NO  ")
    io.close()
}

fun main(args: Array<String>) {
    Thread({ solve() }).start()
}

fun main()
{
    val lens = readLine()!!.toInt()
    val given = readLine()!!
    var c = 'A'
    var answer = "YES"
    while (c <= 'Z')
    {
        if (given.contains(c))
        {
            ++c
            continue
        }
        else if (given.contains(c.toLowerCase()))
        {
            ++c
            continue
        }
        else
        {
            answer = "NO"
            break
        }
    }
    println(answer)
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!
    val diff = r.readLine()!!.toLowerCase().split("").groupBy { it }.size
    println(if (diff==27) "YES" else "NO")
}

fun main(args: Array<String>) {
    var n =  readLine()!!.toInt()
    var s = readLine()!!
    var c = 0
    s = s.toUpperCase()
    for (i in 'A'..'Z'){
        if (s.contains(i)){
            c++
        }
    }
    if (c >= 26){
        print("YES")
    }
    else
        print("NO")
}

import java.util.*

fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    val q = scanner.nextInt()
    var line = scanner.next().toLowerCase()

    var set = mutableSetOf<Char>()

    (0 until q).forEach { set.add(line[it]) }

    if (set.size == 26) println("YES")
    else println("NO")

}

import java.util.Scanner;
import java.util.Arrays;
import java.util.*;
import java.math.*;
import java.io.*;

fun main(args: Array<String>) {
var s = Scanner(System.`in`)
var numberofletters = s.nextInt()
var sentence = s.next()
var res = sentence.toLowerCase();
var charSentence = res.toCharArray()
Arrays.sort(charSentence)
var pangram = 0
var start = 97
for(i in 0 until numberofletters){
val charSentenceAsInt = charSentence[i].toInt()
if(charSentenceAsInt==start){
pangram++
start++
}
}
if(pangram == 26){
print("YES")
}else{
print("NO")
}

}

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

fun main() {
    val scan = Scanner(System.`in`)
    val size = scan.nextInt()
    val list:Iterable<Char> = scan.next().asIterable()
    pangram(list)
}

//  http://codeforces.com/contest/520/problem/A
fun pangram(list: Iterable<Char>) {
    val set = mutableSetOf<Char>()
    for (c in list) {
        set.add(c.toLowerCase())
    }
    val result = if (set.size == 26) "YES" else "NO"
    println(result)
}

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

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val input = InputReader(inputStream)
    val output = PrintWriter(outputStream)
    val solver = Task()
    solver.solve(input, output)
    output.close()
}

private class Task {
    fun solve(input: InputReader, output: PrintWriter) {
        input.nextInt()

        ('a'..'z').toSet().let { set ->
            val s = input.next().toLowerCase()
            output.println(if (set.all { s.contains(it) }) "YES" else "NO")
        }
    }
}

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

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

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return next().toInt()
    }

}

fun main(){
    readLine()
    var set = readLine()!!.toString().toLowerCase().toCharArray().toSet()
    println( if(set.size == 26) "YES\n" else "NO")
}

fun main(args: Array<String>) {
    val n = readInt()
    val s = readLine()!!.toLowerCase().toCharArray().toSet().size
    println(if (s == 26) "YES" else "NO")
}

private fun readInt() = readLine()!!.toInt()

import java.util.*
fun main(args: Array<String>) {
    var sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val s = sc.next().toLowerCase()
    if (n < 26) println("NO")
    else {
        var count = IntArray(26)
        for ( i in 0 .. n-1){
            count[s[i].toInt()- 'a'.toInt()]++
        }
        var test = true
        for (i in 0 .. 25){
            if (count[i] == 0 ){
                test= false
                break
            }
        }
        println(if (test) "YES" else "NO")
    }
}

 fun main(args: Array<String>) {
      readLine()
    var s=readLine()!!.toLowerCase().toSet()
        if(s.size==26)
        print("YES")
        else
        print("NO")

    }

import java.util.*

fun main(args: Array<String>) {
    val alphabet = ('a'..'z').toList().toCharArray()

    val sc = Scanner(System.`in`)
    sc.nextLine()
    val line = sc.nextLine()

    println(if(pangram(line, alphabet)) "YES" else "NO")
}

fun pangram(line: String, alphabet: CharArray): Boolean {
    if (line.length < alphabet.size) {
        return false
    }

    val lowercase = line.toLowerCase()
    return alphabet.filter { it !in lowercase }.isEmpty()
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val s = br.readLine().toLowerCase()
    println(
        if (s.toSet().size == 26) "YES" else "NO"
    )
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    if(n < 26) {
        println("NO")
    } else {
        val word = readLine()!!.toLowerCase().toSortedSet()
        if(word.size >= 26) println("YES")
        else println("NO")
    }
}

fun main(args: Array<String>) {
    val length = Integer.parseInt(readLine().toString())
    val sentence = readLine().toString().toLowerCase()
    if(isPangram(length,sentence)){
        println("YES")
    }
    else{
        println("NO")
    }
}
fun isPangram(inter:Int,input:String):Boolean {
        for (a in 'a'..'z'){
            val isChar: (Char) -> Boolean = {it == a}
            if(!input.any(predicate = isChar )) {
                return false }
            }
        return true
    }

fun main(args: Array<String>) {
    readLine()
    val s = readLine()!!.toLowerCase()
    println(if (('a'..'z').all { s.contains(it) }) "YES" else "NO")
}

import java.util.*

fun main(){

    val scan = Scanner(System.`in`)

    val n = scan.nextInt()
    val arr = Array<Boolean>(26){ _ -> false}
    var c = 0
    val line = scan.next().toUpperCase()

    if (n<26){
        print("NO")
        return
    }
    for (i in line){
        val tmp = i.toInt()
        arr[tmp-65] = true
    }

    for (i in arr) if (i) c++

    if (c == 26) print("YES")
    else print("NO")
}

fun main() {
    readLine()!!
    if (readLine()!!.asSequence().map { it.toLowerCase() }.toSet().size == 26)
        println("YES")
    else
        println("NO")
}

import java.lang.AssertionError
import java.util.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

private fun myAssert(x: Boolean) {
    if (!x) {
        throw AssertionError()
    }
}

fun main(args: Array<String>) {
//  var s = Scanner(System.`in`)
  var n = readInt()
  var s = readLn().toLowerCase()
  var ss = mutableSetOf<Char>()
  for (i in 0..n - 1) {
    ss.add(s[i])
  }
  if (ss.size < 26) {
    println("NO")
  } else {
    println("YES")
  }
}

import java.util.*
import kotlin.collections.HashMap

//author:Ismail moussi
fun main()
{
    val scan=Scanner(System.`in`)
    val n:Int=scan.nextInt()
    var s:String=scan.next()
    var map=HashMap<Char,Int>()
    if(s.length<26)
        print("NO")
    else {

       var ss= s.toUpperCase()
        for (i in 0 until s.length) {
            map.put(ss.get(i), 0)
        }
//     if(map.size<26)
//         println("NO")else println("YES")
        when(map.size)
        {
          in 1..25-> print("NO")
            else -> print("YES")
        }
    }
}

fun main() {
    readLine()
    val s = readLine()!!
    val chars = mutableSetOf<Char>()
    for (c in s) chars.add(c.toLowerCase())
    print(if (chars.size == 26) "YES" else "NO")
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.*
import kotlin.system.measureTimeMillis

fun getMinimumAmountOfChangeFrom(amount: Int): Int {
    val changes = listOf(10, 5, 1)
    var availableAmount = amount
    var numOfCoins = 0
    for (change in changes) {
        while (availableAmount > 0 && availableAmount / change.toDouble() >= 1) {
            numOfCoins += 1
            availableAmount -= change
        }
    }
    return numOfCoins
}

fun getMaximumValueOfTheLootWith(
    W: Int,
    valuePerUnitAndWeight: List<Pair<Double, Int>>
): Double {
    var maximumLootValue = 0.0
    var availableWeight = W
    for (pair in valuePerUnitAndWeight) {
        var availableWeightOfLootItem = pair.second
        while (availableWeight > 0 && availableWeightOfLootItem > 0) {
            maximumLootValue += pair.first
            availableWeightOfLootItem -= 1
            availableWeight -= 1
        }
    }
    return maximumLootValue
}

fun getMinimumNumOfRefills(d: Int, m: Int, stops: List<Int>): Int {
    var availableDistance = d
    var minimumRefills = 0
    var currentRefill = 0
    var lastRefill = 0
    val realStops = listOf<Int>(0, *stops.toTypedArray(), d)
    while (availableDistance > 0 && currentRefill < realStops.size) {
        var movedForward = false
        while (currentRefill < realStops.size && (realStops[currentRefill] - realStops[lastRefill]) <= m) {
            if (realStops[currentRefill] - realStops[lastRefill] == 0) {
                movedForward = false
                currentRefill++
            } else {
                movedForward = true
                currentRefill++
            }
        }
        if (movedForward) {
            minimumRefills++
            currentRefill--
            availableDistance -= (realStops[currentRefill] - realStops[lastRefill])
            lastRefill = currentRefill
        } else {
            return -1
        }
    }
    return minimumRefills - 1
}

fun getMaximizedSumOfProduct(profitPerClick: List<Int>, averageNumberOfClicks: List<Int>): Long {
    var sum = 0L
    println(profitPerClick.toString())
    println(averageNumberOfClicks.toString())
    profitPerClick.forEachIndexed { index, profit ->
        sum += profit * averageNumberOfClicks[index]
    }
    return sum
}

fun getCommon(first: Int, last: Int, segments: MutableList<Pair<Int, Int>>): String {
    var current = first
    val common = mutableListOf<Pair<Int, Int>>()
    while (current <= last) {
        var numOfTimes = 0
        for (pair in segments) {
            if (current in pair.first..pair.second) {
                numOfTimes++
            }
        }
        if (numOfTimes > 1) {
            common.add(Pair(current, numOfTimes))
        }
        current++
    }
    common.sortByDescending { it -> it.second }
    if (common.first().second == segments.size) {
        return "1\n${common.first().first}"
    }
    println(common)
    return "${common.size}\n${common.map { it.first }.joinToString(" ")}"
}

fun getMaximumSetOfPrizes(n: Int): String {
    var numbersOfN = ""
    var sumSoFar = 0
    if (n <= 2) {
        return "1\n$n"
    }
//    println("2*square root of n = ${2 * sqrt(n.toDouble())}")
//    for (i in 1..(2 * sqrt(n.toDouble()).toInt())){
//        if (i+sumSoFar<=n){
//            numbersOfN+="$i "
//            sumSoFar+=i
//        }
//    }
//    var lastNumber = 1
    var currentNumber = 1
    while (((currentNumber + 1) + currentNumber) <= n - sumSoFar) {
        sumSoFar += currentNumber
        numbersOfN += "$currentNumber "
        currentNumber++
    }
    if (((n - currentNumber) + sumSoFar) == n || n - sumSoFar > 0) {
        currentNumber = n - sumSoFar
        sumSoFar += currentNumber
        numbersOfN += "$currentNumber "
    }
//    else if (n-sumSoFar>0){
//        currentNumber = n-sumSoFar
//        numbersOfN += "$currentNumber "
//    }
    return "${numbersOfN.trim().split(" ").size}\n$numbersOfN"
}

fun linelandMail(coordinates: List<Long>): String {
    val mins = mutableListOf<Long>()
    val maxs = mutableListOf<Long>()
    for (i in coordinates.indices) {
        if (i == 0) {
            mins.add(abs(coordinates[i] - coordinates[i + 1]))
            maxs.add(abs(coordinates[i] - coordinates[coordinates.size - 1]))
        } else if (i == coordinates.size - 1) {
            mins.add(abs(coordinates[i] - coordinates[i - 1]))
            maxs.add(abs(coordinates[i] - coordinates[0]))
        } else {
            if (abs(coordinates[i] - coordinates[i - 1])
                > abs(coordinates[i] - coordinates[i + 1])
            )
                mins.add(abs(coordinates[i] - coordinates[i + 1]))
            else
                mins.add(abs(coordinates[i] - coordinates[i - 1]))

            if (abs(coordinates[i] - coordinates[0])
                < abs(coordinates[i] - coordinates[coordinates.size - 1])
            )
                maxs.add(abs(coordinates[i] - coordinates[coordinates.size - 1]))
            else
                maxs.add(abs(coordinates[i] - coordinates[0]))
        }
    }
    return mins
        .zip(maxs)
        .map { pair -> "${pair.first} ${pair.second}" }
        .joinToString("\n")
}

fun snacktower(snacksWeights: List<Int>) {
    val n = snacksWeights.size
    var currentMax = n
    var current = 0
    var processed = mutableListOf<Int>()
    while (current < snacksWeights.size) {
        if (snacksWeights[current] < currentMax) {
            processed.add(snacksWeights[current])
            print("\n")
            current++
        } else {
            if (snacksWeights[current] == currentMax) {
                print(currentMax)
                currentMax--
                var currentProcessed = 0
                while (currentProcessed < processed.size) {
                    var foundConsecutive = false
                    if (processed[currentProcessed] == currentMax) {
                        print(" ")
                        print(processed[currentProcessed])
                        currentMax--
                        foundConsecutive = true
                        processed = processed.swap(currentProcessed, processed.size - 1).toMutableList()
                        processed.removeAt(processed.size - 1)
                    }
                    if (!foundConsecutive) {
                        currentProcessed++
                    } else {
                        currentProcessed = 0
                    }
                }
                println()
                current++
            }
        }
    }
}

fun <T> List<T>.swap(a: Int, b: Int): List<T> = this
    .toMutableList()
    .also {
        it[a] = this[b]
        it[b] = this[a]
    }

fun `Oath of the Night's Watch`(stewardsStrengths: List<Int>) {
    val sortedStrengths = stewardsStrengths.sorted()
    var numberOfThoseWhoNeedSupport = 0
    for (strengthIndex in sortedStrengths.indices) {
        val precedingSteward = strengthIndex - 1
        val nextSteward = strengthIndex + 1
        if (precedingSteward>=0 && nextSteward<sortedStrengths.size){
            if (sortedStrengths[precedingSteward]<sortedStrengths[strengthIndex]
                && sortedStrengths[nextSteward]>sortedStrengths[strengthIndex]){
                numberOfThoseWhoNeedSupport++
            }
        }
    }
    println(numberOfThoseWhoNeedSupport)
}

fun pangram(characters: String){
    print(if (characters.toLowerCase().toSet().size==26) "YES" else "NO")
}

fun main() {

//    val scanner = Scanner(System.`in`)
//    val n = scanner.nextInt()
//    val snacksWeights = MutableList<Int>(n) { index -> 0 }
//    for (i in 0 until n) {
//        snacksWeights[i] = scanner.nextInt()
//    }
//    snacktower(snacksWeights)
//    val scanner = Scanner(System.`in`)
//    val n = scanner.nextInt()
//    val strengths = MutableList<Int>(n) { index -> 0 }
//    for (i in 0 until n) {
//        strengths[i] = scanner.nextInt()
//    }
//    `Oath of the Night's Watch`(strengths)
    val n = readLine()!!.toInt()
    val characters = readLine()!!
    pangram(characters)
}

// start of stress test
//    while (true) {
//        val n = Random.nextLong(1000000)
//        val m = Random.nextLong(100000)
//        if (m<n){
//            val res1 = getFibonacciPartialSumNaive(m,n)
//            val res2 = getLastDigitOfSumOfSubsetOfFibs(m,n)
//            if (res1.toInt() == res2) {
//                println("Ok")
//            } else {
//                println("Wrong Answer at n = $n and m = $m")
//                print("$res1 $res2")
//                break
//            }
//        }
//
//    }

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val s = readLine()!!
    val arr = Array<Int>(26, {i -> 0})
    for (c in s) {
        if ('a' <= c && c <= 'z') {
            arr[c-'a'] = 1
        } else if ('A' <= c && c <= 'Z') {
            arr[c-'A'] = 1
        }
    }
    if (arr.all{it == 1})
        print("YES\n")
    else
        print("NO\n")
}

fun main(args: Array<String>) {
    readLine()
    println(if (readLine()!!.toLowerCase().toSet().size >= 26) "YES" else "NO")
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

val charRange = 'a'..'z'

fun main() {
    readLn()
    val sentence = readLn()

    if(sentence.map { it.toLowerCase() }.containsAll(charRange.toList())) println("YES") else println("NO")
}

fun main(args: Array<String>) {
    readLine() !!
    val count = readLine()!!.toLowerCase().toSet().size
    println(if (count == 26) "YES" else "NO")
}

import java.util.*

fun min(a:Double,b:Double) = if (a<b) a else b
fun max(a:Double,b:Double) = if (a>b) a else b
fun min(a:Long,b:Long) = if (a<b) a else b
fun max(a:Long,b:Long) = if (a>b) a else b

fun readLn():String = readLine()!!.toString()
fun readLong() = readLn().toLong()
fun readLongs()  = readLn().split(" ").map{it.toLong()}
var nul=0.toLong();
var one=1.toLong();
var two=2.toLong();
var three=3.toLong();
var four=4.toLong();
var five=5.toLong();
fun powmod(a:Long,b:Long,mod:Long):Long {

    if (b==1.toLong()) return a;
    var k=powmod(a,b/2,mod);
    if (b%2==0.toLong())
    { return (k*k)%mod }
    else { k=k*k; k=k%mod; k=k*a; k=k%mod; return k; }
}
fun prime (p:Long):Long {
    if (p==one) return 0.toLong();
    var i=two;
    while (i*i<=p) {if (p%i==nul) return i; i++; }
    return one;
}
fun inv (a:Long,mod:Long):Long {
return powmod(a,mod-2,mod);
}

fun solve() {
    val cin = Scanner(System.`in`)

    /*
    var map=hashMapOf<String,Int>();
    map[q] <=> map.getOrDefault(q,0)
    Сортировка вектора пар - k=v.sortedWith(compareBy({it.first},{it.second}));
    prLong("${k[i].second}"); - вывод аргумента пары
    var m=ArrayList<Long> (); <=> vector
    getline(cin,a) <=> readLine()!!.last()
   readLong() - одно число
   readLongs() - несколько чисел
   readLine()!!.toCharArray() - возвращает массив чаров из строки

    */
    /* --------- */
        // ВСЕГДА ПИСАТЬ В ЛОНГАХ
    var a=readLong();
    var s=readLine()!!;

    var mem=mutableSetOf<Char>();
    for (c in s) {var pog=c; if (c>='A' && c<='Z') { var code=pog.toInt(); code-='A'.toInt(); code+='a'.toInt(); pog=code.toChar(); }
        mem.add(pog); }
    if (mem.size>=26) print("YES"); else print("NO");

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

}

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

    var T=one;
    //T=readLine()!!.toLong();
    for (i55555 in 1..T) solve()
}

fun main(args: Array<String>) {

    var n = readLine()!!.toInt()
    var str = readLine()!!.toLowerCase()
    var ok = 0
    for(i in 'a'..'z')if(str.contains(i)) ok++
    if(ok == 26)print("YES")
    else print("NO")
}

 fun main(args: Array<String>) {

    var s=readLine()!!.toLowerCase().toSet()
        if(s.size==26)
        print("YES")
        else
        print("NO")

    }

import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
//author:Ismail moussi
fun main()
{
    val scan=Scanner(System.`in`)
    val n:Int=scan.nextInt()
    var s:String=scan.next()
    var map=HashMap<Char,Int>()
    if(s.length<26)
    {
        print("NO")
        return
    }
    else
    {
        s.toLowerCase()
        for(i in 0 until s.length)
        {
            map.put(s.get(i),0)
        }
    }
    if(map.size<26)
        print("NO")else
        print("YES")
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
//author:Ismail moussi
fun main()
{
    val scan=Scanner(System.`in`)
    val n:Int=scan.nextInt()
    var s:String=scan.next()
    var map=HashMap<Char,Int>()
    if(s.length<26)
    {
        print("NO")
        return
    }
    else
    {
        s.toLowerCase()
        for(i in 0 until s.length)
        {
            map.put(s.get(i),0)
        }
    }
    if(map.size==26)
        print("YES")else
        print("NO")
}

import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
//author:Ismail moussi
fun main()
{
    val scan=Scanner(System.`in`)
    val n:Int=scan.nextInt()
    var s:String=scan.next()
    var map=HashMap<Char,Int>()
    if(s.length<26)
        print("NO")
    else {
        s.toLowerCase()
        for (i in 0 until s.length) {
            map.put(s.get(i), 0)
        }

        when(map.size)
        {
          in 0..25-> print("NO")
            else -> print("YES")
        }

//        if (map.size == 26)
//            print("YES") else
//            print("NO")
    }
}


Tavak and Seyyed are good friends. Seyyed is very funny and he told Tavak to solve the following problem instead of longest-path.You are given l and r. For all integers from l to r, inclusive, we wrote down all of their integer divisors except 1. Find the integer that we wrote down the maximum number of times.Solve the problem to show that it's not a NP problem.

The first line contains two integers l and r (2 ≤ l ≤ r ≤ 109).

Print single integer, the integer that appears maximum number of times in the divisors.  If there are multiple answers, print any of them.

NoteDefinition of a divisor: https://www.mathsisfun.com/definitions/divisor-of-an-integer-.htmlThe first example: from 19 to 29 these numbers are divisible by 2: {20, 22, 24, 26, 28}.The second example: from 3 to 6 these numbers are divisible by 3: {3, 6}.

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val n = r.readLine()!!
    val (n, m) = r.readLine()!!.split(" ").map { it.toInt() }
    if (n==m) println(n)
    else println(2)
}

import java.util.*

/**
 * Created by Igor on 7/17/2017.
 */

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val l = scanner.nextInt()
    val r = scanner.nextInt()

    if (l == r)
        println(l)
    else
        println(2)
}

import java.util.*

fun main(args: Array<String>){
    var sc = Scanner(System.`in`)
    var l = sc.nextInt()
    var r = sc.nextInt()
    println(if(l == r) l else 2)
}

fun main(args: Array<String>) {
	val (l,r) = readLine()!!.split(' ').map(String::toInt)
	val res = if ( r==l) l else 2;
	println(res)

}

import java.util.*

fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    val left = reader.nextInt()
    val right = reader.nextInt()
    if (left == right && right % 3 == 0) println(3)
    else if (left == right && right % 2 != 0) println(right)
    else println(2)

}

import java.util.*

fun main(args: Array<String>) {
    var(l, r) = readLine()!!.split(" ").map(String::toInt)
    if (l == r) {
        println(l)
    } else {
        println(2)
    }
}

import kotlin.math.abs

fun main() {
    var (l, r) = readLine()!!.split(' ').map { it.toInt() }
    if (abs(l-r)==0){
        println(l)
    }else{
        println(2)
    }
}

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

    val (l, r) = readInts()
    print(if (l == r) l else 2)
}

//fun main() {
//    fun readLongs() = readLine()!!.split(" ").map(String::toLong)
//
//    val (l, r) = readLongs()
//    val divisorToTimes = mutableMapOf<Long, Int>()
//    val composites = mutableSetOf<Long>()
//    for (candidate in 2L..r) {
//        if (candidate in composites) continue
//        divisorToTimes[candidate] = if (candidate in l..r) 1 else 0
//        for (number in candidate + candidate..r step candidate) {
//            if (number in l..r)
//                divisorToTimes[candidate] = divisorToTimes[candidate]!! + 1
//            composites.add(number)
//        }
//    }
//    print(divisorToTimes.maxBy { it.value }!!.key)
//}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val tokenizer = BufferedReader(InputStreamReader(System.`in`)).use { StringTokenizer(it.readText()) }
    val l = tokenizer.nextInt()
    val r = tokenizer.nextInt()
    if (l == r)
        println(l)
    else
        println(2)
}

fun StringTokenizer.nextInt() = Integer.parseInt(nextToken())

fun main(args: Array<String>) {
    val (l, r) = readLine()!!.split(' ').map(String::toInt)
    if (l == r)
        print("$l\n")
    else
        print("2\n")
}

fun main(args : Array<String>)
{
    var line: String = inputNotNull()
    var l: Long = line.split(" ")[0].toLong()
    var r: Long = line.split(" ")[1].toLong()
    var arr: Array<Long> = Array<Long>(Math.sqrt(r.toDouble()).toInt(),{i -> 0})

    if(r == 2L||r==4L){
        println(2)
        return
    }else if(r==3L){
        println(3)
        return
    }else if(l==r){
        println(l)
        return
    }

    println(2)

}

fun inputNotNull(): String
{
    val line: String? = readLine()
    if (line == null) return ""
    return line.trim()
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!
    //val (n, m) = r.readLine()!!.split(" ").map { it.toInt() }
    println(2)
}

import java.util.*

fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    val left = reader.nextInt()
    val right = reader.nextInt()
    if (left == right && right % 3 == 0) println(3)
    else println(2)

}

import java.util.*

fun main(args: Array<String>) {
    var(l, r) = readLine()!!.split(" ").map(String::toInt)
    println(2)
}


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

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

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

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

import kotlin.math.max

fun main() {
    val (numCitizens, numWizards, percentage) = readLine()!!.split(" ").map(String::toInt)
    val total = numCitizens * percentage / 100 + if ((numCitizens * percentage) % 100 == 0) 0 else 1
    print(max(0, total - numWizards))
}

fun main() {
    val (numCitizens, numWizards, percentage) = readLine()!!.split(" ").map(String::toInt)
    val total = numCitizens * percentage / 100 + if ((numCitizens * percentage) % 100 == 0) 0 else 1
    print(total - numWizards)
}


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

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

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

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

import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.AssertionError
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 MAX = if (isDebug) 100 else 100_000
    val flg = BooleanArray(MAX + 1){true}
    val primes = mutableListOf<Int>()
    flg[0] = false
    flg[1] = false

    for (i in 2 .. MAX) {
      if (!flg[i]) continue
      primes += i

      var j = i * 2
      while (j <= MAX) {
        flg[j] = false
        j += i
      }
    }

    fun isPrime(a: Int): Boolean {
      for (p in primes) {
        if (a <= p) return true
        if (a % p == 0) return false
      }
      return true
    }

    val N = ni()
    if (isPrime(N)) {
      out.println(1)
      out.println("$N")
      return
    }

    var Pn = N - 2
    while(!isPrime(Pn)) {
      Pn--
    }

    val x = N - Pn
    if (isPrime(x)) {
      out.println(2)
      out.println("$Pn $x")
      return
    }

    for (p in primes) {
      if (flg[x - p]) {
        out.println(3)
        out.println("$Pn $p ${x - p}")
        return
      }
    }
  }

  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 inline fun debug(a: LongArray) {
    debug { a.joinToString(" ") }
  }

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

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

  private inline fun debugDim(A: Array<LongArray>) {
    if (isDebug) {
      for (a in A) {
        debug(a)
      }
    }
  }
  private inline 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)
  }

  private inline fun assert(b: Boolean) = run{if (!b) throw AssertionError()}
}

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


Little Chris is bored during his physics lessons (too easy), so he has built a toy box to keep himself occupied. The box is special, since it has the ability to change gravity.There are n columns of toy cubes in the box arranged in a line. The i-th column contains ai cubes. At first, the gravity in the box is pulling the cubes downwards. When Chris switches the gravity, it begins to pull all the cubes to the right side of the box. The figure shows the initial and final configurations of the cubes in the box: the cubes that have changed their position are highlighted with orange.  Given the initial configuration of the toy cubes in the box, find the amounts of cubes in each of the n columns after the gravity switch!

The first line of input contains an integer n (1 ≤ n ≤ 100), the number of the columns in the box. The next line contains n space-separated integer numbers. The i-th number ai (1 ≤ ai ≤ 100) denotes the number of cubes in the i-th column.

Output n integer numbers separated by spaces, where the i-th number is the amount of cubes in the i-th column after the gravity switch.

NoteThe first example case is shown on the figure. The top cube of the first column falls to the top of the last column; the top cube of the second column falls to the top of the third column; the middle cube of the first column falls to the top of the second column.In the second example case the gravity switch does not change the heights of the columns.

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    readLine()!!.split(" ").map { it.toInt() }.sorted().forEach({ print("${it} ") })
}

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

class ProblemIO(val rd: BufferedReader, val wr: PrintWriter) {
    var tok = StringTokenizer("")

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

    fun readToken(): String {
        while (!tok.hasMoreTokens()) {
            tok = StringTokenizer(rd.readLine())
        }
        return tok.nextToken()
    }

    fun readInt(): Int = readToken().toInt()
    fun <T> print(v: T) = wr.print(v)
    fun <T> println(v: T) = wr.println(v)
    fun close() {
        rd.close()
        wr.close()
    }
}

fun solve() {
    val io = ProblemIO.console()
    val n = io.readInt()
    val a = IntArray(n)
    for (i in a.indices) {
        a[i] = io.readInt()
    }
    a.sort()
    io.println(a.joinToString(" "))
    io.close()
}

fun main(args: Array<String>) {
    Thread({ solve() }).start()
}

fun main()
{
    val ignore = readLine()!!.toInt()
    println(readLine()!!.split(" ").map { it.toInt() }.sorted().joinToString(" "))

}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    val l = r.readLine()!!.split(" ").map { it.toInt() }.sorted()
    println(l.joinToString(" "))
}

fun main() {
    readLine()!!
    val cubes = readLine()!!.split(" ").map(String::toInt)
    println(cubes.sorted().joinToString(separator = " ").trim())
}

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()

    var max = 0
    val columns = Array(n, {
        val curr = scanner.nextInt()
        if (curr > max) {
            max = curr
        }
        curr
    })

    val tmp = IntArray(max, { 0 })

    columns.forEach {
        tmp[it - 1]++
    }

    var index = 0
    tmp.forEachIndexed { i, v ->
        for (j in 0 until v) {
            columns[index++] = i + 1
        }
    }

    println(columns.joinToString(" "))

}

fun main() {
    readLine()
    readLine()!!.split(' ').map(String::toInt).sorted().forEach { print("$it ") }
}

fun main(args: Array<String>) {
    var count = readLine()!!.toInt()
    println(readLine()!!.split(" ").map { it.toInt() }.sorted()
        .map {
        it.toString()
    }.joinToString (" "))
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.lang.StringBuilder

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    br.readLine()
    val row = br.readLine().split("\\s+".toRegex())
    val sortedRow = row.sortedBy { i -> i.toInt() }
    val sb = StringBuilder()
    for (i in sortedRow)
        sb.append("$i ")
    sb.deleteCharAt(sb.length - 1)
    print(sb.toString())
}

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

fun main(args: Array<String>) {
    val inputStream = System.`in`
    val outputStream = System.out
    val input = InputReader(inputStream)
    val output = PrintWriter(outputStream)
    val solver = Task()
    solver.solve(input, output)
    output.close()
}

private class Task {
    fun solve(input: InputReader, output: PrintWriter) {
        val n = input.nextInt()

        val heights = (1..n).map { input.nextInt() }
        val maxHeight: Int = heights.max()!!

        val box = Array(maxHeight, { IntArray(n, { 0 }) })
        for (i in 0 until n) {
            for (j in 0 until heights[i]) {
                box[maxHeight - j - 1][i] = 1
            }
        }

        for (i in 0 until maxHeight) {
            for (j in n - 2 downTo 0) {
                for (k in j until n - 1) {
                    if (box[i][k] == 1) {
                        if (box[i][k + 1] == 0) {
                            box[i][k + 1] = 1
                            box[i][k] = 0
                        }
                    } else {
                        break
                    }
                }
            }
        }

        for (j in 0 until n) {
            var sum = 0
            for (i in 0 until maxHeight) {
                sum += box[i][j]
            }
            output.print(sum)
            output.print(" ")
        }
    }
}

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

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

        }
        return tokenizer!!.nextToken()
    }

    fun nextInt(): Int {
        return next().toInt()
    }

}

fun main() {
    readLine()
    println(readLine()!!.split(" ").map(String::toInt).sorted().joinToString(" "))
}

fun main() {
    readLine()
    val input = readLine()!!.split(" ").map(String::toInt).sorted()
    println(input.joinToString(" "))
}

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

fun main() {
    io.apply {

        cout .. ints().sorted().toIntArray() .. 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"
    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

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

fun main() {
    var c = readLine()!!.toInt()
    var arr = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    var matrex = Array(arr.max()!!.toInt()) { Array(c) { 0 } }
    var i = 0
    for (col in 0 until c) {
        for (row in (arr.max()!! - 1)downTo 0) {
            if(arr[i] < arr.max()!!){
                matrex[row][col] = 0
                arr[i]++
            }else
                matrex[row][col] = 1
        }
        i++
    }

    var res = Array(c){0}
    var index = 0
    for(i in 0 until arr.max()!!) {
        var lineArray = matrex[i]
        for(j in 0 until lineArray.size){
            if(lineArray[j] == 1) {
                res[index]++
                index++
            }
        }
        index = 0
    }
    for(i in res.size-1 downTo 0)
        print("${res[i]} ")
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val s = readInt()

    val h = readInts().toMutableList()

    h.sort()

    println(h.joinToString(" "))
}

fun main(args: Array<String>) {
    val n = readInt()
    println(readInts().sorted().joinToString(" "))
}

private fun readInt() = readLine()!!.toInt()

private fun readInts() = readLine()!!.split(" ").map { it.toInt() }

fun main() {
    val n = readLine()!!.toInt()
    val a = readLine()!!.split(regex = "\\s".toRegex()).map { it.toInt() }.toTypedArray()
        .sorted()

    println(a.joinToString(separator = " "))
}

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

fun main(args: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    var n = reader.readLine().toInt()
    val nums = reader.readLine().split(" ")
            .mapTo(mutableListOf(), { it.toInt() })

    var mismatch = true

    while (mismatch) {
        var counter = 0
        while (n - 1 != 0) {
            val difference = nums[n - 2] - nums[n - 1]
            if (difference > 0) {
                nums[n - 2] -= difference
                nums[n - 1] += difference
                counter++
            }
            n--
        }
        if(0 == counter) {
            mismatch = false
        }
        n = nums.size
    }
    nums.forEach({ print("$it ") })
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val a = br.readLine().split(" ").map { it.toInt() }
    val count = Array(101){0}
    for (a_i in a) {
        count[a_i]++
    }
    val ans = ArrayList<Int>()
    var i = 0
    while (i < count.size && ans.size < n) {
        if (count[i] > 0) {
            ans.add(i)
            count[i]--
        } else {
            i++
        }
    }
    println(ans.joinToString(" "))
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val n = br.readLine().toInt()
    val a = br.readLine().split(" ").map { it.toInt() }
    val count = Array(105){0}
    for (a_i in a){
        count[a_i]++
    }

    val asorted = Array(n){0}
    var i = 0
    var j = 0

    while (i < count.size){
        if (count[i] != 0){
            asorted[j] = i
            count[i]--
            j++
        }else{
            i++
        }
    }
    println(asorted.joinToString(" "))
}

import java.util.*
import kotlin.math.abs

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var numOfCol = scan.nextInt()
    val list = mutableListOf<Int>()
    while (numOfCol-->0) {
        val s =scan.nextInt()
        list.add(s)
    }
    list.sort()
    list.forEach {
        print("$it ")

    }
}

import kotlin.math.abs

fun readLn() = readLine()!! // string line
fun readInt() = readLn().toInt() // single int
fun readStrings() = readLn().split(" ") // list of strings
fun readInts() = readStrings().map { it.toInt() } // list of ints

fun findFlipCols(): List<Int> {
    val numCols = readInt()
    val colsVals = readInts()
    return colsVals.sorted()
}

fun main() {
    print(findFlipCols().joinToString(separator = " "))
}

fun main(args: Array<String>) {
    gravityChange()
}
fun gravityChange(){
    readLine()
    readLine()?.split(" ")?.map{ it.toInt()}?.sorted()?.forEach { print("$it ") }
}

import java.util.*
import kotlin.collections.ArrayList

fun main() {
    var n = readLine()!!.toInt()
    var list = readLine()!!.split(' ').map { it.toInt() }

    Collections.sort(list)
    for (i in list){
        print("$i ")
    }
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val heights = readLine()!!.split(' ').map { it.toInt() }
    val freqs = IntArray(101)
    for (h in heights) {
        (1..h).forEach { freqs[it]++ }
    }
    for (i in 1..n) {
        print("${freqs.count { it >= n - i + 1 }} ")
    }
    println()
}

import java.util.*

fun main(){
    val scan = Scanner(System.`in`)
    val n = scan.nextInt()
    val arr = IntArray(n)
    for (i in 0 until n) arr[i] = scan.nextInt()
    arr.sort()

    for (i in arr) print("$i ")
}

typealias int = Int

fun main() {
    var n = readLine()!!.toInt()
    var arr : IntArray= readLine()!!.split(' ').map { it.toInt() }.toIntArray()
   arr.sort()

    for( idx in 0..arr.lastIndex) {
        print("${arr[idx]} ")
    }
    println()
}

import java.lang.AssertionError
import java.util.*

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readLong() = readLn().toLong() // single long
private fun readDouble() = readLn().toDouble() // single double
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints
private fun readLongs() = readStrings().map { it.toLong() } // list of longs
private fun readDoubles() = readStrings().map { it.toDouble() } // list of doubles

private fun myAssert(x: Boolean) {
    if (!x) {
        throw AssertionError()
    }
}

fun main(args: Array<String>) {
//  var s = Scanner(System.`in`)
  var n = readInt()
  var l = readInts()
  l = l.sorted()
  println(l.joinToString(" "))
}

import java.util.Scanner
import java.util.Arrays

fun main(args:Array<String>)
{
    var sc=Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val a = IntArray(n)
    for(i in 0 until n)
    {
        a[i] = sc.nextInt()
    }
    Arrays.sort(a)
    for(i in 0 until n)
    {
        print(a[i])
        print(" ")
    }
}

fun main(args: Array<String>) {
    readLine()
    readLine()!!.split(' ').map(String::toInt).sorted().forEach {
        print("$it ")
    }
    print("\n")
}

fun main(args: Array<String>) {
    readLine()
    readLine()!!.split(' ').map(String::toInt).toTypedArray().sorted().forEach {
        print("$it ")
    }
    print("\n")
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val matrix = readLine()!!.split(' ').map { it.toInt() }.toMutableList()

    while ((n - 2 downTo 0).count {
                val delta = matrix[it] - matrix[it + 1]
                if (delta > 0) {
                    matrix[it] -= delta
                    matrix[it + 1] += delta
                }
                delta > 0
            } > 0){}

        println(matrix.joinToString(separator = " "))
}

fun main(args: Array<String>) {
    readLine()!!.toInt()
    val array = readLine()!!.split(' ').map { it.toInt() }.sorted()
    println(array.joinToString(" "))
}

fun main() {
    readLine()
    readLine()!!.split(' ').sorted().forEach { print("$it ") }
}

import java.io.BufferedReader
import java.io.InputStreamReader
import java.lang.StringBuilder

fun main(args: Array<String>) {
    val br = BufferedReader(InputStreamReader(System.`in`))
    br.readLine()
    val row = br.readLine().split("\\s+".toRegex())
    val sortedRow = row.sorted()
    val sb = StringBuilder()
    for (i in sortedRow)
        sb.append("$i ")
    sb.deleteCharAt(sb.length - 1)
    print(sb.toString())
}

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {
    val s = readInt()

    val h = readInts().toMutableList()

    var c = 0

    // 4
    //3 2 1 2

    while (c < s-1) { // no point for the last grid
        var i = c;
        var moved = false

        while (i < s-1) {
            if (h[i] > h[i+1]) {
                val t = h[i] - h[i + 1]
                h[i] = h[i] - t
                h[i + 1] = h[i+1] + t
                moved = true
                i++
            } else {
                moved = false
                break
            }
        }

        if (!moved) {
            c++
        }
    }

    println(h.joinToString(" "))
}


A monster is chasing after Rick and Morty on another planet. They're so frightened that sometimes they scream. More accurately, Rick screams at times b, b + a, b + 2a, b + 3a, ... and Morty screams at times d, d + c, d + 2c, d + 3c, ....   The Monster will catch them if at any point they scream at the same time, so it wants to know when it will catch them (the first time they scream at the same time) or that they will never scream at the same time.

The first line of input contains two integers a and b (1 ≤ a, b ≤ 100).  The second line contains two integers c and d (1 ≤ c, d ≤ 100).

Print the first time Rick and Morty will scream at the same time, or  - 1 if they will never scream at the same time.

NoteIn the first sample testcase, Rick's 5th scream and Morty's 8th time are at time 82. In the second sample testcase, all Rick's screams will be at odd times and Morty's will be at even times, so they will never scream at the same time.

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

fun DataReader.solve(out: PrintWriter) {
    val a = nextInt()
    val b = nextInt()
    val c = nextInt()
    val d = nextInt()

    var answer = 100500

    for (i in 0..111) {
        for (j in 0..111) {
            if (b + a * i == d + c * j) {
                answer = Math.min(answer, b + a * i)
            }
        }
    }

    if (answer == 100500) {
        answer = -1
    }

    out.println(answer)
}

// Taken from `bintree`-s code.
class DataReader(private val reader: BufferedReader) {
    var st : StringTokenizer? = null
    companion object {
        fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))
    }

    fun next() : String? {
        while (st == null || !st!!.hasMoreTokens()) {
            val s = reader.readLine() ?: return null
            st = StringTokenizer(s)
        }

        return st?.nextToken()
    }

    fun nextToken() = next()!!

    fun nextInt() = nextToken().toInt()
    fun nextLong() = nextToken().toLong()
    fun readIntArray(n: Int) : IntArray {
        val result = IntArray(n)
        result.indices.forEach { i -> result[i] = nextInt() }
        return result
    }

    fun readLongArray(n: Int) : LongArray {
        val result = LongArray(n)
        result.indices.forEach { i -> result[i] = nextLong() }
        return result
    }

    fun nextLine() = reader.readLine()
}

fun main(args: Array<String>) {
    val wr = PrintWriter(System.out);
    val re = BufferedReader(InputStreamReader(System.`in`));
    DataReader(re).solve(wr)
    wr.flush()
}

import kotlin.math.abs

fun main() {
    val (a, b) = readLine()!!.split(" ").map { it.toLong() }
    val (c, d) = readLine()!!.split(" ").map { it.toLong() }
    val diffs = mutableSetOf<Long>()
    when {
        a % 2L == 0L && b % 2L == 0L && c % 2L == 0L && d % 2L != 0L -> print(-1)
        c % 2L == 0L && d % 2L == 0L && a % 2L == 0L && b % 2L != 0L -> print(-1)
        else -> {
            var first = b
            var second = d
            while (first != second) {
                if (diffs.contains(first - second)) {
                    first = -1
                    break
                } else diffs.add(first - second)
                if (first < second) first += a else second += c
            }
            print(first)
        }
    }
}

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

tailrec fun gcd(a: Int, b: Int): Int {
    if (a != 0 && b != 0) {
        if (a > b) return gcd(a % b, b)
        else return gcd(b % a, a)
    }

    return a + b
}

fun gcde(a: Int, b: Int): Triple<Int, Int, Int> {
    if (a == 0) {
        return Triple(b, 0, 1)
    }

    val (d, x1, y1) = gcde(b % a, a)

    return Triple(d, y1 - (b / a) * x1, x1)
}

fun DataReader.solve(out: PrintWriter) {
    val b = nextInt()
    val a = nextInt()
    val d = nextInt()
    val c = nextInt()

    val q = c - a
    val (g) = gcde(b, -d)

    if (q % g != 0) {
        out.println(-1)
        return
    }

    for (i in 0..100000000) {
        val w = a + i * b - c

        if (w >= 0 && w % d == 0) {
            out.println(w + c)
            return
        }
    }

//
//    val p = q / g
//
//    val (g1, x, y) = gcde(b / g, -d / g)
//
//    val (xr, yr) = x * p to y * p

    throw RuntimeException(":(")
}

fun Boolean.toYesNo() = if (this) "YES" else "NO"

class DataReader(private val reader: BufferedReader) {
    var st : StringTokenizer? = null
    companion object {
        fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))
    }

    fun next() : String? {
        while (st == null || !st!!.hasMoreTokens()) {
            val s = reader.readLine() ?: return null
            st = StringTokenizer(s)
        }

        return st?.nextToken()
    }

    fun nextToken() = next()!!

    fun nextInt() = nextToken().toInt()
    fun nextLong() = nextToken().toLong()
    fun readIntArray(n: Int) : IntArray {
        val result = IntArray(n)
        result.indices.forEach { i -> result[i] = nextInt() }
        return result
    }

    fun readLongArray(n: Int) : LongArray {
        val result = LongArray(n)
        result.indices.forEach { i -> result[i] = nextLong() }
        return result
    }

    fun nextLine() = reader.readLine()
}

fun main(args: Array<String>) {
    val r: Reader
    val out: PrintWriter
    if (System.getProperty("ONLINE_JUDGE") == null) {
        r = FileReader("input.txt")
        out = PrintWriter("output.txt")
    } else {
        r = InputStreamReader(System.`in`)
        out = PrintWriter(System.out)
    }

    DataReader(BufferedReader(r)).solve(out)
    out.flush()
}

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

    var ans = -1

    loop@ for (x in 0..99) {
        for (y in 0..99) {
            val t1 = b + x * a
            val t2 = d + y * c
            if (t1 == t2) {
                ans = t1
                break@loop
            }
        }
    }

    println(ans)
}

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

//val inp = BufferedReader(FileReader ( "input.txt" ) )
val inp = BufferedReader(InputStreamReader(System.`in`))

fun solve() : Int {
	val a = ( inp.readLine() ?: return 1 ).split(" ").map{ it.toInt() }
	val b = ( inp.readLine() ?: return 1 ).split(" ").map{ it.toInt() }
	var curA = a[1]
	var curB = b[1]
	for ( i in 1..1000000 ) {
		if ( curA == curB ) {
			println ( "" + curA )
			return 0
		}
		if ( curA < curB ) curA += a[0]
		else curB += b[0]
	}
	println ( "-1" )
	return 0
}

fun main ( args : Array<String> ) {
	while (solve()==0);
}

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

fun DataReader.solve(out: PrintWriter) {
    val b = nextInt()
    val a = nextInt()
    val d = nextInt()
    val c = nextInt()

    for (i in 1..1000000) {
        val q = a + i * b - c

        if (q >= 0 && q % d == 0) {
            out.println(q + c)
            return
        }
    }

    out.println(-1)
}

fun Boolean.toYesNo() = if (this) "YES" else "NO"

class DataReader(private val reader: BufferedReader) {
    var st : StringTokenizer? = null
    companion object {
        fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))
    }

    fun next() : String? {
        while (st == null || !st!!.hasMoreTokens()) {
            val s = reader.readLine() ?: return null
            st = StringTokenizer(s)
        }

        return st?.nextToken()
    }

    fun nextToken() = next()!!

    fun nextInt() = nextToken().toInt()
    fun nextLong() = nextToken().toLong()
    fun readIntArray(n: Int) : IntArray {
        val result = IntArray(n)
        result.indices.forEach { i -> result[i] = nextInt() }
        return result
    }

    fun readLongArray(n: Int) : LongArray {
        val result = LongArray(n)
        result.indices.forEach { i -> result[i] = nextLong() }
        return result
    }

    fun nextLine() = reader.readLine()
}

fun main(args: Array<String>) {
    val r: Reader
    val out: PrintWriter
    if (System.getProperty("ONLINE_JUDGE") == null) {
        r = FileReader("input.txt")
        out = PrintWriter("output.txt")
    } else {
        r = InputStreamReader(System.`in`)
        out = PrintWriter(System.out)
    }

    DataReader(BufferedReader(r)).solve(out)
    out.flush()
}

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

tailrec fun gcd(a: Int, b: Int): Int {
    if (a != 0 && b != 0) {
        if (a > b) return gcd(a % b, b)
        else return gcd(b % a, a)
    }

    return a + b
}

fun gcde(a: Int, b: Int): Triple<Int, Int, Int> {
    if (a == 0) {
        return Triple(b, 0, 1)
    }

    val (d, x1, y1) = gcde(b % a, a)

    return Triple(d, y1 - (b / a) * x1, x1)
}

fun DataReader.solve(out: PrintWriter) {
    val b = nextInt()
    val a = nextInt()
    val d = nextInt()
    val c = nextInt()

    val q = c - a
    val (g) = gcde(b, -d)

    if (q % g != 0) {
        out.println(-1)
        return
    }

    for (i in 1..100000000) {
        val w = a + i * b - c

        if (w >= 0 && w % d == 0) {
            out.println(w + c)
            return
        }
    }

//
//    val p = q / g
//
//    val (g1, x, y) = gcde(b / g, -d / g)
//
//    val (xr, yr) = x * p to y * p

    out.println(-1)
}

fun Boolean.toYesNo() = if (this) "YES" else "NO"

class DataReader(private val reader: BufferedReader) {
    var st : StringTokenizer? = null
    companion object {
        fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))
    }

    fun next() : String? {
        while (st == null || !st!!.hasMoreTokens()) {
            val s = reader.readLine() ?: return null
            st = StringTokenizer(s)
        }

        return st?.nextToken()
    }

    fun nextToken() = next()!!

    fun nextInt() = nextToken().toInt()
    fun nextLong() = nextToken().toLong()
    fun readIntArray(n: Int) : IntArray {
        val result = IntArray(n)
        result.indices.forEach { i -> result[i] = nextInt() }
        return result
    }

    fun readLongArray(n: Int) : LongArray {
        val result = LongArray(n)
        result.indices.forEach { i -> result[i] = nextLong() }
        return result
    }

    fun nextLine() = reader.readLine()
}

fun main(args: Array<String>) {
    val r: Reader
    val out: PrintWriter
    if (System.getProperty("ONLINE_JUDGE") == null) {
        r = FileReader("input.txt")
        out = PrintWriter("output.txt")
    } else {
        r = InputStreamReader(System.`in`)
        out = PrintWriter(System.out)
    }

    DataReader(BufferedReader(r)).solve(out)
    out.flush()
}

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

tailrec fun gcd(a: Int, b: Int): Int {
    if (a != 0 && b != 0) {
        if (a > b) return gcd(a % b, b)
        else return gcd(b % a, a)
    }

    return a + b
}

fun gcde(a: Int, b: Int): Triple<Int, Int, Int> {
    if (a == 0) {
        return Triple(b, 0, 1)
    }

    val (d, x1, y1) = gcde(b % a, a)

    return Triple(d, y1 - (b / a) * x1, x1)
}

fun DataReader.solve(out: PrintWriter) {
    val b = nextInt()
    val a = nextInt()
    val d = nextInt()
    val c = nextInt()

    val q = c - a
    val (g) = gcde(b, -d)

    if (q % g != 0) {
        out.println(-1)
        return
    }

    for (i in 1..100000000) {
        val w = a + i * b - c

        if (w >= 0 && w % d == 0) {
            out.println(w + c)
            return
        }
    }

//
//    val p = q / g
//
//    val (g1, x, y) = gcde(b / g, -d / g)
//
//    val (xr, yr) = x * p to y * p

    throw RuntimeException(":(")
}

fun Boolean.toYesNo() = if (this) "YES" else "NO"

class DataReader(private val reader: BufferedReader) {
    var st : StringTokenizer? = null
    companion object {
        fun createFromFile(name: String) = DataReader(BufferedReader(FileReader(name)))
    }

    fun next() : String? {
        while (st == null || !st!!.hasMoreTokens()) {
            val s = reader.readLine() ?: return null
            st = StringTokenizer(s)
        }

        return st?.nextToken()
    }

    fun nextToken() = next()!!

    fun nextInt() = nextToken().toInt()
    fun nextLong() = nextToken().toLong()
    fun readIntArray(n: Int) : IntArray {
        val result = IntArray(n)
        result.indices.forEach { i -> result[i] = nextInt() }
        return result
    }

    fun readLongArray(n: Int) : LongArray {
        val result = LongArray(n)
        result.indices.forEach { i -> result[i] = nextLong() }
        return result
    }

    fun nextLine() = reader.readLine()
}

fun main(args: Array<String>) {
    val r: Reader
    val out: PrintWriter
    if (System.getProperty("ONLINE_JUDGE") == null) {
        r = FileReader("input.txt")
        out = PrintWriter("output.txt")
    } else {
        r = InputStreamReader(System.`in`)
        out = PrintWriter(System.out)
    }

    DataReader(BufferedReader(r)).solve(out)
    out.flush()
}