$i = 0 $x = 0 $y = 0 while($i < H*W) $a = $i / H $b = $i % W if(A[$a+1,$b+1] == B[$a+1,$b+1]) $x = $a+1 $y = $b+1 end $i = $i + 1 end return($x,$y)