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  x 1 , y 1 , s 1  x 2 , y 2 , s 2 :
  : ( x i , y i ) represents the position of the i -th drop and s i 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 (Python):


import sys
import os
import math

P = [[0 for i in range(10)] for j in range(10)]

def paint(x, y):
    if 0 <= x <= 9 and 0 <= y <= 9:
        P[x][y] += 1

for s in sys.stdin:
    x, y, s = map(int, s.split(','))

    if s >= 1:
        paint(x, y)
        paint(x - 1, y)
        paint(x + 1, y)
        paint(x, y - 1)
        paint(x, y + 1)

    if s >= 2:
        paint(x - 1, y - 1)
        paint(x + 1, y - 1)
        paint(x - 1, y + 1)
        paint(x + 1, y + 1)

    if s >= 3:
        paint(x - 2, y)
        paint(x + 2, y)
        paint(x, y - 2)
        paint(x, y + 2)

    
    
    
    

white = 0
for row in P:
    white += row.count(0)

max_value = 0
for row in P:
    max_value = max(max_value, max(row))

print(white)
print(max_value)

Solution (Python):
import sys
n1 = [[0, 1], [1, 0], [-1, 0], [0, -1]]
n2 = n1 + [[a, b] for a in [-1, 1] for b in [-1, 1]]
n3 = n2 + [[a*2, b*2] for a, b in n1]
mas = [[0]*10 for i in range(10)]
for i in sys.stdin:
    try:
        x, y, a = list(map(int, i.split(",")))
        mas[y][x] += 1
        for k,l in eval("n"+str(a)):
            try:
                if y+l >= 0 and x+k >= 0:
                    mas[y+l][x+k] += 1
            except IndexError:
                continue
    except ValueError:
        break
print(len([i for x in mas for i in x if not i]))
print(max([max(v) for v in mas]))

Solution (Python):
t = [[0 for i in range(10)] for j in range(10)]
case1 = [(0, 0), (0, -1), (1, 0), (0, 1), (-1, 0)]
case2 = [(1, -1), (1, 1), (-1, 1), (-1, -1)]
case3 = [(0, -2), (2, 0), (0, 2), (-2, 0)]
while True:
    try:
        x, y, s = map(int, input().split(','))
    except:
        break
    for c in [case1, case2, case3][:s]:
        for _x, _y in c:
            if y+_y < 0 or x+_x < 0:
                continue
            try:
                t[y+_y][x+_x] += 1
            except IndexError:
                continue

print(sum(1 for l in t for v in l if not v))
print(max(v for l in t for v in l))

Solution (Python):
paper = [[0 for _ in range(10)] for _ in range(10)]
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def paint(x, y):
    if 0 <= x <= 9 and 0 <= y <= 9:
        paper[x][y] += 1

while True:
    try:
        x, y, s = map(int, input().split(","))
    except EOFError:
        break
    if x == y == s == -1:
        break
    paint(x, y)
    for i in range(4):
        paint(x + dx[i], y + dy[i])
    if s >= 2:
        for i in range(4):
            paint(x + dx[i] + dx[(i + 1) % 4], y + dy[i] + dy[(i + 1) % 4])
    if s >= 3:
        for i in range(4):
            paint(x + 2 * dx[i], y + 2 * dy[i])

print(sum(paper[i].count(0) for i in range(10)))
print(max(paper[i][j] for i in range(10) for j in range(10)))

Solution (Python):
import sys
table = [[0 for j in range(10)] for i in range(10)]


def flag(x, y):
    if x > 9 or y > 9 or x < 0 or y < 0:
        return False
    else:
        return True


def small(x, y):
    table[x][y] += 1
    if flag(x+1, y):
        table[x+1][y] += 1
    if flag(x-1, y):
        table[x-1][y] += 1
    if flag(x, y+1):
        table[x][y+1] += 1
    if flag(x, y-1):
        table[x][y-1] += 1


def medium(x, y):
    small(x, y)
    if flag(x+1, y+1):
        table[x+1][y+1] += 1
    if flag(x+1, y-1):
        table[x+1][y-1] += 1
    if flag(x-1, y+1):
        table[x-1][y+1] += 1
    if flag(x-1, y-1):
        table[x-1][y-1] += 1


def large(x, y):
    medium(x, y)
    if flag(x+2, y):
        table[x+2][y] += 1
    if flag(x-2, y):
        table[x-2][y] += 1
    if flag(x, y+2):
        table[x][y+2] += 1
    if flag(x, y-2):
        table[x][y-2] += 1


