#!/usr/bin/ python3.8 import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines import numpy as np H, W, K = map(int, readline().split()) C = np.frombuffer(read(), 'S1').reshape(H, -1)[:, :W] INF = np.int32(10 ** 5) def calc_alphabet(a): dp = (C != a) * INF for n in range(1, H): np.minimum(dp[n - 1] + 1, dp[n], out=dp[n]) for n in range(1, W): np.minimum(dp[:, n - 1] + 1, dp[:, n], out=dp[:, n]) np.minimum(dp[:-1, n - 1] + 1, dp[1:, n], out=dp[1:, n]) return dp dp = np.empty((26, H, W), np.int32) for i in range(26): a = chr(ord('a') + i).encode() dp[i] = calc_alphabet(a) dp.sort(axis=0) low = dp[K - 1] if K == 26: high = np.full_like(low, INF) else: high = dp[K] for n in range(min(H, W)): np.minimum(high[n, n:], n + 1, out=high[n, n:]) np.minimum(high[n:, n], n + 1, out=high[n:, n]) x = high - low answer = np.maximum(x, 0).sum() print(answer)