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):
def drop(x,y):
    global paper
    if 0<=x<10 and 0<=y<10: paper[y][x]+=1
    return

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

paper = [[0 for i in range(10)] for j in range(10)]
while True:
    try:
        x,y,size = map(int, raw_input().split(","))
        ink(x,y,size)
    except:
        break

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

Solution (Python):
px = ((0,0,-1,1), (-1,-1,1,1), (0,0,-2,2))
py = ((-1,1,0,0), (-1,1,-1,1), (-2,2,0,0))

p = [[0]*14 for i in range(14)]

while True:
    try:
        x,y,s = map(int,raw_input().split(','))
        x += 2
        y += 2
        p[x][y] += 1
        for i in range(s):
            for j in range(4):
                p[x+px[i][j]][y+py[i][j]] += 1
    except EOFError:
        break
p = [a[2:-2] for a in p[2:-2]]
print sum([a.count(0) for a in p])
print max([max(a) for a in p])

Solution (Python):
import sys

SIZE = 10
paper = []


def main():
    init()

    for line in sys.stdin:
        data = line.strip().split(',')
        i = int(data[0])
        j = int(data[1])
        size = int(data[2])

        if   size == 1:
            drop_small(i, j)
        elif size == 2:
            drop_medium(i, j)
        elif size == 3:
            drop_large(i, j)

    print count_white()
    print find_max()

def find_max():
    mx = 0
    for i in xrange(SIZE):
        for j in xrange(SIZE):
            mx = max(mx, paper[i][j])

    return mx

def count_white():
    c = 0
    for i in xrange(SIZE):
        for j in xrange(SIZE):
            if paper[i][j] == 0:
                c += 1

    return c

def init():
    global paper
    for i in xrange(SIZE):
        paper.append([0]*SIZE)


def check(i, j):
    if i < 0 or SIZE <= i:
        return False
    if j < 0 or SIZE <= j:
        return False

    return True


def drop(i, j):
    global paper
    if not check(i, j):
        return False

    paper[i][j] += 1
    return True


def drop_small(i, j):
    drop(i, j)
    drop(i - 1, j)
    drop(i + 1, j)
    drop(i, j - 1)
    drop(i, j + 1)


def drop_medium(i, j):
    drop_small(i, j)
    drop(i - 1, j - 1)
    drop(i - 1, j + 1)
    drop(i + 1, j - 1)
    drop(i + 1, j + 1)


def drop_large(i, j):
    drop_medium(i, j)
    drop(i - 2, j)
    drop(i, j - 2)
    drop(i, j + 2)
    drop(i + 2, j)

main()

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,y+1)
    drop(x-1,y); 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,y+2)
    drop(x-2,y); 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
