($_,$s,$t)=<>;for$j(!/ /..$'){@b=@a;map+($a[$_])=($r)=$_?$j?sort{$a-$b}$b[$_-1]+(vec($s,$_-1,8)!=vec$t,$j-1,8),$r+1,$b[$_]+1:$_:$j,0..$_}print$r