Function to calculate the number of valid assignments
int noOfAssignments ( string & S , int & n , int i , int c_x , int c_y ) { if ( F [ i ] [ c_x ] [ c_y ] != -1 ) return F [ i ] [ c_x ] [ c_y ] ; if ( i == n ) {