Problem:
Score : 300 points

Problem Statement

Takahashi, Nakahashi and Hikuhashi have integers A, B and C, respectively.
After repeating the following operation K times, find the integer Takahashi will get minus the integer Nakahashi will get:

Each of them simultaneously calculate the sum of the integers that the other two people have, then replace his own integer with the result.

However, if the absolute value of the answer exceeds 10^{18}, print Unfair instead.

Constraints

1 \leq A,B,C \leq 10^9

0 \leq K \leq 10^{18}

All values in input are integers.

Input

Input is given from Standard Input in the following format:

A B C K

Output

Print the integer Takahashi will get minus the integer Nakahashi will get, after repeating the following operation K times.
If the absolute value of the answer exceeds 10^{18}, print Unfair instead.

Sample Input 1

1 2 3 1

Sample Output 1

1

After one operation, Takahashi, Nakahashi and Hikuhashi have 5, 4 and 3, respectively. We should print 5-4=1.

Sample Input 2

2 3 2 0

Sample Output 2

-1

Sample Input 3

1000000000 1000000000 1000000000 1000000000000000000

Sample Output 3

0

Solution in C++14 (GCC 5.4.1) (judge verdict: Time Limit Exceeded)

#include <iostream>
#include <algorithm>
/*#include <cstdlib>
#include <cstdio>
#include <numeric>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#define MAX_U   10
#define MIN_U   0
*/#define rep(i,n) for(int i=0;i<n;i++)
//#define sz(x) ((int)(x).size())
using namespace std;
/*typedef long long ll;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef queue<int> qi;*/
const int INF=numeric_limits<int>::infinity();
void printa(){cout<<"\n";}
template<class T, class... A>void printa(const T&first,const A&... rest){cout<<first;printa(rest...);}
template<class... A>void printa(const A&... rest){printa(rest...);}
/*void prints(){cout<<" ";}
template<class T, class... A>void prints(const T&first,const A&... rest){cout<<first;prints(rest...);}
template<class... A>void prints(const A&... rest){prints(rest...);}
int factorial(int x){int f=1;for(int i=1;i<x+1;i++)f=f*i;return f;}
int sigma(int x){int s;for(int i=1;i<x+1;i++)s=s+i;return s;}
int middle(int x){if(x%2==0)return x/2;else return x/2+1;}
double heron(int a,int b,int c){double s;s=(a+b+c)/2;return sqrt(s*(s-a)*(s-b)*(s-c));}
double trapezium(int a,int b,int h){return (a+b)*h/2;}
double triangle(int a,int h){return a*h/2;}
void sorm(vector<int> vec){sort(vec.begin(),vec.end());}
void sorg(vector<int> vec){sort(vec.begin(),vec.end(),greater<int>());}
int cmp( const void *p, const void *q ) {if( *(double*)p > *(double*)q ) return 1;if( *(double*)p < *(double*)q ) return -1;return 0;}*/
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c,k,buf,buf2,f1=0,f2=0,f3=0;
    cin >>a>>b>>c>>k;
    if(k==0){
        printa(a-b);
    }
    else{
        for(int i=0;i<k;i++){
        buf=a;
        buf2=b;
        a=b+c;
        b=buf+c;
        c=buf+buf2;
        if(a>1000){
            a=a/1000;
            f1++;
        }
        if(b>1000){
            b=b/1000;
            f2++;
        }
        if(c>1000){
            c=c/1000;
            f3++;
        }
    }
    /*if(f1==1)a=a*1000;
    if(f2==1)b=b*1000;
    if(f3==1)c=c*1000;*/
    rep(i,f1)a=a*1000;
    rep(i,f2)b=b*1000;
    rep(i,f3)c=c*1000;
    printa(a-b);
    }
    return 0;
}