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

const val STRESS = false
const val STRESS_ITER = 100

data class Solver(val io: FastIO) {
    fun FastIO.solve() {
        val n = nextInt()
        val a = IntList(n / 2, { nextInt() - 1 })
        var a1 = 0
        var a2 = 0
        a.sort()
        for (i in 0 until a.size) {
            a1 += abs(a[i] - i * 2)
            a2 += abs(a[i] - i * 2 - 1)
        }
        println(min(a1, a2))
    }

    fun run() {
        io.use { it.solve() }
    }
}

fun main(args: Array<String>) {
    if (args.isNotEmpty() && args[0] == "KLOCAL") {
        if (STRESS) {
            Stresser.doStress()
        } else {
            Solver(FastIO(FileInputStream("input.txt"), System.out)).run()
        }
    } else {
        Solver(FastIO(System.`in`, System.out)).run()
    }
}

data class SlowSolver(val io: FastIO) {
    fun FastIO.slowSolve() {

    }

    fun run() {
        io.use { it.slowSolve() }
    }
}

class Stresser {
    companion object {
        const val INPUT = "input.txt"
        const val OUTPUT = "output.txt"
        const val SLOW = "slow.txt"

        fun PrintWriter.generateTest() {
            val rand = Random(31)

        }

        fun doStress() {
            for (it in 1..STRESS_ITER) {
                System.err.println(it)
                PrintWriter(INPUT).use { it.generateTest() }
                SlowSolver(FastIO(FileInputStream(INPUT), FileOutputStream(SLOW))).run()
                Solver(FastIO(FileInputStream(INPUT), FileOutputStream(OUTPUT))).run()
                compareFiles()
            }
        }

        fun compareFiles() {
            val out = File(OUTPUT).readLines().toMutableList()
            val slw = File(SLOW).readLines().toMutableList()
            while (out.size < slw.size) {
                out.add("\n")
            }
            while (out.size > slw.size) {
                slw.add("\n")
            }
            for (i in 0 until out.size) {
                if (out[i].trimEnd() != slw[i].trimEnd()) {
                    throw AssertionError("\nline ${i + 1}\nout: ${out[i]}\nslw: ${slw[i]}")
                }
            }
        }
    }
}

class FastIO(input: InputStream, output: OutputStream) : PrintWriter(output, false) {
    val br = BufferedReader(InputStreamReader(input))
    var stok = StringTokenizer("")

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

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

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

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

    fun print(vararg args: Any?) {
        args.forEachIndexed { i, arg ->
            if (i != 0) {
                print(" ")
            }
            print(arg)
        }
    }

    fun println(vararg args: Any?) {
        print(*args)
        println()
    }
}

class IntList {
    private var a: IntArray
    var size = 0

    constructor() {
        a = IntArray(4)
    }

    constructor(n: Int, x: Int = 0) {
        a = if (x == 0) {
            IntArray(n)
        } else {
            IntArray(n, { x })
        }
        size = n
    }

    constructor(n: Int, init: (Int) -> Int) {
        a = IntArray(n, init)
        size = n
    }

    fun add(x: Int) {
        ensureCapacity()
        a[size++] = x
    }

    fun front(): Int {
        return a[0]
    }

    fun back(): Int {
        return a[size - 1]
    }

    fun pop(): Int {
        return a[--size]
    }

    operator fun get(i: Int): Int {
        return a[i]
    }

    operator fun set(i: Int, x: Int) {
        a[i] = x
    }

    fun removeAt(i: Int) {
        var i = i
        while (i + 1 < size) {
            a[i] = a[i + 1]
            i++
        }
        --size
    }

    fun rotate(distance: Int) {
        if (size == 0)
            return
        var distance = distance % size
        if (distance < 0)
            distance += size
        if (distance == 0)
            return

        var cycleStart = 0
        var nMoved = 0
        while (nMoved != size) {
            var displaced = a[cycleStart]
            var i = cycleStart
            do {
                i += distance
                if (i >= size)
                    i -= size
                val tmp = a[i]
                a[i] = displaced
                displaced = tmp
                nMoved++
            } while (i != cycleStart)
            cycleStart++
        }
    }

    fun isEmpty(): Boolean {
        return size == 0
    }

    operator fun contains(x: Int): Boolean {
        for (i in 0 until size) {
            if (a[i] == x) {
                return true
            }
        }
        return false
    }

    override fun equals(other: Any?): Boolean {
        if (other == null || other !is IntList || size != other.size) {
            return false
        }

        for (i in 0 until size) {
            if (a[i] != other.a[i]) {
                return false
            }
        }

        return true
    }

    operator fun compareTo(other: IntList): Int {
        var i = 0
        while (i < min(size, other.size)) {
            if (a[i] < other.a[i]) {
                return -1
            }
            if (a[i] > other.a[i]) {
                return 1
            }
        }
        if (size < other.size) {
            return -1
        }
        if (size > other.size) {
            return 1
        }
        return 0
    }

    fun sort(from: Int = 0, to: Int = size) {
        a.sort(from, to)
    }

    fun reverse() {
        var i = 0
        while (i * 2 < size) {
            val x = a[i]
            a[i] = a[size - 1 - i]
            a[size - 1 - i] = x
            i++
        }
    }

    fun shuffle(rand: Random = Random()) {
        for (i in 1 until size) {
            val j = rand.nextInt(i + 1)
            if (i != j) {
                val x = a[i]
                a[i] = a[j]
                a[j] = x
            }
        }
    }

    fun nextPermutation(): Boolean {
        var i = size - 2
        while (i >= 0) {
            if (a[i] < a[i + 1]) {
                var b = size - 1
                while (true) {
                    if (a[b] > a[i]) {
                        var t = a[i]
                        a[i] = a[b]
                        a[b] = t
                        ++i
                        b = size - 1
                        while (i < b) {
                            t = a[i]
                            a[i] = a[b]
                            a[b] = t
                            ++i
                            --b
                        }
                        return true
                    }
                    --b
                }
            }
            --i
        }
        return false
    }

    fun forEach(block: (x: Int) -> Unit) {
        for (i in 0 until size) {
            block(a[i])
        }
    }

    fun forEachIndexed(block: (i: Int, x: Int) -> Unit) {
        for (i in 0 until size) {
            block(i, a[i])
        }
    }

    fun getArray(): IntArray {
        return a.copyOf(size)
    }

    private fun ensureCapacity() {
        if (size == a.size) {
            a = a.copyOf(size * 2)
        }
    }
}

class LongList {
    private var a: LongArray
    var size = 0

    constructor() {
        a = LongArray(4)
    }

    constructor(n: Int, x: Long = 0) {
        a = if (x == 0L) {
            LongArray(n)
        } else {
            LongArray(n, { x })
        }
        size = n
    }

    constructor(n: Int, init: (Int) -> Long) {
        a = LongArray(n, init)
        size = n
    }

    fun add(x: Long) {
        ensureCapacity()
        a[size++] = x
    }

    fun front(): Long {
        return a[0]
    }

    fun back(): Long {
        return a[size - 1]
    }

    fun pop(): Long {
        return a[--size]
    }

    operator fun get(i: Int): Long {
        return a[i]
    }

    operator fun set(i: Int, x: Long) {
        a[i] = x
    }

    fun removeAt(i: Int) {
        var i = i
        while (i + 1 < size) {
            a[i] = a[i + 1]
            i++
        }
        --size
    }

    fun rotate(distance: Int) {
        if (size == 0)
            return
        var distance = distance % size
        if (distance < 0)
            distance += size
        if (distance == 0)
            return

        var cycleStart = 0
        var nMoved = 0
        while (nMoved != size) {
            var displaced = a[cycleStart]
            var i = cycleStart
            do {
                i += distance
                if (i >= size)
                    i -= size
                val tmp = a[i]
                a[i] = displaced
                displaced = tmp
                nMoved++
            } while (i != cycleStart)
            cycleStart++
        }
    }

    fun isEmpty(): Boolean {
        return size == 0
    }

    operator fun contains(x: Long): Boolean {
        for (i in 0 until size) {
            if (a[i] == x) {
                return true
            }
        }
        return false
    }

    override fun equals(other: Any?): Boolean {
        if (other == null || other !is LongList || size != other.size) {
            return false
        }

        for (i in 0 until size) {
            if (a[i] != other.a[i]) {
                return false
            }
        }

        return true
    }

    operator fun compareTo(other: LongList): Int {
        var i = 0
        while (i < min(size, other.size)) {
            if (a[i] < other.a[i]) {
                return -1
            }
            if (a[i] > other.a[i]) {
                return 1
            }
        }
        if (size < other.size) {
            return -1
        }
        if (size > other.size) {
            return 1
        }
        return 0
    }

    fun sort(from: Int = 0, to: Int = size) {
        a.sort(from, to)
    }

    fun reverse() {
        var i = 0
        while (i * 2 < size) {
            val x = a[i]
            a[i] = a[size - 1 - i]
            a[size - 1 - i] = x
            i++
        }
    }

    fun shuffle(rand: Random = Random()) {
        for (i in 1 until size) {
            val j = rand.nextInt(i + 1)
            if (i != j) {
                val x = a[i]
                a[i] = a[j]
                a[j] = x
            }
        }
    }

    fun nextPermutation(): Boolean {
        var i = size - 2
        while (i >= 0) {
            if (a[i] < a[i + 1]) {
                var b = size - 1
                while (true) {
                    if (a[b] > a[i]) {
                        var t = a[i]
                        a[i] = a[b]
                        a[b] = t
                        ++i
                        b = size - 1
                        while (i < b) {
                            t = a[i]
                            a[i] = a[b]
                            a[b] = t
                            ++i
                            --b
                        }
                        return true
                    }
                    --b
                }
            }
            --i
        }
        return false
    }

    fun forEach(block: (x: Long) -> Unit) {
        for (i in 0 until size) {
            block(a[i])
        }
    }

