// Arup Guha
// 11/14/2015
// Solution to 2015 SER D2 Problem: Blur

import java.util.*;

public class blur {

	// So we don't need to use doubles.
	final public static int BIT = 9*9*9*9*9*9*9*9*9;

	// So we don't have to pass these as parameters.
	public static int c;
	public static int r;

	public static void main(String[] args) {

		// Read in input.
		Scanner stdin = new Scanner(System.in);
		c = stdin.nextInt();
		r = stdin.nextInt();
		int numBlur = stdin.nextInt();

		// Store the grid with 9^9 for on.
		int[][] grid = new int[r][c];
		for (int i=0; i<r; i++)
			for (int j=0; j<c; j++)
				grid[i][j] = stdin.nextInt()*BIT;

		// Blur it!
		for (int i=0; i<numBlur; i++)
			grid = mix(grid);

		// Count unique values.
		HashSet<Integer> set = new HashSet<Integer>();
		for (int i=0; i<r; i++)
			for (int j=0; j<c; j++)
				set.add(grid[i][j]);

		// Output the size of the set.
		System.out.println(set.size());
	}

	public static int[][] mix(int[][] grid) {

		// Store answer here.
		int[][] res = new int[r][c];

		// Calculate each bit.
		for (int i=0; i<r; i++)
			for (int j=0; j<c; j++)
				res[i][j] = getBit(grid, i, j);

		return res;
	}

	public static int getBit(int[][] grid, int x, int y) {

		long sum = 0;

		// Go through each of the 9 squares to average.
		for (int dx=-1; dx<=1; dx++)
			for (int dy=-1; dy<=1; dy++)
				sum += grid[(x+dx+r)%r][(y+dy+c)%c];

		// This is the average.
		return (int)(sum/9L);
	}
}