@@=1..<>;${s/^/ /;map{0while-$$_+($$_=$$$_//$_)}/( \d+)(.*)/;$2?@{$$a=$b}[$a-$b&&@$a+@$b]=($a,$b)=sort{@$a-@$b||$b-$a}$$1,$$2:print$$_,$/}for<>,@@