    fun forEachIndexed(block: (i: Int, x: Long) -> Unit) {
        for (i in 0 until size) {
            block(i, a[i])
        }
    }

    fun getArray(): LongArray {
        return a.copyOf(size)
    }

    private fun ensureCapacity() {
        if (size == a.size) {
            a = a.copyOf(size * 2)
        }
    }
}

class DoubleList {
    private var a: DoubleArray
    var size = 0

    constructor() {
        a = DoubleArray(4)
    }

    constructor(n: Int, x: Double = .0) {
        a = if (x == .0) {
            DoubleArray(n)
        } else {
            DoubleArray(n, { x })
        }
        size = n
    }

    constructor(n: Int, init: (Int) -> Double) {
        a = DoubleArray(n, init)
        size = n
    }

    fun add(x: Double) {
        ensureCapacity()
        a[size++] = x
    }

    fun front(): Double {
        return a[0]
    }

    fun back(): Double {
        return a[size - 1]
    }

    fun pop(): Double {
        return a[--size]
    }

    operator fun get(i: Int): Double {
        return a[i]
    }

    operator fun set(i: Int, x: Double) {
        a[i] = x
    }

    fun removeAt(i: Int) {
        var i = i
        while (i + 1 < size) {
            a[i] = a[i + 1]
            i++
        }
        --size
    }

    fun rotate(distance: Int) {
        if (size == 0)
            return
        var distance = distance % size
        if (distance < 0)
            distance += size
        if (distance == 0)
            return

        var cycleStart = 0
        var nMoved = 0
        while (nMoved != size) {
            var displaced = a[cycleStart]
            var i = cycleStart
            do {
                i += distance
                if (i >= size)
                    i -= size
                val tmp = a[i]
                a[i] = displaced
                displaced = tmp
                nMoved++
            } while (i != cycleStart)
            cycleStart++
        }
    }

    fun isEmpty(): Boolean {
        return size == 0
    }

    operator fun contains(x: Double): Boolean {
        for (i in 0 until size) {
            if (a[i] == x) {
                return true
            }
        }
        return false
    }

    override fun equals(other: Any?): Boolean {
        if (other == null || other !is DoubleList || size != other.size) {
            return false
        }

        for (i in 0 until size) {
            if (a[i] != other.a[i]) {
                return false
            }
        }

        return true
    }

    operator fun compareTo(other: DoubleList): Int {
        var i = 0
        while (i < min(size, other.size)) {
            if (a[i] < other.a[i]) {
                return -1
            }
            if (a[i] > other.a[i]) {
                return 1
            }
        }
        if (size < other.size) {
            return -1
        }
        if (size > other.size) {
            return 1
        }
        return 0
    }

    fun sort(from: Int = 0, to: Int = size) {
        a.sort(from, to)
    }

    fun reverse() {
        var i = 0
        while (i * 2 < size) {
            val x = a[i]
            a[i] = a[size - 1 - i]
            a[size - 1 - i] = x
            i++
        }
    }

    fun shuffle(rand: Random = Random()) {
        for (i in 1 until size) {
            val j = rand.nextInt(i + 1)
            if (i != j) {
                val x = a[i]
                a[i] = a[j]
                a[j] = x
            }
        }
    }

    fun nextPermutation(): Boolean {
        var i = size - 2
        while (i >= 0) {
            if (a[i] < a[i + 1]) {
                var b = size - 1
                while (true) {
                    if (a[b] > a[i]) {
                        var t = a[i]
                        a[i] = a[b]
                        a[b] = t
                        ++i
                        b = size - 1
                        while (i < b) {
                            t = a[i]
                            a[i] = a[b]
                            a[b] = t
                            ++i
                            --b
                        }
                        return true
                    }
                    --b
                }
            }
            --i
        }
        return false
    }

    fun forEach(block: (x: Double) -> Unit) {
        for (i in 0 until size) {
            block(a[i])
        }
    }

    fun forEachIndexed(block: (i: Int, x: Double) -> Unit) {
        for (i in 0 until size) {
            block(i, a[i])
        }
    }

    fun getArray(): DoubleArray {
        return a.copyOf(size)
    }

    private fun ensureCapacity() {
        if (size == a.size) {
            a = a.copyOf(size * 2)
        }
    }
}

class BooleanList {
    private var a: BooleanArray
    var size = 0

    constructor() {
        a = BooleanArray(4)
    }

    constructor(n: Int, x: Boolean = false) {
        a = if (x == false) {
            BooleanArray(n)
        } else {
            BooleanArray(n, { x })
        }
        size = n
    }

    constructor(n: Int, init: (Int) -> Boolean) {
        a = BooleanArray(n, init)
        size = n
    }

    fun add(x: Boolean) {
        ensureCapacity()
        a[size++] = x
    }

    fun front(): Boolean {
        return a[0]
    }

    fun back(): Boolean {
        return a[size - 1]
    }

    fun pop(): Boolean {
        return a[--size]
    }

    operator fun get(i: Int): Boolean {
        return a[i]
    }

    operator fun set(i: Int, x: Boolean) {
        a[i] = x
    }

    fun removeAt(i: Int) {
        var i = i
        while (i + 1 < size) {
            a[i] = a[i + 1]
            i++
        }
        --size
    }

    fun rotate(distance: Int) {
        if (size == 0)
            return
        var distance = distance % size
        if (distance < 0)
            distance += size
        if (distance == 0)
            return

        var cycleStart = 0
        var nMoved = 0
        while (nMoved != size) {
            var displaced = a[cycleStart]
            var i = cycleStart
            do {
                i += distance
                if (i >= size)
                    i -= size
                val tmp = a[i]
                a[i] = displaced
                displaced = tmp
                nMoved++
            } while (i != cycleStart)
            cycleStart++
        }
    }

    fun isEmpty(): Boolean {
        return size == 0
    }

    operator fun contains(x: Boolean): Boolean {
        for (i in 0 until size) {
            if (a[i] == x) {
                return true
            }
        }
        return false
    }

    override fun equals(other: Any?): Boolean {
        if (other == null || other !is BooleanList || size != other.size) {
            return false
        }

        for (i in 0 until size) {
            if (a[i] != other.a[i]) {
                return false
            }
        }

        return true
    }

    operator fun compareTo(other: BooleanList): Int {
        var i = 0
        while (i < min(size, other.size)) {
            if (a[i] < other.a[i]) {
                return -1
            }
            if (a[i] > other.a[i]) {
                return 1
            }
        }
        if (size < other.size) {
            return -1
        }
        if (size > other.size) {
            return 1
        }
        return 0
    }

    fun reverse() {
        var i = 0
        while (i * 2 < size) {
            val x = a[i]
            a[i] = a[size - 1 - i]
            a[size - 1 - i] = x
            i++
        }
    }

    fun shuffle(rand: Random = Random()) {
        for (i in 1 until size) {
            val j = rand.nextInt(i + 1)
            if (i != j) {
                val x = a[i]
                a[i] = a[j]
                a[j] = x
            }
        }
    }

    fun nextPermutation(): Boolean {
        var i = size - 2
        while (i >= 0) {
            if (a[i] < a[i + 1]) {
                var b = size - 1
                while (true) {
                    if (a[b] > a[i]) {
                        var t = a[i]
                        a[i] = a[b]
                        a[b] = t
                        ++i
                        b = size - 1
                        while (i < b) {
                            t = a[i]
                            a[i] = a[b]
                            a[b] = t
                            ++i
                            --b
                        }
                        return true
                    }
                    --b
                }
            }
            --i
        }
        return false
    }

    fun forEach(block: (x: Boolean) -> Unit) {
        for (i in 0 until size) {
            block(a[i])
        }
    }

    fun forEachIndexed(block: (i: Int, x: Boolean) -> Unit) {
        for (i in 0 until size) {
            block(i, a[i])
        }
    }

    fun getArray(): BooleanArray {
        return a.copyOf(size)
    }

    private fun ensureCapacity() {
        if (size == a.size) {
            a = a.copyOf(size * 2)
        }
    }
}


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

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

val MAX_N = (1e6 + 10).toInt()
val INF = (1e9 + 7).toInt()
val MOD = (1e9 + 7).toInt()
val INF_F = 1e-6

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

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

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val m = n / 2
    val a = reader.nextArrayInt(m).sorted()

    var i = 1
    var j = 2
    var count1 = 0
    var count2 = 0
    a.forEach {
        count1 += abs(i - it)
        count2 += abs(j - it)
        i += 2
        j += 2
    }
    writer.println("${min(count1, count2)}")
}

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

class InputReader(stream: InputStream) {
    private val reader = BufferedReader(InputStreamReader(stream), 32768)
    private 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 nextArrayInt(count: Int): IntArray {
        return nextArrayInt(0, count)
    }

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

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


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

fun main(args : Array<String>) {
    val n = readLine()!!.toInt()
    var arr : Array<Int> = readLine()!!.split(' ').map { it.toInt() }.toTypedArray()
    arr.sort()
    var moves1 = 0
    var moves2 = 0
    for (i in 1..(n/2)) {
        moves1 += abs(arr[i-1] - (i*2))
        moves2 += abs(arr[i-1] - (i*2 -1))
    }
    println(min(moves1, moves2))
}


import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    val input = scanner.next()

    if (input.isEmpty()) {
        println(0)
        return
    }

    val maxCarry = 5
    var currentCarry = 1
    var firstChar = input[0]
    var result = 1

    for (i in 1 until input.length) {
        val nextChar = input[i]
        currentCarry++

        if (firstChar != nextChar) {
            firstChar = nextChar
            currentCarry = 1
        }

        if (currentCarry == 1) {
            result++
        }

        if (currentCarry == maxCarry) {
            currentCarry = 0
        }
    }

    println(result)
}


fun main() {
    val s = readLine()!!
    var current = 'a'
    var count = 0
    var sol = 0
    for (c in s) {
        if (c == current && count < 5) count++
        else {
            sol++
            current = c
            count = 1
        }
    }
    print(sol)
}


