fun main() {
    val n = nextInt()
    val a = nextIntList()
        .let { a ->
        a.filterIndexed { index, i ->
            if (index == 0 || index == n - 1) return@filterIndexed true
            i !in a[index + 1]..a[index - 1] && i !in a[index - 1]..a[index + 1]
        }
    }
    println(a)
    var stock = 0
    var account = 1000
    repeat(a.lastIndex) {
        when {
            a[it] < a[it + 1] -> {
                stock += account / a[it]
                account %= a[it]
            }
            a[it] > a[it + 1] -> {
                account += stock * a[it]
                stock = 0
            }
            else -> Unit
        }
        println(stock.times(a[it]).plus(account))
    }
    account += stock * a.last()
    println(account)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)

// ## Array
inline fun <reified T> sizedArray(size: Int, default: T) = Array(size) { default }

// ## mod^-1
//    [NOTE] CANNOT use this for 0, mod, 2mod, 3mod ...(return wrong value)
fun modinv(num: Long, mod: Long): Long {
    var a = num
    var b = mod
    var u = 1L
    var v = 0L
    while (b > 0) {
        val t = a.div(b)
        a -= t * b
        a = b.also { b = a } // swap a and b
        u -= t * v
        u = v.also { v = u } // swap u and v
    }
    u %= mod
    if (u < 0) u += mod
    return u
}
