package com.study.classAlgo;
import java.awt.List;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.Queue;
import java.util.StringTokenizer;
public class BOJ17144_미세먼지_안녕 {
static int N,M,T;
static int[][] map, temp;
static Queue<Dust> queue = new LinkedList<>();
static ArrayList<Integer> machine = new ArrayList<Integer>();
static int[] dx = {-1,1,0,0};
static int[] dy = {0,0,-1,1};
static class Dust {
int x;
int y;
public Dust(int x, int y) {
super();
this.x = x;
this.y = y;
}
}
public static void main(String[] args) throws Exception {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringTokenizer st = new StringTokenizer(br.readLine());
N = Integer.parseInt(st.nextToken());
M = Integer.parseInt(st.nextToken());
T = Integer.parseInt(st.nextToken());
map = new int[N][M];
temp = new int[N][M];
for(int i=0; i<N; i++) {
st = new StringTokenizer(br.readLine());
for (int j = 0; j < M; j++) {
map[i][j] = Integer.parseInt(st.nextToken());
temp[i][j] = map[i][j];
if(map[i][j]>0) queue.offer(new Dust(i,j));
if(map[i][j]==-1) machine.add(i);
}
}
for(int tc = 0; tc<T; tc++) {
spread();
operate();
copy();
}
result();
}
private static void copy() {
for(int i=0; i<N; i++) {
for (int j = 0; j < M; j++) {
map[i][j] = temp[i][j];
if(map[i][j]>0) queue.offer(new Dust(i,j));
}
}
}
private static void result() {
int r = 0;
for(int i=0; i<N; i++) {
for (int j = 0; j < M; j++) {
r += temp[i][j];
}
}
System.out.println(r+2);
}
private static void operate() {
int first = machine.get(0);
for(int i=first-1; i>0; i--) {
temp[i][0] = temp[i-1][0];
}
for(int i=0; i<M-1; i++) {
temp[0][i] = temp[0][i+1];
}
for(int i=0; i<=first; i++) {
temp[i][M-1] = temp[i+1][M-1];
}
for(int i=M-1; i>1; i--) {
temp[first][i] = temp[first][i-1];
}
temp[first][1] = 0;
first = machine.get(1);
for(int i=first+1; i<N-1; i++) {
temp[i][0] = temp[i+1][0];
}
for(int i=0; i<M-1; i++) {
temp[N-1][i] = temp[N-1][i+1];
}
for(int i=N-1; i>first; i--) {
temp[i][M-1] = temp[i-1][M-1];
}
for(int i=M-1; i>1; i--) {
temp[first][i] = temp[first][i-1];
}
temp[first][1] = 0;
}
private static boolean isValid(int nx, int ny) {
return (nx>=0 && nx<N && ny>=0 && ny<M) ? true : false;
}
private static void spread() {
while(!queue.isEmpty()) {
Dust d = queue.poll();
int x = d.x;
int y = d.y;
int count = 0;
int dust = map[x][y] / 5;
for(int i=0; i<4; i++) {
int nx = x + dx[i];
int ny = y + dy[i];
if(isValid(nx,ny) && map[nx][ny] != -1) {
temp[nx][ny] += dust;
count++;
}
}
temp[x][y]-= dust * count;
}
}
}