import Control.Monad
import qualified Data.IntSet as IntSet

check :: String -> String -> Bool
check [] [] = True
check (a : as) (b : bs) = if a == b || a == '?' || b == '?' then check as bs else False
check _ _ = False

findMatches :: String -> String -> [Int]
findMatches s t = filter checkOffset [-lt-2000..ls+2000]
  where
  ls = length s
  lt = length t
  checkOffset offset =
    let b = max 0 offset
        e = min (lt + offset) ls
        l = e - b
        ss = if offset > 0 then drop offset s else s
        tt = if offset < 0 then drop (-offset) t else t
    in check (take l ss) (take l tt)

solve :: String -> String -> String -> Int
solve a b c = 
  let [la, lb, lc] = map length [a, b, c]
      calcLength x y = maximum [la, x + lb, y + lc] - minimum [0, x, y]
      xs = findMatches a b
      ys = findMatches a c
      zs = IntSet.fromList $ findMatches b c
      as = [calcLength x y | x <- xs, y <- ys, IntSet.member (y - x) zs]
  in if null as then la + lb + lc else minimum as

main :: IO ()
main = do
  [a, b, c] <- replicateM 3 getLine
  putStrLn $ show $ solve a b c