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):
peper=[[0 for i in range(14)]for j in range(14)]
while True:
    try:
        x,y,s=map(int,input().split(","))
        x +=2
        y +=2
        if s==3:
            peper[y][x] +=1
            peper[y][x-1] +=1
            peper[y][x-2] +=1
            peper[y][x+1] +=1
            peper[y][x+2] +=1
            peper[y-1][x] +=1
            peper[y-2][x] +=1
            peper[y+1][x] +=1
            peper[y+2][x] +=1
            peper[y-1][x-1] +=1
            peper[y-1][x+1] +=1
            peper[y+1][x-1] +=1
            peper[y+1][x+1] +=1
        elif s==2:
            peper[y][x] +=1
            peper[y][x+1] +=1
            peper[y][x-1] +=1
            peper[y+1][x] +=1
            peper[y+1][x+1] +=1
            peper[y+1][x-1] +=1
            peper[y-1][x] +=1
            peper[y-1][x+1] +=1
            peper[y-1][x-1] +=1
        elif s==1:
            peper[y][x] +=1
            peper[y+1][x] +=1
            peper[y-1][x] +=1
            peper[y][x+1] +=1
            peper[y][x-1] +=1
    except:
        co=0
        ma=0
        for i in range(2,12):
            for j in range(2,12):
                if peper[i][j]==0:
                    co +=1
                else:
                    ma=max(ma,peper[i][j])
        print(co)
        print(ma)
        break

Solution (Python):


paper = [[0] * 10 for i in range(10)]

def small(x, y):
    p = [[x, y]]
    for i, j in zip([-1, 0, 1, 0], [0, -1, 0, 1]):
        p.append([x + i, y + j])
    return p

def middle(x, y):
    p = small(x, y)
    for i, j in zip([1, -1, 1, -1], [1, 1, -1, -1]):
        p.append([x + i, y + j])
    return p

def big(x, y):
    p = middle(x, y)
    for i, j in zip([-2, 0, 2, 0], [0, -2, 0, 2]):
        p.append([x + i, y + j])
    return p

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

    if size == 1:
        bp = small(x, y)
    elif size == 2:
        bp = middle(x, y)
    elif size == 3:
        bp = big(x, y)
    for p in bp:
        if 0 <= p[0] < 10 and 0 <= p[1] < 10:
            paper[p[1]][p[0]] += 1

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

Solution (Python):



import sys

def printp():
  for q in p:
    print q

def if_in_paper(x,y):
  if 0 <= x and x < 10 and 0 <= y and y <10:
    return True
  else:
    return False

def pro(x,y,lis):
  for e in lis:
    px,py = x+e[0], y+e[1]
    if if_in_paper(px,py):
      p[py][px] += 1

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

small = [[0,0],[1,0],[0,1],[-1,0],[0,-1]]
midium = small + [[1,1],[1,-1],[-1,1],[-1,-1]]
large = midium + [[2,0],[0,2],[-2,0],[0,-2]]
water_list = [small,midium,large]

for s in sys.stdin:
  d = map(int,s.split(","))
  pro( d[0], d[1], water_list[ d[2]-1 ] )

print sum( [ 1 for i in range(10) for j in range(10) if p[i][j] == 0] )
print max( [ max(q) for q in p] )

Solution (Python):
import sys
f = sys.stdin

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

drop_range = {}
drop_range[1] = ((0, 0), (0, -1), (1, 0), (0, 1), (-1, 0))
drop_range[2] = drop_range[1] + ((-1, -1), (1, -1), (1, 1), (-1, 1))
drop_range[3] = drop_range[2] + ((0, -2), (2, 0), (0, 2), (-2, 0))

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

for line in f:
    x, y, size = map(int, line.split(','))
    
    for dx, dy in drop_range[size]:
        drop(paper, x + dx, y + dy)

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

