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

import java.io.PrintWriter
import java.util.Arrays
import java.util.NoSuchElementException
import java.util.TreeSet
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: ")

        object {
            val n = readInt()
            val m = readInt()
            val q = readInt()

            val P = readIntArray(n)
            val Q = IntArray(n + 1)
            init {
                for(i in 0 until n) Q[P[i]] = i
            }

            val A = IntArray(m)
            val B = IntArray(m) {
                A[it] = readInt() - 1
                readInt() - 1
            }

            val T = IntArray(q)
            val X = IntArray(q) {
                T[it] = readInt()
                readInt() - 1
            }

            val edgeRemoved = BooleanArray(m)

            init {
                for (i in 0 until q) {
                    if (T[i] == 2) edgeRemoved[X[i]] = true
                }
            }

            val C = Array(n) { i -> _Ez_Int_TreeSet().also { it.add(P[i]) } }
            val par = IntArray(n) { it }

            val hist = IntList()
            fun merge(ei: Int): Int {
                var u = par[A[ei]]
                var v = par[B[ei]]

                if(u == v) return -1

                if(C[u].size() < C[v].size()) u = v.also { v = u }
                for(x in C[v]) {
                    par[Q[x]] = u
                    C[u].add(x)
                }

                return v
            }

            init {
                for(i in 0 until m) if(!edgeRemoved[i]) merge(i)
                for(i in q-1 downTo 0) if(T[i] == 2) {
                    hist.add(merge(X[i]))
                }

                for(i in 0 until q) {
                    val x = X[i]
                    when(T[i]) {
                        1 -> {
                            val ans = C[par[x]].removeLast()
                            println(ans)
                        }
                        2 -> {
                            val v = hist.pop()
                            if (v != -1) {
                                val u = par[v]

                                if(C[v].size() > 0) {
                                    var w = C[v].first
                                    while (true) {
                                        if (!C[u].remove(w)) C[v].remove(w)
                                        par[Q[w]] = v
                                        w = C[v].higher(w)
                                        if(C[v].returnedNull()) break
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }

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

class _Ez_Int_TreeSet @JvmOverloads constructor(capacity: Int = DEFAULT_CAPACITY) {
    // Arrays are 1-indexed. Index 0 is a null node.
    private /*C*/  var key: IntArray
    private var left: IntArray
    private var right: IntArray
    private var p: IntArray
    private var color: BooleanArray
    private var size = 0
    private var root = 0
    private var returnedNull = false

    constructor( /*C*/
        srcArray: IntArray
    ) : this(srcArray.size) {
        for ( /*C*/
        /*C*/element in srcArray) {
            add(element)
        }
    }

    constructor(javaCollection: Collection<Int>) : this(javaCollection.size) {
        for ( /*C*/
        /*C*/element in javaCollection) {
            add(element)
        }
    }

    fun size(): Int {
        return size
    }

    val isEmpty: Boolean
        get() = size == 0

    operator fun contains( /*C*/
        /*C*/element: Int
    ): Boolean {
        var x = root
        while (x != NULL) {
            x = if (element < key[x]) {
                left[x]
            } else if (element > key[x]) {
                right[x]
            } else {
                return true
            }
        }
        return false
    }

    operator fun iterator(): IntIterator {
        return _Ez_Int_TreeSetIterator()
    }

    /*C*/   fun toArray(): IntArray {
        /*C*/
        val result = IntArray(size)
        var i = 0
        var x = firstNode()
        while (x != NULL) {
            result[i] = key[x]
            x = successorNode(x)
            i++
        }
        return result
    }

    fun add( /*C*/
        /*C*/element: Int
    ): Boolean {
        var y = NULL
        var x = root
        while (x != NULL) {
            y = x
            x = if (element < key[x]) {
                left[x]
            } else if (element > key[x]) {
                right[x]
            } else {
                return false
            }
        }
        if (size == color.size - 1) {
            enlarge()
        }
        val z = ++size
        key[z] = element
        p[z] = y
        if (y == NULL) {
            root = z
        } else {
            if (element < key[y]) {
                left[y] = z
            } else {
                right[y] = z
            }
        }
        left[z] = NULL
        right[z] = NULL
        color[z] = RED
        fixAfterAdd(z)
        return true
    }

    fun remove( /*C*/
        /*C*/element: Int
    ): Boolean {
        var z = root
        while (z != NULL) {
            z = if (element < key[z]) {
                left[z]
            } else if (element > key[z]) {
                right[z]
            } else {
                removeNode(z)
                return true
            }
        }
        return false
    }

    private fun removeNode(z: Int) {
        val y = if (left[z] == NULL || right[z] == NULL) z else successorNode(z)
        val x = if (left[y] != NULL) left[y] else right[y]
        p[x] = p[y]
        if (p[y] == NULL) {
            root = x
        } else {
            if (y == left[p[y]]) {
                left[p[y]] = x
            } else {
                right[p[y]] = x
            }
        }
        if (y != z) {
            key[z] = key[y]
        }
        if (color[y] == BLACK) {
            fixAfterRemove(x)
        }
        // Swap with last
        if (y != size) {
            // copy fields
            key[y] = key[size]
            left[y] = left[size]
            right[y] = right[size]
            p[y] = p[size]
            color[y] = color[size]
            // fix the children's parents
            p[left[size]] = y
            p[right[size]] = y
            // fix one of the parent's children
            if (left[p[size]] == size) {
                left[p[size]] = y
            } else {
                right[p[size]] = y
            }
            // fix root
            if (root == size) {
                root = y
            }
        }
        size--
    }

    private fun successorNode(x: Int): Int {
        var x = x
        return if (right[x] != NULL) {
            x = right[x]
            while (left[x] != NULL) {
                x = left[x]
            }
            x
        } else {
            var y = p[x]
            while (y != NULL && x == right[y]) {
                x = y
                y = p[y]
            }
            y
        }
    }

    private fun fixAfterAdd(z: Int) {
        var z = z
        while (color[p[z]] == RED) {
            if (p[z] == left[p[p[z]]]) {
                val y = right[p[p[z]]]
                if (color[y] == RED) {
                    color[p[z]] = BLACK
                    color[y] = BLACK
                    color[p[p[z]]] = RED
                    z = p[p[z]]
                } else {
                    if (z == right[p[z]]) {
                        z = p[z]
                        rotateLeft(z)
                    }
                    color[p[z]] = BLACK
                    color[p[p[z]]] = RED
                    rotateRight(p[p[z]])
                }
            } else {
                val y = left[p[p[z]]]
                if (color[y] == RED) {
                    color[p[z]] = BLACK
                    color[y] = BLACK
                    color[p[p[z]]] = RED
                    z = p[p[z]]
                } else {
                    if (z == left[p[z]]) {
                        z = p[z]
                        rotateRight(z)
                    }
                    color[p[z]] = BLACK
                    color[p[p[z]]] = RED
                    rotateLeft(p[p[z]])
                }
            }
        }
        color[root] = BLACK
    }

    private fun fixAfterRemove(x: Int) {
        var x = x
        while (x != root && color[x] == BLACK) {
            if (x == left[p[x]]) {
                var w = right[p[x]]
                if (color[w] == RED) {
                    color[w] = BLACK
                    color[p[x]] = RED
                    rotateLeft(p[x])
                    w = right[p[x]]
                }
                if (color[left[w]] == BLACK && color[right[w]] == BLACK) {
                    color[w] = RED
                    x = p[x]
                } else {
                    if (color[right[w]] == BLACK) {
                        color[left[w]] = BLACK
                        color[w] = RED
                        rotateRight(w)
                        w = right[p[x]]
                    }
                    color[w] = color[p[x]]
                    color[p[x]] = BLACK
                    color[right[w]] = BLACK
                    rotateLeft(p[x])
                    x = root
                }
            } else {
                var w = left[p[x]]
                if (color[w] == RED) {
                    color[w] = BLACK
                    color[p[x]] = RED
                    rotateRight(p[x])
                    w = left[p[x]]
                }
                if (color[left[w]] == BLACK && color[right[w]] == BLACK) {
                    color[w] = RED
                    x = p[x]
                } else {
                    if (color[left[w]] == BLACK) {
                        color[right[w]] = BLACK
                        color[w] = RED
                        rotateLeft(w)
                        w = left[p[x]]
                    }
                    color[w] = color[p[x]]
                    color[p[x]] = BLACK
                    color[left[w]] = BLACK
                    rotateRight(p[x])
                    x = root
                }
            }
        }
        color[x] = BLACK
    }

    private fun rotateLeft(x: Int) {
        val y = right[x]
        right[x] = left[y]
        if (left[y] != NULL) {
            p[left[y]] = x
        }
        p[y] = p[x]
        if (p[x] == NULL) {
            root = y
        } else {
            if (x == left[p[x]]) {
                left[p[x]] = y
            } else {
                right[p[x]] = y
            }
        }
        left[y] = x
        p[x] = y
    }

    private fun rotateRight(x: Int) {
        val y = left[x]
        left[x] = right[y]
        if (right[y] != NULL) {
            p[right[y]] = x
        }
        p[y] = p[x]
        if (p[x] == NULL) {
            root = y
        } else {
            if (x == right[p[x]]) {
                right[p[x]] = y
            } else {
                left[p[x]] = y
            }
        }
        right[y] = x
        p[x] = y
    }

    fun clear() {
        color[NULL] = BLACK
        size = 0
        root = NULL
    }

    private fun enlarge() {
        val newLength = Math.max(
            color.size + 1,
            (color.size * ENLARGE_SCALE).toInt()
        )
        key = Arrays.copyOf(key, newLength)
        left = Arrays.copyOf(left, newLength)
        right = Arrays.copyOf(right, newLength)
        p = Arrays.copyOf(p, newLength)
        color = Arrays.copyOf(color, newLength)
    }

    private fun firstNode(): Int {
        var x = root
        while (left[x] != NULL) {
            x = left[x]
        }
        return x
    }

    private fun lastNode(): Int {
        var x = root
        while (right[x] != NULL) {
            x = right[x]
        }
        return x
    }

    /*C*/  /*C*/
    val first: Int
        get() {
            if (root == NULL) {
                returnedNull = true
                return DEFAULT_NULL_ELEMENT
            }
            val x = firstNode()
            returnedNull = false
            return key[x]
        }

    /*C*/  /*C*/
    val last: Int
        get() {
            if (root == NULL) {
                returnedNull = true
                return DEFAULT_NULL_ELEMENT
            }
            val x = lastNode()
            returnedNull = false
            return key[x]
        }

    /*C*/   fun  /*C*/removeFirst(): Int {
        if (root == NULL) {
            returnedNull = true
            return DEFAULT_NULL_ELEMENT
        }
        val x = firstNode()
        returnedNull = false
        val   /*C*/removedElement/*C*/ = key[x]
        removeNode(x)
        return removedElement
    }

    /*C*/   fun  /*C*/removeLast(): Int {
        if (root == NULL) {
            returnedNull = true
            return DEFAULT_NULL_ELEMENT
        }
        val x = lastNode()
        returnedNull = false
        val   /*C*/removedElement/*C*/ = key[x]
        removeNode(x)
        return removedElement
    }

    /*C*/   fun  /*C*/floor( /*C*/
        /*C*/element: Int
    ): Int {
        var x = root
        while (x != NULL) {
            if (element > key[x]) {
                if (right[x] != NULL) {
                    x = right[x]
                } else {
                    returnedNull = false
                    return key[x]
                }
            } else if (element < key[x]) {
                if (left[x] != NULL) {
                    x = left[x]
                } else {
                    var y = p[x]
                    while (y != NULL && x == left[y]) {
                        x = y
                        y = p[y]
                    }
                    return if (y == NULL) {
                        returnedNull = true
                        DEFAULT_NULL_ELEMENT
                    } else {
                        returnedNull = false
                        key[y]
                    }
                }
            } else {
                returnedNull = false
                return key[x]
            }
        }
        returnedNull = true
        return DEFAULT_NULL_ELEMENT
    }

    /*C*/   fun  /*C*/ceiling( /*C*/
        /*C*/element: Int
    ): Int {
        var x = root
        while (x != NULL) {
            if (element < key[x]) {
                if (left[x] != NULL) {
                    x = left[x]
                } else {
                    returnedNull = false
                    return key[x]
                }
            } else if (element > key[x]) {
                if (right[x] != NULL) {
                    x = right[x]
                } else {
                    var y = p[x]
                    while (y != NULL && x == right[y]) {
                        x = y
                        y = p[y]
                    }
                    return if (y == NULL) {
                        returnedNull = true
                        DEFAULT_NULL_ELEMENT
                    } else {
                        returnedNull = false
                        key[y]
                    }
                }
            } else {
                returnedNull = false
                return key[x]
            }
        }
        returnedNull = true
        return DEFAULT_NULL_ELEMENT
    }

    /*C*/   fun  /*C*/lower( /*C*/
        /*C*/element: Int
    ): Int {
        var x = root
        while (x != NULL) {
            if (element > key[x]) {
                if (right[x] != NULL) {
                    x = right[x]
                } else {
                    returnedNull = false
                    return key[x]
                }
            } else {
                if (left[x] != NULL) {
                    x = left[x]
                } else {
                    var y = p[x]
                    while (y != NULL && x == left[y]) {
                        x = y
                        y = p[y]
                    }
                    return if (y == NULL) {
                        returnedNull = true
                        DEFAULT_NULL_ELEMENT
                    } else {
                        returnedNull = false
                        key[y]
                    }
                }
            }
        }
        returnedNull = true
        return DEFAULT_NULL_ELEMENT
    }

    /*C*/   fun  /*C*/higher( /*C*/
        /*C*/element: Int
    ): Int {
        var x = root
        while (x != NULL) {
            if (element < key[x]) {
                if (left[x] != NULL) {
                    x = left[x]
                } else {
                    returnedNull = false
                    return key[x]
                }
            } else {
                if (right[x] != NULL) {
                    x = right[x]
                } else {
                    var y = p[x]
                    while (y != NULL && x == right[y]) {
                        x = y
                        y = p[y]
                    }
                    return if (y == NULL) {
                        returnedNull = true
                        DEFAULT_NULL_ELEMENT
                    } else {
                        returnedNull = false
                        key[y]
                    }
                }
            }
        }
        returnedNull = true
        return DEFAULT_NULL_ELEMENT
    }

    fun returnedNull(): Boolean {
        return returnedNull
    }

    override fun equals(o: Any?): Boolean {
        if (this === o) return true
        if (o == null || javaClass != o.javaClass) return false
        val that = o as _Ez_Int_TreeSet
        if (size != that.size) {
            return false
        }
        var x = firstNode()
        var y = that.firstNode()
        while (x != NULL) {
            if (key[x] != that.key[y]) {
                return false
            }
            x = successorNode(x)
            y = that.successorNode(y)
        }
        return true
    }

    override fun hashCode(): Int {
//        var hash = HASHCODE_INITIAL_VALUE
//        var x = firstNode()
//        while (x != NULL) {
//            hash = (hash xor PrimitiveHashCalculator.getHash(key[x])) * HASHCODE_MULTIPLIER
//            x = successorNode(x)
//        }
//        return hash
        return 0
    }

    override fun toString(): String {
        val sb = StringBuilder()
        sb.append('[')
        var x = firstNode()
        while (x != NULL) {
            if (sb.length > 1) {
                sb.append(", ")
            }
            sb.append(key[x])
            x = successorNode(x)
        }
        sb.append(']')
        return sb.toString()
    }

    private inner class _Ez_Int_TreeSetIterator constructor() : IntIterator() {
        private var x: Int
        override fun hasNext(): Boolean {
            return x != NULL
        }

        /*C*/   override fun  /*C*/nextInt(): Int {
            if (x == NULL) {
                throw NoSuchElementException("Iterator doesn't have more elements")
            }
            val   /*C*/result/*C*/ = key[x]
            x = successorNode(x)
            return result
        }

        init {
            x = firstNode()
        }
    }

    companion object {
        private const val DEFAULT_CAPACITY = 10
        private const val ENLARGE_SCALE = 2.0
        private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b
        private const val HASHCODE_MULTIPLIER = 0x01000193
        private const val BLACK = false
        private const val RED = true
        private const val NULL = 0
        private const /*C*/ val   /*C*/DEFAULT_NULL_ELEMENT = 0
    }

    init {
        var capacity = capacity
        require(capacity >= 0) { "Capacity must be non-negative" }
        capacity++
        key = IntArray(capacity)
        left = IntArray(capacity)
        right = IntArray(capacity)
        p = IntArray(capacity)
        color = BooleanArray(capacity)
        color[NULL] = BLACK
        size = 0
        root = NULL
        returnedNull = false
    }
}

class IntList(initialCapacity: Int = 12) {
    private var _arr = IntArray(initialCapacity)
    private val capacity get() = _arr.size
    var size = 0
        private set
    inline val lastIndex get() = size - 1
    inline val indices get() = 0 until size

    constructor(copyFrom: IntArray): this(copyFrom.size) { copyFrom.copyInto(_arr); size = copyFrom.size }
    constructor(copyFrom: Collection<Int>): this(copyFrom.size) { _arr = copyFrom.toIntArray(); size = copyFrom.size }

    fun contentEquals(other: IntList): Boolean {
        return this === other || size == other.size && indices.all { this[it] == other[it] }
    }

    private fun grow(minCapacity: Int = 8) {
        val newCapacity = maxOf(minCapacity, capacity + (capacity shr 1))
        _arr = _arr.copyOf(newCapacity)
    }

    fun ensureCapacity(minCapacity: Int) { if(capacity < minCapacity) grow(minCapacity) }

    operator fun get(index: Int): Int {
        require(index in 0 until size)
        return _arr[index]
    }

    operator fun set(index: Int, value: Int) {
        require(index in 0 until size)
        _arr[index] = value
    }

    fun add(value: Int) {
        if(size == capacity) grow()
        _arr[size++] = value
    }

    fun addAll(list: IntList) {
        ensureCapacity(size + list.size)
        list._arr.copyInto(_arr, size, 0, list.size)
        size += list.size
    }

    fun add(index: Int, element: Int) {
        if(size == capacity) grow()
        _arr.copyInto(_arr, index + 1, index, size)
        size++
        set(index, element)
    }

    fun clear() { size = 0 }

    fun removeAt(index: Int): Int {
        val e = get(index)
        _arr.copyInto(_arr, index, index + 1, size)
        size--
        return e
    }

    fun indexOf(e: Int): Int {
        for(i in 0 until size) if(this[i] == e) return i
        return -1
    }

    fun remove(e: Int): Boolean {
        val i = indexOf(e)
        if(i == -1) return false
        removeAt(i)
        return true
    }

    operator fun iterator() = object: IntIterator() {
        private var pos = 0
        override fun hasNext() = pos < size
        override fun nextInt() = get(pos++)
    }

    inline fun isEmpty() = size == 0
    inline fun isNotEmpty() = size != 0

    fun pop() = _arr[--size]

    fun popToSize(s: Int) {
        require(s >= 0)
        if(s < size) size = s
    }

    fun swap(i: Int, j: Int) { val t = this[i]; this[i] = this[j]; this[j] = t }
    fun reverse() {
        for(i in 0 until size / 2) swap(i, lastIndex - i)
    }

    fun shuffle(rnd: Random = random) { for(i in lastIndex downTo 1) swap(i, rnd.nextInt(i + 1)) }
    fun sort() { shuffle(); _arr._sort(0, size) }
    fun sortDescending() { sort(); reverse() }

    fun joinToString(separator: CharSequence) = if(size == 0) "" else let {
        buildString {
            append(it[0])
            for (i in 1 until size) {
                append(separator).append(it[i])
            }
        }
    }

    override fun toString() = "[" + joinToString(", ") + "]"

    fun toIntArray() = _arr.copyOf(size)
    fun toList() = List(size, ::get)

    inline fun first() = get(0)
    inline fun last() = get(lastIndex)
}

inline fun IntList(size: Int, init: (Int) -> Int) = IntList(size).apply {
    for(i in 0 until size) { add(init(i)) }
}
inline fun IntArray.toIntList() = IntList(this)
inline fun Collection<Int>.toIntList() = IntList(this)
inline fun intListOf(vararg values: Int) = IntList(values)

fun IntList.max() = (1 until size).fold(this[0]) { acc, i -> max(acc, this[i]) }
fun IntList.min() = (1 until size).fold(this[0]) { acc, i -> min(acc, this[i]) }
fun IntList.getOrNull(i: Int) = if(i in indices) get(i) else null
inline fun IntList.count(predicate: (Int) -> Boolean) = indices.count { predicate(this[it]) }
fun IntList.copyOf() = IntList(size, ::get)

/** IO */
//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 }

fun IntArray.sort() { shuffle(random); _sort() }
fun IntArray.sortDescending() { shuffle(random); _sortDescending() }

fun LongArray.sort() { shuffle(random); _sort() }
fun LongArray.sortDescending() { shuffle(random); _sortDescending() }

fun DoubleArray.sort() { shuffle(random); _sort() }
fun DoubleArray.sortDescending() { shuffle(random); _sortDescending() }

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

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


import kotlin.math.*
fun main(args: Array<String>){
	val n  = readLine()!!.toLong()
	println((n/2).toLong()+1)
}


import java.util.*

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

    println(1 + n / 2)
}


import java.lang.Math.floor
//   1 2 3 4 5 6 7 8 9
// 0,1,2,2,3,3,4,4,5,5
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    if(n == 0) print(0)
    else if(n == 1) print(1)
    else print(floor(n.toDouble() / 2).toInt() + 1)
}


fun main(args: Array<String>) {
    println(readLine()!!.toInt()/2 + 1)
}


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


fun main() {
    val n = readInt()

    var possibilities = setOf(0)

    repeat(n) {
        val a = readInt()

        possibilities = sequence {
            for(p in possibilities) {
                yield((p + a) umod 360)
                yield((p - a) umod 360)
            }
        }.toSet()
    }

    if(0 in possibilities) println("YES") else println("NO")
}

infix fun Int.umod(divisor: Int) =
    (this % divisor).let { if(it >= 0) it else it + divisor }

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


import kotlin.math.*

fun main(arg: Array<String>){
	var N = readLine()!!.toInt()
	val NN = N
	val M = 2.0.pow(N.toDouble()).toInt()
	val L = mutableListOf<Int>()
	var S = 0
	while(N > 0){
		L.add(readLine()!!.toInt())
		N--
	}
	L.forEach(){
		S += it
	}
	for(i in 0..M-1){
		val opts = i.toString(2).padStart(NN,'0')
		//println(opts)
		var Sum = 0
		for (i in 1..opts.length){
			if(opts[i-1] == '0'){
				Sum -= L[i-1]
			}else{
				Sum += L[i-1]
			}
		}
		if(Sum.rem(360) == 0){
			//println("OGON: $opts $Sum")
			println("YES")
			return
		}

	}
	println("NO")
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val nums = IntArray(n)
    for (i in 0 until n) {
        nums[i] = readLine()!!.toInt()
    }
    var res = mutableListOf<Int>()
    res.add(circle(nums[0]))
    res.add(circle(-nums[0]))
    for (i in 1 until n) {
        val lr = res.count()
        val nres = mutableListOf<Int>()
        for (j in 0 until lr) {
            nres.add(circle(res[j] + nums[i]))
            nres.add(circle(res[j] - nums[i]))
        }
        res = nres
    }
    if (res.contains(0)) {
        println("YES")
    } else {
        println("NO")
    }
}

fun circle(x: Int): Int {
    if (x < 0) {
        return 360 + x
    } else
        return x % 360
}


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

fun BufferedReader.readIntList() = readLine().split(' ').map(String::toInt)
fun BufferedReader.readLongList() = readLine().split(' ').map(String::toLong)

class Solution(private val inf: BufferedReader, private val ouf: PrintWriter) : Runnable {
    constructor() : this(BufferedReader(InputStreamReader(System.`in`)), PrintWriter(System.out))

    fun solve() {
        val n = inf.readLine().toInt()
        val a = IntArray(n) {
            inf.readLine().toInt()
        }
        var ans = false
        for (i in 0 until (1 shl n)) {
            var sum = 0
            for (j in a.indices) {
                if ((i and (1 shl j)) == 0) sum += a[j] else sum -= a[j]
            }
            if ((sum % 360 + 360) % 360 == 0) ans = true
        }
        ouf.println(if (ans) "YES" else "NO")
    }

    override fun run() {
//        for (testNum in 1..inf.readLine().toInt()) {
            solve()
//        }

        ouf.close()
    }
}

fun main(args: Array<String>) {
    Thread(null, Solution(), "name", 1 shl 27).start()
}


import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val n = sc.nextInt()
    val m = sc.nextInt()
    val adj = Array(n) { mutableSetOf<Int>() }
    for (i in 0 until m) {
        val u = sc.nextInt() - 1
        val v = sc.nextInt() - 1
        adj[u].add(v)
        adj[v].add(u)
    }
    if (n <= 6) {
        println(m)
    } else {
        var max = 0
        for (i in 0 until n) {
            for (j in 0 until n) {
                val count = m - adj[i].intersect(adj[j]).count()
                max = Math.max(max, count)
            }
        }
        println(max)
    }
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

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

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

        return st.nextToken()
    }

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


import kotlin.math.*

fun main() {
    val (n, m) = readLine()!!.split(" ").map(String::toInt)
    val graph = Array(n) { ArrayList<Int>() }

    for (i in 0 until m) {
        val (u, v) = readLine()!!.split(" ").map(String::toInt)
        graph[u - 1].add(v - 1)
        graph[v - 1].add(u - 1)
    }

    val a = Array(6) { CharArray(6) { 0.toChar() } }
    var ans = 0

    for (i in 0..279936) {
        for (w in 0 until 6) {
            for (q in 0 until 6) a[w][q] = 0.toChar()
        }

        val c = ArrayList<Int>()
        var v = i
        for (j in 0 until n) {
            c.add(v % 6)
            v /= 6
        }

        var cans = 0
        for (j in 0 until n) {
            for (t in graph[j]) {
                if (a[min(c[j], c[t])][max(c[j], c[t])] == 0.toChar()) {
                    a[min(c[j], c[t])][max(c[j], c[t])] = 1.toChar()
                    cans++
                }
            }
        }
        ans = max(ans, cans)
    }
    println(ans)
}


import java.lang.Integer.min

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

fun main() {
    val (n,m) = readInts()
    val graph = HashMap<Int, MutableSet<Int>>()
    if (n <= 6) {
        println(m)
        return
    }
    for (i in 1..n) {
        graph[i] = HashSet<Int>()
    }
    for (i in 1..m) {
        val (s, t) = readInts()
        graph[s]?.add(t)
        graph[t]?.add(s)
    }
    // Iterate over all pairs, find ones with smallest intersection
    // in their adjacency sets
    // return m - size(intersection)
    var minIntersection = m
    for (i in 1..n) {
        for (j in i..n) {
            minIntersection = graph[j]?.let { graph[i]?.intersect(it)?.size }?.let { min(minIntersection, it) }!!
        }
    }
    println(m - minIntersection)
    return

}


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

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

    val n = sc.nextInt()
    val m = sc.nextInt()

    val vs = Array(n + 1) { i -> Vertex(i) }

    repeat(m) {
        val u = vs[sc.nextInt()]
        val v = vs[sc.nextInt()]
        u.edge.add(v)
        v.edge.add(u)
    }

    solve(n, vs, mutableListOf<Int>())
    println(max)
}

var max = -1

fun solve(n: Int, vs: Array<Vertex>, marked: MutableList<Int>) {
    if (marked.size == n) {
        val res: Int = check(n, vs, marked) ?: -1
        if (res == 21) {
            println(marked)
            readLine()
        }
        max = maxOf(max, res)
        return
    }

    for (j in 1..6) {
        marked.add(j)
        solve(n, vs, marked)
        marked.removeAt(marked.lastIndex)
    }
}

fun check(n: Int, vs: Array<Vertex>, marked: MutableList<Int>): Int? {
    val used = mutableSetOf<Domino>()
    for (x in 1..n) {
        val v = vs[x]
        for (u in v.edge) {
            if (v.n >= u.n) continue
            used.add(Domino(minOf(marked[v.n - 1], marked[u.n - 1]), maxOf(marked[v.n - 1], marked[u.n - 1])))
        }
    }
    return used.size
}

data class Domino(val x: Int, val y: Int)

data class Vertex(val n: Int) {
    val edge = mutableListOf<Vertex>()
}

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

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

        return st.nextToken()
    }

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


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

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

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

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

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    val s = reader.next()
    var lc: Char? = null
    for (c in s) {
        if (c !in listOf<Char>('a','e','i','o','u','y') || lc == null) {
            writer.print(c)
        } else if (lc !in listOf<Char>('a','e','i','o','u','y')){
            writer.print(c)
        }
        lc = c
    }
    writer.println()
}

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

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

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

        }
        return tokenizer!!.nextToken()
    }

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

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

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

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

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


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

