sub f{ $p[$_]=$_-$p[$_]?f(local$_=$p[$_]):$_ } map$p[$_]=$_,@@=1..<>; map{ @a=sort{$n[$a]-$n[$b]||$b-$a}map f,glob; $n[$p["@a"]=$a[1]]+="@a"-$a[1]&&$n["@a"]+1 }<>; print f,$/for@@