#!/bin/python3 import sys def countArray(n, k, x): # Return the number of ways to fill in the array. b = k - 1 res = 0 if n % 2 == 0: res = ((pow(b, n) - 1) // (b ** 2 - 1) - b * (pow(b, n - 2) - 1) // (b ** 2 - 1)) % (10 ** 9 + 7) if x == 1: res -= 1 else: res = ((pow(b, n - 1) - 1) // (b + 1)) % (10 ** 9 + 7) if x == 1: res += 1 return res if __name__ == "__main__": n, k, x = input().strip().split(' ') n, k, x = [int(n), int(k), int(x)] answer = countArray(n, k, x) print(answer)