def calc(a, b, k): for i in range(k): a, b = a - b, a + b return a + b mod = 10 ** 9 + 7 a, b, c, d = map(int, input().split()) n = int(input()) k = n % 8 m = max(calc(a, c, k), calc(b, c, k), calc(a, d, k), calc(b, d, k)) print(m * pow(16, n // 8, mod) % mod)