import java.io.BufferedInputStream
import java.io.File
import java.io.PrintWriter
import kotlin.math.ln
import kotlin.system.measureTimeMillis

inline fun TIME(f:()->Unit){
    val t = measureTimeMillis(){
        f()
    }
    println("$t ms")
}

object IO{
    private const val BS = 1 shl 16
    private const val NC = 0.toChar()
    private val buf = ByteArray(BS)
    private var bId = 0
    private var size = 0
    private var c = NC

    var warningActive = true
    var fakein = StringBuilder()

    private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)
    val OUT: PrintWriter = PrintWriter(System.out)

    private val char: Char
        get() {
            while (bId == size) {
                size = IN.read(buf) // no need for checked exceptions
                if (size == -1) return NC
                bId = 0
            }
            return buf[bId++].toChar()
        }

    fun nextInt(): Int {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }
    fun nextLong(): Long {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0L
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }
    fun nextString():String{
        val ret = StringBuilder()
        while (true){
            c = char
            if(!isWhitespace(c)){ break}
        }
        ret.append(c)
        while (true){
            c = char
            if(isWhitespace(c)){ break}
            ret.append(c)
        }
        return ret.toString()
    }
    fun isWhitespace(c:Char):Boolean{
        return c == ' ' || c == '\n' || c == '\r' || c == '\t'
    }
    fun rerouteInput(){
        if(warningActive){
            put("You forgot to disable tests you digital dummy!")
            println("You forgot to disable tests you digital dummy!")
            warningActive = false
        }
        val S = fakein.toString()
        println("New Case ")
        println(S.take(80))
        println("...")
        fakein.clear()
        IN = BufferedInputStream(S.byteInputStream(),BS)
    }
    fun takeFile(name:String){
        IN = BufferedInputStream(File(name).inputStream(),BS)
    }
}
fun put(aa:Any){ IO.OUT.println(aa)}
fun done(){ IO.OUT.close() }
fun share(aa:Any){
    if(aa is IntArray){IO.fakein.append(aa.joinToString(" "))}
    else if(aa is LongArray){IO.fakein.append(aa.joinToString(" "))}
    else if(aa is List<*>){IO.fakein.append(aa.toString())}
    else{IO.fakein.append(aa.toString())}
    IO.fakein.append("\n")
}

val getint:Int get() = IO.nextInt()
val getlong:Long get() = IO.nextLong()
val getstr:String get() = IO.nextString()
fun getline(n:Int):IntArray{
    return IntArray(n){getint}
}
fun getlineL(n:Int):LongArray{
    return LongArray(n){getlong}
}
fun getbinary(n:Int):BooleanArray{
    val str = getstr
    return BooleanArray(n){str[it] == '1'}
}

val List<Char>.ret:String
get() = this.joinToString("")
infix fun Any.dei(a:Any){
    //does not stand for anything it is just easy to type, have to be infix because kotlin does not have custom prefix operators
    var str = ""
    if(this is String){ str = this
    }else if(this is Int){ str = this.toString()
    }else if(this is Long){ str = this.toString()
    }
    if(a is List<*>){ println("$str : ${a.joinToString(" ")}")
    }else if(a is IntArray){ println("$str : ${a.joinToString(" ")}")
    }else if(a is LongArray){ println("$str : ${a.joinToString(" ")}")
    }else{ println("$str : $a")
    }
}
val just = " " // usage: just dei x , where x is the debug variable
fun crash(){throw Exception("Bad programme")} // because assertion does not work
fun assert(a:Boolean){
    if(!a){throw Exception("Failed Assertion")
    }}
enum class solveMode {
    real, rand, tc
}
const val withBruteForce = false
const val randCount = 100
object solve{
    var mode:solveMode = solveMode.real
    var tcNum:Int = 0
    var rand:()->Unit = {}
    var TC:MutableMap<Int,()->Unit> = mutableMapOf()
    var answersChecked = 0
    var tn:Long = 0
    fun cases(onecase:()->Unit){
        val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount
        //safety checks
        if(pI != 998_244_353 && pI != 1_000_000_007){
            throw Exception("Modding a wrong prime!")
        }

        if(t == 1 && mode != solveMode.real){
            tn = System.currentTimeMillis()
        }
        repeat(t){
            if(mode == solveMode.tc){
                TC[tcNum]?.let { it() }
                IO.rerouteInput()
            }else if(mode == solveMode.rand){
                rand()
                IO.rerouteInput()
            }
            currentAnswer = null
            currentBruteAnswer = null
            onecase()
        }
        if(withBruteForce){
            put("Checked ${answersChecked}")
        }
        if(t == 1 && mode != solveMode.real){
            val dt = System.currentTimeMillis() - tn
            println("Time $dt ms ")
        }
    }
    inline fun singleCase(a:solve.()->Unit){
        val t = if(mode != solveMode.rand){1} else randCount
        repeat(t) { a() }
    }
    fun rand(a:()->Unit){
        this.rand = a
    }
    fun tc(id:Int = 0,a:()->Unit){
        TC[id] = a
    }
    inline fun brute(a:()->Unit){
        if(withBruteForce){
            a()
        }
    }
    fun usetc(a:Int = 0 ){
        this.tcNum = a
        this.mode = solveMode.tc
    }
    fun userand(){
        this.mode = solveMode.rand
    }

    var currentAnswer:String? = null
    var currentBruteAnswer:String? = null
    fun answer(a:Any){
        currentAnswer = a.toString()
        if(currentBruteAnswer != null){
            checkAnswer()
        }
    }
    fun put2(a:Any){answer(a);put(a) }

    fun bruteAnswer(a:Any){
        currentBruteAnswer = a.toString()
        if(currentAnswer != null){
            checkAnswer()
        }
    }
    fun checkAnswer(){
        if(currentAnswer != currentBruteAnswer){
            throw Exception("Failed Test: BF $currentBruteAnswer Current $currentAnswer")
        }
        answersChecked ++
    }
}
// 1. Modded
const val p = 998244353L
const val pI = p.toInt()
fun Int.adjust():Int{ if(this >= pI){ return this  - pI }else if (this < 0){ return this + pI };return this }
fun Int.snap():Int{ if(this >= pI){return this - pI} else return this}
infix fun Int.modM(b:Int):Int{ return ((this * 1L * b) % pI).toInt() }
infix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }
// 2. DP initial values
const val plarge = 1_000_000_727
const val nlarge = -plarge
const val phuge = 2_727_000_000_000_000_000L
const val nhuge = -phuge
// 3. conveniecen conversions
val Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function
val Char.code :Int get() = this.toInt() -  'a'.toInt()
//3. hard to write stuff
fun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }
val mint:MutableList<Int> get() = mutableListOf<Int>()
val mong:MutableList<Long> get() = mutableListOf<Long>()

infix fun Int.divCeil(b:Int):Int{
    //Positives numbers only!
    if(this == 0) {
        return 0
    }
    return (this-1)/b + 1
}
infix fun Long.divCeil(b:Long):Long{
    //Positives numbers only!
    if(this == 0L) {
        return 0
    }
    return (this-1)/b + 1
}

infix fun Long.modM(b:Long):Long{
    return (this * b) % p
}
//infix fun Int.modPlus(b:Int):Int{
//    val ans = this + b
//    return if(ans >= pI) ans - pI else ans
//}
infix fun Int.modMinus(b:Int):Int{
    val ans = this - b
    return if(ans < 0) ans + pI else ans
}
infix fun Int.modDivide(b:Int):Int{
    return this modM (b.inverse())
}
fun Int.additiveInverse():Int{
    return if(this == 0) 0 else pI - this
}

fun intPow(x:Int,e:Int,m:Int):Int{
    var X = x
    var E =e
    var Y = 1
    while(E > 0){
        if(E % 2 == 0){
            X = ((1L * X * X) % m).toInt()
            E /= 2
        }else{
            Y = ((1L * X * Y) % m).toInt()
            E -= 1
        }
    }
    return Y
}

fun pow(x:Long,e:Long,m:Long):Long{
    var X = x
    var E =e
    var Y = 1L
    while(E > 0){
        if(E % 2 == 0L){
            X = (X * X) % m
            E /= 2
        }else{
            Y = (X * Y) % m
            E -= 1
        }
    }
    return Y
}
fun Long.inverse():Long{
    return pow(this,p-2,p)
}
fun Int.inverse():Int{
    return intPow(this,pI-2,pI)
}
//make this int instead
class FACT{
    companion object {
        var store = IntArray(0)
        var invStore = IntArray(0)

        var slowStore:IntArray = IntArray(0)

        fun preCal(upto:Int){
            store = IntArray(upto+1)
            invStore = IntArray(upto + 1 )
            store[0] = 1
            invStore[0] = 1

            for(i in 1..upto) {
                store[i] = store[i-1] modM i
                invStore[i] = invStore[i-1] modM (i.inverse())
            }
        }
        fun choose(n:Int,r:Int):Int{
            if(r < 0 || r > n) return 0
            val a = store[n]
            val b = invStore[n-r]
            val c = invStore[r]
            return (a modM b) modM c
        }

        fun bigChoose(n:Int,r:Int):Int{
            var ret = 1
            for(i in 0 until r){
                ret = ret modM (n - i)
            }
            ret = ret modM (invStore[r])
            return ret
        }

    }
}

