Given an integer $$$x$$$, find 2 integers $$$a$$$ and $$$b$$$ such that:   $$$1 \le a,b \le x$$$  $$$b$$$ divides $$$a$$$ ($$$a$$$ is divisible by $$$b$$$).  $$$a \cdot b>x$$$.  $$$\frac{a}{b}<x$$$.

The only line contains the integer $$$x$$$ $$$(1 \le x \le 100)$$$.

You should output two integers $$$a$$$ and $$$b$$$, satisfying the given conditions, separated by a space. If no pair of integers satisfy the conditions above, print "-1" (without quotes).

fun main(args : Array<String>) {

    val n1 = readLine()!!
    var n = n1.toInt()
    var a = 0
    var b = 0
    var c = 0

    if(n==1){
        c = 0
    }
    else{
         for(i in 1..n){
             for(j in 1..n){
                 if(i%j==0 && i/j<n && i*j>n){
                     a = i
                     b = j
                     c++
                     break
                 }
             }
         }

    }

    if(c==0){
       println(-1)
    }
    else{
        print(a)
        print(" ")
        print(b)
    }
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    println(if (n==1) -1 else "$n $n")
}

import java.io.*
val br = BufferedReader(InputStreamReader(System.`in`))
val bw = BufferedWriter(OutputStreamWriter(System.out))
fun println(s: String) { bw.write(s + "\n") }
fun readLine() = br.readLine()!!

fun main(args: Array<String>) {
    solve()
    bw.close()
}

fun solve() {
    val r = readLine().toInt()
    for (a in 1..r) {
        for (b in 1..r) {
            if (a % b == 0 && a * b > r && a.toDouble() / b.toDouble() < r ) {
                println("$a $b")
                return
            }
        }
    }
    println("-1")

}

fun constructIntegers(n:Int):String{
        val a=n
        val b=n
        if(n > 1) {
            return a.toString()+" "+b.toString()
        }
        return "-1"
    }
    fun main(args : Array<String>){
    println(constructIntegers(readLine()!!.toInt()))
}

fun main() {
    val x = readLine()!!.toInt()
    if (x == 1) {
        println(-1)
    } else {
        println("${x - (x and 1)} 2")
    }
}

private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)

fun main(args: Array<String>) {
    val (num) = read().map(String::toInt)

    var found = false

    for (x in 2..num) {
        val a = x
        val b = x/2

        if ((a%b == 0) && ((a/b) < num) && ((a*b) > num)) {
            print("$a $b")
            found = true
            break
        }
    }

    if (!found) {
        for (x in 2..num) {
            val a = x
            val b = x

            if ((a%b == 0) && ((a/b) < num) && ((a*b) > num)) {
                print("$a $b")
                found = true
                break
            }
        }
    }

    if (!found) {
        println(-1)
    }
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = n
    var b = n
    if (n == 1) {
        println(-1)
    } else {
        println("$a $b")
    }
}

import java.io.*
import kotlin.system.measureTimeMillis

fun solve(input: BufferedReader) {
    val x = input.readLine().toInt()
    for (a in 1..x)
        for (b in 1..x)
            if (a % b == 0 && a / b < x && a * b > x) {
                print("%d %d\n".format(a, b))
                return
            }
    println(-1)
}

fun main(args: Array<String>) {
    System.err.println("time = %dms".format(measureTimeMillis {
        solve(System.`in`.bufferedReader())
//        solve(File("a.out").bufferedReader())
    }))
}

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    var x = sc.nextInt()
    if(x == 1) println(-1)
    else print("${x} ${x}")
}

fun main() {
    val x = readLine()!!.toInt()
    for (b in 1..x)
        for (a in b..x step b)
            if (a * b > x && a / b < x) return print("$a $b")
    print(-1)
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val result = solve(n)
    if (result == null) {
        println(-1)
    } else {
        println("${result.first} ${result.second}")
    }
}

fun solve(x: Int): Pair<Int, Int>? {
    for (b in 1..x) {
        for (a in x downTo 1) {
            if (a % b == 0) {
                if (a * b > x) {
                    if (a.toFloat()/b.toFloat() < x) {
                        return a to b
                    }
                }
            }
        }
    }

    return null
}

import java.util.*

fun main(args: Array<String>) {
    Scanner(System.`in`).forEach {
        val x = it.toInt()
        for (a in 1..100) {
            for (b in 1..100) {
                if (a % b == 0 && b <= x && a * b > x && a / b < x) {
                    println("$a $b")
                    return
                }
            }
        }
        println("-1")
        return
    }

}

fun main(args: Array<String>)
{ var c: Int=0
	var x= readLine()!!.toInt()
	for(i in 1..x)
		{
			for(j in 1..(i*x))
				{
					if((j*i)>x && (j%i)==0)
						{
							println("$j   $i")
							c++
							break
						}
				}
			if(c==1)break

		}
	if(c==0)println("-1")

}

fun main()
{ var c: Int=0
	var x= readLine()!!.toInt()
	for(i in 1..x)
		{
			for(j in 1..(i*x))
				{
					if((j*i)>x && (j%i)==0)
						{
							println("$j   $i")
							c++
							break
						}
				}
			if(c==1)break

		}
	if(c==0)println("-1")

}

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

class A {
    fun solve(x : Int) : Pair<Int, Int> {
        if (x == 1) {
            return Pair(-1, -1)
        }
        if (x % 2 == 0) {
            return Pair(x, 2)
        } else {
            return Pair(x - 1, 2)
        }
    }

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

        val x = reader.nextInt()
        val (a, b) = solve(x)
        if (a == -1) {
            writer.println("-1")
        } else {
            writer.println("$a $b")
        }

        writer.close()
    }

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

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

            }
            return tokenizer!!.nextToken()
        }

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

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

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

fun constructIntegers(n:Int):String{
    var a = 0
    var b = 0
        if(n > 3) {
            for(i in n downTo 2){
                a = i
                for(j in a-1 downTo 2) {
                    b = j
                    if (a%b == 0 && a*b > n && a/b < n){
                        return a.toString()+" "+b.toString()
                    }
                }
            }
        }
        return "-1"
    }

    fun main(args: Array<String>){
    println(constructIntegers(readLine()!!.toInt()))
}

fun main() {
    val x = readLine()!!.toInt()
    if (x == 1) {
        println(-1)
    } else {
        println("${x + (x and 1)} 2")
    }
}

private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)

fun main(args: Array<String>) {
    val (num) = read().map(String::toInt)

    var found = false

    for (x in 1..num) {
        if (x * 2 <= num) {
            print("$x ${x * 2}")
            found = true
            break
        }
    }

    if (!found) {
        println(-1)
    }
}

private fun read(delimit: Char = ' ') = readLine()!!.split(delimit)

fun main(args: Array<String>) {
    val (num) = read().map(String::toInt)

    var found = false

    for (x in 2..num) {

        if ((x%2 == 0) && (x/2 < num) && (x*2 > num)) {
            print("$x ${x / 2}")
            found = true
            break
        }
    }

    if (!found) {
        println(-1)
    }
}

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var a = n/2
    var b = n/2
    while (!c(a,b,n)) {
        if (a <1 || a > n || b < 1 || b > n) {
            println(-1)
            return
        }
        a++
        b--
    }
    print("$a $b")
}

fun c(a: Int, b: Int, n: Int) = a*b > n && a/b < n && a%b == 0

fun main()
{ var c: Int=0
	var x= readLine()!!.toInt()
	for(i in 1..x-1)
		{
			for(j in 1..(i*x)-1)
				{
					if((j*i)>x && (j%i)==0)
						{
							println("$j   $i")
							c++
							break
						}
				}
			if(c==1)break

		}
	if(c==0)println("-1")

}


Santa Claus is the first who came to the Christmas Olympiad, and he is going to be the first to take his place at a desk! In the classroom there are n lanes of m desks each, and there are two working places at each of the desks. The lanes are numbered from 1 to n from the left to the right, the desks in a lane are numbered from 1 to m starting from the blackboard. Note that the lanes go perpendicularly to the blackboard, not along it (see picture).The organizers numbered all the working places from 1 to 2nm. The places are numbered by lanes (i. e. all the places of the first lane go first, then all the places of the second lane, and so on), in a lane the places are numbered starting from the nearest to the blackboard (i. e. from the first desk in the lane), at each desk, the place on the left is numbered before the place on the right.    The picture illustrates the first and the second samples. Santa Clause knows that his place has number k. Help him to determine at which lane at which desk he should sit, and whether his place is on the left or on the right!

The only line contains three integers n, m and k (1 ≤ n, m ≤ 10 000, 1 ≤ k ≤ 2nm) — the number of lanes, the number of desks in each lane and the number of Santa Claus' place.

Print two integers: the number of lane r, the number of desk d, and a character s, which stands for the side of the desk Santa Claus. The character s should be "L", if Santa Clause should sit on the left, and "R" if his place is on the right.

NoteThe first and the second samples are shown on the picture. The green place corresponds to Santa Claus' place in the first example, the blue place corresponds to Santa Claus' place in the second example.In the third sample there are two lanes with four desks in each, and Santa Claus has the fourth place. Thus, his place is in the first lane at the second desk on the right.

