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 = [0]*H

for i in range(H):
    C[i] = list(str(input()))
    

    
def gyotsubushi(n,E):
    if I[n] == 1:
        E[n] = ['R']*W
        #print('GYO')
        
def retsutsubushi(n,E):
    if J[n] == 1:
        for i in range(H):
            E[i][n] = 'R'
            
def ango(lis):
    num = 1
    summ = 0
    for i in range(H+W):
        summ += lis[i]*num
        num *= 2
    return(summ)
    
            
stock = [0]*1024
counter = 0
import copy
for i0 in range(2):
    for i1 in range(2):
        for i2 in range(2):
            for i3 in range(2):
                for i4 in range(2):
                    for i5 in range(2):
                        for j0 in range(2):
                            for j1 in range(2):
                                for j2 in range(2):
                                    for j3 in range(2):
                                        for j4 in range(2):
                                            for j5 in range(2):
                                                preI = [i0,i1,i2,i3,i4,i5]
                                                preJ = [j0,j1,j2,j3,j4,j5]
                                                I = preI[0:H]
                                                J = preJ[0:W]
                                                
                                                if stock[ango(I+J)]==1:
                                                    break
                                                stock[ango(I+J)]=1
                                                D = copy.deepcopy(C)
                                                #print(D,I,J)
                                                for i in range(H):
                                                    gyotsubushi(i,D)
                                                for j in range(W):
                                                    retsutsubushi(j,D)
                                                #print(D)
                                                count = 0
                                                for i in range(H):
                                                    for j in range(W):
                                                        if D[i][j] == '#':
                                                            count += 1
                                                if count == K:
                                                    counter += 1

    
print(counter)

Submission status: Runtime Error

Solution code:
H, W, K = map(int, input().split())
C = []
for i in range(H):
    tmp = list(map(str, input().split()))
    C.append(tmp)
black = 0
for c in C: black += c.count('#')

row = [r.count('#') for r in c]
tpC = [list(x) for x in zip(*C)]
colum = [r.count('#') for r in tpC]

ans = 0
for i in range(2**H):
    Rchoice = [0]*H
    for k in range(H):
        if (i-2**k) % 2 == 0: Rchoice[k] = 1
    Rdel = sum([row[i] * Rchoice[i] for i in range(H)])
    for j in range (2**W):
        Cchoice = [0]*W
        for k in range(W):
            if (i-2**k) % 2 == 0: Cchoice[k] = 1
        Cdel = sum([colum[i] * Cchoice[i] for i in range(W)])
        doublecount = 0
        for l in range(H):
            for m in range(W):
                if Rchoice[l] * Cchoice[m] == 1 and C[l][m] == '#':
                    doublecount += 1
        if black - Rdel - Cdel + doublecount == K:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

N = int(input())
A = list(map(int,input().split()))

A.sort(reverse=True)
#print(A)

ans = 0
list = []
for i in range(N):
  if ( i==0 ) :
    list.append(A[0])
  else:
    max_index = list.index(max(list))
    ans += list[max_index]
    list[max_index] = A[i]
    list.insert(max_index, A[i])
  #print(list,ans)

print(ans)

Submission status: Runtime Error

Solution code:
h,w,k=map(int,input().split())
table=[]
cntr=[]
cntc=[]
for i in range(h):
  row=str(input())
  table.append(row)
  cntr.append(row.count('#'))

for i in range(w):
  b_num=0
  for j in range(h):
    if table[j][i]=="#":
      b_num+=1
  cntc.append(b_num)
total=sum(cntr)
def myfunc(r,c):
    if r==0 and c==0:
        return 0
    elif r==0:
        return cntc[c-1]
    elif c==0:
        return cntr[r-1]
    else:
        return (cntr[r-1] + cntc[c-1]) if table[r-1][c-1]!="#" else (cntr[r-1] + cntc[c-1]-1)
ans=0    
for i in range(h):
    for j in range(i+1,h,1):
        if k == total-(cntr[i]+cntr[j]):
            ans+=1
for i in range(w):
    for j in range(i+1,h,1):
        if k == total-(cntc[i]+cntc[j]):
            ans+=1