class FFT {
    companion object{
        //        val fftmod = 7340033
//        val root = 5
//        val root_1 = 4404020
//        val root_pw = 1 shl 20
        private const val fftmod = 998244353
        private const val root = 15311432
        private const val root_1 = 469870224
        private const val root_pw = 1 shl 23

        fun calculateRoot(){
            println("root :$root")
            //   intPow(3,7 * 17,fftmod)
            println("root_1 : $root_1")
            //       intPow(root,fftmod -2,fftmod)
        }

        fun fft(a:IntArray,invert:Boolean){
            val n = a.size
            var j = 0

            for(i in 1 until n){
                var bit = n shr 1
                while(j and bit > 0){
                    j = j xor bit
                    bit = bit shr 1
                }
                j = j xor bit
                if(i < j){
                    val temp = a[i]
                    a[i] = a[j]
                    a[j] = temp
                }
            }
            var len = 2
            while(len <= n){
                var wlen = if(invert) root_1 else root
                var i = len
                while(i < root_pw){
                    wlen = (1L * wlen * wlen % fftmod).toInt()
                    i = i shl 1
                }
                i = 0
                while(i < n){
                    var w = 1
                    for(j in 0 until len/2){
                        val u = a[i+j]
                        val v = (1L * a[i+j+len/2] * w % fftmod).toInt()
                        a[i+j] = if(u+v < fftmod) u + v else u + v - fftmod
                        a[i+j+len/2] = if(u-v >= 0) u-v else u-v+fftmod
                        w = (1L * w * wlen % fftmod).toInt()
                    }
                    i += len
                }
                len = len shl 1
            }
            if(invert){
                val n_1 = pow(n.toLong(),(fftmod-2).toLong(),fftmod.toLong())
                for((i,x) in a.withIndex()){
                    a[i] = (1L * x * n_1 % fftmod).toInt()
                }
            }
        }
        fun fullconvolution(at:IntArray,bt:IntArray):IntArray{
            return fullconvolutionOpt(at,bt,at.size,bt.size)
        }

        fun fullconvolutionOpt(at:IntArray,bt:IntArray,sizeA:Int,sizeB:Int):IntArray{
            // 1 shl 18 done in 77 ms
            val maxSize = (sizeA + sizeB).takeHighestOneBit() * 2
            val a = at.copyOf(maxSize)
            val b = bt.copyOf(maxSize)
            val expectedSize = at.size + bt.size - 1
            fft(a,false)
            fft(b,false)
            val new = IntArray(maxSize)
            for(i in new.indices){
                new[i] = (1L * a[i] * b[i] % fftmod).toInt()
            }
            fft(new,true)
            return new.copyOf(expectedSize)
        }
    }
}

fun stir(l:Int, r:Int):IntArray{
    if(l == r){
        return intArrayOf(l,1)
    }else{
        val mid = (l+r) shr 1
        return FFT.fullconvolution(stir(l,mid), stir(mid+1,r))
    }
}

object sieve{

    const val sieveMx = 200005
    val primeOf = IntArray(sieveMx + 1)
    var primeCounter = 0
    val primeUpperBound = maxOf(25,(sieveMx.toDouble()/(ln(sieveMx.toDouble()) -4)).toInt() +3)
    val primes = IntArray(primeUpperBound)
    var sieveCalculated = false
    val nextPrime = IntArray(sieveMx+1)
    val nextPrimePower = IntArray(sieveMx+1)
    val afterPrimePowerDivison = IntArray(sieveMx+1)
    var mobius = IntArray(0)

    var factors:List<MutableList<Int>> = mutableListOf()

    fun calculateSieveFast(){
        if(sieveCalculated){
            return
        }
        sieveCalculated = true
        for(i in 2..sieveMx){
            if(primeOf[i] == 0 ){
                primeOf[i] = i
                primes[primeCounter] = i
                primeCounter += 1
            }
            for(j in 0 until primeCounter){
                val p = primes[j]
                val pd = p * i
                if(p <= i && pd <= sieveMx){
                    primeOf[pd] = p
                }else{
                    break
                }
            }
        }
    }
    fun preparePrimePower(){
        nextPrime[1] = -1
        nextPrimePower[1] = -1
        afterPrimePowerDivison[1] = 1
        for(i in 2..sieveMx){
            val p = primeOf[i]
            val new = i / p
            nextPrime[i] = p
            if(nextPrime[new] == p){
                nextPrimePower[i] = nextPrimePower[new]
                afterPrimePowerDivison[i] = afterPrimePowerDivison[new]
            }else{
                afterPrimePowerDivison[i] = new
            }
            nextPrimePower[i] += 1
        }
    }
    fun prepareFactors(){
        // 700ms in 1M
        // shoudl not be used for 1M
        // 200ms codeforces for 200k
        factors = List(sieveMx + 1){ mutableListOf()}
        factors[1].add(1)

        for(i in 2..sieveMx){
            val p = nextPrime[i]
            val a = nextPrimePower[i]
            val old = afterPrimePowerDivison[i]

            var here = 1
            repeat(a+1){
                for(c in factors[old]){
                    factors[i].add(c * here )
                }
                here *= p
            }
//            factors[1].ad
//            factors[i].addAll(i.factors())
        }
    }
    fun calculateMobius(){
        kotlin.assert(sieveCalculated)
        mobius = IntArray(sieveMx + 1)
        mobius[1] = 1
        for(i in 2..sieveMx){
            val p = primeOf[i]
            if(p == primeOf[i/p]){
                mobius[i] = 0
            }else{
                mobius[i] = -1 * mobius[i/p]
            }
        }
    }
}
inline fun Int.eachPrimePower(act:(Int,Int)->Unit){
    var here = this
    while(here > 1){
        act(sieve.nextPrime[here], sieve.nextPrimePower[here])
        here = sieve.afterPrimePowerDivison[here]
    }
}
fun GS(start:Int,ratio:Int,count:Int) = sequence {
    var ret = 1
    for(i in 1
            ..count){
        ret *= ratio
        yield(ret)
    }
}
fun Int.factors():List<Int>{
    val ret = mutableListOf(1)
    this.eachPrimePower { p, e ->
        val s = ret.toList()
        for(pn in GS(p,p,e)){
            ret.addAll(s.map{it * pn})
        }
    }
    return ret
}
fun totient(a:Int):Int{
    var ret = a
    a.eachPrimePower{
            p, _ ->
        ret /= p
        ret *= (p-1)
    }
    return ret
}
fun Int.numOfDivisors():Int{
    var ret = 1
    this.eachPrimePower { _, e -> ret *= (e+1) }
    return ret
}
fun Int.factorLook():List<Int>{
    return sieve.factors[this]
}

fun stirlingNumbers(n:Int):IntArray {
    val A = IntArray(n+1){
        val x = FACT.invStore[it]
        if(it %2 == 0) x else x.additiveInverse()
    }
    val B = IntArray(n+1){
        intPow(it, n,pI) modM FACT.invStore[it]
    }
    val F = FFT.fullconvolution(A,B)

    return F
}
val recitations = mutableMapOf<Int,Int>()
fun getitdone(n:Int, k:Int):Int{
    if(recitations[n] != null){
        return recitations[n]!!
    }
    val that = stirlingNumbers(n)
    var ret = 0
    for(i in 1..minOf(n,k)){
        ret = ret modPlus that[i]
    }
//    "$n $k " dei thatv\\

    val final = ret modMinus 1
    recitations[n] = final
    return final
}

var n =0
const val singleCase = true
fun main(){
    FACT.preCal(200005)
    sieve.calculateSieveFast()
    sieve.calculateMobius()

//    just dei stirtry2(6)
    solve.cases{
        n = getint
        val k = getint
        var ans = 0

        if(k == 1 || n ==1){
            put(1)
            return@cases

        }

        for(i in 1..n){
            val m = sieve.mobius[i].adjust()
            if(m == 0) continue

            val now = getitdone(n divCeil i,k)
//            i dei now
            ans = ans modPlus ( now modM m)
        }
        put(ans)
    }
    done()
}
/*
just number of such patterns

n
n/2
n/3

 */


// 2022.06.17 at 18:59:23 HKT
import java.io.BufferedInputStream
import java.io.File
import java.io.PrintWriter
import kotlin.system.measureTimeMillis
import java.util.TreeMap
import java.util.TreeSet
import kotlin.random.Random
import kotlin.random.nextInt

