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 in PyPy3 (2.4.0) (judge verdict: Runtime Error)

from itertools import permutations
def match(a,b):
    nb = len(b)
    na = len(a)
    res=0
    for i in range(1,nb+1):
        for j in range(i):
            if not(a[na-i+j] == b[j] or a[na-i+j] == '?' or  b[j] == '?'):
                break
        else:
            res=max(res,i)
    return res


a = input()
b = input()
c = input()
stls = [a,b,c]
ans=1001001001

for ls in permutations(stls):
    ansstring = ls[0]
    idx = match(ansstring, ls[1])
    ansstring += ls[1][idx:]
    idx = match(ansstring, ls[2])
    ansstring += ls[2][idx:]
    ans=min(ans,len(ansstring))

print(ans)