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

for h in range(R):
    for w in range(C):
        if h!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w])
            dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w])
        if w!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1])
            dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w])
            dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w])
            dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w])
ans = []
for k in range(4):
    ans.append(dp[k][-1][-1])
print(max(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 _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C item = [[0]*C for _ in range(R)] item [[0]*C for _ in range(R)] for _ in range(K):
    r, c, v = map(int, input().split())
    item[r-1][c-1] = v _ 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 item[r-1][c-1] = v item[r-1][c-1] [r-1] item r-1 r 1 c-1 c 1 v [[0]*C for _ in range(R)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*C for _ in range(R)] dp = [[[0]*C for _ in range(R)] for _ in range(4)] dp [[[0]*C for _ in range(R)] for _ in range(4)] dp[1][0][0] = item[0][0] dp[1][0][0] [0] [1] dp 1 0 0 item[0][0] [0] item 0 0 for h in range(R):
    for w in range(C):
        if h!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w])
            dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w])
        if w!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1])
            dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w])
            dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w])
            dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) h range(R) range R for w in range(C):
        if h!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w])
            dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w])
        if w!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1])
            dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w])
            dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w])
            dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) w range(C) range C if h!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w])
            dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w])
         h!=0 h 0 dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w]) dp[0][h][w] [h] [0] dp 0 h w max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w]) max dp[0][h][w] [h] [0] dp 0 h w dp[0][h-1][w] [h-1] [0] dp 0 h-1 h 1 w dp[1][h-1][w] [h-1] [1] dp 1 h-1 h 1 w dp[2][h-1][w] [h-1] [2] dp 2 h-1 h 1 w dp[3][h-1][w] [h-1] [3] dp 3 h-1 h 1 w dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w]) dp[1][h][w] [h] [1] dp 1 h w max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w]) max dp[1][h][w] [h] [1] dp 1 h w dp[0][h-1][w]+item[h][w] dp[0][h-1][w] [h-1] [0] dp 0 h-1 h 1 w item[h][w] [h] item h w dp[1][h-1][w]+item[h][w] dp[1][h-1][w] [h-1] [1] dp 1 h-1 h 1 w item[h][w] [h] item h w dp[2][h-1][w]+item[h][w] dp[2][h-1][w] [h-1] [2] dp 2 h-1 h 1 w item[h][w] [h] item h w dp[3][h-1][w]+item[h][w] dp[3][h-1][w] [h-1] [3] dp 3 h-1 h 1 w item[h][w] [h] item h w if w!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1])
            dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w])
            dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w])
            dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) w!=0 w 0 dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1]) dp[0][h][w] [h] [0] dp 0 h w max(dp[0][h][w], dp[0][h][w-1]) max dp[0][h][w] [h] [0] dp 0 h w dp[0][h][w-1] [h] [0] dp 0 h w-1 w 1 dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w]) dp[1][h][w] [h] [1] dp 1 h w max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w]) max dp[1][h][w] [h] [1] dp 1 h w dp[1][h][w-1] [h] [1] dp 1 h w-1 w 1 dp[0][h][w-1]+item[h][w] dp[0][h][w-1] [h] [0] dp 0 h w-1 w 1 item[h][w] [h] item h w dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w]) dp[2][h][w] [h] [2] dp 2 h w max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w]) max dp[2][h][w] [h] [2] dp 2 h w dp[2][h][w-1] [h] [2] dp 2 h w-1 w 1 dp[1][h][w-1]+item[h][w] dp[1][h][w-1] [h] [1] dp 1 h w-1 w 1 item[h][w] [h] item h w dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) dp[3][h][w] [h] [3] dp 3 h w max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w]) max dp[3][h][w] [h] [3] dp 3 h w dp[3][h][w-1] [h] [3] dp 3 h w-1 w 1 dp[2][h][w-1]+item[h][w] dp[2][h][w-1] [h] [2] dp 2 h w-1 w 1 item[h][w] [h] item h w ans = [] ans [] for k in range(4):
    ans.append(dp[k][-1][-1]) k range(4) range 4 ans.append(dp[k][-1][-1]) ans.append ans append dp[k][-1][-1] [-1] [k] dp k -1 -1 print(max(ans)) print max(ans) max ans R, C, K = map(int, input().split()) map(int, input().split()) R r, c, v = map(int, input().split()) map(int, input().split()) r item = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] item K = map(int, input().split()) map(int, input().split()) K C, K = map(int, input().split()) map(int, input().split()) C ans = [] [] ans c, v = map(int, input().split()) map(int, input().split()) c dp = [[[0]*C for _ in range(R)] for _ in range(4)] [[[0]*C for _ in range(R)] for _ in range(4)] dp v = map(int, input().split()) map(int, input().split()) v
R, C, K = map(int, input().split())
item = [[0]*C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, input().split())
    item[r-1][c-1] = v
dp = [[[0]*C for _ in range(R)] for _ in range(4)]
dp[1][0][0] = item[0][0]

for h in range(R):
    for w in range(C):
        if h!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h-1][w], dp[1][h-1][w],  dp[2][h-1][w],  dp[3][h-1][w])
            dp[1][h][w] = max(dp[1][h][w], dp[0][h-1][w]+item[h][w], dp[1][h-1][w]+item[h][w], dp[2][h-1][w]+item[h][w], dp[3][h-1][w]+item[h][w])
        if w!=0:
            dp[0][h][w] = max(dp[0][h][w], dp[0][h][w-1])
            dp[1][h][w] = max(dp[1][h][w], dp[1][h][w-1], dp[0][h][w-1]+item[h][w])
            dp[2][h][w] = max(dp[2][h][w], dp[2][h][w-1], dp[1][h][w-1]+item[h][w])
            dp[3][h][w] = max(dp[3][h][w], dp[3][h][w-1], dp[2][h][w-1]+item[h][w])
ans = []
for k in range(4):
    ans.append(dp[k][-1][-1])
print(max(ans))