def ink(x,y,size):
    global paper
    paper[y][x]+=1
    for d in [-1,1]:
        paper[y+d][x]+=1
        paper[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        paper[y+d][x+d]+=1
        paper[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        paper[y+d][x]+=1
        paper[y][x+d]+=1
    return

R=range(14)
paper=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in paper[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Solution (Python):
import sys
def ink(x,y,size):
    global P
    P[y][x]+=1
    for d in [-1,1]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    if size==1: return
    for d in [-1,1]:
        P[y+d][x+d]+=1
        P[y+d][x-d]+=1
    if size==2: return
    for d in [-2,2]:
        P[y+d][x]+=1
        P[y][x+d]+=1
    return

R=range(14)
P=[[0 for i in R] for j in R]
for s in sys.stdin:
    x,y,size = map(int, s.split(","))
    ink(x+2,y+2,size)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Solution (Python):
import sys
def ink(x,y,s):
    global P
    P[y][x]+=1
    P[y+1][x]+=1
    P[y-1][x]+=1
    P[y][x+1]+=1
    P[y][x-1]+=1
    if s==1: return
    P[y+1][x+1]+=1
    P[y+1][x-1]+=1
    P[y-1][x+1]+=1
    P[y-1][x-1]+=1
    if s==2: return
    P[y+2][x]+=1
    P[y-2][x]+=1
    P[y][x+2]+=1
    P[y][x-2]+=1
    return

P=[[0]*14 for j in range(14)]
for s in sys.stdin:
    x,y,s = map(int, s.split(","))
    ink(x+2,y+2,s)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Solution (Python):
small_x = [-1, 0, 0, 1]
small_y = [0, -1, 1, 0]
middle_x = [-1, -1, -1, 0, 0, 1, 1, 1]
middle_y = [-1, 0, 1, -1, 1, -1, 0, 1]
big_x = [-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2]
big_y = [0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0]
dx = [[], small_x, middle_x, big_x]
dy = [[], small_y, middle_y, big_y]

field = [[0] * 10 for _ in range(10)]
while 1:
    try:
        x1, y1, size = map(int, raw_input().split(','))
        field[y1][x1] += 1
        for k in range(len(dx[size])):
            ny = y1 + dy[size][k]
            nx = x1 + dx[size][k]
            if nx < 0 or ny < 0 or nx >= 10 or ny >= 10:
                continue
            field[ny][nx] += 1
    except:
        break
ret, mx = 0, 0
for i in range(10):
    for j in range(10):
        if field[i][j] == 0:
            ret += 1
        mx = max(mx, field[i][j])
print ret
print mx

Solution (Python):
dx = [[0, 1, 0, -1, 0], [1, 1, -1, -1], [2, 0, -2, 0]]
dy = [[0, 0, 1, 0, -1], [-1, 1, 1, -1], [0, 2, 0, -2]]
a = [[0 for i in range(14)] for j in range(14)]
try:
    while True:
        x, y, s = map(int, raw_input().split(','))
        x += 2
        y += 2
        for i in range(s):
            for j in range(len(dx[i])):
                a[x + dx[i][j]][y + dy[i][j]] += 1
except:
    pass
ct = mx = 0
for b in a[2:-2]:
    for p in b[2:-2]:
        mx = max(mx, p)
        if p == 0:
            ct += 1
print ct
print mx

Solution (Python):
import sys

def plot(x, y):
    global ban
    if 0 <= x < 10 and 0 <= y < 10: ban[y][x] += 1

def drop(x, y, s):
    for dx, dy in [(0, 0), (-1, 0), (1, 0), (0, -1), (0, 1)]:
        plot(x + dx, y + dy)
    if s == 1: return
    for dx, dy in [(-1, -1), (-1, 1), (1, -1), (1, 1)]:
        plot(x + dx, y + dy)
    if s == 2: return
    for dx, dy in [(-2, 0), (2, 0), (0, -2), (0, 2)]:
        plot(x + dx, y + dy)

ban = [[0 for x in range(10)] for y in range(10)]
for line in sys.stdin:
    x, y, size = map(int, line.split(','))
    drop(x, y, size)

print(sum(ban[y][x] == 0 for y in range(10) for x in range(10)))
print(max(ban[y][x] for y in range(10) for x in range(10)))

Solution (Python):
mat = []
for i in range(10):
    mat.append([0]*10)

while True:
    try:
        lst = list(map(int, input().split(',')))
        x, y, s = lst[0], lst[1], lst[2]
        
        if s == 1:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1]]

        elif s == 2:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1], [x-1, y-1], [x+1, y-1], [x-1, y+1], [x+1, y+1]]

        else:
            tmplst = [[x, y], [x, y-1], [x-1, y], [x+1, y], [x, y+1], [x-1, y-1], [x+1, y-1], [x-1, y+1], [x+1, y+1], [x, y-2], [x-2, y], [x+2, y], [x, y+2]]

        for i in tmplst:
            if i[0] < 0 or i[0] > 9 or i[1] < 0 or i[1] > 9:
                pass
            else:
                mat[i[1]][i[0]] +=1
        
    except EOFError:
        break

