def chk(a,b):

    A,B=len(a),len(b)

    rt=[0]*A

    for i in range(A):

        f=1

        for j in range(min(A-i,B)):

            if len(set([a[i+j],b[j],'?']))>2:f=0;break

        rt[i]=f

    return rt+[1]



def tri_chk(ix):

    i1,i2,i3=ix

    ab,bc,ac=M[i1][i2],M[i2][i3],M[i1][i3]

    A,B,C=list(map(len,[S[i]for i in ix]))

    rt=A+B+C

    for l in range(A+1):

        if ab[l]==0:continue

        for r in range(l,A+B+1):

            if (B<r-l or bc[r-l]==1) and ac[min(A,r)]==1:

                rt=min(rt,max(A,l+B,r+C))

    return rt



S=[eval(input())for i in'abc']

A,B,C=list(map(len,S))

L=10**5

M=[[chk(S[i],S[j]) if i!=j else []for j in range(3)]for i in range(3)]



for i in [(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,1,0),(2,0,1)]:

    L=min(L,tri_chk(i))



print(L)

def F(a,b):

 A,B=len(a),len(b)

 r=[0]*A

 for i in range(A):

  f=1

  for j in range(min(A-i,B)):

   if len(set([a[i+j],b[j],'?']))>2:f=0;break

  r[i]=f

 return r+[1]

def T(ix):

 i1,i2,i3=ix;ab,bc,ac=M[i1][i2],M[i2][i3],M[i1][i3];A,B,C=list(map(len,[S[i]for i in ix]));q=A+B+C

 for l in range(A+1):

  if ab[l]!=0:

   for r in range(l,A+B+1):

    if (B<r-l or bc[r-l]==1) and ac[min(A,r)]==1:q=min(q,max(A,l+B,r+C))

 return q

S=[eval(input())for i in'abc']

M=[[F(S[i],S[j]) if i!=j else []for j in range(3)]for i in range(3)]

print((min([T(i)for i in [(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,1,0),(2,0,1)]])))
def chk(a, b):
    A, B = len(a), len(b)
    rt = [0] * A
    for i in range(A):
        f = 1
        for j in range(min(A - i, B)):
            if len(set([a[i + j], b[j], "?"])) > 2:
                f = 0
                break
        rt[i] = f
    return rt + [1]


def tri_chk(ix):
    i1, i2, i3 = ix
    ab, bc, ac = M[i1][i2], M[i2][i3], M[i1][i3]
    A, B, C = list(map(len, [S[i] for i in ix]))
    rt = A + B + C
    for l in range(A + 1):
        if ab[l] == 0:
            continue
        for r in range(l, A + B + 1):
            if (B < r - l or bc[r - l] == 1) and ac[min(A, r)] == 1:
                rt = min(rt, max(A, l + B, r + C))
    return rt


S = [eval(input()) for i in "abc"]
A, B, C = list(map(len, S))
L = 10**5
M = [[chk(S[i], S[j]) if i != j else [] for j in range(3)] for i in range(3)]
for i in [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1)]:
    L = min(L, tri_chk(i))
print(L)

def F(a, b):
    A, B = len(a), len(b)
    r = [0] * A
    for i in range(A):
        f = 1
        for j in range(min(A - i, B)):
            if len(set([a[i + j], b[j], "?"])) > 2:
                f = 0
                break
        r[i] = f
    return r + [1]


def T(ix):
    i1, i2, i3 = ix
    ab, bc, ac = M[i1][i2], M[i2][i3], M[i1][i3]
    A, B, C = list(map(len, [S[i] for i in ix]))
    q = A + B + C
    for l in range(A + 1):
        if ab[l] != 0:
            for r in range(l, A + B + 1):
                if (B < r - l or bc[r - l] == 1) and ac[min(A, r)] == 1:
                    q = min(q, max(A, l + B, r + C))
    return q


S = [eval(input()) for i in "abc"]
M = [[F(S[i], S[j]) if i != j else [] for j in range(3)] for i in range(3)]
print(
    (
        min(
            [
                T(i)
                for i in [
                    (0, 1, 2),
                    (0, 2, 1),
                    (1, 0, 2),
                    (1, 2, 0),
                    (2, 1, 0),
                    (2, 0, 1),
                ]
            ]
        )
    )
)

-def chk(a, b): +def F(a, b): -    rt = [0] * A +    r = [0] * A -        rt[i] = f -    return rt + [1] +        r[i] = f +    return r + [1] -def tri_chk(ix): +def T(ix): -    rt = A + B + C +    q = A + B + C -        if ab[l] == 0: -            continue -        for r in range(l, A + B + 1): -            if (B < r - l or bc[r - l] == 1) and ac[min(A, r)] == 1: -                rt = min(rt, max(A, l + B, r + C)) -    return rt +        if ab[l] != 0: +            for r in range(l, A + B + 1): +                if (B < r - l or bc[r - l] == 1) and ac[min(A, r)] == 1: +                    q = min(q, max(A, l + B, r + C)) +    return q -A, B, C = list(map(len, S)) -L = 10**5 -M = [[chk(S[i], S[j]) if i != j else [] for j in range(3)] for i in range(3)] -for i in [(0, 1, 2), (0, 2, 1), (1, 0, 2), (1, 2, 0), (2, 1, 0), (2, 0, 1)]: -    L = min(L, tri_chk(i)) -print(L) +M = [[F(S[i], S[j]) if i != j else [] for j in range(3)] for i in range(3)] +print( +    ( +        min( +            [ +                T(i) +                for i in [ +                    (0, 1, 2), +                    (0, 2, 1), +                    (1, 0, 2), +                    (1, 2, 0), +                    (2, 1, 0), +                    (2, 0, 1), +                ] +            ] +        ) +    ) +)