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: # パナソニック2020E
  
  import sys
  
  input = sys.stdin.readline
  sys.setrecursionlimit(max(1000, 10**9))
  
  
  a, b, c = [input() for _ in range(3)]
  la, lb, lc = len(a), len(b), len(c)
  
  
  def ok(c1, c2):
      return True if c1 == c2 or c1 == "?" or c2 == "?" else False
  
  
  def sub(s, t, gap):
      # tを固定したとき、
      # sの開始位置座標としてありえるもののset
      S = set(list(range(-len(s) - gap, -len(s) + 1)) + list(range(len(t), len(t) + gap)))
      i1 = min(len(s), len(t))
      i2 = max(len(s), len(t))
      i3 = len(s) + len(t)
      for i in range(1, i1):
          if all((ok(s[-i + ii], t[ii])) for ii in range(i)):
              S.add(i - len(s))
      for i in range(i1, i2):
          if len(s) < len(t) and all((ok(s[ii], t[ii + i - i1]) for ii in range(i1))):
              S.add(i - len(s))
          elif len(t) <= len(s) and all(ok(s[i1 - i + ii], t[ii]) for ii in range(i1)):
              S.add(i - len(s))
      for i in range(i2, i3):
          if all((ok(s[ii], t[i - i3 + ii]) for ii in range(i3 - i))):
              S.add(i - len(s))
      return S
  
  
  ab = sub(a, b, lc)
  bc = sub(c, b, la)
  ac = sub(a, c, lb)
  ans = 10**9
  import itertools
  
  for ii, jj in itertools.product(ab, bc):
      if ii - jj in ac:
          val = max(lb, ii + la, jj + lc) - min(0, ii, jj)
          ans = min(ans, val)
  print(ans)
  
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."}]