A, B, C, D = gets.split.map(&:to_i) N = gets.to_i MOD = 10 ** 9 + 7 ans = -Float::INFINITY d, m = N.divmod(8) [[A, C], [A, D], [B, C], [B, D]].each do |a, b| m.times do a, b = a - b, a + b end ans = a + b if ans < a + b end puts (ans * 16.pow(d, MOD)) % MOD