R, C, K = map(int, input().split())
points_dict = dict()
for _ in range(K):
    r, c, v = map(int, input().split())
    points_dict[r * 30000 + c] = v

dp = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] # dp[4][R+1][C+1]
index = 0
for i in range(1, R+1):
    for j in range(1, C+1):
        #移動
        for k in range(4):
            if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
            if dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
        if i * 30000 + j in points_dict:
            v = points_dict[i * 30000 + j]
            for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v
"""
for i in range(4):
    print(i)
    print(*dp[i], sep = '\n')
"""
print(max((dp[i][R][C] for i in range(4)))) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K points_dict = dict() points_dict dict() dict for _ in range(K):
    r, c, v = map(int, input().split())
    points_dict[r * 30000 + 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 points_dict[r * 30000 + c] = v points_dict[r * 30000 + c] points_dict r * 30000 + c r * 30000 r 30000 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)] index = 0 index 0 for i in range(1, R+1):
    for j in range(1, C+1):
        #移動
        for k in range(4):
            if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
            if dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
        if i * 30000 + j in points_dict:
            v = points_dict[i * 30000 + j]
            for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v i range(1, R+1) range 1 R+1 R 1 for j in range(1, C+1):
        #移動
        for k in range(4):
            if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
            if dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
        if i * 30000 + j in points_dict:
            v = points_dict[i * 30000 + j]
            for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v j range(1, C+1) range 1 C+1 C 1 for k in range(4):
            if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
            if dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
         k range(4) range 4 if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
             dp[0][i][j] < dp[k][i-1][j] 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 dp[0][i][j] = dp[k][i-1][j] 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 dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
         dp[k][i][j] < dp[k][i][j-1] dp[k][i][j] [i] [k] dp k i j dp[k][i][j-1] [i] [k] dp k i j-1 j 1 dp[k][i][j] = dp[k][i][j-1] 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 * 30000 + j in points_dict:
            v = points_dict[i * 30000 + j]
            for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v i * 30000 + j in points_dict i * 30000 + j i * 30000 i 30000 j points_dict v = points_dict[i * 30000 + j] v points_dict[i * 30000 + j] points_dict i * 30000 + j i * 30000 i 30000 j for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v k range(3, 0, -1) range 3 0 -1 if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v dp[k][i][j] < dp[k-1][i][j] + v dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j] + v dp[k-1][i][j] [i] [k-1] dp k-1 k 1 i j v dp[k][i][j] = dp[k-1][i][j] + v dp[k][i][j] [i] [k] dp k i j dp[k-1][i][j] + v dp[k-1][i][j] [i] [k-1] dp k-1 k 1 i j v """
for i in range(4):
    print(i)
    print(*dp[i], sep = '\n')
""" dp[i][R][C] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) dp[i][R][C] [R] [i] dp i R C print(max((dp[i][R][C] for i in range(4)))) print max((dp[i][R][C] for i in range(4))) max (dp[i][R][C] for i in range(4)) c, v = map(int, input().split()) map(int, input().split()) c R, C, K = map(int, input().split()) map(int, input().split()) R index = 0 0 index C, K = map(int, input().split()) map(int, input().split()) C v = map(int, input().split()) map(int, input().split()) v points_dict = dict() dict() points_dict v = points_dict[i * 30000 + j] points_dict[i * 30000 + j] v 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 r, c, v = map(int, input().split()) map(int, input().split()) r
R, C, K = map(int, input().split())
points_dict = dict()
for _ in range(K):
    r, c, v = map(int, input().split())
    points_dict[r * 30000 + c] = v

dp = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] # dp[4][R+1][C+1]
index = 0
for i in range(1, R+1):
    for j in range(1, C+1):
        #移動
        for k in range(4):
            if dp[0][i][j] < dp[k][i-1][j]:
                dp[0][i][j] = dp[k][i-1][j]
            if dp[k][i][j] < dp[k][i][j-1]:
                dp[k][i][j] = dp[k][i][j-1]
        #あれば、拾うかどうか
        if i * 30000 + j in points_dict:
            v = points_dict[i * 30000 + j]
            for k in range(3, 0, -1):
                if dp[k][i][j] < dp[k-1][i][j] + v:
                    dp[k][i][j] = dp[k-1][i][j] + v
"""
for i in range(4):
    print(i)
    print(*dp[i], sep = '\n')
"""
print(max((dp[i][R][C] for i in range(4))))