fun main(args: Array<String>) {
    val (n, m, k) = readLine()!!.split(" ").map(String::toInt)
    val lane = ((k-1) / (2 * m)) + 1
    val desk = (((k-1)/2) % m) + 1
    val side = if(k%2 == 1) "L" else "R"
    println("$lane $desk $side")
}

fun findRow(k: Int, m: Int) = if ((k / 2) % m == 0) (k / 2) / m else (k / 2) / m + 1

fun findDesk(k: Int, m: Int) = if ((k / 2) % m == 0) m else (k / 2) % m

fun main(args: Array<String>) {
    val (n, m, k) = readLine()!!.split(" ").map(String::toInt)
    var side = 'R'
    var row: Int
    var desk: Int
    if (k % 2 == 0) {
        row = findRow(k, m)
        desk = findDesk(k, m)
    } else {
        row = findRow(k+1, m)
        desk = findDesk(k+1, m)
        side = 'L'
    }
    println("$row $desk $side")
}

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

    val (_, desksPerLane, santaPlace) = readInts()
    val lane = santaPlace / (2 * desksPerLane) + if (santaPlace % (2 * desksPerLane) == 0) 0 else 1
    val deskInLane = santaPlace - (lane - 1) * 2 * desksPerLane
    val numRow = (deskInLane + 1) / 2
    print("$lane $numRow ${if (santaPlace % 2 == 0) 'R' else 'L'}")
}


You are given a square board, consisting of $$$n$$$ rows and $$$n$$$ columns. Each tile in it should be colored either white or black.Let's call some coloring beautiful if each pair of adjacent rows are either the same or different in every position. The same condition should be held for the columns as well.Let's call some coloring suitable if it is beautiful and there is no rectangle of the single color, consisting of at least $$$k$$$ tiles.Your task is to count the number of suitable colorings of the board of the given size.Since the answer can be very large, print it modulo $$$998244353$$$.

A single line contains two integers $$$n$$$ and $$$k$$$ ($$$1 \le n \le 500$$$, $$$1 \le k \le n^2$$$) — the number of rows and columns of the board and the maximum number of tiles inside the rectangle of the single color, respectively.

Print a single integer — the number of suitable colorings of the board of the given size modulo $$$998244353$$$.

NoteBoard of size $$$1 \times 1$$$ is either a single black tile or a single white tile. Both of them include a rectangle of a single color, consisting of $$$1$$$ tile.Here are the beautiful colorings of a board of size $$$2 \times 2$$$ that don't include rectangles of a single color, consisting of at least $$$3$$$ tiles:  The rest of beautiful colorings of a board of size $$$2 \times 2$$$ are the following:

import kotlin.math.*

private const val MOD = 998244353

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val c = Array(n + 1) { IntArray(n + 1) }
    val d = Array(n + 1) { IntArray(n + 1) }
    c[0][0] = 1
    d[0][0] = 1
    for (x in 1..n) {
        for (m in 1..x) {
            c[x][m] = d[x - m][min(m, x - m)]
            for (l in 1 until m) {
                c[x][m] = add(c[x][m], c[x - l][m])
            }
            d[x][m] = add(c[x][m], d[x][m - 1])
        }
    }
    var sum = 0
    wl@ for (w in 1..n) {
        for (h in 1..n) {
            if (w * h >= k) continue@wl
            sum = add(sum, mul(c[n][w], c[n][h]))
        }
    }
    sum = mul(sum, 2)
    println(sum)
}

private fun add(a: Int, b: Int): Int = ((a.toLong() + b) % MOD).toInt()
private fun mul(a: Int, b: Int): Int = ((a.toLong() * b) % MOD).toInt()

import java.util.*

val MOD = 998244353L

fun main() {
    val jin = Scanner(System.`in`)
    val n = jin.nextInt()
    val k = jin.nextInt()
    val amts = LongArray(n + 1) {
        if (it == 0) {
            0L
        } else {
            val dp = LongArray(n + 1)
            dp[0] = 1L
            var sum = 1L
            for (j in 1..n) {
                dp[j] = sum
                sum += dp[j]
                if (j >= it) {
                    sum -= dp[j - it]
                }
                sum %= MOD
            }
            dp[n]
        }
    }
    for (j in n downTo 1) {
        amts[j] -= amts[j - 1]
    }
    var answer = 0L
    for (a in 1..n) {
        for (b in 1..n) {
            if (a * b < k) {
                answer += amts[a] * amts[b]
                answer %= MOD
            }
        }
    }
    answer *= 2
    println(((answer % MOD) + MOD) % MOD)
}


Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard. Here are some ways of placing signs and brackets:  1+2*3=7  1*(2+3)=5  1*2*3=6  (1+2)*3=9 Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers. For instance, in the given sample you cannot get expression (1+3)*2.It's easy to see that the maximum value that you can obtain is 9.Your task is: given a, b and c print the maximum value that you can get.

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 a = io.readInt()
    val b = io.readInt()
    val c = io.readInt()
    val v = intArrayOf(a * b * c, (a + b) * c, a * (b + c), a + b * c, a * b + c, a + b + c)
    io.println(v.max())
    io.close()
}

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

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val a = r.readLine()!!.toInt()
    val b = r.readLine()!!.toInt()
    val c = r.readLine()!!.toInt()
    val max1 = maxOf(a+b*c, (a+b)*c, a*b+c)
    val max2 = maxOf(a*(b+c), a*b*c, a+b+c)
    println(maxOf(max1, max2))
}

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

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

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun main(){
    var a=readInt()
    var b=readInt()
    var c=readInt()
    var ans=a+b+c
    ans=max(ans,a+b*c)
    ans=max(ans,a*b+c)
    ans=max(ans,a*b*c)
    ans=max(ans,(a+b)*c)
    ans=max(ans,a*(b+c))
    printLine("$ans")
    output()
}

import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextInt()
    val b = sc.nextInt()
    val c = sc.nextInt()
    val list = arrayListOf<Int>()
    // Manually declare all possible expression results
    list.add(a+b+c)
    list.add(a*b*c)
    list.add(a+b*c)
    list.add(a*b+c)
    list.add((a+b)*c)
    list.add(a*(b+c))
    // Print maximum
    println(list.max())
}

import java.util.*

fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)

    val a = scanner.nextLong()
    val b = scanner.nextLong()
    val c = scanner.nextLong()

    var res : Long = a + b + c

    res = Math.max(res, (a+b)*c)
    res = Math.max(res, a*(b+c))
    res = Math.max(res, a*b*c)
    res = Math.max(res, a+b*c)
    res = Math.max(res, a*b+c)

    System.out.print(res)

}

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 a = input.nextInt()
        val b = input.nextInt()
        val c = input.nextInt()

        output.print(listOf(
                a * b * c,
                a + b * c,
                a * b + c,
                a + b + c,
                (a + b) * c,
                a * (b + c)).max()
        )

    }
}

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

}

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 a = input.nextInt()
        val b = input.nextInt()
        val c = input.nextInt()

        output.print(listOf(a * b * c, a + b + c, a + b * c, a * b + c, (a + b) * c, a * (b + c)).max())
    }
}

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

}

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

fun main() {
    io.apply {

        val a = int
        val b = int
        val c = int
        cout .. arrayOf(a + b + c, a * b + c, a * (b + c), (a + b) * c, a + b * c, a * b * c).max()!! .. 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 func :(Int , Int , Int) -> Unit = {n1,n2,n3 ->
        var arr = arrayOf(0,0,0,0)
        arr[0] = n1 + n2 + n3
        arr[1] = (n1 + n2) * n3
        arr[2] = n1 * (n2 + n3)
        arr[3] = n1 * n2 * n3
        println(arr.max())
    }
    func(readLine()!!.toInt() , readLine()!!.toInt() , readLine()!!.toInt())

}

import java.lang.Integer.max

fun main(args: Array<String>) {
    var first = readLine()!!.toInt()
    var second = readLine()!!.toInt()
    var third = readLine()!!.toInt()

    println(
            arrayOf(
                    first * second * third,
                    (first + second) * third,
                    first * (second + third),
                    first + second + third,
                    first + second * third,
                    first * second + third
            ).max()
    )
}

fun main(args: Array<String>) = println(arrayOf(readLine()!!, readLine()!!, readLine()!!).map(String::toInt).let { (a, b, c) -> arrayOf(a + b + c, a * b * c, a + b * c, a * b + c, (a + b) * c, a * (b + c)).max() })

fun main() {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()

    println(listOf(a*b*c, a*b+c, a*(b+c), a+b*c, (a+b)*c, a+b+c).max())
}

import java.util.*

/**
 * Created by v.shipugin on 30/08/2018
 */

fun main(args: Array<String>) {
    Cont274().first()
}

class Cont274 {

    fun first() {
        val scanner = Scanner(System.`in`)

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

        val fist = a + b + c
        val second = (a + b) * c
        val third = a * (b + c)
        val foufh = a * b * c

        println(
                Math.max(
                        Math.max(fist, second),
                        Math.max(third, foufh)
                )
        )
    }
}

fun main(args : Array<String>) {
    var arr = IntArray(3)
    for (i in 0..2)
        arr[i] = readLine()!!.toInt()
    var ans1 = 0
    var ans2 = 0
    var max = arr[0] * arr[1]

    if (arr[0] + arr[1] > max)
        max = arr[0] + arr[1]

    if (max * arr[2] > max + arr[2])
        ans1 = max * arr[2]
    else
        ans1 = max * arr[2]

    max = arr[1] * arr[2]
    if (arr[1] + arr[2] > max)
        max = arr[1] + arr[2]
    if (max * arr[0] > max + arr[0])
        ans2 = max * arr[0]
    else
        ans2 = max + arr[0]

    if (ans1 > ans2)
        println(ans1)
    else
        println(ans2)
}

import java.util.*

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

    val case1 = (a + b) * c
    val case6 = a * b + c

    val case2 = a + b + c
    val case3 = a * b * c

    val case4 = a * b + c
    val case5 = a * (b + c)

    val result = arrayOf(case1, case2, case3, case4, case5, case6)

    println(result.max())
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val nums = Array(3){0}
    for (i in 0 until 3){
        nums[i] = br.readLine().toInt()
    }
    val a = nums[0]
    val b = nums[1]
    val c = nums[2]
    val options = listOf(
        a + b + c,
        a * b * c,
        (a + b)*c,
        a*(b + c),
        a*b + c,
        a + b*c
    )
    println(options.max())
}