for i in range(h+1):
    for j in range(w+1):
        #print(myfunc(i,j))
        if k==(total-myfunc(i,j)):
            ans+=1
print(ans)

Submission status: Runtime Error

Solution code:
h, w, k = map(int, input().split())
p = [list(str(input())) for _ in range(h)]
bl = p.count('#')
bl = bl - k
ee = list(range(h))
q = list(range(w))
kotae = 0
pp = []
qq = []
for i in range(h + 1):
    pp += list(itertools.combinations(ee, i))
for i in range(w + 1):
    qq += list(itertools.combinations(q, i))
for i in pp:
    for j in qq:
        ans = 0
        for zz in range(h):
            for ww in range(w):
                if zz not in i:
                    if ww not in j:
                        if p[zz][ww] == '#':
                            ans += 1
        if ans == k:
            kotae += 1
print(kotae)

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

sum_A = np.sum(A)

num_of_comb = 0

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

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

num_of_comb += np.sum(sum_A - H_sum ==K) + np.sum(sum_A - W_sum==K) + (sum_A==K)

print(num_of_comb)

Submission status: Runtime Error

Solution code:
import numpy as np
H,W,K = map(int,input().split())
c = [input().split() for l in range(H)]

c1 = c.count("#")

num = 0
while c1 > K:
  for i in range(H,W)
  c = np.delete(c, H, W)
  num += 1
  
print(num)

Submission status: Runtime Error

Solution code:
import copy
def count(picture, ans_num):
    count_num = 0
    flag = 0
    for row in range(len(picture)):
        for column in range(len(picture)):
            if picture[row][column] == '#':
                count_num = count_num + 1
    if count_num == ans_num:
        flag = 1
    return flag


if __name__ == "__main__":
    ans_list = input().split(' ')
    num_list = []
    picture = []
    ans_num = 0

    for ans in ans_list:
        num_list.append(int(ans))
    # 入力絵の作成（list化）
    for row_num in range(num_list[0]):
        picture.append(list(input()))

    # padding
    for num in range(num_list[0]):
        picture[num].append('0')
    zero_list = []
    for n in range(num_list[1]+1):
        zero_list.append('0')
    picture.append(zero_list)

    # 探索a
    for row in range(len(picture)):
        # 初期化必要
        tmp_picture = copy.deepcopy(picture)
        tmp_picture[row] = zero_list
        for column in range(len(picture[0])):
            # 初期化必要
            tmp_tmp_picture = copy.deepcopy(tmp_picture)
            for n in range(len(picture)):
                tmp_tmp_picture[n][column] = '0'
            ans_num = ans_num + count(tmp_picture, num_list[2])
            print(tmp_tmp_picture)

    print(ans_num)

Submission status: Runtime Error

Solution code:
H, W, K = map(int, input().split)
C = []
for i in range(H):
    tmp = list(map(str, input().split))
    C.append(tmp)
black = 0
for c in C: black += c.count('#')

row = [r.count('#') for r in c]
tpC = [list(x) for x in zip(*C)]
colum = [r.count('#') for r in tpC]

ans = 0
for i in range(2**H):
    Rchoice = [0]*H
    for k in range(H):
        if (i-2**k) % 2 == 0: Rchoice[k] = 1
    Rdel = sum([row[i] * Rchoice[i] for i in range(H)])
    for j in range (2**W):
        Cchoice = [0]*W
        for k in range(W):
            if (i-2**k) % 2 == 0: Cchoice[k] = 1
        Cdel = sum([colum[i] * Cchoice[i] for i in range(M)])
        doublecount = 0
        for l in range(H):
            for m in range(W):
                if Rchoice[l] * Cchoice[m] == 1 and C[l][m] == '#':
                    doublecount += 1
        if black - Rdel - Cdel + doublecount == K:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
H, W, K = map(int, input().split)
C = []
for i in range(H):
    tmp = list(map(int, input().split))
    C.append(tmp)
black = 0
for c in C: black += c.count('#')

row = [r.count('#') for r in c]
tpC = [list(x) for x in zip(*C)]
colum = [r.count('#') for r in tpC]