fun main(args : Array<String>) {
    Thread { run() }.start()
}
val vowels = sortedSetOf('a', 'e', 'i', 'o', 'u', 'y')
fun isVowel(c:Char):Boolean{
  for(x in vowels)
    if(x == c)
      return true
  return false
}
val sc = Scanner(System.`in`)
fun run() {
  val n = sc.nextInt()
  val s = sc.next()
  var out = ArrayList<Char>()
  var ok = false
  for(i in 0 until n){
    if(ok && isVowel(s[i]))continue;
    out.add(s[i])
    ok = (isVowel(s[i]))
  }
  for(c in out)
    print(c)
}

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))
}
fun Array<IntArray>.print() {
    for (i in this)
        i.print()
}
fun LongArray.print() {
    println(Arrays.toString(this))
}
fun Array<LongArray>.print() {
    for (i in this)
        i.print()
}
fun BooleanArray.print() {
    println(Arrays.toString(this))
}
fun nod(a: Long, b: Long): Long {
    var a1 = a
    var b1 = b
    while (a1 != 0L && b1 != 0L) {
        if (a1 < b1)
            b1 %= a1
        else
            a1 %= b1
    }
    return a1 + b1
}
fun nok(a: Long, b: Long): Long = a * b / nod(a, b)


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

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

    var n = sc.nextInt()

    var str = sc.next().toCharArray()

    var i = 0

    var list = listOf('a', 'e', 'i', 'o', 'u', 'y')
    var ans = ""