Solution (Python):
p = [[0 for a in range(10)] for b in range(10)]
def smallink(x,y):
    return [(x+i,y+j) for i in range(-1,2,1) for j in range(-1,2,1)\
            if abs(i)+abs(j)<=1 and x+i>=0 and x+i<=9 and y+j>=0\
            and y+j<=9]
def ink(x,y):
    return [(x+i,y+j) for i in range(-1,2,1) for j in range(-1,2,1)\
            if x+i>=0 and y+j>=0 and x+i<=9 and y+j<=9]
def bigink(x,y):
    return [(x+i,y+j) for i in range(-2,3,1) for j in range(-2,3,1)\
            if abs(i)+abs(j)<=2 and x+i>=0 and y+j>=0 and x+i<=9\
            and y+j<=9]

while True:
    try:
        x,y,size=map(int,raw_input().split(","))
        if size==1:
            L=smallink(x,y)
        elif size==2:
            L=ink(x,y)
        else:
            L=bigink(x,y)
        while len(L)!=0:
            point=L.pop(0)
            p[point[0]][point[1]]+=1
    except:
        break

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

Solution (Python):
import sys
p = [[0 for a in range(10)] for b in range(10)]
def smallink(x,y):
    return [(x+i,y+j) for i in range(-1,2,1) for j in range(-1,2,1)\
            if abs(i)+abs(j)<=1 and x+i>=0 and x+i<=9 and y+j>=0\
            and y+j<=9]
def ink(x,y):
    return [(x+i,y+j) for i in range(-1,2,1) for j in range(-1,2,1)\
            if x+i>=0 and y+j>=0 and x+i<=9 and y+j<=9]
def bigink(x,y):
    return [(x+i,y+j) for i in range(-2,3,1) for j in range(-2,3,1)\
            if abs(i)+abs(j)<=2 and x+i>=0 and y+j>=0 and x+i<=9\
            and y+j<=9]
for dataset in sys.stdin:
    x,y,size=map(int,dataset.split(","))
    if size==1:
        L=smallink(x,y)
    elif size==2:
        L=ink(x,y)
    else:
        L=bigink(x,y)
    while len(L)!=0:
        point=L.pop(0)
        p[point[0]][point[1]]+=1

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

Solution (Python):
board = [[0]*10 for _ in range(10)]
while True:
    try:
        x, y, size = map(int, input().split(','))
    except:
        break
    small = [(-1, 0), (0, -1), (0, 0), (0, 1), (1, 0)]
    med = [(-1, -1), (-1, 0), (-1, 1),
           (0, -1), (0, 0), (0, 1),
           (1, -1), (1, 0), (1, 1)]
    large = [(-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)]
    dyx = [small, med, large][size-1]
    for dy, dx in dyx:
        ny, nx = y + dy, x + dx
        if 0 <= nx < 10 and 0 <= ny < 10:
            board[ny][nx] += 1

print(sum(sum(1 for i in range(10) if row[i] == 0) for row in board))
print(max([max(row) for row in board]))

Solution (Python):
def main():
    if size == 1:
        index_lis = [(0,0),(0,-1),(0,1),(-1,0),(1,0)]
    elif size == 2:
        index_lis = [(0,0),(0,-1),(0,1),(-1,-1),(-1,0),(-1,1),(1,-1),(1,0),(1,1)]
    elif size == 3:
        index_lis = [(0,0),(0,-1),(0,-2),(0,1),(0,2),(-1,-1),(-1,0),(-1,1),
                     (1,-1),(1,0),(1,1),(-2,0),(2,0)]
    drop(index_lis, x, y)
    
def drop(index_lis, x, y):
    for add_x, add_y in index_lis:
        _x = x + add_x
        _y = y + add_y
        if 0 <= _x <= 9 and 0 <= _y <= 9:
            sheet[_x][_y] = sheet[_x][_y] + 1
            
def check():
    total = 0
    max_num = 0
    for x in range(10):
        for y in range(10):
            if sheet[x][y] == 0:
                total += 1
            else:
                if sheet[x][y] > max_num:
                    max_num = sheet[x][y]
    print total
    print max_num

