local mma, mmi = math.max, math.min
local a = io.read()
local b = io.read()
local c = io.read()
local t1, t2, t3 = {}, {}, {}
for i = 1, #a do
  local ss = a:sub(i, i)
  t1[i] = ss == "?" and 0 or ss:byte() - 96
end
for i = 1, #b do
  local ss = b:sub(i, i)
  t2[i] = ss == "?" and 0 or ss:byte() - 96
end
for i = 1, #c do
  local ss = c:sub(i, i)
  t3[i] = ss == "?" and 0 or ss:byte() - 96
end
local ans = #t1 + #t2 + #t3
for iz = 1, 6 do
  local p1, p2, p3 = 0, 0, 0
  if iz == 1 then
    p1, p2, p3 = t1, t2, t3
  elseif iz == 2 then
    p1, p2, p3 = t1, t3, t2
  elseif iz == 3 then
    p1, p2, p3 = t2, t1, t3
  elseif iz == 4 then
    p1, p2, p3 = t2, t3, t1
  elseif iz == 5 then
    p1, p2, p3 = t3, t1, t2
  else
    p1, p2, p3 = t3, t2, t1
  end
  -- p1 is first and p3 is end
  -- find p2 point
  local mincand = mma(#p2, mma(#p1, #p3))
  for totallen = mincand, #p1 + #p2 + #p3 do
    local v = true
    local d = {}
    for i = 1, totallen do
      local cand = 0
      if i <= #p1 then
        if p1[i] ~= 0 then
          if cand == 0 then
            cand = p1[i]
          elseif cand ~= p1[i] then v = false break
          end
        end
      end
      if totallen - i + 1 <= #p3 then
        local a3 = p3[#p3 - (totallen - i)]
        if a3 ~= 0 then
          if cand == 0 then
            cand = a3
          elseif cand ~= a3 then v = false break
          end
        end
      end
      d[i] = cand
    end
    if v then
      local ofst_max = totallen - #p2
      v = false
      for ofst = 0, ofst_max do
        local f = true
        for i = 1, #p2 do
          local a2 = p2[i]
          local dd = d[ofst + i]
          if dd * a2 ~= 0 and dd ~= a2 then
            f = false
            break
          end
        end
        if f then v = true break end
      end
    end
    if v then ans = mmi(ans, totallen) break end
  end
end
print(ans)