//    var flag = true
//    while (i<str.size){
//        if (list.contains(str[i]) && list.contains(str[i+1]) && flag){
//            ans+=str[i]
//            i++
//            flag = false
//        }else{
//            ans+=str[i]
//            flag = true
//        }
//        i++
//    }
//    println(ans)
    var flag = true
    while (i < str.size) {
        if (list.contains(str[i]) && flag) {
            ans += str[i]
            flag = false
        } else if (!list.contains(str[i])) {
            ans += str[i]
            flag = true
        }
        i++
    }
    println(ans)

}


fun main(args: Array<String>) {

    val n: Int = readLine()!!.toInt()
    val s: String = readLine()!!

    var i: Int = 0
    var prevVowel: Boolean = false
    while (i < s.length) {

        if (!isCHarVowel(s[i])) {
            print(s[i])

            prevVowel = false
        }
        if (!prevVowel && isCHarVowel(s[i]))
        {
            print(s[i])
            prevVowel = true
        }

        i++
    }

}

fun isCHarVowel(chr: Char): Boolean {
    val vowel: String = "aeiouy"

    for (item in vowel) {
        if (item == chr) {
            return true
        }
    }

    return false
}


import kotlin.math.*

fun main(args: Array<String>) {
    val (n, m, a, b) = readLine()!!.split(" ").map { it.toLong() }
    val d = n % m
    val u = m - d
    val pu = u * a
    val pd = d * b
    println(min(pu, pd))
}


