solve :: [Int] -> [Int] -> Int solve ls rby = minimum (iter ls 3) where [red,blue,yellow] = rby iter [x,y,z] i | i == 0 = [] | otherwise = (rRap + bRap + yRap) : iter [y,z,x] (i - 1) where rRap = (y + z) * 2 * red bRap = (x + y) * 2 * blue yRap = (z + x) * 2 * yellow main = do ls <- map read . words <$> getLine rby <- map read . words <$> getLine print $ solve ls rby