use 5.01; ($n,$k)=glob<>; @i=0..$n-2; say @i*@i*3+2; for(@i){ for(@i){ $i=$_+1; say "XOR $n $i $_"; say "AND $i $i $_"; say "XOR $_ $i $n"; } } $i=$k-1; say "XOR $n $n $n"; say "XOR $n $n $i";