A, B, K, C = (int(i) for i in input().split()) print(((K * pow(2, K - 1)) if C in (A, B) else 0) % 1000000007)