#!/bin/ruby def countArray(n, k, x) memo_x = Array.new(n) memo_notx = Array.new(n) if x == 1 memo_x[0] = 1 memo_notx[0] = 0 else memo_x[0] = 0 memo_notx[0] = 1 end for i in (1..n - 2) memo_x[i] = memo_notx[i - 1] memo_x[i] %= (10 ** 9 + 7) memo_notx[i] = memo_notx[i - 1] * (k - 2) + memo_x[i - 1] * (k - 1) memo_notx[i] %= (10 ** 9 + 7) end STDERR.puts(memo_x.inspect) STDERR.puts(memo_notx.inspect) return memo_notx[n - 2] end n, k, x = gets.strip.split(' ') n = n.to_i k = k.to_i x = x.to_i answer = countArray(n, k, x) puts answer