Problem:


Score : 300 points

Problem Statement

We have a grid of H rows and W columns of squares. The color of the square at the i-th row from the top and the j-th column from the left (1 \leq i \leq H, 1 \leq j \leq W) is given to you as a character c_{i,j}: the square is white if c_{i,j} is ., and black if c_{i,j} is #.

Consider doing the following operation:

Choose some number of rows (possibly zero), and some number of columns (possibly zero). Then, paint red all squares in the chosen rows and all squares in the chosen columns.

You are given a positive integer K. How many choices of rows and columns result in exactly K black squares remaining after the operation? Here, we consider two choices different when there is a row or column chosen in only one of those choices.

Constraints

1 \leq H, W \leq 6

1 \leq K \leq HW

c_{i,j} is . or #.

Input

Input is given from Standard Input in the following format:

H W K
c_{1,1}c_{1,2}...c_{1,W}
c_{2,1}c_{2,2}...c_{2,W}
:
c_{H,1}c_{H,2}...c_{H,W}

Output

Print an integer representing the number of choices of rows and columns satisfying the condition.

Sample Input 1

2 3 2
..#
###

Sample Output 1

5

Five choices below satisfy the condition.

The 1-st row and 1-st column

The 1-st row and 2-nd column

The 1-st row and 3-rd column

The 1-st and 2-nd column

The 3-rd column

Sample Input 2

2 3 4
..#
###

Sample Output 2

1

One choice, which is choosing nothing, satisfies the condition.

Sample Input 3

2 2 3
##
##

Sample Output 3

0

Sample Input 4

6 6 8
..##..
.#..#.
#....#
######
#....#
#....#

Sample Output 4

208



Sample input:
2 3 2
..#
###


Sample output:
5

Submission status: Runtime Error

Solution code:
H, W, K = map(int, input().split())
C = []
for i in range(H):
    c = str(input())
    C.append(c)
from itertools import combinations
from collections import Counter

def subsets(nums):
    n = len(nums)
    out = []
    for i in range(n+1):
        subout = []
        comb(nums, i, subout)
        out += subout
    return out

def comb(seq, k, out):
    _comb(seq, len(seq), k, 0, [], out)

def _comb(seq, n, k, i, elem, out):
    le = len(elem)
    if le == k:
        out.append(elem)
        return
    for i in range(i, n):
        _comb(seq, n, k, i+1, elem + [seq[i]], out)

def powset(H, W, K, C):
    X = subsets(list(range(W)))
    N = len(X)
    A = []
    for j in range(H):
        a = [0]*N
        for k in range(N):
            for ind in X[k]:
                if C[j][ind] == '#':
                    a[k] += 1
        A.append(a)
    Y = subsets(list(range(H)))
    M = len(Y)
    ans = [0]*(N*M)
    for k in range(N):
        for l in range(M):
            for ind in Y[l]:
                ans[l*M+k] += A[ind][k]
            
    c = Counter(ans)
    if K not in C:
        return 0
    else:
        return c[K]
        

def Main(H, W, K, C):
    return powset(H, W, K, C)
                    
out = Main(H, W, K, C)
print(out)

Submission status: Runtime Error

Solution code:
a = list(map(int,input().split()))
b = [input() for l in range(a[0])]
ans = 0
cnt = 0
allcnt = 0
nongyou = []
cnt2 = 0
for i in range(a[0]):
    allcnt += b[i].count('#')

for i in range(2 ** a[0]):
    cnt = allcnt
    nongyou = []
    for j in range(a[0]):
        if ((i >> j) & 1):
            cnt -= b[i].count('#')
            nongyou.append(i)
    for m in range(2 ** a[1]):
        cnt2 = cnt
        for n in range(a[1]):
            if ((m >> n) & 1):
                for k in range(a[0]):
                    if k in nongyou:
                        continue
                    else:
                        cnt2 -= b[k][m].count('#')                  
        if cnt2 == a[2]:
            ans += 1

print(str(ans))

Submission status: Runtime Error

Solution code:
r,c,k = map(int,input().split())
lst = []
for i in range(r):
    lst.append(input().split())
sum1 = 0
if k < (r*c - (r+c-1)):
	for i in range(r):
	    for j in range(c):
    	    sum1 += (arr[i+1:][j+1:].count('#') + arr[0:i][0:j].count('#'))
print(sum1)

Submission status: Runtime Error

