n = gets.to_i c, v = gets.split.map(&:to_i) ans = nil n.times do |i| a, b, cost = 1, 0, 0 (i + 1).times do # c+v a, b, cost = 2 * a, a, cost + c + v # p ['c+v =>', a, b, cost] break if a >= n end while a < n # v a, b, cost = a + b, b, cost + v # p ['v =>', a, b, cost] end ans = ans == nil ? cost : [ans, cost].min end p ans