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; i++) {
            key *= 2;
            //key = getCongruence(key);
        }
        key *= k;        
        key /= 2;
        key = getCongruence(key);
        return key;
    }

    
    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(c==a && a==b) System.out.println(k);
        else if(c==a || c==b) System.out.println(calculateKey(k));
        else if(c != a && c!=b) System.out.println(0);
    }
    
}