// 1. Modded
const val p = 1000000007L
const val pI = p.toInt()
fun Int.adjust():Int{ if(this >= pI){ return this  - pI }else if (this < 0){ return this + pI };return this }
fun Int.snap():Int{ if(this >= pI){return this - pI} else return this}
infix fun Int.modM(b:Int):Int{ return ((this.toLong() * b) % pI).toInt() }
infix fun Int.modPlus(b:Int):Int{ val ans = this + b;return if(ans >= pI) ans - pI else ans }
fun intPow(x:Int,e:Int,m:Int):Int{
    var X = x ; var E =e ; var Y = 1
    while(E > 0){
        if(E and 1 == 0){
            X = ((1L * X * X) % m).toInt()
            E = E shr 1
        }else{
            Y = ((1L * X * Y) % m).toInt()
            E -= 1
        }
    }
    return Y
}
// 2. DP initial values
const val plarge = 1_000_000_727
const val nlarge = -plarge
const val phuge = 2_727_000_000_000_000_000L
const val nhuge = -phuge
// 3. conveniecen conversions
val Boolean.chi:Int get() = if(this) 1 else 0 //characteristic function
val Char.code :Int get() = this.toInt() -  'a'.toInt()
//3. hard to write stuff
fun IntArray.put(i:Int,v:Int){ this[i] = (this[i] + v).adjust() }
val mint:MutableList<Int> get() = mutableListOf<Int>()
val mong:MutableList<Long> get() = mutableListOf<Long>()
//4. more outputs
fun List<Char>.conca():String = this.joinToString("")
val CharArray.conca :String get() = this.joinToString("")
val IntArray.conca :String get() = this.joinToString(" ")
@JvmName("concaInt")
fun List<Int>.conca():String = this.joinToString(" ")
val LongArray.conca:String get() = this.joinToString(" ")
@JvmName("concaLong")
fun List<Long>.conca():String = this.joinToString(" ")
//5. Pair of ints
const val longmask = (1L shl 32) - 1
fun makepair(a:Int, b:Int):Long = (a.toLong() shl 32) xor (longmask and b.toLong()) // remember positev sonly
val Long.first get() = (this ushr 32).toInt()
val Long.second get() = this.toInt()
//6. strings
val String.size get() = this.length
const val randCount = 100
//7. bits
fun Int.has(i:Int):Boolean = (this and (1 shl i) != 0)
fun Long.has(i:Int):Boolean = (this and (1L shl i) != 0L)
//8 TIME
inline fun TIME(f:()->Unit){
    val t = measureTimeMillis(){
        f()
    }
    println("$t ms")
}
object Reader{
    private const val BS = 1 shl 16
    private const val NC = 0.toChar()
    private val buf = ByteArray(BS)
    private var bId = 0
    private var size = 0
    private var c = NC

    var warningActive = true
    var fakein = StringBuilder()

    private var IN: BufferedInputStream = BufferedInputStream(System.`in`, BS)
    val OUT: PrintWriter = PrintWriter(System.out)

    private val char: Char
        get() {
            while (bId == size) {
                size = IN.read(buf) // no need for checked exceptions
                if (size == -1) return NC
                bId = 0
            }
            return buf[bId++].toChar()
        }

    fun nextInt(): Int {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }
    fun nextLong(): Long {
        var neg = false
        if (c == NC) c = char
        while (c < '0' || c > '9') {
            if (c == '-') neg = true
            c = char
        }
        var res = 0L
        while (c in '0'..'9') {
            res = (res shl 3) + (res shl 1) + (c - '0')
            c = char
        }
        return if (neg) -res else res
    }
    fun nextString():String{
        val ret = StringBuilder()
        while (true){
            c = char
            if(!isWhitespace(c)){ break}
        }
        ret.append(c)
        while (true){
            c = char
            if(isWhitespace(c)){ break}
            ret.append(c)
        }
        return ret.toString()
    }
    fun isWhitespace(c:Char):Boolean{
        return c == ' ' || c == '\n' || c == '\r' || c == '\t'
    }
    fun rerouteInput(){
        if(warningActive){
            put("Custom test enabled")
            println("Custom test enabled")
            warningActive = false
        }
        val S = fakein.toString()
        println("New Case ")
        println(S.take(80))
        println("...")
        fakein.clear()
        IN = BufferedInputStream(S.byteInputStream(),BS)
    }
    fun takeFile(name:String){
        IN = BufferedInputStream(File(name).inputStream(),BS)
    }
}
fun put(aa:Any){ Reader.OUT.println(aa)}
fun done(){ Reader.OUT.close() }
fun share(aa:Any){
    if(aa is IntArray){Reader.fakein.append(aa.joinToString(" "))}
    else if(aa is LongArray){Reader.fakein.append(aa.joinToString(" "))}
    else if(aa is List<*>){Reader.fakein.append(aa.toString())}
    else{Reader.fakein.append(aa.toString())}
    Reader.fakein.append("\n")
}

val getintfast:Int get() = Reader.nextInt()
val getint:Int get(){ val ans = getlong ; if(ans > Int.MAX_VALUE) IntArray(1000000000); return ans.toInt() }
val getlong:Long get() = Reader.nextLong()
val getstr:String get() = Reader.nextString()
fun getline(n:Int):IntArray{
    return IntArray(n){getint}
}
fun getlineL(n:Int):LongArray{
    return LongArray(n){getlong}
}
var dmark = -1
infix fun Any.dei(a:Any){
    dmark++
    var str = "<${dmark}>   "
    debug()
    if(this is String){ str += this
    }else if(this is Int){ str += this.toString()
    }else if(this is Long){ str += this.toString()
    }else{ str += this.toString()}
    if(a is List<*>){ println("$str : ${a.joinToString(" ")}")
    }else if(a is IntArray){ println("$str : ${a.joinToString(" ")}")
    }else if(a is LongArray){ println("$str : ${a.joinToString(" ")}")
    }else if(a is BooleanArray){ println("$str :${a.map{if(it)'1' else '0'}.joinToString(" ")}")
    }else if(a is Array<*>){
        println("$str : ")
        for(c in a){if(c is IntArray){println(c.joinToString(" "))}
        else if(c is LongArray){println(c.joinToString(" "))}
        else if(c is BooleanArray){println(c.map { if(it) '1' else '0' }.joinToString(""))
        }
        }
        println()
    }else{ println("$str : $a")
    }
}
val just = " "
fun crash(){
    throw Exception("Bad programme")}
fun assert(a:Boolean){
    if(!a){
        throw Exception("Failed Assertion")
    }}
enum class solveMode {
    real, rand, tc
}
object solve{
    var mode:solveMode = solveMode.real
    var tcNum:Int = 0
    var rand:()->Unit = {}
    var TC:MutableMap<Int,()->Unit> = mutableMapOf()
    var tn:Long = 0
    fun cases(onecase:()->Unit){
        val t = if(mode == solveMode.real){if(singleCase) 1 else getint} else if(mode == solveMode.tc){1 } else randCount
        if(pI != 998_244_353 && pI != 1_000_000_007){
            throw Exception("Not usual primes!")
        }
        if(t == 1 && mode != solveMode.real){
            tn = System.currentTimeMillis()
        }
        repeat(t){
            if(mode == solveMode.tc){
                TC[tcNum]?.let { it() }
                Reader.rerouteInput()
            }else if(mode == solveMode.rand){
                rand()
                Reader.rerouteInput()
            }
            onecase()
        }
        if(t == 1 && mode != solveMode.real){
            val dt = System.currentTimeMillis() - tn
            println("Time $dt ms ")
        }
    }
    inline fun singleCase(a:solve.()->Unit){
        val t = if(mode != solveMode.rand){1} else randCount
        repeat(t) { a() }
    }
    fun rand(a:()->Unit){
        this.rand = a
    }
    fun tc(id:Int = 0,a:()->Unit){
        TC[id] = a
    }
    fun usetc(a:Int = 0 ){
        this.tcNum = a
        this.mode = solveMode.tc
    }
    fun userand(){
        this.mode = solveMode.rand
    }
}
fun debug(){}
const val singleCase = true

class cache<T,V> {
    val map = mutableMapOf<T,V>()
    fun get(a:T,ow:(T)->V):V{
        if(a in map){
            return map[a]!!
        }
        val new = ow(a)
        map[a] = new
//        just dei map.size
        return new
    }
    fun debug(a:T,ow:(T)->V):V{
        if(a in map){
            return map[a]!!
        }
        val new = ow(a)
        map[a] = new
        println("$a $new")
        return new
    }
}
infix fun Int.divceil(b:Int):Int{
    return (this/b) + if(this % b > 0) 1 else 0
}
infix fun Long.divceil(b:Long):Long{
    return (this/b) + if(this % b > 0) 1L else 0L
}
infix fun Int.div_neg_floor(b:Int):Int{
    return (this/b) - if(this % b < 0) 1 else 0
}
infix fun Long.div_neg_floor(b:Long):Long{
    return (this/b) - if(this % b < 0) 1L else 0L
}
fun modCount(x:Long, mod:Long, l:Long, r:Long):Long{
    val ans = ((r -x) div_neg_floor mod ) - ((l - x) divceil mod) + 1
    return maxOf(ans,0)
    //coun number of x mod mod in [l..r]
}
class largedecimal(var arr:LongArray){
    companion object{
        const val baselen = 17
        const val mod = 1_000_000_000_000_000_00L
        val zeros = List(baselen){'0'}.joinToString("")
    }
    constructor(a:Int):this(longArrayOf(a.toLong())){

    }
    constructor(str:String):this(longArrayOf(0)){
        for(c in str){
            val v = c.toInt() - '0'.toInt()
            this.shlonce()
            this.adding(v)
        }
    }
    fun copy():largedecimal{
        return largedecimal(arr.copyOf())
    }
    fun clean(){
        val max = arr.lastIndex
        for(i in 0..max){
            if(arr[i] >= mod){
                val extra = arr[i] / mod
                arr[i] -= extra * mod
                if(i == arr.lastIndex){
                    arr = arr.copyOf(arr.size + 1 )
                }
                arr[i+1] += extra
            }
        }
    }
    fun doubleclean(){
        val max = arr.lastIndex
        for(i in 0..max){
            if(arr[i] >= mod){
                val extra = arr[i] / mod
                arr[i] -= extra * mod
                if(i == arr.lastIndex){
                    arr = arr.copyOf(arr.size + 1 )
                }
                arr[i+1] += extra
            }else if(arr[i] < 0){
                val extra = arr[i] div_neg_floor mod
                arr[i] -= extra * mod
                if(i == arr.lastIndex){
                    arr = arr.copyOf(arr.size + 1 )
                }
                arr[i+1] += extra
            }
        }
    }
    fun smallmultiply(x:Int){
        // x <= 10 is needed
        for(i in arr.indices){
            arr[i] *= x.toLong()
        }
        clean()
    }
    fun adding(x:Int){
        arr[0] += x.toLong()
        doubleclean()
    }
    fun shlonce(){
        for(i in arr.indices){
            arr[i] *= 10L
        }
        clean()
    }
    fun shronce(){
        for(i in arr.indices){
            val new = arr[i] % 10
            arr[i] /= 10L
            if(i != 0){
                arr[i-1] += new * mod / 10
            }
        }
    }
    fun unitdigit():Int{
        return (arr[0] %10).toInt()
    }
    fun iszero():Boolean{
        return arr.all { it == 0L }
    }
    fun isnegative():Boolean{
        return arr.any { it < 0 }
    }