summat = 0
maxmat = 0
for j in mat:
    summat += j.count(0)
    if maxmat < max(j):
        maxmat = max(j)

print(summat)
print(maxmat)

Solution (Python):
import sys
readlines = sys.stdin.readlines
write = sys.stdout.write
def solve():
    P = []
    for line in readlines():
        x, y, s = map(int, line.split(","))
        P.append((x, y, s))
    L = 10
    MP = [[0]*L for i in range(L)]
    def update(k, ps):
        for x, y, s in P:
            if k <= s:
                for dx, dy in ps:
                    nx = x + dx; ny = y + dy
                    if not 0 <= nx < L or not 0 <= ny < L:
                        continue
                    MP[ny][nx] += 1
    update(0, [(0, 0)])
    update(1, [(-1, 0), (0, -1), (1, 0), (0, 1)])
    update(2, [(-1, -1), (1, -1), (-1, 1), (1, 1)])
    update(3, [(-2, 0), (0, -2), (2, 0), (0, 2)])
    z = m = 0
    for i in range(L):
        for j in range(L):
            if MP[i][j] == 0:
                z += 1
            m = max(m, MP[i][j])
    write("%d\n%d\n" % (z, m))
solve()

Solution (Python):
paper = [[0 for i in range(10)] for j in range(10)]
while True :
    try :
        x, y, s = map(int, input().split(","))
        
        paper[x][y] += 1
        if x > 0 :
            paper[x-1][y] += 1
        if y > 0 :
            paper[x][y-1] += 1
        if x < 9 :
            paper[x+1][y] += 1
        if y < 9 :
            paper[x][y+1] += 1

        if s > 1 :
            if x > 0 :
                if y > 0 :
                    paper[x-1][y-1] += 1
                if y < 9 :
                    paper[x-1][y+1] += 1
            if x < 9 :
                if y > 0 :
                    paper[x+1][y-1] += 1
                if y < 9 :
                    paper[x+1][y+1] += 1
        if s > 2 :
            if x > 1 :
                paper[x-2][y] += 1
            if y > 1 :
                paper[x][y-2] += 1
            if x < 8 :
                paper[x+2][y] += 1
            if y < 8 :
                paper[x][y+2] += 1
                
    except EOFError :
        break


S = 0
M = 0
for i in range(10) :
    for j in range(10) :
        if paper[i][j] == 0 :
            S += 1
        if paper[i][j] > M :
            M = paper[i][j]
        
print(S)
print(M)

Solution (Python):
def solve():
    from sys import stdin
    input_lines = stdin
    
    paper = [0] * 196
    
    size = [[0, -1, 1, -14, 14], [0, -1, 1, -15, -14, -13, 13, 14, 15],
            [0, -1, 1, -15, -14, -13, 13, 14, 15, -28, -2, 2, 28]]
    
    for line in input_lines:
        x, y, s = map(int, line.split(','))
        
        pos = 30 + x + 14 * y
        s -= 1
        
        for move in size[s]:
            paper[pos+move] += 1
    
    zero_cnt = 0
    max_density = 0
    for i in range(30, 157, 14):
        line = paper[i:i+10]
        zero_cnt += line.count(0)
        max_density = max(max_density, max(line))
    
    print(zero_cnt)
    print(max_density)

