using System;
using System.Text;
using System.Collections.Generic;
class Solve{
    int H;
    int W;
    int K;
    int[,] c;
    public Solve(){}
    StringBuilder sb;
    public static int Main(){
        new Solve().Run();
        return 0;
    }
    void Run(){
        sb = new StringBuilder();
        Read();
        Calc();
        Console.Write(sb.ToString());
    }
    void Calc(){
        long max = 0;
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                long count = 0;
                long pow = 1;
                int[,] d = new int[H,W];
                for(int k=0;k<H;k++){
                    for(int l=0;l<W;l++){
                        d[k,l] = c[k,l];
                    }
                }
                for(int k=i;k<H;k++){
                    if(k == H-1){
                        d[k,j] = 0;
                    }
                    else{
                        d[k,j] = d[k+1,j];
                    }
                }
                while(true){
                    int[,] d0 = new int[H,W];
                    bool[,] b = new bool[H,W];
                    bool fin = true;
                    for(int k=0;k<H;k++){
                        int row = 1;
                        for(int l=1;l<W;l++){
                            if(d[k,l] == d[k,(l-1)] && d[k,l] != 0){
                                row++;
                                if(l == W-1 && row >= K){
                                    for(int m=l+1-row;m<=l;m++){
                                        b[k,m] = true; 
                                    }
                                    count += pow*(d[k,l-1]*row);
                                    fin = false;
                                }
                            }
                            else{
                                if(row >= K){
                                    for(int m=l-row;m<l;m++){
                                        b[k,m] = true; 
                                    }
                                    count += pow*(d[k,l-1]*row);
                                    fin = false;
                                }
                                row = 1;
                            }
                        }
                    }
                    if(fin){
                        break;
                    }
                    for(int k=0;k<W;k++){
                        int m = 0;
                        for(int l=0;l<H;l++){
                            if(m == W){
                                d0[l,k] = 0;
                            }
                            else{
                                while(b[m,k]){
                                    m++;
                                    if(m == W){
                                        break;
                                    }
                                }
                                if(m == W){
                                    d0[l,k] = 0;
                                }
                                else{
                                    d0[l,k] = d[m,k];
                                    m++;
                                }
                            }
                        }
                    }
                    d = d0;
                    pow *= 2;
                }
                if(max <= count){
                    max = count;
                }
            }
        }
        sb.Append(max+"\n");
    }
    void Read(){
        string[] str = Console.ReadLine().Split(' ');
        H = int.Parse(str[0]);
        W = int.Parse(str[1]);
        K = int.Parse(str[2]);
        c = new int[H,W];
        for(int i=H-1;i>=0;i--){
            string s = Console.ReadLine();
            for(int j=0;j<W;j++){
                c[i,j] = int.Parse(s[j]+"");
            }
        }
    }    
}

Measured memory_bytes: 6872