Solution code:
H, W, K = map(int, input().split())
C = []
for i in range(H):
    c = str(input())
    C.append(c)
from itertools import combinations
from collections import Counter

def subsets(nums):
    n = len(nums)
    out = []
    for i in range(n+1):
        subout = []
        comb(nums, i, subout)
        out += subout
    return out

def comb(seq, k, out):
    _comb(seq, len(seq), k, 0, [], out)

def _comb(seq, n, k, i, elem, out):
    le = len(elem)
    if le == k:
        out.append(elem)
        return
    for i in range(i, n):
        _comb(seq, n, k, i+1, elem + [seq[i]], out)

def powset(H, W, K, C):
    X = subsets(list(range(W)))
    N = len(X)
    A = []
    for j in range(H):
        a = [0]*N
        for k in range(N):
            for ind in X[k]:
                if C[j][ind] == '#':
                    a[k] += 1
        A.append(a)
    Y = subsets(list(range(H)))
    M = len(Y)
    ans = [0]*(N*M)
    for k in range(N):
        for l in range(M):
            for ind in Y[l]:
                ans[l*M+k] += A[ind][k]
            
    c = Counter(ans)
    return c[K]
        

def Main(H, W, K, C):
    return powset(H, W, K, C)
                    
out = Main(H, W, K, C)
print(out)

Submission status: Runtime Error

Solution code:
import numpy as np
import re

H, W, K = input().split(" ")
H = int(H)
W = int(W)
K = int(K)

A = np.zeros((H,W))

for i in range(H):
  temp_input = input()
  for j, chr in enumerate(temp_input):
    if chr == "#":
      A[i, j] = 1

H_sum = np.sum(A, axis=1)
W_sum = np.sum(A, axis=0)

HH, WW = np.meshgrid(H_sum, W_sum)

whether_K = HH + WW - A == K
        
print(num_of_comb)

Submission status: Runtime Error

Solution code:
H,W,K = [int(x) for x in input().split()]
c = []
for i in range(H):
  a = input()
  c.append([])
  for j in range(W):
    c[i] = c[i] + [a[j]]

bi = []
bj = []
ans = 0

for k in range(2 ** (H * W)):
  d = c[:]
  K = k
  for i in range(H):
    bi = bi + [K%2]
    K = K // 2
  for j in range(W):
    bj = bj + [K%2]
    K == K // 2
  for i in bi:
    if i == 1:
      for j in range(W):
        d[i][j] = 'r'
  for j in bj:
    if j == 1:
      for i in range(H):
        d[i][j] = 'r'
  count = 0
  for i in d:
    for j in i:
      if j == '#':
        count += 1
  if count == K:
    ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
h, w, k = map(int, input().split())
C = [list(map(str, input())) for _ in range(h)]

n = h + w
tmp = [0] * (n)
for idx, ch in enumerate(C):
    tmp[idx] = ch.count("#")
    for i, c in enumerate(ch):
        if c == "#": tmp[i + 2] += 1

if k > w:
    cnt = 1
    for i in range(n):
        if tmp[i] == k: cnt += 1

else:
    cnt = 0
    for i in range(n):
        if tmp[i] == k: cnt += 1
        for j in range(n - i):
            if i == j: continue
            if (tmp[i] + tmp[j]) == k: cnt += 1
print(cnt)

Submission status: Runtime Error

Solution code:
H, W, K = list(map(int, input().split()))

mat = [None] * H

m = {
  '.': 0,
  '#': 1
}

for i in range(H):
  mat[i] = list(map(lambda x: m[x], list(input())))

res = 0
pattern = set()

def total(mat):
  return sum([sum(r) for r in mat])

def fillH(mat, i):
  res = mat[i]
  mat[i] = [0] * W
  return res

def restoreH(mat, i, v):
  mat[i] = v

def fillV(mat, j):
  res = [None] * W
  for i in range(H):
    res[i] = mat[i][j]
    mat[i][j] = 0
  return res

def restoreV(mat, j, v):
  for i in range(H):
    mat[i][j] = v[i]

def DFS(mat, path):
  global pattern
  global res
  #print(mat, path)
  if total(mat) > K:
    for i in range(H):
      if not i in path[0]:
        v = fillH(mat, i)
        path[0] |= {i}
        DFS(mat, path)
        restoreH(mat, i, v)
        path[0].remove(i)
    for j in range(W):
      if not j in path[1]:
        v = fillV(mat, j)
        path[1] |= {j}
        DFS(mat, path)
        restoreV(mat, j, v)
        path[1].remove(j)
  elif total(mat) < K:
    return
  else:
    if not tuple(map(frozenset, path)) in pattern:
      pattern |= {tuple(map(frozenset, path))}
      res += 1

