R,C,K = map(int,input().split())

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

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for h in range(R+1):
    for w in range(C+1):
        for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1])

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 + 1) for _ in range(R + 1) for _ in range(R + 1) _ range(R + 1) range R + 1 R 1 for _ in range(R + 1) [0] * (C + 1) [0] 0 C + 1 C 1 item = [[0] * (C + 1) for _ in range(R + 1)] item [[0] * (C + 1) for _ in range(R + 1)] for i in range(K):
    r,c,v = map(int,input().split())
    item[r][c] = 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 item[r][c] = v item[r][c] [r] item r c v [[0]*(C+1) for _ in range(R+1)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*(C+1) for _ in range(R+1)] dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] dp [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] for h in range(R+1):
    for w in range(C+1):
        for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) h range(R+1) range R+1 R 1 for w in range(C+1):
        for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) w range(C+1) range C+1 C 1 for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) k range(4) range 4 position = dp[k][h][w] position dp[k][h][w] [h] [k] dp k h w if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
             h+1 <= R h+1 h 1 R dp[0][h+1][w] = max(dp[0][h+1][w], position) dp[0][h+1][w] [h+1] [0] dp 0 h+1 h 1 w max(dp[0][h+1][w], position) max dp[0][h+1][w] [h+1] [0] dp 0 h+1 h 1 w position dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w]) dp[1][h+1][w] [h+1] [1] dp 1 h+1 h 1 w max(dp[1][h+1][w], position+item[h+1][w]) max dp[1][h+1][w] [h+1] [1] dp 1 h+1 h 1 w position+item[h+1][w] position item[h+1][w] [h+1] item h+1 h 1 w if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) w+1 <= C w+1 w 1 C dp[k][h][w+1] = max(dp[k][h][w+1], position) dp[k][h][w+1] [h] [k] dp k h w+1 w 1 max(dp[k][h][w+1], position) max dp[k][h][w+1] [h] [k] dp k h w+1 w 1 position if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) k < 3 k 3 dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1]) dp[k+1][h][w+1] [h] [k+1] dp k+1 k 1 h w+1 w 1 max(dp[k+1][h][w+1], position+item[h][w+1]) max dp[k+1][h][w+1] [h] [k+1] dp k+1 k 1 h w+1 w 1 position+item[h][w+1] position item[h][w+1] [h] item h w+1 w 1 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 C,K = map(int,input().split()) map(int,input().split()) C r,c,v = map(int,input().split()) map(int,input().split()) r v = map(int,input().split()) map(int,input().split()) v c,v = map(int,input().split()) map(int,input().split()) c R,C,K = map(int,input().split()) map(int,input().split()) R item = [[0] * (C + 1) for _ in range(R + 1)] [[0] * (C + 1) for _ in range(R + 1)] item K = map(int,input().split()) map(int,input().split()) K dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)] dp position = dp[k][h][w] dp[k][h][w] position ans = max(ans, dp[k][-1][-1]) max(ans, dp[k][-1][-1]) ans ans = 0 0 ans
R,C,K = map(int,input().split())

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

dp = [[[0]*(C+1) for _ in range(R+1)] for _ in range(4)]

for h in range(R+1):
    for w in range(C+1):
        for k in range(4):
            position = dp[k][h][w]
            if h+1 <= R:
                # 移動先のアイテムを取らない場合
                dp[0][h+1][w] = max(dp[0][h+1][w], position)
                 # 移動先のアイテムを取る場合
                dp[1][h+1][w] = max(dp[1][h+1][w], position+item[h+1][w])
            if w+1 <= C:
                # 移動先のアイテムを取らない場合
                dp[k][h][w+1] = max(dp[k][h][w+1], position)
                # 現在のkが3未満のときのみ, 移動先のアイテムを取ることが可能
                if k < 3:
                    dp[k+1][h][w+1] = max(dp[k+1][h][w+1], position+item[h][w+1])

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

print(ans)