import sys if len(sys.argv) == 2: sys.stdin = open(sys.argv[1]) a, b, c, d = map(int, input().split()) n = int(input()) mod = 10**9 + 7 q, r = divmod(n, 8) ans = -10**18 for x in [a, b]: for y in [c, d]: if r == 0: ans = max(ans, x + y) elif r == 1: ans = max(ans, 2 * x) elif r == 2: ans = max(ans, 2 * (x - y)) elif r == 3: ans = max(ans, -4 * y) elif r == 4: ans = max(ans, -4 * (x + y)) elif r == 5: ans = max(ans, -8 * x) elif r == 6: ans = max(ans, -8 * (x - y)) else: ans = max(ans, 16 * y) ans %= mod ans *= pow(16, q, mod) ans %= mod print(ans)