a = input()
b = input()
c = input()
 
def common(s1, s2):
	l1 = len(s1)
	l2 = len(s2)
	memo = [[0 for i in range(l1+2)] for j in range(l2+2)]
 
	for idx1,w1 in enumerate(s1):
		for idx2,w2 in enumerate(s2):
			if w1==w2 or w1=='?'or w2=='?':
				memo[idx2+1][idx1+1] = memo[idx2][idx1] + 1
 
	return memo
m1 = 0
m2 = 0
m3 = 0
for l in common(a,b):
	if max(l)>m1:
		m1 = max(l)
for l in common(a,c):
	if max(l)>m2:
		m2 = max(l)
for l in common(b,c):
	if max(l)>m3:
		m3 = max(l)
ans=len(a)+len(b)+len(c)-m1-m2-m3+min([m1,m2,m3])
 
print(ans)