import kotlin.math.max

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

    val (a, b, c, d) = readInts()
    val diff = max(3 * a / 10, a - a / 250 * c) - max(3 * b / 10, b - b / 250 * d)
    print(
        when {
            diff > 0 -> "Misha"
            diff == 0 -> "Tie"
            else -> "Vasya"
        }
    )
}


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

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val mishaP = sc.nextInt()
    val VasyaP = sc.nextInt()
    val mishaT = sc.nextInt()
    val vasyaT = sc.nextInt()
    val mishaPoints = getPoints(mishaP, mishaT)
    val vasyaPoints = getPoints(VasyaP, vasyaT)
    if (mishaPoints > vasyaPoints) {
        print("Misha")
    } else if (mishaPoints == vasyaPoints) {
        print("Tie")
    } else print("Vasya")

}

fun getPoints(p: Int, t: Int) = max(p * 3 / 10f, p - p / 250f * t)


import java.io.BufferedInputStream
import java.io.BufferedOutputStream
import java.io.OutputStreamWriter
import java.util.*
import kotlin.math.max

fun main(args: Array<String>) {
    val scanner = Scanner(BufferedInputStream(System.`in`))
    val output = OutputStreamWriter(BufferedOutputStream(System.out))

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

    val p1 = points(a, c)
    val p2 = points(b, d)

    when {
        p1 == p2 -> output.write("Tie\n")
        p1 > p2 -> output.write("Misha\n")
        else -> output.write("Vasya\n")
    }

    output.flush()
    output.close()
    scanner.close()
}

fun points(p: Int, t: Int) = max(3*p/10f, p - (p/250f * t))


fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //var (x, y) = r.readLine()!!.split(" ").map { it.toLong() }
    //val n = r.readLine()!!.toInt()
    val (a, b, c, d) = r.readLine()!!.split(" ").map { it.toInt() }
    val alice = maxOf(3*a/10, a-a/250*c)
    val bob = maxOf(3*b/10, b-b/250*d)
    println(when{
        alice>bob -> "Misha"
        bob >alice -> "Vasya"
        else -> "Tie"
    })
}


import java.util.*

fun main(args: Array<String>) {
    val n : Long
    var b : Long
    var h : Long
    var k : Long = 0
    val scan = Scanner(System.`in`)
    n = scan.nextLong()
    b = scan.nextLong()
    h = b
    while (b > 0){
        k++
        h -= k
        if (k == n) k = 0
        b-= k +1
    }
    println(h)

}


import java.util.*

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

        var n = sc.nextInt()
        var m = sc.nextInt()
        var i = 0
        while (m >= 0) {
            var index = (i % n) + 1
            if (m < index) break
            m -= index
            i++
        }
        print(m)

}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val n = r.readLine()!!.toInt()
    var (n, m) = r.readLine()!!.split(" ").map { it.toInt() }
    var i = 0
    while (m > 0) {
        if (m >= (i + 1)) {
            m -= (i + 1)
            if (m==0) println(0)
            i = (i + 1) % n
        } else{
            println(m)
            m -= m
        }
    }
}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val x : Int = sc.nextInt()
    val t : Int = sc.nextInt()
    val a : Int = sc.nextInt()
    val b : Int = sc.nextInt()
    val da : Int = sc.nextInt()
    val db : Int = sc.nextInt()

    for (i in 0 until t) {
        for (j in 0 until t) {
            if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {
                print("YES")
                return
            }
        }
    }

    print("NO")

}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val x : Int = sc.nextInt()
    val t : Int = sc.nextInt()
    var a = sc.nextInt()
    var b = sc.nextInt()
    val da : Int = sc.nextInt()
    val db : Int = sc.nextInt()

    for (i in 0 until t) {
        for (j in 0 until t) {
            if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {
                print("YES")
                return
            }
        }
    }

    print("NO")

}


import java.util.Scanner

fun main() {

    val sc = Scanner(System.`in`)
    val x : Int = sc.nextInt()
    val t : Int = sc.nextInt()
    val a : Int = sc.nextInt()
    val b : Int = sc.nextInt()
    val da : Int = sc.nextInt()
    val db : Int = sc.nextInt()

    for (i : Int in 0 until t) {
        for (j : Int in 0 until t) {
            if ((a - i * da) + (b - j * db) == x || a - i * da == x || b - j * db == x || x == 0) {
                print("YES")
                return
            }
        }
    }

    print("NO")

}


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

    painting =
            painting.replace("C?Y", "CMY")
                    .replace("C?M", "CYM")
                    .replace("Y?C", "YMC")
                    .replace("Y?M", "YCM")
                    .replace("M?C", "MYC")
                    .replace("M?Y", "MCY")

    with (painting) {
        if (contains("CC") || contains("MM") || contains("YY")) {
            println("No")
            return
        }
        if (painting.count { it == '?' } == 0) {
            println("No")
            return
        }
    }

    println("Yes")
}


fun main(args : Array<String>) {
    var input = System.`in`.bufferedReader()
    try {
        var n = input.readLine().toInt()
        var s = input.readLine()

        var i = 0
        var ok = false
        mainloop@ while (i < s.length) {
            when (s[i]) {
                '?' -> {
                    var j = i
                    while (j < s.length && s[i] == s[j])
                        ++j

                    if (j - i >= 2)
                        ok = true
                    else {
                        var lch = if (i > 0) s[i - 1] else '\u0000'
                        var rch = if (j < s.length) s[j] else '\u0000'
                        if (lch == rch || lch == '\u0000' || rch == '\u0000')
                            ok = true
                    }
                    i = j
                }
                else -> {
                    if (i < s.length - 1 && s[i] == s[i + 1]) {
                        ok = false
                        break@mainloop
                    } else
                        ++i
                }
            }
        }

        println(if (ok) "Yes" else "No")
    } finally {
        input.close()
    }
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val n = r.readLine()!!.toInt()
    val (n, k) = r.readLine()!!.split(" ").map { it.toInt() }
    val v = r.readLine()!!.split(" ").map { it.toInt() }
    var have = 0
    var total = 0
    var ans = -1
    for (i in 0..n-1){
        total += v[i]
        have += minOf(total, 8).also { total -= minOf(total, 8) }
        if (have>=k){
            ans = i+1
            break
        }
    }
    println(ans)
}


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

fun countDays(): Int {
    val (days, sweets) = readLine()!!.split(' ').map(String::toInt)
    val sweetsOnDayX = readLine()!!.split(' ').map(String::toInt)
    var aryaSweets = 0
    var branSweets = 0
    for (i in 0 until days) {
        aryaSweets += sweetsOnDayX[i]
        if (aryaSweets >= 8) {
            branSweets += 8
            aryaSweets -= 8
        } else {
            branSweets += aryaSweets
            aryaSweets = 0
        }
        if (branSweets >= sweets) return i + 1
    }
    return -1
}


fun main() {

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

    var sum = 0
    var count = 0
    for (i in 0..list.size - 1) {
        sum += list[i]
        if (sum >= 8) {
            count += 8
            sum -= 8
        } else {
            count += sum
            sum = 0
        }
        if (count >= k) {
            println(i + 1)
            return
        }

    }
    println(-1)
    return

}


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

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

    val (_, k) = readInts()
    val arr = readInts()
    var sum = 0
    var extras = 0
    for ((pos, a) in arr.withIndex()) {
        val candies = extras + a
        sum += min(candies, 8)
        extras = max(0, candies - 8)
        if (sum >= k) return print(pos + 1)
    }
    print(-1)
}


import kotlin.math.min

fun main() {
    fun readInt() = readLine()!!.toInt()

    val n = readInt()
    val daysOffFullWeeks = 2 * (n / 7)
    print("${daysOffFullWeeks + if (n % 7 == 6) 1 else 0} ${daysOffFullWeeks + min(2, (n % 7))}")
}


//package codeforces.com.tasks.task670A

fun main() {
    val days = readLine()!!.toInt()
    val weeks = days / 7
    var minDaysOff = weeks * 2
    var maxDaysOff = weeks * 2

    when(days % 7) {
        0 -> { }
        1 -> maxDaysOff += 1
        6 -> { maxDaysOff += 2; minDaysOff += 1 }
        else -> maxDaysOff += 2
    }
    println("$minDaysOff $maxDaysOff")
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val n = r.readLine()!!.split(" ").map { it.toInt() }
    val n = r.readLine()!!.toInt()
    val min = n/7*2 + if (n%7==6) 1 else 0
    val max = n/7*2+ minOf(2, n%7)
    println("$min $max")
}


fun main() {
    var n = readLine()!!.toInt()
    var ans = 0
    var max = 0
    var min = 0
    if (n >= 7) {
        ans = n / 7
        var rem = n % 7
        if (rem >= 2) {
            max += ans*2 + 2
        } else if (rem == 1) {
            max += ans*2 + 1
        } else {
            max += ans*2
        }

        if (rem <= 5) {
            min += ans*2
        } else if (rem == 6) {
            min += ans*2 + 1
        }
    }else{
        if (n>=2){
            max = 2
        }else if (n==1){
            max = 1
        }
        if (n==6){
            min = 1
        }else{
            min = 0
        }
    }

    println("$min $max")
}


import java.util.*
import java.text.SimpleDateFormat

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.nextLine()
    val b = sc.nextLine()
    val c = SimpleDateFormat("HH:mm")
    val d1 = c.parse(a)
    val d2 = c.parse(b)
    var e = d1.time - d2.time
    if (e < 0)
        e += 24 * 60 * 60 * 1000
    val h = e/(60 * 60 * 1000)
    val m = (e%(60 * 60 * 1000))/(60 * 1000)
    when {
        h<10&&m<10 -> println("0$h:0$m")
        h>=10&&m<10 -> println("$h:0$m")
        h<10&&m>=10 -> println("0$h:$m")
        else -> println("$h:$m")
    }
}


