def F(a,b):

 A=len(a)

 r=[all([len(set([a[i+j],b[j],'?']))<3for j in range(min(A-i,len(b)))])for i in range(A)]

 return r+[1]

def Z(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']

T=list(range(3));M=[[F(S[i],S[j])for j in T]for i in T]

print((min([Z(i)for i in[(0,1,2),(0,2,1),(1,0,2),(1,2,0),(2,1,0),(2,0,1)]])))
def F(a,b):A=len(a);r=[all([len(set([a[i+j],b[j],'?']))<3for j in range(min(A-i,len(b)))])for i in range(A)];return r+[1]

def Z(X):

 i,j,k=X;U,V,W=M[i][j],M[j][k],M[i][k];A,B,C=list(map(len,[S[i]for i in X]));q=A+B+C

 for l in range(A+1):

  if U[l]!=0:

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

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

 return q

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

T=list(range(3))

M=[[F(S[i],S[j])for j in T]for i in T]

from itertools import *;print((min([Z(i)for i in permutations(T)])))
def F(a, b):
    A = len(a)
    r = [
        all([len(set([a[i + j], b[j], "?"])) < 3 for j in range(min(A - i, len(b)))])
        for i in range(A)
    ]
    return r + [1]


def Z(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"]
T = list(range(3))
M = [[F(S[i], S[j]) for j in T] for i in T]
print(
    (
        min(
            [
                Z(i)
                for i in [
                    (0, 1, 2),
                    (0, 2, 1),
                    (1, 0, 2),
                    (1, 2, 0),
                    (2, 1, 0),
                    (2, 0, 1),
                ]
            ]
        )
    )
)

def F(a, b):
    A = len(a)
    r = [
        all([len(set([a[i + j], b[j], "?"])) < 3 for j in range(min(A - i, len(b)))])
        for i in range(A)
    ]
    return r + [1]


def Z(X):
    i, j, k = X
    U, V, W = M[i][j], M[j][k], M[i][k]
    A, B, C = list(map(len, [S[i] for i in X]))
    q = A + B + C
    for l in range(A + 1):
        if U[l] != 0:
            for r in range(l, A + B + 1):
                if (B < r - l or V[r - l] == 1) and W[min(A, r)] == 1:
                    q = min(q, max(A, l + B, r + C))
    return q


S = [eval(input()) for i in "abc"]
T = list(range(3))
M = [[F(S[i], S[j]) for j in T] for i in T]
from itertools import *

print((min([Z(i) for i in permutations(T)])))

-def Z(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])) +def Z(X): +    i, j, k = X +    U, V, W = M[i][j], M[j][k], M[i][k] +    A, B, C = list(map(len, [S[i] for i in X])) -        if ab[l] != 0: +        if U[l] != 0: -                if (B < r - l or bc[r - l] == 1) and ac[min(A, r)] == 1: +                if (B < r - l or V[r - l] == 1) and W[min(A, r)] == 1: -print( -    ( -        min( -            [ -                Z(i) -                for i in [ -                    (0, 1, 2), -                    (0, 2, 1), -                    (1, 0, 2), -                    (1, 2, 0), -                    (2, 1, 0), -                    (2, 0, 1), -                ] -            ] -        ) -    ) -) +from itertools import * + +print((min([Z(i) for i in permutations(T)])))