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 Java8 (OpenJDK 1.8.0) (judge verdict: Wrong Answer)

import java.math.BigInteger;
import java.util.*;
public class Main {
	
	public static BigInteger cmp;
	public static int len;
	public static int P;
	public static BigInteger A,B,C;
	public static boolean flag;
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sca=new Scanner(System.in);
		cmp=new BigInteger("1000000000000000000");
		
		while(sca.hasNext()){
			 A=sca.nextBigInteger();
			 B=sca.nextBigInteger();
			 C=sca.nextBigInteger();
			long K=sca.nextLong();
			
			Matrix a=new Matrix();
			 a.mat[2][1]=BigInteger.ONE;
			    a.mat[3][1]=BigInteger.ONE;
			    a.mat[1][2]=BigInteger.ONE;
			    a.mat[3][2]=BigInteger.ONE;
			    a.mat[1][3]=BigInteger.ONE;
			    a.mat[2][3]=BigInteger.ONE;
			    flag=true;
			    Matrix c=Poww(a,K);
			
			if(K==0){
				System.out.println(A.subtract(B));
			}
		
			else{
				   BigInteger p1=B.multiply(c.mat[2][1]).add(C.multiply(c.mat[3][1]));
	        	   BigInteger p2=A.multiply(c.mat[1][2]).add(C.multiply(c.mat[3][2]));
	               BigInteger cc=p1.subtract(p2);
	               if(cc.compareTo(BigInteger.ZERO)<0){
	            	   cc=p2.subtract(p1);
	               }
	               if(cc.compareTo(cmp)>0){
	                 System.out.println("Unfair");
	               }	
	               else 
	               System.out.println(cc);
			}
		}
	}
	public static Matrix MUL(Matrix a,Matrix b){
		Matrix c=new Matrix();
		for(int i=1;i<=3;i++){
			for(int j=1;j<=3;j++){
				for(int k=1;k<=3;k++){
					c.mat[i][j]=(c.mat[i][j].add(a.mat[i][k].multiply(b.mat[k][j])));
				}
			}
		}
		return c;
	}
	public static Matrix Poww(Matrix a,long b){
	    Matrix ans=new Matrix();
	    for(int i=1;i<=3;i++)ans.mat[i][i]=BigInteger.ONE;
	    while(b%2!=0){
	        if(b%2==1){
	        	ans=MUL(ans,a);
	        	
	        
	        
	        }
	        
	        
	        a=MUL(a, a);
	        b=b/2;
	    }
	    return ans;
	}

}
class Matrix{
	public  BigInteger mat[][]=new BigInteger[4][4];
	public Matrix(){
		for(int i=1;i<=3;i++){
			for(int j=1;j<=3;j++){
				mat[i][j]=BigInteger.ZERO;
			}
		}
	}
	
}