//package problem479A

fun main() {
    val numbers = listOf(readLine()!!, readLine()!!, readLine()!!).map { it.toInt() }

    val possibilities = mutableListOf(numbers.reduce { acc, i -> acc * i }, numbers.sum())
    possibilities.add(numbers[0] + numbers[1] * numbers[2])
    possibilities.add((numbers[0] + numbers[1]) * numbers[2])
    possibilities.add(numbers[0] * numbers[1] + numbers[2])
    possibilities.add(numbers[0] * (numbers[1] + numbers[2]))

    println(possibilities.max())
}

fun main(){
    val list=ArrayList<Int>()
    for(i in 0..2){
        list.add(readLine()!!.toInt())
    }
    val list2=ArrayList<Int>()
    list2.add((list[0]+list[1])*list[2])
    list2.add(list[0]+(list[1]*list[2]))
    list2.add(list[0]*list[1]*list[2])
    list2.add((list[0]*list[1])+list[2])
    list2.add(list[0]*(list[1]+list[2]))
    list2.add(list[0]+list[1]+list[2])
    print(list2.max())
}

import com.sun.xml.internal.fastinfoset.util.StringArray
import java.awt.List
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.min

fun main() {
    var sc = Scanner(System.`in`)
    var a = sc.nextInt()
    var b = sc.nextInt()
    var c = sc.nextInt()

    var max = 0
    if (a * b * c > max) max = a * b * c
    if ((a + b) * c > max) max = (a + b) * c
    if (a * (b + c) > max) max = a * (b + c)
    if (a * b + c > max) max = a * b + c
    if (a + b + c > max) max = a + b + c

    println(max)
}

fun main(args: Array<String>) {
    val (a, b, c) = (1..3).map { readLine()!!.toInt() }

    val m = arrayOf(a * b + c, a * (b + c), a + b * c, (a + b) * c, a + b + c, a * b * c).max()!!

    println(m)
}

import java.lang.Math.*

fun main(){

    val a = readLine()?.toInt() ?: 1
    val b = readLine()?.toInt() ?: 1
    val c = readLine()?.toInt() ?: 1

    var answer = a + b + c
    answer = max(answer, a.plus(b).times(c))
    answer = max(answer, a.times(b.plus(c)))
    answer = max(answer, a.times(b).times(c))

    println(answer)
}

fun main() {
    val a = readLine()!!.toInt()
    val b = readLine()!!.toInt()
    val c = readLine()!!.toInt()

    println(arrayOf(
        a + b + c,
        a + b * c,
        a * b * c,
        a * b + c,
        a * (b + c),
        (a + b) * c
    ).max())
}

import java.util.*

fun main (args:Array<String>)
{
    var a:Int= readLine()!!.toInt()
    var b: Int= readLine()!!.toInt()
    var c:Int= readLine()!!.toInt()
    var Max:Int=0
    if(a+b*c>Max)
        Max=a+b*c
     if(a*(b+c)>Max)
        Max=a*(b+c)
     if((a*b*c)>Max)
        Max=(a*b*c)
     if((a+b)*c>Max)
        Max=(a+b)*c
    if(a+b+c>Max)
    Max=a+b+c
System.out.println(Max)
}

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

val alg1 = { i1: Int, i2: Int, i3: Int -> i1 + i2 * i3 }
val alg2 = { i1: Int, i2: Int, i3: Int -> i1 * (i2 + i3) }
val alg3 = { i1: Int, i2: Int, i3: Int -> i1 * i2 * i3 }
val alg4 = { i1: Int, i2: Int, i3: Int -> (i1 + i2) * i3 }
val alg5 = { i1: Int, i2: Int, i3: Int -> i1 + i2 + i3 }
val alg6 = { i1: Int, i2: Int, i3: Int -> i1 * i2 + i3 }

fun main(args: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val arg1 = reader.readLine().toInt()
    val arg2 = reader.readLine().toInt()
    val arg3 = reader.readLine().toInt()
    val answers = listOf(alg1(arg1, arg2, arg3),
            alg2(arg1, arg2, arg3),
            alg3(arg1, arg2, arg3),
            alg4(arg1, arg2, arg3),
            alg5(arg1, arg2, arg3),
            alg6(arg1, arg2, arg3))
    println(answers.max())
}

fun main(args: Array<String>) {
    val (a,b,c) = Array(3, { readLine()!!.toInt()})
    println(arrayOf(a*b*c,(a+b)*c,a*(b+c),a+b+c).max())
}

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

    fun addOrMultiply(x: Int, y: Int): Int {
        if (x == 1 || y == 1) {
            return x + y
        }
        else {
            return x * y
        }
    }

    val larger = maxOf(a, c)
    val smaller = minOf(a, c)
    println(addOrMultiply(addOrMultiply(smaller, b), larger))
}

import kotlin.math.max

fun main(args : Array<String>){

    var X = readLine()!!.toInt()
    var Y = readLine()!!.toInt()
    var Z = readLine()!!.toInt()

    println(MAX(X+Y+Z,X*Y*Z,(X+Y)*Z,X*(Y+Z)))

                              }

fun MAX(V:Int,X:Int,Y:Int,Z:Int) : Int {
        if (V > X && V > Y && V > Z)
            return V

        else if (X > V && X > Y && X > Z)
            return X

        else if (Y > V && Y > X && Y > Z)
            return Y

        else
            return Z
                                       }

fun main(args: Array<String>) {
	val a = readLine()!!.toInt()
	val b = readLine()!!.toInt()
	val c = readLine()!!.toInt()
	findMaxVal(a, b, c)
}

fun findMaxVal(a: Int, b: Int, c: Int){
	val maxOfSumAllAndProductAll = Integer.max(a*b*c, a + b + c)
	val maxOfPartialSumAll = Integer.max(partialSum(a, b, c), partialSum(c, b, a))
	val maxOfPartialSumBracesAll = Integer.max(partialSumBraces(a, b, c), partialSumBraces(c, b, a))
	println(Integer.max(Integer.max(maxOfSumAllAndProductAll, maxOfPartialSumAll),maxOfPartialSumBracesAll))
}
fun partialSum(a: Int, b: Int, c: Int): Int {
	return a+b*c
}
fun partialSumBraces(a: Int, b: Int, c: Int) = (a+b)*c

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

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */
fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun maxExp(list: MutableList<Int>): Int {
    val expr1 = list[0] + list[1] + list[2]
    val expr2 = list[0] * list[1] * list[2]
    val expr3 = list[0] + list[1] * list[2]
    val expr4 = list[0] * list[1] + list[2]
    val expr5 = list[0] * (list[1] + list[2])
    val expr6 = (list[0] + list[1]) * list[2]
    return max(max(max(max(max(expr1, expr2), expr3), expr4), expr5), expr6)
}
/*
fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    var counter = 0
    for (i in 0..2){
        if (list[i] == 1) counter++
    }
    return if(counter != 3) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            if(index!=0 && index!=2) {
                val minValue = min(list[index], list[index - 1])
                if (minValue == list[index]) list[index]++ else list[index - 1]++
            }
            else if(index == 0){
                list[index]++
            }
            else{
                list[index-1]++
            }
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }
*/

fun main(){
    val inputValues = readInputs().toMutableList()
    /*
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    */
    println(maxExp(inputValues))
}

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val a = r.readLine()!!.toInt()
    val b = r.readLine()!!.toInt()
    val c = r.readLine()!!.toInt()
    val max1 = maxOf(a+b*c, (a+b)*c)
    val max2 = maxOf(a*(b+c), a*b*c)
    println(maxOf(max1, max2))
}

fun main(args : Array<String>) {
    var arr = IntArray(3)
    for (i in 0..2)
        arr[i] = readLine()!!.toInt()
    arr.sort()
    var max = arr[0] * arr[1]
    if (arr[0] + arr[1] > max)
        max = arr[0] + arr[1]
    if (max * arr[2] > max + arr[2])
        println(max * arr[2])
    else
        println(max + arr[2] )
}

