gets a=gets.split.map &:to_i s=t=0 n=[(a.inject(:+)**0.5).to_i,-~a.size/2].min (2*n-1).times{|x|b=n-(n-x-1).abs-a[x];b>0 ? s+=b : t-=b} p [s,t].max