### BUGGY CODE ###

import copy
h, w, k = map(int, input().split())
a = [[] for j in range(h)]
for i in range(h):
    a[i] = [int(i) for i in input()]
ans = 0
for p in range(h):
    for q in range(w):
        cand = 0
        b = copy.deepcopy(a)
        b[p][q] = 0
        disap = True
        fall = True
        disapnum = 0
        while(disap):
            disap=False
            cur = 0
            for i in range(h):
                suc = 1
                for j in range(w-1):
                    if b[i][j] == b[i][j+1]:
                        suc += 1
                    else:
                        if suc >= k:
                            if b[i][j]:
                                disap=True
                                fall=True
                                cur += b[i][j]*suc
                            for m in range(j+1-suc, j+1):
                                b[i][m] = 0
                        suc = 1
                if suc >= k:
                    if b[i][w-1]:
                        disap=True
                        fall=True
                        cur += b[i][w-1]*suc
                    for m in range(w-suc, w):
                        b[i][m] = 0
            if disap:
                cand += cur*(2**disapnum)
                disapnum += 1
            while(fall):
                fall=False
                for i in range(1, h):
                    for j in range(w):
                        if b[i][j] == 0 and b[i-1][j]:
                            b[i][j], b[i-1][j] = b[i-1][j], b[i][j]
                            fall = True
                            disap = True
        ans = max(cand, ans)
print(ans)

### FIXED CODE ###

import copy
h, w, k = map(int, input().split())
a = [[] for j in range(h)]
for i in range(h):
    a[i] = [int(i) for i in input()]
ans = 0
for p in range(h):
    for q in range(w):
        cand = 0
        b = copy.deepcopy(a)
        b[p][q] = 0
        disap = True
        fall = True
        disapnum = 0
        while(disap):
            disap=False
            cur = 0
            for i in range(h):
                suc = 1
                for j in range(w-1):
                    if b[i][j] == b[i][j+1]:
                        suc += 1
                    else:
                        if suc >= k:
                            if b[i][j]:
                                disap=True
                                fall=True
                                cur += b[i][j]*suc
                            for m in range(j+1-suc, j+1):
                                b[i][m] = 0
                        suc = 1
                if suc >= k:
                    if b[i][w-1]:
                        disap=True
                        fall=True
                        cur += b[i][w-1]*suc
                    for m in range(w-suc, w):
                        b[i][m] = 0
            if disap:
                cand += cur*(2**disapnum)
                disapnum += 1
            while(fall):
                fall=False
                for i in range(1, h):
                    for j in range(w):
                        if b[i][j] == 0 and b[i-1][j]:
                            b[i][j], b[i-1][j] = b[i-1][j], b[i][j]
                            fall = True
                            disap = True
        ans = max(cand, ans)
print(ans)