fun main(args : Array<String>) {
    var arr = IntArray(3)
    for (i in 0..2)
        arr[i] = readLine()!!.toInt()
    var max = arr[0] * arr[1]
    if (arr[0] + arr[1] > max)
        max = arr[0] + arr[1]
    if (max * arr[2] > max + arr[2])
        println(max * arr[2])
    else
        println(max + arr[2] )
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val abc = Array(3){0}
    for (i in 0 until 3){
        abc[i] = br.readLine().toInt()
    }
    val nums = abc.sorted()
    println(
        if (nums[0] == 1){
            (nums[0] + nums[1]) * nums[2]
        } else if (nums.fold(true){acc, x -> x == 1 && acc}){
            nums[0] + nums[1] + nums[2]
        } else{
            nums[0] * nums[1] * nums[2]
        }
    )
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val abc = Array(3){0}
    for (i in 0 until 3){
        abc[i] = br.readLine().toInt()
    }
    val nums = abc.sorted()
    println(
        if (nums.fold(true){acc, x -> x == 1 && acc}){
            (nums[0] + nums[1]) * nums[2]
        } else if (nums[0] == 1){
            nums[0] + nums[1] + nums[2]
        } else{
            nums[0] * nums[1] * nums[2]
        }
    )
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val nums = Array(3){0}
    for (i in 0 until 3){
        nums[i] = br.readLine().toInt()
    }
    println(
        if (nums.fold(true){acc, x -> x == 1 && acc}){
            nums[0] + nums[1] + nums[2]
        } else if (nums[0] == 1){
            (nums[0] + nums[1]) * nums[2]
        } else{
            nums[0] * nums[1] * nums[2]
        }
    )
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val abc = Array(3){0}
    for (i in 0 until 3){
        abc[i] = br.readLine().toInt()
    }
    val nums = abc.sorted()
    println(
        if (nums.fold(true){acc, x -> x == 1 && acc}){
            nums[0] + nums[1] + nums[2]
        } else if (nums[0] == 1){
            (nums[0] + nums[1]) * nums[2]
        } else{
            nums[0] * nums[1] * nums[2]
        }
    )
}

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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val abc = Array(3){0}
    for (i in 0 until 3){
        abc[i] = br.readLine().toInt()
    }
    val nums = abc.sorted()
    println(
        if (nums[0] == 1){
            (nums[0] + nums[1]) * nums[2]
        } else{
            nums[0] * nums[1] * nums[2]
        }
    )
}

import java.lang.Math.*

fun main(){

    val a = readLine()?.toInt() ?: 1
    val b = readLine()?.toInt() ?: 1
    val c = readLine()?.toInt() ?: 1

    if (a != 1 && b != 1 && c != 1)
        println(a.times(b).times(c))
    else if(a == 1 && b == 1 && c == 1)
        println(a.plus(b).plus(c))
    else{
        val x = min(a, min(b,c))
        val y = if (a == x) min(b,c) else if (b == x) min(a,c) else min(a, b)
        println(x.plus(y).times(max(a, max(b,c))))

    }
}

import java.util.*

fun main (args:Array<String>)
{
    var a:Int= readLine()!!.toInt()
    var b: Int= readLine()!!.toInt()
    var c:Int= readLine()!!.toInt()
    var Max:Int=0
    if(a+b*c>Max)
        Max=a+b*c
     if(a*(b+c)>Max)
        Max=a*(b+c)
     if((a*b*c)>Max)
        Max=(a*b*c)
     if((a+b)*c>Max)
        Max=(a+b)*c
System.out.println(Max)
}

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

val alg1 = { i1: Int, i2: Int, i3: Int -> i1 + i2 * i3 }
val alg2 = { i1: Int, i2: Int, i3: Int -> i1 * (i2 + i3) }
val alg3 = { i1: Int, i2: Int, i3: Int -> i1 * i2 * i3 }
val alg4 = { i1: Int, i2: Int, i3: Int -> (i1 + i2) * i3 }

fun main(args: Array<String>) {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val arg1 = reader.readLine().toInt()
    val arg2 = reader.readLine().toInt()
    val arg3 = reader.readLine().toInt()
    val answers = listOf(alg1(arg1, arg2, arg3),
            alg2(arg1, arg2, arg3),
            alg3(arg1, arg2, arg3),
            alg4(arg1, arg2, arg3))
    println(answers.max())
}

fun main(args: Array<String>) {
    val (a,b,c) = Array(3, { readLine()!!.toInt()})
    println(arrayOf(a*b*c,(a+b)*c,a*(b+c)).max())
}

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

    fun addOrMultiply(x: Int, y: Int): Int {
        if (x == 1 || y == 1) {
            return x + y
        }
        else {
            return x * y
        }
    }

    println(addOrMultiply(addOrMultiply(a, b), c))
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    val checkList = list intersect listOf(1, 1)
    return if(checkList != listOf(1, 1) && checkList != listOf(1, 1, 1)) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            list[index]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    val checkList = list intersect listOf(1, 1, 1)
    return if(checkList.size < 2) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            list[index]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

