import Control.Applicative ((<$>)) import Data.List (foldl') main :: IO () main = do [g, c, p] <- map read <$> words <$> getLine solve (g, c, p) <$> foldl' f (0, 0, 0) <$> getLine >>= print where f (g, c, p) s | s == 'G' = (g+1, c, p) | s == 'C' = (g, c+1, p) | otherwise = (g, c, p+1) solve :: (Int,Int,Int) -> (Int,Int,Int) -> Int solve (g, c, p) (g', c', p') = h $ f (g, c, p) (g', c', p') where f (g1, c1, p1) (g2, c2, p2) = let mg = min g1 c2 mc = min c1 p2 mp = min p1 g2 in ((g1-mg, c1-mc, p1-mp), (g2-mp, c2-mg, p2-mc), 3 * (mg+mc+mp)) h ((g1, c1, p1), (g2, c2, p2), p) = p + min g1 g2 + min c1 c2 + min p1 p2