fun max(a: Long, b: Long): Long = if (a>b) a else b fun abs(a: Long): Long = if (a<0) -a else a fun f(a: Long): Long = a shr 1 fun g(a: Long): Long = (f(a) shl 1) + a tailrec fun h(a: Long, b: Long, c: Long): Long = if (a>0) h(f(a),b+f(a),max(c,g(a))) else abs(c-b) fun main(args: Array) { val n: Long = readLine()!!.toLong() println(h(n,n,n shl 1)) }