import kotlin.math.min

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */
fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    var counter = 0
    for (i in 0..2){
        if (list[i] == 1) counter++
    }
    return if(counter != 3) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            if(index!=0 && index!=2) {
                val minValue = min(list[index], list[index - 1])
                if (minValue == list[index]) list[index]++ else list[index - 1]++
            }
            else if(index == 0){
                list[index]++
            }
            else{
                list[index-1]++
            }
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    return if(list != listOf(1, 1, 1)) {
        if (list.contains(1)) {
            list.remove(1)
            list[list.lastIndex]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */
fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    var counter = 0
    for (i in 0..2){
        if (list[i] == 1) counter++
    }
    return if(counter < 2) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            list[index]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    val checkList = list intersect listOf(1, 1, 1)
    return if(checkList != setOf(1, 1) && checkList != setOf(1, 1, 1)) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            list[index]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    return if(list != listOf(1, 1, 1)) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            list[index]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList.sortedDescending().toMutableList()
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    if(list.contains(1)){
        list.remove(1)
        list[list.lastIndex] ++
    }
    return list.toList()
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */

fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList.sortedDescending().toMutableList()
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    return if(list != listOf(1, 1, 1)) {
        if (list.contains(1)) {
            list.remove(1)
            list[list.lastIndex]++
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}

import kotlin.math.min

/**
 * Petya studies in a school and he adores Maths. His class has been studying arithmetic expressions. On the last
 * class the teacher wrote three positive integers a, b, c on the blackboard. The task was to insert signs of
 * operations '+' and '*', and probably brackets between the numbers so that the value of the resulting expression is
 * as large as possible. Let's consider an example: assume that the teacher wrote numbers 1, 2 and 3 on the blackboard.
 * Here are some ways of placing signs and brackets:
 * 1+2*3=7
 * 1*(2+3)=5
 * 1*2*3=6
 * (1+2)*3=9
 * Note that you can insert operation signs only between a and b, and between b and c, that is, you cannot swap integers.
 * For instance, in the given sample you cannot get expression (1+3)*2.
 * It's easy to see that the maximum value that you can obtain is 9.
 * Your task is: given a, b and c print the maximum value that you can get.
 *
 * Input
 * The input contains three integers a, b and c, each on a single line (1 ≤ a, b, c ≤ 10).
 *
 * Output
 * Print the maximum value of the expression that you can obtain.
 */
fun readInt(): Int = readLine()!!.toInt()

fun readInputs():MutableList<Int> {
    val inputList:MutableList<Int> = mutableListOf()
    for (i in 0..2){
        inputList += listOf(readInt())
    }
    return inputList
}

fun sum0and1(list: MutableList<Int>):List<Int>{
    if (list.contains(0)) {
        list.remove(0)
    }
    var counter = 0
    for (i in 0..2){
        if (list[i] == 1) counter++
    }
    return if(counter < 2) {
        if (list.contains(1)) {
            val index = list.indexOf(1)
            list.remove(1)
            if(index!=0 && index!=2) {
                val minValue = min(list[index], list[index - 1])
                if (minValue == list[index]) list[index]++ else list[index - 1]++
            }
            else if(index == 0){
                list[index]++
            }
            else{
                list[index-1]++
            }
        }
        list.toList()
    }
    else {
        listOf(list.reduce { acc: Int, i: Int -> acc + i }.toInt())
    }
}

fun maxResult(list: List<Int>): Int = list.reduce { acc, i -> acc * i }

fun main(){
    val inputValues = readInputs().toMutableList()
    val filteredList = sum0and1(inputValues)
    val result = maxResult(filteredList)
    println(result)
}


There is a very secret base in Potatoland where potato mash is made according to a special recipe. The neighbours from Porridgia decided to seize this recipe and to sell it to Pilauland. For this mission they have been preparing special agent Pearlo for many years. When, finally, Pearlo learned all secrets of espionage, he penetrated into the Potatoland territory and reached the secret base.Now he is standing at the entrance, but to get inside he need to pass combination lock. Minute ago one of the workers entered the password on the terminal and opened the door. The terminal is a square digital keyboard 3 × 3 with digits from 1 to 9.Pearlo knows that the password consists from distinct digits and is probably symmetric with respect to the central button of the terminal. He has heat sensor which allowed him to detect the digits which the worker pressed. Now he wants to check whether the password entered by the worker is symmetric with respect to the central button of the terminal. This fact can Help Pearlo to reduce the number of different possible password combinations.

Input contains the matrix of three rows of three symbols each. Symbol «X» means that the corresponding button was pressed, and «.» means that is was not pressed. The matrix may contain no «X», also it may contain no «.».

Print YES if the password is symmetric with respect to the central button of the terminal and NO otherwise.

NoteIf you are not familiar with the term «central symmetry», you may look into http://en.wikipedia.org/wiki/Central_symmetry

import java.util.Scanner

fun main(args : Array<String>) {

    var line1: MutableList<Char> = mutableListOf()
    var line2: MutableList<Char> = mutableListOf()
    var line3: MutableList<Char> = mutableListOf()
    val a = readLine()!!
    val b = readLine()!!
    val c = readLine()!!

    for (char in a) { line1.add(char) }
    for (char in b) { line2.add(char) }
    for (char in c) { line3.add(char) }

    if(line1[0]==line1[2] && line2[0]==line2[2] && line3[0]==line3[2] && line1[1]==line3[1]){
        println("YES")
    }
    else if(line1[0]==line3[0] && line1[1]==line3[1] && line1[2]==line3[2] && line2[0]==line2[2]){
        println("YES")
    }
    else if(line1[0]==line3[2] && line1[1]==line3[1] && line1[2]==line3[0] && line2[0]==line2[2]){
        println("YES")
    }
    else {
        println("NO")

    }

}

fun main(args: Array<String>) {
    val a = Array(3) {readLine()}
    var bad = false
    for (i in 0 until 3)
        for (j in 0 until 3)
            bad = bad or (a[i]!![j] != a[2 - i]!![2 - j])
    println(if (bad) "NO" else "YES")
}

fun main() {
    val board = Array(3) { "" }
    board[0] = readLine()!!
    board[1] = readLine()!!
    board[2] = readLine()!!
    for (row in 0 until 2)
        for (column in 0 until 3)
            if (board[row][column] != board[2 - row][2 - column]) return print("NO")
    print("YES")
}

fun main(args: Array<String>) {

    val matrix = Array(3){""}
    for (x in 0 until 3) matrix[x] = readLine()!!
    when {
        matrix[0][0] != matrix[2][2] -> print("NO")
        matrix[0][1] != matrix[2][1] -> print("NO")
        matrix[0][2] != matrix[2][0] -> print("NO")
        matrix[1][0] != matrix[1][2] -> print("NO")
        else -> print("YES")
    }
}


Bob loves everything sweet. His favorite chocolate bar consists of pieces, each piece may contain a nut. Bob wants to break the bar of chocolate into multiple pieces so that each part would contain exactly one nut and any break line goes between two adjacent pieces.You are asked to calculate the number of ways he can do it. Two ways to break chocolate are considered distinct if one of them contains a break between some two adjacent pieces and the other one doesn't. Please note, that if Bob doesn't make any breaks, all the bar will form one piece and it still has to have exactly one nut.

The first line of the input contains integer n (1 ≤ n ≤ 100) — the number of pieces in the chocolate bar. The second line contains n integers ai (0 ≤ ai ≤ 1), where 0 represents a piece without the nut and 1 stands for a piece with the nut.

Print the number of ways to break the chocolate into multiple parts so that each part would contain exactly one nut.

NoteIn the first sample there is exactly one nut, so the number of ways equals 1 — Bob shouldn't make any breaks.In the second sample you can break the bar in four ways:10|10|11|010|110|1|011|01|01

fun main() {
    data class R(var t: Long, var m: Int, var f: Boolean)
    readLine()
    readLine()!!.split(" ").fold(R(1, 1, true)) { acc, i ->
        if (i == "1") {
            if (!acc.f) acc.t *= acc.m
            acc.m = 1
            acc.f = false
        } else {
            acc.m++
        }
        acc
    }.run { print(if (f) 0 else t) }
}

fun main() {
    data class R(var t: Long, var m: Int, var f: Boolean)
    readLine()
    readLine()!!.split(" ").fold(R(1, 1, true)) { acc, i ->
        if (i == "1") {
            if (!acc.f) acc.t *= acc.m
            acc.m = 1
            acc.f = false
        } else {
            acc.m++
        }
        acc
    }.run { print(t) }
}


The king is left alone on the chessboard. In spite of this loneliness, he doesn't lose heart, because he has business of national importance. For example, he has to pay an official visit to square t. As the king is not in habit of wasting his time, he wants to get from his current position s to square t in the least number of moves. Help him to do this.  In one move the king can get to the square that has a common side or a common vertex with the square the king is currently in (generally there are 8 different squares he can move to).

The first line contains the chessboard coordinates of square s, the second line — of square t. Chessboard coordinates consist of two characters, the first one is a lowercase Latin letter (from a to h), the second one is a digit from 1 to 8.

In the first line print n — minimum number of the king's moves. Then in n lines print the moves themselves. Each move is described with one of the 8: L, R, U, D, LU, LD, RU or RD.  L, R, U, D stand respectively for moves left, right, up and down (according to the picture), and 2-letter combinations stand for diagonal moves. If the answer is not unique, print any of them.

import java.util.Scanner

fun main(args : Array<String>) {

    var coor1: MutableList<Char> = mutableListOf()
    var coor2: MutableList<Char> = mutableListOf()
    val n = readLine()!!
    val m = readLine()!!

    for(char in n){ coor1.add(char) }
    for(char in m){ coor2.add(char) }

    if(coor1[0]==coor2[0] && coor1[1]==coor2[1]){ println(0) }
    else if(coor1[0]==coor2[0] && coor1[1]>coor2[1]){
        println(coor1[1]-coor2[1])
        for(i in 1..(coor1[1]-coor2[1])){ println("D") }
    }
    else if(coor1[0]==coor2[0] && coor1[1]<coor2[1]){
        println(coor2[1]-coor1[1])
        for(i in 1..(coor2[1]-coor1[1])){ println("U") }
    }
    else if(coor1[1]==coor2[1] && coor1[0]<coor2[0]){
        println(coor2[0]-coor1[0])
        for(i in 1..(coor2[0]-coor1[0])){ println("R") }
    }
    else if(coor1[1]==coor2[1] && coor1[0]>coor2[0]){
        println(coor1[0]-coor2[0])
        for(i in 1..(coor1[0]-coor2[0])){ println("L") }
    }
    else if(coor1[1]<coor2[1] && coor1[0]<coor2[0]){
        if((coor2[1]-coor1[1])<(coor2[0]-coor1[0])){
            println((coor2[0]-coor1[0]))
            for(i in 1..(coor2[1]-coor1[1])){ println("RU") }
            for(i in 1..(coor2[0]-coor1[0])-(coor2[1]-coor1[1])){ println("R") }
        }
        else if((coor2[1]-coor1[1])>(coor2[0]-coor1[0])){
            println((coor2[1]-coor1[1]))
            for(i in 1..(coor2[0]-coor1[0])){ println("RU") }
            for(i in 1..(coor2[1]-coor1[1])-(coor2[0]-coor1[0])){ println("U") }
        }
        else {
            println((coor2[1] - coor1[1]))
            for (i in 1..(coor2[0] - coor1[0])) { println("RU") }
        }
    }
    else if(coor1[1]>coor2[1] && coor1[0]<coor2[0]){
        if((coor1[1]-coor2[1])<(coor2[0]-coor1[0])){
            println((coor2[0]-coor1[0]))
            for(i in 1..(coor1[1]-coor2[1])){ println("RD") }
            for(i in 1..(coor2[0]-coor1[0])-(coor1[1]-coor2[1])){ println("R") }
        }
        else if((coor1[1]-coor2[1])>(coor2[0]-coor1[0])){
            println((coor1[1]-coor2[1]))
            for(i in 1..(coor2[0]-coor1[0])){ println("RD") }
            for(i in 1..(coor1[1]-coor2[1])-(coor2[0]-coor1[0])){ println("D") }
        }
        else {
            println((coor1[1] - coor2[1]))
            for (i in 1..(coor1[1] - coor2[1])) { println("RD") }
        }
    }
    else if(coor1[1]<coor2[1] && coor1[0]>coor2[0]){
        if((coor2[1]-coor1[1])<(coor1[0]-coor2[0])){
            println((coor1[0]-coor2[0]))
            for(i in 1..(coor2[1]-coor1[1])){ println("LU") }
            for(i in 1..(coor1[0]-coor2[0])-(coor2[1]-coor1[1])){ println("L") }
        }
        else if((coor2[1]-coor1[1])>(coor1[0]-coor2[0])){
            println((coor2[1]-coor1[1]))
            for(i in 1..(coor1[0]-coor2[0])){ println("LU") }
            for(i in 1..(coor2[1]-coor1[1])-(coor1[0]-coor2[0])){ println("U") }
        }
        else {
            println((coor2[1] - coor1[1]))
            for (i in 1..(coor2[1] - coor1[1])) { println("LU") }
        }
    }
    else if(coor1[1]>coor2[1] && coor1[0]>coor2[0]){
        if((coor1[1]-coor2[1])<(coor1[0]-coor2[0])){
            println((coor1[0]-coor2[0]))
            for(i in 1..(coor1[1]-coor2[1])){ println("LD") }
            for(i in 1..(coor1[0]-coor2[0])-(coor1[1]-coor2[1])){ println("L") }
        }
        else if((coor1[1]-coor2[1])>(coor1[0]-coor2[0])){
            println((coor1[1]-coor2[1]))
            for(i in 1..(coor1[0]-coor2[0])){ println("LD") }
            for(i in 1..(coor1[1]-coor2[1])-(coor1[0]-coor2[0])){ println("D") }
        }
        else {
            println((coor1[1] - coor2[1]))
            for (i in 1..(coor1[1] - coor2[1])) { println("LD") }
        }
    }
}

import kotlin.math.abs

fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val (s, n) = r.readLine()!!.split(" ").map { it.toInt() }
    //val n = r.readLine()!!.toInt()
    val st = r.readLine()!!
    val en = r.readLine()!!
    var right = en[0].toInt() - st[0].toInt()
    var up = en[1].toInt() - st[1].toInt()
    println(maxOf(abs(right), abs(up)))
    var ans = 0
    while (up != 0 || right != 0) {
        when {
            up != 0 && right != 0 -> {
                when {
                    up > 0 && right > 0 -> {
                        println("RU")
                        up--
                        right--
                    }
                    up > 0 && right < 0 -> {
                        println("LU")
                        up--
                        right++
                    }
                    up < 0 && right > 0 -> {
                        println("RD")
                        up++
                        right--
                    }
                    up < 0 && right < 0 -> {
                        println("LD")
                        up++
                        right++
                    }
                }
            }
            up == 0 -> if (right>0){
                println("R")
                right--
            } else{
                println("L")
                right++
            }
            right==0->if (up>0){
                println("U")
                up--
            }else{
                println("D")
                up++
            }
        }
    }
}

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

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

val out=mutableListOf<String>()
fun printLine(s:String){out.add(s)}
fun output(){println(out.joinToString("\n"))}

fun main(){
    var a=readLn()
    var b=readLn()
    var x=abs(a[0]-b[0])
    var y=abs(a[1]-b[1])
    var ch1=if(a[0]>b[0])'L' else 'R'
    var ch2=if(a[1]>b[1])'D' else 'U'
    printLine("${max(x,y)}")
    repeat(min(x,y)){printLine("$ch1$ch2")}
    for(i in 1..x-y){printLine("$ch1")}
    for(i in 1..y-x){printLine("$ch2")}
    output()
}

import java.util.Scanner
import java.lang.Math.*

class Cell(s : String) {
    val col = s[0] - 'a'
    val row = s[1].toInt()
}

fun move(source: Cell, target: Cell) {
    var deltaCol = target.col - source.col
    var deltaRow = target.row - source.row
    val absoluteCol = abs(deltaCol)
    val absoluteRow = abs(deltaRow)
    val steps = max(absoluteCol, absoluteRow)
    println(steps)
    for (i in 0 until steps) {
        if (deltaCol > 0) {
            print('R')
            deltaCol--
        } else if (deltaCol < 0) {
            print('L')
            deltaCol++
        }

        if (deltaRow > 0) {
            print('U')
            deltaRow--
        } else if (deltaRow < 0) {
            print('D')
            deltaRow++
        }

        println()
    }
}

fun main() {
    val scanner = Scanner(System.`in`)
    val source = Cell(scanner.nextLine())
    val target = Cell(scanner.nextLine())
    move(source, target)
}

fun a3() {
    var result = arrayOf<String>()
    var first = ""
    var second = ""
    var intSize : Int
    var charSize : Int
    val loopSize : Int

    val start = readLine()!!
    val end = readLine()!!

    if (start[1].toInt() > end[1].toInt()) {
        intSize = start[1].toInt() - end[1].toInt()
        second = "D"
    } else {
        intSize = end[1].toInt() - start[1].toInt()
        second = "U"
    }

    if (start[0] > end[0]) {
        charSize = start[0] - end[0]
        first = "L"
    } else {
        charSize = end[0] - start[0]
        first = "R"
    }

    loopSize = if(intSize > charSize) intSize else charSize

    for (i in 0 until loopSize) {
        if(intSize <= 0) second = ""
        if(charSize <= 0) first = ""

        intSize--
        charSize--

        result += "$first$second"
    }

    println(loopSize)
    result.forEach {
        println(it)
    }
}

fun main() {
    a3()
}

import java.util.*

fun main(args: Array<String>) {
    main { readLine() }
}

fun main(readLine: () -> String?) {
    val problem = readProblem(readLine)
    val solution = solve(problem)
    printSolution(solution)
}

// READ

fun readProblem(readLine: () -> String?): Problem {
    val start = Position.parse(readLine()!!.trim())
    val target = Position.parse(readLine()!!.trim())
    return Problem(start, target)
}

class Position (val x: Int, val y: Int) {
    companion object {
        fun parse(str: String): Position {
            return Position(
                    str[0].toInt() - 'a'.toInt(),
                    str[1].toInt() - '0'.toInt()
            )
        }
    }

    override fun toString(): String {
        return "($x - $y)"
    }
}

class Problem (val from: Position, val to: Position)

// SOLVE PROBLEM

fun solve(problem: Problem): Answer {
    val answer = Answer()
    var xd = problem.to.x - problem.from.x
    var yd = problem.to.y - problem.from.y
    when {
        (xd < 0 && yd < 0) -> {
            val len = if (-xd < -yd) { -xd } else { -yd }
            xd += len
            yd += len
            answer.go(Direction.LD, len)
        }
        (xd < 0 && yd > 0) -> {
            val len = if (-xd < yd) { -xd } else { yd }
            xd += len
            yd -= len
            answer.go(Direction.LU, len)
        }
        (xd > 0 && yd > 0) -> {
            val len = if (xd < yd) { xd } else { yd }
            xd -= len
            yd -= len
            answer.go(Direction.RU, len)
        }
        (xd > 0 && yd < 0) -> {
            val len = if (xd < -yd) { xd } else { -yd }
            xd -= len
            yd += len
            answer.go(Direction.RD, len)
        }
    }
    when {
        (xd < 0) -> {
            answer.go(Direction.L, -xd)
        }
        (xd > 0) -> {
            answer.go(Direction.R, xd)
        }
        (yd < 0) -> {
            answer.go(Direction.D, -yd)
        }
        (yd > 0) -> {
            answer.go(Direction.U, yd)
        }
    }
    return answer
}

// PRINT SOLUTION

class Answer () {
    private val segments: MutableList<Segment> = ArrayList()

    fun go(dir: Direction, length: Int) {
        if (length > 0) {
            segments.add(Segment(dir, length))
        }
    }

    fun print(consumer: (String) -> Unit) {
        val length = segments.map { it.length } .sum()
        consumer(length.toString())
        for (seg in segments) {
            for (i in 1..seg.length) {
                consumer(seg.dir.name)
            }
        }
    }
}

class Segment(val dir: Direction, val length: Int) {
    override fun toString(): String {
        val sb = StringBuilder()
        for (i in 1..length) {
            sb.append(dir)
        }
        return sb.toString()
    }
}

enum class Direction() {
    L, LD, D, RD, R, RU, U, LU
}

fun printSolution(solution: Answer) {
    solution.print { println(it) }
}

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

fun main() {
    val from = readLine()!!
    val to = readLine()!!
    var horizontal = from[0] - to[0]
    var vertical = from[1] - to[1]
    println(max(abs(horizontal), abs(vertical)))
    while (horizontal != 0 || vertical != 0) {
        when {
            horizontal < 0 -> {
                print('R'); horizontal++
            }
            horizontal > 0 -> {
                print('L'); horizontal--
            }
        }
        when {
            vertical < 0 -> {
                print('U'); vertical++
            }
            vertical > 0 -> {
                print('D'); vertical--
            }
        }
        println()
    }
}

import kotlin.math.abs

private fun readLn() = readLine()!!

fun main() {
    val s = readLn().toCharArray()
    val d = readLn().toCharArray()

    var dr: Int = abs(s[0] - d[0])
    var dw: Int = abs(s[1] - d[1])

    val n = maxOf(dr, dw)
    println(n)
    repeat(n) {
        if(dr>0) {
            if (s[0] > d[0]) {
                s[0]--
                print("L")
            } else {
                s[0]++
                print("R")
            }
            dr--
        }
        if(dw>0) {
            if (s[1] > d[1]) {
                s[1]--
                print("D")
            } else {
                s[1]++
                print("U")
            }
            dw--
        }
        println()
    }
}

fun main() {
    val s = readLine()!!.toCharArray()
    val d = readLine()!!.toCharArray()
    var hori = s[0] - d[0]
    var vert = s[1] - d[1]
    if (hori >= 0 && vert >= 0) { // a8 - h1 = 7 fin
        if (hori > vert) {
            println(hori)
        } else {
            println(vert)
        }
    } else if (hori <= 0 && vert >= 0) {
        if (-hori > vert) {
            println(-hori)
        } else {
            println(vert)
        }
    } else if (hori >= 0 && vert <= 0) {
        if (hori > -vert) {
            println(hori)
        } else {
            println(-vert)
        }
    } else { // hori and vert are negative , (-x,0)
        if (-hori < -vert) {
            println(-vert)
        } else {
            println(-hori)
        }
    }
    while (hori != 0 || vert != 0) { // add or sub until equals to 0
        //println("$hori $vert")
        if (hori < 0) {
            print('R')
            hori++
        } else if (hori > 0) {
            print('L')
            hori--
        }
        if (vert < 0) {
            print('U')
            vert++
        } else if (vert > 0) {
            print('D')
            vert--
        }
        println()
    }
}

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

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

    var start = reader.nextLine().trim()
    var end = reader.nextLine().trim()

    var x = start[0] - end[0]
    var y = start[1] - end[1]

    val res = max(abs(x), abs(y))
    println(res)
    repeat(res) {
        if (x > 0) {
            print('L')
            x--
        }
        if (x < 0) {
            print('R')
            x++
        }
        if (y > 0) {
            print('D')
            y--
        }
        if (y < 0) {
            print('U')
            y++
        }
        println()
    }
}

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

fun main (args: Array<String>)
{
    val first: String = readString1()
    val second: String = readString1()

    var x1: Int = 0
    var y1: Int = 0
    var x2: Int = 0
    var y2: Int = 0

    x1 = first.get(0).toInt() - 'a'.toInt()
    y1 = first.get(1).toString().toInt()-1

    x2 = second.get(0).toInt() - 'a'.toInt()
    y2 = second.get(1).toString().toInt()-1

    var c: Int = 0
    var r: MutableList<String> = mutableListOf()

    while (!(x1==x2&&y1==y2))
    {

        var m: String = ""

        if(x1 > x2)
        {
            x1--
            m+="L"
        }
        else if(x1 < x2)
        {
            x1++
            m+="R"
        }

        if(y1 > y2)
        {
            y1--
            m+="D"
        }
        else if(y1 < y2)
        {
            y1++
            m+="U"
        }
        r.add(m)
        c++
    }
    print(r.joinToString(separator = "\n",prefix = ("$c\n")))

}

fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val (s, n) = r.readLine()!!.split(" ").map { it.toInt() }
    //val n = r.readLine()!!.toInt()
    val st = r.readLine()!!
    val en = r.readLine()!!
    var right = en[0].toInt() - st[0].toInt()
    var up = en[1].toInt() - st[1].toInt()
    println(maxOf(right, up))
    var ans = 0
    while (up != 0 || right != 0) {
        when {
            up != 0 && right != 0 -> {
                when {
                    up > 0 && right > 0 -> {
                        println("RU")
                        up--
                        right--
                    }
                    up > 0 && right < 0 -> {
                        println("LU")
                        up--
                        right++
                    }
                    up < 0 && right > 0 -> {
                        println("RD")
                        up++
                        right--
                    }
                    up < 0 && right < 0 -> {
                        println("LD")
                        up++
                        right++
                    }
                }
            }
            up == 0 -> if (right>0){
                println("R")
                right--
            } else{
                println("L")
                right++
            }
            right==0->if (up>0){
                println("U")
                up--
            }else{
                println("D")
                up++
            }
        }
    }
}

