def f(N, x, y): q, r = divmod(N, 4) v = pow(-4, q, mod) if r == 0: return v * x % mod elif r == 1: return v * 2 * x % mod elif r == 2: return v * 2 * (x - y) % mod else: return v * (-4) * y % mod A, B, C, D = map(int, input().split()) N = int(input()) mod = 10 ** 9 + 7 ans = f(N, A, C) q, r = divmod(N, 4) if q % 2 == 0: print(f(N, B, C)) else: print(f(N, A, D))