### BUGGY CODE ###

from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from heapq import heapify, heappush, heappop, heappushpop, heapreplace
from bisect import bisect_left, bisect_right

from math import atan, degrees

h, w, k = map(int, input().split())
ori = [list(map(int, list(input()))) for _ in range(h)]
ori.reverse()
ans = 0
for x in range(w):
    for y in range(h - 1):
        data = [[ori[i][j] for j in range(w)] for i in range(h)]
        for i in range(y, h - 1):
            data[i][x] = data[i+1][x]
        data[h-1][x] = 0
        score = 0
        lc = 1
        nxt = True
        while nxt:
            nxt = False
            for i in range(h):
                c = 1
                for j in range(1, w):
                    if data[i][j] != 0 and data[i][j] == data[i][j-1]:
                        c += 1
                    else:
                        if c >= k:
                            nxt = True
                            score += data[i][j-1] * c * lc
                            for l in range(j - c, j):
                                data[i][l] = 0
                        c = 1
                if c >= k:
                    nxt = True
                    score += data[i][w-1] * c * lc
                    for l in range(w - c, w):
                        data[i][l] = 0
            for j in range(w):
                z = 0
                for i in range(h):
                    if data[i][j] == 0:
                        z += 1
                    elif z > 0:
                        data[i-z][j] = data[i][j]
                        data[i][j] = 0
            lc *= 2
        ans = max(ans, score)
        if score == 0:
            break
print(ans)


### FIXED CODE ###

from sys import setrecursionlimit, exit
setrecursionlimit(1000000000)

from heapq import heapify, heappush, heappop, heappushpop, heapreplace
from bisect import bisect_left, bisect_right

from math import atan, degrees

h, w, k = map(int, input().split())
ori = [list(map(int, list(input()))) for _ in range(h)]
ori.reverse()
ans = 0
for x in range(w):
    for y in range(h - 1):
        data = [[ori[i][j] for j in range(w)] for i in range(h)]
        for i in range(y, h - 1):
            data[i][x] = data[i+1][x]
        data[h-1][x] = 0
        score = 0
        lc = 1
        nxt = True
        while nxt:
            nxt = False
            for i in range(h):
                c = 1
                for j in range(1, w):
                    if data[i][j] != 0 and data[i][j] == data[i][j-1]:
                        c += 1
                    else:
                        if c >= k:
                            nxt = True
                            score += data[i][j-1] * c * lc
                            for l in range(j - c, j):
                                data[i][l] = 0
                        c = 1
                if c >= k:
                    nxt = True
                    score += data[i][w-1] * c * lc
                    for l in range(w - c, w):
                        data[i][l] = 0
            for j in range(w):
                z = 0
                for i in range(h):
                    if data[i][j] == 0:
                        z += 1
                    elif z > 0:
                        data[i-z][j] = data[i][j]
                        data[i][j] = 0
            lc *= 2
        ans = max(ans, score)
        if score == 0:
            break
print(ans)