def ink(x, y, s):
    if s == 1:
        small(x, y)
    if s == 2:
        medium(x, y)
    if s == 3:
        large(x, y)


def Search():
    counter = 0
    thickest = 0
    for i in range(10):
        for j in range(10):
            if table[i][j] == 0:
                counter += 1
            elif thickest < table[i][j]:
                thickest = table[i][j]
    print(counter)
    print(thickest)


for l in sys.stdin:
    data = list(map(int, l.split(",")))
    x, y, s = data
    ink(x, y, s)

Search()

Solution (Python):


import sys, math, os


PYDEV = os.environ.get('PYDEV')
if PYDEV=="True":
    sys.stdin = open("sample-input.txt", "rt")


paper = [[0 for col in range(10)] for row in range(10)]


ink_forms = {1: [[0, 0], [-1, 0], [1, 0], [0, -1], [0, 1]],
             2: [[-1, -1], [-1, 0], [-1, 1],
                 [0, 1], [0, 0], [0, -1],
                 [1, -1], [1, 0], [1, 1]],
             3: [[-1, -1], [-1, 0], [-1, 1],
                 [0, 1], [0, 0], [0, -1],
                 [1, -1], [1, 0], [1, 1],
                 [-2, 0], [2, 0], [0, -2], [0, 2]]}

while True:
    try:
        x, y, s = [int(_) for _ in input().split(',')]
    except EOFError:
        break
    for x_off, y_off in ink_forms[s]:
        x1 = x + x_off
        y1 = y + y_off
        if 0 <= x1 < 10 and 0 <= y1 < 10:
            paper[x1][y1] += 1

print(sum([row.count(0) for row in paper]))
print(max([max(row) for row in paper]))

Solution (Python):
import sys

b = [ list(0 for i in range(14)) for j in range(14)]

def s(b,x,y):
    b[x][y]   += 1
    b[x+1][y] += 1
    b[x-1][y] += 1
    b[x][y+1] += 1
    b[x][y-1] += 1

def m(b,x,y):
    b[x-1][y-1] += 1
    b[x  ][y-1] += 1
    b[x+1][y-1] += 1
    b[x-1][y  ] += 1
    b[x  ][y  ] += 1
    b[x+1][y  ] += 1
    b[x-1][y+1] += 1
    b[x  ][y+1] += 1
    b[x+1][y+1] += 1

def l(b,x,y):
    b[x  ][y-2] += 1

    b[x-1][y-1] += 1
    b[x  ][y-1] += 1
    b[x+1][y-1] += 1

    b[x-2][y  ] += 1
    b[x-1][y  ] += 1
    b[x  ][y  ] += 1
    b[x+1][y  ] += 1
    b[x+2][y  ] += 1

    b[x-1][y+1] += 1
    b[x  ][y+1] += 1
    b[x+1][y+1] += 1

    b[x  ][y+2] += 1

for line in sys.stdin:
    d = list(map(int,line.split(",")))

    c = d[2]
    x = d[0] + 2
    y = d[1] + 2

    if c == 1:
        s(b,x,y)
    elif c == 2:
        m(b,x,y)
    elif c == 3:
        l(b,x,y)

ttl = 0
num = 0
max = 0
for x in range(2,12):
    for y in range(2,12):
        ttl += 1
        if b[x][y] == 0:
            num += 1
        if b[x][y] > max:
            max = b[x][y]
            
print(num)
print(max)

Solution (Python):
paper = [[0 for i in range(10)] for j in range(10)]

def drop_ink(x, y, s):
    for i in range(-1, 2):
        for j in range(-1, 2):
            if s == 1 and i * j != 0:
                continue
            if 0 <= x + i < 10 and 0 <= y + j < 10:
                paper[x+i][y+j] += 1
    if s == 3:
        if x - 2 >= 0:
            paper[x-2][y] += 1
        if x + 2 < 10:
            paper[x+2][y] += 1
        if y - 2 >= 0:
            paper[x][y-2] += 1
        if y + 2 < 10:
            paper[x][y+2] += 1

while True:
    try:
        x, y, s = map(int, input().split(','))
        drop_ink(x, y, s)
    except:
        break

count = 0
max_density = 0
for i in range(10):
    for j in range(10):
        if paper[i][j] == 0:
            count += 1
        elif paper[i][j] > max_density:
            max_density = paper[i][j]
print(count)
print(max_density)

