#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

struct Solver {
    H: usize,
    W: usize,
    K: usize,
    c: Vec<Vec<usize>>,
}

impl Solver {
    fn new(H: usize, W: usize, K: usize, c: Vec<Vec<usize>>) -> Self {
        Solver {
            H: H,
            W: W,
            K: K,
            c: c,
        }
    }
    fn check(&mut self, row: usize, col: usize, num: usize, clear: &mut Vec<Vec<bool>>,
                visited: &mut Vec<Vec<bool>>) -> usize {
        let mut conti = 0;
        for c in col..self.W {
            if self.c[row][c] == num {
                visited[row][c] = true;
                conti += 1;
            } else {
                break;
            }
        }
        if conti >= self.K {
            for c in col..col+conti {
                clear[row][c] = true;
            }
            conti * num
        } else {
            0
        }
    }
    fn solve(&mut self, row: usize, col: usize) -> usize {
        let mut ret = 0;
        let mut is_coutinued = true;
        let mut i = 0;
        while is_coutinued {
            is_coutinued = false;
            let mut clear = vec![vec![false; self.W]; self.H];
            let mut visited = vec![vec![false; self.W]; self.H];
            for row in 0..self.H {
                for col in 0..self.W {
                    let num = self.c[row][col];
                    if visited[row][col] || num == 0 {
                        continue;
                    }
                    let erased = self.check(row, col, num, &mut clear, &mut visited);
                    is_coutinued |= erased != 0;
                    if erased == 0 {
                        continue;
                    }
                    let score = erased * usize::pow(2, i-1);
                    ret += score;
                }
            }
            if i == 0 {
                clear[row][col] = true;
                is_coutinued = true;
            }
            for row in 0..self.H {
                for col in 0..self.W {
                    if clear[row][col] {
                        for r in (1..row+1).rev() {
                            self.c[r][col] = self.c[r-1][col];
                        }
                        self.c[0][col] = 0;
                    }
                }
            }
            i += 1;
        }
        ret
    }
}


fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let H: usize = sc.get();
    let W: usize = sc.get();
    let K: usize = sc.get();
    let mut c = vec![vec![0; W]; H];
    for row in 0..H {
        let l: Vec<char> = sc.chars();
        for col in 0..W {
            let d = l[col] as u8 - b'0';
            c[row][col] = d as usize;
        }
    }
    let mut ans = 0;
    for row in 0..H {
        for col in 0..W {
            let mut s = Solver::new(H, W, K, c.clone());
            ans = max(ans, s.solve(row, col));
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352