fun main() {
    val s = readLine()!!.toCharArray()
    val d = readLine()!!.toCharArray()
    var hori = s[0]-d[0]
    var vert = s[1]-d[1]
    if(hori>0&&vert>0){ // a8 - h1 = 7 fin
        if(hori>vert){
            println(hori)
        }else{
            println(vert)
        }
    }else if(hori<0&&vert>0){
        if(-hori > vert){
            println(-hori)
        }else{
            println(vert)
        }
    }else if(hori>0&&vert<0){
        if(hori>-vert){
            println(hori)
        }else{
            println(-vert)
        }
    }else{ // hori and vert are negative
        if(hori>vert){
            println(-vert)
        }else{
            println(-hori)
        }
    }
    while (hori!=0||vert!=0){ // add or sub until equals to 0
        //println("$hori $vert")
        if(hori<0){
            print('R')
            hori++
        }else if(hori > 0){
            print('L')
            hori--
        }
        if(vert<0){
            print('U')
            vert++
        }else if(vert > 0){
            print('D')
            vert--
        }
        println()
    }
}

fun main() {
    val s = readLine()!!.toCharArray()
    val d = readLine()!!.toCharArray()
    var hori = s[0]-d[0]
    var vert = s[1]-d[1]
    if(hori>0&&vert>0){ // a8 - h1 = 7 fin
        if(hori>vert){
            println(hori)
        }else{
            println(vert)
        }
    }else if(hori<0&&vert>0){
        if(-hori > vert){
            println(-hori)
        }else{
            println(vert)
        }
    }else if(hori>0&&vert<0){
        if(hori>-vert){
            println(hori)
        }else{
            println(-vert)
        }
    }else{ // hori and vert are negative
        if(hori>vert){
            println(-vert)
        }else{
            println(-hori)
        }
    }
    while (hori!=0&&vert!=0){
        if(hori<0){
            print('R')
            hori++
        }else{
            print('L')
            hori--
        }
        if(vert<0){
            print('D')
            vert++
        }else{
            print('U')
            vert--
        }
        println()
    }
}

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

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

    var start = reader.nextLine().trim()
    var end = reader.nextLine().trim()

    var x = start[0] - end[0]
    var y = start[1] - end[1]

    val res = max(abs(x), abs(y))
    println(res)
    repeat(res) {
        if (x > 0) {
            print('L')
            x--
        }
        if (x < 0) {
            print('R')
            x++
        }
        if (y > 0) {
            println('D')
            y--
        }
        if (y < 0) {
            println('U')
            y++
        }
    }
}