Solution (Python):
A=[[int(0) for i in range(10)]for j in range(10)]
count=0
while 1:
    try:
        x,y,s = map(int, input().split(','))
        if s==1:
            for i in range(x-1,x+2):
                if i>=0 and i<=9:
                    A[i][y]=A[i][y]+1
            for i in range(y-1,y+2):
                if i>=0 and i<=9:
                    A[x][i]=A[x][i]+1
            A[x][y]=A[x][y]-1 
        elif s==2:
            for i in range(x-1,x+2):
                for j in range(y-1,y+2):
                    if i>=0 and i<=9 and j>=0 and j<=9:
                        A[i][j]=A[i][j]+1
        else:
            for i in range(x-2,x+3):
                if i>=0 and i<=9:
                    A[i][y]=A[i][y]+1
            for i in range(y-2,y+3):
                if i>=0 and i<=9:
                    A[x][i]=A[x][i]+1
            for i in range(x-1,x+2):
                if i>=0 and i<=9:
                    A[i][y]=A[i][y]-1
            for i in range(y-1,y+2):
                if i>=0 and i<=9:
                    A[x][i]=A[x][i]-1
            for i in range(x-1,x+2):
                for j in range(y-1,y+2):
                    if i>=0 and i<=9 and j>=0 and j<=9:
                        A[i][j]=A[i][j]+1
    except:
        break
num=0
for i in range(10):
    for j in range(10):
        if A[i][j]==0:
            count=count+1
        if A[i][j]!=0:
            if num<A[i][j]:
                num=A[i][j]
print(count)
print(num)

Solution (Python):
def check(x, y):
    return 0 <= x <= 9 and 0 <= y <= 9


def small(x, y, area):
    if check(x+1, y):
        area[x+1][y] += 1
    if check(x, y+1):
        area[x][y+1] += 1
    if check(x-1, y):
        area[x-1][y] += 1
    if check(x, y-1):
        area[x][y-1] += 1
    area[x][y] += 1
    return area


def mediam(x, y, area):
    area = small(x, y, area)
    if check(x+1, y+1):
        area[x+1][y+1] += 1
    if check(x+1, y-1):
        area[x+1][y-1] += 1
    if check(x-1, y+1):
        area[x-1][y+1] += 1
    if check(x-1, y-1):
        area[x-1][y-1] += 1
    return area


def large(x, y, area):
    area = mediam(x, y, area)
    if check(x+2, y):
        area[x+2][y] += 1
    if check(x, y+2):
        area[x][y+2] += 1
    if check(x-2, y):
        area[x-2][y] += 1
    if check(x, y-2):
        area[x][y-2] += 1
    return area

area = [[0 for i in range(10)] for j in range(10)]

while True:
    try:
        x, y, s = map(int, input().split(','))
    except:
        break

    if s == 1:
        area = small(x, y, area)
    if s == 2:
        area = mediam(x, y, area)
    if s == 3:
        area = large(x, y, area)

max = 0
cnt = 0

for i in range(10):
    for j in range(10):
        if area[i][j] == 0:
            cnt += 1
        if area[i][j] > max:
            max = area[i][j]
print(cnt)
print(max)

Solution (Python):
p = [[0 for i in range(14)] for j in range(14)]
while True:
    try:
        x_inp, y_inp, s = map(int, input().split(","))
        x = x_inp + 2
        y = y_inp + 2
        if s == 1:
            p[y-1][x] = p[y-1][x] + 1
            p[y][x-1] = p[y][x-1] + 1
            p[y][x]   = p[y][x]   + 1
            p[y][x+1] = p[y][x+1] + 1
            p[y+1][x] = p[y+1][x] + 1
        elif s == 2:
            p[y-1][x-1] = p[y-1][x-1] + 1
            p[y-1][x]   = p[y-1][x]   + 1
            p[y-1][x+1] = p[y-1][x+1] + 1
            p[y][x-1]   = p[y][x-1]   + 1
            p[y][x]     = p[y][x]     + 1
            p[y][x+1]   = p[y][x+1]   + 1
            p[y+1][x-1] = p[y+1][x-1] + 1
            p[y+1][x]   = p[y+1][x]   + 1
            p[y+1][x+1] = p[y+1][x+1] + 1
        else:
            p[y-2][x] += 1
            p[y-1][x-1] = p[y-1][x-1] + 1
            p[y-1][x]   = p[y-1][x]   + 1
            p[y-1][x+1] = p[y-1][x+1] + 1
            p[y][x-2]   = p[y][x-2]   + 1
            p[y][x-1]   = p[y][x-1]   + 1
            p[y][x]     = p[y][x]     + 1
            p[y][x+1]   = p[y][x+1]   + 1
            p[y][x+2]   = p[y][x+2]   + 1
            p[y+1][x-1] = p[y+1][x-1] + 1
            p[y+1][x]   = p[y+1][x]   + 1
            p[y+1][x+1] = p[y+1][x+1] + 1
            p[y+2][x] += 1
    except:
        break
