#!/bin/python3 import sys def countArray(n, k, x): if k==2: if (n%2==0 and x==2) or (n%2==1 and x==1): return 0 ending_with_x = 1 if x==1 else 0 others = 0 if x==1 else 1 for _ in range(n-2): ending_with_x_old = ending_with_x ending_with_x = others * 1 others = (ending_with_x_old*(k-1) + others*(k-2)) % (10**9+7) return others 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)