Buggy python submission (verdict: Time Limit Exceeded):
mod = 10**9+7
n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

nn = 1 << n

dp = [0 for __ in range(nn)]
dp[0] = 1

for bit in range(nn):
    cur = dp[bit] % mod
    if cur == 0:
        continue
    i = bin(bit).count("1")
    for j in range(n):
        bit_new = bit | (1 << j)
        if bit_new != bit and a[i-1][j] == 1:
            dp[bit_new] += cur

print(dp[-1] % mod)


Fixed submission:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))

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

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [0 for __ in range(1 << n)]
dp[0] = 1

for bit in range(1 << n):
    i = bin(bit).count("1")
    for j in range(n):
        bit_new = bit | (1 << j)
        if bit_new != bit and a[i-1][j] == 1:
            dp[bit_new] += dp[bit]
            dp[bit_new] %= mod

print(dp[-1])


Fixed submission:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))

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

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [0 for __ in range(1 << n)]
dp[0] = 1

for bit in range(1 << n):
    i = bin(bit).count("1")
    for j in range(n):
        if a[i-1][j] == 1 and (bit & 1 << j):
            dp[bit] += dp[bit ^ (1 << j)]
    dp[bit] %= mod

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


Fixed submission:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))

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

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [0 for __ in range(1 << n)]
dp[0] = 1

for bit in range(1 << n):
    i = bin(bit).count("1")
    for j in range(n):
        if a[i-1][j] == 1 and (bit & 1 << j):
            dp[bit] += dp[bit ^ (1 << j)]
    dp[bit] %= mod

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


Fixed submission:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))

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

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [0 for __ in range(1 << n)]
dp[0] = 1

for bit in range(1 << n):
    i = bin(bit).count("1")
    for j in range(n):
        if a[i-1][j] == 1 and (bit & 1 << j):
            dp[bit] += dp[bit ^ (1 << j)]
            dp[bit] %= mod

print(dp[(1<<n)-1])


Fixed submission:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

dp = [[0 for __ in range(1 << n)] for _ in range(n+1)]
dp[0][0] = 1

for i in range(n):
    a = [int(x) for x in input().split()]
    for j in range(n):
        for bit in range(1 << n):
            if a[j] == 1 and (bit & 1 << j):
                dp[i+1][bit] += dp[i][bit ^ (1 << j)]

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

Fixed submission:
mod = 10**9+7

n = int(input())
a = [[int(x) for x in input().split()] for _ in range(n)]

dp = [-1 for __ in range(1 << n)]
dp[0] = 1


def dfs(bit, i):
    if dp[bit] != -1:
        return dp[bit]
    else:
        tmp = 0
        for j in range(n):
            if bit & (1 << j) and a[i][j]:
                tmp += dfs(bit ^ (1 << j), i+1)
    dp[bit] = tmp % mod
    return dp[bit]


print(dfs(2**n-1, 0))