p_trim = [p[i][2:12] for i in range(2,12)]
p_flatten = sum(p_trim,[])
print(sum(x==0 for x in p_flatten))
print(max(p_flatten))

Solution (Python):
import sys


def small(grid, x, y):
    grid[x][y] += 1
    grid[x + 1][y] += 1
    grid[x][y + 1] += 1
    grid[x][y - 1] += 1
    grid[x - 1][y] += 1
    return grid


def middle(grid, x, y):
    grid[x][y] += 1
    grid[x + 1][y] += 1
    grid[x][y + 1] += 1
    grid[x][y - 1] += 1
    grid[x - 1][y] += 1
    grid[x - 1][y - 1] += 1
    grid[x - 1][y + 1] += 1
    grid[x + 1][y + 1] += 1
    grid[x + 1][y - 1] += 1
    return grid


def large(grid, x, y):
    grid[x][y] += 1
    grid[x + 1][y] += 1
    grid[x][y + 1] += 1
    grid[x][y - 1] += 1
    grid[x - 1][y] += 1
    grid[x - 1][y - 1] += 1
    grid[x - 1][y + 1] += 1
    grid[x + 1][y + 1] += 1
    grid[x + 1][y - 1] += 1
    grid[x][y + 2] += 1
    grid[x][y - 2] += 1
    grid[x + 2][y] += 1
    grid[x - 2][y] += 1
    return grid


grid = [[0 for _ in range(14)] for __ in range(14)]
for line in sys.stdin:
    d = list(map(int, line.split(",")))
    x = d[0] + 2
    y = d[1] + 2
    ink_size = d[2]
    if ink_size == 1:
        grid = small(grid, x, y)
    elif ink_size == 2:
        grid = middle(grid, x, y)
    else:
        grid = large(grid, x, y)
max_element = 0
count = 0
for i in range(2, 12):
    for j in range(2, 12):
        max_element = max(max_element, grid[i][j])
        if grid[i][j] == 0:
            count += 1
print(count)
print(max_element)

Solution (Python):
paper=[[0 for i in range(10)] for j in range(10)]


def drop(x,y):
    global paper
    if 0<=x<10 and 0<=y<10:
        paper[y][x] += 1
    return

def ink(x,y,s):
    drop(x,y)
    drop(x-1,y); drop(x+1,y)
    drop(x,y-1); drop(x,y+1)
    if s==1: return
    drop(x-1,y-1); drop(x-1,y+1)
    drop(x+1,y-1); drop(x+1,y+1)
    if s==2: return
    drop(x-2,y); drop(x+2,y)
    drop(x,y-2); drop(x,y+2)
    return

while True:
    try:
        x,y,s=map(int,raw_input().split(","))
        ink(x,y,s)
    except:
        break

print sum([i.count(0) for i in paper])
print max([max(i) for i in paper])

Solution (Python):
import sys
a=[[0]*10for _ in[0]*10]
p=[[(-1,0),(0,-1),(0,0),(0,1),(1,0)],[(-1,-1),(-1,1),(1,-1),(1,1)],[(-2,0),(0,-2),(0,2),(2,0)]]
for e in sys.stdin:
 x,y,s=map(int,e.split(','))
 for f in p[:s]:
  for s,t in f:
   if 0<=y+s<10 and 0<=x+t<10:a[y+s][x+t]+=1
print(sum(1 for r in a for c in r if c==0))
print(max(max(r)for r in a))

Solution (Python):
def get_input():
    while True:
        try:
            yield ''.join(input())
        except EOFError:
            break

N = list(get_input())
board = [[0 for i in range(14)] for j in range(14)]
for l in range(0,len(N)):
    x,y,s = [int(i) for i in N[l].split(",")]
    x = x + 2
    y = y + 2
    if s >= 1:
        board[x+1][y] += 1
        board[x-1][y] += 1
        board[x][y+1] += 1
        board[x][y-1] += 1
        board[x][y] += 1
    if s >= 2:
        board[x+1][y+1] += 1
        board[x+1][y-1] += 1
        board[x-1][y+1] += 1
        board[x-1][y-1] += 1
    if s >= 3:
        board[x+2][y] += 1
        board[x-2][y] += 1
        board[x][y+2] += 1
        board[x][y-2] += 1

