Problem:
 Score : 500 points    Problem Statement Snuke has a string s .
From this string, Anuke, Bnuke, and Cnuke obtained strings a , b , and c , respectively, as follows:   Choose a non-empty (contiguous) substring of s (possibly s itself). Then, replace some characters (possibly all or none) in it with ? s.   For example, if s is mississippi , we can choose the substring ssissip and replace its 1 -st and 3 -rd characters with ? to obtain ?s?ssip .  You are given the strings a , b , and c .
Find the minimum possible length of s .      Constraints  1 \leq |a|, |b|, |c| \leq 2000  a , b , and c consists of lowercase English letters and ? s.         Input Input is given from Standard Input in the following format:  a  b  c       Output Print the minimum possible length of s .        Sample Input 1 a?c
der
cod      Sample Output 1 7  For example, s could be atcoder .       Sample Input 2 atcoder
atcoder
???????      Sample Output 2 7  a , b , and c may not be distinct.

Solution (Python):
a = input()
b = input()
c = input()

la = len(a)
lb = len(b)
lc = len(c)

AB = [False]*la
AC = [False]*la
BA = [False]*lb
BC = [False]*lb
CA = [False]*lc
CB = [False]*lc
for i in range(la):
    for s,t in zip(a[i:],b):
        if not(s=='?' or t=='?' or s==t):
            break
    else:
        AB[i] = True
for i in range(la):
    for s,t in zip(a[i:],c):
        if not(s=='?' or t=='?' or s==t):
            break
    else:
        AC[i] = True
for i in range(lb):
    for s,t in zip(b[i:],a):
        if not(s=='?' or t=='?' or s==t):
            break
    else:
        BA[i] = True
for i in range(lb):
    for s,t in zip(b[i:],c):
        if not(s=='?' or t=='?' or s==t):
            break
    else:
        BC[i] = True
for i in range(lc):
    for s,t in zip(c[i:],a):
        if not(s=='?' or t=='?' or s==t):
            break
    else:
        CA[i] = True
for i in range(lc):
    for s,t in zip(c[i:],b):
        if not(s=='?' or t=='?' or s==t):
            break
    else:
        CB[i] = True

ans = la+lb+lc
for i in range(-(lb+lc),la+max(lb,lc)+1):
    if 0<=i<la:
        ab = AB[i]
    elif -lb<i<0:
        ab = BA[-i]
    else:
        ab = True
    if not ab: continue
    l = min(0,i)
    r = max(la,i+lb)
    if ans <= r-l : continue
    for j in range(-(lb+lc),la+max(lb,lc)+1):
        
        
        if 0<=j<la:
            ac = AC[j]
        elif -lc<j<0:
            ac = CA[-j]
        else:
            ac = True
            
        k = j-i
        if 0<=k<lb:
            bc = BC[k]
        elif -lc<k<0:
            bc = CB[-k]
        else:
            bc = True
        
        if ab and ac and bc:
            l = min(0,i,j)
            r = max(la,i+lb,j+lc)
            ans = min(ans,r-l)
print(ans)

Solution (Python):
import sys, itertools
range = xrange
input = raw_input

orda = ord('a')

A = [ord(c) - orda for c in input()]
B = [ord(c) - orda for c in input()]
C = [ord(c) - orda for c in input()]

A = [-1 if a == - 34 else a for a in A]
B = [-1 if a == - 34 else a for a in B]
C = [-1 if a == - 34 else a for a in C]

An = len(A)
Bn = len(B)
Cn = len(C)

 
ABhit = []
AChit = []
BChit = []

big = 4010
for i in range(-big,big):

    for j in range(max(0, i), min(An, Bn + i)):
        if A[j] != -1 and B[j - i] != -1 and A[j] != B[j - i]:
            break
    else:
        ABhit.append(i)

for i in range(-big,big):

    for j in range(max(0, i), min(An, Cn + i)):
        if A[j] != -1 and C[j - i] != -1 and A[j] != C[j - i]:
            break
    else:
        AChit.append(i)

for i in range(-big,big):

    for j in range(max(0, i), min(Bn, Cn + i)):
        if B[j] != -1 and C[j - i] != -1 and B[j] != C[j - i]:
            break
    else:
        BChit.append(i)

best = An + Bn + Cn
for i in ABhit:
    ind1 = 0
    ind2 = 0
    
    while ind1 < len(AChit) and ind2 < len(BChit):
        if AChit[ind1] - BChit[ind2] < i:
            ind1 += 1
        elif AChit[ind1] - BChit[ind2] > i:
            ind2 += 1
        else:
            j = AChit[ind1]
            best = min(best, max(An, Bn + i, Cn + j) - min(0,i,j))
            ind1 += 1




print best

Solution (Python):
K = 4000
A = input()
B = input()
C = input()
la, lb, lc = len(A), len(B), len(C)

def check(S, T):
    R = [1] * (K * 2 + 1)
    for i in range(-len(T), len(S)):
        for j in range(max(i, 0), min(len(S), len(T)+i)):
            if S[j] != T[j-i] and S[j] != "?" and T[j-i] != "?":
                R[i] = 0
                break
    return R

AB = check(A, B)
AC = check(A, C)
BC = check(B, C)

mi = K * 3
for ib in range(-K, K + 1):
    if AB[ib] == 0: continue
    for ic in range(-K, K + 1):
        if AC[ic] == 0 or BC[ic - ib] == 0: continue
        mi = min(mi, max(ib + lb, ic + lc, la) - min(ib, ic, 0))

print(mi)

Solution (Python):
K = 4000
A = input()
B = input()
C = input()
la, lb, lc = len(A), len(B), len(C)

def check(S, T):
    R = [1] * (K * 2 + 1)
    for i in range(-len(T), len(S)):
        for j in range(max(i, 0), min(len(S), len(T)+i)):
            if S[j] != T[j-i] and S[j] != "?" and T[j-i] != "?":
                R[i] = 0
                break
    return R

AB = check(A, B)
AC = check(A, C)
BC = check(B, C)

mi = K * 3
for i_ab in range(-K, K + 1):
    if AB[i_ab] == 0: continue
    for i_ac in range(max(-K, min(i_ab, 0) - lc), min(K + 1, max(la, i_ab + lb))):
        if AC[i_ac] == 0: continue
        if BC[i_ac - i_ab] == 0: continue
        mi = min(mi, max(i_ab + lb, i_ac + lc, la) - min(i_ab, i_ac, 0))

print(mi)

Solution (Python):
K = 4000
A = input()
B = input()
C = input()
la, lb, lc = len(A), len(B), len(C)

def check(S, T):
    R = [1] * (K * 2 + 1)
    for i in range(-len(T), len(S)):
        for j in range(max(i, 0), min(len(S), len(T)+i)):
            if S[j] != T[j-i] and S[j] != "?" and T[j-i] != "?":
                R[i] = 0
                break
    return R

AB = check(A, B)
AC = check(A, C)
BC = check(B, C)

mi = K * 3
for i_ab in range(-K, K + 1):
    if AB[i_ab] == 0: continue
    for i_ac in range(max(-K, min(i_ab, 0) - lc), min(K + 1, max(la, i_ab + lb))):
        if AC[i_ac] == 0: continue
        if BC[i_ac - i_ab] == 0: continue
        mi = min(mi, max(i_ab + lb, i_ac + lc, la) - min(i_ab, i_ac, 0))

print(mi)