package com.test

fun main(args: Array<String>) {
    val result = decrease(512,4)
    println(result)
}

fun decrease(number: Int, times: Int): Int {
    var numberStr = number.toString()
    var lastChar = numberStr.takeLast(1)
    var lastCharAsNumber = lastChar.toInt()
    var newNumber = number
    for(j in 1..times) {
        if(lastCharAsNumber!=0) {
            newNumber = newNumber-1;
        }
        else {
            newNumber = newNumber/10;
        }

        numberStr = newNumber.toString()
        lastChar = numberStr.takeLast(1)
        lastCharAsNumber = lastChar.toInt()
    }
    return newNumber
}


object Main {

    @JvmStatic
    fun main(args: Array<String>) {
        val a = readLine()!!.split(" ").map{ it.toInt() }.toMutableList()
        for (i in 1..a[1]) {
            if (a[0] % 10 == 0) {
                a[0] /= 10
            } else {
                a[0]--
            }
        }
    }
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<k;i++)
    {
        if(n%10)
        {
            n--;
        }
        else
        {
            n=n/10;
        }
    }
    cout<<n;
}


fun main(args: Array)
{
    var n: Int =Integer.valueOf(readLine())
    var k: Int =Integer.valueOf(readLine())

    for(i in 1..k)
    {
        var rem = n % 10
        n = if(rem == 0) {
            n = n / 10
        } else {
            n = n - 1
        }
    }
    println(n)

}


package Codeforces

fun main(args: Array<String>){
    var (n , k) = readLine()!!.split(' ').map{it.toInt()}
    while(k-->0){
        if(n%10 == 0 ){
            n /=10
        }
        else n-=1
    }
    println(n)
}


fun main(args: Array<String>) {
    var n = Long.valueOf(readLine())
    var k = Integer.valueOf(readLine())
    while(k>0)
    {
        var lastDigit = n % 10
        if(lastDigit > k)
        {
            n = n - k
            k = 0
        }
        else
        {
            n = (n / 10)*10
            k = k - lastDigit
        }
        if(n % 10 == 0 && k > 0)
        {
            k--;
            n = n / 10
        }
    }
}


fun main(args: Array<String>) {
    var (n,k) = readLine()!!.split(' ').toInt()
    println(n+k)
}


package kotlinheroes.episode2.practice.a

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

typealias TanyaInt = Int

data class Operators(val minuend: Int, val subtrahend: Int)

fun TanyaInt.decrement(): Int =
    if (this % 10 == 0) {
        this / 10
    } else {
        this - 1
    }

infix fun TanyaInt.subtract(subtrahend: Int): Int =
    (1..subtrahend).fold(this) { acc, _ ->
        acc.decrement()
    }

fun List<String>.minuend(): Int = this.first().toInt()
fun List<String>.subtrahend(): Int = this.last().toInt()

fun readInput(): Operators {
    val inputStreamReader = InputStreamReader(System.`in`)
    val bufferedReader = BufferedReader(inputStreamReader)

    val inputLine = bufferedReader.readLine()
    val input = inputLine.split(" ")

    return Operators(
        minuend = input.minuend(),
        subtrahend = input.subtrahend()
    )
}

fun main() {

    val (minuend, subtrahend) = readInput()

    val result = minuend subtract subtrahend

    print(result)

}


val line = readLine()
val strs = line.split(' ')
var num = strs[0].toInt()
var count = strs[1].toInt()

while(count != 0) {
    --count
    val lastDigit = num % 10
    if(lastDigit == 0) {
        num /= 10
    } else {
        --num
    }
}

return num


import java.util.Scanner

fun main(args: Array<String>) {

    val reader = Scanner(System.`in`)

    var x:Int = reader.nextInt()
    var k:Int = reader.nextInt()

    for (var i in 0 until k)
    {
        var mod = x % 10
        if(mod == 0)
        {
            x/=10;
        }
        else x--
    }
        println(x)

}


package com.example.kotlinheroes

import kotlin.math.max

fun main(args: Array<String>) {
    if(args.size != 2) return

    var number = args[0].toInt()
    val subtractions = args[1].toInt()

    for (i in 1..subtractions) {
        number = number.wrongSubtraction()
    }

    println(max(0, number))
}

private fun Int.wrongSubtraction(): Int =
        if (this % 10 == 0) this / 10 else this - 1


fun main(args: Array<String>) {
    val line = readLine()
    val strs = line.split(' ')
    var num = strs[0]!!.toInt()
    var count = strs[1]!!.toInt()

    while(count != 0) {
        --count
        val lastDigit = num % 10
        if(lastDigit == 0) {
            num /= 10
        } else {
            --num
        }
    }

    println(num)
}


    package com.my.stuff

    class programkt {
        companion object {
            @JvmStatic fun main(args: Array<String>) {
                while (true) {
                    print("  Enter text: ")
                    print(run(readLine()!!))
                }
            }
            fun parseInts(input: String) = input.split(" ").map{it->it.toInt()}
            fun run(input: String):Int {
                val pars = parseInts(input)
                var numb = pars[0] // input validation goes somewhere else
                val iter = pars[1]
                for (i in 1..iter) numb =  if (numb%10==0) numb/10 else numb-1
                return numb
            }
        }
    }


    fun main(args: Array<String>) {
        var (a, j) = readLine()!!.split(' ').map(String::toInt)
        for (i in 1..j)
        {
            if (a%10 == 0)
                n /= 10
            else
                a--
        }

        println(a)
    }


package drigor.multipart

