<>=~/ .* /;$\+=($==($_+=2e9)/$&)>${$_%=-$&}+2*$'|$$_<1?2*$'+1:$=-$$_,$$_=$=for sort{$a-$b}glob<>;print