// This program will allow us to calculate different arrangements of
// any piece on any nxn chessboard.
// (c) 1996 Pablo Sanfrancisco.

#include 
#include 
#include 

int cases = 0;
int nn;
int expn;
int matr[128][128];

void NonTaking(int n, char choice, int number, int l, int l2)
{
  int last = 0;
  int work;
  int j;
  int j2;
  int done;
  int prev = 0;
  number--;
  for (int i=l;i= 0)&&!done)
		{
		  if (matr[i+j++][i2-j2++])
		    done = 1;
		}
	      if (done)
		work = 0;
	      done = 0;
	      j = 1;
	      j2 = 1;	  
	      while ((i-j >= 0)&&(i2-j2 >= 0)&&!done)
		{
		  if (matr[i-j++][i2-j2++])
		    done = 1;
		}
	      if (done)
		work = 0;
	      done = 0;
	      j = 1;
	      j2 = 1;	  
	      while ((i-j >= 0)&&(i2+j2 < n)&&!done)
		{
		  if (matr[i-j++][i2+j2++])
		    done = 1;
		}
	      if (done)
		work = 0;
	    }
	  else
	    if (choice == 'k')
	      {
		if (((i+1)=0)&&((i2+2)=0))		
		  if (matr[i+1][i2-2])
		    work = 0;
		if (((i-1)>=0)&&((i2-2)>=0))		
		  if (matr[i-1][i2-2])
		    work = 0;
		if (((i+2)=0))
		  if (matr[i+2][i2-1])
		    work = 0;
		if (((i-2)>=0)&&((i2+1)=0)&&((i2-1)>=0))		
		  if (matr[i-2][i2-1])
		    work = 0;
	      }
	  else
	    if (choice == 'r')
	      {
		j = 1;
		j2 = 1;
		done = 0;
		while ((i+j < n)&&!done)
		  {
		    if (matr[i+j++][i2])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;
		while ((i2-j2 >= 0)&&!done)
		  {
		    if (matr[i][i2-j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;	  
		while ((i-j >= 0)&&!done)
		  {
		    if (matr[i-j++][i2])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;	  
		while ((i2+j2 < n)&&!done)
		  {
		    if (matr[i][i2+j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;		
	      }
	  else
	    if (choice == 'q')
	      {
		j = 1;
		j2 = 1;
		done = 0;
		while ((i+j < n)&&(i2+j2 < n)&&!done)
		  {
		    if (matr[i+j++][i2+j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;
		while ((i+j < n)&&(i2-j2 >= 0)&&!done)
		  {
		    if (matr[i+j++][i2-j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;	  
		while ((i-j >= 0)&&(i2-j2 >= 0)&&!done)
		  {
		    if (matr[i-j++][i2-j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;	  
		while ((i-j >= 0)&&(i2+j2 < n)&&!done)
		  {
		    if (matr[i-j++][i2+j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;
		j = 1;
		j2 = 1;
		done = 0;
		while ((i+j < n)&&!done)
		  {
		    if (matr[i+j++][i2])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;
		while ((i2-j2 >= 0)&&!done)
		  {
		    if (matr[i][i2-j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;	  
		while ((i-j >= 0)&&!done)
		  {
		    if (matr[i-j++][i2])
		      done = 1;
		  }
		if (done)
		  work = 0;
		done = 0;
		j = 1;
		j2 = 1;	  
		while ((i2+j2 < n)&&!done)
		  {
		    if (matr[i][i2+j2++])
		      done = 1;
		  }
		if (done)
		  work = 0;		
	      }
	  else
	    if (choice == 'K')
	      {

		if (((i+1)=0))		
		  if (matr[i+1][i2-1])
		    work = 0;
		if (((i-1)>=0)&&((i2-1)>=0))		
		  if (matr[i-1][i2-1])
		    work = 0;
		if ((i-1)>=0)		
		  if (matr[i-1][i2])
		    work = 0;
		if (((i-1)>=0)&&((i2+1)=0)		
		  if (matr[i][i2-1])
		    work = 0;
	      }
	    }
	  if (work)
	    if (number)
		NonTaking(n,choice,number,i,i2);
	    else
	      {
	        cases++;
		for (int h=0;h> n;
  while (n < 1)
    {
      cout << "Incorrect entry. Please try again.\n";
      cout << "Please enter value n for the dimensions of the nxn chessboard (max 128): ";
      cin >> n;
    }      
  cout << "Select one of these figures, (b)ishop, (k)night, (r)ook, (q)ueen, (K)ing: ";
  cin >> choice;
  while ((choice != 'b')&&(choice != 'k')&&(choice != 'r')&&(choice != 'q')&&(choice != 'K'))
    {
      cout << "Incorrect entry. Please try again.\n";
      cout << "Select one of these figures, (b)ishop, (k)night, (r)ook, (q)ueen, (K)ing: ";
      cin >> choice;
    }
  cout << "How many of these figures do you want to place on the board? (1-" << n*n << "): ";
  cin >> number;
  while (number > n*n)
    {
      cout << "Incorrect entry. Please try again.\n";
      cout << "How many of these figures do you want to place on the board? (1-" << n*n << "): ";
      cin >> number;
    }
  cout << "\n\n\n\n\n";
  cout << "For a "<< n << "x" << n << " board, we will determine how many ways there is of placing " << number;
    if (choice == 'b')
      cout << " bishop ";
  else
    if (choice == 'k')
      cout << " knight ";
  else
    if (choice == 'r')
      cout << " rook ";
  else
    if (choice == 'q')
      cout << " queen ";
  else
    if (choice == 'K')
      cout << " King ";
  cout << "such that they don't 'take' each other.\n\n";
  expn = 1;
  for (int h=1;h