'''
Joydeep Mukherjee
Feb 4, 2020
Sr5
Enloe
Potter
'''

def lcs(x, y):
    valid = []
    xs = list(x[i:j+1] for i in range (len(x)) for j in range(i,len(x)))
    ys = list(y[i:j+1] for i in range (len(y)) for j in range(i,len(y)))
    max_l = -1
    for s in xs:
        if s in ys:
            if len(s) == max_l:
                valid.append((s, x.index(s), y.index(s), len(s)))
            elif len(s) > max_l:
                valid = []
                valid.append((s, x.index(s), y.index(s), len(s)))
                max_l = len(s)
    if not valid:
        return (None, 0, 0, 0)
    else:
        return min(valid, key = lambda t: t[0])

def adf(x, y):
    c, i, j, l = lcs(x, y)
    if c is None:
        return
    else:
        substr.append(c)
        adf(x[:i], y[:j])
        adf(x[i+l:], y[j+l:])

def compute():
    ans = 0
    for s in substr:
        ans += len(s)
    return ans

def rem(s):
    i = 0
    while i < len(s):
        if not s[i].isalpha():
            s = s[:i] + s[i+1:]
            i -= 1
        else:
            s = s[:i] + s[i].upper() + s[i+1:]
        i += 1
    return s

with open("F:/2srtest.txt") as f:
     for line in f:
        a, b, substr = line, f.readline(), []
        adf(rem(a), rem(b))
        print(compute())