Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = 2**k-1
    yield _a
    _ALL=2**n
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

MOD=10**9+7
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

dp = [0]*(2**n)
dp[0] = 1
"""
for m in range(1,n+1):
    for a in itercomb(n,m):
        dp[a] = sum(dp[a^2**c] for c in range(n) if 2**c&a and A[m-1][c])%MOD

for a in range(1,2**n):
    m=bin(a).count("1")
    dp[a] = sum(dp[a^2**c] for c in range(n) if 2**c&a and A[m-1][c])%MOD


_ALL=2**n
for m in range(1,n+1):
    a = 2**m-1
    while a < _ALL:
        ans=0
        for c in range(n):
            if 2**c&a and A[m-1][c]:
                ans += dp[a^2**c]
                ans%=MOD
        dp[a] = ans
        x = a & -a
        y = a + x
        a = (((a & ~y) // x) >> 1) | y

for m in range(1,n+1):
    for a in itercomb(n,m):
        ans=0
        for c in range(n):
            if 2**c&a and A[m-1][c]:
                ans += dp[a^2**c]
                ans%=MOD
        dp[a] = ans

for m in range(1,n+1):
    for a in itercomb(n,m):
        ans=0
        for c,i in enumerate(A[m-1]):
            if i and 2**c&a:
                ans += dp[a^2**c]
                ans%=MOD
        dp[a] = ans
"""
_ALL=2**n
for m in range(1,n+1):
    a = 2**m-1
    while a < _ALL:
        ans=0
        for c,i in enumerate(A[m-1]):
            if i and 2**c&a:
                ans += dp[a^2**c]
                ans%=MOD
        dp[a] = ans
        x = a & -a
        y = a + x
        a = (((a & ~y) // x) >> 1) | y


print(dp[2**n-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

MOD=10**9+7
_ALL=1<<n
dp = [0]*(_ALL)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        for c,i in enumerate(A[m-1]):
            if (1<<c)&a and i:
                dp[a] += dp[a^(1<<c)]
                if dp[a] > MOD:
                    dp[a] -= MOD


#print(dp)
print(dp[2**n-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def itercomb(n,k):
    _a = 2**k-1
    yield 2**k-1
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= 2**n: break
        yield _a

MOD=10**9+7
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

dp = [0]*(2**n)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        #print(a)
        #if bin(a).count("1") != m: continue
        dp[a] = sum(dp[a-2**c] for c in range(n) if 2**c&a != 0 and A[m-1][c]==1)%MOD


print(dp[2**n-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

MOD=10**9+7
_ALL=1<<n
dp = [0]*(_ALL)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        for c,i in enumerate(A[m-1]):
            if (1<<c)&a and i:
                dp[a] += dp[a^(1<<c)]
                if dp[a] > MOD:
                    dp[a] -= MOD


#print(dp)
print(dp[2**n-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
def itercomb(n,k):
    _a = 2**k-1
    yield 2**k-1
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= 2**n: break
        yield _a

MOD=10**9+7
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

dp = [[0]*(2**n) for i in range(n+1)]
dp[0][0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        #print(a)
        #if bin(a).count("1") != m: continue
        dp[m][a] = sum(dp[m-1][a-2**c] for c in range(n) if 2**c&a != 0 and A[m-1][c]==1)%MOD


print(dp[n][2**n-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

MOD=10**9+7
_ALL=1<<n
dp = [0]*(_ALL)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        for c,i in enumerate(A[m-1]):
            if (1<<c)&a and i:
                dp[a] += dp[a^(1<<c)]
                if dp[a] > MOD:
                    dp[a] -= MOD


#print(dp)
print(dp[2**n-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
class comb(object):
    def __init__(self, n,k):
        self._i = 2**k-1
        self._ans = 0
    def __iter__(self):
        # __next__()はselfが実装してるのでそのままselfを返す
        return self
    def __next__(self):  # Python2だと next(self) で定義
        if self._i >= 2**n:
            raise StopIteration()
        self._ans = self._i
        x = self._i & -self._i
        y = self._i + x
        self._i = (((self._i & ~y) // x) >> 1) | y
        return self._ans


MOD=10**9+7
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

dp = [[0]*(2**n) for i in range(n+1)]
dp[0][0] = 1
for m in range(1,n+1):
    for a in comb(n,m):
#        print(a)
        #if bin(a).count("1") != m: continue
        dp[m][a] = sum(dp[m-1][a-2**c] for c in range(n) if 2**c&a != 0 and A[m-1][c]==1)%MOD


print(dp[n][2**n-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

MOD=10**9+7
_ALL=1<<n
dp = [0]*(_ALL)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        for c,i in enumerate(A[m-1]):
            if (1<<c)&a and i:
                dp[a] += dp[a^(1<<c)]
                if dp[a] > MOD:
                    dp[a] -= MOD


#print(dp)
print(dp[2**n-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
MOD=10**9+7
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

dp = [[0]*(2**n) for i in range(n+1)]
dp[0][0] = 1
for m in range(1,n+1):
    for a in range(2**n):
        if bin(a).count("1") != m: continue
        dp[m][a] = sum(dp[m-1][a-2**c] for c in range(n) if 2**c&a != 0 and A[m-1][c]==1)%MOD


print(dp[n][2**n-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

MOD=10**9+7
_ALL=1<<n
dp = [0]*(_ALL)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        for c,i in enumerate(A[m-1]):
            if (1<<c)&a and i:
                dp[a] += dp[a^(1<<c)]
                if dp[a] > MOD:
                    dp[a] -= MOD


#print(dp)
print(dp[2**n-1])

Buggy python submission (verdict: Time Limit Exceeded):
# coding: utf-8
# Your code here!
MOD=10**9+7
n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

dp = [[0]*(2**n) for i in range(n+1)]
dp[0][0] = 1
for m in range(1,n+1):
    for a in range(2**n):
        dp[m][a] = sum(dp[m-1][a-2**c] for c in range(n) if 2**c&a != 0 and A[m-1][c]==1)%MOD


print(dp[n][2**n-1])

Fixed submission:
# coding: utf-8
# Your code here!
import sys
input = sys.stdin.readline

def itercomb(n,k):
    _a = (1<<k)-1
    yield _a
    while 1:
        _x = _a & -_a
        _y = _a + _x
        _a = (((_a & ~_y) // _x) >> 1) | _y
        if _a >= _ALL: break
        yield _a

n=int(input())
A= [[int(i) for i in input().split()] for j in range(n)]

MOD=10**9+7
_ALL=1<<n
dp = [0]*(_ALL)
dp[0] = 1

for m in range(1,n+1):
    for a in itercomb(n,m):
        for c,i in enumerate(A[m-1]):
            if (1<<c)&a and i:
                dp[a] += dp[a^(1<<c)]
                if dp[a] > MOD:
                    dp[a] -= MOD


#print(dp)
print(dp[2**n-1])