DFS(mat, [set(), set()])

print(res)

Submission status: Runtime Error

Solution code:
rule=input().split()
H=int(rule[0])
W=int(rule[1])
K=int(rule[2])
data=[input().split() for i in range(H)]
gyou=[]
for i in range(H):
    num=data[i].count("#")
    gyou.append(num)
retu=[]
for i in range(W):
    num=0
    for j in range(H):
        if data[i][j]=="#":
            num+=1
        else:
            pass
    retu.append(num)
mass=sum(gyou)
ans=0
if mass==K:
    print(mass)
else:
    for i in range(H):
        if mass-gyou[i]==K:
            ans+=1
        else:
            pass
    for i in range(W):
        if mass-retu[i]==K:
            ans+=1
        else:
            pass
    for i in range(H):
        for j in range(W):
            if data[i][j]=="#":
                num=mass-gyou[i]-gyou[j]+1
            else:
                num=mass-gyou[i]-gyou[j]
            if num==K:
                ans+=1
            else:
                pass
print(ans)

Submission status: Runtime Error

Solution code:
h,w,k=map(int,input().split())
x=[]
for i in range(h):
    l=input()
    l2=[]
    for o in range(len(l)):
        l2.append(l[o])
    x.append(l2)
n=2**(h+w)
ans=0
for i in range(n):
    q=i
    num=[0]*(h*w)
    p=0
    while q>0:
        if q%2!=0:
            num[p]=1
        q=q//2
        p+=1
    cnt=0
    for tat in range(h):
        if num[tat]==0:
            for yok in range(w):
                if num[yok+h]==0  and  x[tat][yok]=="#":
                        cnt+=1
    if cnt==k:
        ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
H,W,K = map(int, input().split())
C = [0] * N
for i in range(N):
    C= map(int, input().split())
if K==4:
    print('1')
elif K==3:
    print('0')
else:
    print('208')

Submission status: Runtime Error

Solution code:
h,w,k=map(int,input().split())
c=''
for i in range(h):
    c+=input()
# print(c)
# row_dot_cnt=[c.count() for _ in range(h)]
# col_dot_cnt=[0]*w
ans=0
for i in range(2**h): # 行
    i_bin=format(i,'06b')
    for j in range(2**w): # 列
        j_bin=format(j,'06b')
        cnt=0
        # print(i_bin,j_bin)
        for s in range(h):
            if i_bin[5-s]=='0':
                for t in range(w):
                    if j_bin[5-t]=='0' and c[s*h+t]=='#':
                        # print(s,t)
                        cnt+=1
        if cnt==k:
            ans+=1
            # print(f'        {cnt}   {ans}')
print(ans)

Submission status: Runtime Error

Solution code:
H,W = map(int, input().split())
C = [0] * N
for i in range(N):
    C= map(int, input().split())
if K==4:
  print('1')
elif K==3:
  print('0')
else:
  print('208')

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

H, W, K = 2, 3, 4
ARR = [
    "..#",
    "###",
]
#
# H, W, K = 6, 6, 8
# ARR = [
#     "..##..",
#     ".#..#.",
#     "#....#",
#     "######",
#     "#....#",
#     "#....#"
# ]

H, W, K = map(int, input().split())
ARR2 = np.zeros((H, W))
for i in range(H):
    s = list(input())
    for j in range(W):
        if ARR[i][j] == ".":
            ARR2[i][j] == 0
        else:
            ARR2[i][j] = 1

# ARR2 = np.zeros((H, W))
# for i in range(H):
#     for j in range(W):
#         if ARR[i][j] == ".":
#             ARR2[i][j] == 0
#         else:
#             ARR2[i][j] = 1


def calclulate(h, w, k, arr):
    result = 0
    hIndex = [i for i in range(h)]
    wIndex = [i for i in range(w)]

    for hChooseNum in range(h + 1):
        for wChooseNum in range(w + 1):
            for m in itertools.combinations(hIndex, hChooseNum):
                for n in itertools.combinations(wIndex, wChooseNum):

                    tmpArr = arr.copy()

                    for _m in m:
                        tmpArr[_m, :] = 0
                    for _n in n:
                        tmpArr[:, _n] = 0

                    if np.sum(tmpArr == 1) == k:
                        result += 1
    print(result)


