eval"N,K,*A,X=#{`tr ' ' ,`}0" Y=N*K A.reduce{X,Y=[X+K,Y+K,[X+z=_2-_1,X].max].min,[X+K,Y+K,[Y-z,Y].max].min;_2} p [X,Y].min