As you may know, MemSQL has American offices in both San Francisco and Seattle. Being a manager in the company, you travel a lot between the two cities, always by plane.You prefer flying from Seattle to San Francisco than in the other direction, because it's warmer in San Francisco. You are so busy that you don't remember the number of flights you have made in either direction. However, for each of the last n days you know whether you were in San Francisco office or in Seattle office. You always fly at nights, so you never were at both offices on the same day. Given this information, determine if you flew more times from Seattle to San Francisco during the last n days, or not.

The first line of input contains single integer n (2 ≤ n ≤ 100) — the number of days. The second line contains a string of length n consisting of only capital 'S' and 'F' letters. If the i-th letter is 'S', then you were in Seattle office on that day. Otherwise you were in San Francisco. The days are given in chronological order, i.e. today is the last day in this sequence.

Print "YES" if you flew more times from Seattle to San Francisco, and "NO" otherwise. You can print each letter in any case (upper or lower).

NoteIn the first example you were initially at San Francisco, then flew to Seattle, were there for two days and returned to San Francisco. You made one flight in each direction, so the answer is "NO".In the second example you just flew from Seattle to San Francisco, so the answer is "YES".In the third example you stayed the whole period in San Francisco, so the answer is "NO".In the fourth example if you replace 'S' with ones, and 'F' with zeros, you'll get the first few digits of π in binary representation. Not very useful information though.

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    //val v = r.readLine()!!.split(" ").map { it.toLong() }
    val str = r.readLine()!!
    var sf = 0
    var fs = 0
    (0..n-2).forEach {
        when{
            str[it]=='S'&&str[it+1]=='F' -> sf++
            str[it]=='F'&&str[it+1]=='S' -> fs++
        }
    }
    println(if (sf>fs) "YES" else "NO")
}

fun main(args: Array<String>){
    val n = readLine()!!.toInt()
    val s = readLine()!!
    if (s[0]=='S' && s[n-1]=='F') println("YES") else println("NO")
}

fun main(args:Array<String>)
{
var n=readLine()!!
    var t=readLine()!!
    var switch=0
    var counter=0
    var counter1=0
    var flag=false
    var f=false
for(i in t) {
    if(i=='S')
    {
        f=true
    }
    if(i=='F'&&f)
    {
        f=false
        counter++;
    }
}
    f=false
    for(i in t) {
        if(i=='F')
        {
            f=true
        }
        if(i=='S'&&f)
        {
            f=false
            counter1++;
        }
    }

    println(if(counter>counter1) "YES" else "NO")
}

fun main(args: Array<String>) {
    readLine()
    val input = readLine()!!
    val chars = input.toCharArray()

    var previousChar = chars.first()
    var i = 0
    var sf = 0
    var fs = 0

    for (char in chars) {
        if (i > 0 && char != previousChar) {
            if (char == 'S') {
                fs += 1
            } else {
                sf += 1
            }
        }
        previousChar = char
        i += 1
    }

    if (sf > fs) println("YES") else println("NO")
}

/* https://codeforces.com/problemset/problem/867/A */

fun main() {
    readLine()!!.toInt() // read number of days
    val cityInitials = readLine()!!
    var tripsFromStoF = 0
    var tripsFromFtoS = 0
    var lastChar = '_'
    cityInitials.forEach {
        if (it == 'F' && lastChar == 'S') {
            tripsFromStoF++
        } else if (it == 'S' && lastChar == 'F') {
            tripsFromFtoS++
        }
        lastChar = it
    }
    println(if (tripsFromStoF > tripsFromFtoS) "YES" else "NO")
}

fun main() {
    val nightCount = Integer.parseInt(readLine()!!)
    val cities = readLine()!!
    var sf = 0
    var fs = 0
    for(i in 0 until nightCount - 1) {
        val flight = cities.substring(i, i + 2)
        when (flight) {
            "SF" -> sf++
            "FS" -> fs++
        }
    }

    if (sf > fs) {
        println("YES")
    } else {
        println("NO")
    }
}

