Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [[0]*(1<<N) for _ in range(N+1)]
    dp[0][0] = 1
    for iM in range(N):
        for S in range(1<<N):
            if dp[iM][S]:
                dp[iM][S] %= MOD
                for iW in range(N):
                    if S & (1<<iW) == 0 and Ass[iM][iW]:
                        S2 = S ^ (1<<iW)
                        dp[iM+1][S2] += dp[iM][S]

    print(dp[-1][-1] % MOD)


solve()


Fixed submission:
MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        for iW in range(N):
            if A2 & (1 << iW):
                dp[patW ^ (1 << iW)] += dpNow
                dp[patW ^ (1 << iW)] %= MOD

print(dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [0] * (1<<N)
    dp[0] = 1
    for S in range((1<<N)-1):
        dp[S] %= MOD
        iM = bin(S).count('1')
        for iW in range(N):
            if S & (1<<iW) == 0 and Ass[iM][iW]:
                S2 = S ^ (1<<iW)
                dp[S2] += dp[S]

    print(dp[-1] % MOD)


solve()


Fixed submission:
MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        for iW in range(N):
            if A2 & (1 << iW):
                dp[patW ^ (1 << iW)] += dpNow
                dp[patW ^ (1 << iW)] %= MOD

print(dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    dp = [0] * (1<<N)
    dp[0] = 1
    for S in range(1, 1<<N):
        iM = bin(S).count('1') - 1
        for iW in range(N):
            if S & (1<<iW) and Ass[iM][iW]:
                S0 = S ^ (1<<iW)
                dp[S] += dp[S0]
        dp[S] %= MOD

    print(dp[-1])


solve()


Fixed submission:
MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        for iW in range(N):
            if A2 & (1 << iW):
                dp[patW ^ (1 << iW)] += dpNow
                dp[patW ^ (1 << iW)] %= MOD

print(dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
def solve():
    MOD = 10**9 + 7

    N = int(input())
    Ass = [tuple(map(int, input().split())) for _ in range(N)]

    Sss = [[] for _ in range(N+1)]
    for S in range(1<<N):
        num1 = bin(S).count('1')
        Sss[num1].append(S)

    dp = [0] * (1<<N)
    dp[0] = 1
    for iM, Ss in enumerate(Sss[:-1]):
        for S in Ss:
            dp[S] %= MOD
            for iW in range(N):
                if S & (1<<iW) == 0 and Ass[iM][iW]:
                    S2 = S | (1<<iW)
                    dp[S2] += dp[S]

    print(dp[-1] % MOD)


solve()


Fixed submission:
MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        for iW in range(N):
            if A2 & (1 << iW):
                dp[patW ^ (1 << iW)] += dpNow
                dp[patW ^ (1 << iW)] %= MOD

print(dp[0])

Buggy python submission (verdict: Time Limit Exceeded):
MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        mask = 1 << (N-1)
        for iW in range(N):
            if A2 & mask:
                 dp[patW ^ mask] += dpNow
                 dp[patW ^ mask] %= MOD
            mask >>= 1

print(dp[0])


Fixed submission:
MOD = 10**9 + 7

N = int(input())
As = [int(input().replace(' ', ''), 2) for _ in range(N)]

patWsList = [[] for _ in range(N+1)]
for patW in range(2**N):
    num1 = sum([(patW >> i) & 1 for i in range(N)])
    patWsList[num1].append(patW)

dp = [0] * (2**N)
dp[-1] = 1
for iM, (A, patWs) in enumerate(zip(As, reversed(patWsList))):
    for patW in patWs:
        A2 = A & patW
        dpNow = dp[patW]
        for iW in range(N):
            if A2 & (1 << iW):
                dp[patW ^ (1 << iW)] += dpNow
                dp[patW ^ (1 << iW)] %= MOD

print(dp[0])