ans = 0
for i in range(2**H):
    Rchoice = [0]*H
    for k in range(H):
        if (i-2**k) % 2 == 0: Rchoice[k] = 1
    Rdel = sum([row[i] * Rchoice[i] for i in range(H)])
    for j in range (2**W):
        Cchoice = [0]*W
        for k in range(W):
            if (i-2**k) % 2 == 0: Cchoice[k] = 1
        Cdel = sum([colum[i] * Cchoice[i] for i in range(M)])
        doublecount = 0
        for l in range(H):
            for m in range(W):
                if Rchoice[l] * Cchoice[m] == 1 and C[l][m] == '#':
                    doublecount += 1
        if black - Rdel - Cdel + doublecount == K:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
import numpy as np
d = stdin.readline().rstrip().split()
H = int(d[0])
W = int(d[1])
K = int(d[2])

data = []
bCount = 0
result = 0
for el1 in range(H):
    tmp = stdin.readline().rstrip().split()
    d = []
    for el in tmp:
        for el3 in el:
            if el3 == '#':
                bCount += 1
            d.append(el3)
    data.append(d)
tr = []
for i in range(W):
    tr_row = []
    for vector in data:
        tr_row.append(vector[i])
    tr.append(tr_row)
data2 = tr
counter = 0
for el in range(H+W):
    counter += 2**el
for el in range(counter+1):
    bin_str = ''.join(list(reversed(str(bin(el))[2:])))
    poss = []
    count = 0
    for el2 in bin_str:
        if el2 == '1':
            poss.append(count)
        count += 1
    res = 0
    for el2 in poss:
        if el2 >= H:
            el2 -= H
            res += data2[el2].count('#')
        else:
            res += data[el2].count('#')
    if bCount-res == K:
        result += 1

print(result)

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

sum_A = np.sum(A)

num_of_comb = 0

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

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

num_ob_comb += np.sum(sum_A - H_sum ==K) + np.sum(sum_A - W_sum==K) + (sum_A==K)

print(num_of_comb)

Submission status: Runtime Error

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
import numpy as np
d = stdin.readline().rstrip().split()
H = int(d[0])
W = int(d[1])
K = int(d[2])

data = []
bCount = 0
result = 0
for el1 in range(H):
    tmp = stdin.readline().rstrip().split()
    d = []
    for el in tmp:
        for el3 in el:
            if el3 == '#':
                bCount += 1
            d.append(el3)
    data.append(d)
tr = []
for i in range(W):
    tr_row = []
    for vector in data:
        tr_row.append(vector[i])
    tr.append(tr_row)
data2 = tr
counter = 0
for el in range(H+W):
    counter += 2**el
for el in range(counter+1):
    bin_str = ''.join(list(reversed(str(format(el, 'b')))))
    poss = []
    count = 0
    for el2 in bin_str:
        if el2 == '1':
            poss.append(count)
        count += 1
    res = 0
    for el2 in poss:
        if el2 >= H:
            el2 -= H
            res += data2[el2].count('#')
        else:
            res += data[el2].count('#')
    if bCount-res == K:
        result += 1

print(result)

Submission status: Runtime Error

Solution code:
h,w,k=map(int, input().split())
L=[]
for i in range(h):
	S=list(input())
	for j in range(w):
		L.append(S[j])
import itertools
import copy
t=[1,0]
cnt=0

for v in itertools.product(t, repeat=h+w):
	LL=copy.copy(L)
	#print(v)
	for i in range(h+w):
		if v[i]==1 and i<h:
			for j in range(w):
				LL[h*i+j]='r'
		elif v[i]==1 and i>=h:
			for j in range(h):
				LL[w*j+(i-h)]='r'
	#print(LL)
	s=LL.count('#')
	if s==k:
		cnt+=1
print(cnt)

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
  for j in range(W):
    index_W = np.ones(W, dtype=bool)
    index_W[j] = False
    if np.sum(A[index_H, index_W]) == K:
      num_of_comb += 1

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

num_ob_comb += np.sum(H_sum ==K) + np.sum(W_sum==K) + (np.sum(A)==K)

print(num_of_comb)

Submission status: Runtime Error

Solution code:
h,w,k=map(int,input().split())
c=[]
#行ごと
hk=[]
for i in range(h):
    kki=0
    hwi=list(map(str,input().split()))
    hw=[]
    for j in range(w):
        if hwi[j]=='#':
            hw.append(1)
            kki+=1
        else:
            hw.append(0)
    c.append(hw)
    hk.append(kki)
