main::IO() main = do wsg <- fmap (fmap read . words) getLine wsa <- fmap (\xs-> map (\c-> length . filter (==c) $xs) "GCP") getLine let sLoop i xs = drop i . concat . repeat $xs katiS = zipWith min wsg (sLoop 1 wsa) hikiwakeS = zipWith min (zipWith subtract katiS wsg) (zipWith subtract (sLoop 2 katiS) wsa) print $ 3 * sum katiS + sum hikiwakeS