R, C, K = map(int, input().split())
item = {}
for _ in range(K):
    r, c, v = map(int, input().split())
    item[(r, c)] = v

dp = [[0] * 4 for _ in range(3010)]
ndp = [[0] * 4 for _ in range(3010)]
for r in range(1, R+1):
    for c in range(1, C+1):
        prer = max(dp[c])
        ndp[c][0] = max(prer, ndp[c-1][0])
        ndp[c][1] = max(prer, ndp[c-1][1])
        ndp[c][2] = max(prer, ndp[c-1][2])
        ndp[c][3] = max(prer, ndp[c-1][3])
        if item.get((r, c)):
            ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
            ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
            ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
    dp = ndp
    ndp = [[0] * 4 for _ in range(3010)]

#print(dp)
print(max(dp[C])) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K item = {} item {} for _ in range(K):
    r, c, v = map(int, input().split())
    item[(r, c)] = 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, c)] = v item[(r, c)] item (r, c) r c v [0] * 4 for _ in range(3010) for _ in range(3010) _ range(3010) range 3010 for _ in range(3010) [0] * 4 [0] 0 4 dp = [[0] * 4 for _ in range(3010)] dp [[0] * 4 for _ in range(3010)] [0] * 4 for _ in range(3010) for _ in range(3010) _ range(3010) range 3010 for _ in range(3010) [0] * 4 [0] 0 4 ndp = [[0] * 4 for _ in range(3010)] ndp [[0] * 4 for _ in range(3010)] for r in range(1, R+1):
    for c in range(1, C+1):
        prer = max(dp[c])
        ndp[c][0] = max(prer, ndp[c-1][0])
        ndp[c][1] = max(prer, ndp[c-1][1])
        ndp[c][2] = max(prer, ndp[c-1][2])
        ndp[c][3] = max(prer, ndp[c-1][3])
        if item.get((r, c)):
            ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
            ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
            ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
    dp = ndp
    ndp = [[0] * 4 for _ in range(3010)]

#print(dp) r range(1, R+1) range 1 R+1 R 1 for c in range(1, C+1):
        prer = max(dp[c])
        ndp[c][0] = max(prer, ndp[c-1][0])
        ndp[c][1] = max(prer, ndp[c-1][1])
        ndp[c][2] = max(prer, ndp[c-1][2])
        ndp[c][3] = max(prer, ndp[c-1][3])
        if item.get((r, c)):
            ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
            ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
            ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
     c range(1, C+1) range 1 C+1 C 1 prer = max(dp[c]) prer max(dp[c]) max dp[c] dp c ndp[c][0] = max(prer, ndp[c-1][0]) ndp[c][0] [c] ndp c 0 max(prer, ndp[c-1][0]) max prer ndp[c-1][0] [c-1] ndp c-1 c 1 0 ndp[c][1] = max(prer, ndp[c-1][1]) ndp[c][1] [c] ndp c 1 max(prer, ndp[c-1][1]) max prer ndp[c-1][1] [c-1] ndp c-1 c 1 1 ndp[c][2] = max(prer, ndp[c-1][2]) ndp[c][2] [c] ndp c 2 max(prer, ndp[c-1][2]) max prer ndp[c-1][2] [c-1] ndp c-1 c 1 2 ndp[c][3] = max(prer, ndp[c-1][3]) ndp[c][3] [c] ndp c 3 max(prer, ndp[c-1][3]) max prer ndp[c-1][3] [c-1] ndp c-1 c 1 3 if item.get((r, c)):
            ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
            ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
            ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
     item.get((r, c)) item.get item get (r, c) r c ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)]) ndp[c][1] [c] ndp c 1 max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)]) max ndp[c][1] [c] ndp c 1 max(prer, ndp[c-1][0]) + item[(r,c)] max(prer, ndp[c-1][0]) max prer ndp[c-1][0] [c-1] ndp c-1 c 1 0 item[(r,c)] item (r,c) r c ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)]) ndp[c][2] [c] ndp c 2 max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)]) max ndp[c][2] [c] ndp c 2 max(prer, ndp[c-1][1]) + item[(r,c)] max(prer, ndp[c-1][1]) max prer ndp[c-1][1] [c-1] ndp c-1 c 1 1 item[(r,c)] item (r,c) r c ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)]) ndp[c][3] [c] ndp c 3 max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)]) max ndp[c][3] [c] ndp c 3 max(prer, ndp[c-1][2]) + item[(r,c)] max(prer, ndp[c-1][2]) max prer ndp[c-1][2] [c-1] ndp c-1 c 1 2 item[(r,c)] item (r,c) r c dp = ndp dp ndp [0] * 4 for _ in range(3010) for _ in range(3010) _ range(3010) range 3010 for _ in range(3010) [0] * 4 [0] 0 4 ndp = [[0] * 4 for _ in range(3010)] ndp [[0] * 4 for _ in range(3010)] print(max(dp[C])) print max(dp[C]) max dp[C] dp C item = {} {} item dp = [[0] * 4 for _ in range(3010)] [[0] * 4 for _ in range(3010)] dp R, C, K = map(int, input().split()) map(int, input().split()) R ndp = [[0] * 4 for _ in range(3010)] [[0] * 4 for _ in range(3010)] ndp C, K = map(int, input().split()) map(int, input().split()) C r, c, v = map(int, input().split()) map(int, input().split()) r c, v = map(int, input().split()) map(int, input().split()) c ndp = [[0] * 4 for _ in range(3010)] [[0] * 4 for _ in range(3010)] ndp v = map(int, input().split()) map(int, input().split()) v K = map(int, input().split()) map(int, input().split()) K prer = max(dp[c]) max(dp[c]) prer dp = ndp ndp dp
R, C, K = map(int, input().split())
item = {}
for _ in range(K):
    r, c, v = map(int, input().split())
    item[(r, c)] = v

dp = [[0] * 4 for _ in range(3010)]
ndp = [[0] * 4 for _ in range(3010)]
for r in range(1, R+1):
    for c in range(1, C+1):
        prer = max(dp[c])
        ndp[c][0] = max(prer, ndp[c-1][0])
        ndp[c][1] = max(prer, ndp[c-1][1])
        ndp[c][2] = max(prer, ndp[c-1][2])
        ndp[c][3] = max(prer, ndp[c-1][3])
        if item.get((r, c)):
            ndp[c][1] = max(ndp[c][1], max(prer, ndp[c-1][0]) + item[(r,c)])
            ndp[c][2] = max(ndp[c][2], max(prer, ndp[c-1][1]) + item[(r,c)])
            ndp[c][3] = max(ndp[c][3], max(prer, ndp[c-1][2]) + item[(r,c)])
    dp = ndp
    ndp = [[0] * 4 for _ in range(3010)]

#print(dp)
print(max(dp[C]))
