def main():
    a = input()
    b = input()
    c = input()
    A, B, C = len(a), len(b), len(c)
    ab = [True]*10000
    ac = [True]*10000
    bc = [True]*10000

    def check(c1, c2):
        if c1 == '?' or c2 == '?' or c1 == c2:
            return False
        return True

    for i in range(A):
        for j in range(B):
            if check(a[i], b[j]):
                ab[i-j+5000] = False
    for i in range(A):
        for j in range(C):
            if check(a[i], c[j]):
                ac[i-j+5000] = False
    for i in range(B):
        for j in range(C):
            if check(b[i], c[j]):
                bc[i-j+5000] = False
    ans = A + B + C
    for i in range(-(B+C), A+C):
        for j in range(-(B+C), A+B):
            if ab[i+5000] and ac[j+5000] and bc[j-i+5000]:
                L = min(0, i, j)
                R = max(A, i+B, j+C)
                ans = min(ans, R - L)
    print(ans)


main()
