A, B, C, D, E = gets.split.map(&:to_i) def f(m) total = x = 0 1.upto((B - C) * A) do |i| if i == 1 total += (x = D) elsif i % 10 != 0 total += x else if E <= x total += (x = [0, x - E].max) else total += x end end end total <= m end ok = 10 ** 18 ng = -1 while (ok - ng).abs >= 2 x = (ok + ng) / 2 if f(x) ok = x else ng = x end end puts ok