solve()

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):
def paint(masu,data):
    masu[data[1]][data[0]]+=1                   
    
    if data[2]==1:                              
        if data[0]!=0:
            masu[data[1]][data[0]-1]+=1
        if data[0]!=9:
            masu[data[1]][data[0]+1]+=1
        if data[1]!=0:
            masu[data[1]-1][data[0]]+=1
        if data[1]!=9:
            masu[data[1]+1][data[0]]+=1
        
    elif data[2]==2:                            
        if data[0]!=0:
            masu[data[1]][data[0]-1]+=1
        if data[0]!=9:
            masu[data[1]][data[0]+1]+=1
        if data[1]!=0:
            masu[data[1]-1][data[0]]+=1
        if data[1]!=9:
            masu[data[1]+1][data[0]]+=1
        if data[1]!=9 and data[0]!=9:
            masu[data[1]+1][data[0]+1]+=1
        if data[1]!=9 and data[0]!=0:
            masu[data[1]+1][data[0]-1]+=1
        if data[1]!=0 and data[0]!=9:
            masu[data[1]-1][data[0]+1]+=1
        if data[1]!=0 and data[0]!=0:
            masu[data[1]-1][data[0]-1]+=1
        
    elif data[2]==3:                            
        if data[0]!=0:
            masu[data[1]][data[0]-1]+=1
        if data[0]!=9:
            masu[data[1]][data[0]+1]+=1
        if data[1]!=0:
            masu[data[1]-1][data[0]]+=1
        if data[1]!=9:
            masu[data[1]+1][data[0]]+=1
        if data[1]!=9 and data[0]!=9:
            masu[data[1]+1][data[0]+1]+=1
        if data[1]!=9 and data[0]!=0:
            masu[data[1]+1][data[0]-1]+=1
        if data[1]!=0 and data[0]!=9:
            masu[data[1]-1][data[0]+1]+=1
        if data[1]!=0 and data[0]!=0:
            masu[data[1]-1][data[0]-1]+=1
        if data[1]>=2:
            masu[data[1]-2][data[0]]+=1
        if data[1]<=7:
            masu[data[1]+2][data[0]]+=1
        if data[0]>=2:
            masu[data[1]][data[0]-2]+=1
        if data[0]<=7:
            masu[data[1]][data[0]+2]+=1
        
    return masu

masu=[
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0],
        [0,0,0,0,0,0,0,0,0,0]
    ]



def keisan(masu):
    max=0
    num1=0
    for na in range(10):
        for ma in range(10):
            if masu[na][ma]==0:
                num1+=1
            if masu[na][ma]>max:
                max=masu[na][ma]
    print(num1)
    print(max)

while True:
    try:
        x,y,s=list(map(int, input().split(',')))
        data=[x,y,s]   
        masu2=paint(masu,data)
    except:
        break

    
    

keisan(masu2)

Solution (Python):
def small(x, y, a):
    a[x][y] += 1
    a[x + 1][y] += 1
    a[x - 1][y] += 1
    a[x][y + 1] += 1
    a[x][y - 1] += 1


def medium(x, y, a):
    small(x, y, a)
    a[x + 1][y + 1] += 1
    a[x - 1][y + 1] += 1
    a[x - 1][y - 1] += 1
    a[x + 1][y - 1] += 1


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


p = [[0] * 13 for i in range(13)]
while 1:
    try:
        x, y, s = map(int, input().split(','))
        if s == 1:
            small(x, y, p)
        elif s == 2:
            medium(x, y, p)
        elif s == 3:
            large(x, y, p)
    except:
        break

w, dens = 0, 0
for i in range(10):
    for j in range(10):
        if p[i][j] == 0:
            w += 1
        if p[i][j] >= dens:
            dens = p[i][j]

print(w)
print(dens)

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

s1i = [-1, 0, 0, 1]
s1j = [0, -1, 1, 0]
s2i = [-1, -1, -1, 0, 0, 1, 1, 1]
s2j = [-1, 0, 1, -1, 1, -1, 0, 1]
s3i = [-2, -1, -1, -1, 0, 0, 0, 0, 1, 1, 1, 2]
s3j = [0, -1, 0, 1, -2, -1, 1, 2, -1, 0, 1, 0]

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

  p[y][x] += 1
  if s == 1:
    for k in range(len(s1i)):
      xx = x + s1j[k]
      yy = y + s1i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
  elif s == 2:
    for k in range(len(s2i)):
      xx = x + s2j[k]
      yy = y + s2i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
  else:
    for k in range(len(s3i)):
      xx = x + s3j[k]
      yy = y + s3i[k]
      if 0 <= xx and xx < 10 and 0 <= yy and yy < 10:
        p[yy][xx] += 1
    
