Problem:
Dropping Ink

As shown in the following figure, there is a paper consisting of a grid structure where each cell is indicated by (x, y) coordinate system.

We are going to put drops of ink on the paper. A drop comes in three different sizes: Large, Medium, and Small. From the point of fall, the ink sinks into surrounding cells as shown in the figure depending on its size. In the figure, a star denotes the point of fall and a circle denotes the surrounding cells.

Originally, the paper is white that means for each cell the value of density is 0. The value of density is increased by 1 when the ink sinks into the corresponding cells.

For example, if we put a drop of Small ink at (1, 2) and a drop of Medium ink at (3, 2), the ink will sink as shown in the following figure (left side):

In the figure, density values of empty cells are 0. The ink sinking into out of the paper should be ignored as shown in the figure (top side). We can put several drops of ink at the same point.

Your task is to write a program which reads a sequence of points of fall (x, y) with its size (Small = 1, Medium = 2, Large = 3), and prints the number of cells whose density value is 0. The program must also print the maximum value of density.

You may assume that the paper always consists of 10 × 10, and 0 ≤ x < 10, 0 ≤ y < 10.

Input

x1,y1,s1
x2,y2,s2
:
:

(xi, yi) represents the position of the i-th drop and si denotes its size. The number of drops is less than or equal to 50.

Output

Print the number of cells whose density value is 0 in first line.

Print the maximum value of density in the second line.

Sample Input

2,5,3
3,6,1
3,4,2
4,5,2
3,6,3
2,4,1

Output for the Sample Input

77
5

Solution in JAVA (judge verdict: Accepted)

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

class Main {

	public static void main(String[] args) {

		// ストリームを作成する
		BufferedReader reader = new BufferedReader(new InputStreamReader(
				System.in));

		int[][] paper = new int[10][10];
		while (true) {
			int[] ink = readPair(reader);
			// 終了判定
			if (ink == null) {
				break;
			}
			// インクを落とす
			drop(ink, paper);
		}

		// 結果を集計する
		int white = 0;
		int max = 0;
		for (int i = 0; i < 10; i++) {
			for (int j = 0; j < 10; j++) {
				if (paper[i][j] == 0) {
					white++;
				}
				if (paper[i][j] > max) {
					max = paper[i][j];
				}
			}
		}
		System.out.println(white);
		System.out.println(max);
	}

	/**
	 * 紙にインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void drop(int[] ink, int paper[][]) {
		if (ink[2] == 1) {
			// 小インク
			dropSmall(ink, paper);
		} else if (ink[2] == 2) {
			// 中インク
			dropMiddle(ink, paper);
		} else if (ink[2] == 3) {
			dropLarge(ink, paper);
		}

	}

	/**
	 * 紙に小さいインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void dropSmall(int[] ink, int paper[][]) {
		paper[ink[0]][ink[1]]++;
		if (ink[0] > 0) {
			paper[ink[0] - 1][ink[1]]++;
		}
		if (ink[0] < 9) {
			paper[ink[0] + 1][ink[1]]++;
		}
		if (ink[1] > 0) {
			paper[ink[0]][ink[1] - 1]++;
		}
		if (ink[1] < 9) {
			paper[ink[0]][ink[1] + 1]++;
		}
	}

	/**
	 * 紙に中くらいのインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void dropMiddle(int[] ink, int paper[][]) {
		dropSmall(ink, paper);
		if (ink[0] > 0 && ink[1] > 0) {
			paper[ink[0] - 1][ink[1] - 1]++;
		}
		if (ink[0] < 9 && ink[1] > 0) {
			paper[ink[0] + 1][ink[1] - 1]++;
		}
		if (ink[0] < 9 && ink[1] < 9) {
			paper[ink[0] + 1][ink[1] + 1]++;
		}
		if (ink[0] > 0 && ink[1] < 9) {
			paper[ink[0] - 1][ink[1] + 1]++;
		}
	}

	/**
	 * 紙に大きいインクを落とす
	 *
	 * @param ink
	 *            インク
	 * @param paper
	 *            紙
	 */
	private static final void dropLarge(int[] ink, int paper[][]) {
		dropMiddle(ink, paper);
		if (ink[0] > 1) {
			paper[ink[0] - 2][ink[1]]++;
		}
		if (ink[0] < 8) {
			paper[ink[0] + 2][ink[1]]++;
		}
		if (ink[1] > 1) {
			paper[ink[0]][ink[1] - 2]++;
		}
		if (ink[1] < 8) {
			paper[ink[0]][ink[1] + 2]++;
		}
	}

	/**
	 * ストリームから1行読み込んで、3つ1組の数値として返す。
	 *
	 * @param reader
	 *            入力ストリーム
	 * @return 3つ1組の数値
	 */
	private static int[] readPair(BufferedReader reader) {
		int[] result = new int[4];
		try {
			String line = reader.readLine();
			if (line == null || line.isEmpty()) {
				return null;
			}
			String[] array = line.split(",");
			result[0] = Integer.parseInt(array[0]);
			result[1] = Integer.parseInt(array[1]);
			result[2] = Integer.parseInt(array[2]);
		} catch (IOException e) {
			throw new RuntimeException();
		}
		return result;
	}

}