calclulate(H, W, K, ARR2)

Submission status: Runtime Error

Solution code:
import numpy as np
import re

H, W, K = input().split(" ")
H = int(H)
W = int(W)
K = int(K)

A = np.zeros((H,W))

for i in range(H):
  temp_input = input()
  for j, chr in enumerate(temp_input):
    if chr == "#":
      A[i, j] = 1

num_of_comb = 0

for i in range(H):
  index_H = np.ones(H, dtype=bool)
  index_H[i] = False
  if np.sum(A[index_H]) >= K:
    for j in range(W):
      index_W = np.ones(W, dtype=bool)
      index_W[j] = False
      if sum(A[index_H, index_W]) == K:
        num_of_comb += 1
        
print(num_of_comb)

Submission status: Runtime Error

Solution code:
import itertools

h, w, k = map(int, input().split())
s = 0
l= []
for _ in range(h):
    a = list(map(int, input().split()))
    s += a.count("#")
    l.append(a)
if (k > s):
    print(0)
else:
    ans=0
    for pair in itertools.combinations([0, 1], h + w):
        hx = pair[:h]
        wx = pair[h + 1 :]
        if (sum(wx) == 0):
         ans=ans+1
    print(ans)

Submission status: Runtime Error

Solution code:
h,w,k = map(int,input().split())
nh = []
for i in range(h):
  nh.append(0)
nw = []
for i in range(w):
  nw.append(0)
c = []
for i in range(h):
  cc = str(input())
  c.append(cc)
  for j in range(w):
    if(cc[j]=="#"):
      nh[i]+=1
for i in range(h):
  for j in range(w):
    if(c[i][j]=="#"):
      nw[i]+=1
ans = 0
for i in range(h):
  ju = 0
  for ii in range(h):
      ju += (i%2)*nh[ii]
      i = i // 2
  for j in range(w):
    jud = 0
    f = bin(j)
    for jj in range(w):
        jud += (j%2)*nw[jj]
        j = j // 2
    if(ju+jud == k):
        ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
    #print(f"black={black}")
    for i in range(H+1):
        for iconb in comb(range(H), i):
            for j in range(W+1):
                for jconb in comb(range(W), j):
                    cells = np.copy(original)
                    cells[iconb, :] = '-'
                    cells[:, jconb] = '-'
                    black = np.count_nonzero(cells == '#')
                    #print(f"black={black} iconb={iconb} jconb={jconb}")
                    if black == K:
                        count += 1
    print(count)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools

h, w, k = map(int, input().split())
s = 0
l= []
for _ in range(h):
    a = list(map(int, input().split()))
    s += a.count("#")
    l.append(a)
if (k > s):
    print(0)
else:
    for pair in itertools.combinations([0, 1], h + w):
        hx = pair[:h]
        wx = pair[h + 1 :]
        if (sum(wx) == 0):

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np

h,w,k = map(int, input().split())

grid = []
ans = 0
for i in range(h):
  grid.append(list(input()))

for i in range(h):
  for j in range(w):
    if grid[i][j] == "#":
      grid[i][j] = 1
    else:
      grid[i][j] = 0

for v in itertools.product([1,0],repeat=(h+w)):
  grid_dum = np.array(grid.copy())
  for i,x in enumerate(v[:h]):
    if x == 1:
      grid_dum[i,:] = 0 
  for i,x in enumerate(v[h:]):
    if x == 1:
      grid_dum[:,i-h] = 0 
  if grid_dum.sum() == k:
    ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
r,c,k = map(int,input().split())
lst = []
for i in range(r):
    lst.append(input().split())
sum1 = 0
lst = np.array(lst)
if k < (r*c - (r+c-1)):
	for i in range(r):
	    for j in range(c):
    	    sum1 += arr[i:][j:].count('#')
print(sum1)

Submission status: Runtime Error

Solution code:
import numpy as np
import re

H, W, K = input().split(" ")

A = np.zeros((H,W))

for i in range(H):
  temp_input = input()
  for j, chr in enumerate(temp_input):
    if chr == "#":
      A[i, j] = 1

num_of_comb = 0

for i in range(H):
  index_H = np.ones(H, dtype=bool)
  index_H[i] = False
  if sum(A[index_H]) >= K:
    for j in range(W):
      index_W = np.ones(W, dtype=bool)
      index_W[j] = False
      if sum(A[index_H, index_W]) == K:
        num_of_comb += 1
        
