a, b, c, d, n = gets.split.map(&:to_i) as = [a, b, c, d] xs = [a, 0, 0, 0] hash = {} hash[xs] = 0 len = 1 n.times do |i| i %= 4 j = (i + 1) % 4 h = [xs[i], as[j] - xs[j]].min xs[i] -= h xs[j] += h break if hash[xs] hash[xs] = len len += 1 end tail = hash[xs] cycle = len - tail m = tail + (n - tail) % cycle xs = [a, 0, 0, 0] m.times do |i| i %= 4 j = (i + 1) % 4 h = [xs[i], as[j] - xs[j]].min xs[i] -= h xs[j] += h end puts xs.join(" ")