from itertools import permutations

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 a[i+j]!=b[j] and a[i+j]!='?' and b[j]!='?':

                f=0;break

        rt[i]=f

    return rt+[1]



def tri_chk(ix):

    i1,i2,i3=ix

    a,b,c=[S[i] for i in ix]

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

    A,B,C=list(map(len,(a,b,c)))

    rt=A+B+C

    for l in range(A+1):

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

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

                        alt=max(A,l+B,r+C)

                        if alt<rt:

                            rt=alt

    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 permutations(list(range(3))):

    L=min(L,tri_chk(i))



print(L)
from itertools import permutations



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 a[i+j]!=b[j] and a[i+j]!='?' and b[j]!='?':

                f=0;break

        rt[i]=f

    return rt+[1]



def tri_chk(ix):

    i1,i2,i3=ix

    a,b,c=[S[i] for i in ix]

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

    A,B,C=list(map(len,(a,b,c)))

    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:

                alt=max(A,l+B,r+C)

                if alt<rt:

                    rt=alt

    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 permutations(list(range(3))):

    L=min(L,tri_chk(i))



print(L)
from itertools import permutations


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 a[i + j] != b[j] and a[i + j] != "?" and b[j] != "?":
                f = 0
                break
        rt[i] = f
    return rt + [1]


def tri_chk(ix):
    i1, i2, i3 = ix
    a, b, c = [S[i] for i in ix]
    ab, bc, ac = M[i1][i2], M[i2][i3], M[i1][i3]
    A, B, C = list(map(len, (a, b, c)))
    rt = A + B + C
    for l in range(A + 1):
        for r in range(l, A + B + 1):
            if ab[l] == 1 and (B < r - l or bc[r - l] == 1) and ac[min(A, r)] == 1:
                alt = max(A, l + B, r + C)
                if alt < rt:
                    rt = alt
    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 permutations(list(range(3))):
    L = min(L, tri_chk(i))
print(L)

from itertools import permutations


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 a[i + j] != b[j] and a[i + j] != "?" and b[j] != "?":
                f = 0
                break
        rt[i] = f
    return rt + [1]


def tri_chk(ix):
    i1, i2, i3 = ix
    a, b, c = [S[i] for i in ix]
    ab, bc, ac = M[i1][i2], M[i2][i3], M[i1][i3]
    A, B, C = list(map(len, (a, b, c)))
    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:
                alt = max(A, l + B, r + C)
                if alt < rt:
                    rt = alt
    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 permutations(list(range(3))):
    L = min(L, tri_chk(i))
print(L)

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