sub min{$_[$_[0]>$_[1]]} <>; $s=<>; $t=<>; print min($s=~y/A//,$t=~y/A//)+min($s=~y/B//,$t=~y/B//)