fun main() {
    val (hourWokeUp, minutesWokeUp) = readLine()!!.split(":").map(String::toInt)
    val wokeUp = 60 * hourWokeUp + minutesWokeUp
    val (hourSleep, minutesSleep) = readLine()!!.split(":").map(String::toInt)
    val sleep = 60 * hourSleep + minutesSleep
    val sol = (wokeUp + 24 * 60 - sleep) % (24 * 60)
    print("${String.format("%02d", sol / 60)}:${String.format("%02d", sol % 60)}")
}


import kotlin.math.*

fun main(args: Array<String>) {
    val a = readLine()!!.splitToIntArray().toRect()
    val b = readLine()!!.splitToIntArray().toRect()
    val h = (b.x1 - b.x0) / 2
    val s0 = b.x1 + b.y0 - h
    val s1 = b.x1 + b.y0 + h
    val d0 = b.x0 - b.y0 - h
    val d1 = b.x0 - b.y0 + h
    for (x in a.x0..a.x1) {
        for (y in a.y0..a.y1) {
            if ((x + y) in s0..s1 && (x - y) in d0..d1) {
                println("YES")
                return
            }
        }
    }
    println("NO")
}

fun IntArray.toRect(): Rect {
    var x0 = Int.MAX_VALUE
    var x1 = Int.MIN_VALUE
    var y0 = Int.MAX_VALUE
    var y1 = Int.MIN_VALUE
    for (i in 0..3) {
        x0 = min(get(2 * i), x0)
        x1 = max(get(2 * i), x1)
        y0 = min(get(2 * i + 1), y0)
        y1 = max(get(2 * i + 1), y1)
    }
    return Rect(x0, x1, y0, y1)
}

class Rect(val x0: Int, val x1: Int, val y0: Int, val y1: Int)

private fun String.splitToIntArray(): IntArray {
    val n = length
    if (n == 0) return IntArray(0) // EMPTY
    var res = IntArray(4)
    var m = 0
    var i = 0
    while (true) {
        var cur = 0
        var neg = false
        var c = get(i) // expecting number, IOOB if there is no number
        if (c == '-') {
            neg = true
            i++
            c = get(i) // expecting number, IOOB if there is no number
        }
        while (true) {
            val d = c.toInt() - '0'.toInt()
            require(d >= 0 && d <= 9) { "Unexpected character '$c' at $i" }
            require(cur >= Integer.MIN_VALUE / 10) { "Overflow at $i" }
            cur = cur * 10 - d
            require(cur <= 0) { "Overflow at $i" }
            i++
            if (i >= n) break
            c = get(i)
            if (c == ' ') break
        }
        if (m >= res.size) res = res.copyOf(res.size * 2)
        res[m++] = if (neg) cur else (-cur).also { require(it >= 0) { "Overflow at $i" } }
        if (i >= n) break
        i++
    }
    if (m < res.size) res = res.copyOf(m)
    return res
}


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

fun main(args: Array<String>) {
    val (h1, h2) = readInts()
    val (a, b) = readInts()

    // get to 10 pm
    var x = h1
    x += 8 * a
    if (x >= h2) {
        println(0)
        return
    }
    if (a <= b) {
        println(-1)
        return
    }

    var ans = 0
    while (x < h2) {
        x += 12 * (a - b)
        ans += 1
    }

    println(ans)
}


fun main() {
    //println((4 or 6)xor(4 or 5))
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val (n, x, y) = r.readLine()!!.split(" ").map { it.toInt() }
    val n1 = r.readLine()!!.toLong()
    val n2 = r.readLine()!!.toLong()
    val n3 = n1 + n2
    val n4 = n1.toString().split("").filter { it.isNotEmpty() }.filter { it != "0" }.joinToString("").toLong()
    val n5 = n2.toString().split("").filter { it.isNotEmpty() }.filter { it != "0" }.joinToString("").toLong()
    val n6 = n3.toString().split("").filter { it.isNotEmpty() }.filter { it != "0" }.joinToString("").toLong()
    println(if (n4+n5==n6) "YES" else "NO")
}


fun main (args:Array<String>){
    var num1 = readLine()!!.toInt()
    var num2 = readLine()!!.toInt()

    var result = num1 + num2

    var num_1 = ""
    var num_2 = ""
    var result_ = ""

    var resultTemp = ""

    var temp = num1
    while(temp > 0) {
        var i = temp % 10
        temp /= 10
        if (i == 0)
            continue
        num_1 = i.toString() + num_1
    }

    temp = num2
    while(temp > 0) {
        var i = temp % 10
        temp /= 10
        if (i == 0)
            continue
        num_2 = i.toString() + num_2
    }

    temp = result
    while(temp > 0) {
        var i = temp % 10
        temp /= 10
        if (i == 0)
            continue
        result_ = i.toString() + result_
    }

    for(i in result.toString()){
        if(i == '0'){
            continue
        }
        resultTemp += i
    }
    if (num_1.toInt() + num_2.toInt() == result_.toInt() && resultTemp == result_)
        print("YES")
    else
        print("NO")
}


fun main(args : Array<String>) {

    val d1 = readLine()!!
    val d2 = readLine()!!
    var list1: MutableList<Char> = mutableListOf()
    var list1n: MutableList<Char> = mutableListOf()
    var list2: MutableList<Char> = mutableListOf()
    var list2n: MutableList<Char> = mutableListOf()
    var list3: MutableList<Char> = mutableListOf()
    var list3n: MutableList<Char> = mutableListOf()

    for (char in d1) { list1.add(char) }
    for (char in d2) { list2.add(char) }
    var t = d1.toInt()+d2.toInt()
    for (char in t.toString()) { list3.add(char) }

    for(i in 0..list1.size-1){
        if(list1[i]!='0'){ list1n.add(list1[i]) }
    }

    for(k in 0..list2.size-1){
        if(list2[k]!='0'){ list2n.add(list2[k]) }
    }
    for(j in 0..list3.size-1){
        if(list3[j]!='0'){ list3n.add(list3[j]) }
    }

    var a1 = 1
    var s1 = 0
    for(i in list1n.size-1 downTo 0){
        s1 = s1+list1n[i].toString().toInt()*a1
        a1 = a1 * 10
    }
    var a2 = 1
    var s2 = 0
    for(i in list2n.size-1 downTo 0){
        s2 = s2+list2n[i].toString().toInt()*a2
        a2 = a2 * 10
    }
    var a3 = 1
    var s3 = 0
    for(i in list3n.size-1 downTo 0){
        s3 = s3+list3n[i].toString().toInt()*a3
        a3 = a3 * 10
    }

    if(s1+s2==s3){ println("YES") }
    else { println("NO") }

}


import java.util.*

private val scan = Scanner(System.`in`)

fun main(args: Array<String>) {
    val m = scan.next().sort()
    val n = scan.next()
    val ni = n.toLong()

    if (n.length > m.length) {
        println(m.toList().sortedDescending().joinToString(""))
        return
    }

    var ans = m.toList()
    for (i in 0 until m.length) {
        for (j in i + 1 until m.length) {
            val temp = ans.toMutableList()
            Collections.swap(temp, i, j)
//            println("temp=$temp")
            val xList = temp.subList(0, i + 1) + temp.subList(i + 1, temp.size).sorted()
//            println("xList=$xList")
            val x = xList.joinToString("").toLong()
            if (x <= ni) {
                ans = xList
            }
        }
    }

    println(ans.joinToString(""))
}

fun String.sort() =
        toList().sorted().joinToString("")


import java.util.*

data class ArrayViewer(val pos: Int, val array: IntArray) {

    fun empty() = pos >= array.size
    fun head() = array[pos]
    fun tail() = ArrayViewer(pos + 1, array)

}

fun IntArray.viewer() = ArrayViewer(0, this)

fun main(args: Array<String>) = with(Scanner(System.`in`)) {

    val a = nextLine()!!.map { it.toInt() - '0'.toInt() }.toIntArray()
    val b = nextLine()!!.map { it.toInt() - '0'.toInt() }.toIntArray()

    val counts = countDigits(a)

    if (a.size < b.size) {
        print(maxPossible(counts).fold("") { str, digit ->
            str + digit.toString() })
        return
    } else {
        print(makeLess(counts, b.viewer())!!.fold("") {
                str, digit ->
            str + digit.toString() })
    }

}

fun makeLess(counter: IntArray, value: ArrayViewer): List<Int>? {
    if (value.empty()) {
        return List<Int>(0){0}
    }

    val digit = value.head()
    val rest = value.tail()

    if (counter[digit] != 0) {
        var counterWithout = counter
        counterWithout[digit] -= 1

        val other = makeLess(counterWithout, rest)
        if (other != null) {
            return List<Int>(1){digit} + other
        }

        counterWithout[digit] += 1
    }

    for (nextDigit in (digit - 1) downTo 0) {
        if (counter[nextDigit] != 0) {
            var counterWithout = counter
            counterWithout[nextDigit] -= 1

            val other = maxPossible(counterWithout)
            return List<Int>(1){nextDigit} + other
        }
    }

    return null

}

fun maxPossible(counter: IntArray): List<Int> {
    var c = List<Int>(0) {0}

    for (digit in 9 downTo 0) {
        for (i in 1..counter[digit]) {
            c += digit
        }
    }

    return c
}