fun main() {
    var (n, m, a, b) = readLongs()
    if (n < m) {
        var t = (m - n) * a
        var g = n * b
        println(minOf(t,g))
    } else {
        var t = (n % m) * b
        var g = (m - (n % m)) * a
        println(minOf(t, g))
    }
}

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


import java.util.*

fun main(args: Array<String>) {
    val reader = Scanner(System.`in`)
    var m = 0L
    var n = 0L
    var a = 0L
    var b = 0L

    reader.nextLine().split(" ").forEachIndexed { index, s ->
        when(index){
            0 -> n = s.toLong()
            1 -> m = s.toLong()
            2 -> a = s.toLong()
            3 -> b = s.toLong()
        }
    }

    var build = (m - n % m) * a
    var decrease = n % m *b

    if (build < decrease){
        println(build)
    } else {
        println(decrease)
    }
}


import kotlin.math.min

fun main() {
    val (numBoxes, numDelegations, buildFee, demolishFee) = readLine()!!.split(" ").map(String::toLong)
    print(min(demolishFee * (numBoxes % numDelegations), buildFee * (numDelegations - (numBoxes % numDelegations))))
}


fun main() {
    val numberOfRequiredLetters = readLine()?.toInt()
    val pattern = readLine()

    if (numberOfRequiredLetters == null || pattern == null) {
        println("Wrong input")
        return
    }

    println(Solution.solve(pattern, numberOfRequiredLetters))
}

private class Solution private constructor(private val pattern: String,
                                           numberOfRequiredLetters: Int) {

    private val requiredCharacterRange = FIRST_LETTER until FIRST_LETTER + numberOfRequiredLetters
    private val resultArray = Array(pattern.length) { ANY_LETTER }

    private fun prepareResultArray() {
        for (i in pattern.indices) {
            if (pattern[i] != ANY_LETTER) {
                resultArray[i] = pattern[i]
            } else {
                resultArray[i] = pattern[pattern.lastIndex - i]
            }
        }
    }

    private fun getLettersNotContainedInPattern() : HashSet<Char> {
        val notContainedLetters = requiredCharacterRange.toHashSet()
        for (character in pattern) {
            notContainedLetters.remove(character)
        }
        return notContainedLetters
    }

    private fun resultArrayIsCorrect() : Boolean {
        for (i in 0..(resultArray.size / 2)) {
            if (resultArray[i] != resultArray[resultArray.lastIndex - i]) {
                return false
            }
            if (resultArray[i] !in requiredCharacterRange) {
                return false
            }
        }
        return true
    }

    private fun solveImpl() : String {
        prepareResultArray()
        val notContainedLettersDescending = getLettersNotContainedInPattern().sorted().toMutableList()
        for (i in (resultArray.size - 1) / 2 downTo 0) {
            if (resultArray[i] != ANY_LETTER) {
                continue
            }
            val letterToWrite = if (notContainedLettersDescending.isNotEmpty()) {
                val lastCharacter = notContainedLettersDescending.last()
                notContainedLettersDescending.removeAt(notContainedLettersDescending.lastIndex)
                lastCharacter
            } else {
                'a'
            }
            resultArray[i] = letterToWrite
            resultArray[resultArray.lastIndex - i] = letterToWrite
        }

        if (notContainedLettersDescending.isNotEmpty() || !resultArrayIsCorrect()) {
            return IMPOSSIBLE_MESSAGE
        }
        return resultArray.joinToString(separator = "")
    }

    companion object {
        private const val ANY_LETTER = '?'
        private const val FIRST_LETTER = 'a'
        private const val IMPOSSIBLE_MESSAGE = "IMPOSSIBLE"

        fun solve(pattern: String, numberOfRequiredLetters: Int) : String {
           return Solution(pattern, numberOfRequiredLetters).solveImpl()
        }
    }
}


import java.util.*

private const val NO_SOLUTION_ANSWER = "IMPOSSIBLE"
private const val QUESTION_MARK = '?'

/**
 * Solution for codeforces.com/problemset/problem/59/C?locale=en.
 *
 * @param maxLetterNumber maximum letter number that must be used in the title
 * @param pattern approximate variant of the title
 */
class Problem59C(private val maxLetterNumber: Int, pattern: String) {
    private var isSolved = false
    private var answer: String? = null
    private var unusedLetter = 'a'
    private val pattern: CharArray = pattern.toCharArray()
    private val usedLetters = HashMap<Char, Boolean>()

    /**
     * Returns lexicographically smallest correct title if it's possible, and null otherwise.
     */
    fun solve(): String? {
        if (isSolved) {
            return answer
        }

        if (!completePattern()) {
            return toSolvedState(null)
        }
        markUsedLetters()

        val unusedLettersNumber = maxLetterNumber - usedLetters.size
        val lastIndex = pattern.lastIndex
        val freePosNumber = (0..lastIndex / 2)
                .count { pattern[it] == QUESTION_MARK }
        if (unusedLettersNumber > freePosNumber || unusedLettersNumber < 0) {
            return toSolvedState(null)
        }
        var difference = freePosNumber - unusedLettersNumber
        (0..lastIndex / 2)
                .filter { pattern[it] == '?' }
                .forEach {
                    if (difference > 0) {
                        pattern[it] = 'a'
                        pattern[lastIndex - it] = 'a'
                        difference--
                    } else {
                        updateUnusedLetter()
                        pattern[it] = unusedLetter
                        pattern[lastIndex - it] = unusedLetter
                        usedLetters[unusedLetter] = true
                    }
                }

        return toSolvedState(pattern.joinToString(""))
    }

    /**
     * Change object's state to solved and cashes [answer]
     *
     * @return [answer]
     */
    private fun toSolvedState(answer: String?): String? {
        return answer.also {
            this.answer = answer
            isSolved = true
        }
    }

