queen = [0 for c in range(8)]
rfree = [True for r in range(8)]
du = [True for i in range(15)]
dd = [True for i in range(15)]
def solve(c):
global solutions
if c == 8:
solutions += 1
print(solutions, end = ": ")
for r in range(8):
print (queen[r] + 1 ,end = " " if r<7 else "\n")
else:
for r in range(8):
if rfree[r] and dd[c + r] and du[ c+7-r]:
queen[c] = r
rfree[r] = dd[ c+r ] = du[ c+7-r ] = False
solve(c+1)
rfree[r] = dd[ c+r ] = du[ c+7-r ] = True
solutions = 0
solve(0)
print()
print(solutions, "solutions")
cXVlZW4gPSBbMCBmb3IgYyBpbiByYW5nZSg4KV0gICAgIApyZnJlZSA9IFtUcnVlIGZvciByIGluIHJhbmdlKDgpXQpkdSA9IFtUcnVlIGZvciBpIGluIHJhbmdlKDE1KV0KZGQgPSBbVHJ1ZSBmb3IgaSBpbiByYW5nZSgxNSldCgpkZWYgc29sdmUoYyk6CglnbG9iYWwgc29sdXRpb25zCgoJaWYgYyA9PSA4OgoJCXNvbHV0aW9ucyArPSAxIAoJCXByaW50KHNvbHV0aW9ucywgZW5kID0gIjogIikKCQlmb3IgciBpbiByYW5nZSg4KToKCQkJcHJpbnQgKHF1ZWVuW3JdICsgMSAsZW5kID0gIiAiIGlmIHI8NyBlbHNlICJcbiIpCgllbHNlOgkJCgkJZm9yIHIgaW4gcmFuZ2UoOCk6CgkJCWlmIHJmcmVlW3JdIGFuZCBkZFtjICsgcl0gYW5kIGR1WyBjKzctcl06CgkJCQlxdWVlbltjXSA9IHIKCQkJCXJmcmVlW3JdID0gZGRbIGMrciBdID0gZHVbIGMrNy1yIF0gPSBGYWxzZQoJCQkJc29sdmUoYysxKQoJCQkJcmZyZWVbcl0gPSBkZFsgYytyIF0gPSBkdVsgYys3LXIgXSA9IFRydWUKCnNvbHV0aW9ucyA9IDAKc29sdmUoMCkKcHJpbnQoKQpwcmludChzb2x1dGlvbnMsICJzb2x1dGlvbnMiKQ==