def g;gets.split.map(&:to_i);end n,k=g e=(1..n).map{g} m=(1..1502).map{[0]*1502} k.times{ x,y,w,h,d=g x+=500;y+=500 m[y][x]+=d m[y][x+w+1]-=d m[y+h+1][x]-=d m[y+h+1][x+w+1]+=d } a=[0]*1502 m.map!{|i| s=0 a=a.zip(i.map{|j|s+=j}).map{|j,l|j+l} } p e.map{|x,y,h|[h-m[y+500][x+500],0].max}.inject(:+) #require'pp' #pp m[490..510].map{|i|i[490..510]}