lib C fun strtoll(s : UInt8*, p : UInt8**, b : Int32) : Int64 end class String def to_i64 C.strtoll(self, nil, 10) end end def generate_dp(n, a, x) dp = [-10i64 ** 9] * -~n n.times do |i| dp[i + 1] = (x - a[i]) + {dp[i], 0i64}.max end n.times do |i| dp[i + 1] = {dp[i + 1], dp[i]}.max end dp end n, x, y = read_line.split.map(&.to_i64) a = read_line.split.map(&.to_i64) sum = a.sum left = generate_dp(n, a, x) right = generate_dp(n, a.reverse, y).reverse puts (1...n - 1).join('\n') { |i| sum + left[i] + right[i + 1] }