import java.util.*

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`, "UTF-8")
    var n = scanner.nextInt()
    var k = scanner.nextInt()

    while (k > 0) {
        val last = n % 10
        if (last == 0) {
            n /= 10
            k--
        } else {
            n -= last
            k -= last
        }
    }
    println(n)
}


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

//production code
fun subtractOne(value: Int): Int {
    if (value.rem(10) == 0) {
        return value / 10
    } else {
        return value - 1
    }
}

val (n, k) = readInts()

var answer = n
for (idx in 1..k) {
    answer = subtractOne(answer)
}
println(answer) //50


#include <iostream>
using namespace std;

int main()
{
    int n,k,i;
    cin>>n>>k;
    while(k--){
        if(n%10==0)
            n/=10;
        else
            n--;
    }
    cout<<n<<endl;
    return 0;
}


fun main() {
    var (n, k) = readInts()
    for (i in 1..k) {
        if (n % 10 == 0 && n > 9) {
            n /= 10
        } else {
            n -= 1
        }
    }
    println(n)
}


fun main() {
    var (a, b) = readLine()!!.split(' ')
    var (n = a.toInt(), k = b.toInt())
    for (i in 1..k) {
        if (n % 10 == 0) {
            n /= 10
        } else {
            n--
        }
    }
    println(n)
}


package heroes2.practice

fun main() {
    var (n, k) = readLine()!!.split(" ").map(String::toInt)

    for (i in 1..k) {
        n = substract(n)
    }

    println(n)
}

fun substract(n: Int): Int = if (n % 10 == 0) {
    n / 10
} else {
    n - 1
}


package foo

import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    var n = scanner.nextInt()
    val k = scanner.nextInt()

    for (i in 0 until k) {
        if (n % 10 == 0) {
            n /= 10
        } else {
            n -= 1
        }
    }

    print(n)
}


package kotlinheroes

fun Int.lastChar(): Int  {
    return this.toString().last().toInt()-48
}

fun substruct(num: Int): Int {
    return when {
        num.lastChar() > 0 -> num-1
        else -> num/10
    }
}

fun substructMultiple(num: Int, div: Int) : Int  {
    var current = num
    for (count in 1..div)   {
        current = substruct(current)
    }

    return current
}

fun main()  {
    val num = readLine()
    val div = readLine()

    require(num != null && div != null)

    print(substructMultiple(num.toInt(), div.toInt()))
}


package app

fun main(args: Array<String>) {
    println(Decreasing().decrease(args[0].toInt(), args[1].toInt()))
}

class Decreasing {

    fun decrease(source: Int, times: Int): Int {
        var result = source
        1.rangeTo(times).map {
            result = decreaseWithRules(result)
        }
        return result
    }

    private fun decreaseWithRules(number: Int) =
            when(lastDigit(number)) {
                0 -> number / 10
                else -> number - 1
            }

    private fun lastDigit(number: Int) = number % 10
}


#include<iostream>
using namespace std;
int main(){
	int n,k;
	cin>>n>>k;
	for(int i=1;i<=k;i++){
		if(n%10)n--;
		else n/=10;
	}
	cout<<n;
}


fun main(arguments: Array<String>){
    val inputs = readLine().split(" ");
    val number = Integer.parseInt(inputs[0]);
    val count = Integer.parseInt(inputs[1]);

    while(count > 0){
        if(number % 10 == 0){
            number = number / 10;
        } else {
            number = number - 1;
        }

        count = count - 1;
    }

    println(number);
}


package com.example.kotlinheroes

import kotlin.math.max

class ProblemA {
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            require(args.size == 2)

            var number = args[0].toInt()
            val subtractions = args[1].toInt()

            for (i in 1..subtractions) {
                number = number.wrongSubtraction()
            }

            println(max(0, number))
        }
    }
}

private fun Int.wrongSubtraction(): Int =
        if (this % 10 == 0) this / 10 else this - 1


fun main(args: Array<String>) {
	var n = readLine()!!.toInt()
	var A = readLine()!!.split(' ').map(String::toInt)
	if (A.containsKey(1) == true){
		println("HARD")
	}
	else{
		println("EASY")
	}

}


package practice2.a

import java.util.stream.IntStream

class WrongSubtraction {

    fun subtract(_number: Int, times: Int): Int {
        var number = _number

        for (i in 0 until times) {
            if (number % 10 == 0)
                number /= 10
            else
                number--
        }

        return number
    }

}

fun main(args: Array<String>) {
    val wrongSubtraction = WrongSubtraction()
    println(wrongSubtraction.subtract(args[0].toInt(), args[1].toInt()))
}


fun main(args: Array<String>){
    val n = nextInt()
    val k = nextInt()
    println(50);
}


#include<stdio.h>

int main()

{
    int i,n,k;

    scanf("%d ",&n);

    scanf("%d",&k);
for(i=0;i<k;i++)
{

    if(n%10==0)
    {
        n=n/10;
    }
    else
    {

        n--;
    }
}
printf("%d",n);

   return 0;
}


package codeforces

import java.io.BufferedReader
import java.io.BufferedWriter
import java.io.FileReader
import java.io.FileWriter
import java.io.InputStreamReader
import java.io.OutputStreamWriter
import java.io.PrintWriter
import java.util.*

fun solve() {
    //your solution
    var n = nextInt()
    val k = nextInt()

    for (i in 1..k) {
        if (n % 10 != 0) {
            n--
        } else {
            n /= 10
        }
    }

    output.println(n)
}

fun hasNext() : Boolean {
    while (!st.hasMoreTokens()) {
        st = StringTokenizer(input.readLine() ?: return false)
    }
    return true
}

fun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException("No tokens")

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

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

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

fun nextLine() = if (hasNext()) st.nextToken("\n")!! else throw RuntimeException("No tokens")

fun nextArray(n : Int) = IntArray(n, { nextInt() })

val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null

var input = when(ONLINE_JUDGE) {
    true -> BufferedReader(InputStreamReader(System.`in`), 32768)
    else -> BufferedReader(FileReader("in.txt"))
}

var output = when(ONLINE_JUDGE) {
    true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))
    else -> PrintWriter(BufferedWriter(FileWriter("out.txt")))
}

var st = StringTokenizer("")

fun main(args: Array<String>) {
    val start = System.currentTimeMillis()
    solve()

    output.close()
    input.close()

    if (!ONLINE_JUDGE) {
        System.err.println("${System.currentTimeMillis() - start} ms")
    }
}


package test

import java.util.Scanner

object WrongSubtraction {
    @JvmStatic
    fun main(args: Array<String>) {
        val sc = Scanner(System.`in`)
        var n = sc.nextInt()
        var k = sc.nextInt()
        while (k-- > 0) {
            if (n % 10 > 0)
                n--
            else
                n /= 10
        }
        println(n)
    }
}


    fun main(arguments: Array<String>){
        val input : String? = readLine();
        val inputs = input.split(" ");
        val number = Integer.parseInt(inputs[0]);
        val count = Integer.parseInt(inputs[1]);

        while(count > 0){
            if(number % 10 == 0){
                number = number / 10;
            } else {
                number = number - 1;
            }

            count = count - 1;
        }

        println(number);
    }


fun main(args: Array<String>) {
    var n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    for (i in [1,k]) {
    	if( n % 10 ==  0) n = n / 10
        else n = n-1
    }
        println(n)
}


fun main(args: Array<String>) {

    val input = Scanner(System.`in`)
    val n = input.nextLine()
    val k = input.nextLine()

    var nextNumberToSubstract = n.toInt()

    for (i in 1..k.toInt()) {
        nextNumberToSubstract = if (nextNumberToSubstract % 10 == 0) nextNumberToSubstract/10 else nextNumberToSubstract - 1
        println(nextNumberToSubstract)
    }
}


import java.util.*

fun substract(numberToSubstract: Int, steps: Int): Int {
    var nextNumber = numberToSubstract

    for (i in 1..steps) {
        nextNumber = if (nextNumber % 10 == 0) nextNumber/10 else nextNumber-1
    }
    return nextNumber
}

fun main(args: Array<String>) {
    var substracts = substracts(512, 4)
    println substracts
}


fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val k = readLine()!!.toInt()
    for (i in 1 until k) {
    	if( n % 10 != 0) n = n-1
        else n = n % 10
    }
        println(n)
}


import java.util.Scanner

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

    var num:Int = scan.nextInt()
    var k:Int = scan.nextInt()

    println("Read val=$val k=$k)
    for( i in 1..k) {
     	if ( num % 10 > 0 ) {
            num = num - 1
        } else {
            num = num / 10
        }
    }
    println(num)
}


#include <iostream>
using namespace std;

int main() {
	long long n;
	cin>>n;
	long long k;
	cin>>k;
	for(int i=0;i<k;i++){
		if(n%10 == 0) n/=10;
		else n-=1;
	}
	cout<<n<<endl;
	// your code goes here
	return 0;
}


import java.io.OutputStream
import java.io.IOException
import java.io.InputStream
import java.io.PrintWriter
import java.util.InputMismatchException

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author prakhar17252
 */
object Main {
    fun main(args: Array<String>) {
        val inputStream = System.`in`
        val outputStream = System.out
        val `in` = InputReader(inputStream)
        val out = PrintWriter(outputStream)
        val solver = AWrongSubtraction()
        solver.solve(1, `in`, out)
        out.close()
    }

    internal class AWrongSubtraction {
        fun solve(testNumber: Int, `in`: InputReader, out: PrintWriter) {
            var n = `in`.nextInt()
            var k = `in`.nextInt()

            while (k-- > 0) {
                if (n % 10 == 0) {
                    n /= 10
                } else {
                    --n
                }
            }
            out.println(n)
        }

    }

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

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

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

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

        fun isSpaceChar(c: Int): Boolean {
            return filter?.isSpaceChar(c) ?: isWhitespace(c)
        }

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

        }

        companion object {

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

    }
}


fun main() {
    var (n, k) = readLine()!!.split(' ')
    // n = n.toInt()
    // k = k.toInt()

    while (k>0) {
        if (n%10 == 0) {
            n = (n/10).toInt()
        }
        else {
            n -= 1
        }
        k--
    }
    println(n)
}


package app

fun main(args: Array<String>) {
    println(args)
    println(Decreasing().decrease(args[0].toInt(), args[1].toInt()))
}

class Decreasing {

    fun decrease(source: Int, times: Int): Int {
        var result = source
        1.rangeTo(times).map {
            result = decreaseWithRules(result)
        }
        return result
    }

    private fun decreaseWithRules(number: Int) =
            when(lastDigit(number)) {
                0 -> number / 10
                else -> number - 1
            }

    private fun lastDigit(number: Int) = number % 10
}


val readIn = readLine() ?: throw RuntimeException("Expected a line from readIn, got null")
val (n, k) = readIn.split(" ").map { it.toInt() }
var tmp = n
repeat(k) {
    if (tmp % 10 == 0)
        tmp -= 1
    else
        tmp /= 10
}
return tmp


package cp

object April1120 {
fun april1120(){
    var(a,b) = readLine()!!.split(" ").map{it.toInt()}
    for(i in 1..b){
       if(a % 10 == 0){
           a /= 10
       }else{
           a -= 1
       }
    }
    println(a)
}
}


fun main() {
    var (n: Int, k: Int) = readLine()!!.split(' ')
    for (i in 0..k) {
        if (n % 10 == 0) {
            n /= 10
        } else {
            n--
        }
    }
    println(n)
}


package com.test

fun main() {
    val number = readLine()!!.toInt()
    val times = readLine()!!.toInt()
    val result = decrease(number, times)
    println(result)
}

fun decrease(number: Int, times: Int): Int {
    var lastChar = number.toString().takeLast(1)
    var lastCharAsNumber = lastChar.toInt()
    var newNumber = number

    for(j in 1..times) {
        if(lastCharAsNumber!=0) {
            newNumber= newNumber-1;
        }
        else {
           newNumber=newNumber/10;
        }

        lastChar = newNumber.toString().takeLast(1)
        lastCharAsNumber = lastChar.toInt()
    }
    return newNumber
}


import java.util.*;
import java.io.*;
import java.text.*;
public class Main{
    //SOLUTION BEGIN
    //Into the Hardware Mode
    void pre() throws Exception{}
    void solve(int TC)throws Exception{
        long n = nl(), k = nl();
        for(int i=0;i<k;i++)
        {
            if(n%10==0)
                n = n/10;
            else
                n--;
        }
        pn(n);
    }
    //SOLUTION END
    void hold(boolean b)throws Exception{if(!b)throw new Exception("Hold right there, Sparky!");}
    void exit(boolean b){if(!b)System.exit(0);}
    long IINF = (long)1e18, mod = (long)1e9+7;
    final int INF = (int)1e9, MX = (int)2e6+5;
    DecimalFormat df = new DecimalFormat("0.00000000");
    double PI = 3.141592653589793238462643383279502884197169399, eps = 1e-6;
    static boolean multipleTC = false, memory = false, fileIO = false;
    FastReader in;PrintWriter out;
    void run() throws Exception{
        if(fileIO){
            in = new FastReader("input.txt");
            out = new PrintWriter("output.txt");
        }else {
            in = new FastReader();
            out = new PrintWriter(System.out);
        }
        //Solution Credits: Taranpreet Singh
        int T = (multipleTC)?ni():1;
        pre();
        for(int t = 1; t<= T; t++)solve(t);
        out.flush();
        out.close();
    }
    public static void main(String[] args) throws Exception{
        if(memory)new Thread(null, new Runnable() {public void run(){try{new Main().run();}catch(Exception e){e.printStackTrace();}}}, "1", 1 << 28).start();
        else new Main().run();
    }

    int digit(long s){int ans = 0;while(s>0){s/=10;ans++;}return ans;}
    long gcd(long a, long b){return (b==0)?a:gcd(b,a%b);}
    int gcd(int a, int b){return (b==0)?a:gcd(b,a%b);}
    int bit(long n){return (n==0)?0:(1+bit(n&(n-1)));}
    void p(Object o){out.print(o);}
    void pn(Object o){out.println(o);}
    void pni(Object o){out.println(o);out.flush();}
    String n()throws Exception{return in.next();}
    String nln()throws Exception{return in.nextLine();}
    int ni()throws Exception{return Integer.parseInt(in.next());}
    long nl()throws Exception{return Long.parseLong(in.next());}
    double nd()throws Exception{return Double.parseDouble(in.next());}

    class FastReader{
        BufferedReader br;
        StringTokenizer st;
        public FastReader(){
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastReader(String s) throws Exception{
            br = new BufferedReader(new FileReader(s));
        }

        String next() throws Exception{
            while (st == null || !st.hasMoreElements()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (IOException  e){
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        String nextLine() throws Exception{
            String str = "";
            try{
                str = br.readLine();
            }catch (IOException e){
                throw new Exception(e.toString());
            }
            return str;
        }
    }
}


package foo

import java.util.*

fun main() {
    val scanner = Scanner(System.`in`)
    var n = scanner.nextInt()
    val k = scanner.nextInt()

    for (i in 0 until k) {
        if (n.lastDigitIsZero()) {
            n /= 10
        } else {
            n -= 1
        }
    }

    print(n)
}

private fun Int.lastDigitIsZero(): Boolean {
    return this.lastDigit() == 0
}

private fun Int.lastDigit(): Int {
    return this % 10
}


fun main(args: Array<String>) {
    val n = Long.valueOf(readLine())
    val k = Integer.valueOf(readLine())
    while(k>0)
    {
        val lastDigit = n % 10
        if(lastDigit > k)
        {
            n = n - k
            k = 0
        }
        else
        {
            n = (n / 10)*10
            k = k - lastDigit
        }
        if(n % 10 == 0 && k > 0)
        {
            k--;
            n = n / 10
        }
    }
}


import java.util.ArrayList
import java.util.Comparator
import java.util.HashSet
import java.util.Scanner
object Main {
  @JvmStatic fun main(args:Array<String>) {
    var `in` = Scanner(System.`in`)
    var n = `in`.nextInt()
    var k = `in`.nextInt()
    for (i in 0 until k)
    {
      if (n % 10 == 0)
      n /= 10
      else
      n--
    }
    println(n)
  }
}


import java.util.Scanner

object WrongSubtraction {
    @JvmStatic
    fun main(args: Array<String>) {
        val sc = Scanner(System.`in`)
        var n = sc.nextInt()
        var k = sc.nextInt()
        while (k-- > 0) {
            if (n % 10 > 0)
                n--
            else
                n /= 10
        }
        println(n)
    }
}


import java.util.Scanner
fun main(args: Array<String>) {
    val read = Scanner(System.`in`)

    var n = read.nextInt()
    var k = read.nextInt()
    for(var i=0;i<k;i++){
    	if(n%10 == 0) n/=10
    	else n-=1
    }
    println(n)
}


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

object TaskA {
    @JvmStatic
    fun main(args: Array<String>) {
        var n: Int
        val k: Int
        val br = BufferedReader(InputStreamReader(System.`in`))
        val zer = StringTokenizer(br.readLine())
        n = Integer.parseInt(zer.nextToken())
        k = Integer.parseInt(zer.nextToken())
        for (i in 0 until k) {
            if (n % 10 == 0) {
                n /= 10
            } else {
                n--
            }
        }
        println(n)
    }
}


fun main() {
    var n, k: Int
    (n, k) = readLine()!!.split(' ')
    for (i in 0..k) {
        if (n % 10 == 0) {
            n /= 10
        } else {
            n--
        }
    }
    println(n)
}


fun main() {
    var (n, k) = readLine()!!.split(' ')
    n = n.toInt()
    k = k.toInt()

    while (k>0) {
        if (n%10 == 0) {
            n = (n/10).toInt()
        }
        else {
            n -= 1
        }
        k--
    }
    println(n)
}


package KoKoKotlin
import java.util.ArrayList
import java.util.Comparator
import java.util.HashSet
import java.util.Scanner
object Main {
  @JvmStatic fun main(args:Array<String>) {
    var `in` = Scanner(System.`in`)
    var n = `in`.nextInt()
    var k = `in`.nextInt()
    for (i in 0 until k)
    {
      if (n % 10 == 0)
      n /= 10
      else
      n--
    }
    println(n)
  }
}


package codes

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

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

fun solve(scanner: Scanner) {
    val num = scanner.nextInt()

    if (num % 2 == 0) {
        print(0)
    } else {
        print(1)
    }
}

class Scanner(`in`: InputStream) {
    val reader: BufferedReader = BufferedReader(InputStreamReader(`in`), 32768)
    var tokenizer: StringTokenizer = StringTokenizer("")

    fun next(): String {
        while (!tokenizer.hasMoreTokens()) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer.nextToken()
    }

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


package codes

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

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

fun solve(scanner: Scanner) {
    val num = scanner.nextInt()

    if (num % 2 == 0) {
        print(0)
    } else {
        print(1)
    }
}

class Scanner(`in`: InputStream) {
    val reader: BufferedReader = BufferedReader(InputStreamReader(`in`), 32768)
    var tokenizer: StringTokenizer = StringTokenizer("")

    fun next(): String {
        while (tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = StringTokenizer(reader.readLine())
        }
        return tokenizer.nextToken()
    }

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


fun main() {
    val n = readLine()!!.toInt()
    val x = BigInteger("2").pow(n).minus(BigInteger("1"))
    val b = BigInteger(readLine()!!.map { if (it == 'R') '1' else '0' }.joinToString(""), 2)
    val ans = x.minus(b)
    println(ans.toString())
}


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

class Solver : SolverBase() {

    fun solve() {
        for (i in 1..4) {
            val a = readIntArray(4)
            if (a[3] == 1 && a.sum() > 1) {
                print("YES")
                return
            }
        }
        print("NO")
    }

}

object Algorithms {

    tailrec fun gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
    tailrec fun gcd(a: Long, b: Long): Long = if (b == 0L) a else gcd(b, a % b)

    fun lcm(a: Int, b: Int): Int = a / gcd(a, b) * b
    fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

}

open class SolverBase {
    private val bufferedReader: BufferedReader = System.`in`.bufferedReader()
    private var stringTokenizer: StringTokenizer = StringTokenizer("")

    fun nextLine(): String = bufferedReader.readLine()
    fun next(): String {
        while (!stringTokenizer.hasMoreTokens())
            stringTokenizer = StringTokenizer(nextLine())
        return stringTokenizer.nextToken()
    }

    fun readInt(): Int = next().toInt()
    fun readLong(): Long = next().toLong()
    fun readDouble(): Double = next().toDouble()

    fun readIntArray(size: Int): IntArray = IntArray(size, { readInt() })
    fun readLongArray(size: Int): LongArray = LongArray(size, { readLong() })
    fun readStringArray(size: Int): Array<String> = Array(size, { next() })
    inline fun <reified T> readTArray(size: Int, convert: (Int, String) -> T): Array<T> = Array(size, { convert(it, next()) })
    inline fun <reified T> readTArray(size: Int, convert: (String) -> T): Array<T> = Array(size, { convert(next()) })
}

fun main(args: Array<String>) {
    val millis = measureTimeMillis(Solver()::solve)
    System.err.println("Time spent: $millis")
}


fun f(x: Int): Int {
    var y = x + 1
    while (y.rem(10) == 0) {
        y = y.div(10)
    }
    return y
}

fun reachableNums(n: Int): Int {
    val results: MutableSet<Int> = mutableSetOf()
    var m = n
    while (!results.contains(m)) {
        results.add(m)
        m = f(m)
    }
//    println(results)x
    return results.size
}
val a = readLine()!!.toInt()
println(reachableNums(a))


fun f(x:Int):Int
{
	var ss = x + 1
	while(ss % 10 == 0)
		ss /= 10
	return ss
}

fun main(args:Array<String>)
{
	var t = readLine()!!.toInt()
	var hs = HashSet<Int>()
	var cnt = 0
	while(hs.add(x))
	{
		x = f(x)
		cnt++
	}
	println(cnt);
}


package contest555

/**
 * Reachable numbers
 *
 * http://codeforces.com/contest/1157/problem/A
 */

fun reachableNumbers(n: Int, f: (Int) -> Int): List<Int> {
    tailrec fun reachableNumbersAcc(n: Int, f: (Int) -> Int, acc: List<Int>): List<Int> {
        if (f(n) in acc) return acc
        val m = f(n)
        return reachableNumbersAcc(m, f, acc + listOf(m))
    }
    return reachableNumbersAcc(n, f, listOf(n)).sorted()
}

/**
 * apply addition of 1 to n.
 * as long as the result is divisible to 10, keep dividing by 10
 */
val f: (Int) -> Int = { n -> f(n) }

fun f(n: Int): Int =
        removeTrailingZero(n + 1)

tailrec fun removeTrailingZero(n: Int): Int =
        if ((n % 10) != 0) n else removeTrailingZero(n / 10)


import java.util.*
import kotlin.collections.HashSet

public fun f(n : Int): Int {
    var x = n + 1
    while (x % 10 == 0) x /= 10
    return x
}
public fun main() {
    var n = readLine()!!.toInt()
    val st = HashSet<Int>()
    while (st.add(n))
        n = f(n)


/**
 * You can edit, run, and share this code.
 * play.kotlinlang.org
 */
fun toDo(n:Int):Int{
    var value1 = n
    var s = n.toString()
    var counter = 1
    var arrayList = ArrayList<Int>()
    while(true){
        value1 = value1 + 1
        s = value1.toString()
        while (s[s.length-1]=='0') {
        	s = s.substring(0,s.length-1)
            value1 = s.toInt()
        }
        if (value1 in arrayList){
            break
        }
        else{
            arrayList.add(value1)
            counter+=1
        }
    }
    return counter
}

fun main() {
    var n = readLine()!1.toInt()
    print(toDo(n))
}


fun main(args: Array<String>) {

    var inputNum = readLine()!!.toInt()

    val resultList = ArrayList<Int>()
    resultList.add(inputNum)

    while(true) {
        inputNum += 1
        inputNum = reachableNumbers(inputNum)
        if (inputNum in resultList) break
        else resultList.add(inputNum)
    }

    println(resultList.size)
}

fun reachableNumbers(inputNumber: Int): Int {
    if (inputNumber % 10 == 0) reachableNumbers(inputNumber/10)
    else inputNumber
}


fun f(x: Int): Int = generateSequence(x + 1) { y -> y / 10 }
.dropWhile{ y -> y % 10 == 0 && y!= 0}
.first()

fun ff(x: Int) = generateSequence(x, ::f)

fun r(x: Int) = ff(x)
  .takeWhile(HashSet<Int>()::add)
  .count()

fun main() {

    println(r(readInt()));

}


fun f(x : int): int {
    var cur = x+1
    while (cur % 10 == 0)
    {cur/=10}
return cur }


fun f(x: Int): Int {
    var y = x + 1
    while (y.rem(10) == 0) {
        y = y.div(10)
    }
    return y
}

fun reachableNums(n: Int): Int {
    val results: MutableSet<Int> = mutableSetOf()
    var m = n
    while (!results.contains(m)) {
        results.add(m)
        m = f(m)
    }
//    println(results)x
    return results.size
}
val a = input()
print(reachableNums(a))


fun f(x: Int) {
    var cur = x + 1
    while(cur % 10 == 0) cur /= 10
    return cur
}

fun main() {
    var n = readLine()!!.toInt()
    val reached = HashSet<Int>()
    while (reached.add(n)) n = f(n)
    println(reached.size)
}


package com.rakeshpillai.kotlin

fun main() {
    val num = readLine()!!.toInt()
    val output = getReachableNumberCount(num)
    println(output)
}

fun getReachableNumberCount(num: Int): Int {
    var count = 1
    var nextReachableNum = num

    while (nextReachableNum != 1) {
        nextReachableNum = nextReachableNumber(nextReachableNum)
        count++
    }

    return count
}

fun nextReachableNumber(num: Int): Int {
    var nextNum = num + 1
    while (nextNum % 10 == 0) {
        nextNum = nextNum / 10
    }

    return nextNum
}


fun main(args: Array<String>) {
    val (x) = readLine()!!.map(String::toInt)
    println(x)
}


package contest555

import org.junit.Assert.assertEquals
import org.junit.Test

/**
 * Reachable numbers
 *
 * http://codeforces.com/contest/1157/problem/A
 */
class A {

    fun reachableNumbers(n: Int, f: (Int) -> Int): List<Int> {
        tailrec fun reachableNumbersAcc(n: Int, f: (Int) -> Int, acc: List<Int>): List<Int> {
            if (f(n) in acc) return acc
            val m = f(n)
            return reachableNumbersAcc(m, f, acc + listOf(m))
        }
        return reachableNumbersAcc(n, f, listOf(n)).sorted()
    }

    /**
     * apply addition of 1 to n.
     * as long as the result is divisible to 10, keep dividing by 10
     */
    val f: (Int) -> Int = { n -> f(n) }

    fun f(n: Int): Int =
            removeTrailingZero(n + 1)

    tailrec fun removeTrailingZero(n: Int): Int =
            if ((n % 10) != 0) n else removeTrailingZero(n / 10)

    @Test
    fun removeTrailingZeroTest() {
        assertEquals(1, removeTrailingZero(1))
        assertEquals(1, removeTrailingZero(10))
        assertEquals(1, removeTrailingZero(100))
    }

    @Test
    fun addOneAndRemoveTrailingZerosTest() {
        assertEquals(1, f(99))
        assertEquals(101, f(100))
    }

    @Test
    fun reachableNumbersTest() {
        assertEquals(
                listOf(1, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 1098, 1099),
                reachableNumbers(1098, f))
    }

    @Test
    fun reachableNumbersCountTest() {
        assertEquals(20, reachableNumbers(1098, f).size)
        assertEquals(19, reachableNumbers(10, f).size)
    }

}


  1 import java.util.Scanner
  2
  3 fun main() {
  4         val reader = Scanner(System.`in`)
  5         var x =reader.nextInt()
  6         var cnt = 0
  7         while(x>9)
  8         {
  9                 x+=1
 10                 while(x%10==0)
 11                         x/=10
 12                 cnt+=1
 13         }
 14         println(cnt+9)
 15 }


#include <bits/stdc++.h>

using namespace std;

int removeZeroes(int x) {
  return x % 10 == 0 ? removeZeroes(x / 10) : x;
}

int f(int x) {
  return removeZeroes(x + 1);
}

int main() {
  int n;
  while (scanf("%d", &n) != EOF) {
    unordered_set<int> reached;
    while (reached.insert(n).second) {
      n = f(n);
    }
    printf("%d\n", reached.size());
  }
  return 0;
}


 fun main(args: Array<String>) {

    var inputNum = readLine()!!.toInt()

    val resultSet = mutableSetOf(inputNum)

    while(true) {
        inputNum += 1
        inputNum = reachableNumbers(inputNum)
        resultSet.add(inputNum)
        if(inputNum == 1) break
    }

    return resultSet.size
}

fun reachableNumbers(inputNumber: Int): Int {
    if (inputNumber % 10 == 0) return reachableNumbers(inputNumber/10)
    else return inputNumber
}


fun main(args: String) {

    // converting the parameter to an int
    var inputNum = args[0].toInt()

    // declaring the result list
    val resultList = ArrayList<Int>()

    while(true) {
        inputNum += 1
        resultList.add(reachableNumbers(inputNum))
        if(inputNum == 1) break
    }

    val result = resultList.size

    println(result)
}

fun reachableNumbers(inputNumber: Int): Int {
    if (inputNumber % 10 == 0) reachableNumbers(inputNumber/10)
    else inputNumber
}


tailrec fun removeZeroesRecursion(number: Int): Int =
    if (number % 10 == 0) removeZeroesRecursion(number / 10) else number

fun removeZeroesByRecursion(x: Int) = removeZeroesRecursion(x + 1)

fun removeZeroes(number: Int): Int {
    var cur = number + 1
    while (cur % 10 == 0) cur /= 10
    return cur
}

fun main() {
    var n = readLine()!!.toInt()
    var reached = HashSet<Int>()
    // while (reached.add(n)) n = removeZeroes(n)
    while (reached.add(n)) n = removeZeroesByRecursion(n)
    println(reached.size)
}

// val number = 3232199
// println(removeZeroesByRecursion(number))
// println(removeZeroes(number))

main()


package com.dishan.example.solutions

private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int

fun f(x: Int): Int {
    var cur = x + 1
    while ( cur % 10 == 0)
        cur /= 10
    return cur
}

fun reachableCount(n: Int): Int {
    var x = n
    val reached = HashSet<Int>()
    while (reached.add(x))
        x = f(x)
    return reached.size
}

fun main() {
    val n = readInt()
    val count = reachableCount(n)
    println(count)
}


fun main() {
    var n = readLine()!!.toInt() // read integer from the input
    val reached = HashSet<Int>() // a mutable hash set
    while (reached.add(n)) n = f(n) // iterate function f
    println(reached.size) // print answer to the output
}


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

fun main(args: Array<String>) {
	val `in` = InputReader(System.`in`)
	val out = PrintWriter(System.out)
	val n = `in`.nextInt()
	val m = `in`.nextInt()
	val k = `in`.nextInt()
	val a = LongArray(n)
	for (i in 0 until n) {
		a[i] = `in`.nextInt().toLong()
	}
	val b = LongArray(m)
	for (i in 0 until m) {
		b[i] = `in`.nextInt().toLong()
	}
	val c = Array(n) { IntArray(m) }
	for (i in 0 until n) {
		for (j in 0 until m) {
			c[i][j] = `in`.nextInt()
		}
	}
	c[0][0] += k
	val open = PriorityQueue(n * m, Collections.reverseOrder<Int>())
	var sum: Long = 0
	var row = 0
	while (row < n && a[row] <= sum) {
		++row
	}
	var col = 0
	while (col < m && b[col] <= sum) {
		for (i in 0 until row) {
			open.offer(c[i][col])
		}
		++col
	}
	var ans = 0
	while (row < n || col < m) {
		sum += open.poll()
		++ans
		while (row < n && a[row] <= sum) {
			for (i in 0 until col) {
				open.offer(c[row][i])
			}
			++row
		}
		while (col < m && b[col] <= sum) {
			for (i in 0 until row) {
				open.offer(c[i][col])
			}
			++col
		}
	}
	out.println(ans)
	out.close()
}

internal class Pair(var a: Int, var b: Int) : Comparable<Pair?> {
	override operator fun compareTo(oth: Pair): Int {
		return if (a == oth.a) {
			b - oth.b
		} else a - oth.a
	}

}

internal class InputReader(str: InputStream?) {
	var reader: BufferedReader
	var tokenizer: StringTokenizer? = null
	operator fun next(): String {
		while (tokenizer == null || !tokenizer!!.hasMoreTokens()) {
			tokenizer = try {
				StringTokenizer(reader.readLine())
			} catch (e: IOException) {
				throw RuntimeException(e)
			}
		}
		return tokenizer!!.nextToken()
	}

	fun nextInt(): Int {
		return next().toInt()
	}

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

	init {
		reader = BufferedReader(InputStreamReader(str), 1 shl 15)
	}
}


package kotlinheroes

import java.lang.Long.min
import java.util.*
import kotlin.math.max

@JvmField val INPUT = System.`in`
@JvmField val OUTPUT = System.out
@JvmField val _reader = INPUT.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!
@JvmField var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
  while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
  return _tokenizer.nextToken()
}
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() }

fun divRoundUp(num : Long, denom: Long) : Long {
  return (num + denom - 1)/denom
}

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

fun main() {
  val n = readInt()
  val m = readInt()
  val k = readInt()

  val a = LongArray(n)
  val b = LongArray(m)

  for (i in 0 until n) a[i] = readLong()
  for (i in 0 until m) b[i] = readLong()

  // sorted unlock thresholds
  val events = (a + b).distinct().sorted()

  // unlock threshold -> index of events
  val eventIndicesMap = hashMapOf<Long, Int>()
  for (i in events.indices) {
    eventIndicesMap[events[i]] = i
  }

  // max points among characters unlocked at event i
  val mxPointsPerEvent = LongArray(events.size)

  for (i in 0 until n) {
    for (j in 0 until m) {
      val cij = readLong()
      val mxab = max(a[i], b[j])
      val eventInd = eventIndicesMap[mxab]
      mxPointsPerEvent[eventInd!!] = max(mxPointsPerEvent[eventInd], cij)
    }
  }

  myAssert(events[0] == 0L)

  val evaluate : (Int) -> Long = { guideIndex ->
    mxPointsPerEvent[guideIndex] = mxPointsPerEvent[guideIndex] + k

    var round = 0L
    var score = 0L
    var bestOption = mxPointsPerEvent[0]
    var nextEventIndex = 1

    while (nextEventIndex < mxPointsPerEvent.size) {
      val nextThreshold = events[nextEventIndex]
      val diff = nextThreshold - score
      if (diff > 0) {
        round += divRoundUp(diff, bestOption)
        score = divRoundUp(diff, bestOption) * bestOption
      }
      bestOption = max(bestOption, mxPointsPerEvent[nextEventIndex++])
    }
    mxPointsPerEvent[guideIndex] = mxPointsPerEvent[guideIndex] - k
    round
  }

  var mn = Long.MAX_VALUE
  for (i in mxPointsPerEvent.indices) {
    mn = min(mn, evaluate(i))
  }
  println(mn)
}


class Main {

    private fun readLn() = readLine()!!
    private fun readStrings() = readLn().split(" ") // list of strings
    private fun readInts() = readStrings().map { it.toInt() }

    fun main(args: Array<String>): Int {
        val yellow = readLn().toInt()
        val blue = readLn().toInt()
        val  red = readLn().toInt()

        if (yellow < blue){
            if(blue < red){
                //yellow < blue < red
                println(yellow*3+3)
            }else{
                //yellow < blue >= red
                println(red*3-2)
            }
        }else{
            //blue <= yellow
            if(blue < red){
                //blue < red && blue < yellow
                println(blue*3)
            }else{
                //red <= blue && blue <= yellow
                println(red*3 - 2)
            }
        }

        return 0
    }

}


import java.util.*
object cf {
  @JvmStatic fun main(args:Array<String>) {
    val s = Scanner(System.`in`)
    val a:Long
    val b:Long
    val i:Long
    val j:Long
    val c:Long
    a = s.nextLong()
    b = s.nextLong()
    c = s.nextLong()
    i = Math.min(b, Math.min(a + 1, c - 1))
    System.out.println(3 * x)
  }
}


fun main(args: Array <String>){
    val (x, y, z) = readLine()!!.split(' ').map(String::toInt)
    while (x > y - 1 || x > z - 2){
        x = x - 1
    }
    println(3 * x + 3)
}


import kotlin.math.min

val rgb = readLine()!!.split(' ').map(String::toInt).take(3)
    println(min(min(rgb[0], rgb[1] - 1), rgb[2] - 2))


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

fun main(){
    var y : Int = 0
    var b : Int = 0
    var r : Int = 0

    (y b r) = readInts()

    var ans : Int = 0

    if( y+1 <= b && y+2 <= r && 3*y+3 > ans ) ans = 3*y+3

    if( b-1 <= y && b+1 <= r && 3*b > ans ) ans = 3*b

    if( r-2 <= y && r-1 <= b && 3*r-3 > ans ) ans = 3*r-3

    println("$ans")

}


import java.io.File
import kotlin.test.todo

class MyReader(fileName: String) {
    val file = File(fileName)

    val contents : List<String>?

    init {
        contents = try {
            file.readLines()
        } catch (e : Throwable) {
            null
        }
    }

    val line : String
    get() {
        return if (contents != null) {
            contents[pointer++]
        } else {
            readLine()!!
        }
    }

    var pointer = 0
}

var reader : MyReader = MyReader("src/input.txt")

fun getLine() = reader.line
fun readInt() = getLine().toInt()
fun readInts() = getLine().split(" ").map { it.toInt() }

fun RE() : Nothing {
    throw RuntimeException()
}

fun main() {
    val (y, b, r) = readInts()
    val ans = when {
        b >= r-1 && y >= r-2 -> 3*r - 3
        r >= b + 1 && y >= b - 1 -> b*3
        b >= y + 1 && r >= y + 2 -> 3*y + 3
        else -> RE()
    }
    println(ans)
}


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

fun main(){
    var y : Int = 0
    var b : Int = 0
    var r : Int = 0

    val(y, b, r) = readInts()

    var ans : Int = 0

    if( y+1 <= b && y+2 <= r && 3*y+3 > ans ) ans = 3*y+3

    if( b-1 <= y && b+1 <= r && 3*b > ans ) ans = 3*b

    if( r-2 <= y && r-1 <= b && 3*r-3 > ans ) ans = 3*r-3

    println("$ans")

}


import java.util.*;
fun main()
{
  var sc = Scanner(System.`in`)
  var y:Int = sc.nextInt()
  var b:Int = sc.nextInt()
  var r:Int = sc.nextInt()
  y += 2
  b += 1
  var lol:Int = maxOf(y: Int, b: Int, r:Int)
  if ( lol < 2)
  println("0")
  else
  println("${lol*3 - 3} ")

}


fun main()
{
    val nn = readLine()!!.split(" ").map { it.toInt() }
    val mini = 999
    for (i in 0..2)
    {
        val m = nn[i]
        if (m - i < mini) mini = m - i
    }
    mini += 1
    println(mini * 3)
}


import java.util.Scanner

fun main(args: Array<String>) {
   	var s = 6
    val input = Scanner(System.`in`)
    val A=input.nextInt()
    val B=input.nextInt()
    val B=input.nextInt()
    for (i in 2..999){
        if(I <= A && I + 1 <= B && I + 2 <= C)
        	s = s+3
        else break
    }
    println(score)
}
/*import java.util.Scanner

fun main(args: Array<String>) {
   	var score = 6
    val input = Scanner(System.`in`)
    val a = input.nextInt()
    val b = input.nextInt()
    val c = input.nextInt()
    for (i in 2..999){
        if(i <= a && i+1 <= b && i+2 <= c)
        	score = score+3
        else break
    }
    println(score)
}*/


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

fun main() {
  var (y,b,r) = readInts();
  println(max(y,max(b-1,r-2))*3+3)
}


import java.util.Scanner

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readLong() = readLn().toLong()
fun readBigInt(radix: Int = 10) = readLn().toBigInteger(radix)
fun readBigDecimal() = readLn().toBigDecimal()
fun readLinesSeq(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.take(limit)
fun readStrings(delim: Char = ' ') = readLn().split(delim)
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }

fun readIntArray() = readInts().toIntArray()
fun readLnIntArray(n: Int) = IntArray(n) { readInt() }
fun readLongArray() = readLongs().toLongArray()
fun readLnLongArray(n: Int) = LongArray(n) { readLong() }

fun main(){
	val (x, y, z) = readLine()!!.split(" ").map { it.toInt() }
    while (x > y - 1 || x > z - 2){
        x = x - 1
    }
    println(3 * x + 3)
}


data class Ornament(val ornament: Int, val offset: Int) {
    fun get() = ornament - offset
}

// red > blue > yellow exactly 1 is great christmas ornament
class ChristmasOrnament : ProblemSolver() {
    var totalRed: Int = 0
    var totalBlue: Int = 0
    var totalYellow: Int = 0

    override fun input() {
        val args = mutableListOf<Ornament>()
        val ornaments = readLine()!!.split(" ").map { it.toInt() }
        totalYellow = ornaments[0]
        totalBlue = ornaments[1]
        totalRed = ornaments[2]
        args.add(Ornament(totalRed, 0))
        args.add(Ornament(totalRed, 1))
        args.add(Ornament(totalRed, 2))
        output(args)
    }

    override fun output(args: List<Any>) {
        val ornaments = args.map { it as Ornament }
        val christmasOrnaments = decrease(ornaments[0], ornaments[1], ornaments[2])
        val totalOrnaments = christmasOrnaments.reduce { acc, i -> acc + i }
        println(totalOrnaments)
    }

    private fun decrease(red: Ornament, blue: Ornament, yellow: Ornament): List<Int> {
        return if (blue.get() < totalBlue && yellow.get() < totalYellow) listOf(red.get(), blue.get(), yellow.get())
        else decrease(
            Ornament(red.get() - 1, offset = 0),
            Ornament(blue.get() - 1, offset = 1),
            Ornament(yellow.get() - 1, offset = 2)
        )
    }
}

fun main() {
    ChristmasOrnament().input()
}


import java.lang.Math.min
import java.util.Scanner

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

    var y = reader.nextInt()
    var b = reader.nextInt()
    var r = reader.nextInt()
    var ans = min(y,b-1)
    ans = min(r-28 1,ans)
    ans = ans*3 + 3;8
    println(ans)

}


fun main() {
    val (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    println(3 * min(min(b, y + 1), r - 1))
}


fun main() {
    var (y, b, r) = readLine()!!.split(' ').map(String::toInt)
    println("${3 * minOf(y, minOf(b, r))}")
    }
}


import javax.swing.text.MutableAttributeSet

class Main {

    companion object {
        @JvmStatic
        fun main(args: Array<String>) {

            var inputList =readLine()!!.split(" ").toList()

            var beginList = mutableListOf(1, 2, 3)
            while (true) {

                if (beginList.count { b -> inputList.count { b <= it.toString().toInt() } == 3} != 3)
                    break
                else
                    beginList.replaceAll { it + 1 }

            }
//            beginList.replaceAll { it - 1 }
            println(beginList.sum())

        }
    }
}


package higherOrderFunKotlin

import java.util.Scanner

    fun main(args: Array<String>) {

        val sc = Scanner(System.`in`)

        val y = sc.nextInt()
        val b = sc.nextInt() - 1
        val r = sc.nextInt() - 2

        val result = Math.min(Math.min(y, b), r) * 3 + 3

        println(result)
    }


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

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    var y:Int = scanner.nextInt()
    var b:Int = scanner.nextInt()
    var r:Int = scanner.nextInt()
    y-=1;b-=2;r-=3
    //var ans:Int=min(y,b);
    //ans=min(ans,r);
    //println("$y $b $r")
    //println(ans);
    var ans=minOf(y,b,r);
    println(3*ans+6);
}


package koitlin_heroes_practice

fun main() {
    val (y, b, r) = readLine()!!.split(" ").map { it.toInt() }
    val min = minOf(y, b, r)
    if (min == r) {
        println(3 * r - 3)
        return
    }

    if (min == b) {
        println(3 * (b))
        return
    }

    if (min == y) {
        if (r > b) {
            println((3 * y) + 3)
        } else {
            println(y + 2 * r - 2)
        }
    }
}


fun main() {
    val input = Scanner(System.`in`).nextLine().split(" ").map { Integer.parseInt(it) }.toList()

    fun isValid(yellow: Int, blue: Int, red: Int): Boolean {
        return yellow <= input[0] && blue <= input[1] && red <= input[2] && yellow == blue + blue - red
    }

    var yellow = input[0]
    var blue = yellow + 1
    var red = blue + 1

    while (!isValid(yellow, blue, red)) {
        yellow--
        blue--
        red--
    }

    print(yellow + blue + red)
}


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

fun main(){
    var y : Int
    var b : Int
    var r : Int

    (y, b, r) = readInts()

    var ans : Int = 0

    if( y+1 <= b && y+2 <= r && 3*y+3 > ans ) ans = 3*y+3

    if( b-1 <= y && b+1 <= r && 3*b > ans ) ans = 3*b

    if( r-2 <= y && r-1 <= b && 3*r-3 > ans ) ans = 3*r-3

    println("$ans")

}


fun getMin(a, b, c)
{
    if (a <= b && a <= c) return a
    if (b <= c) return b
    return c
}

fun main()
{
    val nn = readLine()!!.split(" ").map { it.toInt() }
    val mini = getMin(nn[0], nn[1] - 1, nn[2] - 2) + 1
    println(mini * 3)
}


class ChristmasOrnament {
    var totalRed: Int = 0
    var totalBlue: Int = 0
    var totalYellow: Int = 0

    fun input() {
        val args = mutableListOf<Ornament>()
        val ornaments = readLine()!!.split(" ").map { it.toInt() }
        totalYellow = ornaments[0]
        totalBlue = ornaments[1]
        totalRed = ornaments[2]
        args.add(Ornament(totalRed, 0))
        args.add(Ornament(totalRed, 1))
        args.add(Ornament(totalRed, 2))
        output(args)
    }

    fun output(args: List<Any>) {
        val ornaments = args.map { it as Ornament }
        val christmasOrnaments = decrease(ornaments[0], ornaments[1], ornaments[2])
        val totalOrnaments = christmasOrnaments.reduce { acc, i -> acc + i }
        println(totalOrnaments)
    }

    private fun decrease(red: Ornament, blue: Ornament, yellow: Ornament): List<Int> {
        return if (blue.get() < totalBlue && yellow.get() < totalYellow) listOf(red.get(), blue.get(), yellow.get())
        else decrease(
            Ornament(red.get() - 1, offset = 0),
            Ornament(blue.get() - 1, offset = 1),
            Ornament(yellow.get() - 1, offset = 2)
        )
    }
}

fun main() {
    ChristmasOrnament().input()
}


import java.util.Scanner

fun readLn() = readLine()!!
fun readInt() = readLn().toInt()
fun readLong() = readLn().toLong()
fun readBigInt(radix: Int = 10) = readLn().toBigInteger(radix)
fun readBigDecimal() = readLn().toBigDecimal()
fun readLinesSeq(limit: Int = Int.MAX_VALUE) = generateSequence { readLine() }.take(limit)
fun readStrings(delim: Char = ' ') = readLn().split(delim)
fun readInts() = readStrings().map { it.toInt() }
fun readLongs() = readStrings().map { it.toLong() }

fun readIntArray() = readInts().toIntArray()
fun readLnIntArray(n: Int) = IntArray(n) { readInt() }
fun readLongArray() = readLongs().toLongArray()
fun readLnLongArray(n: Int) = LongArray(n) { readLong() }

fun main(args: Array <String>){
//    val (x, y) = readLine()!!.split(' ').map(String::toInt)
//    val x = Scanner(System.`in`)
//    val y = Scanner(System.`in`)
	val (x, y, z) = readInts()
    while (x > y - 1 || x > z - 2){
        --x
    }
    println(3 * x + 3)
}


#include <bits/stdc++.h>
#define ll long long
#define S second
#define F first
#define pii pair<ll, ll>
#define pb push_back
#define pob pop_back

using namespace std;

int main()
{
    ios::sync_with_stdio(false), cin.tie(), cout.tie();

    int y, b, r;
    cin >> y >> b >> r;
    if(r > b && b > y)
        cout << y * 3 + 3;
    else if(r > b && b <= y)
        cout << b * 3;
    else if (r <= b && r <= y)
        cout << r * 3 - 3;
    else if(r <= b && r > y + 1)
        cout << y * 3 + 3;
    else if(r <= b && r == y + 1)
        cout << y - 1 + y + 1 + y;

    return 0;
}


import kotlin.io.*

fun main() {
    var temp = readLine()

    val tokens = temp.split(" ")
    var list = mutableListOf<Int>()
    for (token in tokens) {
        list.add(token.toInt())
    }
    val min = list.min()
    var total = 0
    when {
        list[2] == min -> total = list[2] + (list[2]-1) + (list[2]-2)
        list[1] == min -> total = list[1] + (list[1]-1) + (list[1]+1)
        else -> total = list[0] + (list[0]+1) + (list[0]+2)
    }
    println(total)
}


package com.example.circleprogressbar

import java.lang.Math.min

fun main(args : Array<String>) {
    val (y,b,r) = readInts()
    var c = min(min(y +2, b + 1), r)
    println(c*3-3)
}
private fun readLn() = readLine()!! // string line
private fun readInt() = readLn().toInt() // single int
private fun readStrings() = readLn().split(" ") // list of strings
private fun readInts() = readStrings().map { it.toInt() } // list of ints


fun main() {
    val s = readLine()
    val s2 = s.split(' ')
    var yellows = s2[0].toInt()
    var blues = s2[1].toInt()
    var reds = s2[2].toInt()

    if (yellows >= blues) {
        yellows -= (yellows - blues) + 1
    }
    if (blues != yellows + 1) {
        blues = yellows + 1
    }
    if (blues >= reds) {
        blues -= (blues - reds) + 1
        yellows -= (blues - reds) + 2
    }
    if (reds != blues + 1) {
        reds = blues + 1
    }
    print(yellows + blues + reds)
}


fun  main( args :  Array<String>) {

    val str= readLine()!!
    val str = "13 3 6"
    val ar = str.split(" ")
    val y = ar[0].toInt()
    val b = ar[1].toInt()
    val r = ar[2].toInt()
    val n = minOf(y + 1, b, r - 1)
    println(n*3)


fun main() {
        val br = Scanner(System.`in`)
        val a = br.nextInt()
        val b = br.nextInt()
        val c = br.nextInt()
        for (i in c downTo 3) {
            if (a >= i - 2 && b >= i - 1) {
                println(i + (i - 1) + (i - 2))
                break
            }
        }
    }


#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>

#define all(x) (x.begin(), x.end())
#define sor(x) sort(all(x))
#define rev(x) reverse(all(x))
#define pb push_back
#define pp pop_back
#define sqr(x) (x) * (x)
#define F first
#define S second
#define N 222222
#define INF 1000000021
#define MOD 1000000007
#define Z size()
#define I insert
#define M(a, b) make_pair(a,b)
#define T(a, b, c) make_pair(a, make_pair(b, c))
#define forn(x) for (int i = 1; i <= n; i ++)

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <ll> vll;
typedef set <int> sl;
//typedef tree<int, null_type, less<int>, rb_tree_tag,tree_order_statistics_node_update> indexed_set;

//int yil[13] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	cout << min(a, min(b - 1, c - 2)) * 3 + 3;

	getchar();
	getchar();
	return 0;
}


import kotlin.io.*

fun main() {
    var temp = readLine()

    val tokens = temp!!.split(" ")
    var min = "";
    if (tokens[0] <= tokens[1] && tokens[1] <= tokens[2]) {
        min = tokens[0]
    } else if (tokens[1] <= tokens[0] && tokens[0] <= tokens[2]) {
        min = tokens[1]
    } else {
        min = tokens[2]
    }

    /*
    var list = mutableListOf<Int>()
    for (token in tokens) {
        list.add(token.toInt())
    }
    val min = list.min()
    */
    var total = 0
    when {
        tokens[2] == min -> total = tokens[2].toInt() + (tokens[2].toInt()-1) + (tokens[2].toInt()-2)
        tokens[1] == min -> total = tokens[1].toInt() + (tokens[1].toInt()-1) + (tokens[1].toInt()+1)
        tokens[0] + 2 > tokens[2].toInt() -> total = (tokens[0].toInt()-1) + tokens[0].toInt() + (tokens[0].toInt()+1)
        else -> total = tokens[0].toInt() + (tokens[0].toInt()+1) + (tokens[0].toInt()+2)
    }
    println(total)
}


fun main() {
    val reader = BufferedReader(InputStreamReader(System.`in`))
    val readString = reader.readLine().split(" ")
    val y = readString[0].toInt()
    val b = readString[1].toInt()
    val r = readString[2].toInt()
    println(getMaxOrnaments(y, b, r))
}

fun getMaxOrnaments(y: Int, b: Int, r: Int): Int {
    val input = arrayOf(y, b - 1, r - 2)
    val x = input[input.indices.minBy { input[it] }!!]
    return 3 * x + 3
}


fun main(args: Array<String>) = with(Scanner(System.`in`)) {
    val y = nextInt()
    val b = nextInt()
    val r = nextInt()
    println(getMaxOrnaments(y, b, r))
}

fun getMaxOrnaments(y: Int, b: Int, r: Int): Int {
    val input = arrayOf(y, b - 1, r - 2)
    val x = input[input.indices.minBy { input[it] }!!]
    return 3 * x + 3
}


import kotlin.io.*

fun main() {
    var temp = readLine()

    val tokens = temp!!.split(" ")
    var min = 0;
    if (tokens[0] <= tokens[1] && tokens[1] <= tokens[2]) {
        min = tokens[0].toInt()
    } else if (tokens[1] <= tokens[0] && tokens[0] <= tokens[2]) {
        min = tokens[1].toInt()
    } else {
        min = tokens[2].toInt()
    }

    /*
    var list = mutableListOf<Int>()
    for (token in tokens) {
        list.add(token.toInt())
    }
    val min = list.min()
    */
    var total = 0
    when {
        list[2] == min -> total = list[2] + (list[2]-1) + (list[2]-2)
        list[1] == min -> total = list[1] + (list[1]-1) + (list[1]+1)
        list[0] + 2 > list[2] -> total = (list[0]-1) + list[0] + (list[0]+1)
        else -> total = list[0] + (list[0]+1) + (list[0]+2)
    }
    println(total)
}


val rgb = readLine()!!.split(' ').map(String::toInt).take(3)
println(min(min(rgb[0], rgb[1] - 1), rgb[2] - 2))


fun main(args: Array <string>){
    val (x, y, z) = readLine()!!.split(' ').map(String::toInt)
    while (x > y - 1 || x > z - 2){
        x--
    }
    println(3 * x + 3)
}


fun main() {
    val (y, b, r) = readLine()?.split(" ").map { it.toInt() }

    val base = listOf(y - 2, b - 1, r).min()!!

    val result = base * 3 - 3

    println(result)
}


fun readInts() = readStrings().map { it.toInt() } // list of ints

fun main() {

    val (a,b,c) = readInts()
    println((6 + 3*minOf(a,b-1,c-2)))
}


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

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

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

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

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

    println(result.max())
}


package codeforce

fun main(args: Array<String>) {
    val n = args.component1().toInt()
    val p = args.component2().toInt()
    val k = args.component3().toInt()
    val items = mutableListOf<String>()
    if (p - k > 1)
        items.add("<<")
    val start = if (p - k > 0) p - k else 1
    val end = if (n - p > k) p + k else n
    for (i in start..end) {
        if (i == p)
            items.add("($i)")
        else
            items.add("$i")
    }
    if (n - p > k)
        items.add(">>")
    print(items.joinToString(separator = " "))
}


package codeforce

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


package codeforce

fun main(arg: ArrayList<String>) {
    val problem399 = Problem399()
    problem399.solve(arg)
}

open class Problem399 {
    fun solve(arg: ArrayList<String>) {
        val n = arg.component1().toInt()
        val p = arg.component2().toInt()
        val k = arg.component3().toInt()
        val items = mutableListOf<String>()
        if (p - k > 1)
            items.add("<<")
        val start = if (p - k > 0) p - k else 1
        val end = if (n - p > k) p + k else n
        for (i in start..end) {
            if (i == p)
                items.add("($i)")
            else
                items.add("$i")
        }
        if (n - p > k)
            items.add(">>")
        print(items.joinToString(separator = " "))
    }
}


package codeforce

fun main(args: Array<String>) {
    val n = args[0].toInt()
    val p = args[1].toInt()
    val k = args[2].toInt()
    val items = mutableListOf<String>()
    if (p - k > 1)
        items.add("<<")
    val start = if (p - k > 0) p - k else 1
    val end = if (n - p > k) p + k else n
    for (i in start..end) {
        if (i == p)
            items.add("($i)")
        else
            items.add("$i")
    }
    if (n - p > k)
        items.add(">>")
    print(items.joinToString(separator = " "))
}


import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.stream.IntStream;
import java.io.PrintStream;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskA solver = new TaskA();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskA {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            String s = in.next().toLowerCase().replaceAll("[aoyeui]", "");
            s.chars().forEach(c -> System.out.print("." + (char) c));
        }

    }
}


fun main() {
    val x = readLine()!!.toLowerCase()
    println(x.replaceAll("[aoyeui]+".toRegex(), "."))
}


fun main()
    val x = readLine()!!.toLowerCase()
    println(x.replaceAll("[aoyeui]+".toRegex(), "."))
}


class Main {
    companion object {
        @JvmStatic
        fun main(args: Array<String>) {
            val vowels = "aAoOyYeEuUiI"
            val str = readLine()!!
            var newStr = ""
            for (c: Char in str) {
                if (!(c in vowels)) {
                    newStr += "." + c.toLowerCase()
                }
            }
            println(newStr)
        }
    }
}


var x = readLine()
    x = x!!.toLowerCase()
    var a : String = ""
    for (c in x)
    {
        if (c!='o' && c!='i' && c!='u'&&c!='e'&&c!='y' && c!='a')
        {
            a+=".$c"
        }
    }
    println(a)


import java.util.Scanner

fun main() {

    val x: Int = nextInt()
    if (x % 5 == 0) {

        println((x/5))
    } else {

        println((x/5)+1)
    }

}


package codeforces

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

fun main() {
    val In = BufferedReader(InputStreamReader(System.`in`))
    val name = In.readLine()!!.toSet()
    if(name.size % 2 ==0)
        println("IGNORE HIM!")
    else
        println("CHAT WITH HER!")
}


fun main(args: Array<String>) {
    val sol = Solution()
    if(sol.checkGender(readLine().toString())) {
        println("CHAT WITH HER!")
    }
    else {
        println("IGNORE HIM!")
    }
}

fun checkGender(hello:String):Boolean {
        val map: HashMap<Char, Int> = HashMap()
        for(c in hello){
            if(!map.containsKey(c)){
                map[c] = 1
            }
        }
        return map.size%2==0
    }


fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val m = scanner.nextInt()
    val a = mutableListOf<Int>()
    while (scanner.hasNextInt()) {
        a.add(scanner.nextInt())
    }

    a.sortByDescending { it }
    val firstValue = a[0] + m
    for (i in 0 until m) {
        a.sortBy { it }
        a[0]++
    }
    print(a[0])
    print(" ")
    print(firstValue)
}


import java.util.Scanner

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var n = scan.nextLong()
    var m = scan.nextLong()
    var a = scan.nextLong()
    var b = scan.nextLong()
    if (n%m==0) print(0)
    else {
        val p=(n+m-1)/m
        if ((n-(m*(p-1)))*b<(m*p-n)*a) print ((n-(m*(p-1)))*b)
        else print ((m*p-n)*a)
    }
}


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

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

    var build = 0
    var decrease = 0
    var buildDiff = 0
    var decreaseDiff = 0

    while ((n + buildDiff) % m != 0){
        buildDiff++
        build += a

    }

    while ((n - decreaseDiff) % m != 0){
        decreaseDiff++
        decrease += b
    }

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


package cf435

import java.util.*

fun main(args: Array<String>) {
    val tokenizer = StringTokenizer(readLine())
    val n = tokenizer.nextToken().toInt()
    val x = tokenizer.nextToken().toInt()
    val arrayTokenizer = StringTokenizer(readLine())
    var steps = x
    generateSequence { arrayTokenizer.takeIf { it.hasMoreTokens() }?.nextToken()?.toInt() }.forEach {
        if (it < x) {
            steps--
        } else if (it == x) {
            steps++
        }
    }
    println(steps)
}


fun main() {
	val input = readLine()!!.split(' ')
	val n = input[0]
	val k = input[1]

	var r = 0

	for (i in 0 until k) {
		val a = readLine()!!.toInt()
		if (a >= k) r++
		else break
	}

	println(r)
}


package olimpiad.codeforce

fun main(){
    val (a, b) = readLine()!!.split(' ').map { it.toInt() }
    val arr = readLine()!!.split(' ').map { it.toInt() }

    if (arr[b]>0){
        var f = false
        for (i in b until a){
            if (arr[i]<arr[b-1]){
                f = true
                println(i)
                break
            }
        }
        if (!f) println(a)
    }else{
        var f = false
        for (i in b-1 downTo 0){
            if (arr[i]>0){
                println(i+1)
                f=true
                break
            }
        }
        if (!f) println(0)
    }

}


fun main() {
	val input = readLine()!!.split(' ')
	val a = readLine()!!.split(' ')

	val n = input[0].toInt()
	val k = input[1].toInt()

	var r = 0

	for (i in 0 until k) {
		if (a[i] >= k) r++
		else break
	}

	println(r)
}


#include <bits/stdc++.h>

using namespace std;

typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<string> vs;

template<typename T1, typename T2>
pair<T1, T2> operator+(pair<T1, T2> a, pair<T1, T2> b) {
    return make_pair(a.first + b.first, a.second + b.second);
}

template<typename T1, typename T2>
pair<T1, T2> operator-(pair<T1, T2> a, pair<T1, T2> b) {
    return make_pair(a.first - b.first, a.second - b.second);
}

template<typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> p) {
    out << p.first << " " << p.second;
    return out;
}

template<typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& p) {
    in >> p.first >> p.second;
    return in;
}

template<typename T>
ostream& operator<<(ostream& out, vector<T> v) {
    for (auto a: v)
        out << a << " ";

    return out;
}

template<typename T>
istream& operator>>(istream& in, vector<T>& v) {
    for (auto &a: v)
        in >> a;

    return in;
}

template<typename T>
ostream& operator<<(ostream& out, multiset<T> S) {
    for (auto a: S)
        out << a << " ";

    return out;
}

template<typename T>
ostream& operator<<(ostream& out, set<T> S) {
    for (auto a: S)
        out << a << " ";

    return out;
}

template<typename T>
ostream& operator<<(ostream& out, unordered_set<T> S) {
    for (auto a: S)
        out << a << " ";

    return out;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& out, map<T1,T2>& M) {
    for (auto m: M)
        out << "[" << m.first << "]=" << m.second << " " ;

    return out;
}

int main() {
    ios::sync_with_stdio(false);
    int n, k;
    vi v;
    cin >> n >> k;
    v.resize(n);
    cin >> v;
    sort(v.begin(), v.end());
    int val = max(v[n-1-k], 1);
    auto first = lower_bound(v.begin(), v.end(), val);
    cout << distance(first, v.end()) << endl;
    return 0;
}


val line = readLine() ?: ""
    val ints = line.split(" ").map { it.toInt() }
    val k = ints[0]
    val n = ints[1]
    val scores = (readLine() ?: "").split(" ").map { it.toInt() }.sorted().reversed()
    var last = 1
    var min = scores[n-last]
    while (min ==0 && n - last > 0){
        last+=1
        min = scores[n-last]
    }
    if(min!=0) println(scores.lastIndexOf(min)+1)
    else println(0)


import java.util.*

class  Solution {
    fun main(args : Array<String>){
        var input = Scanner(System.`in`)
        var n = input.nextInt()
        var k = input.nextInt()
        var sum =0;
        input.nextLine()
        var arrayInput = input.nextLine()
        var results = arrayInput.split(" ").map { it.toInt() }.let { values ->
            sum =values.filter { it >= values[k-1] && values[k-1] > 0 }.size
        }
        System.out.println("${sum}")

    }
}


fun main() {
    val r = System.`in`.bufferedReader()
    val s1 = StringBuilder()
    val (n, k) = r.readLine()!!.split(" ").map { it.toInt() }
    val v2 = List(n) {
        val a = r.readInt()
        Pair(a, it)
    }.sortedBy { it.first }
    //val v1 = r.readLine()!!.split(" ").map { it.toInt() }.sorted()
    val v = v2.map { it.first }.toIntArray()
    (1..n - 1).forEach { v[it] += v[it - 1] }
    fun f(intArray: IntArray, x: Int): Int {
        var le = 0
        var ri = intArray.size
        while (le < ri) {
            val mi = le + (ri - le) / 2
            when {
                intArray[mi] <= x -> le = mi + 1
                intArray[mi] > x -> ri = mi
            }
        }
        return le - 1
    }

    val i = f(v, k)
    println(i + 1)
    println(v2.subList(0, i + 1).map { it.second+1 }.joinToString(" "))
    //val n = r.readLine()!!.toInt()
}


package A

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

fun solve() {

    val n = nextInt()
    val k = nextInt()
    val array = nextArray(n)

    val ans = ArrayList<Int>()
    val s = mutableSetOf<Int>()
    var count = 0
    for ((index, a) in array.withIndex()) {
        if (!s.contains(a)) {
            s.add(a)
            ans.add(index+1)
            count++
        }
        if (count == k) {
            println("YES")
            println(ans.joinToString(separator = " "))
            return
        }
    }

    println("NO")
}

fun hasNext() : Boolean {
    while (!st.hasMoreTokens()) {
        st = StringTokenizer(input.readLine() ?: return false)
    }
    return true
}

fun next() = if (hasNext()) st.nextToken()!! else throw RuntimeException("No tokens")

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

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

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

fun nextLine() = if (hasNext()) st.nextToken("\n")!! else throw RuntimeException("No tokens")

fun nextArray(n : Int) = IntArray(n, { nextInt() })

val ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null

var input = when(ONLINE_JUDGE) {
    true -> BufferedReader(InputStreamReader(System.`in`), 32768)
    else -> BufferedReader(FileReader("in.txt"))
}

var output = when(ONLINE_JUDGE) {
    true -> PrintWriter(BufferedWriter(OutputStreamWriter(System.out)))
    else -> PrintWriter(BufferedWriter(FileWriter("out.txt")))
}

var st = StringTokenizer("")

fun main(args: Array<String>) {
    val start = System.currentTimeMillis()
    solve()

    output.close()
    input.close()

    if (!ONLINE_JUDGE) {
        System.err.println("${System.currentTimeMillis() - start} ms")
    }
}


package ru.ak.tochki

fun main(args: Array<String>){
	val string1: String = readLine().toString()
	var mnozh: List<Int> = readLine().toString().split(" ").map{x -> x.toInt()}
	val N = string1.split(" ")[0].toInt()
	val expD = string1.split(" ")[1].toInt()
	mnozh = mnozh.sorted()
	val D = mnozh.last() - mnozh.first()
	if (D <= expD){
		println(0)
	}else{
		//println("Expected: $expD, real: $D")
		var realD: Int = 101
		var minDropped = 101
		var dropped = 101
		for (i in 0..N-2){
			for (j in i+1..N-1){
				realD = mnozh[j]-mnozh[i]
				dropped = N - (j - i + 1)
				if((realD <= expD) and (dropped <= minDropped)){
					minDropped = dropped
					//println("i: $i, j: $j, Distance: $realD, dropped: $dropped")
				}
			}
		}
		println(minDropped)
	}
}


package ru.ak.cf940A

fun main(args: Array<String>){
	val string1: String = readLine().toString()
	var mnozh: List<Int> = readLine().toString().split(" ").map{x -> x.toInt()}
	val N = string1.split(" ")[0].toInt()
	val expD = string1.split(" ")[1].toInt()
	mnozh = mnozh.sorted()
	val D = mnozh.last() - mnozh.first()
	if (D <= expD){
		println(0)
	}else{
		//println("Expected: $expD, real: $D")
		var solution = listOf<Int>()
		var realD: Int = 101
		var minDropped = 101
		var dropped = 101
		for (i in 0..N-2){
			for (j in i+1..N-1){
				realD = mnozh[j]-mnozh[i]
				dropped = N - (j - i + 1)
				if((realD <= expD) and (dropped <= minDropped)){
					minDropped = dropped
					//println("i: $i, j: $j, Distance: $realD, dropped: $dropped")
				}
			}
		}
		println(minDropped)
	}
}


import kotlin.math.abs

class Main {
    fun main(): String {
        val (x, y, z) = readLine()!!.split(' ').map { it.toInt() }
        val xy = x - y

        return when {
            z >= abs(xy) -> "?"
            xy < 0 -> "-"
            xy > 0 ->"+"
            else -> "0"
        }
    }
}


fun main(args: Array<String>) {
    var ligne = readLine()!!.toString().split(" ")
    var x = Integer.parseInt(ligne.elementAt(0))
    var y = Integer.parseInt(ligne.elementAt(1))
    var z = Integer.parseInt(ligne.elementAt(2))
    var res =""

    if( x > y && abs(x-y) > z) res = "+"
    if( x < y  && abs(x-y) > z ) res= "-"
    if( x > y && abs(x-y) <= z) res = "?"
    if( x < y  && abs(x-y) <= z ) res= "?"
    if( x==y && z==0) res="0"
    if( x==y && z!=0) res="?"
    println("$res")
}


import com.sun.org.apache.xpath.internal.operations.Bool
import dfs
import dfs1
import java.util.*
import kotlin.collections.ArrayList
import kotlin.collections.HashMap
import kotlin.math.max
import kotlin.math.min
import java.io.IOException
import jdk.nashorn.internal.runtime.ScriptingFunctions.readLine
import java.util.StringTokenizer
import java.io.InputStreamReader
import java.io.BufferedReader
import java.io.InputStream
import kotlin.math.abs

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

fun solve() {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    var k1 = -2
    var k2 = -1
    val arr = IntArray(n / 2) { scanner.nextInt() - 1 }.sorted()
    print(min(arr.sumBy { k1 += 2; abs(it - k1) }, arr.sumBy { k2 += 2; abs(it - k2) }))
}

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

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


package greedy

// https://codeforces.com/problemset/problem/996/A

fun bills(n: Int) : Int {
    var remainder = n
    var bills = 0
    while (remainder > 0) {
        if (remainder >= 100) {
            remainder -= 100
            bills++
        } else if (remainder >= 20) {
            remainder -= 20
            bills++
        } else if (remainder >= 10) {
            remainder -= 10
            bills++
        } else if (remainder >= 5) {
            remainder -= 5
            bills++
        } else if (remainder >= 1) {
            remainder -= 1
            bills++
        }
    }
    return bills
}


package problem996

fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    println(numOfPapers(n))
}

fun numOfPapers(n: Int): Int {
    var papers = 0
    var remain = n
    val nominals = intArrayOf(100, 20, 10, 5 , 1)
    for (nominal in nominals) {
        papers += remain / nominal
        remain %= nominal
    }
    return papers
}


package greedy

// https://codeforces.com/problemset/problem/996/A

fun bills(n: Int) : Int {
    var remainder = n
    var bills = 0
    while (remainder > 0) {
        if (remainder >= 100) {
            remainder -= 100
            bills++
        } else if (remainder >= 20) {
            remainder -= 20
            bills++
        } else if (remainder >= 10) {
            remainder -= 10
            bills++
        } else if (remainder >= 5) {
            remainder -= 5
            bills++
        } else if (remainder >= 1) {
            remainder -= 1
            bills++
        }
    }
    return bills
}

fun main(args: Array<String>) {
    val amount = readLine()!!.toInt()
    println(bills(amount))
}


import java.io.*;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.nio.charset.IllegalCharsetNameException;
import java.util.*;

public class Main {

    static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static StringTokenizer st;
    static PrintWriter out = new PrintWriter(System.out);

    static String next() throws IOException {
        while (st == null || !st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }

    static int nextInt() throws IOException {
        return Integer.parseInt(next());
    }

    static long nextLong() throws IOException {
        return Long.parseLong(next());
    }

    static void solve() throws IOException {
        int n = nextInt(), m = nextInt(), k = nextInt();
        int a[] = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = nextInt();
        }
        Arrays.sort(a);
        long pr[] = new long[n + 1];
        for (int i= 0; i < n; i++) pr[i + 1] = pr[i] + a[i];
        long ans = pr[n];
        for (int i = 0; i + m - 1 < n; i++) {
            int l = i, r = i + m - 1;
            int mid = (l + r) / 2;
            long sum = (mid - l) * (long) a[mid] - (pr[mid] - pr[l]);
            if (sum <= k) {
                sum += (pr[r + 1] - pr[mid]) - (r + 1 - mid) * (long) a[mid];
                ans = Math.min(ans, sum);
            } else {
                int vl = l, vr = r;
                while (vl < vr - 1) {
                    int vm = (vl + vr) / 2;
                    long sm = (vm + 1 - l) * (long) a[vm] - (pr[vm + 1] - pr[l]);
                    if (sm <= k) {
                        vl = vm;
                    } else {
                        vr = vm;
                    }
                }
                long ret = (vl + 1 - l) * (long) a[vl] - (pr[vl + 1] - pr[l]);
                long val = a[vl];
                val += (k - ret) / (vl - l + 1);
                ret = (vl - l + 1) * val - (pr[vl + 1] - pr[l]);
                ret += (pr[r + 1] - pr[vl + 1]) - (r + 1 - (vl + 1)) * val;
                ans = Math.min(ans, ret);
            }
        }
        out.println(ans);
    }

    public static void main(String[] args) throws IOException {
        solve();
        out.close();
    }
}


import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.*
import java.util.Arrays.*
import kotlin.Comparator
import kotlin.collections.ArrayList
import kotlin.collections.HashSet
import kotlin.math.*

fun read() = readLine()!!
fun getStr() = read()
fun getInt() = read().toInt()
fun getInts() = read().splitToIntArray()
fun yes() = print("YES\n")
fun no() = print("NO\n")

fun main() {
    val (n, m, k) = getInts()
    var a = getInts().toMutableList()
    a.sort()
    var b = Array(n + 1) {0L}
    for (i in 1..n) {
        b[i] = b[i - 1] + a[i - 1]
    }
    var aa: Long = 1000L * 1000 * 1000 * 1000 * 1000 * 1000 * 8
    for (start in 0 until n - m + 1) {
        var l = a[start]
        var r = a[start + (m - 1) / 2] + 1
        var mid = 0
        while (r - l > 1) {
            mid = (r + l) / 2
            if (can(mid.toLong(), a, b, start, k, m)) {
                l = mid
            } else {
                r = mid
            }
        }
        aa = min(aa, ans(l.toLong(), a, b, start, k, m))
    }
    println(aa)
}

fun ans(x: Long, a: IntArray, b: Array<Long>, start: Int, k: Int, m: Int): Long {
    var i = a.binarySearch(x.toInt(), start)
    if (i < 0) {
        i = -i - 1
    }
    val have = b[i] - b[start]
    val need: Long = x * (i - start) - have
    return need + (b[start + m] - b[i]) - x * (start + m - i)
}

fun can(x: Long, a: IntArray, b: Array<Long>, start: Int, k: Int, m: Int): Boolean {
    var i = a.binarySearch(x.toInt(), start)
    if (i < 0) {
        i = -i - 1
    }
    val have = b[i] - b[start]
    val need = x * (i - start) - have
    return need <= k
}

private fun dfs(x: Int, g: MutableList<HashSet<Int>>, ans: MutableList<ArrayList<Int>>, used: MutableList<Boolean>, p: MutableList<Int>): Int {
    while(g[x].isNotEmpty()) {
        used[x] = true
        val to = g[x].first()
        if (used[to]) {
            ans.add(ArrayList())
            ans[ans.size - 1].add(to)
            ans[ans.size - 1].add(x)
            g[x].remove(to)
            g[to].remove(x)
            used[x] = false
            return to
        } else {
            g[x].remove(to)
            g[to].remove(x)
            val ret = dfs(to, g, ans, used, p)
            used[x] = false
            if (ret < 0) {
                return ret - 1
            }
            ans[ans.size - 1].add(x)
            used[x] = false
            if (ret != x)
                return ret
        }
    }
    used[x] = false
    return -1
}

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


import java.util.ArrayList
import java.util.Comparator
import java.util.Scanner

  fun main(args:Array<String>) {
    // TODO Auto-generated method stub
    val `in` = Scanner(System.`in`)
    val n = `in`.nextInt()
    val m = `in`.nextInt()
    val k = `in`.nextLong()
    val v = ArrayList<Int>()
    val pr = ArrayList<Long>()
    for (i in 0 until n)
    {
      val x = `in`.nextInt()
      v.add(x)
    }
    v.sort(object:Comparator<Int> {
      public override fun compare(a:Int, b:Int):Int {
        if (a < b) return -1
        if (a > b) return 1
        return 0
      }
    })
    var sm = 0.toLong()
    for (i in 0 until n)
    {
      sm += v.get(i).toLong()
      pr.add(sm)
    }
    var rez = 1e18.toLong()
    var it = 0
    var S:Long = 0
    var cnt:Long = 0
    for (st in 0 until n - m + 1)
    {
      var all = pr.get(st + m - 1)
      if (st != 0) all -= pr.get(st - 1)
      while (2 * cnt < m && it < n && v.get(it) * (cnt) - S <= k)
      {
        S += v.get(it).toLong()
        cnt++
        it++
      }
      var up:Long = 0
      if (2 * cnt < m)
      {
        up = (k - (v.get(it - 1) * cnt - S)) / cnt
      }
      val meet = Math.min(v.get(it - 1) + up, v.get(st + m / 2).toLong())
      rez = Math.min(rez, meet * cnt - S + (all - S) - (meet) * (m - cnt))
      S -= v.get(st).toLong()
      cnt--
    }
    println(rez)
  }


import java.lang.StringBuilder
import java.util.*

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

fun main() {
    val (n, m, k) = readInts()
    if(m == 1) {
        println("0")
        return;
    }
    var A = readLongs().sorted().toLongArray()
    var Pref = Array<Long>(A.size+1){0}
    for(x in 1..n) {
        Pref[x] = Pref[x-1]+A[x-1]
        //println(A[x-1])
    }
    var sum: Long = 0
    for(x in 0..m-1) {
        sum += A[x]
    }
    var lft = 0;
    var rgt = m;
    var ans: Long = Long.MAX_VALUE
    for(posun in 0..n-m) {
        if(posun > 0) {
            sum += A[m+posun-1]
            sum -= A[posun-1]
            lft++
            rgt++
        }
        var l1 = lft
        var r1 = rgt
        while(l1+1 < r1) {
            var mid = (l1+r1)/2
            if(A[mid]*(mid-lft)-(Pref[mid]-Pref[lft]) <= k) {
                l1 = mid;
            } else {
                r1 = mid;
            }
        }
        //println("start: $lft konec $rgt, max muzu vzit pozici $l1")
        var center = (lft+rgt+1)/2
        if(l1 < center) {
            var zvetseni = A[l1]*(l1-lft)-(Pref[l1]-Pref[lft]);
            var zmenseni = (Pref[rgt]-Pref[l1])-A[l1]*(rgt-l1);
            var rezerva1: Long = k-zvetseni;
            var needForOne: Long = (l1-lft.toLong())+1;
            var enlargements: Long = rezerva1/needForOne
            if(A[l1]+enlargements >= A[l1+1]) {
                throw Exception("WTF");
            }
            var cans = zvetseni+zmenseni
            ans = Math.min(ans, cans);
            cans -= enlargements*needForOne
            cans -= enlargements*(m-needForOne)
            ans = Math.min(ans, cans);
            if(cans == 99442292919397) {
                println("L1: center == $center, l1 = $l1, zvetseni = $zvetseni, zmenseni = $zmenseni, rezerva1 = $rezerva1, lft=$lft, needForOne=$needForOne")
                println("L1: A[$l1] = ${A[l1]}, A[${l1+1}] = ${A[$l1+1]}, enlargements = $enlargements")
            }
        } else {
            var zvetseni = A[center]*(center-lft)-(Pref[center]-Pref[lft]);
            var zmenseni = (Pref[rgt]-Pref[center])-A[center]*(rgt-center);
            //println("$zvetseni $zmenseni")
            ans = Math.min(ans, zvetseni+zmenseni);
            if(zvetseni+zmenseni == 99442292919397) {
                println("L1: center == $center")
            }
        }
    }

    println(Math.max(ans, 0))
}


import kotlin.test.assertTrue

fun lowerBound(x: Int, a: IntArray): Int {
    var left = 0
    var right = a.size
    while (left + 1 < right) {
        val ave = (left + right) / 2
        if (a[ave] < x) {
            left = ave
        } else {
            right = ave
        }
    }
    return right
}

fun main() {
    val (n, m, k) = readLine()!!.split(" ").map { it.toInt() }
    val a = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    a.sort()
    val b = LongArray(a.size + 1) { 0 }
    for (i in a.indices) {
        b[i + 1] = b[i] + a[i]
    }
//    println(a.toList())
    var res = Long.MAX_VALUE
    for (i in 0..(n - m)) {
        var left = a[i]
        var right = a[i + m - 1] + 1
        val t = a[i + m / 2]
//        println("t = $t")
        while (left + 1 < right) {
            val ave = (left + right) / 2
            val j = Math.max(Math.min(lowerBound(ave, a), i + m - 1), i)
            assertTrue(a[j] >= ave)
            val s = ave.toLong() * (j - i) - (b[j] - b[i])
//            println("ave = $ave s = $s j = $j")
//            println("b[j] - b[i] = ${b[j] - b[i]}")
            if (s <= k) {
                left = ave
            } else {
                right = ave
            }
        }
//        println("i = $i, left = $left")
        val ans = Math.min(t, left)
//        println("ans = $ans")
        var cur = 0.toLong()
        val j = Math.max(Math.min(lowerBound(ans, a), i + m), i)
        cur += ans.toLong() * (j - i) - (b[j] - b[i])
        cur += (b[i + m] - b[j]) - ans.toLong() * (i + m - j)
        res = Math.min(res, cur)
    }
    println(res)
}


import java.util.*
import kotlin.collections.HashMap

var scanner = Scanner(System.`in`)

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

fun main() {
  val (n, m, k) = readInts()
  var A = readLongs()
  var a = arrayListOf <Long> ()

  a.addAll(A)
  a.sort()

  var ans = (1e18).toLong()
  var ans = (1e18).toLong()
    var ind = 0
    var above:Long = 0
    var below:Long = 0
    for (i in 0..m-1) above += a[i]-a[0]
    for (i in 0..n-m) {
        val des = i+(m-1)/2
        while (ind < des) { // try to get closer to median if possible
            if (below+(a[ind+1]-a[ind])*(ind+1-i) <= k) {
                below += (a[ind+1]-a[ind])*(ind+1-i)
                above -= (a[ind+1]-a[ind])*(i+m-1-ind) // ind+1 to i+m-1
                ind ++
            } else break
        }
        assert (k >= below)
        if (ind < des) {
            var oops: Long = (k-below)/(ind+1-i)
            ans = minOf(ans,below+above-(i+m-1-ind)*oops+(ind+1-i)*oops)
            assert(i+m-1-ind >= ind+1-i)
        } else ans = minOf(ans,above+below)
        if (i < n-m) {
            below -= a[ind]-a[i]
            above += a[i+m]-a[ind]
        }
    }
  print(ans)
}


import java.util.*
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextInts() = next().split(" ").map { it.toInt() }
fun nextLongs() = next().split(" ").map { it.toLong() }
val OUT = mutableListOf<String>()
val N = 100000
var cnt = IntArray(10)
val dp = HashMap<Long,Long>()

fun dfs(len: Int, c2: Int, c3: Int, c5: Int, c7: Int) : Long {
  if (c2 < 0 || c3 < 0 || c5 < 0 || c7 < 0)
    return 0L
  var tmp = (c2 + (c3 shl 5) + (c5 shl 10) + (c7 shl 14) + (len shl 18)).toLong()
  if (len == 0) {
    if (tmp == 0L)
      return 1L
    return 0L
  }
  dp[tmp]?.let { return it }
  var ret = 0L
  ret += dfs(len-1, c2, c3, c5, c7)     // 1
  ret += dfs(len-1, c2-1, c3, c5, c7)   // 2
  ret += dfs(len-1, c2, c3-1, c5, c7)   // 3
  ret += dfs(len-1, c2-2, c3, c5, c7)   // 4
  ret += dfs(len-1, c2, c3, c5-1, c7)   // 5
  ret += dfs(len-1, c2-1, c3-1, c5, c7) // 6
  ret += dfs(len-1, c2, c3, c5, c7-1)   // 7
  ret += dfs(len-1, c2-3, c3, c5, c7)   // 8
  ret += dfs(len-1, c2, c3-2, c5, c7)   // 9
  dp[tmp] = ret
  return ret
}

var ret = ""

fun solve(k: Long, len: Int, c2: Int, c3: Int, c5: Int, c7: Int) {
  if (c2 < 0 || c3 < 0 || c5 < 0 || c7 < 0)
    return
  if (len == 0)
    return
  var cur = 0L
  var tmp = dfs(len-1, c2, c3, c5, c7)
  if (cur+tmp >= k) {
    ret += "1"
    solve(k-cur, len-1, c2, c3, c5, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2-1, c3, c5, c7)   // 2
  if (cur+tmp >= k) {
    ret += "2"
    solve(k-cur, len-1, c2-1, c3, c5, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2, c3-1, c5, c7)   // 3
  if (cur+tmp >= k) {
    ret += "3"
    solve(k-cur, len-1, c2, c3-1, c5, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2-2, c3, c5, c7)   // 4
  if (cur+tmp >= k) {
    ret += "4"
    solve(k-cur, len-1, c2-2, c3, c5, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2, c3, c5-1, c7)   // 5
  if (cur+tmp >= k) {
    ret += "5"
    solve(k-cur, len-1, c2, c3, c5-1, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2-1, c3-1, c5, c7) // 6
  if (cur+tmp >= k) {
    ret += "6"
    solve(k-cur, len-1, c2-1, c3-1, c5, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2, c3, c5, c7-1)   // 7
  if (cur+tmp >= k) {
    ret += "7"
    solve(k-cur, len-1, c2, c3, c5, c7-1)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2-3, c3, c5, c7)   // 8
  if (cur+tmp >= k) {
    ret += "8"
    solve(k-cur, len-1, c2-3, c3, c5, c7)
    return
  }
  cur += tmp
  tmp = dfs(len-1, c2, c3-2, c5, c7)   // 9
  if (cur+tmp >= k) {
    ret += "9"
    solve(k-cur, len-1, c2, c3-2, c5, c7)
    return
  }
}

fun solve() {
  var (m,kk) = nextInts()
  var k = kk.toLong()
  var n = m
  var ar = mutableListOf<Int>()
  for (i in 2..9) {
    while (n % i == 0) {
      n /= i
      cnt[i]++
    }
  }
  if (n != 1) {
    println("-1")
    return
  }
  var len = 0
  while (1) {
    len += 1
    var nx = dfs(len, cnt[2], cnt[3], cnt[5], cnt[7]);
    if (nx < k) {
      k -= nx;
      continue
    }
    solve(k, len, cnt[2], cnt[3], cnt[5], cnt[7])
    println(ret)
    return
  }
}

fun main() {
  var T = 1 // nextInt()
  for (i in 1..T) {
    solve()
  }
  //println(OUT.joinToString("\n"))
}