sub f{$r+=$a=!grep$_-$_[1]&&f($_,$_[0]),@$_;$a}/ /&&push@{$`},$'+!push@{$'+0},$`for<>;f$_=1;print$r