a,b,c,d = map(int,input().split()) n = int(input()) p,q = divmod(n,8) ans = [(a,c),(a,d),(b,c),(b,d)] for _ in range(q): ans = [(x-y,x+y) for x,y in ans] v = max(x+y for x,y in ans) MOD = 10**9+7 print(v*pow(16,p,MOD)%MOD)