a = 0
b = 0
for i in range(2,12):
    for j in range(2,12):
        if board[i][j] == 0:
            a += 1
        if board[i][j] > b:
            b = board[i][j]

print(a)
print(b)

Solution (Python):
p = [[0] * 10 for _ in range(10)]
x, y, s = 0, 0, 0
while True:
    try:
        x, y, s = map(int, input().split(","))
    except:
        break

    if s >= 1:
        p[x][y] += 1
        for i in range(x-1, x+2, 2):
            if -1 < i < 10:
                p[i][y] += 1
        for i in range(y-1, y+2, 2):
            if -1 < i < 10:
                p[x][i] += 1

    if s >= 2:
        for i in range(x-1, x+2, 2):
            for j in range(y-1, y+2, 2):
                if -1 < i < 10 and -1 < j < 10:
                    p[i][j] += 1

    if s == 3:
        for i in range(x-2, x+3, 4):
            if -1 < i < 10:
                p[i][y] += 1
        for i in range(y-2, y+3, 4):
            if -1 < i < 10:
                p[x][i] += 1

cnt_0 = 0
max_inc = 0

for l in p:
    cnt_0 += l.count(0)
    max_inc = max(l + [max_inc])

print(cnt_0)
print(max_inc)

Solution (Python):
import sys

lines = []
for line in sys.stdin:
    lines.append(line.strip().split(','))

field = [[0 for i in range(10)] for j in range(10)]

def drop(x, y, z):
    if z==1:
        for i in range(-1,2):
            for j in range(-1,2):
                if abs(i)+abs(j)<2 and 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1
    elif z==2:
        for i in range(-1,2):
            for j in range(-1,2):
                if 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1
    else:
        for i in range(-2,3):
            for j in range(-2,3):
                if abs(i)+abs(j)<3 and 0<=y+j<=9 and 0<=x+i<=9:
                    field[y+j][x+i] += 1



for line in lines:
    x,y,z = map(int, line)
    drop(x,y,z)

n = 0
m = 0
for f in field:
    for e in f:
        if e > m:
            m = e
        if e==0:
            n+=1

print(n)
print(m)

Solution (Python):
def dot(h, w):
    global area
    if 0 <= h and h < 10 and 0 <= w and w < 10:
        area[h][w] += 1
def sdot(h,w):
    [dot(h + i, w + j) for j in range(-1, 2) for i in range(-1 + abs(j), 2 - abs(j))]
def mdot(h,w):
    [dot(h + i, w + j) for j in range(-1, 2) for i in range(-1, 2)]
def ldot(h, w):
    [dot(h + i, w + j) for j in range(-2, 3) for i in range(-2 + abs(j), 3 - abs(j))]
dots = (sdot, mdot, ldot)
area = [[0 for _ in range(10)] for _ in range(10)]
while True:
    try:w, h, s = map(int, input().split(","))
    except:break
    dots[s - 1](h, w)
print(sum(i.count(0) for i in area))
print(max(max(i) for i in area))

Solution (Python):
import sys,collections
c=[tuple([i,j]) for i in range(10) for j in range(10)]
d=[list(map(int,text.split(","))) for text in sys.stdin]
o=[]
for b in d:
    if b[2]==1:
        t=[tuple([b[0]+i,b[1]+j]) for i in range(-1,2) for j in range(-1,2) if (i==0 or j==0) and 0<=b[0]+i<=9 and 0<=b[1]+j<=9]
    elif b[2]==2:
        t=[tuple([b[0]+i,b[1]+j]) for i in range(-1,2) for j in range(-1,2) if 0<=b[0]+i<=9 and 0<=b[1]+j<=9]
    elif b[2]==3:
        t=[tuple([b[0]+i,b[1]+j]) for i in range(-2,3) for j in range(-2,3) if abs(i)+abs(j)<=2 and 0<=b[0]+i<=9 and 0<=b[1]+j<=9]
    o+=t
print(len(set(c)-set(o)))
print(sorted(collections.Counter(o).values())[-1])

Solution (Python):

sheet = [[0 for _ in range(10)] for _ in range(10)]


