MOD = 10 ** 9 + 7 a, b, c, d = map(int, input().split()) n = int(input()) times = pow(16, n // 8, MOD) n %= 8 max_ = -float("inf") for xx in (a, b): for y in (c, d): x = xx for _ in range(n): x, y = x - y, x + y max_ = max(max_, x + y) print(max_ * times % MOD)