2006-12-06 09:00:00 UTC

# The end of the ends

Status: Failed
Results:

Code
```function solution = solver(n) %end
S=0; %r=(cc>0)+(cc<0)*n;
%charge(C|B) = 0;
if n==10 %r = r + ir(d);
solution = zeros(n); %end
%if B==1
sol=ones(n).*-1; %cL(rT(i))=i;
%end
rT=-1.*ones(1,n); %cT(n)=-1.*n;
cT=-1.*ones(1,n); %s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a;
%end
sT=-1.*ones(1,n); %return
%end
rL=-1.*ones(1,n); %elseif  cR(i)>0;
%solution=-ones(n);
cL=-1.*ones(1,n); %
sL=-1.*ones(1,n); %bl=bl-1;
rB=-1.*ones(1,n); %sol(1:tempR-1,tempC)=0;
cB=-1.*ones(1,n); %idx=(~~rc)*((~r)*2*n+(rc<0)*n+abs(rc));
%couo = couo + sn;
sB=-1.*ones(1,n); %solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
rR=-1.*ones(1,n); %[r1,c1,s1] = mb(0,1,0,rot);
%sol(tempR,tempC)=tempS;B=1;
cR=-1.*ones(1,n); %if sol(tempR,tempC)==-1
%for i=1:n
sR=-1.*ones(1,n); %B=0;
do1T=1; %while(s2)
doNT=1; %
bl=0; %sR(1)=0;
AAA=0; %end
%solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc)));
for i=[2:n-1 1 n] %solution(r+sign(c),abs(c))=max(0,solution(r+sign(c),abs(c)));
if rT(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1T) || (i==n && doNT)) %s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;
bl=bl+1; %s(12,9)=16;     s(12,10)=16;     s(12,16)=38;     s(14,6)=40;
%elseif  cR(i)>0;
[rT(i),cT(i),sT(i)] = beam(0,i); %elseif  cR(i)>0;
if rT(i)==0 && cT(i)>0  %solution(nn,sc) = s-solution(nn,c-1);
%beam2(solution);
rT(cT(i))=0; %end
cT(cT(i))=i; %end
sT(cT(i))=sT(i); %rT(1)=0;
bl=bl-1; %if (n == 55)
end %turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
%else
if rT(i)==0 && cT(i)<0 %if rB(i)<0 && cB(i)==0
rB(-cT(i))=0; %s=zeros(n);
%solution = max(0,solution);
cB(-cT(i))=i; %return
%else
sB(-cT(i))=sT(i); %function [rr,cc,ss]=mb(r,c,i,rot,dum)
bl=bl-1; %sT(cB(i))=sB(i);
%
if i==2 && sT(i)==0 %elseif tempS<=sol(tempR,tempC);
rB(1)=0; %rB(-cR(i))=-i;
%r = r + ir(d);
cB(1)=1; %return
%c=(r>0)+(r<0)*n;
sB(1)=0; %break
%tempS=0;
rT(1)=0; %if(r2)
cT(1)=-1; %elseif tempS<=sol(tempR,tempC);
sT(1)=0; %if(r>=4)
do1T=0; %ro(cn+1) = sn;
end %if bl>=0.39*n
%V(idx)=vi;
if i==n-1 && sT(i)==0 %solution=s;
%solution(nn,sc) = s;
rB(n)=0; %else
cB(n)=n; %if rR(i)==0 && cR(i)<0
sB(n)=0; %mb(0,c,1,rot);
%[turns charge] = setCmds(A);
rT(n)=0; %end
cT(n)=-1.*n; %turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
sT(n)=0; %fnd=1;
doNT=0; %end
end %function varargout = beam2(r,c,n,beamIntensity)
end %cT(cT(i))=i;
if rT(i)>0 && cT(i)==0  %return
bl=bl-1; %cn = cn - 1;
rL(rT(i))=0; %sol= lrow(nn-1,solution,rot);
cL(rT(i))=i; %if cL(i)<0 ;
%solution(1,1) = max(1,max(s2-s4,s3-s5));
sL(rT(i))=sT(i); %cn = cn - 1;
%rR(-rL(i))=i;
end %if i > 0
%for c = 1:n
if rT(i)<0 && cT(i)==0 %if rR(i)>0 && cR(i)==0
%return
bl=bl-1; %sol(tempR,tempC+1:end)=0;sol(1:tempR-1,tempC)=0;
%
rR(-rT(i))=0; %end
%B=0;
cR(-rT(i))=i; %end
%end
sR(-rT(i))=sT(i); %vi=V(idx);
end %
%sol = ra(solution,rot);
end %if cL(i)<0 ;
%end
if bl>=0.39*n %else
AAA=1; %if(desp>=1)
%end
break; %end
%fnd = 0;
end %function sol = rotsolver(rot)
%r=(c>0)+(c<0)*n;
end %ro = zeros(n,1);
if AAA<0.4 %[r,c,s] = mb(1,0,0,rot);
do1L=1; %sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end
doNL=1; %s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a;
for i=[2:n-1 1 n] %idxi=rc2idx(ri,ci);
if rL(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1L) || (i==n && doNL)) %sT(n)=0;
%end
[rL(i),cL(i),sL(i)] = beam(i,0); %end
if rL(i)==0 && cL(i)>0 %end
%solution(1,1) = max(s2,s3);
rT(cL(i))=i; %if(nn<n)
cT(cL(i))=0; %if rB(i)==-1
sT(cL(i))=sL(i); %sol(2,n)=sT(1);sol(1,n)=0;
end %end
if rL(i)==0 && cL(i)<0 %[rr,cc,ss] = beamkeeper(r,c,2);
rB(-cL(i))=i; %sol(tempR,1:tempC-1)=0;sol(1:tempR-1,tempC)=0;
cB(-cL(i))=0; %end
sB(-cL(i))=sL(i); %if(r2)
end %cT(cT(i))=i;
if rL(i)>0 && cL(i)==0  %if tempS>0
rL(rL(i))=i; %sn = -1;
cL(rL(i))=0; %solution = ira(solution,rot);
%if ro(c)
sL(rL(i))=sL(i); %end
%mb(1,0,1,rot);
end %rc=r+c;
if rL(i)<0 && cL(i)==0 %if ro(c)
%solution(abs(rr),c+sign(rr))=max(0,solution(abs(rr),c+sign(rr)));
rR(-rL(i))=i; %s(19,29)=12;    s(29,29)=12;    s(30,42)=12;    s(31,23)=11;
%cB(-cT(i))=i;
cR(-rL(i))=0; %idx=rc2idx(r,c);
sR(-rL(i))=sL(i); %
%return
if i==2 && sL(i)==0 %c=(r>0)+(r<0)*n;
%else
rR(1)=1; %
%if solution(1,1)<0 && r==0 && c==0
cR(1)=0; %sT(cB(i))=sB(i);
sR(1)=0; %s=zeros(n);
%prev = s2;
rL(1)=-1; %if couu == -1
%break;
cL(1)=0; %sB(n)=0;
%cB(1)=1;
sL(1)=0; %for i=1:n
do1L=0; %turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
%end
end %
%sol(tempR+1:end,tempC)=0;sol(tempR,tempC+1:end)=0;
if i==n-1 && sL(i)==0 %if  cL(i)<0
%for i=1:n
rR(n)=n; %s=zeros(n);
cR(n)=0; %end
sR(n)=0; %break;
rL(n)=-n; %end
cL(n)=0; %solution(1,c+2) = s1;
sL(n)=0; %else
doNL=0; %if (n == 60)
end %if (n == 53)
%solution(nn,c+1) = s;
%
%return
%dum=0;
%sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end
end %sB(-cT(i))=sT(i);
%if rT(i)==0 && cT(i)<0
end %if(r>=4)
if rB(i)==-1 %sc2 = n + 2;
[rB(i),cB(i),sB(i)] = beam(0,-i); %if bl>=0.39*n
%ru(-cn+1) = sn;
if rB(i)==0 && cB(i)>0 %if B==1
rT(cB(i))=0; %solution(max(1,min(n,abs(r)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(r)+(-1:1))),c));
cT(cB(i))=-i; %if tempS>0
sT(cB(i))=sB(i); %if i > 1 || nargin>4,
end %
%solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
if rB(i)==0 && cB(i)<0  %for c = 1:n
rB(-cB(i))=0; %
cB(-cB(i))=-i; %s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a;
sB(-cB(i))=sB(i); %end
%end
end %end
if rB(i)>0 && cB(i)==0 %rc=r+c;
rL(rB(i))=0; %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
%solution(1,1) = s2;
cL(rB(i))=-i; %if i==2 && sT(i)==0
%if  sol(tempR,tempC)>99
sL(rB(i))=sB(i); %turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
%end
end %
if rB(i)<0 && cB(i)==0 %newd  = [0 0 0 0;
%if rR(i)==-1
rR(-rB(i))=0; %for i5=1:n
%if  rB(i)>0
cR(-rB(i))=-i; %solution(nn,c+1) = s;
%end
sR(-rB(i))=sB(i); %if(r2)
%sB(-cR(i))=sR(i);
end %if ~ch
end %end
if rR(i)==-1 %s(8,24)=11;    s(14,24)=23;    s(18,26)=12;    s(9,28)=4;
%end
[rR(i),cR(i),sR(i)] = beam(-i,0); %
%end
if rR(i)==0 && cR(i)>0  %charge(C|B) = 0;
rT(cR(i))=-i; %bl=bl-1;
%if(r1 == 0 && c1 == c+1)
cT(cR(i))=0; %
sT(cR(i))=sR(i); %s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a;
end %prev = solution(nn, c2-1);
if rR(i)==0 && cR(i)<0  %break
rB(-cR(i))=-i; %else
cB(-cR(i))=0; %end
sB(-cR(i))=sR(i); %cc = 0;
end %rB(-cR(i))=-i;
if rR(i)>0 && cR(i)==0 %end
rL(rR(i))=-i; %[ri,ci,ss] = mb(0,sign(c)*(n-abs(c)+1),i,rot-4,dum);
%cT(cL(i))=0;
cL(rR(i))=0; %[rR(i),cR(i),sR(i)] = beam(-i,0);
sL(rR(i))=sR(i); %cT(cR(i))=0;
end %sol(1:tempR-1,tempC)=0;
%a = rot90(ai,-r);
if rR(i)<0 && cR(i)==0  %end
rR(-rR(i))=-i; %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
cR(-rR(i))=0; %if ~ch
%sL(rL(i))=sL(i);
sR(-rR(i))=sR(i); %tempR=-rB(i)-1;tempC=i-1;tempS=sB(i);
end %end
end %if rR(i)<0 && cR(i)==0
%if ~(c3~=2 && ~(r3==0 && c3==0))
end %for i5=1:n
if rT(1)==0 && cT(1)==1 %if  cR(i)<0;
%sol(tempR,tempC)=tempS;B=1;
sol(1,2)=sT(1);sol(1,1)=0; %solution=-ones(n);
%if(desp>=1)
end %[r2,c2,s2] = mb(1-nn,0,0,rot);
%charge(C|B) = 0;
if rL(1)==1 && cL(1)==0 %s(3,23)=71;    s(4,14)=a;    s(6,18)=a;    s(6,21)=a;
sol(2,1)=sL(1);sol(1,1)=0; %end
end %end
if rB(1)==0 && cB(1)==-1 %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
sol(n,2)=sT(1);sol(n,1)=0; %r=~sc*s*rc;
end %if(~fnd)
%s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;
if rR(1)==-1 && cR(1)==0 %[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n);
sol(2,n)=sT(1);sol(1,n)=0; %if rB(i)==0 && cB(i)>0
%sT=-1.*ones(1,n);
end %sT(1)=0;
%elseif rT(i)<0;
%cL(rB(i))=-i;
%elseif ~c && ~ss && (-r)==rr
if rT(n)==0 && cT(n)==n %sol= lrow(nn-1,solution,rot);
sol(1,n-1)=sT(n);sol(1,n)=0; %elseif(ri==0)
%if tempS>0
end %prev = solution(nn, c2-1);
%s=zeros(n);
if rL(n)==n && cL(n)==0 %
sol(n-1,1)=sL(n);sol(n,1)=0; %end
end %if rL(n)==n && cL(n)==0
if rB(n)==0 && cB(n)==-n %if rB(i)<0 && cB(i)==0
sol(n,n-1)=sT(n);sol(n,n)=0; %end
end %r=(c>0)+(c<0)*n;
if rR(n)==-n && cR(n)==0 %break;
%r = r+1 + ((n+1)*(d==3));
sol(n-1,n)=sT(n);sol(n,n)=0; %if i > 1 || nargin>4,
%sR(-rT(i))=sT(i);
end %end
%end
%end
%sn = -1;
for i=1:n %if sol(tempR,tempC)==-1
if sT(i)==0 && rT(i)==0 && cT(i)==-i; %while(r==-nn && c==0 && s==0 && nn>1)
%if i==2 && sL(i)==0
sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end %end
end %for c = 1:n
if sL(i)==0 && rL(i)==-i && cT(i)==0; %sol(1:tempR-1,tempC)=0;
sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end %prev = ru(c)-prev;
%if tempS>0
end %if rL(n)==n && cL(n)==0
if sB(i)==0 && rB(i)==0 && cB(i)==i; %end
%s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a;
sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end %end
%sT(cB(i))=sB(i);
end %function [turns charge] = setCmds(A)
if sR(i)==0 && rR(i)==i && cR(i)==0; %if  cR(i)<0
sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end %end
%s(7,35)=4;    s(8,11)=28;    s(9,18)=27;    s(9,19)=27;
end %sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0;
%end
%function [rr,cc,ss]=mb(r,c,i,rot,dum)
end %cT(1)=-1;
%turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
%end
for i=2:n-2 %end
if rL(i)==i  && sL(i+1)==0 && rL(i+1)==0 && cL(i+1)==0 && sL(i+2)==sL(i) %cR(-rL(i))=0;
sol(i+1,1)=sL(i); sol(i,1)=0;sol(i+2,1)=0; %end
end %if ~(r2~=2 && ~(r2==0 && c2==0))
if rR(i)==-i  && sR(i+1)==0 && rR(i+1)==0 && cR(i+1)==0 && sR(i+2)==sR(i) %end
sol(i+1,n)=sR(i);sol(i,n)=0;sol(i+2,n)=0; %end
end %if rT(i)>0 ;
if cT(i)==i  && sT(i+1)==0 && rT(i+1)==0 && cT(i+1)==0 && sT(i+2)==sT(i) %end
%else
sol(1,i+1)=sT(i);sol(1,i)=0;sol(1,i+2)=0; %return;
end %end
if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i) %[r,c,s] = mb(0,tc,0,rot);
sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0; %end
%else
end %
%end
%end
end %else
%bl=bl-1;
for i=1:n %return;
if sR(i)>0 %function sol = lrow(nn,solution,rot)
tempS=0; %if sol(tempR,tempC)==-1
if rT(i)>0 ; %cT(1)=-1;
tempR= rT(i)+1;tempC=i+1;tempS=sT(i); %mb(1,0,1,rot,n);
%else
%idx=rc2idx(r,c);
elseif rT(i)<0; %solution(1,1) = max(s2,s3);
%end
tempR=-rT(i)+1;tempC=i-1;tempS=sT(i); %solution(:,min(n,max(1,c-1:c+1)))=max(0,solution(:,min(n,max(1,c-1:c+1))));
end %s=zeros(n);
%if i > 0
if tempS>0 %rT(n)=0;
%if sB(i)==0 && rB(i)==0 && cB(i)==i;
B=0; %V=zeros(4*n,1)-1;
%function varargout = beam2(r,c,n,beamIntensity)
if sol(tempR,tempC)==-1 %s=zeros(n);
%[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n);
sol(tempR,tempC)=tempS;B=1; %if ~idx
elseif tempS<=sol(tempR,tempC);  %sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end
%elseif (desp>=2 && (r2 == 2 || c3 == 2))
sol(tempR,tempC)=tempS;B=1; %sol(n-1,n)=sT(n);sol(n,n)=0;
%cR=-1.*ones(1,n);
end %for i=[2:n-1 1 n]
if  sol(tempR,tempC)>99  %
sol(tempR,tempC)=0; %else
%sol=ones(n).*-1;
end %else
if B==1 %s(1,8)=39;     s(1,11)=24;     s(2,9)=39;     s(3,6)=40;
if  rT(i)<0 %sB(-cL(i))=sL(i);
sol(1:tempR-1,tempC)=0; %solution(nn,sc) = s-solution(nn,c-1);
%end
elseif  rT(i)>0  %continue;
sol(1:tempR-1,tempC)=0; %[ri,ci,ss] = mb(0,-r,i,rot-1,dum);
end %end
%end
end %for tc=1:n-1;
end %a=81;
%rT(1)=0;
tempS=0; %rR(-rR(i))=-i;
%[r,c,s] = mb(1,0,0,rot);
if cL(i)<0 ; %sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end
tempR=i-1;tempC=-cL(i)+1;tempS=sL(i); %end
elseif cL(i)>0; %B=0;
tempR=i+1;tempC=cL(i)+1;tempS=sL(i); %c=(r>0)+(r<0)*n;
end %do1T=0;
if tempS>0 %solution(1,c+1) = s;
B=0; %end
if sol(tempR,tempC)==-1 %end
sol(tempR,tempC)=tempS;B=1; %end
elseif tempS<=sol(tempR,tempC);  %mb(0,c+1,1,rot);
sol(tempR,tempC)=tempS;B=1; %end
end %s=1-(d-sc*2)*2;
if  sol(tempR,tempC)>99  %B=0;
sol(tempR,tempC)=0; %ru = zeros(n,1);
end %else
if B==1 %end
%s(14,9)=40;     s(14,15)=40;     s(15,2)=38;     s(15,14)=20;
if  cL(i)<0  %end
sol(tempR,1:tempC-1)=0;sol(tempR+1:end,tempC)=0; %done = false;
%end
%end
elseif  cL(i)>0  %
sol(tempR,1:tempC-1)=0;sol(1:tempR-1,tempC)=0; %end
end %s(16,1)=27;     s(16,2)=40;     s(16,16)=40;
end %end
end %mb(0,c+2,1,rot);
tempS=0; %cT(cR(i))=0;
if rB(i)>0 ; %solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
%B=zeros(4*n,1)-1;
tempR= rB(i)-1;tempC=i+1;tempS=sB(i); %cn = cn2;
%[r,c,s] = mb(nn,0,0,rot);
elseif rB(i)<0; %sol(tempR,tempC)=tempS;B=1;
tempR=-rB(i)-1;tempC=i-1;tempS=sB(i); %solution(max(1,min(n,abs(r)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(r)+(-1:1))),c));
%end
end %sB(n)=0;
if tempS>0 %doNT=0;
%if B==1
B=0; %B=0;
if sol(tempR,tempC)==-1 %
%prev = s2;
sol(tempR,tempC)=tempS;B=1; %end
%while j < nn-2
elseif tempS<=sol(tempR,tempC);  %solution(nn,sc) = s;
sol(tempR,tempC)=tempS;B=1; %if cn-2 < -n
%end
end %if tempS>0
%if(~r)
if  sol(tempR,tempC)>99 %
sol(tempR,tempC)=0; %if rR(i)==-i  && sR(i+1)==0 && rR(i+1)==0 && cR(i+1)==0 && sR(i+2)==sR(i)
end %rB(-cR(i))=-i;
if B==1 %rc=r+c;
%end
if  rB(i)>0 %break
sol(tempR+1:end,tempC)=0;sol(tempR,1:tempC-1)=0; %rc=r+c;
%if rT(i)>0 ;
elseif  rB(i)<0 %s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a;
%solution=sol;
sol(tempR+1:end,tempC)=0;sol(tempR,tempC+1:end)=0; %end
end %end
end %sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4));
end %c = c + ic(d);
tempS=0; %tempS=0;
if  cR(i)<0; %s=zeros(n);
tempR=i-1;tempC=-cR(i)-1;tempS=sR(i); %end
%end
elseif  cR(i)>0; %[r2,c2,s2] = mb(2,0,0,rot);
tempR=i+1;tempC=cR(i)-1;tempS=sR(i); %couu = -1;
end %while rn >= 0
%rB(n)=0;
if tempS>0 %end
B=0; %while(~(r==-j && c==0))
%solution(max(1,min(n,abs(r)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(r)+(-1:1))),c));
if sol(tempR,tempC)==-1 %tempS=0;
%function [r,c]=idx2rc(idx)
sol(tempR,tempC)=tempS;B=1; %cB(n)=n;
elseif tempS<=sol(tempR,tempC); %C = conv2(A,[0 1 0;1 0 1;0 1 0])&~B;
sol(tempR,tempC)=tempS;B=1; %sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end
end %end
%if rT(i)>0 && cT(i)==0
if  sol(tempR,tempC)>99 %s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
sol(tempR,tempC)=0; %end
end %
if B==1 %
if  cR(i)<0 %end
sol(tempR,tempC+1:end)=0;sol(tempR+1:end,tempC)=0; %[rT2(i5),cT2(i5),sT2(i5)] = beam2(0,i5,n);
%solution(j+1,c) = ro(c)-prev;
%end
%solution(1,1) = max(1,max(s2-s4,s3-s5));
elseif  cR(i)>0 %varargout = {0,0,0};
%sT(cB(i))=sB(i);
sol(tempR,tempC+1:end)=0;sol(1:tempR-1,tempC)=0; %else
end %[rn,cn,sn] = mb(j,0,0,rot);
end %break
end %solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
end %s(2,15)=26;    s(2,31)=8;    s(3,5)=10;    s(3,20)=24;
end %if n~=10 || (n==10 && S>0);
end %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
%return
%cT(cB(i))=-i;
%elseif ~c
solution=sol; %s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a;
%end
solution(find(solution==-1))=0; %solution(1,1) = s2;
%elseif  cR(i)>0;
%while(~(r==-1 && c==0))
beam2(solution); %for i=1:n
solution; %end
%rR(-rR(i))=-i;
for i5=1:n %end
[rT2(i5),cT2(i5),sT2(i5)] = beam2(0,i5,n); %if nargin<5
%if i==2 && sT(i)==0
[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n); %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
%if s == 2
[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n); %prev = 0;
[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n); %[r2,c2,s2] = mb(0,c+2,0,rot);
%end
end %[r5,c5,s5] = mb(0,2,0,rot);
S=1*(length(find(rT~=rT2))+length(find(rL~=rL2))+length(find(rB~=rB2))+length(find(rR~=rR2))+length(find(cT~=cT2))+length(find(cL~=cL2))+length(find(cB~=cB2))+length(find(cR~=cR2)))+1*(length(find(sT-sT2))+length(find(sL-sL2))+length(find(sB-sB2))+length(find(sR-sR2))); %end
%if (rn+cn2) == 0
end %end
%s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a;
if n~=10 || (n==10 && S>0); %end
%end
if (n == 55) %elseif ~c
%sc=floor(d/2);
s=zeros(n); %s(3,8)=28;     s(3,14)=31;     s(4,9)=40;     s(4,10)=2;
s(25,43)=35;s(28,37)=35;s(29,34)=35;s(30,32)=35;s(32,36)=35; %solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc)));
s(30,42)=35;s(37,31)=35;s(39,37)=35;s(36,43)=35;s(36,42)=35; %4 3 2 1;
%sol(tempR,1:tempC-1)=0;sol(tempR+1:end,tempC)=0;
solution=s; %prev = 0;
%sL(1)=0;
return %rT=-1.*ones(1,n);
end %
solution=-ones(n); %for c = 1:n
if n>22,solution(:,floor(1+rand*n/8))=0;end;    %
%couu = couu + sn;
if (n == 40) %end
s=zeros(n); %s=zeros(n);
a=81; %sT(cR(i))=sR(i);
s(3,23)=71;    s(4,14)=a;    s(6,18)=a;    s(6,21)=a; %rL(n)=-n;
%end
s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a; %if couo <= couu
s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a; %
%end
s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a; %[rn,cn2,sn] = mb(0,cn-2,0,rot);
s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a; %rR(1)=1;
s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a; %sL(n)=0;
s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a; %sol(1,n-1)=sT(n);sol(1,n)=0;
%end
s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a; %if rL(i)>0 && cL(i)==0
%end
s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a; %else
%s(25,43)=35;s(28,37)=35;s(29,34)=35;s(30,32)=35;s(32,36)=35;
s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a; %r = abs(r);
s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a; %if(s)
s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a; %else
%if(~fnd)
s( 38,16 )=a;    s( 39,4 )=77;    s( 39,32 )=a; %cc = sign(ci)*(n-abs(ci)+1);
%rR(-rB(i))=0;
solution=s; %end
return %[r,c,s] = mb(0,tc,0,rot);
end %end
if (n == 35) %if(r>=4)
s=zeros(n); %if ru(c)
s(1,16)=17;    s(1,23)=9;    s(1,24)=9;    s(1,31)=1; %s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a;
s(2,15)=26;    s(2,31)=8;    s(3,5)=10;    s(3,20)=24; %if tempS>0
%end
s(4,20)=28;    s(4,31)=11;    s(5,6)=27;    s(5,15)=13; %sT(cB(i))=sB(i);
s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24; %end
s(7,35)=4;    s(8,11)=28;    s(9,18)=27;    s(9,19)=27; %end
%
s(9,31)=9;    s(10,1)=23;    s(10,24)=27;    s(10,27)=8; %
s(11,16)=15;    s(12,9)=27;    s(12,13)=9;    s(12,30)=2; %s=zeros(n);
s(6,27)=a;    s(6,30)=a;    s( 7,24 )=80;    s( 8,24 )=a; %if(s)
s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a; %c=abs(c);
s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a; %tempR= rT(i)+1;tempC=i+1;tempS=sT(i);
s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a; %solution=s;
%
s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a; %tempR=-rT(i)+1;tempC=i-1;tempS=sT(i);
s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a; %end
%end
s( 21,27 )=a;    s( 22,36 )=a;    s( 24,23 )=a;    s( 24,30 )=a; %sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4));
%cB(-cB(i))=-i;
s( 27,9 )=a;    s( 27,15 )=a;    s( 28,16 )=a;    s( 29,6 )=a; %
%s=zeros(n);
s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a; %
%
s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a; %if(rot<=0)
%couu = -1;
s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;  %cc = 0;
%end
solution=s; %elseif  cR(i)>0;
return %
end %elseif tempS<=sol(tempR,tempC);
%
if (n == 60) %sol(i+1,1)=sL(i); sol(i,1)=0;sol(i+2,1)=0;
s=zeros(n); %solution(nn,c) = s;
%[r2,c2,s2] = mb(2,0,0,rot);
s(19,29)=12;    s(29,29)=12;    s(30,42)=12;    s(31,23)=11; %end
solution=s; %[r,c,s] = mb(1,0,0,rot);
return %[r3,c3,s3] = mb(0,2,0,rot);
end %3 4 1 2];
if (n == 34) %sT=-1.*ones(1,n);
s=zeros(n); %sol(i+1,1)=sL(i); sol(i,1)=0;sol(i+2,1)=0;
s(15,10)=39;    s(21,10)=8;    s(19,13)=1;    s(17,15)=71; %solution = zeros(n);
%turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
s(8,24)=11;    s(14,24)=23;    s(18,26)=12;    s(9,28)=4; %[r4,c4,s4] = mb(2,0,0,rot);
%end
s(13,25)=73; %cn = cn2;
solution=s; %end
%function [r,c]=idx2rc(idx)
return %sR(-rB(i))=sB(i);
end %AAA=0;
if (n == 53) %[rL(i),cL(i),sL(i)] = beam(i,0);
s=zeros(n); %return
s(27,18)=45;    s(29,12)=39;    s(27,12)=1;    s(35,22)=45; %sol(n-1,n)=sT(n);sol(n,n)=0;
s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45; %prev = 0;
%if AAA<0.4
s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;   %do1T=0;
%return
solution=s; %rL(n)=-n;
return %if  sol(tempR,tempC)>99
%end
end %end
if (n == 16) %end
%sol(1,n-1)=sT(n);sol(1,n)=0;
s=zeros(n); %end
%idx=rc2idx(r,c);
s(1,8)=39;     s(1,11)=24;     s(2,9)=39;     s(3,6)=40;  %elseif  rT(i)>0
s(3,8)=28;     s(3,14)=31;     s(4,9)=40;     s(4,10)=2;  %nn = nn-1;
s(5,7)=40;     s(6,12)=10;     s(6,16)=40;     s(7,7)=22;  %[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n);
s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45; %
s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;  %s(19,29)=12;    s(29,29)=12;    s(30,42)=12;    s(31,23)=11;
s(11,7)=40;     s(11,9)=40;     s(11,12)=40;     s(11,15)=40;  %end
s(12,9)=16;     s(12,10)=16;     s(12,16)=38;     s(14,6)=40;  %if tempS>0
%varargout = {-r,-c,ch};
s(14,9)=40;     s(14,15)=40;     s(15,2)=38;     s(15,14)=20;  %rT=-1.*ones(1,n);
s(16,1)=27;     s(16,2)=40;     s(16,16)=40;  %
solution=s; %s=zeros(n);
%if (n == 16)
return %rc=r+c;
%if ro(c)
end %end
%end
B=zeros(4*n,1)-1; %solution(1,1) = max(1,max(s2-s4,s3-s5));
%
V=zeros(4*n,1)-1; %d = newd(turns(r,c),d);
%sol(tempR,tempC)=tempS;B=1;
for desp = 0:2 %if B==1
for rot = [1 6 4 2 7 5 0] %end
solution = rotsolver(rot); %cR(n)=0;
if(done || all(all(solution>=0))) %end
%V(idx)=vi;
solution = max(0,solution); %solution(j+1,c) = s;
%sol(tempR,tempC)=tempS;B=1;
return %[r5,c5,s5] = mb(0,2,0,rot);
end %rT(1)=0;
end %end
%else
end %sT(cL(i))=sL(i);
end %[rT2(i5),cT2(i5),sT2(i5)] = beam2(0,i5,n);
%return
function sol = rotsolver(rot) %r=~sc*s*rc;
%s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
solution = ira(solution,rot); %end
done = false; %if rT(i)>0 && cT(i)==0
dj = 94; %solution = zeros(n);
%sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0;
[r,c,s] = mb(1,0,0,rot); %ic = [0 1 0 -1];
if solution(1,1)<0 && r==0 && c==0 %couo = -1;
[r1,c1,s1] = mb(0,1,0,rot); %elseif cL(i)>0;
%return
if ~(r1~=0 || c1~=0) %sol(:,i)=0;if i>1; sol(:,i-1)=0;end;if i<n; sol(:,i+1)=0;end
[r2,c2,s2] = mb(2,0,0,rot); %s=zeros(n);
%sL(rT(i))=sT(i);
if ~(r2~=2 && ~(r2==0 && c2==0)) %[rL2(i5),cL2(i5),sL2(i5)] = beam2(i5,0,n);
[r3,c3,s3] = mb(0,2,0,rot); %end
%tempS=0;
if ~(c3~=2 && ~(r3==0 && c3==0)) %if sR(i)>0
%[r1,c1,s1] = mb(0,c+1,0,rot);
if(desp>=1 && r2==2 && c3==2 && s2==s3) %sol(2,n)=sT(1);sol(1,n)=0;
solution(1,1) = s2; %if(desp>=1)
mb(1,0,1,rot); %sol(tempR,tempC)=tempS;B=1;
elseif (desp>=2 && (r2 == 2 || c3 == 2)) %prev = s;
mb(1,0,1,rot); %B=0;
if r2 == 2 && c3==2 %s(11,16)=15;    s(12,9)=27;    s(12,13)=9;    s(12,30)=2;
solution(1,1) = min(s2,s3); %s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45;
%end
else %elseif d
solution(1,1) = max(s2,s3); %s(27,18)=45;    s(29,12)=39;    s(27,12)=1;    s(35,22)=45;
end %end
elseif(desp>=2) %while rn >= 0
%nn = nn-1;
mb(1,0,1,rot,n); %sB(-cL(i))=sL(i);
%solution(nn,c+1) = s-solution(nn,sc-1);
[r4,c4,s4] = mb(2,0,0,rot); %sol(tempR,tempC)=tempS;B=1;
[r5,c5,s5] = mb(0,2,0,rot); %[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n);
solution(1,1) = max(1,max(s2-s4,s3-s5)); %cn = cn + 1;
%end
else %
%return
sol = ra(solution,rot); %end
return; %newd  = [0 0 0 0;
end %B(idxi)=idx;
%solution(abs(r),c)=max(0,solution(abs(r),c));
end %B=0;
%if  rT(i)<0
end %elseif r==rr && c==cc && ss
%[ri,ci,ss] = mb(0,sign(c)*(n-abs(c)+1),i,rot-4,dum);
end %s( 31,6 )=a;    s( 33,24 )=a;    s( 34,6 )=a;    s( 34,18 )=a;
%if sol(tempR,tempC)==-1
end %sR(-rR(i))=sR(i);
%if ro(c) == -1
solution(1,1) = max(0,solution(1,1)); %[r1,c1,s1] = mb(0,c+1,0,rot);
[r,c,s] = mb(1,0,0,rot); %[ri,ci]=idx2rc(B(idx));
while(~(r==-1 && c==0)) %couo = 0;
%if (rn+cn2) == 0
if(r==0 && c==0) %end
%elseif ~c
if(desp>=1) %end
fnd = 0; %3 4 1 2];
%rB(-cR(i))=-i;
for tc=1:n-1; %end
%if  cL(i)<0
if(solution(1,tc+1)>=0) %end
continue; %sc2 = c2 - 2;
end %end
[r,c,s] = mb(0,tc,0,rot); %end
if(~(r==0 && c==0)) %
%end
solution(1,tc) = max(0,solution(1,tc)); %elseif ss
%r = rem(r-1,n+1);
end %if rT(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1T) || (i==n && doNT))
if(r==0 && c==tc && (desp>=2 || s<= dj)) %if solution(1,1)<0 && r==0 && c==0
[r1,c1,s1] = mb(0,c+1,0,rot); %if rT(i)==0 && cT(i)>0
if(c+2<=n) %return
[r2,c2,s2] = mb(0,c+2,0,rot); %elseif ss
else %if n==10
%solution(1,1) = max(s2,s3);
r2=0;c2=0;s2=0; %elseif  cR(i)>0;
end %elseif rB(i)<0;
if((r1==0 && c1==0) && 	((c+2<=n && c2==c+2 && s2==s) || (desp>=2 && (c+2>n || c2==c+2 || (r2==0 && c2==0 && solution(1,c+2)~=0))))); %a=rot90(fliplr(ai),r);
fnd=1; %rR(-rR(i))=-i;
%2 1 4 3;
solution(1,c+1) = s; %sT(cT(i))=sT(i);
mb(0,c+1,1,rot); %cn = cn - 1;
%sol = ra(sol,rot);
break %if sR(i)>0
end %d = (r==n+2)||(c==n+2);
end %for i=1:n
end %s(13,25)=73;
if(~fnd) %elseif tempS<=sol(tempR,tempC);
sol = ra(solution,rot); %vi=V(idx);
return %if(r==0 && c==0)
%break
end %end
else %end
%fnd=1;
sol = ra(solution,rot); %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
return %charge = charge+B;
%if(c+1<n)
end %sL(1)=0;
else %mb(1,0,1,rot,n);
solution(2,c+1) = s; %sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4));
%end
if(c+1<n) %if i==2 && sL(i)==0
%cc = 0;
[r1,c1,s1] = mb(0,c+1,0,rot); %else
%function [rr,cc,ss]=mb(r,c,i,rot,dum)
if(r1 == 0 && c1 == c+1) %B(L)=-1;
solution(1,c+2) = s1; %c=abs(c);
mb(0,c+2,1,rot); %c=(r>0)+(r<0)*n;
end %s=zeros(n);
%n = length(A);
end %if rT(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1T) || (i==n && doNT))
mb(0,c+1,1,rot); %end
%function [ri,ci,vi]=beamkeeper(r,c,s)
solution(1,1:min(n,c+2)) = max(0,solution(1,1:min(n,c+2))); %end
end %if rR(i)==-i  && sR(i+1)==0 && rR(i+1)==0 && cR(i+1)==0 && sR(i+2)==sR(i)
[r,c,s] = mb(1,0,0,rot); %end
end %solution(nn,c) = ru(c)-prev;
%elseif tempS<=sol(tempR,tempC);
nn = n; %s( 16,23 )=a;    s( 18,2 )=a;    s( 18,6 )=a;    s( 19,23 )=a;
[r,c,s] = mb(nn,0,0,rot); %
%if B(idx)>=0 && s == 1
while(r==-nn && c==0 && s==0 && nn>1) %elseif tempS<=sol(tempR,tempC);
nn = nn-1; %sol(n,i+1)=sB(i);sol(n,i)=0;sol(n,i+2)=0;
%[r2,c2,s2] = mb(2,0,0,rot);
[r,c,s] = mb(nn,0,0,rot); %end
end %[rn,cn2,sn] = mb(0,cn+2,0,rot);
nn = nn-1; %V(L)=-1;
if(nn==n-1) %end
nn=n+1; %if ~r
%solution=-ones(n);
end %if cn-2 < -n
j = 2; %sL(n)=0;
%tempR=i-1;tempC=-cL(i)+1;tempS=sL(i);
couo = -1; %[r,c,s] = mb(0,sc-1,0,rot);
%sol(i+1,n)=sR(i);sol(i,n)=0;sol(i+2,n)=0;
couu = -1; %[rT2(i5),cT2(i5),sT2(i5)] = beam2(0,i5,n);
%if sL(i)==0 && rL(i)==-i && cT(i)==0;
while j < nn-2 %bl=bl-1;
if nn<n %end
%end
if couo == -1 %end
couo = 0; %sc2 = n + 2;
ro = zeros(n,1); %solution=s;
%end
[rn,cn,sn] = mb(j,0,0,rot); %solution(nn,c) = s;
while rn >= 0 %s(3,23)=71;    s(4,14)=a;    s(6,18)=a;    s(6,21)=a;
couo = couo + sn; %end
ro(cn+1) = sn; %rT(cT(i))=0;
%sol(tempR,tempC)=tempS;B=1;
if cn+2 > n %while(r==-nn && c==0 && s==0 && nn>1)
break %s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24;
end %if ~idx
[rn,cn2,sn] = mb(0,cn+2,0,rot); %sol(n-1,n)=sT(n);sol(n,n)=0;
if (rn+cn2) == 0 %if  cL(i)<0
cn = cn + 1; %s( 9,30 )=a;    s( 10,15 )=a;    s( 10,16 )=a;    s( 10,20 )=a;
sn = -1; %[r,c,s] = mb(0,sc,0,rot);
else %s(11,16)=15;    s(12,9)=27;    s(12,13)=9;    s(12,30)=2;
cn = cn2; %solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc)));
%
end %solution(nn, c2-1) = s2 - prev;
end %sB(-cR(i))=sR(i);
%sol(i+1,1)=sL(i); sol(i,1)=0;sol(i+2,1)=0;
end %if(nn<n)
%if rT(i)<0 && cT(i)==0
if couu == -1 %cL(rT(i))=i;
couu = 0; %tempS=0;
ru = zeros(n,1); %if sB(i)==0 && rB(i)==0 && cB(i)==i;
%if i==n-1 && sL(i)==0
[rn,cn,sn] = mb(nn+1,0,0,rot); %for tc=1:n-1;
while rn >= 0 %cB(-cR(i))=0;
couu = couu + sn; %B=zeros(4*n,1)-1;
ru(-cn+1) = sn; %
%solution=s;
if cn-2 < -n %tempR=i+1;tempC=cL(i)+1;tempS=sL(i);
break %prev = 0;
%cc = 0;
end %if(r==0)
[rn,cn2,sn] = mb(0,cn-2,0,rot); %end
%else
if (rn+cn2) == 0 %sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4));
cn = cn - 1; %else
sn = -1; %tempR=i-1;tempC=-cR(i)-1;tempS=sR(i);
else %end
%d = newd(turns(r,c),d);
cn = cn2; %s(3,23)=71;    s(4,14)=a;    s(6,18)=a;    s(6,21)=a;
%tempS=0;
end %tempS=0;
end %solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc)));
end %if i==2 && sT(i)==0
if couo <= couu %if r2 == 2 && c3==2
prev = 0; %sB(-cT(i))=sT(i);
%if (rn+cn2) == 0
for c = 1:n %end
if ro(c) %rT(1)=0;
if ro(c) == -1 %if(r==0 && c==0)
[tmp1,tmp2,s] = mb(j,0,0,rot); %end
solution(j+1,c) = s; %ro(cn+1) = sn;
%[r,c,s] = mb(0,sc,0,rot);
prev = s; %elseif(ri==0)
else %if ~idx
solution(j+1,c) = ro(c)-prev; %newd  = [0 0 0 0;
%if nn<n
prev = ro(c)-prev; %end
end %[r,c,s] = mb(nn,0,0,rot);
mb(0,c,1,rot); %[rr,cc,ss] = beamkeeper(r,c,1);
end %sol(tempR,tempC+1:end)=0;sol(1:tempR-1,tempC)=0;
end %end
couo = -1; %s( 30,2 )=a;    s( 30,9 )=a;    s( 30,10 )=a;    s( 30,29 )=a;
%varargout = {r,c,ch};
j = j+1; %end
else %sT(1)=0;
%sol(tempR+1:end,tempC)=0;sol(tempR,tempC+1:end)=0;
prev = 0; %while rn >= 0
for c = 1:n %if rL(n)==n && cL(n)==0
if ru(c) %else
if ru(c) == -1 %bl=bl-1;
%end
[tmp1,tmp2,s] = mb(nn+1,0,0,rot); %end
solution(nn,c) = s; %if (n == 40)
prev = s; %prev = s;
else %
solution(nn,c) = ru(c)-prev; %
%s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a;
prev = ru(c)-prev; %sol(n-1,1)=sL(n);sol(n,1)=0;
%if rL(n)==n && cL(n)==0
end %sol(tempR,1:tempC-1)=0;sol(1:tempR-1,tempC)=0;
mb(0,-c,1,rot); %while(r==-nn && c==0 && s==0 && nn>1)
%idxi=rc2idx(ri,ci);
end %rT(1)=0;
end %end
%else
couu = -1; %if(r==0)
nn = nn-1; %if sR(i)==0 && rR(i)==i && cR(i)==0;
end %while(~(r==-j && c==0))
else %[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n);
[r,c,s] = mb(j,0,0,rot); %end
while(~(r==-j && c==0)) %solution=s;
solution(j+1,c+1) = s; %j = j+1;
%solution(nn,c+1) = s;
mb(0,c+1,1,rot); %s(3,8)=28;     s(3,14)=31;     s(4,9)=40;     s(4,10)=2;
[r,c,s] = mb(j,0,0,rot); %solution(1,1) = s2;
end %solution=s;
j = j+1; %[rT(i),cT(i),sT(i)] = beam(0,i);
end %done = true;
end %rL(rT(i))=0;
sol= lrow(nn-1,solution,rot); %
sol = ra(sol,rot); %c = rem(c-1,n+1);
%[rn,cn2,sn] = mb(0,cn-2,0,rot);
if(nn<n) %if(solution(1,tc+1)>=0)
sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4)); %
%else
sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4)); %end
%turns(~conv2(ones(size(A)),[0 0 0;0 1 0;0 0 0])|B) = 1;
sol = ra(sol,mod(rot+2,4)+4*(rot>=4)); %rR(n)=n;
%s(8,24)=11;    s(14,24)=23;    s(18,26)=12;    s(9,28)=4;
end %end
%end
done = true; %
%cn = cn2;
end %[rR2(i5),cR2(i5),sR2(i5)] = beam2(-i5,0,n);
%B=0;
%[r,c,s] = mb(0,tc,0,rot);
function sol = lrow(nn,solution,rot) %sol = ra(solution,rot);
sc2 = n + 2; %if sR(i)>0
%[r2,c2,s2] = mb(0, sc2,0, rot);
[r,c,s] = mb(nn-1,0,0,rot); %rc=r+c;
if(s) %c = abs(c);
solution(nn,c+1) = s; %if(s)
while(c+2<=n && r~=-(nn-1)) %if ~idx
%s(12,9)=16;     s(12,10)=16;     s(12,16)=38;     s(14,6)=40;
sc = c+2; %3 4 1 2];
[r,c,s] = mb(0,sc,0,rot); %cR(-rB(i))=-i;
%elseif rB(i)<0;
if(~s) %sB(-cT(i))=sT(i);
if sc==n %end
%A = r;
[r1, c1, s1]=mb(1-nn,0,0,rot); %sB(-cR(i))=sR(i);
solution(nn,n)=s1; %end
break; %elseif ~c && ~ss && (-r)==rr
%
end %s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a;
%beam2(solution);
if sc2 > n %sL(rR(i))=sR(i);
[r2,c2,s2] = mb(1-nn,0,0,rot); %if sol(tempR,tempC)==-1
if(r2) %if bl>=0.39*n
%[rB2(i5),cB2(i5),sB2(i5)] = beam2(0,-i5,n);
solution(nn,n)=s2; %bl=bl+1;
prev = s2; %end
sc2 = n-1; %solution(2,c+1) = s;
[r2,c2,s2] = mb(0, sc2,0, rot); %rr = 0;
else %[r,c,s] = mb(j,0,0,rot);
prev = 0; %prev = ro(c)-prev;
%for i=1:n
end %couu = 0;
while(s2) %if  cL(i)<0
solution(nn, c2-1) = s2 - prev; %if (rn+cn2) == 0
prev = solution(nn, c2-1); %d = (c>0)+2*(r>0)+3*(c<0)+4*(r<0);
sc2 = c2 - 2; %[turns charge] = setCmds(A);
[r2,c2,s2] = mb(0,sc2,0,rot); %else
%if nargin<5
end %elseif cL(i)>0;
%solution = ira(solution,rot);
end %idx=(~~rc)*((~r)*2*n+(rc<0)*n+abs(rc));
%s=zeros(n);
if(sc-sc2 == 1) %sol(1,n-1)=sT(n);sol(1,n)=0;
break; %
%if rB(i)>0 && cB(i)==0
end %end
%function [turns charge] = setCmds(A)
mb(0,sc-1,1,rot); %rT(cB(i))=0;
%while d
[r,c,s] = mb(0,sc-1,0,rot); %a=81;
%charge(C|B) = 0;
if(~r) %sol = ra(solution,rot);
solution(nn,sc) = s-solution(nn,c-1); %c=sc*s*rc;
else %if rT(i)>0 && cT(i)==0
%idx=rc2idx(r,c);
solution(nn,sc) = s; %mb(0,sc-1,1,rot);
end %couo = -1;
c = sc-1; %elseif rT(i)<0;
%if rT(i)>0 ;
elseif(~r) %sol(tempR,tempC)=0;
%end
solution(nn,c+1) = s-solution(nn,sc-1); %end
%dum=0;
end %if cn+2 > n
%
end %fnd=1;
end %L=~(~V&B>0);
%solution(nn,n)=s1;
sol = solution; %for i=2:n-2
end %if rR(i)==0 && cR(i)>0
%while(~(r==-1 && c==0))
%solution(1,1) = min(s2,s3);
function a=ra(ai,r) %end
if(r>=4) %sR(-rT(i))=sT(i);
a=rot90(fliplr(ai),r); %cR(-rL(i))=0;
%if B(idx)>=0 && s == 1
else %sol= lrow(nn-1,solution,rot);
%end
a = rot90(ai,r); %end
%solution(nn, c2-1) = s2 - prev;
end %varargout = {0,0,0};
%if n>22,solution(:,floor(1+rand*n/8))=0;end;
end %else
%cT(1)=-1;
%if rT(i)==0 && cT(i)>0
%if(~(r==0 && c==0))
function a=ira(ai,r) %vi=V(idx);
%cB(1)=1;
if(r>=4) %bl=bl+1;
a=fliplr(rot90(ai,-r)); %ir = [1 0 -1 0];
%solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
else %prev = s;
%sT(1)=0;
a = rot90(ai,-r); %end
end %rr = 0;
end %end
%end
%a = rot90(ai,-r);
function [rr,cc,ss]=mb(r,c,i,rot,dum) %end
%end
if nargin<5 %sR(-rL(i))=sL(i);
dum=0; %sol(n-1,1)=sL(n);sol(n,1)=0;
end %V(idxi)=vi;
if(rot<=0) %if(r>=4)
%charge = charge+B;
if i > 0 %r = abs(r);
[rr,cc,ss] = beamkeeper(r,c,2); %solution;
else %end
[rr,cc,ss] = beamkeeper(r,c,1); %sol = ra(solution,rot);
end %cB(-cT(i))=i;
%rL(rT(i))=0;
elseif(rot>=4) %rr = 0;
%s=zeros(n);
if(r==0) %else
[ri,ci,ss] = mb(0,sign(c)*(n-abs(c)+1),i,rot-4,dum); %return
%solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
else %if (n == 60)
%while(~(r==-1 && c==0))
[ri,ci,ss] = mb(-r,0,i,rot-4,dum); %elseif rB(i)<0;
%
end %solution = rotsolver(rot);
if(ri==0 && ci==0) %
rr = 0; %return
cc = 0; %turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2;
%else
elseif(ri==0) %ro(cn+1) = sn;
rr = 0; %rr = 0;
cc = sign(ci)*(n-abs(ci)+1); %s=zeros(n);
else %if(~(r==0 && c==0))
rr = -ri; %return
cc = 0; %
end %return
%j = j+1;
else %sB(-cT(i))=sT(i);
if(r==0) %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
[ri,ci,ss] = mb(sign(c)*(n-abs(c)+1),0,i,rot-1,dum); %rc=idx-d*n;
%end
else %end
[ri,ci,ss] = mb(0,-r,i,rot-1,dum); %end
end %varargout = {-r,-c,ch};
if(ri==0 && ci==0) %solution(r+sign(c),abs(c))=max(0,solution(r+sign(c),abs(c)));
rr = 0; %sc2 = c2 - 2;
%if tempS>0
cc = 0; %
%s( 13,32 )=a;    s( 13,33 )=a;    s( 14,39 )=a;    s( 15,9 )=a;
elseif(ri==0) %if rT(i)==0 && cT(i)>0
rr = -ci; %rr = 0;
cc = 0; %end
%if ~r
else %if rR(i)==0 && cR(i)<0
rr = 0; %s( 34,39 )=a;    s( 36,7 )=a;    s( 36,23 )=a;    s( 38,4 )=a;
%if sol(tempR,tempC)==-1
cc = sign(ri)*(n-abs(ri)+1); %
%end
end %cR(1)=0;
%varargout = {-r,-c,ch};
end %end
if i > 1 || nargin>4, %if sol(tempR,tempC)==-1
%do1L=0;
return; %
%sol=ones(n).*-1;
end %nn = nn-1;
if ~r && -c==cc && ~ss %sol = ra(solution,rot);
c=abs(c); %end
%B=0;
solution(:,min(n,max(1,c-1:c+1)))=max(0,solution(:,min(n,max(1,c-1:c+1)))); %break
%cB(-cT(i))=i;
elseif ~c && ~ss && (-r)==rr %
r=abs(r); %sol(tempR,tempC)=tempS;B=1;
%cR=-1.*ones(1,n);
solution(min(n,max(1,r-1:r+1)),:)=max(0,solution(min(n,max(1,r-1:r+1)),:)); %solution(r,max(1,min(n,abs(c)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(c)+(-1:1)))));
%end
elseif r==rr && c==cc && ss %cc = 0;
%end
if ~r %else
%cL(n)=0;
r=(c>0)+(c<0)*n; %end
%rB=-1.*ones(1,n);
solution(r,abs(c))=max(0,solution(r,abs(c))); %bl=bl-1;
elseif ~c %if rB(i)>0 ;
c=(r>0)+(r<0)*n; %rT=-1.*ones(1,n);
%if (n == 53)
solution(abs(r),c)=max(0,solution(abs(r),c)); %if rB(i)<0 && cB(i)==0
end %end
elseif ss %sol = ra(sol,mod(rot+2,4)+4*(rot>=4));
%if  rB(i)>0
if ~r %s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;
%cR(-rT(i))=i;
r=(c>0)+(c<0)*n; %if ~(c3~=2 && ~(r3==0 && c3==0))
%if sT(i)==0 && rT(i)==0 && cT(i)==-i;
solution(r,max(1,min(n,abs(c)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(c)+(-1:1))))); %elseif r==rr && c==cc && ss
solution(r+sign(c),abs(c))=max(0,solution(r+sign(c),abs(c))); %end
%L=~(~V&B>0);
elseif ~c %[r,c,s] = mb(j,0,0,rot);
c=(r>0)+(r<0)*n; %fnd=1;
solution(max(1,min(n,abs(r)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(r)+(-1:1))),c)); %end
solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r))); %end
%for i=2:n-2
end %if  rB(i)>0
if ~rr %s(7,35)=4;    s(8,11)=28;    s(9,18)=27;    s(9,19)=27;
r=(cc>0)+(cc<0)*n; %ch = charge(r,c);
%end
solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1))))); %if rT(n)==0 && cT(n)==n
%rT(n)=0;
solution(r+sign(cc),abs(cc))=max(0,solution(r+sign(cc),abs(cc))); %end
elseif ~cc %tempR=i+1;tempC=cL(i)+1;tempS=sL(i);
%varargout = {0,0,0};
c=(rr>0)+(rr<0)*n; %end
%end
solution(max(1,min(n,abs(rr)+(-1:1))),c)=max(0,solution(max(1,min(n,abs(rr)+(-1:1))),c)); %elseif  cR(i)>0;
%cR(n)=0;
solution(abs(rr),c+sign(rr))=max(0,solution(abs(rr),c+sign(rr))); %solution(1,c+2) = s1;
%sL(rR(i))=sR(i);
end %cL(rT(i))=i;
end %
end %sol = lrow(n-nn+1,sol2,mod(rot+2,4)+4*(rot>=4));
%end
%V=zeros(4*n,1)-1;
function [ri,ci,vi]=beamkeeper(r,c,s) %else
idx=rc2idx(r,c); %tempR=i-1;tempC=-cR(i)-1;tempS=sR(i);
if B(idx)>=0 && s == 1 %s(24,20)=27;    s(24,26)=45;    s(26,28)=45;    s(29,40)=45;
[ri,ci]=idx2rc(B(idx)); %cT(1)=-1;
vi=V(idx); %for c = 1:n
return %if sol(tempR,tempC)==-1
%idx=rc2idx(r,c);
end %solution=s;
if s == 2 %if  sol(tempR,tempC)>99
[ri,ci,vi]=beam(r,c,'high'); %s(6,30)=14;    s(6,34)=11;    s(7,4)=8;    s(7,10)=24;
%V=zeros(4*n,1)-1;
L=~(~V&B>0); %end
B(L)=-1; %return
%function varargout = beam2(r,c,n,beamIntensity)
V(L)=-1; %end
return %s(34,23)=45;    s(31,8)=45;    s(30,27)=45;    s(23,18)=45;
else %if r&&c
[ri,ci,vi]=beam(r,c,'low'); %elseif ~c
end %for c = 1:n
%sn = -1;
idxi=rc2idx(ri,ci); %if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i)
%[rR(i),cR(i),sR(i)] = beam(-i,0);
B(idx)=idxi; %solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
V(idx)=vi; %tempS=0;
%rT(cL(i))=i;
if idxi>0 %cc = 0;
B(idxi)=idx; %sL(rR(i))=sR(i);
V(idxi)=vi; %sol(2,n)=sT(1);sol(1,n)=0;
end %if rR(n)==-n && cR(n)==0
end %c=(r>0)+(r<0)*n;
%if rR(i)>0 && cR(i)==0
%c=(r>0)+(r<0)*n;
function idx=rc2idx(r,c) %if rB(n)==0 && cB(n)==-n
rc=r+c; %rr = -ci;
idx=(~~rc)*((~r)*2*n+(rc<0)*n+abs(rc)); %s( 20,28 )=a;    s( 20,31 )=a;    s( 21,1 )=a;    s( 21,13 )=a;
end %rL(rL(i))=i;
%sol(tempR,tempC)=tempS;B=1;
function [r,c]=idx2rc(idx) %end
if ~idx %end
r=0; %
c=0; %if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i)
return %r=0;
end %end
d=floor((idx-1)/n); %solution = ira(solution,rot);
%
sc=floor(d/2); %newd  = [0 0 0 0;
%V(L)=-1;
rc=idx-d*n; %if(ri==0 && ci==0)
s=1-(d-sc*2)*2; %solution(abs(r),c+sign(r))=max(0,solution(abs(r),c+sign(r)));
%C = conv2(A,[0 1 0;1 0 1;0 1 0])&~B;
r=~sc*s*rc; %rR=-1.*ones(1,n);
%solution(nn,c) = ru(c)-prev;
c=sc*s*rc; %if(r==0 && c==0)
%end
end %return
%break
end %end
%a = rot90(ai,r);
%cR(n)=0;
%s( 11,4 )=a;    s( 11,18 )=a;    s( 11,23 )=a;    s( 13,9 )=a;
function varargout = beam2(r,c,n,beamIntensity) %[ri,ci,vi]=beam(r,c,'high');
global A turns charge newd ir ic %else
%if rL(i)==-1 && ((i~=1 && i~=n) || (i==1 && do1L) || (i==n && doNL))
if nargin==1 %[ri,ci,ss] = mb(sign(c)*(n-abs(c)+1),0,i,rot-1,dum);
%s(7,35)=4;    s(8,11)=28;    s(9,18)=27;    s(9,19)=27;
A = r; %solution=s;
%sol(tempR,tempC)=tempS;B=1;
newd  = [0 0 0 0;  %else
%if n==10
1 2 3 4; %
4 3 2 1;  %elseif ~c
2 1 4 3; %solution(r,max(1,min(n,abs(cc)+(-1:1))))=max(0,solution(r,max(1,min(n,abs(cc)+(-1:1)))));
3 4 1 2];  %a=rot90(fliplr(ai),r);
ir = [1 0 -1 0]; %solution(r,abs(c))=max(0,solution(r,abs(c)));
%if i==n-1 && sL(i)==0
ic = [0 1 0 -1]; %[r,c,s] = mb(0,sc-1,0,rot);
n = length(A); %ro(cn+1) = sn;
[turns charge] = setCmds(A); %sol(tempR,tempC)=0;
varargout = {0,0,0}; %if rL(i)>0 && cL(i)==0
return %r=(c>0)+(c<0)*n;
end %end
%rL(rR(i))=-i;
%elseif rT(i)<0;
d = (c>0)+2*(r>0)+3*(c<0)+4*(r<0);  %end
r = abs(r); %[r,c,s] = mb(1,0,0,rot);
c = abs(c); %end
%if rR(1)==-1 && cR(1)==0
r = r+1 + ((n+1)*(d==3)); %[turns charge] = setCmds(A);
c = c+1 + ((n+1)*(d==4)); %if  rT(i)<0
%sol(i,:)=0;if i>1; sol(i-1,:)=0;end;if i<n; sol(i+1,:)=0;end
ch = charge(r,c); %if couo == -1
%return
if ~ch %doNT=0;
while d %function varargout = beam2(r,c,n,beamIntensity)
r = r + ir(d); %sol2 = ira(sol,mod(rot+2,4)+4*(rot>=4));
%else
c = c + ic(d); %if  sol(tempR,tempC)>99
%d = (c>0)+2*(r>0)+3*(c<0)+4*(r<0);
d = newd(turns(r,c),d); %s(3,8)=28;     s(3,14)=31;     s(4,9)=40;     s(4,10)=2;
ch = ch + charge(r,c); %
end %couu = -1;
end %end
d = (r==n+2)||(c==n+2); %solution(1,tc) = max(0,solution(1,tc));
%if(r1 == 0 && c1 == c+1)
r = rem(r-1,n+1); %sol(n-1,1)=sL(n);sol(n,1)=0;
c = rem(c-1,n+1); %end
if r&&c %if sT(i)==0 && rT(i)==0 && cT(i)==-i;
varargout = {0,0,0}; %if ru(c)
elseif d %rL(rB(i))=0;
%function [turns charge] = setCmds(A)
varargout = {-r,-c,ch}; %sol(tempR,tempC)=tempS;B=1;
else %if(r==0)
varargout = {r,c,ch}; %if ru(c)
%function [rr,cc,ss]=mb(r,c,i,rot,dum)
end %c = abs(c);
%if rB(i)==0 && cB(i)<0
end %r=0;
%end
%end
function [turns charge] = setCmds(A) %end
B = conv2(A,[0 0 0;0 1 0;0 0 0]); %sol = ra(solution,rot);
C = conv2(A,[0 1 0;1 0 1;0 1 0])&~B; %[r,c,s] = mb(nn-1,0,0,rot);
%sB(1)=0;
turns = conv2(single(A>0),[1 0 2;0 0 0;2 0 1])+2; %sB(-cB(i))=sB(i);
turns(~conv2(ones(size(A)),[0 0 0;0 1 0;0 0 0])|B) = 1; %s(12,9)=16;     s(12,10)=16;     s(12,16)=38;     s(14,6)=40;
turns(C) = 2; %sol(n-1,1)=sL(n);sol(n,1)=0;
charge = conv2(A,ones(3)); %end
%sol(n-1,n)=sT(n);sol(n,n)=0;
charge(C|B) = 0; %if rB(n)==0 && cB(n)==-n
%end
charge = charge+B; %sol(tempR,tempC)=tempS;B=1;
%[rT(i),cT(i),sT(i)] = beam(0,i);
end %if cB(i)==-i  && sB(i+1)==0 && rB(i+1)==0 && cB(i+1)==0 && sB(i+2)==sB(i)
```