kk=sum(hk)
ans=0
#残す行を選ぶ
for i in range(2**h):
    #列ごと
    wk=[0]
    wk*=w
    for j in range(h):
        if (i>>j &1):
            #残った行の列ごとの和
            for l in range(w):
                wk[l]+=c[j][l]
    #残す列を選ぶ
    for j in range(2**w):
        ansi=0
        for l in range(w):
            if (j>>l & 1):
                ansi+=wk[l]
        if ansi==k:
            ans+=1
    
print(ans)

Submission status: Runtime Error

Solution code:
'''
.append(要素) リストに要素を追加
.extend(リスト) リストを連結する
.insert(場所,要素) 指定した場所に要素追加
del 配列名[場所]
-1で末尾で末尾から一つ前
sort()
sorted(reverse=true)
配列の初期化
配列名=[a]*n+[b]*m
Decimal()
'''

from sys import stdin
from itertools import accumulate, dropwhile, takewhile, groupby
import bisect
import copy
import math
from functools import reduce
from operator import mul
from collections import Counter
import itertools
import fractions
import sys
import numpy as np
d = stdin.readline().rstrip().split()
H = int(d[0])
W = int(d[1])
K = int(d[2])

data = []
bCount = 0
result = 0
for el1 in range(H):
    tmp = stdin.readline().rstrip().split()
    d = []
    for el in tmp:
        for el3 in el:
            if el3 == '#':
                bCount += 1
            d.append(el3)
    data.append(d)
data2 = np.array(data).T.tolist()
counter = 0
for el in range(H+W):
    counter += 2**el
for el in range(counter+1):
    bin_str = ''.join(list(reversed(str(format(el, 'b')))))
    poss = []
    count = 0
    for el2 in bin_str:
        if el2 == '1':
            poss.append(count)
        count += 1
    res = 0
    for el2 in poss:
        if el2 >= H:
            el2 -= H
            res += data2[el2].count('#')
        else:
            res += data[el2].count('#')
    if bCount-res == K:
        result += 1

print(result)

Submission status: Runtime Error

Solution code:
import numpy as np
import copy

H, W, K = input().split(' ')
H = int(H)
W = int(W)
K = int(K)
c = [list(str(input())) for i in range(H)]
cnp = np.array(c)

countAll = np.count_nonzero(cnp == '#')
countH = []
countW = []
for i in range(H):
    countH.append(np.count_nonzero(cnp[i] == '#'))
for i in range(W):
    countW.append(np.count_nonzero(cnp[:, i] == '#'))

ans = 0
for i in range(2 ** H - 1):
    for j in range(2 ** W - 1):
        tmp = copy.deepcopy(countAll)
        tmp2 = []
        choiceH = format(i, '0' + str(H) + 'b')
        for m in range(len(choiceH)):
            if int(choiceH[m]):
                tmp -= countH[m]
                tmp2.append(m)
        choiceW = format(j, '0' + str(W) + 'b')
        for n in range(len(choiceW)):
            if int(choiceW[n]):
                tmp -= countW[n]
                for o in range(len(tmp2)):
                    if cnp[tmp2[o], n] == '#':
                        tmp += 1
        if tmp == K:
            ans += 1

print(ans)

Submission status: Runtime Error

Solution code:
#include<bits/stdc++.h>
using namespace std;

int main()
{
    int h,w,k;
    cin>>h>>w>>k;
    int ans=0;
    vector<vector<char>> c(h,vector<char>(w));

    for (int i=0;i<h;i++){
        for (int j=0;j<w;j++){
            cin>>c.at(i).at(j);
        }
    }
    for (int bit=0;bit<(1<<h+w);++bit){
        vector<vector<char>> t=c;
        int cnt=0;
        for (int i=0;i<h;++i){
            if ((bit>>i)%2==0){
                continue;
            }
            else{
                t.at(i).assign(w,'r');
            }
        }
        for (int j=h;j<h+w;++j){
            if((bit>>j)%2==1){
                continue;
            }
            else{
                for(int i=0;i<h;++i){
                    if(t.at(i).at(j-h)=='#'){
                        cnt++;
                    }
                }
            }
        }
        if(cnt==k){
            ans++;
        }
    }
    cout<<ans<<endl;

}

