def solve(nums) return 0 if nums[1] <= nums[2] # 参加者がいない場合 prices = [nums[3]] drop_num = (nums[1] - nums[2]) * nums[0] # 参加者 x 1人あたりの個数 (2..drop_num).each do |i| x = prices.last if (i % 10).zero? e = nums[4] # E price if e <= x prices << [x - e, 0].max else prices << x end else prices << x end end prices.sum end nums = gets.chomp.split.map(&:to_i) puts solve(nums)