function [D]=ELS(s,word1,word2,h)

r=length(s);
k=[];
for i=2:(r/3);
    for j=1:i;
        els=s(j:i:r);
        %word1
        k=strfind(els,word1);
        %[j i]
        if isempty(k)==0;
        break %if word found, then loop broken
        end
    end
    if isempty(k)==0;
        break %if word found, then loop broken
    end
end
if isempty(k)==0;
    k=k(1);
    whichelshasword1=[j i]; %assigns this variable only when word found
    helpsmakes1=(((k-1)*i+j):i:((k-1)*i+j+(length(word1)-1)*i));
    binarys1=zeros(1,length(s));
    binarys1(helpsmakes1)=1;
    s1=char(s.*binarys1);
    a1=makearray(s1,h);
    [row1,col1]=find(a1);
    dist1=norm([row1(2)-row1(1), col1(2)-col1(1)]);
else 
    %'word not found'
end

l=[];
for i=2:(r/3);
    %fprintf(1,'skip d= %1g\n',i)
    for j=1:i;
        %fprintf(1,'starting letter n= %1g',j)
        els=s(j:i:r);
        l=strfind(els,word2);
       
        if isempty(l)==0;
        break %if word found, then loop broken
        end
    end
    if isempty(l)==0;
        break %if word found, then loop broken
    end
end
if isempty(l)==0; 
   l=l(1);
   whichelshasword2=[j i]; %assigns this variable only when word found
   helpsmakes2=((l-1)*i+j):i:((l-1)*i+j+(length(word2)-1)*i);
    binarys2=zeros(1,length(s));
    binarys2(helpsmakes2)=1;
    s2=char(s.*binarys2);
    a2=makearray(s2,h);
    [row2,col2]=find(a2);

dist2=norm([row2(2)-row2(1), col2(2)-col2(1)]);
else 
    %'word not found'
end




if ((isempty(k)==0)&&(isempty(l)==0))
for i=1:length(word1);
    for j=1:length(word2);
        if i*j==1;
            L=sqrt(((row2(j)-row1(i))^2)+((col2(j)-(col1(i)))^2));
            
        else 
            maybeL=sqrt(((row2(j)-row1(i))^2)+((col2(j)-(col1(i)))^2));
            if maybeL < L;
                L=maybeL;
            end
        end
    end
end
D=(dist1)^2+(dist2)^2+L^2;
else 
    D=0;
end