fun countDigits(array: IntArray): IntArray {
    var counter = IntArray(10){0}

    for (digit in array) {
        counter[digit] += 1
    }

    return counter
}


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

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

        val first = reader.next()
        val second = reader.next()

        writer.println(solve(first, second))

        writer.close()
    }

    fun solve(first : String, second : String) : String {
        val digits = Array(10, {_ -> 0})
        for (char in first) {
            digits[char - '0']++
        }
        return trySolve(digits, second, second.length - first.length, first.length == second.length)!!
    }

    fun trySolve(digits : Array<Int>, number : String, pos : Int, eq : Boolean) : String? {
        if (pos == number.length) {
            return ""
        }

        if (!eq) {
            for (x in (0..9).reversed()) {
                if (digits[x] > 0) {
                    digits[x]--
                    val result = trySolve(digits, number, pos + 1, eq)
                    digits[x]++
                    if (result == null) {
                        return result
                    }
                    return x.toString() + result
                }
            }
        }

        // try with the same number
        val current = number[pos] - '0'
        if (digits[current] > 0) {
            digits[current]--
            val result = trySolve(digits, number, pos + 1, eq)
            digits[current]++
            if (result != null) {
                return current.toString() + result
            }
        }

        // or try with lower
        for(x in (0 until current).reversed()) {
            if (digits[x] > 0) {
                digits[x]--
                val result = trySolve(digits, number, pos + 1, false)
                digits[x]++
                if (result == null) {
                    return result
                }
                return x.toString() + result
            }
        }

        return null
    }

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

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

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

            }
            return tokenizer!!.nextToken()
        }

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

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

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


import kotlin.math.sqrt

fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    //val (s, n) = r.readLine()!!.split(" ").map { it.toInt() }
    val (a, b, c) = r.readLine()!!.split(" ").map { it.toDouble() }
    val x = sqrt(a*b/c).toInt()
    val y = sqrt(a*c/b).toInt()
    val z = sqrt(b*c/a).toInt()
    println(4*(x+y+z))
}


fun main() {
    val (ab, bc, ac) = readLine()!!.split(" ").map{ it.toInt() }
    var a: Int
    var b: Int
    var c: Int
    for(i in 1..10000) {
        if(ab % i == 0 && ac % i == 0 && (ab / i) * (ac / i) == bc) {
            a = i
            b = ab / a
            c = ac / a
            println(4 * (a + b + c))
            break
        }
    }
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.*
fun main(args: Array<String>) {

    val scanner = Scanner(System.`in`)
    val ab = scanner.nextLong()
    val bc = scanner.nextLong()
    val ac = scanner.nextLong()
    val abc = sqrt((ab * bc * ac).toDouble()).toDouble()
    println(4 * ((abc / ab) + (abc / ac) + (abc / bc)).toLong())
}

class Scanner(s: InputStream) {
    var st: StringTokenizer? = null
    var br: BufferedReader = BufferedReader(InputStreamReader(s))
    @Throws(IOException::class)
    operator fun next(): String {
        while (st == null || !st!!.hasMoreTokens())
            st = StringTokenizer(br.readLine())
        return st!!.nextToken()
    }
    @Throws(IOException::class)
    fun nextInt(): Int {
        return Integer.parseInt(next())
    }
    @Throws(IOException::class)
    fun nextLong(): Long {
        return java.lang.Long.parseLong(next())
    }
    @Throws(IOException::class)
    fun nextLine(): String {
        return br.readLine()
    }
    @Throws(IOException::class)
    fun nextDouble(): Double {
        return java.lang.Double.parseDouble(next())
    }
    @Throws(IOException::class)
    fun ready(): Boolean {
        return br.ready()
    }
}

fun IntArray.print() {
    println(Arrays.toString(this))
}

//class Pair(var a: Int, var b: Int): Comparable<Pair> {
//    override fun compareTo(other: Pair): Int {
//        return b - a - other.b + other.a
//    }
//}


fun main(args: Array<String>) {

    var n = readLine()!!.toLong()
    n++

    var sum = 0L
    var res = 0L

    readLine()!!.split(' ').map { sum += it.toLong() }

    sum--;

    for (i in 1..5) {
        if ((sum + i) % n != 0L) res++
    }

    print(res)

}


import java.util.*

val reader = Scanner(System.`in`)
var c = 0
var ans = 0
fun main(args: Array<String>) {
    val n = reader.nextInt()
    for (i in 1..n)
        c+=reader.nextInt()
    for (i in 1..5)
    {
        if ((i+c)%(n+1) !=1)
            ans++
    }
    /*if ((c+1)%(n+1)==1)
        println(2)
    else
        println(3)*/
    println(ans)
}


fun main() {
    var n = readLine()!!.toInt()
    var list = readLine()!!.split(' ').map { it.toInt() }.sum()
    var ans = 0
    for (i in 1..5) {
        if ((list + i) % (n + 1) != 1) {
            ans++
        }
    }
    println(ans)
}


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

fun <T : Comparable<T>> max(a: T, b: T): T = if (b > a) b else a
fun <T : Comparable<T>> min(a: T, b: T): T = if (b < a) b else a
fun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false
fun Number.isOdd (): Boolean = !this.isEven()

fun getVal(num: Long, rows: Long, cols: Long): Long {
    var res: Long = 0
    for (i in 1..min(num, rows)) {
        res += min(cols, num / i)
    }
    return res
}

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    val st = StringTokenizer(br.readLine())
    val on = st.nextToken().toLong()
    val om = st.nextToken().toLong()
    val k = st.nextToken().toLong()
    val n = min(on, om); val m = max(on, om)
    var lo = 1L; var hi: Long = n * m
    while (lo < hi) {
        val mid = (lo + hi) ushr 1
        if (k <= getVal(mid, n, m)) hi = mid
        else lo = mid + 1
    }

    outer@ while (true) {
        var i = 1L
        while (i * i <= lo) {
            if (lo % i == 0L && i <= n && lo / i <= m) break@outer
            ++i
        }
        ++lo
    }

    bw.write("$lo\n")
    bw.close()
}


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

class Solution : Runnable {
    override fun run() {
        solve()
    }

    fun start() {
        Thread(null, Solution(), "whatever", (1 shl 27).toLong()).start()
    }
}

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

class IO {
    companion object {

        private val reader: InputReader
        private val writer: OutputWriter

        init {
            if (System.getProperty("ONLINE_JUDGE") == null) {
                reader = InputReader(FileInputStream("/Users/300041735/competitiveProgramming/src/codeforces/in.txt"))
                writer = OutputWriter(FileOutputStream("/Users/300041735/competitiveProgramming/src/codeforces/out.txt"))
            } else {
                reader = InputReader(System.`in`)
                writer = OutputWriter(System.`out`)
            }
        }

        private fun readMultipleInts(count: Int): List<Int> {
            val map = mutableListOf<Int>()
            repeat(count) {
                map.add(reader.readInt())
            }
            return map
        }

        fun readInt() = reader.readInt()
        fun readLong() = reader.readLong()
        fun readTwoInts() = readMultipleInts(2)
        fun readThreeInts() = readMultipleInts(3)
        fun readFourInts() = readMultipleInts(4)
        fun readFiveInts() = readMultipleInts(5)
        fun readSixInts() = readMultipleInts(6)
        fun readString() = reader.readString()
        fun readTree(n: Int): MutableMap<Int, MutableList<Int>> {
            val graph = mutableMapOf<Int, MutableList<Int>>()
            repeat(n - 1) {
                val u = reader.readInt()
                val v = reader.readInt()
                if (!graph.containsKey(u)) graph[u] = mutableListOf()
                if (!graph.containsKey(v)) graph[v] = mutableListOf()
                graph[u]!!.add(v)
                graph[v]!!.add(u)
            }
            return graph
        }

        fun readIntArray(n: Int): IntArray {
            return IntArray(n) { readInt() }
        }

        fun readLongArray(n: Int): Array<Long> {
            return Array(n) { readLong() }
        }

        fun write(obj: Any) {
            writer.printLine(obj)
        }

        fun flushOutput() {
            writer.flush()
        }

        fun closeOutput() {
            writer.close()
        }
    }
}

class MATH {
    companion object {

        val mod = 1000000007
        var ispre = false

        val factMod = Array(300002) { 1 }

        fun pre() {
            for (i in 2 until 300001) {
                factMod[i] = ((factMod[i - 1] * i.toLong()) % MATH.mod).toInt()
            }
        }

        fun gcd(a: Int, b: Int): Int {
            if (b == 0)
                return a
            return gcd(b, a % b)
        }

        fun gcd(a: Long, b: Long): Long {
            if (b == 0L)
                return a
            return gcd(b, a % b)
        }

        fun inverseMod(a: Int): Int {
            return powMod(a, mod - 2)
        }

        fun powMod(a: Int, b: Int): Int {
            //calculate a to the power b mod m
            if (b == 0) return 1
            return if (b % 2 == 1) {
                prodMod(a, powMod(a, b - 1))
            } else {
                val p = powMod(a, b / 2)
                prodMod(p, p)
            }
        }

        fun ncr(n: Int, r: Int): Int {
            if (!ispre) pre(); ispre = true
            return ((factMod[n].toLong() * inverseMod(((factMod[r].toLong() * factMod[n - r]) % mod).toInt())) % mod).toInt()
        }

        fun prodMod(val1: Int, val2: Int): Int {
            return ((val1.toLong() * val2) % mod).toInt()
        }

    }
}

fun solve() {

    val n = IO.readInt()
    val m = IO.readInt()
    var k = IO.readLong()

    k = n*m.toLong() - k + 1

    //loop over the ans
    var ansL = 0L
    var ansH = n*m.toLong()
    while (ansH - ansL > 1){
        //find the largest ans such that numbers greater than it are >= k
        val mid = (ansL + ansH)/2
        val count = getCount(n, m , mid)   //how many numbers are strictly greater than this number
        if (count >= k){
            //we can still go higher
            ansL = mid
        }else{
            ansH = mid - 1
        }
    }

    val count = getCount(n, m , ansH)
    if (count >= k){
        IO.write(ansH + 1)
    }else{
        IO.write(ansL + 1)
    }

    IO.flushOutput()
    IO.closeOutput()
}

fun getCount(n : Int, m : Int, search : Long) : Long{
    var count = 0L
    for(i in 1 until n + 1){
        //over each of the row
        //i*j  find the smallest j such that i*j > search -> ceil(search/i)
        val ans = (search + i )/i
        if (ans <= m) {
            count += m - ans + 1
        }
    }
    return count
}

