### BUGGY CODE ###

import copy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    ans = []
    H,W,K = map(int, readline().split())
    c_ = [list(map(int, list(readline().strip()))) for _ in range(H)]

    for a in range(H):
        for b in range(W):
            c = copy.deepcopy(c_)
            c[a][b] = 0

            seq = [[1] for _ in range(H)]
            ans_tmp = [0]
            
            score = 0
            weight = 1
            while True:
                # 落とす
                for i in reversed(range(H)):
                    for j in range(W):
                        if c[i][j] == 0:
                            for h in reversed(range(i)):
                                if c[h][j] != 0:
                                    c[h][j], c[i][j] = c[i][j], c[h][j]
                                    break

                # 消す
                for i, line in enumerate(c):
                    for j in range(1,W):
                        if line[j] == line[j-1]:
                            seq[i][-1] += 1
                        else:
                            seq[i].append(1)
                
                    acc = -1
                    for s in seq[i]:
                        acc += s
                        if s >= K:
                            score += s * line[acc] * weight
                            for j in range(acc - s + 1, acc + 1):
                                line[j] = 0
                    seq[i] = [1]
                
                weight *= 2

                ans_tmp.append(score)
                if ans_tmp[-1] == ans_tmp[-2]:
                    ans.append(ans_tmp[-1])
                    break

    print(max(ans))


if __name__ == "__main__":
    main()

### FIXED CODE ###

import copy
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    ans = []
    H,W,K = map(int, readline().split())
    c_ = [list(map(int, list(readline().strip()))) for _ in range(H)]

    for a in range(H):
        for b in range(W):
            c = copy.deepcopy(c_)
            c[a][b] = 0

            seq = [[1] for _ in range(H)]
            ans_tmp = [0]
            
            score = 0
            weight = 1
            while True:
                # 落とす
                for i in reversed(range(H)):
                    for j in range(W):
                        if c[i][j] == 0:
                            for h in reversed(range(i)):
                                if c[h][j] != 0:
                                    c[h][j], c[i][j] = c[i][j], c[h][j]
                                    break

                # 消す
                for i, line in enumerate(c):
                    for j in range(1,W):
                        if line[j] == line[j-1]:
                            seq[i][-1] += 1
                        else:
                            seq[i].append(1)
                
                    acc = -1
                    for s in seq[i]:
                        acc += s
                        if s >= K:
                            score += s * line[acc] * weight
                            for j in range(acc - s + 1, acc + 1):
                                line[j] = 0
                    seq[i] = [1]
                
                weight *= 2

                ans_tmp.append(score)
                if ans_tmp[-1] == ans_tmp[-2]:
                    ans.append(ans_tmp[-1])
                    break

    print(max(ans))


if __name__ == "__main__":
    main()