cnt = 0
m = 0
for i in range(10):
  
  for j in range(10):
    if p[i][j] == 0:
      cnt += 1
    else:
      pass
    m = max(p[i][j], m)


print(cnt)
print(m)

Solution (Python):
if __name__ == '__main__':

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

	while True:
		try:
			x,y,s = map(int,input().split(","))
			if s == 0:
				break
			if s == 1:
				
				DI[x][y] += 1
				
				if y >= 1 :
					DI[x][y-1] += 1
				
				if y <= 8:
					DI[x][y+1] += 1
				
				if x >= 1:
					DI[x-1][y] += 1
				
				if x <= 8:
					DI[x+1][y] += 1

			elif s == 2:
				
				DI[x][y] += 1
				
				if y >= 1 :
					DI[x][y-1] += 1
				
				if x >= 1 and y >= 1:
					DI[x-1][y-1] += 1
				
				if x <= 8 and y >= 1 :
					DI[x+1][y-1] += 1
				
				if y <= 8:
					DI[x][y+1] += 1
				
				if x >= 1 and y <= 8:
					DI[x-1][y+1] += 1
				
				if x <= 8 and y <= 8 :
					DI[x+1][y+1] += 1
				
				if x >= 1:
					DI[x-1][y] += 1
				
				if x <= 8:
					DI[x+1][y] += 1

			else:
				
				DI[x][y] += 1
				
				if y >= 1 :
					DI[x][y-1] += 1
				
				if x >= 1 and y >= 1:
					DI[x-1][y-1] += 1
				
				if x <= 8 and y >= 1 :
					DI[x+1][y-1] += 1
				
				if y >= 2 :
					DI[x][y-2] += 1
				
				if y <= 8:
					DI[x][y+1] += 1
				
				if x >= 1 and y <= 8:
					DI[x-1][y+1] += 1
				
				if x <= 8 and y <= 8 :
					DI[x+1][y+1] += 1
				
				if y <= 7:
					DI[x][y+2] += 1
				
				if x >= 1:
					DI[x-1][y] += 1
				
				if x >= 2:
					DI[x-2][y] += 1
				
				if x <= 8:
					DI[x+1][y] += 1
				
				if x <= 7:
					DI[x+2][y] += 1



		except EOFError:
			break




	cnt = 0
	maxcnt = 0
	for k in DI:
		cnt += k.count(0)
		if maxcnt < max(k):
			maxcnt = max(k)
	print(cnt)
	print(maxcnt)

Solution (Python):
def small_ink(paper,x,y):
  paper[x][y] += 1
  if 0 <= x-1 and x-1 < 10:
    paper[x-1][y] += 1
  if 0 <= y-1 and y-1 < 10:
    paper[x][y-1] += 1
  if 0 <= x+1 and x+1 < 10:
    paper[x+1][y] += 1
  if 0 <= y+1 and y+1 < 10:
    paper[x][y+1] += 1
  return paper

def middle_ink(paper,x,y):
  paper = small_ink(paper,x,y)
  if (0 <= x-1 and x-1 < 10) and (0 <= y-1 and y-1 < 10):
    paper[x-1][y-1] += 1
  if (0 <= x-1 and x-1 < 10) and (0 <= y+1 and y+1 < 10):
    paper[x-1][y+1] += 1
  if (0 <= x+1 and x+1 < 10) and (0 <= y-1 and y-1 < 10):
    paper[x+1][y-1] += 1
  if (0 <= x+1 and x+1 < 10) and (0 <= y+1 and y+1 < 10):
    paper[x+1][y+1] += 1
  return paper