fun isBitSet(num : Long, i : Int) : Boolean{
    return  (num.and(1L.shl(i)) > 0)
}

data class Graph(val edges: MutableMap<Int, MutableList<Int>>)

class MinSegmentTree(
        input: Array<Int>
) {
    private val tree: Array<Int>
    private val lazy: Array<Int>

    constructor(size: Int) : this(Array(size) { Int.MAX_VALUE })

    init {
        val size = nextPowerOfTwo(input.size)
        tree = Array(2 * size) { Int.MAX_VALUE }
        lazy = Array(2 * size) { Int.MAX_VALUE }
        for (i in 0 until input.size) {
            tree[i + size] = input[i]
        }
        for (i in (size - 1) downTo 1) {
            tree[i] = Math.min(tree[leftChild(i)], tree[rightChild(i)])
        }
    }

    private fun updateTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int, value: Int) {
        updateLazyNode(index, lowerBound, upperBound, lazy[index])
        if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return
        else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) updateLazyNode(index, lowerBound, upperBound, value)
        else {
            updateTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index), value)
            updateTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index), value)
            tree[index] = Math.min(tree[leftChild(index)], tree[rightChild(index)])
        }
    }

    private fun queryTree(lowerRange: Int, upperRange: Int, lowerBound: Int, upperBound: Int, index: Int): Int {
        updateLazyNode(index, lowerBound, upperBound, lazy[index])
        if (noOverlap(lowerRange, upperRange, lowerBound, upperBound)) return Int.MAX_VALUE
        else if (completeOverlap(lowerRange, upperRange, lowerBound, upperBound)) return tree[index]
        else {
            return Math.min(queryTree(lowerRange, upperRange, lowerBound, midIndex(lowerBound, upperBound), leftChild(index)),
                    queryTree(lowerRange, upperRange, midIndex(lowerBound, upperBound) + 1, upperBound, rightChild(index)))
        }
    }

    private fun updateLazyNode(index: Int, lowerBound: Int, upperBound: Int, delta: Int) {
        tree[index] += delta
        if (lowerBound != upperBound) {
            lazy[leftChild(index)] += delta
            lazy[rightChild(index)] += delta
        }
        lazy[index] = 0
    }

    fun getElements(N: Int): List<Int> {
        return tree.copyOfRange(tree.size / 2, tree.size / 2 + N).asList()
    }

    fun update(lowerRange: Int, upperRange: Int, value: Int) {
        updateTree(lowerRange, upperRange, 1, lazy.size / 2, 1, value)
    }

    fun query(lowerRange: Int, upperRange: Int): Int {
        return queryTree(lowerRange, upperRange, 1, lazy.size / 2, 1)
    }

    private fun noOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb > u || ub < l)

    private fun completeOverlap(l: Int, u: Int, lb: Int, ub: Int): Boolean = (lb >= l && ub <= u)

    private fun nextPowerOfTwo(num: Int): Int {
        var exponent = 2
        while (true) {
            if (exponent >= num) {
                return exponent
            }
            exponent *= 2
        }
    }

    private fun midIndex(l: Int, r: Int) = (l + r) / 2
    private fun parent(i: Int) = i / 2
    private fun leftChild(i: Int) = 2 * i
    private fun rightChild(i: Int) = 2 * i + 1

}

class InputReader(private val stream: InputStream) {
    private val buf = ByteArray(1024)
    private var curChar: Int = 0
    private var numChars: Int = 0
    private val filter: SpaceCharFilter? = null

    fun read(): Int {
        if (numChars == -1)
            throw InputMismatchException()
        if (curChar >= numChars) {
            curChar = 0
            try {
                numChars = stream.read(buf)
            } catch (e: IOException) {
                throw InputMismatchException()
            }

            if (numChars <= 0)
                return -1
        }
        return buf[curChar++].toInt()
    }

    fun readInt(): Int {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        var sgn = 1
        if (c == '-'.toInt()) {
            sgn = -1
            c = read()
        }
        var res = 0
        do {
            if (c < '0'.toInt() || c > '9'.toInt())
                throw InputMismatchException()
            res *= 10
            res += c - '0'.toInt()
            c = read()
        } while (!isSpaceChar(c))
        return res * sgn
    }

    fun readLong(): Long {
        var c = read()
        while (isSpaceChar(c)) {
            c = read()
        }
        var sgn: Long = 1
        if (c == '-'.toInt()) {
            sgn = -1
            c = read()
        }
        var number: Long = 0
        do {
            number *= 10L
            number += (c - '0'.toInt()).toLong()
            c = read()
        } while (!isSpaceChar(c))
        return number * sgn
    }

    fun readString(): String {
        var c = read()
        while (isSpaceChar(c))
            c = read()
        val res = StringBuilder()
        do {
            res.appendCodePoint(c)
            c = read()
        } while (!isSpaceChar(c))
        return res.toString()
    }

    fun isSpaceChar(c: Int): Boolean {
        return filter?.isSpaceChar(c)
                ?: (c == ' '.toInt() || c == '\n'.toInt() || c == '\r'.toInt() || c == '\t'.toInt() || c == -1)
    }

    operator fun next(): String {
        return readString()
    }

    interface SpaceCharFilter {
        fun isSpaceChar(ch: Int): Boolean
    }
}

class OutputWriter {
    private val writer: PrintWriter

    constructor(outputStream: OutputStream) {
        writer = PrintWriter(BufferedWriter(OutputStreamWriter(outputStream)))
    }

    constructor(writer: Writer) {
        this.writer = PrintWriter(writer)
    }

    fun print(vararg objects: Any) {
        for (i in objects.indices) {
            if (i != 0)
                writer.print(' ')
            writer.print(objects[i])
        }
    }

    fun printLine(vararg objects: Any) {
        print(*objects)
        writer.println()
    }

    fun close() {
        writer.close()
    }

    fun flush() {
        writer.flush()
    }

}

class DinitzMaxFlowSolver(val n: Int, val s: Int, val t: Int, val graph: MutableMap<Int, MutableList<Edge>>, val edgeMap: MutableMap<Pair<Int, Int>, Edge>) {

    private val level = IntArray(n + 1) { -1 }  //storing levels of each vertex in level graph
    var maxFlow = 0L

    init {
        solve()
    }

    fun solve() {
        val next = IntArray(n + 1) { 0 }
        while (bfs()) {
            Arrays.fill(next, 0)
            var flow = 0L
            do {
                maxFlow += flow
                flow = dfs(s, next, Long.MAX_VALUE)
            } while (flow != 0L)
        }
    }

    private fun dfs(at: Int, next: IntArray, flow: Long): Long {
        if (at == t) return flow
        var size = 0
        if (graph.containsKey(at)) size = graph[at]!!.size
        while (next[at] < size) {
            val edge = graph[at]!!.get(next[at])
            if (edge.remainingCapacity() > 0 && level[edge.to] == level[at] + 1) {
                val bottleNeck = dfs(edge.to, next, Math.min(flow, edge.remainingCapacity()))
                if (bottleNeck > 0) {
                    edgeMap[Pair(edge.from, edge.to)]!!.flow += bottleNeck
                    edgeMap[Pair(edge.to, edge.from)]!!.flow -= bottleNeck
                    return bottleNeck
                }
            }
            next[at]++
        }
        return 0
    }

    private fun bfs(): Boolean {
        Arrays.fill(level, -1)
        val curLevel = ArrayDeque<Int>()
        curLevel.add(s)
        level[s] = 0

        while (curLevel.isNotEmpty()) {
            val top = curLevel.poll()
            if (graph.containsKey(top)) {
                graph[top]!!.forEach {
                    if (it.remainingCapacity() > 0 && level[it.to] == -1) {
                        level[it.to] = level[top] + 1
                        curLevel.offer(it.to)
                    }
                }
            }
        }
        return level[t] != -1
    }

}

class Edge(val from: Int, val to: Int, val capacity: Long) {
    var flow = 0L
    fun remainingCapacity(): Long {
        return capacity - flow
    }
}


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

fun <T : Comparable<T>> max(a: T, b: T): T = if (b > a) b else a
fun <T : Comparable<T>> min(a: T, b: T): T = if (b < a) b else a
fun Number.isEven(): Boolean = if (this.toInt() and 1 == 0) true else false
fun Number.isOdd (): Boolean = !this.isEven()

inline fun getVal(num: Long, rows: Long, cols: Long): Long {
    var res: Long = 0
    for (i in 1..min(num, rows)) {
        res += min(cols, num / i)
    }
    return res
}

fun main(args: Array<String>) {
    if (args.isNotEmpty()) System.setIn(FileInputStream(args[0]))
    val br = BufferedReader(InputStreamReader(System.`in`))
    val bw = BufferedWriter(OutputStreamWriter(System.out))

    val st = StringTokenizer(br.readLine())
    val on = st.nextToken().toLong()
    val om = st.nextToken().toLong()
    val k = st.nextToken().toLong()
    val n = min(on, om); val m = max(on, om)
    var lo = 1L; var hi: Long = n * m
    while (lo <= hi) {
        val mid = (lo + hi) ushr 1
        if (k <= getVal(mid, n, m)) hi = mid - 1
        else lo = mid + 1
    }
/*
    outer@ while (true) {
        var i = 1L
        while (i * i <= lo) {
            if (lo % i == 0L && i <= n && lo / i <= m) break@outer
            ++i
        }
        ++lo
    }
*/
    bw.write("$lo\n")
    bw.close()
}


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

val MOD = 1_000_000_007L

