fun main() { val builder = StringBuilder() val mod = 1000000007L val (b, c, d) = readInputLine().split(" ").map { it.toLong() } if (c == 1L) { builder.appendln((b % mod) * (d % mod) % mod) } else { val numerator = (pow(c % mod, d + 1L, mod) + mod - 1L) % mod val denominator = modInv((c - 1L) % mod, mod) % mod builder.appendln(((b % mod * numerator % mod * denominator % mod) + mod - (b % mod)) % mod) } print(builder.toString()) } fun readInputLine(): String { return readLine()!! } // a^-1 mod mod fun modInv(a: Long, mod: Long): Long { var aLoc = a var b = mod var u = 1L var v = 0L while (b != 0L) { val t = aLoc / b aLoc -= t * b val swapTmpB = b b = aLoc aLoc = swapTmpB u -= t * v val swapTmpU = u u = v v = swapTmpU } u %= mod if (u < 0) { u += mod } return u } fun pow(x: Long, n: Long, mod: Long): Long { var ret = 1L var base = x var nTmp = n while (nTmp != 0L) { if (nTmp % 2L != 0L) { ret = ret * base % mod } base = base * base % mod nTmp /= 2L } return ret }