    override fun toString():String {
        val ret = mutableListOf<String>()
        var stuff = false
        for(i in arr.lastIndex downTo 0){
            val here = arr[i]
            if(here != 0L){
                stuff = true
                ret.add(here.toString())
            }else{
                if(stuff){
                    ret.add(zeros)
                }
            }
        }
        if(!stuff){
            return "0"
        }
        return ret.joinToString(
            ""
        )
    }
    override fun equals(other:Any?):Boolean {
        if(this === other) return true
        if(javaClass != other?.javaClass) return false

        other as largedecimal

        if(!arr.contentEquals(other.arr)) return false

        return true
    }
    override fun hashCode():Int {
        return arr.contentHashCode()
    }
}
val okcache = cache<arg,Int>()

data class arg(val num:largedecimal, val balance:Int, val rank:Int){

}

fun ok(num:largedecimal,balance:Int, rank:Int):Int{
    if(num.iszero()){
        return if(balance == 0) 0 else plarge
    }
    if(balance !in -600..600) return plarge
    return okcache.get(arg(num,balance,rank)){
        it ->
        with(it){
            val ld = num.unitdigit()
            val t1 = num.copy()
            t1.adding(-ld)
            t1.shronce()
            var best = plarge
            best = minOf(best,ok(t1,balance - ld,rank + 1) + ld * rank )
            val t2 = num.copy()
            t2.adding(10 - ld)
            t2.shronce()
            best = minOf(best,ok(t2, balance + (10-ld), rank + 1) + (10-ld) * rank)
            return@get best
        }

    }
}

fun main(){

//    var v = largedecimal(1)
//    repeat(100){
//        v.smallmultiply(2)
//        just dei v
//    }
    solve.tc {
        share("12345678901234567890123456789012345678901234567890")
    }
//    solve.usetc()
    solve.cases{
        val str = getstr
        val C = largedecimal(str)
        C.smallmultiply(9)

//        just dei ok(largedecimal(92),2,1)
//        just dei C

//        just dei ok(largedecimal(92),2,7,1)

//        return@cases

        var best = plarge
        for(balance in -600..600){
            val now = C.copy()
            now.adding(balance)
            if(now.unitdigit() != 0 || now.isnegative()) continue
            now.shronce()
            val new = ok(now, balance, 1)
//            balance dei new
            best = minOf(best, new)
        }
        put(best)

    }
    done()
}
/*
less greedy

uses at most 10

answer is no more than 500
500,500

 */


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

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

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

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

        val n = read().toBigInteger()

        val ones = Array(51) { one }
        for(i in 1..ones.lastIndex) ones[i] = (ones[i-1] * ten).inc()

        val heap = DijkHeap()
        heap.promote(n, 0)

        val ans = run ans@ {
            while(heap.isNotFinished()) {
                val x = heap.remove()
                val c = heap.cost(x)

                if(x == BigInteger.ZERO) return@ans c

                val i = ones.bsIndexOfLast { it <= x }
                heap.promote(x - ones[i], c + i + 1)
                heap.promote(ones[i+1] - x, c + i + 2)
            }

            -1
        }

        println(ans)
    }

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

val one = BigInteger.ONE
val ten = BigInteger.TEN!!

fun splitmix64(seed: Long): Long {
    var x = seed // * -7046029254386353131
    x = (x xor (x ushr 30)) * -4658895280553007687
    x = (x xor (x ushr 27)) * -7723592293110705685
    return (x xor (x ushr 31))
}
@JvmField val nonce64 = random.nextLong()
@JvmField val gamma64 = random.nextLong() or 1
fun Long.hash() = splitmix64((nonce64 xor this) * gamma64)

fun BigInteger.hash(): Long = toByteArray().run {
    var res = size.toLong()
    for(i in indices) {
        if(i and 7 == 0) res = res.hash()
        res = res xor get(i).toLong().shl(i.and(7) * 8)
    }

    return res//.hash()
}

inline fun bsFirst(first: Int, last: Int, predicate: (Int) -> Boolean): Int {
    var low = first
    var high = last

    while (low <= high) {
        val mid = low.and(high) + low.xor(high).shr(1)
        if(predicate(mid)) high = mid - 1
        else low = mid + 1
    }
    return low
}
inline fun IntRange.bsFirst(predicate: (Int) -> Boolean) = bsFirst(first, last, predicate)

inline fun bsLast(first: Int, last: Int, predicate: (Int) -> Boolean) = bsFirst(first, last) { !predicate(it) } - 1
inline fun IntRange.bsLast(predicate: (Int) -> Boolean) = bsLast(first, last, predicate)

inline fun <T> Array<T>.bsIndexOfFirst(predicate: (T) -> Boolean) = bsFirst(0, lastIndex) { predicate(get(it)) }
inline fun <T> Array<T>.bsFirst(predicate: (T) -> Boolean) = get(bsIndexOfFirst(predicate))
inline fun <T> Array<T>.bsFirstOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfFirst(predicate))
inline fun <T> Array<T>.bsIndexOfLast(predicate: (T) -> Boolean) = bsLast(0, lastIndex) { predicate(get(it)) }
inline fun <T> Array<T>.bsLast(predicate: (T) -> Boolean) = get(bsIndexOfLast(predicate))
inline fun <T> Array<T>.bsLastOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfLast(predicate))

const val inf = Int.MAX_VALUE
class DijkHeap {
    val h = intListOf(-1)
    val pos = IntList()
    val cost = IntList()
    val map = LongIntMap(nullValue = -1)
    val keys = mutableListOf<BigInteger>()

    val inHeap get() = h.lastIndex

    private fun swap(i: Int, j: Int) {
        val hi = h[i]; val hj = h[j]
        h[j] = hi; h[i] = hj
        pos[hi] = j; pos[hj] = i
    }

    fun promote(key0: BigInteger, newCost: Int): Boolean {
        val key = run {
            val hash = key0.hash()
            map[hash].let { if(it != -1) return@run it }
            keys.size.also {
                map[hash] = it
                keys.add(key0)
                h.add(it)
                pos.add(inHeap)
                cost.add(inf)
            }
        }
        if(newCost >= cost[key]) return false
        var i = pos[key]

        while(i > 1) {
            val par = i shr 1
            if (newCost >= cost[h[par]]) break
            swap(i, par)
            i = par
        }

        cost[key] = newCost
        return true
    }

    val head get() = h[1]
    fun isNotFinished() = inHeap > 0

    fun remove() = head.let { hd ->
        swap(1, inHeap)
        pos[hd] = -1
        h.pop()

        var i = 1
        while(true) {
            val l = i shl 1
            if(l > inHeap) break
            val r = l or 1

            var best = l
            var p = cost[h[l]]
            if(r <= inHeap) {
                val pr = cost[h[r]]
                if(pr < p) {
                    best = r
                    p = pr
                }
            }

            if(cost[h[i]] <= p) break

            swap(i, best)
            i = best
        }

        keys[hd]
    }

    fun cost(key: BigInteger): Int {
        val hash = key.hash()
        val i = map[hash]
        return if(i == -1) inf else cost[i]
    }
}

class IntList(initialCapacity: Int = 12) {
    private var arr = IntArray(initialCapacity)
    val _arr get() = arr
    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)) }

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

    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)

typealias LongIntMap = _Ez_Long__Int_HashMap
inline operator fun LongIntMap.set(key: Long, value: Int) { put(key, value) }
inline operator fun LongIntMap.contains(key: Long) = containsKey(key)