def large_ink(paper,x,y):
  paper = middle_ink(paper,x,y)
  if (0 <= x-2 and x-2 < 10):
    paper[x-2][y] += 1
  if (0 <= y-2 and y-2 < 10):
    paper[x][y-2] += 1
  if (0 <= y+2 and y+2 < 10):
    paper[x][y+2] += 1
  if (0 <= x+2 and x+2 < 10):
    paper[x+2][y] += 1
  return paper

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

while True:
  try:
    x,y,s = map(int, input().split(','))
  except EOFError:
    break
  if s == 1:
    paper = small_ink(paper,x,y)
  elif s == 2:
    paper = middle_ink(paper,x,y)
  elif s == 3:
    paper = large_ink(paper,x,y)

sum0 = 0
max_ink = 0
for i in range(10):
  for j in range(10):
    if paper[i][j] == 0:
      sum0 += 1
    if paper[i][j] > max_ink:
      max_ink = paper[i][j]
print(sum0)
print(max_ink)

Solution (Python):
import sys

field = []
for i in range(0, 10):
	lst = []
	for j in range(0, 10):
		lst.append(0)
	field.append(lst)

for line in sys.stdin:
	x, y, s = map(int, line.split(','))
	field[x][y] += 1
	for i in range(0, 2):
		nextx = x-1+2*i
		nexty = y-1+2*i
		if 0 <= nextx and nextx < 10: field[nextx][y] += 1
		if 0 <= nexty and nexty < 10: field[x][nexty] += 1
	if s >= 2:
		for i in range(0, 2):
			nextx = x-1+2*i
			if 0 <= nextx and nextx < 10:
				for j in range(0, 2):
					nexty = y-1+2*j
					if 0 <= nexty and nexty < 10:
						field[nextx][nexty] += 1
	if s == 3:
		for i in range(0, 2):
			nextx = x-2+4*i
			nexty = y-2+4*i
			if 0 <= nextx and nextx < 10: field[nextx][y] += 1
			if 0 <= nexty and nexty < 10: field[x][nexty] += 1

cnt = 0
max = 0
for i in range(0, 10):
	for j in range(0, 10):
		if field[i][j] == 0: cnt += 1
		else:
			if max < field[i][j]: max = field[i][j]
print cnt
print max

Solution (Python):
paper=[[0 for i in range(10)] for j in range(10)]
while 1:
    try:
        x,y,s=map(int,input().split(","))
        if s==1:
            r=[[-1,0],[1,0],[0,0],[0,-1],[0,1]]
        elif s==2:
            r=[[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]]
        elif s==3:
            r=[[-2,0],[-1,-1],[-1,0],[-1,1],[0,-2],[0,-1],[0,0],[0,1],[0,2],[1,-1],[1,0],[1,1],[2,0]]
        for i in r:
            if y+i[0]<0 or y+i[0]>9 or x+i[1]<0 or x+i[1]>9:pass
            else:
                paper[y+i[0]][x+i[1]]+=1
    except:break
ans=0
dark=0
for i in paper:
    for j in i:
        if j==0:ans+=1
        else:dark=max(dark,j)
print(ans)
print(dark)

Solution (Python):
a = [[0 for i in range(14)] for j in range(14)]
drop = [0 for i in range(3)]
drop[0] = [
	[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]
]
drop[1] = [
	[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]
]
drop[2] = [
	[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]
]

while(1):
	try:
		x,y,n = [int(i) for i in input().split(",")]
		for i in range(5):
			for j in range(5):
				a[x+i][y+j] = a[x+i][y+j] + drop[n-1][i][j]
	except EOFError:
		b = [[0 for i in range(10)] for j in range(10)]
		for i in range(10):
			for j in range(10):
				b[i][j] = a[i+2][j+2]
		zero = [sum([1 if b[i][j] == 0 else 0 for j in range(10)]) for i in range(10)]
		print(sum(zero))
		print(int(max([max(i) for i in b])))
		break

