Problem p02614 (python)

Fixed submission:
#!/usr/bin/env python

def count(arr,k,H,W):
    
    num_ans = 0

    for col in kumiawase(arr):
        countlist = [0]*W

        #print("col:")
        #printarr(col)
        #print()

        for i in range(len(col)):
            count = 0
            for j in range(len(col[0])):
                if col[i][j] == 1:
                    countlist[j]=countlist[j]+1
            #countlist.append(count)


        #print("countlist")
        #print(countlist)
        #print()
        for x in kumiawase(countlist):
            if sum(x) == k :
                num_ans += 1
        
    print(num_ans)

def kumiawase(list):
    #listから取り出すすべての組み合わせ：

    returnlist = []
    num_kumi = 2**len(list)
    for i in range(num_kumi):
        tmplist = []
        for j in range(len(list)):
            if (i >> j)%2 == 1:
                tmplist.append(list[j])

        returnlist.append(tmplist)
    
    return returnlist


def printarr(arr):
    for i in range(len(arr)):
        for j in range(len(arr[0])):
            print(arr[i][j],end=" ")
        print()

if __name__ == "__main__":
    H,W,K = map(int,input().split())

    arr = []
    count_H = []
    total = 0
    for i in range(H):
        list = []
        inp = input()
        for j in range(W):
            num = 0
            if "." == inp[j]:
                list.append(0)
            else:
                list.append(1)
                num += 1
                total += 1
        arr.append(list)
        count_H.append(num)
    
    count_W = []
    for i in range(W):
        num = 0
        for j in range(H):
            num += 1
        count_W.append(num)

#    printarr(arr)


    count(arr,K,H,W)

Buggy submission (verdict: Runtime Error):
#!/usr/bin/env python

def count(arr,k,H,W):
    
    num_ans = 0

    for col in kumiawase(arr):
        countlist = [0]*H

        #print("col:")
        #printarr(col)
        #print()

        for i in range(len(col)):
            count = 0
            for j in range(len(col[0])):
                if col[i][j] == 1:
                    countlist[j]=countlist[j]+1
            #countlist.append(count)


        #print("countlist")
        #print(countlist)
        #print()
        for x in kumiawase(countlist):
            if sum(x) == k :
                num_ans += 1
        
    print(num_ans)

def kumiawase(list):
    #listから取り出すすべての組み合わせ：

    returnlist = []
    num_kumi = 2**len(list)
    for i in range(num_kumi):
        tmplist = []
        for j in range(len(list)):
            if (i >> j)%2 == 1:
                tmplist.append(list[j])

        returnlist.append(tmplist)
    
    return returnlist


def printarr(arr):
    for i in range(len(arr)):
        for j in range(len(arr[0])):
            print(arr[i][j],end=" ")
        print()

if __name__ == "__main__":
    H,W,K = map(int,input().split())

    arr = []
    count_H = []
    total = 0
    for i in range(H):
        list = []
        inp = input()
        for j in range(W):
            num = 0
            if "." == inp[j]:
                list.append(0)
            else:
                list.append(1)
                num += 1
                total += 1
        arr.append(list)
        count_H.append(num)
    
    count_W = []
    for i in range(W):
        num = 0
        for j in range(H):
            num += 1
        count_W.append(num)

#    printarr(arr)


    count(arr,K,H,W)