class _Ez_Long__Int_HashMap(capacity: Int = DEFAULT_CAPACITY, val nullValue: Int = 0) :
    _Ez_Long__Int_Map {
    companion object {
        private const val DEFAULT_CAPACITY = 8
        // There are three invariants for size, removedCount and arraysLength:
// 1. size + removedCount <= 1/2 arraysLength
// 2. size > 1/8 arraysLength
// 3. size >= removedCount
// arraysLength can be only multiplied by 2 and divided by 2.
// Also, if it becomes >= 32, it can't become less anymore.
        private const val REBUILD_LENGTH_THRESHOLD = 32
        private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b
        private const val HASHCODE_MULTIPLIER = 0x01000193
        private const val FREE: Byte = 0
        private const val REMOVED: Byte = 1
        private const val FILLED: Byte = 2
        private val hashSeed = random.nextLong()
        private val gamma = random.nextLong() or 1
    }

    private lateinit   var keys: LongArray
    private lateinit   var values: IntArray
    private lateinit var status: ByteArray
    override var size = 0
        private set
    private var removedCount = 0
    private var mask = 0

    constructor(map: _Ez_Long__Int_Map) : this(map.size) {
        val it = map.iterator()
        while (it.hasNext()) {
            put(it.key, it.value)
            it.next()
        }
    }

    constructor(javaMap: Map<Long, Int>) : this(javaMap.size) {
        for ((key, value) in javaMap) {
            put(key, value)
        }
    }

    private fun getStartPos(h: Long): Int {
        var x = (h xor hashSeed) * gamma
        x = (x xor (x ushr 30)) * -4658895280553007687
        x = (x xor (x ushr 27)) * -7723592293110705685
        return (x xor (x ushr 31)).toInt() and mask
    }

    override fun isEmpty(): Boolean = size == 0

    override fun containsKey(
        key: Long
    ): Boolean {
        var pos = getStartPos(key)
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                return true
            }
            pos = pos + 1 and mask
        }
        return false
    }

    override fun  get(
        key: Long
    ): Int {
        var pos = getStartPos(key)
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                return values[pos]
            }
            pos = pos + 1 and mask
        }
        return nullValue
    }

    override fun  put(
        key: Long,
        value: Int
    ): Int {
        var pos = getStartPos(key)
        while (status[pos] == FILLED) {
            if (keys[pos] == key) {
                val   oldValue = values[pos]
                values[pos] = value
                return oldValue
            }
            pos = pos + 1 and mask
        }
        if (status[pos] == FREE) {
            status[pos] = FILLED
            keys[pos] = key
            values[pos] = value
            size++
            if ((size + removedCount) * 2 > keys.size) {
                rebuild(keys.size * 2) // enlarge the table
            }
            return nullValue
        }
        val removedPos = pos
        pos = pos + 1 and mask
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                val   oldValue = values[pos]
                values[pos] = value
                return oldValue
            }
            pos = pos + 1 and mask
        }
        status[removedPos] = FILLED
        keys[removedPos] = key
        values[removedPos] = value
        size++
        removedCount--
        return nullValue
    }

    override fun  remove(
        key: Long
    ): Int {
        var pos = getStartPos(key)
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                val   removedValue = values[pos]
                status[pos] = REMOVED
                size--
                removedCount++
                if (keys.size > REBUILD_LENGTH_THRESHOLD) {
                    if (8 * size <= keys.size) {
                        rebuild(keys.size / 2) // compress the table
                    } else if (size < removedCount) {
                        rebuild(keys.size) // just rebuild the table
                    }
                }
                return removedValue
            }
            pos = pos + 1 and mask
        }
        return nullValue
    }

    override fun clear() {
        if (keys.size > REBUILD_LENGTH_THRESHOLD) {
            initEmptyTable(REBUILD_LENGTH_THRESHOLD)
        } else {
            status.fill(FREE)
            size = 0
            removedCount = 0
        }
    }

    override fun keys(): LongArray {
        val result = LongArray(size)
        var i = 0
        var j = 0
        while (i < keys.size) {
            if (status[i] == FILLED) {
                result[j++] = keys[i]
            }
            i++
        }
        return result
    }

    override fun values(): IntArray {
        val result = IntArray(size)
        var i = 0
        var j = 0
        while (i < values.size) {
            if (status[i] == FILLED) {
                result[j++] = values[i]
            }
            i++
        }
        return result
    }

    override fun iterator(): _Ez_Long__Int_MapIterator {
        return _Ez_Long__Int_HashMapIterator()
    }

    private fun rebuild(newLength: Int) {
        val oldKeys = keys

        val oldValues = values
        val oldStatus = status
        initEmptyTable(newLength)
        for (i in oldKeys.indices) {
            if (oldStatus[i] == FILLED) {
                put(oldKeys[i], oldValues[i])
            }
        }
    }

    private fun initEmptyTable(length: Int) {
        keys = LongArray(length)
        values = IntArray(length)
        status = ByteArray(length)
        size = 0
        removedCount = 0
        mask = length - 1
    }

    fun contentEquals(that: _Ez_Long__Int_HashMap): Boolean {
        if (size != that.size) {
            return false
        }
        for (i in keys.indices) {
            if (status[i] == FILLED) {
                val   thatValue = that[keys[i]]
                if (thatValue != values[i]) {
                    return false
                }
            }
        }
        return true
    }

    override fun toString(): String {
        val sb = StringBuilder()
        sb.append('{')
        for (i in keys.indices) {
            if (status[i] == FILLED) {
                if (sb.length > 1) {
                    sb.append(", ")
                }
                sb.append(keys[i])
                sb.append('=')
                sb.append(values[i])
            }
        }
        sb.append('}')
        return sb.toString()
    }

    private inner class _Ez_Long__Int_HashMapIterator : _Ez_Long__Int_MapIterator {
        private var curIndex = 0
        override fun hasNext(): Boolean {
            return curIndex < status.size
        }

        override val key: Long

            get() {
                if (curIndex == keys.size) {
                    throw NoSuchElementException("Iterator doesn't have more entries")
                }
                return keys[curIndex]
            }

        override val value: Int

            get() {
                if (curIndex == values.size) {
                    throw NoSuchElementException("Iterator doesn't have more entries")
                }
                return values[curIndex]
            }

        override fun next() {
            if (curIndex == status.size) {
                return
            }
            curIndex++
            while (curIndex < status.size && status[curIndex] != FILLED) {
                curIndex++
            }
        }

        init {
            while (curIndex < status.size && status[curIndex] != FILLED) {
                curIndex++
            }
        }
    }

    init {
        require(capacity >= 0) { "Capacity must be non-negative" }
        val length = Integer.highestOneBit(4 * max(1, capacity) - 1)
        // Length is a power of 2 now
        initEmptyTable(length)
    }
}

interface _Ez_Long__Int_Map {

    val size: Int

    fun isEmpty(): Boolean

    fun containsKey(
        key: Long
    ): Boolean

    operator fun  get(
        key: Long
    ): Int

    fun  put(
        key: Long,
        value: Int
    ): Int

    fun  remove(
        key: Long
    ): Int

    fun clear()

    fun keys(): LongArray

    fun values(): IntArray

    operator fun iterator(): _Ez_Long__Int_MapIterator

    override fun toString(): String
}

interface _Ez_Long__Int_MapIterator {
    operator fun hasNext(): Boolean

    val key: Long

    val value: Int

    operator fun next()
}

inline fun LongIntMap.forEach(act: (key: Long, value: Int) -> Unit) {
    val ite = iterator()
    while(ite.hasNext()) {
        act(ite.key, ite.value)
        ite.next()
    }
}

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

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

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

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

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

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

@JvmField val _writer = PrintWriter(OUTPUT, false)

/**  sort overrides to avoid quicksort attacks */

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

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

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

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

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

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

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

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

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

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

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


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

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

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

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

        val n = read().toBigInteger()

        val ones = Array(51) { one }
        for(i in 1..ones.lastIndex) ones[i] = (ones[i-1] * ten).inc()

        val heap = DijkHeap()
        heap.promote(n, 0)

        val ans = run ans@ {
            while(heap.isNotFinished()) {
                val x = heap.remove()
                val c = heap.cost(x)

                if(x == BigInteger.ZERO) return@ans c

                val i = ones.bsIndexOfLast { it <= x }
                heap.promote(x - ones[i], c + i + 1)
                heap.promote(ones[i+1] - x, c + i + 2)
            }

            -1
        }

        println(ans)
    }

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

val one = BigInteger.ONE
val ten = BigInteger.TEN!!

fun splitmix64(seed: Long): Long {
    var x = seed // * -7046029254386353131
    x = (x xor (x ushr 30)) * -4658895280553007687
    x = (x xor (x ushr 27)) * -7723592293110705685
    return (x xor (x ushr 31))
}
@JvmField val nonce64 = random.nextLong()
@JvmField val gamma64 = random.nextLong() or 1
fun Long.hash() = splitmix64((nonce64 xor this) * gamma64)

fun BigInteger.hash(): Long = toByteArray().asUByteArray().run {
    var res = size.toLong()
    for(i in indices) {
        if(i and 7 == 0) res = res.hash()
        res = res xor get(i).toLong().shl(i.and(7) * 8)
    }

    return res//.hash()
}

inline fun bsFirst(first: Int, last: Int, predicate: (Int) -> Boolean): Int {
    var low = first
    var high = last

    while (low <= high) {
        val mid = low.and(high) + low.xor(high).shr(1)
        if(predicate(mid)) high = mid - 1
        else low = mid + 1
    }
    return low
}
inline fun IntRange.bsFirst(predicate: (Int) -> Boolean) = bsFirst(first, last, predicate)

inline fun bsLast(first: Int, last: Int, predicate: (Int) -> Boolean) = bsFirst(first, last) { !predicate(it) } - 1
inline fun IntRange.bsLast(predicate: (Int) -> Boolean) = bsLast(first, last, predicate)

