program eightqueen1;
var i : integer ;
q : boolean ;
a : array [ 1 .. 8 ] of boolean ;
b : array [ 2 .. 16 ] of boolean ;
c : array [ - 7 .. 7 ] of boolean ;
d : array [ 1 .. 8 ] of integer ;
procedure try ( i : integer ; var q : boolean ) ; var j : integer ; begin j : = 0 ;
repeat j : = j + 1 ; q : = false ;
if a[ j] and b[ i + j] and c[ i - j] then
begin x[ i] : = j;
a[ j] : = false ; b[ i + j] : = false ; c[ i - j] : = false ;
if i < 8 then
begin try ( i + 1 , q) ;
if not q then
begin a[ j] : = true ; b[ i + j] : = true ; c[ i - j] : = true ;
end
end else q : = true
end
until q or ( j = 8 ) ;
end ; begin for i : = 1 to 8 do a[ i] : = true ; for i : = 1 to 8 do b[ i] : = true ; for i : = - 7 to 7 do c[ i] : = true ; try ( 1 , q) ; if q then
for i : = 1 to 8 do write ( x[ i] : 4 ) ;
writeln end .
cHJvZ3JhbSBlaWdodHF1ZWVuMTsKdmFyIGkgOiBpbnRlZ2VyOwogICBxIDogYm9vbGVhbjsKICAgYSA6IGFycmF5WyAxIC4uIDhdIG9mIGJvb2xlYW47CiAgIGIgOiBhcnJheVsgMiAuLiAxNl0gb2YgYm9vbGVhbjsKICAgYyA6IGFycmF5WyAtNyAuLiA3XSBvZiBib29sZWFuOwogICBkIDogYXJyYXlbIDEgLi4gOF0gb2YgaW50ZWdlcjsKICAgCgpwcm9jZWR1cmUgdHJ5KCBpIDogaW50ZWdlcjsgdmFyIHEgOiBib29sZWFuKTsgdmFyIGogOiBpbnRlZ2VyOyBiZWdpbiBqIDo9IDA7CiByZXBlYXQgaiA6PSBqICsgMTsgcSA6PSBmYWxzZTsKICAgaWYgYVsgal0gYW5kIGJbIGkgKyBqXSBhbmQgY1sgaSAtIGpdIHRoZW4KICAgYmVnaW4geFsgaV0gOj0gajsKICAgICBhWyBqXSA6PSBmYWxzZTsgYlsgaSArIGpdIDo9IGZhbHNlOyBjWyBpIC0gal0gOj0gZmFsc2U7CiAgICAgaWYgaSA8I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