sheet = []
for i in range(10):
    lis = []
    for i in range(10):
        lis.append(0)
    sheet.append(lis)
    
while True:
    try:
        x, y, size = map(int, raw_input().split(','))
        main()
    except EOFError:
        check()
        break

Solution (Python):
import sys

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

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

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

def drop(paper, x, y, size):

    if size == 1:
        small(paper, x, y)
    elif size == 2:
        medium(paper, x, y)
    else:
        large(paper, x, y)

    return paper


paper = [[0 for i in range(14)] for j in range(14)]
for s in sys.stdin:
    x, y, size = map(int, s.split(','))
    paper = drop(paper, x+2, y+2, size)

empty = 0
deep = 0

for i in range(10):
    for j in range(10):
        if paper[i+2][j+2] == 0:
            empty += 1
        elif paper[i+2][j+2] > deep:
            deep = paper[i+2][j+2]

print(empty)
print(deep)

Solution (Python):


def check(x,i,y,j):
    flagx=True if (x+i>=0 and x+i<=9) else False
    flagy=True if (y+j>=0 and y+j<=9) else False

    return (flagx and flagy)

def main():
    LIST=[]
    for i in range(10):
        LIST.append([0,0,0,0,0,0,0,0,0,0])
        count=0
        M=0
    while True:
        try:
            x,y,size=map(int,input().split(","))
            if size==1:
                for i in range(-1,2):
                    for j in range(-1,2):
                        if check(x,i,y,j) and abs(i)+abs(j)<=1:
                            LIST[y+j][x+i]+=1

            elif size==2:
                for i in range(-1,2):
                    for j in range(-1,2):
                        if check(x,i,y,j) and abs(i)+abs(j)<=2:
                            LIST[y+j][x+i]+=1

            elif size==3:
                for i in range(-2,3):
                    for j in range(-2,3):
                        if check(x,i,y,j) and abs(i)+abs(j)<=2:
                            LIST[y+j][x+i]+=1
            
        except:
            break

    for item in LIST:
        tmp=max(x for x in item)
        M=max(tmp,M)

    for item in LIST:
        count+=item.count(0)

    print(count)
    print(M)
    
        
if __name__ == '__main__':
    main()

Solution (Python):



l=[[0]*10 for _ in range(10)]

while 1:
    try:
        x,y,s=map(int,raw_input().split(','))
        l[y][x]+=1
        syo=[[0,1],[0,-1],[1,0],[-1,0]]
        chu=[[1,1],[-1,-1],[1,-1],[-1,1]]
        dai=[[0,2],[0,-2],[2,0],[-2,0]]
        for i in syo:
            if 0<=y+i[0]<=9 and 0<=x+i[1]<=9:
                l[y+i[0]][x+i[1]]+=1
        if s>1:
            for i in chu:
                if 0<=y+i[0]<=9 and 0<=x+i[1]<=9:
                    l[y+i[0]][x+i[1]]+=1
        if s>2:
            for i in dai:
                if 0<=y+i[0]<=9 and 0<=x+i[1]<=9:
                    l[y+i[0]][x+i[1]]+=1


    except:
        break

a=b=0
for i in l:
    a+=i.count(0)
    b=max(b,max(i))
print a
print b

Solution (Python):
p = [[0 for i in range(14)] for j in range(14)]
c, m = 0, 0
while True:
    try:
        x, y, size = map(int,input().split(','))
    except:
        break
    x += 2
    y += 2
    p[x][y] += 1
    p[x - 1][y] += 1
    p[x + 1][y] += 1
    p[x][y - 1] += 1
    p[x][y + 1] += 1
    if size > 1:
        p[x - 1][y - 1] += 1
        p[x - 1][y + 1] += 1
        p[x + 1][y - 1] += 1
        p[x + 1][y + 1] += 1
        if size > 2:
            p[x - 2][y] += 1
            p[x + 2][y] += 1
            p[x][y - 2] += 1
            p[x][y + 2] += 1