    /**
     * Replaces question marks with already determined by palindrome condition letters.
     *
     * @return true if the title can be palindrome, and false otherwise
     */
    private fun completePattern(): Boolean {
        val lastIndex = pattern.lastIndex

        for (i in 0..lastIndex / 2) {
            when {
                pattern[i] == QUESTION_MARK -> pattern[i] = pattern[lastIndex - i]
                pattern[lastIndex - i] == QUESTION_MARK -> pattern[lastIndex - i] = pattern[i]
                pattern[i] != pattern[lastIndex - i] -> return false
            }
        }

        return true
    }

    /**
     * Marks used letters in [usedLetters].
     */
    private fun markUsedLetters() {
        val middle = pattern.lastIndex / 2
        (0..middle)
                .filter { pattern[it] != QUESTION_MARK }
                .forEach { usedLetters[pattern[it]] = true }
    }

    /**
     * Updates lexicographically smallest unused letter.
     */
    private fun updateUnusedLetter() {
        while (usedLetters[unusedLetter] == true) {
            unusedLetter = unusedLetter.inc()
        }
    }
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val maxLetterNumber = scanner.nextInt()
    val pattern = scanner.next()
    val problem = Problem59C(maxLetterNumber, pattern)
    print(problem.solve() ?: NO_SOLUTION_ANSWER)
}


import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashSet
import kotlin.math.PI
import kotlin.math.atan

fun getSymbolsFromString(string : String) : HashSet<Char> {
    val stringSymbols = HashSet<Char>()
    for (symbol in string) {
        if (!stringSymbols.contains(symbol)) {
            stringSymbols.add(symbol)
        }
    }

    return stringSymbols
}

fun getStringMissingSymbols(string: String) : ArrayList<Char> {
    val stringSymbols = getSymbolsFromString(string)
    val missingSymbols = ArrayList<Char>()

    for (symbol in 'a'..'z') {
        if (!stringSymbols.contains(symbol)) {
            missingSymbols.add(symbol)
        }
    }

    return missingSymbols
}

fun canChooseSymbolNumber(string: String) : Int {
    var canChooseSymbolNumber = 0
    for (i in 0 until (string.length + 1)/ 2) {
        canChooseSymbolNumber +=
                if (string[i] == '?' && string[string.length - 1 - i] == '?') {
                    1
                } else {
                    0
                }
    }

    return canChooseSymbolNumber
}

fun mustChooseSymbolNumber(missingSymbols : ArrayList<Char>, mustHaveCharsNumber: Int) : Int {
    var mustChooseCharsNumber = 0
    for (symbol in missingSymbols) {
        if (symbol - 'a' < mustHaveCharsNumber) {
            mustChooseCharsNumber++
        }
    }

    return mustChooseCharsNumber
}

fun hasAnswer(string: String) : Boolean {
    for (i in 0 until (string.length + 1) / 2) {
        if (string[i] != '?' && string[string.length - 1 - i] != '?') {
            if (string[i] != string[string.length - 1 - i]) {
                return false
            }
        }
    }

    return true
}

fun solveProblem(string: String, mustHaveCharsNumber : Int) : ArrayList<Char>? {
    val chars = ArrayList<Char>()
    val missingSymbols = getStringMissingSymbols(string)
    val mustChooseCharsNumber = mustChooseSymbolNumber(missingSymbols, mustHaveCharsNumber)
    var canChooseCharsNumber = canChooseSymbolNumber(string)
    var index = 0

    if (mustChooseCharsNumber > canChooseCharsNumber || !hasAnswer(string)) {
        return null
    }

    for (char in string) {
        chars.add(char)
    }

    for (i in 0 until (string.length + 1) / 2) {
        if (string[i] == '?' && string[string.length - 1 - i] == '?') {
            if (mustChooseCharsNumber < canChooseCharsNumber) {
                chars[i] = 'a'
                chars[string.length - 1 - i] = 'a'
                canChooseCharsNumber--
            } else {
                chars[i] = missingSymbols[index]
                chars[string.length - 1 - i] = missingSymbols[index]
                index++
            }
        } else if (string[i] == '?') {
            chars[i] = string[string.length - 1 - i]
            chars[string.length - 1 - i] = string[string.length - 1 - i]
        } else {
            chars[i] = string[i]
            chars[string.length - 1 - i] = string[i]
        }
    }

    return chars
}

fun main() {
    val reader = Scanner(System.`in`)
    val mustHaveCharsNumber = reader.nextInt()
    val string = reader.next()
    val resultString = solveProblem(string, mustHaveCharsNumber)

    if (resultString == null) {
        print("IMPOSSIBLE")
    } else {
        for (char in resultString) {
            print(char)
        }
    }
}


//package ru.spbau.mit

import java.util.*

class Solver(k: Int, internal val bookTitle: CharArray) {
    companion object {
        private val IMPOSSIBLE = "IMPOSSIBLE".toCharArray()
    }
    private val unusedLetters: ArrayDeque<Char>
    init {
        val firstKLetters = 'a' until 'a' + k
        val usedLetters = bookTitle.toSet()
        unusedLetters = ArrayDeque(firstKLetters - usedLetters)
    }

    fun solve(): CharArray {
        val ok = removePairedQuestionMarks() && removeSingleQuestionMarks()
        return if (ok) bookTitle else IMPOSSIBLE
    }

    internal fun removeSingleQuestionMarks(): Boolean {
        for (i in 0 until bookTitle.size / 2) {
            val currentSymbol = bookTitle[i]
            val correspondingIndex = i.correspondingIndex
            val correspondingSymbol = bookTitle[correspondingIndex]
            when {
                currentSymbol == '?' -> bookTitle[i] = correspondingSymbol
                correspondingSymbol == '?' -> bookTitle[correspondingIndex] = currentSymbol
                currentSymbol != correspondingSymbol -> return false
            }
        }
        return true
    }

    internal fun removePairedQuestionMarks(): Boolean {
        for (i in bookTitle.size / 2 until bookTitle.size) {
            val currentSymbol = bookTitle[i]
            val correspondingIndex = i.correspondingIndex
            val correspondingSymbol = bookTitle[correspondingIndex]
            if (currentSymbol == '?' && correspondingSymbol == '?') {
                val extractedLetter = getAndExtractMaxUnusedLetterOrA()
                bookTitle[i] = extractedLetter
                bookTitle[correspondingIndex] = extractedLetter
            }
        }
        return unusedLetters.isEmpty()
    }

    private fun getAndExtractMaxUnusedLetterOrA(): Char =
            if (unusedLetters.isEmpty()) 'a' else unusedLetters.removeLast()

    private val Int.correspondingIndex: Int get() = bookTitle.size - this - 1
}

fun main(args: Array<String>) {
    val input = Scanner(System.`in`)
    val k = input.nextInt()
    val bookTitle = input.next().toCharArray()
    print(Solver(k, bookTitle).solve())
}


import java.util.*

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

  if (doStuff(k, title)) {
    println(title)
  }
  else {
    println("IMPOSSIBLE")
  }
}

private fun doStuff(k: Int, title: CharArray): Boolean {
  val n = title.size
  val half = n / 2

  val unusedChars = BitSet(k)
  for (ch in title) {
    if (ch == '?') continue
    unusedChars.set(ch.minus(97).toInt())
  }
  unusedChars.flip(0, k)

  for (leftI in 0..half) {
    val rightI = n - leftI - 1

    val left = title[leftI]
    val right = title[rightI]

    val leftQ = left == '?'
    val rightQ = right == '?'
    if (leftQ && rightQ) continue

    if (leftQ) {
      title[leftI] = right
    }
    else if (rightQ) {
      title[rightI] = left
    }
    else if (left != right) {
      return false
    }
  }

  var lastUsedIndex = k - 1
  for (rightI in half until n) {
    val leftI = n - rightI - 1

    val left = title[leftI]
    val right = title[rightI]

    if (left == '?' && right == '?') {
      lastUsedIndex = unusedChars.previousSetBit(lastUsedIndex)
      val unusedChar = if (lastUsedIndex == -1) {
        'a'
      }
      else {
        unusedChars.set(lastUsedIndex, false)
        lastUsedIndex.plus(97).toChar()
      }
      title[leftI] = unusedChar
      title[rightI] = unusedChar
    }
  }

  return unusedChars.isEmpty
}


//package ru.spbau.mit

import java.util.*

fun getTitle(amountOfLetters: Int, pattern: String): String {
    val patternChars: CharArray = pattern.toCharArray()
    val patternLength = patternChars.size
    val occupiedLetters = BitSet(amountOfLetters)
    occupiedLetters.set(0, amountOfLetters, false)
    patternChars.forEach { letter ->
        if (letter != '?') {
            occupiedLetters.set(letter - 'a')
        }
    }
    val middle = if (patternLength % 2 == 0)
        patternLength / 2 - 1
    else
        patternLength / 2
    for (i in middle downTo 0) {
        if (patternChars[i] == '?') {
            val symmetricIndex = getSymmetricIndex(i, patternLength)
            if (patternChars[symmetricIndex] == '?') {
                val theLastNotOccupiedLetterIndex = occupiedLetters.previousClearBit(amountOfLetters - 1)
                if (theLastNotOccupiedLetterIndex == -1) {
                    patternChars[i] = 'a'
                } else {
                    patternChars[i] = 'a' + theLastNotOccupiedLetterIndex
                    occupiedLetters.set(theLastNotOccupiedLetterIndex)
                }
                patternChars[symmetricIndex] = patternChars[i]
            } else {
                patternChars[i] = patternChars[symmetricIndex]
            }
        }
    }

    (patternLength - 1 downTo middle)
            .forEach {
                val symmetricIndex = getSymmetricIndex(it, patternLength)
                if (patternChars[it] == '?') {
                    patternChars[it] = patternChars[symmetricIndex]
                }
                if (patternChars[it] != patternChars[symmetricIndex]) {
                    return "IMPOSSIBLE"
                }
            }

    if (occupiedLetters.cardinality() != amountOfLetters) {
        return "IMPOSSIBLE"
    }
    return String(patternChars)
}