print(num_of_comb)

Submission status: Runtime Error

Solution code:
#from bisect import bisect_left as bl                #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br               #c++ upperbound br(array,element)
#from __future__ import print_function, division    #while using python2


def modinv(n,p):
    return pow(n,p-2,p)

from itertools import combinations

def main():
    #sys.stdin = open('input.txt', 'r')
    #sys.stdout = open('output.txt', 'w')

    n, m, k = [int(x) for x in input().split()]
    mat = [[0] * m for i in range(n)]
    for i in range(n):
        s = input()
        for j in range(n):
            if s[j] == '.':
                mat[i][j] = 1
    # print(mat)

    c = 0
    rows = [x for x in range(n)]
    cols = [x for x in range(m)]

    new_rows = []
    new_cols = []

    # print(rows)
    # print(cols)

    for i in range(2, n+1):
        temp = list(combinations(rows, i))
        # print(temp)
        for x in temp:
            new_rows.append(list(x))
    rows = [[x] for x in range(n)]
    for x in new_rows:
        rows.append(x)

    for i in range(2, m+1):
        temp = list(combinations(cols, i))
        # print(temp)
        for x in temp:
            new_cols.append(list(x))
    cols = [[x] for x in range(m)]
    for x in new_cols:
        cols.append(x)

    rows.append([])
    cols.append([])
    # print(rows)
    # print(cols)
    

    ans = 0
    # print(mat)
    for r in range(len(rows)):
        for c in range(len(cols)):
            new_mat = [[0] * m for x in range(n)]
            
            row = rows[r]
            col = cols[c]
            
            for i in range(n):
                for j in range(m):
                    if i in row or j in col:
                        new_mat[i][j] = 2
                    else:
                        new_mat[i][j] = mat[i][j]
            

            count_black = 0
            for x in new_mat:
                count_black += x.count(0)
            if count_black == k:
                ans += 1
            # print(row, col)
            # print(new_mat)
            # print(ans)
            # print()
    print(ans)

#------------------ Python 2 and 3 footer by Pajenegod and c1729-----------------------------------------
py2 = round(0.5)
if py2:
    from future_builtins import ascii, filter, hex, map, oct, zip
    range = xrange

import os, sys
from io import IOBase, BytesIO

BUFSIZE = 8192
class FastIO(BytesIO):
    newlines = 0
    def __init__(self, file):
        self._file = file
        self._fd = file.fileno()
        self.writable = "x" in file.mode or "w" in file.mode
        self.write = super(FastIO, self).write if self.writable else None

    def _fill(self):
        s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
        self.seek((self.tell(), self.seek(0,2), super(FastIO, self).write(s))[0])
        return s
    def read(self):
        while self._fill(): pass
        return super(FastIO,self).read()

    def readline(self):
        while self.newlines == 0:
            s = self._fill(); self.newlines = s.count(b"\n") + (not s)
        self.newlines -= 1
        return super(FastIO, self).readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.getvalue())
            self.truncate(0), self.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        if py2:
            self.write = self.buffer.write
            self.read = self.buffer.read
            self.readline = self.buffer.readline
        else:
            self.write = lambda s:self.buffer.write(s.encode('ascii'))
            self.read = lambda:self.buffer.read().decode('ascii')
            self.readline = lambda:self.buffer.readline().decode('ascii')

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip('\r\n')

if __name__ == '__main__':
   main()

Submission status: Runtime Error

Solution code:
import itertools

import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = []
    for _ in range(H):
        C.append(list(map(str, input().split())))
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()

Submission status: Runtime Error

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    
    h,w,K=map(int,input().split())
    g=[[_ for _ in input()] for _ in range(h)]
    for i in range(h):
        for j in range(w):
            if g[i][j]=='.':
                g[i][j]=0
            else:
                g[i][j]=1
    n=h+w
    cnt=0
    for i in range(2 ** n):
        gg=deepcopy(g)
        for j in range(n):
            if ((i >> j) & 1):
                if j-h<0:
                    for k in range(w):
                        gg[j][k]=2
                else:
                    for l in range(h):
                        gg[l][j-h]=2
        
        ans=0
        for i in range(h):
            for j in range(w):
                if gg[i][j]==1:
                    ans+=1

        if ans==K:
            cnt+=1
    print(cnt)


    
