import sys
import re
import heapq

def maxCommonSubstr(s1,s2):
    if len(s1)> len(s2):
        s1,s2=s2,s1
    length=len(s1)
    result=[]
    for step in range(length,0,-1):
        for start in range(0,length-step+1):
            flag=True
            tmp=s1[start:start +step]
            if s2.find(tmp)>-1:
                result.append(tmp)
                flag=True
                newstart =start+1
                newstep=step
                while flag:
                    if newstart+step>length:
                        break
                    newtmp=s1[newstart:newstart+newstep]
                    if s2.find(newtmp)>-1:
                        result.append(newtmp)
                        newstart+=1
                        flag=True
                    else:
                        newstart+=1
                        flag=True
                heapq.heapify(result)
                return heapq.heappop(result)
            else: continue

def find_adf(str1,str2):
    adf=0
    #print("str1",str1,"str2",str2)
    if str1 and str2:
        substr=maxCommonSubstr(str1,str2)
        if substr:
            adf+=len(substr)
            left1=str1.find(substr)
            right1=left1+len(substr)
            left2=str2.find(substr)
            right2=left2+len(substr)
            if right1