Submission status: Runtime Error

Solution code:
import sys
import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

H, W, K = map(int, readline().split())
C = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W]

C = 1 * (C == b'#')

def f(C, x, y):
    rows = [bool(x & (1<<i)) for i in range(H)]
    cols = [bool(y & (1<<i)) for i in range(W)]
    D = C[rows, cols]
    return D.sum() == K

ans = 0
for x in range(1 << H):
    for y in range(1 << W):
        ans += f(C, x, y)
print(ans)

Submission status: Runtime Error

Solution code:
h,w,k=map(int,input().split())
c=[[] for i in range(h)]
for i in range(h):
  S=input()
  for j in range(w):
    c[i].append(S[j])
b1=2**h
b2=2**w
cnt=0
tori=0
for i in range(b1):
  s=(str(bin(i))[2:]).zfill(h)
  for j in range(b2):
    d=[]
    d=copy.deepcopy(c)
    cnt=0
    t=(str(bin(j))[2:]).zfill(w)
    for l in range(h):
      if s[l]=='1':
        for unchi in range(w):
          d[l][unchi]='r'
    for m in range(w):
      if t[m]=='1':
        for unchi in range(h):
          d[unchi][m]='r'
    for ch in range(h):
      cnt+=d[ch].count('#')
    if cnt==k:
      tori+=1
print(tori)

Submission status: Runtime Error

Solution code:
import numpy as np
import copy

H, W, K = map(int, input().split())
if H == 1:
    print("A")
elif W = 1:
    print("B")
else:
    d = list(map(str, input().split()))
    X = list(d[0])
    for i in range(H - 1):
        d = list(map(str, input().split()))
        d = list(d[0])
        X = np.vstack((X, d))

    black = 0
    for i in range(X.shape[0]):
        for j in range(X.shape[1]):
            if X[i,j] == "#":
                black += 1

    t = 0
    s1 = "0" + str(H) + "b"
    s2 = "0" + str(W) + "b"
    for i in range(2**H):
        for j in range(2**W):

            XX = copy.copy(X)
            black_xx = black
            HH = format(i, s1)
            WW = format(j, s2)

            for ii in range(H):
                if HH[ii] == "1":
                    for iii in range(W):
                        if XX[ii,iii] == "#":
                            black_xx -= 1
                            XX[ii,iii] = "."
            for jj in range(W):
                if WW[jj] == "1":
                    for jjj in range(H):
                        if XX[jjj,jj] == "#":
                            black_xx -= 1
                            XX[jjj,jj] = "."
            if black_xx == K:
                t += 1

    print(t)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

cells = []
for _ in range(h):
  cells.append(list(input()))
cells = np.asarray(cells)

n_choice = 0
for n_target_rows in range(h + 1):
  target_rows = list(itertools.combinations(range(h), n_target_rows))
  
  for n_target_clms in range(w + 1):
    target_clms = list(itertools.combinations(range(w), n_target_clms))
    
    for rows in target_rows:
      row_converted_cells = cells.copy()
      row_converted_cells[rows, :] = 'r' * w
      
      for clms in target_clms:
        clm_converted_cells = row_converted_cells.copy()
        clm_converted_cells[:, clms] = 'r'
        n_black = np.count_nonzero(clm_converted_cells == '#')
        
        if n_black == k:
          n_choice += 
                    
print(n_choice)

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):
    	    if (arr[i+1:][j+1:].count('#') + arr[0:i][0:j].count('#')) == k: sum1 += 1
print(sum1)

Submission status: Runtime Error

Solution code:
import numpy as np
import copy

H, W, K = map(int, input().split())
d = list(map(str, input().split()))
X = list(d[0])
for i in range(H - 1):
    d = list(map(str, input().split()))
    d = list(d[0])
    X = np.vstack((X, d))

black = 0
for i in range(X.shape[0]):
    for j in range(X.shape[1]):
        if X[i,j] == "#":
            black += 1