fun main() {
    var n = readLine()!!.toInt()
    val line = readLine()!!.toCharArray()
    var SF = 0
    var FS = 0
    for (i in 0 until line.size-1)
    {
        if (line[i] == 'S' && line[i+1] == 'F')
            SF++
        else if (line[i] == 'F' && line[i+1] == 'S')
            FS++
    }

    if (SF > FS)
        print("YES")
    else
        print("NO")

}

fun main() {
    readLine()
    val s = readLine()

    var franCount = 0
    var sietlCount = 0
    var last = s!![0]
    for (c in s!!) {
        if(last != c) {
            if(c == 'F') {
                franCount++
            } else {
                sietlCount++
            }
            last = c
        }
    }

    if(franCount > sietlCount) print("Yes") else print("No")
}

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

fun main() {
    readInt()
    val flights = readLn()
    var f = 0
    var s = 0
    for (i in 1 until flights.length) {
        if (flights[i] != flights[i - 1]) {
            if (flights[i] == 'S') s++
            else f++
        }
    }
    if (f > s) println("yes") else println("no")
}

/**
 * Problem Link: https://codeforces.com/problemset/problem/867/A
 * Difficulty: 600
 */
fun main(args: Array<String>) {
    readLine()!!
    val s = readLine()!!
    var lastChar = ' '
    var SF = 0
    var FS = 0
    s.forEach { c ->
        if (lastChar == 'F' && c == 'S') {
            FS++
        }
        if (lastChar == 'S' && c == 'F') {
            SF++
        }
        lastChar = c
    }
    println("${if (SF > FS) "YES" else "NO"}")
}

import java.lang.StringBuilder
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.max

fun main() {
    var sc = Scanner(System.`in`)
    var n = sc.nextInt()
    var str = sc.next()
    var s = 0

    for (i in 1..str.length - 1) {
        if (str[i] == 'F' && str[i - 1] == 'S') {
            s++
        } else if (str[i] == 'S' && str[i - 1] == 'F') {
            s--
        }
    }
    if (s > 0) {
        println("YES")
    } else {
        println("NO")
    }

}

fun main() {
    readInteger()
    val s = readLine()!!
    var pre = s[0]
    var sCount = 0
    var fCount = 0
    for (i in 1 until s.length) {
        if (pre != s[i]){
            if (pre == 'S') {
                sCount++
            } else {
                fCount++
            }
        }

        pre = s[i]
    }

    val ans = if (sCount > fCount) {
        "Yes"
    } else {
        "No"
    }

    println(ans)
}

fun readInteger() = readLine()!!.toInt()
fun readStrings() = readLine()!!.split(" ")
fun readIntegers() = readStrings().map(String::toInt)

fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    var String = readLine().toString()
    var dem1 = 0
    var dem2 = 0
    for (i in 0..(String.length-2)){
        if (String[i] == 'F' && String[i+1] == 'S')
            dem1 ++
        if (String[i+1] == 'F' && String[i] == 'S')
            dem2 ++
    }
    print( if (dem1>=dem2) "NO" else "YES")
}

fun main() {
    val numDays = readLine()!!.toInt()
    val cities = readLine()!!
    var counter = 0
    for (pos in 1 until numDays) {
        when {
            (cities[pos] == 'S' && cities[pos - 1] == 'F') -> counter--
            (cities[pos] == 'F' && cities[pos - 1] == 'S') -> counter++
        }
    }
    if (counter > 0) print("YES") else print("NO")
}

    fun main(args: Array<String>){
        var temp = 0
        val n = readLine()!!.toInt()
        val s = readLine()!!

        for(i in 0 until n-1){
            when {
                (s[i] == 'S' && s[i+1] == 'F') ->temp++
                (s[i] == 'F' && s[i+1] == 'S') ->temp--
            }
        }
        if(temp>0) print ("YES") else print("NO")
    }

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

fun main() {
    val n = readInt()
    val s = readLn()
    var cntSF = 0
    var cntFS = 0
    for (i in 1 until s.length) {
        when (s.subSequence(i - 1, i + 1)) {
            "SF" -> cntSF++
            "FS" -> cntFS++
        }
    }
    if (cntSF > cntFS) {
        println("YES")
    } else {
        println("NO")
    }
}

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

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

    var n = reader.nextInt()
    var s = reader.next()

    var win = 0
    var lose = 0
    for(i in 1..n-1){
        if (s[i] == 'F' && s[i-1] == 'S') {
            win++
        } else if (s[i] == 'S' && s[i-1] == 'F') {
            lose++
        }
    }
    if(win > lose) println("YES")
    else println("NO")
}

fun main(args:Array<String>)
{

    var t=readLine()!!
    var switch=0
    var counter=0
    var counter1=0
    var flag=false
    var f=false
for(i in t) {
    if(i=='S')
    {
        f=true
    }
    if(i=='F'&&f)
    {
        f=false
        counter++;
    }
}
    f=false
    for(i in t) {
        if(i=='F')
        {
            f=true
        }
        if(i=='S'&&f)
        {
            f=false
            counter1++;
        }
    }

    println(if(counter>counter1) "YES" else "NO")
}

fun main() {
    val nightCount = Integer.parseInt(readLine()!!)
    val cities = readLine()!!
    var sf = 0
    var fs = 0
    for(i in 0 until nightCount - 1) {
        val flight = cities.substring(i, i + 2)
        println(flight)
        when (flight) {
            "SF" -> sf++
            "FS" -> fs++
        }
    }

    if (sf > fs) {
        println("YES")
    } else {
        println("NO")
    }
}


Just in case somebody missed it: this winter is totally cold in Nvodsk! It is so cold that one gets funny thoughts. For example, let's say there are strings with the length exactly n, based on the alphabet of size m. Any its substring with length equal to k is a palindrome. How many such strings exist? Your task is to find their quantity modulo 1000000007 (109 + 7). Be careful and don't miss a string or two!Let us remind you that a string is a palindrome if it can be read the same way in either direction, from the left to the right and from the right to the left.

The first and only line contains three integers: n, m and k (1 ≤ n, m, k ≤ 2000).

Print a single integer — the number of strings of the described type modulo 1000000007 (109 + 7).

NoteIn the first sample only one string is valid: "a" (let's denote the only letter of our alphabet as "a").In the second sample (if we denote the alphabet letters as "a" and "b") the following strings are valid: "aaaaa" and "bbbbb".

import kotlin.math.*
import java.math.BigInteger

fun pow(n: Long, exp: Int): Long {
  val maxValue = BigInteger.valueOf(10).pow(9) + BigInteger.valueOf(7)
  return (BigInteger.valueOf(n).pow(exp) % maxValue).toLong()
}

fun main() {
  val r = System.`in`.bufferedReader()
  val input = r.readLine()!!.split(" ").map { it.toLong() }

  if (input[2] == 1L || input[2] > input[0]) {
    println(pow(input[1], input[0].toInt()))
  } else if (input[0] == input[2]) {
    println(pow(input[1], (input[0] + 1).toInt() / 2))
  } else {
    val maxValue = 10.toDouble().pow(9).toLong() + 7
    if (input[2] % 2L == 0L) {
      println(input[1] % maxValue)
    } else {
      println((input[1]*input[1]) % maxValue)
    }
  }
}

import kotlin.math.*
import java.math.BigInteger

fun pow(n: Long, exp: Int): Long {
  val maxValue = BigInteger.valueOf(10).pow(9) + BigInteger.valueOf(7)
  return (BigInteger.valueOf(n).pow(exp) % maxValue).toLong()
}

fun main() {
  val r = System.`in`.bufferedReader()
  val input = r.readLine()!!.split(" ").map { it.toLong() }

  if (input[2] == 1L || input[2] > input[0]) {
    println(pow(input[1], input[0].toInt()))
  } else if (input[0] == input[2]) {
    println(pow(input[1], input[0].toInt()))
  } else {
    val maxValue = 10.toDouble().pow(9).toLong() + 7
    if (input[2] % 2L == 0L) {
      println(input[1] % maxValue)
    } else {
      println((input[1]*input[1]) % maxValue)
    }
  }
}

fun main() {
    val r = System.`in`.bufferedReader()
    val input = r.readLine()!!.split(" ").map { it.toInt() }
    val length = input[0]
    val letters = input[1]
    val sublength = input[2]
    if (length < sublength) {
      println(0)
    } else {
      println(letters)
    }
}

import kotlin.math.*

fun main() {
    val r = System.`in`.bufferedReader()
    val input = r.readLine()!!.split(" ").map { it.toInt() }
    val length = input[0]
    val letters = input[1]
    val sublength = input[2]
    val maxValue = 10.toDouble().pow(9).toLong() + 7;
    if (sublength == 1 || sublength > length) {
      println(letters.toDouble().pow(length).toLong() % maxValue)
    } else if (length == sublength) {
      println(letters.toDouble().pow(length).toLong() % maxValue)
    } else if (sublength % 2 == 0) {
      println((letters) % maxValue)
    } else {
      println((letters*letters) % maxValue)
    }
}