for i in range(2, 12):
    for j in range(2, 12):
        if p[i][j] == 0:
            c += 1
        elif p[i][j] > m:
            m = p[i][j]
print(c)
print(m)

Solution (Python):
from __future__ import (absolute_import, division, print_function,
                        unicode_literals)
from sys import stdin
from collections import Counter
import sys
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 sys.stdin:
    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):


import sys

def small_inc(x, y, cells):
    cells[x][y] += 1
    if y > 0:
        cells[x][y-1] += 1
    if x > 0:
        cells[x-1][y] += 1
    if x < MAPSIZE-1:
        cells[x+1][y] += 1
    if y < MAPSIZE-1:
        cells[x][y+1] += 1

def medium_inc(x, y, cells):
    if y > 0:
        cells[x][y-1] += 1
        if x > 0:
            cells[x-1][y-1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y-1] += 1
    cells[x][y] += 1
    if x > 0:
        cells[x-1][y] += 1
    if x < MAPSIZE-1:
        cells[x+1][y] += 1
    if y < MAPSIZE-1:
        cells[x][y+1] += 1
        if x > 0:
            cells[x-1][y+1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y+1] += 1

def large_inc(x, y, cells):
    if y > 1:
        cells[x][y-2] += 1
    if y > 0:
        cells[x][y-1] += 1
        if x > 0:
            cells[x-1][y-1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y-1] += 1
    cells[x][y] += 1
    if x > 1:
        cells[x-2][y] += 1
    if x > 0:
        cells[x-1][y] += 1
    if x < MAPSIZE-1:
        cells[x+1][y] += 1
    if x < MAPSIZE-2:
        cells[x+2][y] += 1
    if y < MAPSIZE-1:
        cells[x][y+1] += 1
        if x > 0:
            cells[x-1][y+1] += 1
        if x < MAPSIZE-1:
            cells[x+1][y+1] += 1
    if y < MAPSIZE-2:
        cells[x][y+2] += 1

SMALL = 1
MEDIUM = 2
LARGE = 3
MAPSIZE = 10

cells = [[0 for i in range(MAPSIZE)] for j in range(MAPSIZE)]
for line in sys.stdin:
    x , y, size = map(int, line.split(','))
    if size == SMALL:
        small_inc(x, y, cells)
    elif size == MEDIUM:
        medium_inc(x, y, cells)
    elif size == LARGE:
        large_inc(x, y, cells)
count = max_d = 0
for i in range(MAPSIZE):
    for j in range(MAPSIZE):
        if cells[i][j] == 0:
            count += 1
        else:
            max_d = max(max_d, cells[i][j])
print count
print max_d

Solution (Python):
class Paper:
    def __init__(self, x, y):
        
        self.A = [[0 for i in range(x)] for j in range(y)]
        self.size = (x, y)
    def drop(self, x, y, s):
        if s == 1:
            if y+1 <= self.size[1]-1:
                self.A[y+1][x] += 1            
            for i in range(max(0, x-1) , 1 + min(self.size[0]-1, x+1)):
                self.A[y][i] += 1
            if y-1 >= 0:
                self.A[y-1][x] += 1

        if s == 2:
            if y+1 <= self.size[1]-1:
                for i in range(max(0, x-1) , 1 + min(self.size[0]-1, x+1)):
                    self.A[y+1][i] += 1
            for i in range(max(0, x-1) , 1 + min(self.size[0]-1, x+1)):
                self.A[y][i] += 1
            if y-1 >= 0:
                for i in range(max(0, x-1) , 1 + min(self.size[0]-1, x+1)):
                    self.A[y-1][i] += 1

        if s == 3:
            if y+2 <= self.size[1]-1:
                self.A[y+2][x] += 1
            if y+1 <= self.size[1]-1:
                for i in range(max(0, x-1) , 1 + min(self.size[0]-1, x+1)):
                    self.A[y+1][i] += 1
            for i in range(max(0, x-2) , 1 + min(self.size[0]-1, x+2)):
                self.A[y][i] += 1
            if y-1 >= 0:
                for i in range(max(0, x-1) , 1 + min(self.size[0]-1, x+1)):
                    self.A[y-1][i] += 1
            if y-2 >= 0:
                self.A[y-2][x] += 1

