R, C, K = map(int, input().split())
values = [[0] * C for i in range(R)]
for i in range(K):
	r, c, v = map(int, input().split())
	values[r - 1][c - 1] = v

dp = [[[0] * C for i in range(R)] for j in range(4)]

dp[1][0][0] = values[0][0]

for i in range(R):
	for j in range(C):
		if values[i][j] == 0:
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		else:
			#取る
			if j != 0:
				for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			if i != 0:
				for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])

ans = 0
for k in range(4):
	ans = max(ans, dp[k][-1][-1])
print(ans) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0] * C for i in range(R) for i in range(R) i range(R) range R for i in range(R) [0] * C [0] 0 C values = [[0] * C for i in range(R)] values [[0] * C for i in range(R)] for i in range(K):
	r, c, v = map(int, input().split())
	values[r - 1][c - 1] = v i range(K) range K r, c, v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c v values[r - 1][c - 1] = v values[r - 1][c - 1] [r - 1] values r - 1 r 1 c - 1 c 1 v [[0] * C for i in range(R)] for j in range(4) for j in range(4) j range(4) range 4 for j in range(4) [[0] * C for i in range(R)] dp = [[[0] * C for i in range(R)] for j in range(4)] dp [[[0] * C for i in range(R)] for j in range(4)] dp[1][0][0] = values[0][0] dp[1][0][0] [0] [1] dp 1 0 0 values[0][0] [0] values 0 0 for i in range(R):
	for j in range(C):
		if values[i][j] == 0:
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		else:
			#取る
			if j != 0:
				for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			if i != 0:
				for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) i range(R) range R for j in range(C):
		if values[i][j] == 0:
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		else:
			#取る
			if j != 0:
				for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			if i != 0:
				for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) j range(C) range C if values[i][j] == 0:
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		else:
			#取る
			if j != 0:
				for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			if i != 0:
				for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) values[i][j] == 0 values[i][j] [i] values i j 0 if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			 j != 0 j 0 for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			 k range(4) range 4 dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k][i][j - 1]) max dp[k][i][j] [i] [k] dp k i j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		 i != 0 i 0 for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		 k range(4) range 4 dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j], dp[k][i - 1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[k][i - 1][j] [i - 1] [k] dp k i - 1 i 1 j if j != 0:
				for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			 j != 0 j 0 for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			 k range(1, 4) range 1 4 dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j]) max dp[k][i][j] [i] [k] dp k i j dp[k - 1][i][j - 1] + values[i][j] dp[k - 1][i][j - 1] [i] [k - 1] dp k - 1 k 1 i j - 1 j 1 values[i][j] [i] values i j if i != 0:
				for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			 i != 0 i 0 for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			 k range(4) range 4 dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j]) dp[1][i][j] [i] [1] dp 1 i j max(dp[1][i][j], dp[k][i - 1][j] + values[i][j]) max dp[1][i][j] [i] [1] dp 1 i j dp[k][i - 1][j] + values[i][j] dp[k][i - 1][j] [i - 1] [k] dp k i - 1 i 1 j values[i][j] [i] values i j if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			 j != 0 j 0 for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			 k range(4) range 4 dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1]) dp[k][i][j] [i] [k] dp k i j max(dp[k][i][j], dp[k][i][j - 1]) max dp[k][i][j] [i] [k] dp k i j dp[k][i][j - 1] [i] [k] dp k i j - 1 j 1 if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) i != 0 i 0 for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) k range(4) range 4 dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j]) dp[0][i][j] [i] [0] dp 0 i j max(dp[0][i][j], dp[k][i - 1][j]) max dp[0][i][j] [i] [0] dp 0 i j dp[k][i - 1][j] [i - 1] [k] dp k i - 1 i 1 j ans = 0 ans 0 for k in range(4):
	ans = max(ans, dp[k][-1][-1]) k range(4) range 4 ans = max(ans, dp[k][-1][-1]) ans max(ans, dp[k][-1][-1]) max ans dp[k][-1][-1] [-1] [k] dp k -1 -1 print(ans) print ans K = map(int, input().split()) map(int, input().split()) K v = map(int, input().split()) map(int, input().split()) v r, c, v = map(int, input().split()) map(int, input().split()) r ans = max(ans, dp[k][-1][-1]) max(ans, dp[k][-1][-1]) ans dp = [[[0] * C for i in range(R)] for j in range(4)] [[[0] * C for i in range(R)] for j in range(4)] dp C, K = map(int, input().split()) map(int, input().split()) C values = [[0] * C for i in range(R)] [[0] * C for i in range(R)] values R, C, K = map(int, input().split()) map(int, input().split()) R c, v = map(int, input().split()) map(int, input().split()) c ans = 0 0 ans
R, C, K = map(int, input().split())
values = [[0] * C for i in range(R)]
for i in range(K):
	r, c, v = map(int, input().split())
	values[r - 1][c - 1] = v

dp = [[[0] * C for i in range(R)] for j in range(4)]

dp[1][0][0] = values[0][0]

for i in range(R):
	for j in range(C):
		if values[i][j] == 0:
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])
		else:
			#取る
			if j != 0:
				for k in range(1, 4):
					dp[k][i][j] = max(dp[k][i][j], dp[k - 1][i][j - 1] + values[i][j])
			if i != 0:
				for k in range(4):
					dp[1][i][j] = max(dp[1][i][j], dp[k][i - 1][j] + values[i][j])
			#取らん
			if j != 0:
				for k in range(4):
					dp[k][i][j] = max(dp[k][i][j], dp[k][i][j - 1])
			if i != 0:
				for k in range(4):
					dp[0][i][j] = max(dp[0][i][j], dp[k][i - 1][j])

ans = 0
for k in range(4):
	ans = max(ans, dp[k][-1][-1])
print(ans)