/ /and++$_[$`],++$_[$'],push@ $`,$'+!push@{$'+0},$`for<>;@q=(1,grep!($L[$_]=$_[$_]-1&&@_),2..@_);push@q,grep{$L[$_]-=$-=$L[$_]-$L[$q]-1;$-}@$q while$q=shift@q;print$_,$/for@L[1..$#_]