inline fun findMin(mn: Long, mx: Long, f: (Long) -> Boolean): Long {
  var low = mn - 1
  var high = mx
  while(high - low > 1) {
    val m = (low + high) / 2
    if (f(m)) high = m
    else low = m
  }
  return high
}
class Solver(stream: InputStream, private val out: java.io.PrintWriter) {
  fun solve() {
    val N = nl()
    val M = nl()
    val K = nl()

    fun test(x: Long): Boolean {
      var sum = 0L
      for (i in 1 .. N) {
        sum += min(M,x / i)
      }

      return sum >= K
    }

    val ans = findMin(0, N * M, ::test)
    out.println(ans)
  }

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

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

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

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

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

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

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

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

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

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

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

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


/**
 * Created by seydazimovnurbol on 5/23/17.
 */

import java.util.*
import kotlin.system.exitProcess

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

    var a : ArrayList<Int> = ArrayList<Int>()

    var sum : Double = 0.0
    for (i in 1 .. n) {
        var x = scanner.nextInt()
        a.add(x)
        sum += x
    }
    sum /= n
    var cntK : Int = 0
    for (i in 0 .. n - 1)
        if (a[i] == k) cntK++;

    var need : Int = 0
    for (i in 0 .. n - 1) {
        if (a[i] < k) {
            var cnt : Int = k - 1 - a[i]
            a[i] += Math.min(cnt, cntK)
            cntK -= Math.min(cnt, cntK)
            need += k - 1 - a[i]
        }
    }

    // [A] [B]

    var cntOther : Int = n - cntK
    if (cntK >= cntOther) println(0)
    else if (need == 0) println(cntOther - cntK)
    else println(need + n + need)
}


fun main(args: Array<String>) {
    val x = readLine()!!.split(" ")
    var courses = x[0].toInt()
    val mark = x[1].toInt()

    var sum = readLine()!!.split(" ").map { it.toInt() }.sum().toDouble()

    var ans = 0
    var curMark =  sum / courses
    while ((curMark + .5).toInt() < mark){
        sum += mark
        courses++
        curMark = sum / courses
        ans++
    }
    println(ans)
}


fun main(args: Array<String>) {

    var x= readLine()?.split(" ")
    var n:Int = Integer.parseInt(x!![0])
    var k:Int = Integer.parseInt(x!![1])
    x= readLine()?.split(" ")
    var sum:Double=0.0
    for(i in 1..n){
        sum+=Integer.parseInt(x!![i-1])
    }
    var avg:Double=sum/n
    if(avg+.5>=k){
        println(0)
        return
    }
    var c=0
    while (true){
        sum+=k
        n++
        c++
        avg=sum/n
        if(avg+.5>=k)break
    }
    println(c)

}


fun main(args: Array<String>) {
    var (n, k) = readLine()!!.split(' ').map(String::toInt)
    var total = 0
    readLine()!!.split(' ').map(String::toInt).forEach {
        total += it
    }
    var ans = 0
    while (true) {
        // print("$n $total\n")
        if (total / n >= k)
            break
        else if (total / n >= k - 1 && total % n >= (n+1) / 2)
            break
        ans++
        n++
        total += k
    }
    print("$ans\n")
}


import kotlin.math.max

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

    val m = Array(3) { IntArray(3) }
    for (row in 0 until 3) m[row] = readInts().toIntArray()
    var x = 0 // sum of rows, columns and diagonals
    for (row in 0 until 3) x = max(x, m[row].sum() + 1)
    for (column in 0 until 3) x = max(x, m.fold(0) { acc, arr -> acc + arr[1] } + 1)
    for (row in 0 until 3) m[row][row] = x - m[row].sum()

    // while (m[0][0] + m[1][1] + m[2][2] != x) {
    // x++
    // m[0][0]++
    // m[1][1]++
    // m[2][2]++
    // }
/*
The sum of the diagonal can not sum x yet, but now the relationship is established and the three cells should
be increased by the same value. Which value? Every time we increase them by one x is increased by three, so the
diagonal is two units closer to x (3 - 1). It's possible then to calculate how many times it's necessary to
increment the cells
*/
    val remaining = (x - m[0][0] - m[1][1] - m[2][2]) / 2
    for (row in 0 until 3) m[row][row] += remaining
    print(m.joinToString(System.lineSeparator()) { row -> row.joinToString(" ") })
}


fun main() {
    val line = readLine()!!.split(" ")
    val n = line[0].toInt()
    val mod = line[1].toLong()
    val limit = (n * (n - 1)) / 2
    val dp = Array(n + 1) { LongArray(limit + 1) }
    dp[0][0] = 1L
    var answer = 0L
    for (k in 1..n) {
        for (j in 0..limit) {
            if (j > 0) {
                dp[k][j] += dp[k][j - 1]
            }
            dp[k][j] += dp[k - 1][j]
            if (j >= k) {
                dp[k][j] -= dp[k - 1][j - k]
            }
            if (dp[k][j] >= mod) {
                dp[k][j] -= mod
            }
            if (dp[k][j] < 0L) {
                dp[k][j] += mod
            }
        }
        var here = 0L
        var curr = 0L
        var addend2 = 0L
        var addend1 = 0L
        for (j in 0..limit) {
            here += dp[k - 1][j] * curr
            here %= mod
            curr += addend2
            if (curr >= mod) {
                curr -= mod
            }
            if (j >= k) {
                addend1 -= dp[k - 1][j - k]
            }
            addend1 += dp[k - 1][j]
            if (addend1 >= mod) {
                addend1 -= mod
            }
            if (addend1 < 0L) {
                addend1 += mod
            }
            addend2 += k.toLong() * dp[k - 1][j]
            addend2 -= addend1
            addend2 += mod
            addend2 %= mod
        }
        for (k2 in k + 1..n) {
            here *= k2.toLong()
            here %= mod
        }
        answer += here
        answer %= mod
    }
    println(answer)
}


@file:Suppress("NOTHING_TO_INLINE", "EXPERIMENTAL_FEATURE_WARNING", "OVERRIDE_BY_INLINE")
@file:OptIn(ExperimentalUnsignedTypes::class, ExperimentalStdlibApi::class)

import java.io.PrintWriter
import kotlin.math.*
import kotlin.random.Random
import kotlin.collections.sort as _sort
import kotlin.collections.sortDescending as _sortDescending
import kotlin.io.println as iprintln

/** @author Spheniscine */
fun main() { _writer.solve(); _writer.flush() }
fun PrintWriter.solve() {
//    val startTime = System.nanoTime()

    val numCases = 1//readInt()

    case@ for(case in 1..numCases) {
        //    print("Case #$case: ")

        val n = readInt()
        MOD = readInt()

//        val C = ModIntArray(n+1)
//        C[n]++
//        for(i in 1..n) {
//            for(j in n-i until n) C[j] += C[j+1]
//        }

        var ans = ModInt(0)
        val P = ModIntArray(n+1)
        P[0]++
        for(i in 0 until n) P[i+1] = P[i] * (n - i)

        var D = OffsetModIntArray(0, 0)
        D[0]++
        for(i in 1 until n) {
            for(j in 0 until D.arr.lastIndex) D.arr[j+1] += D.arr[j]
            var acc = ModInt(0)
            for(j in 1..i) acc += D.getPinned(-j-1) * (i - j + 1)

            ans += acc * P[n-i-1]

            acc = ModInt(0)
            val Di = OffsetModIntArray(D.firstIndex - i, D.lastIndex + i)
            for(j in Di.firstIndex .. Di.lastIndex) {
                acc += D.getPinned(j + i) - D.getPinned(j - 1)
                acc -= D.getPinned(j - 1) - D.getPinned(j - i - 2)
                Di[j] = acc
            }
            D = Di
        }

        println(ans.int)
    }

//    iprintln("Time: ${(System.nanoTime() - startTime) / 1000000} ms")
}

fun OffsetModIntArray.getPinned(i: Int) = if (i < firstIndex) ModInt(0) else get(min(i, lastIndex))

class OffsetModIntArray(val firstIndex: Int, val lastIndex: Int) {
    constructor(indices: IntRange): this(indices.first, indices.last)
    inline val indices get() = firstIndex .. lastIndex
    val arr = ModIntArray(lastIndex - firstIndex + 1)
    val size get() = arr.size

    operator fun get(i: Int) = arr[i - firstIndex]
    operator fun set(i: Int, v: ModInt) { arr[i - firstIndex] = v }
    fun last() = arr.last()
}

var MOD = 998244353

infix fun Int.modulo(mod: Int): Int = (this % mod).let { (it shr Int.SIZE_BITS - 1 and mod) + it }
infix fun Long.modulo(mod: Long) = (this % mod).let { (it shr Long.SIZE_BITS - 1 and mod) + it }
infix fun Long.modulo(mod: Int) = modulo(mod.toLong()).toInt()

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

fun Int.powMod(exponent: Long, mod: Int): Int {
    if(exponent < 0) error("Inverse not implemented")
    var res = 1L
    var e = exponent
    var b = modulo(mod).toLong()

    while(e > 0) {
        if(e and 1 == 1L) {
            res = res * b % mod
        }
        e = e shr 1
        b = b * b % mod
    }
    return res.toInt()
}
fun Int.powMod(exponent: Int, mod: Int) = powMod(exponent.toLong(), mod)
fun Int.modPowArray(n: Int, mod: Int): IntArray {
    val res = IntArray(n+1)
    res[0] = 1
    for(i in 1..n) res[i] = mulMod(res[i-1], mod)
    return res
}

inline fun Int.toModInt() = ModInt(this modulo MOD)
inline fun Long.toModInt() = ModInt(this modulo MOD)

