package barrels;

import java.util.Scanner;

public class Barrels {
    private static final int MODULO = 1000000007;
    
    public static long getCongruence(long key) {
        if(key >= MODULO) return (key % MODULO);
        else return key;
    }
    
    public static long calculateKey(int k) {
        long key = 2;
        for(int i=1; i<k-1; i++) {
            key = (key*2) % MODULO;
            //System.out.println(key);
            //key = getCongruence(key);
        }
        key *= k;
        //System.out.println(key);
        //key /= 2;
        //key = getCongruence(key);
        return key % MODULO;
    }

    
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        int k = s.nextInt();
        int c = s.nextInt();
        if(k == 0) System.out.println(0);
        else if(c != a && c!=b) System.out.println(0);
        else if(k==1) System.out.println(1);
        else if(c==a && a==b) System.out.println(k);        
        else /*if(c==a || c==b)*/ System.out.println(calculateKey(k));
        
    }
    
}

