Problem:
Score : 1500 points

Problem Statement

#nck {
width: 30px;
height: auto;
}

Snuke received two matrices A and B as birthday presents.
Each of the matrices is an N by N matrix that consists of only 0 and 1.

Then he computed the product of the two matrices, C = AB.
Since he performed all computations in modulo two, C was also an N by N matrix that consists of only 0 and 1.
For each 1 ≤ i, j ≤ N, you are given c_{i, j}, the (i, j)-element of the matrix C.

However, Snuke accidentally ate the two matrices A and B, and now he only knows C.
Compute the number of possible (ordered) pairs of the two matrices A and B, modulo 10^9+7.

Constraints

1 ≤ N ≤ 300

c_{i, j} is either 0 or 1.

Input

The input is given from Standard Input in the following format:

N
c_{1, 1} ... c_{1, N}
:
c_{N, 1} ... c_{N, N}

Output

Print the number of possible (ordered) pairs of two matrices A and B (modulo 10^9+7).

Sample Input 1

2
0 1
1 0

Sample Output 1

6

Sample Input 2

10
1 0 0 1 1 1 0 0 1 0
0 0 0 1 1 0 0 0 1 0
0 0 1 1 1 1 1 1 1 1
0 1 0 1 0 0 0 1 1 0
0 0 1 0 1 1 1 1 1 1
1 0 0 0 0 1 0 0 0 0
1 1 1 0 1 0 0 0 0 1
0 0 0 1 0 0 1 0 1 0
0 0 0 1 1 1 0 0 0 0
1 0 1 0 0 1 1 1 1 1

Sample Output 2

741992411

Solution in Fortran (gfortran v4.8.4) (judge verdict: Accepted)

program main
  implicit none
  integer(16) dp(0:300,0:300),a(0:300,0:300)
  integer(16) N
  integer(16) r,ret,i,j,k
  integer(16) pw(0:300)
  integer(16)::mo=1000000007
  read*,N
  pw(0)=1_16
  do i=1,n+1
    pw(i)=mod(pw(i-1)*2_16,mo)
  end do
  dp=0_16
  dp(0,0)=1_16
  do j=0,n-1 
    do k=0,j
  	  dp(j+1,k+1)=mod(dp(j+1,k+1)+mod(dp(j,k)*(pw(n)-pw(k)),mo),mo)
  	  dp(j+1,k)=mod(dp(j+1,k)+mod(dp(j,k)*pw(k),mo),mo)
	end do
  end do
  a=0
  do i=0,n-1
    read*,a(i,0:N-1)
  end do
  r=gauss(a,N)
  ret=0
  do i= r,n
    ret=mod(ret+mod(dp(n,i)*dp(i,r),mo)*powmod(2_16,n*n-i*n,mo),mo)
  end do
  ret=mod(ret*powmod(dp(n,r),mo-2_16,mo),mo)
  
  if(ret<=0)ret=ret+mo
  print"(i0)",ret
  
contains
function powmod(aa,b,mo)
  implicit none
  integer(16) aa,b,mo,ak,bk
  integer(16) powmod
  powmod=1_16
  bk=b
  ak=mod(aa,mo)
  do while(bk/=0_16)
    if(mod(bk,2)==1)then
      powmod=mod(powmod*ak,mo)
    endif
    ak=mod(ak*ak,mo)
    bk=bk/2_16
  end do
end function

function gauss(a,N)
  implicit none
  integer(16) N,a(0:300,0:300)
  integer(16) gauss
  integer(16) p,i,j,k
  integer(16) fg
  p=0
  do i=0,n-1
	fg=0
	do j=p,n-1 
      if (a(j,i)>0)then	
        do k=0,n-1 
          call swap(a(p,k),a(j,k))
        end do
        fg=1
		exit
      endif
    end do
	if (fg==0) cycle
    do j=p+1,n-1 
      if (a(j,i)>0)then
	    do k=0,n-1 
          a(j,k) = xor(a(j,k),a(p,k))
        end do
	  endif
    end do
	p=p+1
  end do
  gauss=p
end function

subroutine swap(a,b)
  implicit none
  integer(16) a,b
  a=xor(a,b)
  b=xor(a,b)
  a=xor(a,b)
end subroutine
end