t = 0
s1 = "0" + str(H) + "b"
s2 = "0" + str(W) + "b"
for i in range(2**H):
    for j in range(2**W):
        XX = copy.copy(X)
        black_xx = black
        HH = format(i, s1)
        WW = format(j, s2)

        # 行を消す
        for ii in range(H):
            if HH[ii] == "1":
                for iii in range(W):
                    if XX[ii,iii] == "#":
                        black_xx -= 1
                        XX[ii,iii] = "."
        # 列を消す
        for jj in range(W):
            if WW[jj] == "1":
                for jjj in range(H):
                    if XX[jjj,jj] == "#":
                        black_xx -= 1
                        XX[jjj,jj] = "."
        if black_xx == K:
            t += 1

print(t)

Submission status: Runtime Error

Solution code:
def main():
    n = int(input())
    comp = list(map(int, input().split()))
    comp.sort(reverse=True)
    
    fin = n - 2
    p = comp[0]
    for i in range(1, n):
        if fin == 1:
            p += comp[i]
            break
        elif fin == 0:
            break

        p += comp[i]*2
        fin -= 2
 
    print(p)
 
 
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
import itertools

H, W, K = map(int, input().split())
c = [['.' for j in range(6)] for i in range(6)]
for i in range(H):
    tmp = str(input())
    for j in range(len(tmp)):
        c[i][j] = tmp[j]
    
hp = list(itertools.product([0,1], repeat=H))
wp = list(itertools.product([0,1], repeat=W))

hl = []
for elem in hp:
    hl.append([i for i, x in enumerate(list(elem)) if x == 1])
wl = []
for elem in wp:
    wl.append([i for i, x in enumerate(list(elem)) if x == 1

def func(hli, wli, c):
    tmp = 0
    for i in range(len(hli)):
        for j in range(len(wli)):
            if c[hli[i]][wli[j]] == '#':
                tmp += 1 
            
    return tmp

ans  = 0
for hli in hl:
    for wli in wl:
        if func(hli, wli, c) == K:
            ans += 1

print(ans)

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)
#     print(c)
    if K in c:
        return c[K]
    else:
        return 0
        

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:
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)
    print(c)
    if K in c:
        return c[K]
    else:
        return 0
        

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:
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:
import itertools

h,w,k = map(int, input().split())
c = [list(input()) for _ in range(h)]
r = []
s = 0
ans = 0
for i in c:
  s += i.count('#')
if s==k:
  print(1)
  quit()
for i in range(w):
  row = []
  for j in range(h):
    if c[j][i]=='#' and 
    row.append(c[j][i])
  r.append(row)
re = c + r
for i in range(1,len(re)):
  combs = itertools.combinations(re, i)
  for j in list(combs):
    if (s-sum(j))==k:
      ans += 1
print(ans)

Submission status: Runtime Error

Solution code:
import numpy as np
import itertools

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

matrix = np.empty((h,w), dtype = 'str')

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

if np.count_nonzero(matrix=='#') == k:
    cnt = 1
else:
    cnt = 0

for n_row in range(h+1):
    for n_col in range(w+1):
        for r in itertools.combinations(range(h), n_row):
            for c in itertools.combinations(range(w), n_col):
                if not r and not c:
                    continue
                chg_matrix = matrix.copy()
                chg_matrix[:,c] = '&'
                chg_matrix[r,:] = '&'
                if np.count_nonzero(chg_matrix=='#') == k:
                    cnt += 1

print(cnt)

Submission status: Runtime Error

Solution code:
import copy
s=0
a=0
H,W,K=map(int,input().split())
L=[[0 for j in range(W)] for i in range(H)]
for i in range(H):
  c=list(input().split())
  L[i]=c
for i in range(2**(H+W)):
  c=bin(i)[2:]
  T=copy.deepcopy(L)
  for k in range(len(c)):
    if c[k] is None:
      print(c,k)
    if c[k]=="1" and k<H:
      T[k]=[0]*W
    if c[k]=="1" and k>=H:
      for n in range(H):
        T[n][k-H]=0
  for j in range(H*W):
    if j%W==0:
      if T[(j//W)-1][-1]=="#":
        a+=1
    else:
      if T[j//W][(j%W)-1]=="#":
        a+=1
  if a==K:
    s+=1
  a=0
print(s)