class Yukicoder def initialize aw, ab = gets.chomp.split(' ').map(&:to_i) bw, bb = gets.chomp.split(' ').map(&:to_i) c, d = gets.chomp.split(' ').map(&:to_i) mw1 = [aw, [0, (c - ab)].max].min aw -= mw1 bw += mw1 mw2 = [bw, d].min aw += mw2 bw -= mw2 puts aw end end Yukicoder.new