#include <iostream>

typedef int index;
const int n = 8;
index  col[n + 1];

bool promising (index i)
{
	index k;
	bool s;

	k = 1;
	s = true;
	while(k < i && s) {
		if( col[i] == col[k] || abs(col[i] - col[k]) == i - k)
			s = false;
		k++;
	}
	return s;
}

void queens (index i)
{
	index j, k;
	if( promising(i)) {
		if (i == n) {
			for(k = 1; k <= n; k++) {
				cout << col[k] << ' ';
			}
			cout << endl;
		} else {
			for (j = 1; j <= n; j++) {
				col[i + 1] = j;
				queens(i + 1);
			}
		}
	}
}

main()
{
	queens(0);
}

