aw,ab,bw,bb,c,d=gets(p).split.map(&:to_i) minb=[ab,c].min c-=minb ab-=minb bb+=minb if c>0 aw-=c bw+=c end minw=[bw,d].min d-=minw bw-=minw aw+=minw if d>0 bb-=d ab+=d end p aw