package com.company;

import java.io.BufferedInputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Scanner;

public class Barrels {

    public static void main(String[] args) {
        Scanner input = new Scanner(new BufferedInputStream(System.in));
        int A=input.nextInt();
        int B=input.nextInt();
        int K=input.nextInt();
        int C=input.nextInt();

         long out=0;

        if((A!=C && B!=C) || K==0){
            System.out.println(0);
            return;
        }
        if(A==B){
            System.out.println(K);
            return;
        }

        out = power(K-1) % 1000000007L;

        System.out.println(out);
    }

    static private long power(int K){
        long acc = 1;
        for (int i = 0; i < K; i++){
            acc *= 2;
            acc %= 1000000007L;
        }
        return acc * (K + 1);
    }

}