private fun getSymmetricIndex(index: Int, length: Int): Int {
    return length - index - 1
}

fun main(args: Array<String>) {
    val input = Scanner(System.`in`)
    val amountOfLetters: Int = input.nextInt()
    val pattern: String = input.next()
    input.close()
    println(getTitle(amountOfLetters, pattern))
}


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

const val INPUT_FILE_NAME = "input"
const val OUTPUT_FILE_NAME = "output"

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
//    solve(FileInputStream("$INPUT_FILE_NAME.txt"), FileOutputStream("$OUTPUT_FILE_NAME.txt"))
}

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

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

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

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextInt()
    var k = reader.nextInt()
    val counter = IntArray(26)
    reader.next().forEach { counter[it - 'a']++ }

    var sum = 0
    for (i in 0 until 26) {
        if (counter[i] > 0 && k > 0) {
            k--
            sum += i + 1
            if (i + 1 < 26) {
                counter[i + 1] = 0
            }
        }
    }
    writer.println(if (k > 0) "-1" else "$sum")
}

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


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

    val (numAvailableStages, numRocketStages) = readInts()
    val availableStages = readLine()!!.toCharArray()
    availableStages.sort()
    var last = 'Z'
    var sol = 0
    var availableStagesPos = 0
    for(pos in 0 until numRocketStages) {
        while (availableStagesPos < numAvailableStages && availableStages[availableStagesPos] - 2 < last)
            availableStagesPos++
        if (availableStagesPos == numAvailableStages) return print(-1)
        last = availableStages[availableStagesPos]
        sol += last - 'a' + 1
    }
    print(sol)
}


import java.util.*

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

    val len = sc.nextInt()
    val needed = sc.nextInt()

    val levels = IntArray(26)

    val str = sc.next()

    for (c in str) {
        levels[c.toInt() - 'a'.toInt()] = 1
    }

    var min = 10000000

    fun bt(sum: Int, k: Int, l: Int) {
        if (l == needed) {
            if (sum < min) {
                min = sum
            }
        } else {
            for (i in k + 2 until levels.size) {
                if (levels[i] == 1) {
                    val s = sum + i + 1
                    bt(s, i, l + 1)
                }
            }
        }
    }
    bt(0, -2, 0)
    if (min == 10000000) {
        println("-1")
    } else {
        println(min)
    }
}


fun main(args: Array<String>) {

    val a = readLine()!!.splitToIntArray()
    val x = readLine()!!.toCharArray()
    val k = a[1]

    for (i in 0 until x.size) {
        var m = i
        for (j in i + 1 until x.size) {
            if (x[j] < x[m]) {
                m = j
            }
        }
        val q = x[i]
        x[i] = x[m]
        x[m] = q
    }

    var s = ""

    s += x[0]

    for (i in 1 until x.size) {
        val c = x[i]
        if ((c - s.last()) < 2) continue
        s += c
    }

    if (s.length < k) {
        System.out.println(-1)
    } else {
        s = s.substring(0 until k)
        var ans = 0
        for (c in s) {
            ans += c.toInt() - 'a'.toInt() + 1
        }
        System.out.println(ans)
    }

}

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
}


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

const val INPUT_FILE_NAME = "input"
const val OUTPUT_FILE_NAME = "output"

fun main(args: Array<String>) {
    solve(System.`in`, System.out)
//    solve(FileInputStream("$INPUT_FILE_NAME.txt"), FileOutputStream("$OUTPUT_FILE_NAME.txt"))
}

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

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

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

fun solve(reader: InputReader, writer: PrintWriter) {
    val n = reader.nextLong()
    if (n == 0L) {
        writer.println("0")
        return
    }
    if (n % 2 == 0L) {
        writer.println(n + 1)
    } else {
        writer.println((n + 1) / 2)
    }
}

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


/**
 * Created by aursaty on 5/14/2018.
 */

fun main(args : Array<String>) {
    var n : Long = 0
    n = readLine()!!.toLong() + 1
    when {
        n % 2 == 0.toLong() -> print(n/2)
        n == 1.toLong() -> print(0)
        else -> print(n)
    }
}


fun main(args: Array<String>){
    val n: Long = readLine()?.toLong() ?: 0
    val pieces = n+1
    if (pieces%2 == 0L)
        println(pieces/2)
    else if (pieces == 1L)
        println(0)
    else
        println(pieces)
}


fun main(args: Array<String>){
	val cats = readLine()!!.toLong() + 1L
	if(cats==1L){
		println(0)
		return
	}
	val res = if(cats.rem(2L)==0L) cats/2L else cats
	println(res)
}


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

fun main(){

    val fr = FastReader()
    var a1 = fr.nextInt()
    var a2 = fr.nextInt()
    var k1 = fr.nextInt()
    var k2 = fr.nextInt()
    var n = fr.nextInt()

    if(k1 > k2){
        var tmp = k1
        k1 = k2;
        k2 = tmp;
        tmp = a1;
        a1 = a2;
        a2 = tmp;
    }

    var min = n - (a1*(k1 - 1) + a2*(k2 - 1))
    var max = 0
    if (min <= 0) {
        min = 0;
    }
    if(n <= a1*k1) {
        max = n / k1;
    }else {
        max = a1 + (n - a1*k1) / k2;
    }
    println("$min $max")

}

class FastReader{

    private var br: BufferedReader = BufferedReader(InputStreamReader(System.`in`))
    private var st : StringTokenizer? = null

    fun next() : String {
        while(st == null || !st!!.hasMoreTokens()){
            try{
                st = StringTokenizer(br.readLine())
            }catch(e: IOException){
                e.printStackTrace()
            }
        }
        return st!!.nextToken()
    }

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

    fun nextDouble() : Double{
        return next().toDouble()
    }

    fun nextLong() : Long{
        return next().toLong()
    }

    fun nextString() : String{
        var str : String = ""
        try{
            str = br.readLine()
        }catch(e: IOException){
            e.printStackTrace()
        }
        return str
    }

}


import kotlin.contracts.contract
import kotlin.math.max
import kotlin.math.min

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

fun mmin(a1: Int, a2: Int, k1: Int, k2: Int, n: Int): Int {
    var ansMin = 0
    var n = n

    val m = ArrayList<Int>()
    for (i in 1..a1) m.add(k1)
    for (i in 1..a2) m.add(k2)

    var key = false
    while (!key) {
        key = true
        for (i in 0 until m.size) {
            val k = m[i]
            if (k <= 1) continue
            n--
            if (n < 0) {
                key = true
                break
            }
            m[i]--
            key = false
        }
    }

    ansMin = max(0, min(n, a1 + a2))

    return ansMin
}

fun mmax(a1: Int, a2: Int, k1: Int, k2: Int, n: Int): Int {
    var ansMax = 0

    val q = ArrayList<Int>()
    for (i in 1..a1) q.add(k1)
    for (i in 1..a2) q.add(k2)
    var nmax = n
    q.sort()

    while (nmax > 0) {
        for (t in q) {
            nmax -= t
            if (nmax >= 0) {
                ansMax++
            }
        }
    }

    return ansMax
}

fun main() {

    release()
//    tests()
}

fun release(){
    var a1 = readInt()
    var a2 = readInt()
    var k1 = readInt()
    var k2 = readInt()
    var n = readInt()
//
    val ansMin = mmin(a1, a2, k1, k2, n)
    val ansMax = mmax(a1, a2, k1, k2, n)
//
    print("$ansMin $ansMax")
}

fun tests() {
    println(test(2,3,5,1,8,0,4))
    println(test(3,1,6,7,25,4,4))
    println(test(6,4,9,10,89,5,9))
//    println(test())
//    println(test())
//    println(test())
}

fun test(a1: Int, a2: Int, k1: Int, k2: Int, n: Int, ans1: Int, ans2: Int): Boolean{
    return (mmin(a1, a2, k1, k2, n) == ans1) && (mmax(a1, a2, k1, k2, n) == ans2)
}


import kotlin.math.max

fun main() {
    var a1 = readLine()!!.toInt()
    var a2 = readLine()!!.toInt()
    var k1 = readLine()!!.toInt()
    var k2 = readLine()!!.toInt()
    var n = readLine()!!.toInt()
    var max = 0
    var min = 0

    if (k1 > k2) {
        var buf = a1
        a1 = a2
        a2 = buf
        buf = k1
        k1 = k2
        k2 = buf
    }

    var zerolimit = (k1 - 1) * a1 + (k2 - 1) * a2

    min = max(0, n - zerolimit)

    max = if (n / k1 < a1) n / k1
    else {
        var nost = n - a1 * k1
        a1 + nost / k2
    }
    println("$min $max")
}


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

fun berlandFootballMinMaxCards(
    numPlayers1: Int,
    numPlayers2: Int,
    numCards1: Int,
    numCards2: Int,
    numCardsShown: Int
): Pair<Int, Int> {
    var amax = numPlayers1
    var kmax = numCards1
    var amin = numPlayers2
    var kmin = numCards2

    // Swap if needed.
    if (kmax < kmin) {
        amax = numPlayers2
        kmax = numCards2
        amin = numPlayers1
        kmin = numCards1
    }

    val min = max(numCardsShown - ((kmin - 1) * amin + (kmax - 1) * amax), 0)

    val rem = max(numCardsShown - amin * kmin, 0)

    val max = if (rem > 0) {
        amin + rem / kmax
    } else numCardsShown / kmin

    return Pair(min, max)
}

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

    val numPlayers1 = scan.nextLine().toInt()
    val numPlayers2 = scan.nextLine().toInt()
    val numCards1 = scan.nextLine().toInt()
    val numCards2 = scan.nextLine().toInt()
    val numCardsShown = scan.nextLine().toInt()

    val result = berlandFootballMinMaxCards(numPlayers1, numPlayers2, numCards1, numCards2, numCardsShown)
    val resultString = "${result.first} ${result.second}"

    println(resultString)
}


