sub f{ my($a,$j,$p)=@_; $a&=$_-$p?f(1,$_,$j):1for@$j; $\+=$a; !$a } <>;/ /,push@{$`},$'+!push@{$'+0},$`for<>; f 1,1; print