Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(1<<n)
dp[0]=1
for i in range(1,1<<n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(1<<j)]
                    dp[i]%=mod


print(dp[-1])
            
    
    

Fixed submission:
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(2**n)
dp[0]=1
for i in range(1,2**n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(2**j)]
                    dp[i]%=mod


print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7

def dp(p,v):
    if p==n:
        return 1
    k=0
    
            
    for j in range(n):
        if g[p][j]==1 and (v>>j)&1==1:
            #print(p,j)

            
            k+=dp(p+1,v^(1<<j))
            k%=mod
            #print(vw)

            
                    
    return k%mod


print(dp(0,(1<<n)-1))

Fixed submission:
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(2**n)
dp[0]=1
for i in range(1,2**n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(2**j)]
                    dp[i]%=mod


print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7

def dp(p,v):
    if p==n:
        return 1
    k=0
    
            
    for j in range(n):
        if g[p][j]==1 and (v>>j)&1==1:
            #print(p,j)

            
            k+=dp(p+1,v^(1<<j))
            k%=mod
            #print(vw)

            
                    
    return k%mod


print(dp(0,(1<<n)-1))

Fixed submission:
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(2**n)
dp[0]=1
for i in range(1,2**n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(2**j)]
                    dp[i]%=mod


print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
def dp(p,vw):
    if p==n:
        return 1
    k=0
    
            
    for j in range(n):
        if g[p][j]==1 and vw[j]==0:
            #print(p,j)

            vw[j]=1
            k+=dp(p+1,vw)
            k%=mod
            #print(vw)

            vw[j]=0
                    
    return k%mod

viw=[0]*n
print(dp(0,viw))
            
    
    

Fixed submission:
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(2**n)
dp[0]=1
for i in range(1,2**n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(2**j)]
                    dp[i]%=mod


print(dp[-1]%mod)

Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))

def dp(p,vw):
    if p==n:
        return 1
    k=0
    
            
    for j in range(n):
        if g[p][j]==1 and vw[j]==0:
            #print(p,j)

            vw[j]=1
            k+=dp(p+1,vw)
            #print(vw)

            vw[j]=0
                    
    return k

viw=[0]*n
print(dp(0,viw))
            
    
    

Fixed submission:
n = int(input())
g=[]
for i in range(n):
    
    g.append(list(map(int,input().split())))
mod=10**9+7
dp=[0]*(2**n)
dp[0]=1
for i in range(1,2**n):
    e=bin(i)[2:]
    y=e.count('1')
    for j in range(len(e)):
        if e[-j-1]=='1':
            if g[y-1][j]:
                    dp[i]+=dp[i-(2**j)]
                    dp[i]%=mod


print(dp[-1]%mod)