if __name__ == "__main__":
    import sys 
    p = Paper(10, 10)
    L = sys.stdin.readlines()
    for l in L:
        x, y, s = map(int, l.split(','))
        p.drop(x, y, s)



    temp = []
    for y in p.A:
        temp.extend(y)

    A1 = temp.count(0)
    A2 = max(temp)

    print(A1)
    print(A2)

Solution (Python):
paper=[[-float('inf')]*14]*2+[[-float('inf')]*2+[0]*10+[-float('inf')]*2 for _ in xrange(10)]+[[-float('inf')]*14]*2
while 1:
    try:
        x,y,size=map(int,raw_input().split(","))
        x+=2
        y+=2
        paper[x][y]+=1
        paper[x+1][y]+=1
        paper[x-1][y]+=1
        paper[x][y+1]+=1
        paper[x][y-1]+=1
        if size>=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
            if size==3:
                paper[x+2][y]+=1
                paper[x-2][y]+=1
                paper[x][y+2]+=1
                paper[x][y-2]+=1
    except:
        break
ct0=0
maxpaper=0
for i in xrange(14):
    for j in xrange(14):
        if paper[i][j]==0:
            ct0+=1
        if maxpaper<paper[i][j]:
            maxpaper=paper[i][j]
print(ct0)
print(maxpaper)

Solution (Python):
d = [[0] * 10 for i in range(10)]

def b(x, y):
    for i in range(x - 2, x + 3):
        a = 3 - abs(x - i)
        for a in range(y - a + 1, y + a):
            if 0 <= i < 10 and 0 <= a < 10:
                d[a][i] += 1


def m(x, y):
    for i in range(x - 1, x + 2):
        for j in range(y - 1, y + 2):
            if 0 <= i < 10 and 0 <= j < 10:
                d[j][i] += 1


def s(x, y):
    r = (1, 0)
    for i in range(x - 1, x + 2):
        a = abs(x - i)
        for j in range(y - r[a], y + r[a] + 1):
            if 0 <= i < 10 and 0 <= j < 10:
                d[j][i] += 1

while 1:
    try:
        f = (None, s, m, b)
        x, y, size = list(map(int, input().split(',')))
        f[size](x, y)
    except:
        break


r1 = r2 = 0
for i in range(10):
    for j in range(10):
        r1 += 1 if d[i][j] == 0 else 0
        r2 = max(r2, d[i][j])

print(r1)
print(r2)

Solution (Python):
masu = [[0 for x in range(10)] for y in range(10)]

syou = [[-1,0], [0,-1], [0,0], [0,1], [1,0]]
tyuu = [[-1,-1], [-1,1], [1,-1], [1,1]] + syou
dai = [[-2,0], [0,-2], [0,2], [2,0]] + tyuu



def drop(x,y,s):
	if s == 1: l = syou
	elif s == 2: l = tyuu
	elif s == 3: l = dai

	for dx,dy in l:
		nx = x + dx
		ny = y + dy
		if nx in range(10) and ny in range(10):
			masu[ny][nx] += 1



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

max = cnt = 0
for y in range(10):
	for x in range(10):
		if masu[y][x] == 0: cnt += 1
		if max < masu[y][x]: max = masu[y][x]

print(cnt)
print(max)

