A,B,C,D = map(int,input().split()) N = int(input()) MOD = 10**9+7 q = (N-1)//4 r = (N-1)%4 if r==0: if q%2==0: ans = (2*pow(4,q,MOD)*B)%MOD else: ans = (-2*pow(4,q,MOD)*A)%MOD elif r==1: if q%2==0: ans = (2*pow(4,q,MOD)*(B-C))%MOD else: ans = (-2*pow(4,q,MOD)*(A-D))%MOD elif r==2: if q%2==0: ans = (-pow(4,q+1,MOD)*C)%MOD else: ans = (pow(4,q+1,MOD)*D)%MOD else: if q%2==0: ans = (-pow(4,q+1,MOD)*(A+C))%MOD else: ans = (pow(4,q+1,MOD)*(B+D))%MOD print(ans)