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 Rust (1.15.1) (judge verdict: Accepted)

use io::*;

fn main() {
    let con = read_string();
    let mut sc = Scanner::new(&con);

    let a: i64 = sc.next();
    let b: i64 = sc.next();
    let c: i64 = sc.next();
    let k: i64 = sc.next();

    let ans = if k % 2 == 0 { a - b } else { b - a };

    println!("{}", ans);

    // let m: Mat = [[0, 1, 1], [1, 0, 1], [1, 1, 0]];

    // for i in 0..100 {
    //     println!("{}: {:?}", i, mpow(&m, i));
    // }

    // let mm = mpow(&m, k);

    // let ma = mm[0][0] * a + mm[0][1] * b + mm[0][2] * c;
    // let mb = mm[1][0] * a + mm[1][1] * b + mm[1][2] * c;
    // let ans = ma - mb;

    // if ans.abs() > 1000_000_000_000_000_000 {
    //     println!("Unfair");
    // } else {
    //     println!("{}", ans);
    // }
}

type Mat = [[i64; 3]; 3];

fn mpow(a: &Mat, n: i64) -> Mat {
    if n == 0 {
        [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
    } else {
        let t = mpow(&mmul(a, a), n / 2);
        if n % 2 == 0 {
            t
        } else {
            mmul(&t, a)
        }
    }
}

fn mmul(a: &Mat, b: &Mat) -> Mat {
    let mut c: Mat = [[0; 3]; 3];

    for i in 0..3 {
        for j in 0..3 {
            for k in 0..3 {
                c[i][j] += a[i][k] * b[k][j];
            }
        }
    }

    c
}

//-----

pub mod io {
    use std;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T>(&mut self) -> T
        where
            T: std::str::FromStr,
            <T as std::str::FromStr>::Err: std::fmt::Debug,
        {
            let s = self.iter.next().unwrap();
            s.parse::<T>().unwrap()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}