output_description: Print the minimum possible length of s.
  
  * * *
input_description: Input is given from Standard Input in the following format:
  
      
      
      a
      b
      c
attempt: # -*- coding: utf-8 -*-
  # input = sys.stdin.readline
  def inpl():
      return list(map(int, input().split()))
  
  
  A = input()
  B = input()
  C = input()
  
  
  ab = []
  bc = []
  ca = []
  
  res = len(A) + len(B) + len(C)
  for i in range(len(A) + len(B) - 1):
      X = A[
          min(max(0, len(B) - i - 1), len(A)) : min(
              len(A) + len(B) - 2, len(A) + len(B) - i - 1
          )
      ]
      Y = B[max(0, i - len(A) + 1) : i + 1]
      for x, y in zip(X, Y):
          if (x == "?") or (y == "?") or (x == y):
              continue
          else:
              break
  
      else:
          ab.append(i)
          res = min(res, len(A) + len(B) + len(C) - len(X))
  
  for i in range(len(B) + len(C) - 1):
      X = B[
          min(max(0, len(C) - i - 1), len(B)) : min(
              len(B) + len(C) - 2, len(B) + len(C) - i - 1
          )
      ]
      Y = C[max(0, i - len(B) + 1) : i + 1]
      for x, y in zip(X, Y):
          if x == "?" or y == "?" or x == y:
              continue
          else:
              break
      else:
          bc.append(i)
          res = min(res, len(A) + len(B) + len(C) - len(X))
  
  for i in range(len(C) + len(A) - 1):
      X = C[
          min(max(0, len(A) - i - 1), len(C)) : min(
              len(C) + len(A) - 2, len(C) + len(A) - i - 1
          )
      ]
      Y = A[max(0, i - len(C) + 1) : i + 1]
      for x, y in zip(X, Y):
          if x == "?" or y == "?" or x == y:
              continue
          else:
              break
      else:
          ca.append(i)
          res = min(res, len(A) + len(B) + len(C) - len(X))
  ab = set(ab)
  bc = set(bc)
  ca = set(ca)
  for x in ab:
      for y in bc:
          z = x + y - len(B) + 1
          if z < 0 or (len(C) + len(A) - 1 <= z) or (z in ca):
              # print(len(B) + max(0, len(A)-x-1, y-len(B)+1) + max(0, x-len(B)+1, len(C)-y-1))
              res = min(
                  res,
                  len(B)
                  + max(0, len(A) - x - 1, y - len(B) + 1)
                  + max(0, x - len(B) + 1, len(C) - y - 1),
              )
  for x in bc:
      for y in ca:
          z = x + y - len(C) + 1
          if z < 0 or (len(A) + len(B) - 1 <= z) or (z in ab):
              # print(len(B) + max(0, len(A)-x-1, y-len(B)+1) + max(0, x-len(B)+1, len(C)-y-1))
              res = min(
                  res,
                  len(C)
                  + max(0, len(B) - x - 1, y - len(C) + 1)
                  + max(0, x - len(C) + 1, len(A) - y - 1),
              )
  for x in ca:
      for y in ab:
          z = x + y - len(A) + 1
          if z < 0 or (len(B) + len(C) - 1 <= z) or (z in bc):
              # print(len(B) + max(0, len(A)-x-1, y-len(B)+1) + max(0, x-len(B)+1, len(C)-y-1))
              res = min(
                  res,
                  len(A)
                  + max(0, len(C) - x - 1, y - len(A) + 1)
                  + max(0, x - len(A) + 1, len(B) - y - 1),
              )
  print(res)
  
problem_description: Statement
  
  Snuke has a string s. From this string, Anuke, Bnuke, and Cnuke obtained
  strings a, b, and c, respectively, as follows:
  
    * Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with `?`s.
  
  For example, if s is `mississippi`, we can choose the substring `ssissip` and
  replace its 1-st and 3-rd characters with `?` to obtain `?s?ssip`.
  
  You are given the strings a, b, and c. Find the minimum possible length of s.
samples: [{"input": "a?c\n    der\n    cod", "output": "7\n    \n\nFor example, s could be `atcoder`.\n\n* * *"}, {"input": "atcoder\n    atcoder\n    ???????", "output": "7\n    \n\na, b, and c may not be distinct."}]