from copy import copy from collections import defaultdict,deque v1,v2,v3,v4,n = map(int,input().split()) volume = [v1,v2,v3,v4] tmp = [v1,0,0,0] dp = [[-1] *((v1+1) ** 3) for _ in range(4)] def convert(x,y,z,X,Y,Z): return X * Y *z + X * y + x def ch(List): v1,v2,v3,v4 = List return convert(v1,v2,v3,volume[0]+1,volume[0]+1,volume[0]+1) q = deque() q.append((tmp,0)) dp[0][ch(tmp)] = 0 memo = [] cycle = -1 while q: board,t = q.popleft() memo.append(board) new = copy(board) co = volume[(t+1)%4] -new[(t+1) % 4] new[(t+1) % 4] += min(new[t%4],co) new[t%4] -= min(new[t%4],co) if dp[(t+1)%4][ch(new)] >= 0: cycle = dp[(t+1)%4][ch(new)] break q.append((new,t+1)) dp[(t+1)%4][ch(new)] = dp[t%4][ch(board)] +1 doubling = [[-1] * len(memo) for _ in range(61)] for i in range(len(memo)): if i == len(memo) -1: doubling[0][i] = cycle else: doubling[0][i] = i + 1 for k in range(60): for i in range(len(memo)): doubling[k+1][i] = doubling[k][doubling[k][i]] now = 0 for k in range(61): if (n>>k) & 1: now = doubling[k][now] n-= (1<