a = [input(),input(),input()]
def checkEqual(l,r,k):
    i = len(l)-k
    j = 0
    for a in range(k):
        x, y = i+a, j+a
        if l[x] != r[y]:
            if l[x]=='?' or r[y]=='?':
                continue
            return False
    return True

overLaps = [[[] for i in range(3)] for j in range(3)]
ij = [(0,1),(1,0),(1,2),(2,1),(0,2),(2,0)]
for i,j in ij:
    l = a[i]
    r = a[j]
    m = min(len(l),len(r))
    for k in range(m+1):
        if checkEqual(l,r,k):
            overLaps[i][j].append(k)

maxRe = 0
combs = [(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,0,1),(2,1,0)]
for x,y,z in combs:
    full = len(a[y])
    o1 = overLaps[x][y]
    o2 = overLaps[y][z]
    midOl = set(overLaps[x][z])
    for i in range(len(o1)-1,-1,-1):
        for j in range(len(o2)-1,-1,-1):
            re = o1[i] + o2[j]
            if re > full:
                if re-full not in midOl:
                    continue
            maxRe = max(re,maxRe)
    # i = len(o1)-1
    # j = len(o2)-1
    # if o1[i] + o2[j] <= full:
    #     re = o1[i] + o2[j]
    #     maxRe = max(re,maxRe)
    #     continue
    #
    # bar = full - o1[i]
    # while o2[j] > bar:
    #     j -= 1
    #     if j == 0:
    #         break
    # while j < len(o2):
    #     bar = full - o2[j]
    #     while o1[i] > bar:
    #         i -= 1
    #         if i<0:
    #             break
    #     if i<0:
    #         break
    #     re = o1[i] + o2[j]
    #     maxRe = max(re,maxRe)
    #     j += 1

ans = len(a[0])+len(a[1])+len(a[2])-maxRe
print(ans)