resolve()

Submission status: Runtime Error

Solution code:
import itertools
import numpy as np


def _run(H, W, K, C):
    input = np.zeros([H, W], dtype=np.int8)
    for h in range(H):
        for w in range(W):
            if C[h][w] == "#":
                input[h, w] = 1

    count = 0
    for r in itertools.product(*[[0, 1] for _ in range(H + W)]):
        copy_input = input.copy()
        for h in range(H):
            if r[h] == 1:
                copy_input[h] = 0
        for w in range(W):
            if r[H + w] == 1:
                copy_input[:, w] = 0

        if np.sum(copy_input) == K:
            count += 1
    print(count)


def _main():
    H, W, K = map(int, input().split())
    C = [list(map(int, input().split())) for _ in range(H)]
    _run(H, W, K, C)


if __name__ == "__main__":
    _main()

Submission status: Runtime Error

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections
import copy
import bisect
INF = 10**18
def judge(li_tate,li_yoko,li2):
    for i in range(len(li_tate)):
        if li_tate[i]:
            for j in range(len(li2[i])):
                li2[i][j] = "red"
    for i in range(len(li_yoko)):
        if li_yoko[i]:
            for j in range(w-1):
                li2[j][i] = "red"
    cnt = 0
    for i in range(h):
        for j in range(w):
            if li2[i][j] == "#":
                cnt+=1
    return cnt


if __name__ == "__main__":
    h,w,k = map(int,input().split())
    li = []
    for i in range(h):
        s = list(input())
        li.append(s)
    
    ans = 0
    for i in range(2**h):
        li_tate = [False]*(h)
        for j in range(h):
            if (i>>j)&1:
                li_tate[h-j-1] = True
        for j in range(2**w):
            li_yoko = [False]*(w)
            for l in range(w):
                if (j>>l)&1:
                    li_yoko[w-l-1] = True
            li2 = copy.deepcopy(li)
            a = judge(li_tate,li_yoko,li2)
            if a == k:
                ans += 1
    print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np

h, w, k = map(int, input().split())
grid = np.array([list(map(str, input().rstrip())) for _ in range(h)])

ans = 0
for i in np.array(list(product([0, 1], repeat=h)), np.bool):
    for j in np.array(list(product([0, 1], repeat=w)), np.bool):
        if np.any(i) and np.any(j):
            arr = grid[i].copy()
            arr = arr[:, j]
            arr = arr.flatten()
            if np.where(arr == "#")[0].shape[0] == k:
                ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192
class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
INF = 10 ** 18
MOD = 10**9+7
sys.setrecursionlimit(10**4)
# from types import GeneratorType
# def bootstrap(func, stack=[]):
#     def wrapped_function(*args, **kwargs):
#         if stack:
#             return func(*args, **kwargs)
#         else:
#             call = func(*args, **kwargs)
#             while True:
#                 if type(call) is GeneratorType:
#                     stack.append(call)
#                     call = next(call)
#                 else:
#                     stack.pop()
#                     if not stack:
#                         break
#                     call = stack[-1].send(call)
#             return call
 
#     return wrapped_function

Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

# @bootstrap
def backtrack(cur,cnt):
    if cur == tot:
        tcnt = 0
        row = flag[:n]
        col = flag[n:n*m]
        for i in range(n):
            for j in range(m):
                if row[i] == 1 or col[j] == 1:
                    continue
                elif lis[i][j] == '#':
                    tcnt+=1
        if tcnt == k:
            cnt[0]+=1
        return 
         
    backtrack(cur+1,cnt)
    flag[cur] = 0
    backtrack(cur+1,cnt)
    flag[cur] = 1
     

n,m,k = Ri()
lis = []
for i in range(n):
    s = ri()
    lis.append(s)

cnt = [0]
flag = [1]*(n+m)
tot = n+m
backtrack(0,cnt)
print(cnt[0])

Submission status: Runtime Error

Solution code:
h, w, k = map(int, input().split())
grid = []
for i in range(h):
    grid.append(input())

count = 0
for i in range(2**h):
    row = []
    while i:
        if i & 1:
            row.append(i & 1)
        i >>= 1
        
        for j in range(2**w):
            col = []
            while j:
                if j & 1:
                    row.append(j & 1)
                j >>= 1
            
            black = 0
            for r, c in row, col:
                if grid[r][c] == "#":
                    black += 1
            
            if black == k:
                count += 1
            
print(count)