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