#include <stdio.h>

#define maxn 120

int a[maxn][maxn], m, n, t;

int check(int *i, int *j){
    int k, cnt_r, cnt_c;
    cnt_r = 0;
    for(k = *i + 1; k < m; k++){
        if(a[*i][*j] == a[k][*j]) cnt_r++;
        if(cnt_r >= t){
            *i = k;
            return 1;
        }
    }
    cnt_c = 0;
    for(k = *j + 1; k < n; k++){
        if(a[*i][*j] == a[*i][k]) cnt_c++;
        if(cnt_c >= t){
            *j = k;
            return 1;
        }
    }
    return 0;
}

int lastSq(int r, int c){
    return (r == n - 1 && c == n);
}

int main(){
    int res = 0, i, j, pos_r = 0, pos_c = 0;
    scanf("%d%d%d", &m, &n, &t);
    for(i = 0; i < m; i++)
        for(j = 0; j < n; j++)
            scanf("%d", &a[i][j]);

    while(!lastSq(pos_r, pos_c)){
        if(a[pos_r][pos_c] == 0){
            if(pos_c < n - 1) pos_c++;
            else if(pos_r < n - 1){
                pos_c = 0;
                pos_r++;
            }
        }
        if(!check(&pos_r, &pos_c)){
            res++;
            if(pos_c < n - 1) pos_c++;
            else{
                pos_c = 0;
                pos_r++;
            }
        }
    }

    printf("%d", res);
}