# Paper
class Paper
  attr_reader :grids

  def initialize(x, y)
    @x, @y, @grids = x, y, Array.new(x) { Array.new(y, 0) }
  end

  def dye(x, y, size)
    case size
    when 1
      dense(x, y)
      dense(x, y - 1)
      dense(x + 1, y)
      dense(x, y + 1)
      dense(x - 1, y)
    when 2
      dense(x, y)
      dense(x, y - 1)
      dense(x + 1, y - 1)
      dense(x + 1, y)
      dense(x + 1, y + 1)
      dense(x, y + 1)
      dense(x - 1, y + 1)
      dense(x - 1, y)
      dense(x - 1, y - 1)
    when 3
      dense(x, y)
      dense(x, y - 1)
      dense(x + 1, y - 1)
      dense(x + 1, y)
      dense(x + 1, y + 1)
      dense(x, y + 1)
      dense(x - 1, y + 1)
      dense(x - 1, y)
      dense(x - 1, y - 1)
      dense(x, y - 2)
      dense(x + 2, y)
      dense(x, y + 2)
      dense(x - 2, y)
    end
  end

  def graph
    @grids.transpose.each do |row|
      puts row.join(' ')
    end
  end

  def dense(x, y, density = 1)
    @grids[x][y] += density if exists?(x, y)
  end

  def exists?(x, y)
    0 <= x && x <= @x - 1 && 0 <= y && y <= @y - 1
  end

  def max_density
    max_density = 0
    @grids.each do |item|
      max_density = [max_density, item.max].max
    end
    max_density
  end

  def while_grids_sum
    while_grids_sum = 0
    @grids.each do |item|
      while_grids_sum += item.select { |x| x == 0 }.size
    end
  end
end

paper = Paper.new(10, 10)

while line = gets
  x, y, size = line.chomp.split(',').map(&:to_i)
  paper.dye(x, y, size)

end

puts while_grids_sum
puts paper.max_densei