inline fun <T> Array<T>.bsIndexOfFirst(predicate: (T) -> Boolean) = bsFirst(0, lastIndex) { predicate(get(it)) }
inline fun <T> Array<T>.bsFirst(predicate: (T) -> Boolean) = get(bsIndexOfFirst(predicate))
inline fun <T> Array<T>.bsFirstOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfFirst(predicate))
inline fun <T> Array<T>.bsIndexOfLast(predicate: (T) -> Boolean) = bsLast(0, lastIndex) { predicate(get(it)) }
inline fun <T> Array<T>.bsLast(predicate: (T) -> Boolean) = get(bsIndexOfLast(predicate))
inline fun <T> Array<T>.bsLastOrNull(predicate: (T) -> Boolean) = getOrNull(bsIndexOfLast(predicate))

const val inf = Int.MAX_VALUE
class DijkHeap {
    val h = intListOf(-1)
    val pos = IntList()
    val cost = IntList()
    val map = LongIntMap(nullValue = -1)
    val keys = mutableListOf<BigInteger>()

    val inHeap get() = h.lastIndex

    private fun swap(i: Int, j: Int) {
        val hi = h[i]; val hj = h[j]
        h[j] = hi; h[i] = hj
        pos[hi] = j; pos[hj] = i
    }

    fun promote(key0: BigInteger, newCost: Int): Boolean {
        val key = run {
            val hash = key0.hash()
            map[hash].let { if(it != -1) return@run it }
            keys.size.also {
                map[hash] = it
                keys.add(key0)
                h.add(it)
                pos.add(inHeap)
                cost.add(inf)
            }
        }
        if(newCost >= cost[key]) return false
        var i = pos[key]

        while(i > 1) {
            val par = i shr 1
            if (newCost >= cost[h[par]]) break
            swap(i, par)
            i = par
        }

        cost[key] = newCost
        return true
    }

    val head get() = h[1]
    fun isNotFinished() = inHeap > 0

    fun remove() = head.let { hd ->
        swap(1, inHeap)
        pos[hd] = -1
        h.pop()

        var i = 1
        while(true) {
            val l = i shl 1
            if(l > inHeap) break
            val r = l or 1

            var best = l
            var p = cost[h[l]]
            if(r <= inHeap) {
                val pr = cost[h[r]]
                if(pr < p) {
                    best = r
                    p = pr
                }
            }

            if(cost[h[i]] <= p) break

            swap(i, best)
            i = best
        }

        keys[hd]
    }

    fun cost(key: BigInteger): Int {
        val hash = key.hash()
        val i = map[hash]
        return if(i == -1) inf else cost[i]
    }
}

class IntList(initialCapacity: Int = 12) {
    private var arr = IntArray(initialCapacity)
    val _arr get() = arr
    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)) }

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

    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)

typealias LongIntMap = _Ez_Long__Int_HashMap
inline operator fun LongIntMap.set(key: Long, value: Int) { put(key, value) }
inline operator fun LongIntMap.contains(key: Long) = containsKey(key)

class _Ez_Long__Int_HashMap(capacity: Int = DEFAULT_CAPACITY, val nullValue: Int = 0) :
    _Ez_Long__Int_Map {
    companion object {
        private const val DEFAULT_CAPACITY = 8
        // There are three invariants for size, removedCount and arraysLength:
// 1. size + removedCount <= 1/2 arraysLength
// 2. size > 1/8 arraysLength
// 3. size >= removedCount
// arraysLength can be only multiplied by 2 and divided by 2.
// Also, if it becomes >= 32, it can't become less anymore.
        private const val REBUILD_LENGTH_THRESHOLD = 32
        private const val HASHCODE_INITIAL_VALUE = -0x7ee3623b
        private const val HASHCODE_MULTIPLIER = 0x01000193
        private const val FREE: Byte = 0
        private const val REMOVED: Byte = 1
        private const val FILLED: Byte = 2
        private val hashSeed = random.nextLong()
        private val gamma = random.nextLong() or 1
    }

    private lateinit   var keys: LongArray
    private lateinit   var values: IntArray
    private lateinit var status: ByteArray
    override var size = 0
        private set
    private var removedCount = 0
    private var mask = 0

    constructor(map: _Ez_Long__Int_Map) : this(map.size) {
        val it = map.iterator()
        while (it.hasNext()) {
            put(it.key, it.value)
            it.next()
        }
    }

    constructor(javaMap: Map<Long, Int>) : this(javaMap.size) {
        for ((key, value) in javaMap) {
            put(key, value)
        }
    }

    private fun getStartPos(h: Long): Int {
        var x = (h xor hashSeed) * gamma
        x = (x xor (x ushr 30)) * -4658895280553007687
        x = (x xor (x ushr 27)) * -7723592293110705685
        return (x xor (x ushr 31)).toInt() and mask
    }

    override fun isEmpty(): Boolean = size == 0

    override fun containsKey(
        key: Long
    ): Boolean {
        var pos = getStartPos(key)
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                return true
            }
            pos = pos + 1 and mask
        }
        return false
    }

    override fun  get(
        key: Long
    ): Int {
        var pos = getStartPos(key)
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                return values[pos]
            }
            pos = pos + 1 and mask
        }
        return nullValue
    }

    override fun  put(
        key: Long,
        value: Int
    ): Int {
        var pos = getStartPos(key)
        while (status[pos] == FILLED) {
            if (keys[pos] == key) {
                val   oldValue = values[pos]
                values[pos] = value
                return oldValue
            }
            pos = pos + 1 and mask
        }
        if (status[pos] == FREE) {
            status[pos] = FILLED
            keys[pos] = key
            values[pos] = value
            size++
            if ((size + removedCount) * 2 > keys.size) {
                rebuild(keys.size * 2) // enlarge the table
            }
            return nullValue
        }
        val removedPos = pos
        pos = pos + 1 and mask
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                val   oldValue = values[pos]
                values[pos] = value
                return oldValue
            }
            pos = pos + 1 and mask
        }
        status[removedPos] = FILLED
        keys[removedPos] = key
        values[removedPos] = value
        size++
        removedCount--
        return nullValue
    }

    override fun  remove(
        key: Long
    ): Int {
        var pos = getStartPos(key)
        while (status[pos] != FREE) {
            if (status[pos] == FILLED && keys[pos] == key) {
                val   removedValue = values[pos]
                status[pos] = REMOVED
                size--
                removedCount++
                if (keys.size > REBUILD_LENGTH_THRESHOLD) {
                    if (8 * size <= keys.size) {
                        rebuild(keys.size / 2) // compress the table
                    } else if (size < removedCount) {
                        rebuild(keys.size) // just rebuild the table
                    }
                }
                return removedValue
            }
            pos = pos + 1 and mask
        }
        return nullValue
    }

    override fun clear() {
        if (keys.size > REBUILD_LENGTH_THRESHOLD) {
            initEmptyTable(REBUILD_LENGTH_THRESHOLD)
        } else {
            status.fill(FREE)
            size = 0
            removedCount = 0
        }
    }

    override fun keys(): LongArray {
        val result = LongArray(size)
        var i = 0
        var j = 0
        while (i < keys.size) {
            if (status[i] == FILLED) {
                result[j++] = keys[i]
            }
            i++
        }
        return result
    }

    override fun values(): IntArray {
        val result = IntArray(size)
        var i = 0
        var j = 0
        while (i < values.size) {
            if (status[i] == FILLED) {
                result[j++] = values[i]
            }
            i++
        }
        return result
    }

    override fun iterator(): _Ez_Long__Int_MapIterator {
        return _Ez_Long__Int_HashMapIterator()
    }

    private fun rebuild(newLength: Int) {
        val oldKeys = keys

        val oldValues = values
        val oldStatus = status
        initEmptyTable(newLength)
        for (i in oldKeys.indices) {
            if (oldStatus[i] == FILLED) {
                put(oldKeys[i], oldValues[i])
            }
        }
    }

    private fun initEmptyTable(length: Int) {
        keys = LongArray(length)
        values = IntArray(length)
        status = ByteArray(length)
        size = 0
        removedCount = 0
        mask = length - 1
    }

    fun contentEquals(that: _Ez_Long__Int_HashMap): Boolean {
        if (size != that.size) {
            return false
        }
        for (i in keys.indices) {
            if (status[i] == FILLED) {
                val   thatValue = that[keys[i]]
                if (thatValue != values[i]) {
                    return false
                }
            }
        }
        return true
    }

    override fun toString(): String {
        val sb = StringBuilder()
        sb.append('{')
        for (i in keys.indices) {
            if (status[i] == FILLED) {
                if (sb.length > 1) {
                    sb.append(", ")
                }
                sb.append(keys[i])
                sb.append('=')
                sb.append(values[i])
            }
        }
        sb.append('}')
        return sb.toString()
    }

    private inner class _Ez_Long__Int_HashMapIterator : _Ez_Long__Int_MapIterator {
        private var curIndex = 0
        override fun hasNext(): Boolean {
            return curIndex < status.size
        }

        override val key: Long

            get() {
                if (curIndex == keys.size) {
                    throw NoSuchElementException("Iterator doesn't have more entries")
                }
                return keys[curIndex]
            }

        override val value: Int

            get() {
                if (curIndex == values.size) {
                    throw NoSuchElementException("Iterator doesn't have more entries")
                }
                return values[curIndex]
            }

        override fun next() {
            if (curIndex == status.size) {
                return
            }
            curIndex++
            while (curIndex < status.size && status[curIndex] != FILLED) {
                curIndex++
            }
        }

        init {
            while (curIndex < status.size && status[curIndex] != FILLED) {
                curIndex++
            }
        }
    }

    init {
        require(capacity >= 0) { "Capacity must be non-negative" }
        val length = Integer.highestOneBit(4 * max(1, capacity) - 1)
        // Length is a power of 2 now
        initEmptyTable(length)
    }
}

