m,n,h=map(int,input().split())#牆壁-1 木樁1 線2 地板0 重複線3
d1=[1,0,0,-1]#列
d2=[0,1,-1,0]#行 下右左上
area=0
ans=[]
uni=False
good=[[-1]*(n+2)]
for k in range(m):
good.append([-1]+[0]*n+[-1])
good.append([-1]*(n+2))
for b in range(h):
r,c,t=map(int,input().split())
if t==0:
w=r+1
e=c+1
if good[r+1][c+1]==2 or good[r+1][c+1]==3:
for g in range(4):
k=r+1
p=c+1
while good[k][p]!=-1 and good[k][p]!=1:
k+=d1[g]
p+=d2[g]
if good[k][p]==1:
uni=True
elif good[k][p]==0 and uni==False:
continue
if uni==False:
continue
while good[w][e]==2 or good[w][e]==3:
if good[w][e]==2:
good[w][e]=0
elif good[w][e]==3:
good[w][e]==2
w+=d1[g]
e+=d2[g]
w=r+1
e=c+1
good[w][e]=2
uni=False
good[r+1][c+1]=0
for i in range(4):
k=r+1
p=c+1
while good[k][p]!=-1 and good[k][p]!=1:
k+=d1[i]
p+=d2[i]
if good[k][p]==1:
uni=True
if uni==False:
continue
w=r+1
e=c+1
while (good[w][e]==0 or good[w][e]==2 or good[w][e]==3) and good[w][e]!=-1:
if good[w][e]==0:
good[w][e]=2
elif good[w][e]==2:
good[w][e]=3
w+=d1[i]
e+=d2[i]
w=r+1
e=c+1
good[r+1][c+1]=0
uni=False
good[r+1][c+1]=1
for l in range(m+2):
for p in range(n+2):
if good[l][p]==1 or good[l][p]==2 or good[l][p]==3:
area+=1
ans.append(area)
area=0
elif t==1:
w=r+1
e=c+1
good[r+1][c+1]=2
for o in range(4):
k=r+1
p=c+1
while good[k][p]!=-1 and good[k][p]!=1:
k+=d1[o]
p+=d2[o]
if good[k][p]==1:
uni=True
elif good[k][p]==0 and uni==False:
continue
if uni==False:
continue
while good[w][e]==2 or good[w][e]==3:
if good[w][e]==2:
good[w][e]=0
elif good[w][e]==3:
good[w][e]=2
w+=d1[o]
e+=d2[o]
w=r+1
e=c+1
good[w][e]=2
uni=False
good[r+1][c+1]=0
for l in range(m+2):
for p in range(n+2):
if good[l][p]==1 or good[l][p]==2 or good[l][p]==3:
area+=1
ans.append(area)
area=0
print(max(ans))
print(ans[-1])