a,b,c,d = map(int,input().split()) n = int(input()) mod = 10**9+7 mul,m = divmod(n, 8) na = [1,0] nb = [0,1] for i in range(m): nna = [na[0]-nb[0],na[1]-nb[1]] nnb = [na[0]+nb[0],na[1]+nb[1]] na = nna nb = nnb ans = -10**20 for i in ((a,b)): for j in ((c,d)): count = na[0]*i+na[1]*j+nb[0]*i+nb[1]*j ans = max(ans,count) print(ans*pow(16,mul,mod)%mod)