function [out]=kamnie2(l,i,f,U,D,k)

    if l==5
        
        d{i,1,1}=f{i-1,1,1};
        out=d{i,1,1};
        out5=out;
    elseif l==6
        
        g=(f{i,1,1});
        h=(U{1,2});
        
        o=0;
        for m=1:3
            for n=1:3
                o=o+1;
                z(o)=g(m)+h(n);
            end
        end
                zz=sort(z);
                zz=unique(zz);
                [~,no]=size(zz);
                if no<k
                    for q=no+1:k
                        zz(q)=inf;
                    end
                end
                zz=zz(1:3);
                
                %ss=[zz cell2mat(f{i-1,1,3})];
                ss=[zz (f{i-1,1,2})];
                ss=sort(ss);
                ss=unique(ss);
                [~,no]=size(ss);
                if no<k
                    for q=no+1:k
                        ss(q)=inf;
                    end
                end
                d{i,1,2}=ss(1:3);
                out=d{i,1,2};
                out6=out;
                
    elseif l==7
        
        g=(f{i,1,1});
        h=(U{1,3});
        
        o=0;
        for m=1:3
            for n=1:3
                o=o+1;
                z(o)=g(m)+h(n);
            end
        end
                zz=sort(z);
                zz=unique(zz);
                [~,no]=size(zz);
                if no<k
                    for q=no+1:k
                        zz(q)=inf;
                    end
                end
                zz=zz(1:3);
                
                
        gg=(f{i,1,2});
        hh=(U{2,3});
        
        o=0;
        for m=1:3
            for n=1:3
                o=o+1;
                y(o)=gg(m)+hh(n);
            end
        end
                yy=sort(y);
                yy=unique(yy);
                [~,no]=size(yy);
                if no<k
                    for q=no+1:k
                        yy(q)=inf;
                    end
                end
                yy=yy(1:3); 
                                
                ss=[zz yy (f{i-1,1,3})];
                ss=sort(ss);
                ss=unique(ss);
                [~,no]=size(ss);
                if no<k
                    for q=no+1:k
                        ss(q)=inf;
                    end
                end
                d{i,1,3}=ss(1:3);
                
                out=d{i,1,3};
                out7=out;
                
    elseif l==8
        g=(f{i,1,1});
        h=(U{1,4});
        
        o=0;
        for m=1:3
            for n=1:3
                o=o+1;
                z(o)=g(m)+h(n);
            end
        end
                zz=sort(z);
                zz=unique(zz);
                [~,no]=size(zz);
                if no<k
                    for q=no+1:k
                        zz(q)=inf;
                    end
                end
                zz=zz(1:3);
                
                
        gg=(f{i,1,2});
        hh=(U{2,4});
        
        o=0;
        for m=1:3
            for n=1:3
                o=o+1;
                y(o)=gg(m)+hh(n);
            end
        end
                yy=sort(y);
                yy=unique(yy);
                [~,no]=size(yy);
                if no<k
                    for q=no+1:k
                        yy(q)=inf;
                    end
                end
                yy=yy(1:3); 
                       
        ggg=(f{i,1,3});
        hhh=(U{3,4});
        
        o=0;
        for m=1:3
            for n=1:3
                o=o+1;
                x(o)=ggg(m)+hhh(n);
            end
        end
                xx=sort(x);
                xx=unique(xx);
                [~,no]=size(xx);
                if no<k
                    for q=no+1:k
                        xx(q)=inf;
                    end
                end
                xx=xx(1:3); 
                                
                ss=[zz yy xx (f{i-1,1,4})];
                ss=sort(ss);
                ss=unique(ss);
                [~,no]=size(ss);
                if no<k
                    for q=no+1:k
                        ss(q)=inf;
                    end
                end
                d{i,1,4}=ss(1:3);
                out=d{i,1,4};
                out8=out;
                
    end
                
                
                
                
                
                
                
                
                
                
                
              