import java.io.InputStream

val input = FastScanner()

fun main(args: Array<String>) = input.run {
    val m = nextInt()
    val b = nextInt()

    var ans = 0L

    (0..b).forEach { y ->
        val x = (b - y) * m
        var acc = 0L
        (0..y).forEach { yy ->
            acc += (x + 1) * yy.toLong() + x * (x + 1L) / 2
        }
        ans = ans.coerceAtLeast(acc)
    }

    println(ans)
}

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

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

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

        var ans = 0L

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

        return sign * ans
    }

    fun nextInt() = nextLong().toInt()

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

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


import java.io.*
import java.util.*
import kotlin.comparisons.compareBy
import kotlin.comparisons.thenBy
import kotlin.comparisons.thenByDescending

val LOCAL_MODE = true

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

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

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

  companion object {
  }

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

  }

  private fun printStress() {
  }

  private fun generateStress() {
  }

  private fun read() {
    val m = input.nextLong()
    val b = input.nextLong()
    var y = b
    var x = 0L
    var ans = getSum(y)
    while (y > 0) {
      y--
      x += m
      val s = getSum(x)
      val cur = (y + 1) * s + (x + 1) * getSum(y)
      ans = Math.max(ans, cur)
    }
    output.println(ans)
  }

  private fun getSum(s: Long): Long {
    return s * (s + 1) / 2
  }

  private fun read2() {
    val n = input.nextInt()
    val a = Array(n, { IntArray(n) })
    for (i in 0..n - 1) {
      for (j in 0..n - 1) {
        a[i][j] = input.nextInt()
      }
    }
    for (i in 0..n - 1) {
      for (j in 0..n - 1) {
        if (a[i][j] != 1) {
          var ok = false
          for (s in 0..n - 1) {
            for (k in 0..n - 1) {
              if (a[i][j] == a[i][s] + a[k][j]) {
                ok = true
              }
            }
          }
          if (!ok) {
            output.println("No")
            return
          }
        }
      }
    }
    output.println("Yes")
  }

}

class InputReader(val stream: InputStream) : Closeable {

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

  var tokenizer: StringTokenizer? = null

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

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

    }
    return tokenizer!!.nextToken()
  }

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

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

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

}


fun main(){
    var b = readLine()!!.toLong()
    var ans = 0
    for(i : Long in 1..b){
        if(i * i > b) break
        if(b % i == 0L){
            ans += 1
            if(i * i != b) ans += 1
        }
    }
    print(ans)
}


import kotlin.math.sqrt

// unable to solve it by myself. Solution on the editorial: https://codeforces.com/blog/entry/62688
fun main() {
    fun readLong() = readLine()!!.toLong()

    fun Long.factors(): MutableSet<Long> {
        val output = mutableSetOf<Long>()
        val endLoop = sqrt(this.toDouble()).toLong()
        for (i in 1L..endLoop) {
            if (this % i == 0L) {
                output.add(i)
                output.add(this / i)
            }
        }
        return output
    }

    print(readLong().factors().size)
}


fun main(args: Array<String>) {
    var b = readLine()!!.toLong()
    var ans = 1
    for (i in 2..100000) {
        if (b % i == 0L) {
            var count = 0
            while (b % i == 0L) {
                b /= i
                count ++
            }
            ans *= (count + 1)
        }
    }
    if (b != 1L) ans *= 2
    println(ans)
}


import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

private fun String.words() = split(" ")

private fun String.toInts() = split(" ").map { it.toInt() }
private fun String.toLongs() = split(" ").map { it.toLong() }

private fun solve(input: BufferedReader, output: PrintWriter) {
    val line = input.readLine()
    var cur = 'a'
    var answer = 0
    for (c in line) {
        val shortest = Math.min(Math.min(Math.abs(c - cur), 'z' - cur + (c - 'a') + 1), cur - 'a' + ('z' - c) + 1)
        answer += shortest
        cur = c
    }
    output.println(answer)
}


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

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

}
fun embosser(s: Scanner){
 val a = s.next()
 val char = a.toCharArray();
 var intial = 'a'
 var total = 0
 for(i in char.indices){
 val value = Math.abs(intial-char[i])
  if(value >13){
    total += 26 - value

  }else{
    total += value
  }
     intial = char[i]
 }

 print(total)

}


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

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

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

fun main(args: Array<String>) {
//  var s = Scanner(System.`in`)
  var s = readLn()
  var ans = 0
  var d = 0
  var a = 'a'
  for (c in s) {
    ans += minOf(maxOf(c.toInt(), a.toInt()) - minOf(c.toInt(), a.toInt()), 26 - (maxOf(c.toInt(), a.toInt()) - (minOf(c.toInt(), a.toInt()))))
    a = c
  }
  println(ans)
}


import java.io.PrintWriter
import java.util.StringTokenizer
import kotlin.math.min

//private val INPUT = File("input.txt").inputStream()
//private val OUTPUT = File("output.txt").outputStream()
private val INPUT = System.`in`
private val OUTPUT = System.out

private val bufferedReader = INPUT.bufferedReader()
private val outputWriter = PrintWriter(OUTPUT, false)
private fun readLn() = bufferedReader.readLine()!!

private fun readList() = readLn().split(' ')
private var tokenizer = StringTokenizer("")
private fun read(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), " ")
    return tokenizer.nextToken()
}

private fun readInt() = read().toInt()
private fun readLong() = read().toLong()
private fun readDouble() = read().toDouble()

private fun readIntList() = readList().map { it.toInt() }
private fun readLongList() = readList().map { it.toLong() }
private fun readDoubleList() = readList().map { it.toDouble() }

private fun readIntArray(n: Int = 0) =
    if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }

private fun readLongArray(n: Int = 0) =
    if (n == 0) readList().run { LongArray(size) { get(it).toLong() } } else LongArray(n) { readLong() }

private fun readDoubleArray(n: Int = 0) =
    if (n == 0) readList().run { DoubleArray(size) { get(it).toDouble() } } else DoubleArray(n) { readDouble() }

private fun Int.modPositive(other: Int): Int = if (this % other < 0) ((this % other) + other) else (this % other)

private class `CF731-D2-A` {
    fun solveTestCase(): Int {
        var total = 0
        var first = false
        var origin: Int = 0
        val aVal = 'a'.toInt()
        val numOfAlphabet = 26
        for (c in read()) {
            if(first) {
                origin = c.toInt() - aVal
                first = false
            } else {
                var destination = c.toInt() - aVal
                var clockwise = destination - origin
                var counterClock = origin - destination
                if (clockwise < 0)
                    clockwise += numOfAlphabet
                if (counterClock < 0)
                    counterClock += numOfAlphabet
                total += min(clockwise, counterClock)
                origin = destination
            }
        }

        return total
    }
}

fun main(args: Array<String>) {
    outputWriter.println(
        `CF731-D2-A`()
            .solveTestCase()
    )

    outputWriter.flush()
}


fun main() {
    val length = readLine()!!.toInt()
    val s = readLine()!!
    val sb = StringBuilder()
    var pos = -1
    while (++pos < length)
        if (pos + 2 >= length || s.substring(pos..pos + 2) != "ogo")
            sb.append(s[pos])
        else {
            sb.append("***")
            while (pos + 2 < length && s.substring(pos + 1..pos + 2) == "go") pos += 2
        }
    print(sb.toString())
}


import java.io.BufferedReader
import java.io.File
import java.io.PrintWriter

fun main(args: Array<String>) {
    val onlineJudge = System.getProperty("ONLINE_JUDGE") == "true"
    val input = if (onlineJudge) System.`in`.bufferedReader() else File("input.txt").bufferedReader()
    val output = if (onlineJudge) PrintWriter(System.out.writer(), true) else PrintWriter(File("output.txt"))

    solve(input, output)

    output.flush()
    output.close()
}

private fun String.words() = split(" ")

private fun String.toInts() = split(" ").map { it.toInt() }
private fun String.toLongs() = split(" ").map { it.toLong() }

private fun solve(input: BufferedReader, output: PrintWriter) {
    val n = input.readLine()
    val l = input.readLine()
    val r = "ogo(go)*".toRegex()
    val o = r.replace(l, "***")
    output.println(o)
}


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

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

    val (numTabs, distance) = readInts()
    val arr = readInts()
    var sol = Integer.MIN_VALUE
    for (start in 0 until distance) {
        var curSol = 0
        for (pos in 0 until numTabs)
            if ((pos - start) % distance != 0) curSol += arr[pos]
        sol = max(sol, abs(curSol))
    }
    print(sol)
}


import kotlin.math.abs

fun main(args: Array<String>) {
    val (n , k) = readLine()!!.split(' ').map ( String::toInt )
    val arr : List<Int> = readLine()!!.split(' ').map ( String::toInt )

    val zeroing = { i : Int, arr : MutableList<Int> ->
        for (j in i until n step k)
            arr[j] = 0
        arr
    }

    val summation = { arr : MutableList<Int> ->
        var sum = 0
        for (j in 0 until n)
            sum += arr[j]
        sum
    }

    var res = 0
    var sum : Int
    for(i in 0 until k) {
        sum = abs(summation(zeroing(i, arr.toMutableList())))
        res = if(res < sum) sum else res
    }

    println(res)
}