Solution (Python):
a = [[0] * 14 for _ in range(14)]
while True:
    try:
        x, y, s = map(int, input().split(','))
    except:
        break
    x += 2
    y += 2
    for d in [(0, 0), (0, -1), (0, 1), (-1, 0), (1, 0)]:
        a[x + d[0]][y + d[1]] += 1
    if s >= 2:
        for d in [(1, 1), (1, -1), (-1, 1), (-1, -1)]:
            a[x + d[0]][y + d[1]] += 1
    if s == 3:
        for d in [(0, 2), (0, -2), (2, 0), (-2, 0)]:
            a[x + d[0]][y + d[1]] += 1
print(sum(a[i][2:12].count(0) for i in range(2, 12)))
print(max(max(a[i][2:12]) for i in range(2, 12)))

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

def drop(x, y, s):
    r = []
    d = [[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 d[0:s*4]:
        if min(i) >= 0 and max(i) < 10: r.append(i)
    p[x][y] += 1
    for i in r:
        p[i[0]][i[1]] += 1

while 1:
    try:
        x, y, s = map(int, raw_input().split(','))
        drop(x, y, s)
    except:
        break

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

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

def drop(x, y, s):
    d = [[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 d[0:s*4]:
        if min(i) >= 0 and max(i) < 10: p[i[0]][i[1]] += 1
    p[x][y] += 1

while 1:
    try:
        x, y, s = map(int, raw_input().split(','))
        drop(x, y, s)
    except:
        break

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

Solution (Python):
import sys

drops = [None,
         [(0,0),(-1,0),(1,0),(0,-1),(0,1)],
         [(0,0),(-1,0),(1,0),(0,-1),(0,1),(-1,1),(-1,-1),(1,-1),(1,1)],
         [(0,0),(-1,0),(1,0),(0,-1),(0,1),(-1,1),(-1,-1),(1,-1),(1,1),(-2,0),(2,0),(0,-2),(0,2)]]

B = [[0 for j in xrange(10)] for i in xrange(10)]

for line in sys.stdin:
    x, y, s = map(int, line.rstrip().split(','))
    for dx, dy in drops[s]:
        nx, ny = x+dx, y+dy
        if (0 <= nx <= 9 and 0 <= ny <= 9):
            B[ny][nx] += 1

emp, m = 0, 0
for i in xrange(10):
    for j in xrange(10):
        if B[i][j] == 0:
            emp += 1
        m = max(m, B[i][j])
print emp
print m

Solution (Python):
import sys

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


def ink(x, y, s):
    for dx, dy in ((0, 0), (0, 1), (1, 0), (-1, 0), (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), (0, 2), (-2, 0), (0, -2)):
        plot(x + dx, y + dy)


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

for line in sys.stdin:
    x, y, s = map(int, line.split(','))
    ink(x, y, s)
print(sum(field, []).count(0))
print(max(sum(field, [])))

Solution (Python):
Masu = []
def access(x,y):
    if x < 0 or y < 0 or x > 9 or y > 9:
        return
    Masu[y][x] += 1

for i in range(10):
    Masu.append([0,0,0,0,0,0,0,0,0,0])
kosu = 0
komax = 0
while True:
    try:
        
        x,y,s = map(int,input().split(","))
        if s == 1:
            for j in range(3):
                access(y +1 - j,x)
            access(y,x - 1)
            access(y,x + 1)

        elif s == 2:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
        elif s == 3:
            for k in range(3):
                for l in range(3):
                    access(y + 1 - k,x + 1 -l)
            access(y - 2,x)
            access(y + 2,x)
            access(y,x + 2)
            access(y,x - 2)
               
    except (EOFError,ValueError):
        for i in range(10):
            kosu += Masu[i].count(0)
        for j in range(10):
            if komax < max(Masu[j]):
                komax = max(Masu[j])
        print(kosu)
        print(komax)
        break

Solution (Python):
import sys


class Paper(object):
    def __init__(self, x=None, y=None):
        if x == None:
            self.x = 10
        else:
            self.x = x
        if y == None:
            self.y = 10
        else:
            self.y = y
        t = [0] * self.x
        self.sheet = [t[:] for _ in range(self.y)]

    def drop_ink(self, ink):
        x, y, s = ink
        if s == 1:
            self.process_ink(x, y)
            self.process_ink(x+1, y)
            self.process_ink(x-1, y)
            self.process_ink(x, y+1)
            self.process_ink(x, y-1)
        elif s == 2:
            self.process_ink(x-1, y-1)
            self.process_ink(x, y-1)
            self.process_ink(x+1, y-1)
            self.process_ink(x-1, y)
            self.process_ink(x, y)
            self.process_ink(x+1, y)
            self.process_ink(x-1, y+1)
            self.process_ink(x, y+1)
            self.process_ink(x+1, y+1)
        elif s == 3:
            self.process_ink(x, y-2)
            self.process_ink(x-1, y-1)
            self.process_ink(x, y-1)
            self.process_ink(x+1, y-1)
            self.process_ink(x-2, y)
            self.process_ink(x-1, y)
            self.process_ink(x, y)
            self.process_ink(x+1, y)
            self.process_ink(x+2, y)
            self.process_ink(x-1, y+1)
            self.process_ink(x, y+1)
            self.process_ink(x+1, y+1)
            self.process_ink(x, y+2)

    def process_ink(self, x, y):
        if 0 <= x < self.x and 0 <= y < self.y:
            self.sheet[y][x] += 1

    def print_sheet(self):
        for row in self.sheet:
            print(row)


if __name__ == '__main__':
    ink_drops = []
    for line in sys.stdin:
        ink_drops.append([int(x) for x in line.strip().split(',')])







    p = Paper(10, 10)
    for ink in ink_drops:
        p.drop_ink(ink)
        
        

    white_cell = 0
    max_ink = 0
    for r in p.sheet:
        white_cell += r.count(0)
        max_ink = max(max(r), max_ink)
    print(white_cell)
    print(max_ink)

Solution (Python):

board=[[0]*10 for i in range(10)]
ink=[[[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]],
[[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]],
[[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 True:
    try:
        x,y,s=map(int,input().split(","))
    except:
        break
    for i in range(5):
        for j in range(5):
            if 0<=i+y-2<=9 and 0<=j+x-2<=9:
                board[i+y-2][j+x-2]+=ink[s-1][i][j]
    
flat=sum(board,[])
print(flat.count(0))
print(max(flat))

Solution (Python):
a = [[0 for i2 in range(10)] for i1 in range(10)]

def small_ink(x,y):
    a[x][y] += 1
    a[x-1][y] += 1
    try:
        a[x+1][y] += 1
    except:
        pass
    a[x][y-1] += 1
    try:
        a[x][y+1] += 1
    except:
        pass
    if x-1 < 0:
        a[x-1][y] -= 1
    if y-1 < 0:
        a[x][y-1] -= 1
    return 0

def mid_ink(x,y):
    for i in [-1,0,1]:
        for j in [-1,0,1]:
            if 9 >= x+i >= 0 and 9>= y+j >= 0:
                a[x+i][y+j] += 1
    return 0

def big_ink(x,y):
    mid_ink(x,y)
    a[x-2][y] += 1
    try:
        a[x+2][y] += 1
    except:
        pass
    a[x][y-2] += 1
    try:
        a[x][y+2] += 1
    except:
        pass
    if x-2 < 0:
        a[x-2][y] -= 1
    if y-2 < 0:
        a[x][y-2] -= 1
    return 0

def ink(x,y,s):
    if s == 1:
        small_ink(x,y)
    if s == 2:
        mid_ink(x,y)
    if s == 3:
        big_ink(x,y)
    return 0

while True:
    try:
        x,y,s = map(int,input().split(','))
        ink(x,y,s)
    except EOFError:
        break
nu = 0
for i in range(10):
    for j in range(10):
        if a[i][j] == 0:
            nu += 1
print(nu)
max_val = 0
for i in range(10):
    for j in range(10):
        if a[i][j] > max_val:
            max_val = a[i][j]
print(max_val)

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

while True:
    try:
        x,y,s = map(int,input().split(','))
    except:
        break
    if s == 1:
        for i in range(10):
            for j in range(10):
                if abs(x - i) + abs(y - j) <= 1:
                    paper [i] [j] += 1
    elif s == 2:
        for i in range(10):
            for j in range(10):
                if abs(x - i) <= 1 and abs(y - j) <= 1:
                    paper [i] [j] += 1
    else:
        for i in range(10):
            for j in range(10):
                if abs(x - i) + abs(y - j) <= 2:
                    paper [i] [j] += 1

ls = sum(paper,[])
print(ls.count(0))
print(max(ls))

Solution (Python):
pap = [[0 for x in range(10)] for y in range(10)]

def brot(x,y,s):
    if s==1:
        for dx in range(-1,+1+1):
            for dy in range(-1,+1+1):
                px = x + dx    
                py = y + dy
                if abs(dx)+abs(dy)<2 and px in range(0,10) and py in range(0,10):
                    pap[py][px] += 1
    elif s==2:
        for dx in range(-1,+1+1):
            for dy in range(-1,+1+1):
                px = x + dx    
                py = y + dy
                if px in range(0,10) and py in range(0,10):
                    pap[py][px] += 1
    elif s==3:
        for dx in range(-2,+2+1):
            for dy in range(-2,+2+1):
                px = x + dx    
                py = y + dy
                if abs(dx)+abs(dy)<3 and px in range(0,10) and py in range(0,10):
                    pap[py][px] += 1
    else:
        raise(ValueError) 

def ans():
    bmax = 0
    wcount = 0
    for y in range(0,+9+1):
        for x in range(0,+9+1):
            b = pap[y][x]
            if b > bmax:
                bmax = b
            elif b == 0:
                wcount += 1
    return(wcount,bmax)

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

print("%d\n%d" % ans())

Solution (Python):
pap = [[0 for x in range(10)] for y in range(10)]
ink = [ [],
        [[-1,0],[0,-1],[0,0],[0,1],[1,0]],
        [[-1,-1],[-1,0],[-1,1],[0,-1],[0,0],[0,1],[1,-1],[1,0],[1,1]],
        [[-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]] ]

def brot(x,y,s):
    global pap
    for i in ink[s]:
        px = x + i[0]    
        py = y + i[1]
        if px in range(0,10) and py in range(0,10):
            pap[py][px] += 1

def ans():
    bmax = max(pap[y][x] for y in range(10) for x in range(10))
    wcount = sum(pap[y][x] == 0 for y in range(10) for x in range(10))
    return(wcount,bmax)

if __name__ == "__main__":
    while True:
        try:
            x,y,s = list(map(int, input().split(',')))
            brot(x,y,s)
        except EOFError:
            break

    print("%d\n%d" % ans())

Solution (Python):
arr = [0]*100
while True:
    try:
        x,y,s = map(int, input().split(","))
        if s==3:
            if x <= 7:
                arr[10*y+x+2] += 1
            if x >= 2:
                arr[10*y+x-2] += 1
            if y <= 7:
                arr[10*y+x+20] += 1
            if y >= 2:
                arr[10*y+x-20] += 1
        if s>=2:
            if x != 9 and y != 9:
                arr[10*y+x+11] += 1
            if x != 9 and y != 0:
                arr[10*y+x-9] += 1
            if x != 0 and y != 0:
                arr[10*y+x-11] += 1
            if x != 0 and y != 9:
                arr[10*y+x+9] += 1
        if True:
            if x != 9:
                arr[10*y+x+1] += 1
            if x != 0:
                arr[10*y+x-1] += 1
            if y != 9:
                arr[10*y+x+10] += 1
            if y != 0:
                arr[10*y+x-10] += 1
        if True:
            if True:
                arr[10*y+x] += 1

    except EOFError:
        break

print(arr.count(0))
print(max(arr))