small_range = ((0, 0), (1, 0), (0, 1), (-1, 0), (0, -1))
middle_range = ((0, 0), (1, 0), (1, 1), (0, 1), (-1, 1), (-1, 0), (-1, -1), (0, -1), (1, -1))
large_range = ((0, 0), (1, 0), (2, 0), (1, 1), (0, 1), (0, 2), (-1, 1), (-1, 0), (-2, 0), (-1, -1), (0, -1), (0, -2), (1, -1))


def drop(x, y, drop_range):
  for dx, dy in drop_range:
    newx, newy = x + dx, y + dy
    if 0 <= newx <= 9 and 0 <= newy <= 9:
      sheet[newx][newy] += 1

while True:
  try:
    x, y, s = map(int, input().split(","))

    if s == 1:
      drop(x, y, small_range)
    elif s == 2:
      drop(x, y, middle_range)
    else:
      drop(x, y, large_range)

  except EOFError:
    break


zero_cnt = 0


max_ink = 0

for x in range(10):
  for y in range(10):
    ink = sheet[x][y]

    if ink == 0:
      zero_cnt += 1

    if max_ink < ink:
      max_ink = ink

print(zero_cnt)
print(max_ink)

Solution (Python):



paper = [[0 for i in range(15)] for j in range(15)]
base = 2

while True:
	try:
		x, y, s = list(map(int, input().split(',')))
	except EOFError:
		break
        
	x += 2
	y += 2
	if s == 3:
		paper[x-2][y] += 1
		paper[x+2][y] += 1
		paper[x][y-2] += 1
		paper[x][y+2] += 1

	if s >= 2:
		paper[x-1][y-1] += 1
		paper[x-1][y+1] += 1
		paper[x+1][y-1] += 1
		paper[x+1][y+1] += 1

	paper[x][y] += 1
	paper[x-1][y] += 1
	paper[x+1][y] += 1
	paper[x][y-1] += 1
	paper[x][y+1] += 1

cnt = max = 0;
for x in range(2, 12):
	for y in range(2, 12):
		if paper[x][y] == 0:
			cnt += 1
		if paper[x][y] > max:
			max = paper[x][y]

print(cnt, max, sep='\n')

Solution (Python):
import sys

paper = [[0] * 10 for x in xrange(10)]

def dropInc(coord, size):
    x, y = coord
    if size == 1:
        paper[y][x] += 1
        if y > 0:
            paper[y-1][x] += 1
        if y < 9:
            paper[y+1][x] += 1
        if x > 0:
            paper[y][x-1] += 1
        if x < 9:
            paper[y][x+1] += 1
    elif size == 2:
        dropInc(coord, 1)
        if y > 0 and x > 0:
            paper[y-1][x-1] += 1
        if x < 9 and y > 0:
            paper[y-1][x+1] += 1
        if x > 0 and y < 9:
            paper[y+1][x-1] += 1
        if x < 9 and y < 9:
            paper[y+1][x+1] += 1
    elif size == 3:
        dropInc(coord, 2)
        if x > 1:
            paper[y][x-2] += 1
        if x < 8:
            paper[y][x+2] += 1
        if y > 1:
            paper[y-2][x] += 1
        if y < 8:
            paper[y+2][x] += 1

for line in sys.stdin.readlines():
    line = line.strip()
    x,y,size = map(int, line.split(","))
    dropInc((x,y), size)

print sum([1 if x == 0  else 0 for y in paper for x in y])
print max([x for y in paper for x in y])

Solution (Python):
drops = {
    1: ((0,0,0,0,0), (0,0,1,0,0), (0,1,1,1,0), (0,0,1,0,0), (0,0,0,0,0)),
    2: ((0,0,0,0,0), (0,1,1,1,0), (0,1,1,1,0), (0,1,1,1,0), (0,0,0,0,0)),
    3: ((0,0,1,0,0), (0,1,1,1,0), (1,1,1,1,1), (0,1,1,1,0), (0,0,1,0,0))}

paper = [[0 for i in xrange(14)] for j in xrange(14)]

def solve(x, y, size):
    for i in xrange(5):
        for j in xrange(5):
            if drops[size][i][j] == 1:
                paper[y+i][x+j] += 1

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    x, y, size = map(int, line.split(','))
    solve(x, y, size)

s = c = 0
for i in range(2, 12):
    for j in range(2, 12):
        if paper[i][j] == 0:
            c += 1
        if s < paper[i][j]:
            s = paper[i][j]

print c
print s

