Problem:
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.

Incorrect submission (verdict: Wrong Answer):
h,w,k = map(int,input().split())

import copy

ar = [[0 for _ in range(w)] for _ in range(h)]


for i in range(h):
    ar[i] = list(input())

print(ar)
d = {}
for i in range(h):
    for j in range(w):
        d[(i+1,j+1)] = ar[i][j]

print(d)
sm = 0
for i in d.values():
    if(i == "#"):
        sm += 1

gl = sm - k
print("gl",gl)

ans = 0
def ch_red(x):
    d_tmp = copy.deepcopy(d)
    #print(d_tmp)
    cnt = 0
    x_ar_bin = [0 for _ in range(h+w)]
    v = h+w
    for i in range(h+w):
        x_ar_bin[i] = int(bin(x >> i),2)%2
    
    #print(x_ar_bin)

    for i in range(h):
        if(x_ar_bin[i] == 0):
            continue
        else:
            for j in range(w):
                key = (i+1,j+1)
                if(d_tmp[key] == "#"):
                    d_tmp[key] = "$"
                    cnt += 1
    
    for i in range(h,h+w):
        if(x_ar_bin[i] == 0):
            continue
        else:
            for j in range(h):
                key = (j+1,i+1-h)
                if(d_tmp[key] == "#"):
                    d_tmp[key] = "$"
                    cnt += 1
    
    
    if(cnt == gl):
        return 1
    else:
        return 0

    #print(cnt)

mx = 2**(h+w)

print(mx)
for i in range(mx):
    ans += ch_red(i)

print(ans)






Fixed, accepted submission:
h,w,k = map(int,input().split())

import copy

ar = [[0 for _ in range(w)] for _ in range(h)]


for i in range(h):
    ar[i] = list(input())

#print(ar)
d = {}
for i in range(h):
    for j in range(w):
        d[(i+1,j+1)] = ar[i][j]

#print(d)
sm = 0
for i in d.values():
    if(i == "#"):
        sm += 1

gl = sm - k
#print("gl",gl)

ans = 0
def ch_red(x):
    d_tmp = copy.deepcopy(d)
    #print(d_tmp)
    cnt = 0
    x_ar_bin = [0 for _ in range(h+w)]
    v = h+w
    for i in range(h+w):
        x_ar_bin[i] = int(bin(x >> i),2)%2
    
    #print(x_ar_bin)

    for i in range(h):
        if(x_ar_bin[i] == 0):
            continue
        else:
            for j in range(w):
                key = (i+1,j+1)
                if(d_tmp[key] == "#"):
                    d_tmp[key] = "$"
                    cnt += 1
    
    for i in range(h,h+w):
        if(x_ar_bin[i] == 0):
            continue
        else:
            for j in range(h):
                key = (j+1,i+1-h)
                if(d_tmp[key] == "#"):
                    d_tmp[key] = "$"
                    cnt += 1
    
    
    if(cnt == gl):
        return 1
    else:
        return 0

    #print(cnt)

mx = 2**(h+w)

#print(mx)
for i in range(mx):
    ans += ch_red(i)

print(ans)