import kotlin.math.absoluteValue

fun remove(sequence: List<Int>, start: Int, step: Int) : List<Int>{
    return sequence.withIndex().filter { (i, _) -> (i - start) % step != 0 }.map {(_, value) -> value}
}

fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(' ').map(String::toInt)
    val codes = readLine()!!.split(' ').map(String::toInt)
    val results = (0 until k).map { start -> remove(codes, start, k).sum().absoluteValue }
    println(results.max())
}


import kotlin.math.abs

fun main(args: Array<String>) {
//    var str = readLine()!!
//    var n = readLine()!!.toInt()
    var ns = readLine()!!.split(" ").map { x -> x.toInt() }
    var tabs = readLine()!!.split(" ").map { x -> x.toInt() }

    var n = ns[0]
    var k = ns[1]

    var list = ArrayList<Int>()

    for(b in 0 until n) {
        var del = tabs(n, k, b)
        var newTab = ArrayList<Int>()
        for (a in 0 until n) {
            if (!del.contains(a)) {
                newTab.add(tabs[a])
            }
        }

        var e = 0
        var s = 0

        for (a in newTab){
            if (a < 0) s++
            else e++
        }

        list.add(abs(e-s))
    }

    print(list.max())

}

fun tabs(n: Int, k: Int, b: Int) : ArrayList<Int> {

    var list = ArrayList<Int>()
    var b2 = b
    while (b2 < n) {
        list.add(b2)
        b2+=k
    }

    b2 = b

    while (b2 >= 0) {
        list.add(b2)
        b2-=k
    }

    return list
}


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

fun find(current : Int, total : Int) : Int{
    var i = 1
    while(current > i ) i*=2
    return if (current == i) total else find(current - i/2, total + 1)
}


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

fun main() {
    val br = BufferedReader(InputStreamReader(System.`in`))
    val x = br.readLine().toInt()
    val bin = x.toString(2)
    println(bin.fold(0){acc, c ->  acc + if (c == '1') 1 else 0})
}


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

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    var mask = 1
    var count = 0
    for (i in 1..32) {
        if (n.and(mask) != 0)
            count++
        mask = mask.shl(1)
    }
    println(count)
}


fun main() {
    println(readLine()!!.toInt().toString(2).count { it == '1' })
}


import java.util.*

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

    val n = scanner.nextInt()

    var cnt = n - 1

    var max: Double = -1.0

    var resA = 0
    var resB = 0

    while (cnt > 0) {
        val a = cnt
        val b = n - cnt
        //System.out.println("$a $b")
        if (a < b && nod(a,b) == 1) {
            if (a.toDouble() / b.toDouble() > max) {
                max = a.toDouble() / b.toDouble()
                resA = a
                resB = b
            }
        }
        cnt--
    }

    System.out.print("$resA $resB")

}

fun nod(a: Int, b: Int): Int {
    var aa = a
    var bb = b

    while (bb != 0) {
        val tmp = bb
        bb = aa % bb
        aa = tmp
    }

    return aa
}


import kotlin.math.min

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

    val n = readInt()
    var bestA = 0
    var bestB = 0
    loop@for (a in 1 .. n/2) {
        val b = n - a
        for (divisor in 2 .. min(a, b))
            if (a % divisor == 0 && b % divisor == 0) continue@loop
        bestA = a
        bestB = b
    }
    print("$bestA $bestB")
}


import java.util.*

/**
 * Created by v.shipugin on 30/08/2018
 */
fun main(args: Array<String>) {
    Cont433().first()
}

class Cont433 {

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

        val n = scanner.nextInt()
        var ar = 1f
        var br = (n - 1).toFloat()

        for (a in 1..n / 2) {
            val b: Float = (n - a).toFloat()
            var coprime = true

//            println("a:$a b:$b")

            for (d in 2..a) {
                val ad = (a % d).toFloat()
                val bd = b % d

//                println("d:$d ad:$ad bd:$bd")

                if (ad == 0f && bd == 0f) {
                    coprime = false
                }
            }

            val adb = a / b
            val ardb = ar / br
//            println("adb:$adb ardb:$ardb")
            if (coprime && adb > ardb) {
                ar = a.toFloat()
                br = b
//                println("change ar:$ar br:$br")
            }
        }

        println("${ar.toInt()} ${br.toInt()}")
    }
}


import kotlin.math.abs

fun main() {
    var (n, pos, l, r) = readLine()!!.split(" ").map(String::toInt)
    val toDelete = mutableListOf<Pair<Int, Int>>()
    if (l > 1)
        toDelete.add(pos - l to l)
    if (r < n)
        toDelete.add(r - pos to r)
    toDelete.sortBy { it.first }
    var sol = 0
    for(tab in toDelete) {
        sol += abs(pos -tab.second) + 1
        pos = tab.second
    }
    print(sol)
}


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

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

        val n = reader.nextInt()
        val pos = reader.nextInt()
        val l = reader.nextInt()
        val r = reader.nextInt()

        writer.println(solve(n, pos, l, r))

        writer.close()
    }

    fun range(a : Int, b : Int) : Int {
        return abs(a - b)
    }

    fun solve(n : Int, pos : Int, l : Int, r : Int) : Int {
        if (l == 1 && r == n) {
            return 0
        }
        if (l == 1) {
            return range(pos, r) + 1
        }
        if (r == n) {
            return range(pos, l) + 1
        }

        val leftFirst = range(pos, l) + 1 + range(l, r) + 1
        val rightFirst = range(pos, r) + 1 + range(l, r) + 1
        return min(leftFirst, rightFirst)
    }

    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>) {
    B().solve(System.`in`, System.out)
}


import java.util.*

fun abs(x: Int) = if (x >= 0) x else -x

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

    val leftToRight = abs(pos - l) + 1 + (1 + r - l) * (if (r != n) 1 else 0)
    val rightToLeft = abs(r - pos) + 1 + (1 + r - l) * (if (l != 1) 1 else 0)

    if (l == 1 && r == n) {
        print(0)
    } else {
        print(minOf(leftToRight, rightToLeft))
    }
}


import java.io.BufferedReader
import java.io.IOException
import java.io.InputStream
import java.io.InputStreamReader
import java.lang.Math.pow
import java.util.*
import kotlin.collections.ArrayList
import kotlin.math.log
import kotlin.math.log2
import kotlin.math.min

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

fun run() {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val days = Array<ArrayList<Int>>(n) { ArrayList() }
    val arr = IntArray(n) { -1 }
    val q = IntArray(m) { 0 }
    val res = IntArray(n)
    for (i in 0 until m) {
        val a = scanner.nextInt() - 1
        val b = scanner.nextInt() - 1
        val c = scanner.nextInt()
        days[a].add(b)
        arr[b] = i
        q[i] = c
    }
    val set = PriorityQueue<Pair> {
        o1, o2 -> o1.a - o2.a
    }
    for (i in 0 until n) {
        for (j in days[i])
            set.add(Pair(j, arr[j]))
        if (arr[i] != -1) {
            if (q[arr[i]] != 0) {
                println(-1)
                return
            }
            res[i] = m + 1
        }
        else if (set.size > 0) {
            val p = set.first()
            q[p.b]--
            if (q[p.b] == 0)
                set.remove(p)
            res[i] = p.b + 1
        }
    }
    res.forEach { print("$it ") }
}

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

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

//class Triple(val a: Int, val b: Int, val c: Int, val i: Int): Comparable<Triple> {
//    override fun compareTo(other: Triple): Int {
//        return b - other.b
//    }
//}


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

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

fun main(args: Array<String>) {
    val(a,b)=readInts()
    var x=0
    var y=0
    var z=0

    for(dice in 1..6) {
        if(abs(dice-a)<abs(dice-b))x++
        else if(abs(dice-a)>abs(dice-b))y++
        else z++
    }

    println("$x $z $y")
}


import kotlin.math.abs

fun main(args: Array<String>) = with(java.util.Scanner(System.`in`)) {
    var a = nextInt()
    var b = nextInt()
    var win = 0
    var draw = 0
    var lose = 0
    for( i in 1..6){
        if(abs(a-i) == abs(i-b))draw++
        else if(abs(a-i)>abs(i-b))lose++
        else win++
    }
    println("$win $draw $lose")
}


import kotlin.math.abs

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    //val len = r.readLine()!!.toInt()
    val (a, b) = r.readLine()!!.split(" ").map { it.toInt() }
    var q = 0
    var w = 0
    var e = 0
    (1..6).forEach {
        when{
            abs(a-it)< abs(b-it) -> q++
            abs(a-it)== abs(b-it) -> w++
            abs(a-it)> abs(b-it) -> e++
        }
    }
    println("$q $w $e")
}


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

fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    val a = nextInt()
    val b = nextInt()
    var res = IntArray(3)
    repeat(6) {
        when {
            abs(a - (it + 1)) < abs(b - (it + 1)) -> res[0]++
            abs(a - (it + 1)) > abs(b - (it + 1)) -> res[2]++
            else -> res[1]++
        }
    }
    res.forEach { s -> print("$s ") }
}


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

fun main() {
    val reader = Scanner(System.`in`)
    val nThOrderRhomb = reader.nextFloat()
    println((nThOrderRhomb.pow(2) + (nThOrderRhomb - 1).pow(2)).toInt())
}