/** note: Only use constructor for int within modulo range, otherwise use toModInt **/
inline class ModInt(val int: Int) {

    // normalizes an integer that's within range [-MOD, MOD) without branching
    private inline fun normalize(int: Int) = ModInt((int shr Int.SIZE_BITS - 1 and MOD) + int)

    operator fun plus(other: ModInt) = normalize(int + other.int - MOD) // overflow-safe even if MOD >= 2^30
    inline operator fun plus(other: Int) = plus(other.toModInt())
    operator fun inc() = normalize(int + (1 - MOD))

    operator fun minus(other: ModInt) = normalize(int - other.int)
    inline operator fun minus(other: Int) = minus(other.toModInt())
    operator fun dec() = normalize(int - 1)
    operator fun unaryMinus() = normalize(-int)

    operator fun times(other: ModInt) = ModInt((int.toLong() * other.int % MOD).toInt())
    inline operator fun times(other: Int) = ModInt(int.mulMod(other, MOD))

    fun pow(exponent: Int): ModInt = ModInt(int.powMod(exponent, MOD))

    fun pow(exponent: Long) = ModInt(int.powMod(exponent, MOD))

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

inline operator fun Int.plus(modInt: ModInt) = modInt + this
inline operator fun Int.minus(modInt: ModInt) = toModInt() - modInt
inline operator fun Int.times(modInt: ModInt) = modInt * this

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

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

    override inline fun contains(element: ModInt): Boolean = element.int in intArray

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

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

    override fun iterator(): Iterator<ModInt> = object: Iterator<ModInt> {
        var index = 0
        override fun hasNext(): Boolean = index < size
        override fun next(): ModInt = get(index++)
    }

    fun copyOf(newSize: Int) = ModIntArray(intArray.copyOf(newSize))
    fun copyOf() = copyOf(size)
}
fun ModIntArray.copyInto(destination: ModIntArray, destinationOffset: Int = 0, startIndex: Int = 0, endIndex: Int = size) =
    ModIntArray(intArray.copyInto(destination.intArray, destinationOffset, startIndex, endIndex))
inline fun ModIntArray(size: Int) = ModIntArray(IntArray(size))
inline fun ModIntArray(size: Int, init: (Int) -> ModInt) = ModIntArray(IntArray(size) { init(it).int })

fun ModInt.powArray(n: Int) = ModIntArray(int.modPowArray(n, MOD))

inline fun ModIntArray.first() = get(0)
inline fun ModIntArray.last() = get(lastIndex)
inline fun ModIntArray.joinToString(separator: CharSequence) = intArray.joinToString(separator)
inline fun <R> ModIntArray.fold(init: R, op: (acc: R, ModInt) -> R) = intArray.fold(init) { acc, i -> op(acc, ModInt(i)) }
inline fun <R> ModIntArray.foldRight(init: R, op: (ModInt, acc: R) -> R) = intArray.foldRight(init) { i, acc -> op(ModInt(i), acc) }
fun ModIntArray.sum() = fold(ModInt(0), ModInt::plus)
fun ModIntArray.product() = fold(ModInt(1), ModInt::times)

inline fun <T> Iterable<T>.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }
inline fun <T> Iterable<T>.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }
inline fun <T> Sequence<T>.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }
inline fun <T> Sequence<T>.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }
inline fun <T> Array<T>.sumByModInt(func: (T) -> ModInt) = fold(ModInt(0)) { acc, t -> acc + func(t) }
inline fun <T> Array<T>.productByModInt(func: (T) -> ModInt) = fold(ModInt(1)) { acc, t -> acc * func(t) }
fun Iterable<ModInt>.sum() = sumByModInt { it }
fun Sequence<ModInt>.sum() = sumByModInt { it }
fun Iterable<ModInt>.product() = productByModInt { it }
fun Sequence<ModInt>.product() = productByModInt { it }
fun Collection<ModInt>.toModIntArray() = ModIntArray(size).also { var i = 0; for(e in this) { it[i++] = e } }

/** IO */
//@JvmField val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null
//const val PATH = "src/main/resources/"
//@JvmField val INPUT = File(PATH + "input.txt").inputStream()
//@JvmField val OUTPUT = File(PATH + "output.txt").outputStream()
@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out

const val _BUFFER_SIZE = 1 shl 16
@JvmField val _buffer = ByteArray(_BUFFER_SIZE)
@JvmField var _bufferPt = 0
@JvmField var _bytesRead = 0

tailrec fun readChar(): Char {
    if(_bufferPt == _bytesRead) {
        _bufferPt = 0
        _bytesRead = INPUT.read(_buffer, 0, _BUFFER_SIZE)
    }
    return if(_bytesRead < 0) Char.MIN_VALUE
    else {
        val c = _buffer[_bufferPt++].toChar()
        if (c == '\r') readChar() else c
    }
}

/** @param skipNext Whether to skip the next character (usually whitespace), defaults to true */
fun readCharArray(n: Int, skipNext: Boolean = true): CharArray {
    val res = CharArray(n) { readChar() }
    if(skipNext) readChar()
    return res
}

fun readLine(): String? {
    var c = readChar()
    return if(c == Char.MIN_VALUE) null
    else buildString {
        while(c != '\n' && c != Char.MIN_VALUE) {
            append(c)
            c = readChar()
        }
    }
}
fun readLn() = readLine()!!

fun read() = buildString {
    var c = readChar()
    while(c <= ' ') {
        if(c == Char.MIN_VALUE) return@buildString
        c = readChar()
    }
    do {
        append(c)
        c = readChar()
    } while(c > ' ')
}
fun readInt() = read().toInt()
fun readDouble() = read().toDouble()
fun readLong() = read().toLong()
fun readStrings(n: Int) = List(n) { read() }
fun readLines(n: Int) = List(n) { readLn() }
fun readInts(n: Int) = List(n) { read().toInt() }
fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readDoubles(n: Int) = List(n) { read().toDouble() }
fun readDoubleArray(n: Int) = DoubleArray(n) { read().toDouble() }
fun readLongs(n: Int) = List(n) { read().toLong() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

@JvmField val _writer = PrintWriter(OUTPUT, false)

/**  sort overrides to avoid quicksort attacks */

@JvmField var _random: Random? = null
val random get() = _random ?: Random(0x594E215C123 * System.nanoTime()).also { _random = it }

inline fun <A, T> _mergeSort(a0: A, n: Int, tmp0: A, get: A.(Int) -> T, set: A.(Int, T) -> Unit, cmp: (T, T) -> Int) {
    var a = a0
    var tmp = tmp0
    var len = 1
    while(len < n) {
        var l = 0
        while(true) {
            val m = l + len
            if(m >= n) break
            val r = min(n, m + len)
            var i = l
            var j = m
            for(k in l until r) {
                if(i != m && (j == r || cmp(a.get(i), a.get(j)) <= 0)) {
                    tmp.set(k, a.get(i++))
                } else tmp.set(k, a.get(j++))
            }
            l = r
        }
        for(i in l until n) tmp.set(i, a.get(i))
        val t = a; a = tmp; tmp = t
        len += len
    }
    if(a !== a0) for(i in 0 until n) a0.set(i, tmp0.get(i))
}

inline fun IntArray.sortWith(cmp: (Int, Int) -> Int) { _mergeSort(this, size, IntArray(size), IntArray::get, IntArray::set, cmp) }
inline fun <T: Comparable<T>> IntArray.sortBy(func: (Int) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> IntArray.sortByDescending(func: (Int) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun IntArray.sort() { sortBy { it } }
fun IntArray.sortDescending() { sortByDescending { it } }

inline fun LongArray.sortWith(cmp: (Long, Long) -> Int) { _mergeSort(this, size, LongArray(size), LongArray::get, LongArray::set, cmp) }
inline fun <T: Comparable<T>> LongArray.sortBy(func: (Long) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> LongArray.sortByDescending(func: (Long) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun LongArray.sort() { sortBy { it } }
fun LongArray.sortDescending() { sortByDescending { it } }

inline fun DoubleArray.sortWith(cmp: (Double, Double) -> Int) { _mergeSort(this, size, DoubleArray(size), DoubleArray::get, DoubleArray::set, cmp) }
inline fun <T: Comparable<T>> DoubleArray.sortBy(func: (Double) -> T) { sortWith { a, b -> func(a).compareTo(func(b)) } }
inline fun <T: Comparable<T>> DoubleArray.sortByDescending(func: (Double) -> T) { sortWith { a, b -> func(b).compareTo(func(a)) } }
fun DoubleArray.sort() { sortBy { it } }
fun DoubleArray.sortDescending() { sortByDescending { it } }

inline fun CharArray.sort() { _sort() }
inline fun CharArray.sortDescending() { _sortDescending() }

inline fun <T : Comparable<T>> Array<out T>.sort() = _sort()
inline fun <T : Comparable<T>> Array<out T>.sortDescending() = _sortDescending()
inline fun <T : Comparable<T>> MutableList<out T>.sort() = _sort()
inline fun <T : Comparable<T>> MutableList<out T>.sortDescending() = _sortDescending()

// import preserving junk function
@Suppress("NonAsciiCharacters") fun 雪花飄飄北風嘯嘯天地一片蒼茫() { iprintln(max(1, 2)) }

fun IntArray.sumLong() = sumOf { it.toLong() }

fun IntArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun IntArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun LongArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun LongArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun DoubleArray.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun DoubleArray.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun <T: Comparable<T>> Array<T>.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun <T: Comparable<T>> Array<T>.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }
fun <T: Comparable<T>> List<T>.sortedIndices() = IntArray(size) { it }.also { it.sortBy(::get) }
fun <T: Comparable<T>> List<T>.sortedIndicesDescending() = IntArray(size) { it }.also { it.sortByDescending(::get) }

// max/min Kotlin 1.6 -> 1.4 shim
fun IntArray.max() = maxOf { it }
fun IntArray.min() = minOf { it }
fun LongArray.max() = maxOf { it }
fun LongArray.min() = minOf { it }
fun CharArray.max() = maxOf { it }
fun CharArray.min() = minOf { it }
fun <T : Comparable<T>> Iterable<T>.max() = maxOf { it }
fun <T : Comparable<T>> Iterable<T>.min() = minOf { it }
fun <T : Comparable<T>> Sequence<T>.max() = maxOf { it }
fun <T : Comparable<T>> Sequence<T>.min() = minOf { it }