
A, B, K, C = list(map(int, input().split()))

divider = 1000000007

if A == C or B == C:
    print(K * pow(2, K - 1) % divider)
else:
    print(0)
