#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define ll long long int
const int mod=1000000007;
using namespace std;

int main()
{
ios::sync_with_stdio(0);
cout.tie();
    int a,b,k,c;
    cin>>a>>b>>k>>c;
    if(a==c||b==c)
    {
        if(a==b){
            cout<<k;
            return 0;
        }
        ll wynik=1;
        for(int i=1;i<k;i++)
        {
            wynik*=2;
            wynik%=mod;
        }
        wynik*=k;
        wynik%=mod;
        cout<<wynik;
    }
    else
        cout<<0;
    return 0;
}

