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)

a = input()
b = input()
c = input()
p = len(a)
q = len(b)
r = len(c)


def func(a, b):
    p = len(a)
    q = len(b)
    for i in range(p):
        f = 0
        for j in range(p - i):
            if a[j + i] != "?" and b[j] != "?" and a[j + i] != b[j]:
                break
            f += 1
        if f == p - i:
            return max(0, q - p + i)
    return q


r1 = func(a, b)
r2 = func(a, c)
r3 = func(b, a)
r4 = func(b, c)
r5 = func(c, a)
r6 = func(c, b)

res = []
res.append(p + r1 + r4)
res.append(p + r2 + r6)
res.append(q + r3 + r2)
res.append(q + r4 + r5)
res.append(r + r5 + r1)
res.append(r + r6 + r3)
print(min(res))