queens(N, Qs) :- length(Qs, N), Qs ins 1..N, safeColumn(Qs), labeling([ffc], Qs).
safeColumn([]).
safeColumn([Q|Qs]) :- safeColumn(Qs, Q, 1), safeColumn(Qs).
safeColumn([],_,_).
safeColumn
([Q
|Qs
], SelQ
, Diagoff
) :- SelQ #\
= Q
, abs(SelQ
- Q
) #\
= Diagoff
, Diagoff1 #
= Diagoff
+ 1, safeColumn
(Qs
, SelQ
, Diagoff1
).
CgpxdWVlbnMoTiwgUXMpIDotIGxlbmd0aChRcywgTiksIFFzIGlucyAxLi5OLCBzYWZlQ29sdW1uKFFzKSwgbGFiZWxpbmcoW2ZmY10sIFFzKS4KCnNhZmVDb2x1bW4oW10pLgpzYWZlQ29sdW1uKFtRfFFzXSkgOi0gc2FmZUNvbHVtbihRcywgUSwgMSksIHNhZmVDb2x1bW4oUXMpLgoKc2FmZUNvbHVtbihbXSxfLF8pLgpzYWZlQ29sdW1uKFtRfFFzXSwgU2VsUSwgRGlhZ29mZikgOi0gU2VsUSAjXD0gUSwgYWJzKFNlbFEgLSBRKSAjXD0gRGlhZ29mZiwgRGlhZ29mZjEgIz0gRGlhZ29mZiArIDEsIHNhZmVDb2x1bW4oUXMsIFNlbFEsIERpYWdvZmYxKS4=