def combine(a,b,x1,x2):
    num=x2-x1
    y1=b.index(a[x1:x2])
    y2=y1+num
    first=a[:x1],b[:y1]
    second=a[x2:],b[y2:]
    return first,second,num



def delete_common(tup):
    index1=[]
    length=len(tup[0])
    for i in range(length):
        if tup[0][i] in tup[1]:
            index1.append(i)
    if not index1:return False
    num=length-index1[0]
    for i in range(num,0,-1):
        temp=[]
        for index in index1:
            j=index+i
            if j>length:break
            if tup[0][index:j] in tup[1]:
                temp.append((tup[0][index:j],index,j))
        if temp:
            temp.sort()
            return combine(tup[0],tup[1],temp[0][1],temp[0][2])

import re
for i in range(5):
    result=0
    line1="".join(re.findall(r"[A-Za-z]",input()))
    line2="".join(re.findall(r"[A-Za-z]",input()))
    line1=line1.upper()
    line2=line2.upper()
    fringe=[(line1,line2)]
    while fringe:
        next_one=delete_common(fringe.pop())
        if next_one:
            result+=next_one[2]
            fringe.append(next_one[0])
            fringe.append(next_one[1])
    print(result)