my ($board_size, @occupied, @past, @solutions);

sub try_column {
        my ($depth, @diag) = shift;
        if ($depth == $board_size) {
                push @solutions, "@past\n";
                return;
        }

        
        
        
        $
        for (0 .. $
                $diag[ $past[$_] + $depth - $_ ] = 1;
                $diag[ $past[$_] - $depth + $_ ] = 1;
        }

        for my $row (0 .. $board_size - 1) {
                next if $occupied[$row] || $diag[$row];

                
                
                
                push @past, $row;
                $occupied[$row] = 1;

                try_column($depth + 1);

                
                $occupied[$row] = 0;
                pop @past;
        }
}

$board_size = 12;
try_column(0);


print "total " . @solutions . " solutions\n";