a,b,c,d=map(int,input().split()) n=int(input()) M=10**9+7 if n%8==0: g=max(x+y for x in [a,b] for y in [c,d]) if n%8==1: g=max(x-y+x+y for x in [a,b] for y in [c,d]) if n%8==2: g=max(-2*y+2*x for x in [a,b] for y in [c,d]) if n%8==3: g=max(-2*x-2*y+2*x-2*y for x in [a,b] for y in [c,d]) if n%8==4: g=max(-4*x-4*y for x in [a,b] for y in [c,d]) if n%8==5: g=max(-4*x+4*y-4*x-4*y for x in [a,b] for y in [c,d]) if n%8==6: g=max(8*y+-8*x for x in [a,b] for y in [c,d]) if n%8==7: g=max(8*x+8*y-8*x+8*y for x in [a,b] for y in [c,d]) print(g*pow(16,n//8,M)%M)