Solution (Python):
paper = [[0]*10 for l in range(10)]
while True:
    try:
        x,y,s = map(int, input().split(","))
        
        paper[x][y] += 1
        if y - 1 >= 0:
            paper[x][y - 1] += 1
        if x - 1 >= 0:
            paper[x - 1][y] += 1
        if x + 1 < 10:
            paper[x + 1][y] += 1
        if y + 1 < 10:
            paper[x][y + 1] += 1

        
        if s >= 2:
            if x - 1 >= 0 and y - 1 >= 0:
                paper[x - 1][y - 1] += 1
            if x + 1 < 10 and y - 1 >= 0:
                paper[x + 1][y - 1] += 1
            if x - 1 >= 0 and y + 1 < 10:
                paper[x - 1][y + 1] += 1
            if x + 1 < 10 and y + 1 < 10:
                paper[x + 1][y + 1] += 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
    except EOFError:
        break
flat_paper = sum(paper, [])
print(flat_paper.count(0))
print(max(flat_paper))

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):
ar = [[0]*14 for _ in range(14)]

while(True):
    try:
        x,y,s = map(int,input().split(","))
        if s == 3:
            for x1,y1 in [[-2,0],[0,2],[2,0],[0,-2],[-1,-1],[0,-1],[1,-1],[-1,0],[0,0],[1,0],[-1,1],[0,1],[1,1]]:
                ar[y1+y+2][x1+x+2] += 1
        elif s == 2:
            for x1,y1 in [[-1,-1],[0,-1],[1,-1],[-1,0],[0,0],[1,0],[-1,1],[0,1],[1,1]]:
                ar[y1+y+2][x1+x+2] += 1
        elif s == 1:
            for x1,y1 in [[0,-1],[-1,0],[0,0],[1,0],[0,1]]:
                ar[y1+y+2][x1+x+2] += 1
    except:
        break
br = [ a[2:12] for a in ar[2:12] ]
print(sum([b.count(0) for b in br]))
print(max([max(b) for b in br]))

Solution (Python):
import sys

class Board():
    
    def __init__(self):
        self.B = [0 for _ in range(12 * 12)]
        
        for i in range(0, 12):
            self.B[i] = -1
        for i in range(12, 12 * 12, 12):
            self.B[i] = -1
        for i in range(11, 11 * 12, 12):
            self.B[i] = -1
        for i in range(12 * 11, 12 * 12):
            self.B[i] = -1
    
    def print(self):
        cnt = 0
        for b in self.B:
            if b == 0:
                cnt += 1
        
        print(cnt)
        print(max(self.B))
    
    def inc_if_non_wall(self, x, y):
        idx = (y + 1) * 12 + (x + 1)
        
        if self.B[idx] != -1:
            self.B[idx] += 1
    
    def drop_s(self, x, y):
        self.inc_if_non_wall(x, y)
        self.inc_if_non_wall(x, y - 1)
        self.inc_if_non_wall(x - 1, y)
        self.inc_if_non_wall(x + 1, y)
        self.inc_if_non_wall(x, y + 1)
    
    def drop_m(self, x, y):
        self.drop_s(x, y)
        self.inc_if_non_wall(x - 1, y - 1)
        self.inc_if_non_wall(x + 1, y - 1)
        self.inc_if_non_wall(x - 1, y + 1)
        self.inc_if_non_wall(x + 1, y + 1)
    
    def drop_l(self, x, y):
        self.drop_m(x, y)
        
        idx = (y + 1) * 12 + (x + 1)
        if 12 * 3 < idx:
            self.inc_if_non_wall(x, y - 2)
        if idx < 12 * 9:
            self.inc_if_non_wall(x, y + 2)
        
        self.inc_if_non_wall(x - 2, y)
        self.inc_if_non_wall(x + 2, y)
    

if __name__ == "__main__":
    B = Board()
    for l in sys.stdin:
        x, y, s = map(int, l.split(','))
        if s == 1:
            B.drop_s(x, y)
        elif s == 2:
            B.drop_m(x, y)
        elif s == 3:
            B.drop_l(x, y)
    
    B.print()