H, W, K = map(int, input().split())
A = [[0] * W for _ in range(H)]
for i in range(K):
    y, x, v = map(int, input().split())
    A[y - 1][x - 1] = v
dp = [[0] * 4 for i in range(W)]
pre = []
dp[0][1] = A[0][0]
for i in range(H):
    for j in range(W):
        if i:
            dp[j][0] = max(dp[j][0], max(pre[j]))
            dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j])
        for k in range(4):
            if j:
                if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                dp[j][k] = max(dp[j][k], dp[j - 1][k])
    pre = dp
ans = 0
for j in range(W):
    ans = max(ans, max(dp[j]))
print(ans) H, W, K = map(int, input().split()) H map(int, input().split()) map int input().split() ().split () input split W K [0] * W for _ in range(H) for _ in range(H) _ range(H) range H for _ in range(H) [0] * W [0] 0 W A = [[0] * W for _ in range(H)] A [[0] * W for _ in range(H)] for i in range(K):
    y, x, v = map(int, input().split())
    A[y - 1][x - 1] = v i range(K) range K y, x, v = map(int, input().split()) y map(int, input().split()) map int input().split() ().split () input split x v A[y - 1][x - 1] = v A[y - 1][x - 1] [y - 1] A y - 1 y 1 x - 1 x 1 v [0] * 4 for i in range(W) for i in range(W) i range(W) range W for i in range(W) [0] * 4 [0] 0 4 dp = [[0] * 4 for i in range(W)] dp [[0] * 4 for i in range(W)] pre = [] pre [] dp[0][1] = A[0][0] dp[0][1] [0] dp 0 1 A[0][0] [0] A 0 0 for i in range(H):
    for j in range(W):
        if i:
            dp[j][0] = max(dp[j][0], max(pre[j]))
            dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j])
        for k in range(4):
            if j:
                if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                dp[j][k] = max(dp[j][k], dp[j - 1][k])
    pre = dp i range(H) range H for j in range(W):
        if i:
            dp[j][0] = max(dp[j][0], max(pre[j]))
            dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j])
        for k in range(4):
            if j:
                if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                dp[j][k] = max(dp[j][k], dp[j - 1][k])
     j range(W) range W if i:
            dp[j][0] = max(dp[j][0], max(pre[j]))
            dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j])
         i dp[j][0] = max(dp[j][0], max(pre[j])) dp[j][0] [j] dp j 0 max(dp[j][0], max(pre[j])) max dp[j][0] [j] dp j 0 max(pre[j]) max pre[j] pre j dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j]) dp[j][1] [j] dp j 1 max(dp[j][1], max(pre[j]) + A[i][j]) max dp[j][1] [j] dp j 1 max(pre[j]) + A[i][j] max(pre[j]) max pre[j] pre j A[i][j] [i] A i j for k in range(4):
            if j:
                if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                dp[j][k] = max(dp[j][k], dp[j - 1][k])
     k range(4) range 4 if j:
                if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                dp[j][k] = max(dp[j][k], dp[j - 1][k])
     j if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                 0 < k 0 k dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j]) dp[j][k] [j] dp j k max(dp[j][k], dp[j - 1][k - 1] + A[i][j]) max dp[j][k] [j] dp j k dp[j - 1][k - 1] + A[i][j] dp[j - 1][k - 1] [j - 1] dp j - 1 j 1 k - 1 k 1 A[i][j] [i] A i j dp[j][k] = max(dp[j][k], dp[j - 1][k]) dp[j][k] [j] dp j k max(dp[j][k], dp[j - 1][k]) max dp[j][k] [j] dp j k dp[j - 1][k] [j - 1] dp j - 1 j 1 k pre = dp pre dp ans = 0 ans 0 for j in range(W):
    ans = max(ans, max(dp[j])) j range(W) range W ans = max(ans, max(dp[j])) ans max(ans, max(dp[j])) max ans max(dp[j]) max dp[j] dp j print(ans) print ans W, K = map(int, input().split()) map(int, input().split()) W A = [[0] * W for _ in range(H)] [[0] * W for _ in range(H)] A dp = [[0] * 4 for i in range(W)] [[0] * 4 for i in range(W)] dp v = map(int, input().split()) map(int, input().split()) v y, x, v = map(int, input().split()) map(int, input().split()) y pre = dp dp pre K = map(int, input().split()) map(int, input().split()) K x, v = map(int, input().split()) map(int, input().split()) x ans = 0 0 ans H, W, K = map(int, input().split()) map(int, input().split()) H pre = [] [] pre ans = max(ans, max(dp[j])) max(ans, max(dp[j])) ans
H, W, K = map(int, input().split())
A = [[0] * W for _ in range(H)]
for i in range(K):
    y, x, v = map(int, input().split())
    A[y - 1][x - 1] = v
dp = [[0] * 4 for i in range(W)]
pre = []
dp[0][1] = A[0][0]
for i in range(H):
    for j in range(W):
        if i:
            dp[j][0] = max(dp[j][0], max(pre[j]))
            dp[j][1] = max(dp[j][1], max(pre[j]) + A[i][j])
        for k in range(4):
            if j:
                if 0 < k:
                    dp[j][k] = max(dp[j][k], dp[j - 1][k - 1] + A[i][j])
                dp[j][k] = max(dp[j][k], dp[j - 1][k])
    pre = dp
ans = 0
for j in range(W):
    ans = max(ans, max(dp[j]))
print(ans)