Solution (Python):
drops = {
    1: ((0,0,0,0,0), (0,0,1,0,0), (0,1,1,1,0), (0,0,1,0,0), (0,0,0,0,0)),
    2: ((0,0,0,0,0), (0,1,1,1,0), (0,1,1,1,0), (0,1,1,1,0), (0,0,0,0,0)),
    3: ((0,0,1,0,0), (0,1,1,1,0), (1,1,1,1,1), (0,1,1,1,0), (0,0,1,0,0))}

paper = [[0] * 14 for j in xrange(14)]

def solve(x, y, size):
    for i in xrange(5):
        for j in xrange(5):
            if drops[size][i][j] == 1:
                paper[y+i][x+j] += 1

while True:
    try:
        line = raw_input()
    except EOFError:
        break
    solve(*map(int, line.split(',')))

result = [f for i in [l[2:12] for l in paper[2:12]] for f in i]

print result.count(0)
print max(result)

Solution (Python):
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print sum([1 if i==0 else 0 for j in board for i in j])
print max([i for j in board for i in j])

Solution (Python):
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print len([j for i in board for j in i if j==0])
print max([i for j in board for i in j])

Solution (Python):
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

print len([j for i in board for j in i if j==0])
print max([j for i in board for j in i])

Solution (Python):
import sys

board=[[0]*10 for i in xrange(10)]

large=[[0,0,1,0,0],
       [0,1,1,1,0],
       [1,1,1,1,1],
       [0,1,1,1,0],
       [0,0,1,0,0],]
middle=[[0,0,0,0,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,1,1,1,0],
        [0,0,0,0,0],]
small=[[0,0,0,0,0],
       [0,0,1,0,0],
       [0,1,1,1,0],
       [0,0,1,0,0],
       [0,0,0,0,0],]

size=[0,small,middle,large]

def isOnBoard(y,x):
    return 0<=y<10 and 0<=x<10

for line in sys.stdin.readlines():
    x,y,s=map(int,line.strip().split(","))
    for i in xrange(-2,3):
        for j in xrange(-2,3):
            if isOnBoard(y+i,x+j):
                board[y+i][x+j]+=size[s][i+2][j+2]

a=[j for i in board for j in i]
print a.count(0)
print max(a)

Solution (Python):
cell = [[0] * 10 for i in xrange(10)]

large = [[0,0,1,0,0],
         [0,1,1,1,0],
         [1,1,1,1,1],
         [0,1,1,1,0],
         [0,0,1,0,0]]

medium= [[0,0,0,0,0],
         [0,1,1,1,0],
         [0,1,1,1,0],
         [0,1,1,1,0],
         [0,0,0,0,0]]

small = [[0,0,0,0,0],
         [0,0,1,0,0],
         [0,1,1,1,0],
         [0,0,1,0,0],
         [0,0,0,0,0]]

size = [0,small,medium,large]

while True:
    try:
        x, y, s = [int(i) for i in raw_input().split(',')]
    except EOFError:
        break
    except ValueError:
        break
    p = size[s]
    for i in xrange(5):
        for j in xrange(5):
            px = i+x-2
            py = j+y-2
            if(px in xrange(10) and py in xrange(10)):
                cell[py][px] += p[i][j]
print reduce(lambda x,y:x+y,map(lambda x:x.count(0),cell))
print max(map(max,cell))

Solution (Python):
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter

NUM = [[0, 0, 1, 0, 0, 1, 1, 1, 0, 0, 1, 0, 0],
       [0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0],
       [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]]
paper = Counter()
for line in stdin:
    if not line.strip():
        break
    x, y, size = (int(s) for s in line.split(','))

    xidx = [x, x-1, x, x+1, x-2, x-1, x, x+1, x+2, x-1, x, x+1, x]
    yidx = [y-2, y-1, y-1, y-1, y, y, y, y, y, y+1, y+1, y+1, y+2]
    val = NUM[size-1]

    for a, b, i in zip(xidx, yidx, xrange(len(xidx))):
        if a < 0 or 9 < a or b < 0 or 9 < b:
            continue
        paper[a + b * 10] += val[i]

print(sum(1 for i in xrange(100) if not paper[i]))
print(max(paper[i] for i in xrange(100)))

