a=[[[0]*101 for _ in range(101)] for __ in range(101)] i1,i2,i3=input(),input(),input() for i in range(1,len(i1)+1): for j in range(1,len(i2)+1): for k in range(1,len(i3)+1): if i1[i-1]==i2[j-1] and i2[j-1]==i3[k-1]: a[i][j][k]=a[i-1][j-1][k-1]+1 else: a[i][j][k]=max(a[i-1][j][k],a[i][j-1][k],a[i][j][k-1]) print(a[len(i1)][len(i2)][len(i3)])