#include <iostream>
#include <fstream>

using namespace std;

int main(int argc, char *argv[])
{
	ofstream lpqueen;
	int nqueens;
	int i,j,k;

	if( argc != 3) 
	{
		cout<<"Usage: "<< argv[0] << "  <nqueens>  <output>" <<endl;
		return 0;
	}	
	nqueens = atoi(argv[1]);
	lpqueen.open(argv[2],ios::trunc);

	lpqueen << "##function (col) col queen." << endl;
	
	for(i=0; i<nqueens; i++) 
		lpqueen << "col(" << i << ")." << endl;

	for(i=0;i<nqueens; i++)
	{
		for(j=0; j<nqueens; j++)
		{
		if (i==j) continue;
		lpqueen << ":- queen(" << i << ")==queen(" << j << ")." << endl;
		}
	}

	for(i=0;i<nqueens; i++)
	{
		for(j=0; j<nqueens; j++)
		{
			if (j==i) continue;
			lpqueen << ":- |queen(" << i << ")-queen(" << j << ")|==" << abs(i-j) << "." << endl;
		}
	}

	return 0;
}