interface _Ez_Long__Int_Map {

    val size: Int

    fun isEmpty(): Boolean

    fun containsKey(
        key: Long
    ): Boolean

    operator fun  get(
        key: Long
    ): Int

    fun  put(
        key: Long,
        value: Int
    ): Int

    fun  remove(
        key: Long
    ): Int

    fun clear()

    fun keys(): LongArray

    fun values(): IntArray

    operator fun iterator(): _Ez_Long__Int_MapIterator

    override fun toString(): String
}

interface _Ez_Long__Int_MapIterator {
    operator fun hasNext(): Boolean

    val key: Long

    val value: Int

    operator fun next()
}

inline fun LongIntMap.forEach(act: (key: Long, value: Int) -> Unit) {
    val ite = iterator()
    while(ite.hasNext()) {
        act(ite.key, ite.value)
        ite.next()
    }
}

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

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

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

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

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

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

@JvmField val _writer = PrintWriter(OUTPUT, false)

/**  sort overrides to avoid quicksort attacks */

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

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

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

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

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

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

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

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

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

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

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


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

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

fun factorList(a: Int): MutableList<Int> {
    var a = a
    var b = 2
    val res = mutableListOf<Int>()
    if (a < 2) return res
    while (b * b <= a) {
        if (a % b == 0) {
            res.add(b)
            a = a / b
            b = 2
        } else ++b
    }
    res.add(a)
    return res
}

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

    var st = StringTokenizer(br.readLine())
    val a = st.nextToken().toInt()
    val b = st.nextToken().toInt()

    val lista = factorList(a)
    val listb = factorList(b)

    val itera = lista.iterator()
    while (itera.hasNext()) {
        val idx = listb.indexOf(itera.next())
        if (idx != -1) {
            listb.removeAt(idx)
            itera.remove()
        }
    }
    if ((lista.isNotEmpty() && lista.last() > 5) ||
            (listb.isNotEmpty() && listb.last() > 5)) bw.write("-1\n")
    else bw.write("${lista.size + listb.size}\n")

    bw.close()
}


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

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

fun factorList(a: Int): MutableList<Int> {
    var a = a
    var b = 2
    val res = mutableListOf<Int>()
    while (b * b <= a) {
        if (a % b == 0) {
            res.add(b)
            a = a / b
            b = 2
        } else ++b
    }
    if (a > 1) res.add(a)
    return res
}

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

    var st = StringTokenizer(br.readLine())
    val a = st.nextToken().toInt()
    val b = st.nextToken().toInt()

    val lista = factorList(a)
    val listb = factorList(b)

    if (a == 1 && b == 1) bw.write("0\n")
    else if (a == 1) {
        if (listb.last() > 5) bw.write("-1\n")
        else bw.write("${listb.size}\n")
    }
    else if (b == 1) {
        if (lista.last() > 5) bw.write("-1\n")
        else bw.write("${lista.size}\n")
    }
    else {
        val itera = lista.iterator()
        while (itera.hasNext()) {
            val idx = listb.indexOf(itera.next())
            if (idx != -1) {
                listb.removeAt(idx)
                itera.remove()
            }
        }
        if ((lista.isNotEmpty() && lista.last() > 5) ||
                (listb.isNotEmpty() && listb.last() > 5)) bw.write("-1\n")
        else bw.write("${lista.size + listb.size}\n")
    }

    bw.close()
}


fun readInts(): List<Int> {
    return readLine()!!.split(" ").map(String::toInt)
}

typealias Edge = Pair<Pair<Int, Int>, Pair<Int, Int>>

fun main() {
    var left = Int.MAX_VALUE
    var right = Int.MIN_VALUE
    var top = Int.MIN_VALUE
    var bottom = Int.MAX_VALUE
    val dict = mutableSetOf<Edge>()
    for (i in 0 until 4) {
        val (x1, y1, x2, y2) = readInts()
        if (x1 == x2 && y1 == y2) {
            println("NO")
            return
        }
        left = left.coerceAtMost(x1.coerceAtMost(x2))
        right = right.coerceAtLeast(x1.coerceAtLeast(x2))
        top = top.coerceAtLeast(y1.coerceAtLeast(y2))
        bottom = bottom.coerceAtMost(y1.coerceAtMost(y2))
        dict.add(Pair(Pair(x1, y1), Pair(x2, y2)))
        dict.add(Pair(Pair(x2, y2), Pair(x1, y1)))
    }

    if (left == right || top == bottom) {
        println("NO")
        return
    }

    val LT = Pair(left, top)
    val LB = Pair(left, bottom)
    val RT = Pair(right, top)
    val RB = Pair(right, bottom)
    val topEdge = Pair(LT, RT)
    val bottomEdge = Pair(LB, RB)
    val leftEdge = Pair(LT, LB)
    val rightEdge = Pair(RT, RB)
    println(
        if (
            dict.contains(topEdge) &&
            dict.contains(bottomEdge) &&
            dict.contains(leftEdge) &&
            dict.contains(rightEdge)
        )
            "YES"
        else
            "NO"
    )
}


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

    var busSize = m
    var count = 1
    for (i in list) {
        if (i <= busSize) {
            busSize = busSize - i
        } else {
            count++
            busSize = m - i
        }
    }
    println(count)

}


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

    val (_, busSize) = readInts()
    val groupsSizes = readInts()
    var currentSize = busSize
    var sol = 1
    for (groupSize in groupsSizes)
        if (groupSize <= currentSize)
            currentSize -= groupSize
        else {
            sol++
            currentSize = busSize - groupSize
        }
    print(sol)
}


fun main(args: Array<String>) {
    val nm = readLine()!!.trim().split(" ").map {it.trim().toInt()}.toIntArray()
    val a = readLine()!!.trim().split(" ").map {it.trim().toInt()}.toIntArray()
    var result = 1
    var people=0
    for (i in 0 until nm[0]){
        if (people + a[i] <= nm[1]){
            people+=a[i]
        }
        else{
            result++
            people=a[i]
        }
    }
    println(result)

}


import java.util.*

fun main() {

    val sc = Scanner(System.`in`)
    val n : Int = sc.nextInt()
    val m : Int = sc.nextInt()
    var k : Int = sc.nextInt()
    val a = IntArray(n)
    var count = n

    for (i in 0 until n) a[i] = sc.nextInt()
    Arrays.sort(a)

    while (k < m && count > 0) {
        count--
        k += a[count] - 1
    }

    if (k < m) print(-1)
    else print(n - count)

}


import java.util.Scanner
fun main(args : Array<String>){
    val reader = Scanner(System.`in`)
    var n: Int = reader.nextInt()
    var b = 0

    for(i in 2..n){
        var a = 0
        for(j in 2..i) {
            if (i % j == 0 && checkPrime(j) == 1) {
                a++
            }
        }
        if(a == 2) b++
    }
    println(b)
}

fun checkPrime(n: Int):Int{
    var a = 0
    for(i in 2..n/2) {
        if (n % i==0) {
            a++
        }
    }
    if(a==0) return 1
    else return 0
}


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

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

class Main {
    internal class TaskA {
        fun solve(inp: InputReader, out: PrintWriter) {
            val n = inp.nextInt()
            val primes = sieve(60)
            var ans = 0
            for (i in 1..n) {
                val set = hashSetOf<Int>()
                var j = 0
                var v = i
                while (primes[j] * primes[j] <= v)
                    if (v % primes[j] == 0) {
                        v /= primes[j]
                        set.add(primes[j])
                    } else
                        j++
                if (v > 1)
                    set.add(v)
                if (set.size == 2)
                    ans++
            }
            out.println(ans)
        }

        private fun sieve(max: Int): IntArray {
            val a = Array(max + 1) { true }
            val primes = arrayListOf<Int>()
            for (i in 2..max)
                if (a[i]) {
                    primes.add(i)
                    var j = 2 * i
                    while (j <= max) {
                        a[j] = false
                        j += i
                    }
                }
            return primes.toIntArray()
        }
    }

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

        init {
            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 next().toLong()
        }
    }
}


import kotlin.math.sqrt

fun main() {
    val r = System.`in`.bufferedReader()
    val s = StringBuilder()
    val n = r.readLine()!!.toInt()
    val prime = mutableSetOf<Int>()
    fun isprime(i: Int) = (2..sqrt(i.toDouble()).toInt()).none { i % it == 0 }
    for (i in 2..3000){
        if (isprime(i)){
            prime += i
        }
    }
    fun fac(i:Int):List<Int>{
        val ans = mutableListOf<Int>()
        for (j in 2..sqrt(i.toDouble()).toInt()){
            if (i%j==0){
                ans+=j
                if (i/j>j){
                    ans+=i/j
                }
            }
        }
        return ans
    }
    var ans = 0
    loop@for (j in 1..n){
        val divisor = fac(j)
        //println("$j ${divisor}")
        var cnt = 0
        for (div in divisor){
            if (div in prime){
                cnt++
                if (cnt>2){
                    continue@loop
                }
            }
        }
        if (cnt==2) {
            ans++
            //println(j)
        }
    }
    println(ans)
}


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

