maxdepth:=6;



S1:=Group((3,4),(3,9),(3,14));
S2:=Group((17,12,7,1)(13,8,2,18)(19,15,10,5)(20,16,11,6),(14,3)(13,7)(17,2)(12,8)(1,18)(20,5)(6,19)(10,16)(15,11));
aR:=(1,5,3,6);
aL:=aR^-1;
aD:=(2,5,4,6);
aU:=aD^-1;
bR:=(3,10,8,11);
bL:=bR^-1;
bD:=(7,10,9,11);
bU:=bD^-1;
dR:=(18,19,14,20);
dL:=dR^-1;
dD:=(4,19,17,20);
dU:=dD^-1;
cR:=(14,15,12,16);
cL:=cR^-1;
cD:=(9,15,13,16);
cU:=cD^-1;



gens:=[aU,aD,aL,aR,bU,bD,bL,bR,cU,cD,cL,cR,dU,dD,dL,dR];
v:=[[()],[],[],[],[],[],[],[],[],[],[],[]];
for y in [1..maxdepth-1] do
    k:=[[],[],[],[],[],[],[],[],[],[],[],[],[],[],[],[]];
    cnt:=1;
    
         for z in [1..16] do
         	for x in v[y] do 
            	k[z][cnt]:=x*gens[z];
			cnt:=cnt+1;         
 	   	od;
         	if y>1 then
   			k[z]:=Difference(k[z],v[y-1]);
         	fi;


		if z=2 then v[y+1]:=Union(k[2],k[1]);k[2]:=[];k[1]:=[];fi;    
            if z>2 then v[y+1]:=Union(k[z],v[y+1]);k[z]:=[];fi;
	  od;
    
    if y>1 then v[y+1]:=Difference(v[y+1],v[y-1]);fi;
   Print(Size(v[y+1]),"\n");
od;


bitvector:=[];
for x in [1..maxdepth] do
	bitvector[x]:=BlistList([1..Size(v[x])],[]);
od;

nonpermited:=[];
for x in [1..maxdepth] do
nonpermited[x]:=[];
od;




m:=[];
for x in [1..maxdepth] do
	m[x]:=[];
od;

m[1]:=[[]];

for depth in [1..maxdepth-1] do
	cnt:=1;new_red:=0;elim1:=0;cnt4:=1;
 	for y in [1..Size(m[depth])] do
  		for x in [1..Size(gens)] do
			elm:=Concatenation(m[depth][y],[x]);
     			elm2:=[];
			
			if depth>13 then
				for z in [14..Size(elm)] do
					elm2[z-13]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-13],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;

			if depth>12 then
				for z in [13..Size(elm)] do
					elm2[z-12]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-12],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;
			
			if depth>11 then
				for z in [12..Size(elm)] do
					elm2[z-11]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-11],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;

			if depth>10 then
				for z in [11..Size(elm)] do
					elm2[z-10]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-10],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;




	
			if depth>9 then
				for z in [10..Size(elm)] do
					elm2[z-9]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-9],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;

			if depth>8 then
				for z in [9..Size(elm)] do
					elm2[z-8]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-8],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;



			if depth>7 then
				for z in [8..Size(elm)] do
					elm2[z-7]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-7],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;





			if depth>6 then
				for z in [7..Size(elm)] do
					elm2[z-6]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-6],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;


			if depth>5 then
				for z in [6..Size(elm)] do
					elm2[z-5]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-5],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;




			if depth>4 then
				for z in [5..Size(elm)] do
					elm2[z-4]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-4],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;




			if depth>3 then
				for z in [4..Size(elm)] do
					elm2[z-3]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-3],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;



			if depth>2 then
				for z in [3..Size(elm)] do
					elm2[z-2]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-2],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;


			if depth>1 then
				for z in [2..Size(elm)] do
					elm2[z-1]:=elm[z];
     				od;
  				if PositionSet(nonpermited[depth-1],elm2)<>fail then elim1:=elim1+1; continue;fi;
			fi;
			
			elm3:=();
			for z in [1..Size(elm)] do
				elm3:=elm3*gens[elm[z]];
			od;
			if PositionSet(v[depth+1],elm3)=fail then new_red:=new_red+1;nonpermited[depth][cnt4]:=elm;cnt4:=cnt4+1; continue;fi;
			if bitvector[depth+1][PositionSet(v[depth+1],elm3)]=true then new_red:=new_red+1;nonpermited[depth][cnt4]:=elm;cnt4:=cnt4+1; continue;
			else
			bitvector[depth+1][PositionSet(v[depth+1],elm3)]:=true;  
			fi;
			m[depth+1][cnt]:=elm;
			cnt:=cnt+1;
		od;
	od;
Print("Depth ",depth," completed. New reductions ",new_red," Eliminations ",elim1,"\n");
MakeImmutable(nonpermited[depth]);
od;

