Type: Default 1000ms 512MiB

躲避导弹

You cannot submit for this problem because the contest is ended. You can click "Open in Problem Set" to view this problem in normal mode.

Problem Description

有一个r×cr×c的棋盘(右上角为(r,cr,c)),ShenChuanShenChuan从(0,0)出发,每秒能往四个方向运动一格,每隔一段时间就会有一颗导弹落下来,这颗导弹会毁坏降落的方块和相邻4个方块。

现在想知道ShenChuanShenChuan能走到离出发点的最远距离所需要的最短时间。

Input Format

三个整数$r,c,n(1\leq r \leq500,1\leq c \leq500,1\leq n \leq500)$,表示会降落nn个导弹。

接下来nn行,每行三个整数,xx,yy,tt,第i行表示第i颗导弹在第tit_i秒降落在(xi,yi)(x_i,y_i)。

(1≤x≤500,1≤y≤500,1≤t≤500)(1\leq x \leq500,1\leq y \leq500,1\leq t \leq500)

Output Format

仅一行,一个整数,代表答案。

Sample

输入样例1

2 2 0

输出样例1

4

输入样例2

2 2 1
1 1 1

输出样例2

0

Hint

1≤r≤500,1≤c≤500,1≤n≤5001\leq r \leq500,1\leq c \leq500,1\leq n \leq500

1≤x≤500,1≤y≤500,1≤t≤5001\leq x \leq500,1\leq y \leq500,1\leq t \leq500