Solution (Python):
mass = [[0 for p in xrange(14)] for q in xrange(14)]
while True:
	try:
		x,y,size = map(int,raw_input().split(','))
		x += 2 ; y += 2
		if   size == 1:
			mass[x-2][y-2]+=0;mass[x-1][y-2]+=0;mass[x][y-2]+=0;mass[x+1][y-2]+=0;mass[x+2][y-2]+=0
			mass[x-2][y-1]+=0;mass[x-1][y-1]+=0;mass[x][y-1]+=1;mass[x+1][y-1]+=0;mass[x+2][y-1]+=0
			mass[x-2][y]  +=0;mass[x-1][y]  +=1;mass[x][y]  +=1;mass[x+1][y]  +=1;mass[x+2][y]  +=0
			mass[x-2][y+1]+=0;mass[x-1][y+1]+=0;mass[x][y+1]+=1;mass[x+1][y+1]+=0;mass[x+2][y+1]+=0
			mass[x-2][y+2]+=0;mass[x-1][y+2]+=0;mass[x][y+2]+=0;mass[x+1][y+2]+=0;mass[x+2][y+2]+=0
		elif size == 2:
			mass[x-2][y-2]+=0;mass[x-1][y-2]+=0;mass[x][y-2]+=0;mass[x+1][y-2]+=0;mass[x+2][y-2]+=0
			mass[x-2][y-1]+=0;mass[x-1][y-1]+=1;mass[x][y-1]+=1;mass[x+1][y-1]+=1;mass[x+2][y-1]+=0
			mass[x-2][y]  +=0;mass[x-1][y]  +=1;mass[x][y]  +=1;mass[x+1][y]  +=1;mass[x+2][y]  +=0
			mass[x-2][y+1]+=0;mass[x-1][y+1]+=1;mass[x][y+1]+=1;mass[x+1][y+1]+=1;mass[x+2][y+1]+=0
			mass[x-2][y+2]+=0;mass[x-1][y+2]+=0;mass[x][y+2]+=0;mass[x+1][y+2]+=0;mass[x+2][y+2]+=0
		elif size == 3:
			mass[x-2][y-2]+=0;mass[x-1][y-2]+=0;mass[x][y-2]+=1;mass[x+1][y-2]+=0;mass[x+2][y-2]+=0
			mass[x-2][y-1]+=0;mass[x-1][y-1]+=1;mass[x][y-1]+=1;mass[x+1][y-1]+=1;mass[x+2][y-1]+=0
			mass[x-2][y]  +=1;mass[x-1][y]  +=1;mass[x][y]  +=1;mass[x+1][y]  +=1;mass[x+2][y]  +=1
			mass[x-2][y+1]+=0;mass[x-1][y+1]+=1;mass[x][y+1]+=1;mass[x+1][y+1]+=1;mass[x+2][y+1]+=0
			mass[x-2][y+2]+=0;mass[x-1][y+2]+=0;mass[x][y+2]+=1;mass[x+1][y+2]+=0;mass[x+2][y+2]+=0
	except: break
white = 0
max = 0
for p in xrange(2,12):
	for q in xrange(2,12):
		if mass[p][q] == 0: white += 1
		if mass[p][q] > max: max = mass[p][q]
print white
print max

Solution (Python):

import sys


class Paper:
    def __init__(self):
        self.paper = [[0 for x in range(10)] for y in range(10)]

    def white_space(self):
        s = 0
        for x in range(10):
            for y in range(10):
                if self.paper[x][y] == 0:
                    s += 1
        return s

    def most_dark(self):
        s = 0
        for x in range(10):
            for y in range(10):
                if self.paper[x][y] > s:
                    s = self.paper[x][y]
        return s

    def drop(self, x, y, size):
        r = []
        if size == 1:
            r.append((x,y))
            r.append((x-1,y))
            r.append((x+1,y))
            r.append((x,y-1))
            r.append((x,y+1))
        elif size == 2:
            r = [(i,j) for i in range(x-1, x+2) for j in range(y-1, y+2)]
        elif size == 3:
            r = [(i,j) for i in range(x-1, x+2) for j in range(y-1, y+2)]
            r.append((x-2, y))
            r.append((x+2, y))
            r.append((x, y-2))
            r.append((x, y+2))
        else:
            pass

        r = filter(self.out_of_paper, r)

        try:
            for p in r:
                self.paper[p[0]][p[1]] += 1
        except:
            pass
        return self

    def out_of_paper(self, p):
        if 0 <= p[0] < 10 and 0 <= p[1] < 10:
            return True
        else:
            return False



paper = Paper()
for line in sys.stdin:
    (x, y, size) = tuple(map(int, line.split(',')))
    paper.drop(x, y, size)
print paper.white_space()
print paper.most_dark()