let eqs a b o =
  let a, b, o = if o < 0 then b, a, -o else a, b, o in
  let rec f i =
    if i+o >= String.length a || i >= String.length b then true
    else (a.[i+o] = '?' || b.[i] = '?' || a.[i+o] = b.[i]) && f (i+1)
  in f 0

let max3 a b = max (max a b)
let min3 a b = min (min a b)

let () =
  Scanf.scanf "%s %s %s" @@ fun a b c ->
  let la, lb, lc = String.(length a, length b, length c) in
  let ab = Array.init 4001 (fun i -> eqs a b (i-2000)) in
  let bc = Array.init 4001 (fun i -> eqs b c (i-2000)) in
  let ac = Array.init 4001 (fun i -> eqs a c (i-2000)) in

  let ans = ref 6000 in
  for i = -4000 to 4000 do
    if abs i > 2000 || ab.(i+2000) then
      for j = -4000 to 4000 do
          if (abs j > 2000 || ac.(j+2000)) &&
             (abs (j-i) > 2000 || bc.(j-i+2000))
          then
            ans := min !ans (max3 la (i+lb) (j+lc) - min3 0 i j)
      done;
  done;
  Printf.printf "%d\n" !ans