fun main() {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val n = reader.readLine().toInt()
    println((1..n).count { x ->
        var z = x
        val primes = hashSetOf<Int>()
        (2 until x).forEach {
            while (z % it == 0) {
                primes.add(it)
                z /= it
            }
        }
        primes.size == 2
    })
}


fun readIntList() = readLine()!!.split(' ').map(String::toInt).toMutableList()
fun readLongList() = readLine()!!.split(' ').map(String::toLong).toMutableList()
fun readInt() = readLine()!!.toInt()

fun main(args: Array<String>) {
    val f = readLine()!!
    val m = readLine()!!
    val s = readLine()!!

    if (isGreaterThan(f, m) && isGreaterThan(f, s)) {
        println("F")
    } else if (isGreaterThan(m, f) && isGreaterThan(m, s)) {
        println("M")
    }else if (isGreaterThan(s, m) && isGreaterThan(s, f)) {
        println("S")
    }else {
        println("?")
    }

}

fun isGreaterThan(str1: String, str2: String): Boolean {
    return (str1 == "scissors" && str2 == "paper") || (str1 == "paper" && str2 == "rock") || (str1 == "rock" && str2 == "scissors")
}


fun main(args : Array<String>) {

    val F = readLine()!!
    val M = readLine()!!
    val S = readLine()!!
    val list = arrayOf("scissors","rock","paper")

    var a = 0
    var b = 0
    var c = 0

    for(i in 0..2){
        if(list[i]==F){ a = i }
    }
    for(i in 0..2){
        if(list[i]==M){ b = i }
    }
    for(i in 0..2){
        if(list[i]==S){ c = i }
    }

    if(a==b && a==c && b==c){
        println("?")
    }
    else if(a!=b && a!=c && b!=c){
        println("?")
    }
    else if(a!=b && b==c){
           if((win(a,b))==1){
                   println("F")
               }
        else {
               println("?")
           }
    }
    else if(b!=a && a==c){
        if((win(b,a))==1){
                println("M")
            }
        else {
            println("?")
        }
    }
    else if(c!=b && b==a){
        if((win(c,b))==1){
                println("S")
            }
        else {
            println("?")
        }
    }
    else{
        println("?")
    }
}

fun win(x:Int, y: Int):Int{
     if((x==2 && y == 1) || (x==1 && y==0) || ( x== 0 && y==2)) {return 1}
     else return 0
}


enum class SetType {
    EMPTY,
    LINE,
    WHOLE_FIELD
}

typealias Line = Triple<Int, Int, Int>
fun Line.a() = first
fun Line.b() = second
fun Line.c() = third

fun Line.setType(): SetType {
    if (a() == 0 && b() == 0 && c() == 0) return SetType.WHOLE_FIELD
    if (a() == 0 && b() == 0) return SetType.EMPTY
    return SetType.LINE
}

fun calcDet(line1: Line, line2: Line) = line1.a() * line2.b() - line1.b() * line2.a()

fun calcIntersections(line1: Line, line2: Line): Int {
    if (line1.setType() == SetType.EMPTY || line2.setType() == SetType.EMPTY) return 0
    if (line1.setType() == SetType.WHOLE_FIELD || line2.setType() == SetType.WHOLE_FIELD) return -1
    val det = calcDet(line1, line2)
    if (det != 0) return 1

    return if (line1.first != 0) {
        val c1f = line1.c() * line2.a()
        val c2f = line2.c() * line1.a()
        if (c1f == c2f) -1 else 0
    } else {
        val c1f = line1.c() * line2.b()
        val c2f = line2.c() * line1.b()
        if (c1f == c2f) -1 else 0
    }
}

fun main(args: Array<String>) {
    val line1 = readLine()!!.split(" ").filter { it.isNotBlank() }.map { it.toInt() }.toIntArray()
    val line2 = readLine()!!.split(" ").filter { it.isNotBlank() }.map { it.toInt() }.toIntArray()

    val line1T = Triple(line1[0], line1[1], line1[2])
    val line2T = Triple(line2[0], line2[1], line2[2])

    println(calcIntersections(line1T, line2T))
}


import java.io.DataInputStream
import java.io.InputStream
import java.lang.StringBuilder
import kotlin.math.min

internal class Parserdoubt(`in`: InputStream) {
    private val BUFFER_SIZE = 1 shl 17

    private val din: DataInputStream
    private val buffer: ByteArray
    private var bufferPointer: Int = 0
    private var bytesRead: Int = 0

    init {
        din = DataInputStream(`in`)
        buffer = ByteArray(BUFFER_SIZE)
        bytesRead = 0
        bufferPointer = bytesRead
    }

    @Throws(Exception::class)
    fun nextString(): String {
        val sb = StringBuffer("")
        var c = read()
        while (c <= ' '.toByte())
            c = read()
        do {
            sb.append(c.toChar())
            c = read()
        } while (c > ' '.toByte())
        return sb.toString()
    }

    @Throws(Exception::class)
    fun wholeLine(): String {
        val sb = StringBuffer("")
        var c = read()
        while (c <= '\n'.toByte())
            c = read()
        do {
            sb.append(c.toChar())
            c = read()
        } while (c > '\n'.toByte())
        return sb.toString()
    }

    @Throws(Exception::class)
    fun nextChar(): Char {
        var c = read()
        while (c <= ' '.toByte())
            c = read()
        return c.toChar()
    }

    @Throws(Exception::class)
    fun nextInt(): Int {
        var ret = 0
        var c = read()
        while (c <= ' '.toByte())
            c = read()
        val neg = c == '-'.toByte()
        if (neg)
            c = read()
        do {
            ret = ret * 10 + c - '0'.toInt()
            c = read()
        } while (c > ' '.toByte())
        return if (neg) -ret else ret
    }

    @Throws(Exception::class)
    fun nextLong(): Long {
        var ret: Long = 0
        var c = read()
        while (c <= ' '.toByte())
            c = read()
        val neg = c == '-'.toByte()
        if (neg)
            c = read()
        do {
            ret = ret * 10 + c - '0'.toLong()
            c = read()
        } while (c > ' '.toByte())
        return if (neg) -ret else ret
    }

    @Throws(Exception::class)
    private fun fillBuffer() {
        bufferPointer = 0
        bytesRead = din.read(buffer, 0, BUFFER_SIZE)
        if (bytesRead == -1)
            buffer[0] = -1
    }

    @Throws(Exception::class)
    private fun read(): Byte {
        if (bufferPointer == bytesRead)
            fillBuffer()
        return buffer[bufferPointer++]
    }
}

data class E (
    val cnt:Int,
    val id: Int
): Comparable<E> {
    override fun compareTo(other: E): Int {
        return other.cnt - cnt
    }
}

fun main(args : Array<String>) {
    val input = Parserdoubt(`in` = System.`in`)
    val NT = 1//input.nextInt()
    val sb = StringBuilder()
    for(test in 1..NT){
        val c = input.nextInt()
        val r = input.nextInt()
        val n = input.nextInt() - 1
        var ans = 0

        for(i in -5000 .. 5000 step 2){
            if(i<0){
                val start = -i
                val num = min(r - start, c)
                if(num <= 0)continue
                if(num%2==1){
                    if(num/2 == n)ans ++
                    else if(num/2 > n)ans +=2
                }else {
                    if(num/2 > n)ans +=2
                }
            } else {
                val end = c - i
                val num = min(r, end)
                if(num <= 0)continue
                if(num%2==1){
                    if(num/2 == n)ans ++
                    else if(num/2 > n)ans +=2
                }else {
                    if(num/2 > n)ans +=2
                }
            }
        }
        println(ans)

    }
}


fun main(args: Array<String>) {
    val (n,m)=readLine()!!.split(' ').take(2).map { it.toInt() }
    val x = readLine()!!.toInt()
    val (r, c) = n - 2 * x to m - 2 * x
    fun ans(x: Int):Int {
        val (r, c) = n - 2 * (x - 1) to m - 2 * (x - 1)
        return if (r < 0 || c < 0)
            0
        else
            ((r-(r / 2)) * ((c + 1) / 2)) + ((r / 2) * (c / 2))
    }
    println(ans(x) - ans(x+1))
}


import java.util.Scanner
import kotlin.math.min

fun main(args : Array<String>) {

    val reader = Scanner(System.`in`)
    var a: Int = reader.nextInt()
    var b: Int = reader.nextInt()
    var x: Int = reader.nextInt()
    var y: Int = reader.nextInt()

    var d = gcd(x,y)
    x = x / d
    y = y / d

    var m = min(a/x, b/y)

    print(m*x)
    print(" ")
    print(m*y)

}

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


fun main(args: Array<String>) {
    val (n, k) = readLine()!!.split(" ").map(String::toLong)
    val ans = if (k == 1L) n else n.toString(2).replace('0', '1').toLong(2)
    println(ans)
}


fun main() {
    val (n, k) = readLine()!!.split(" ").map(String::toLong)
    if (k == 1L) print(n) else {
        var result = Long.MAX_VALUE
        while (result shr 1 >= n) result = result shr 1
        print(result)
    }
}