import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
    R, C, K = NMI()
    grid = make_grid_int(R, C, 0)

    for i in range(K):
        r_, c_, v_, = NMI()
        grid[r_ - 1][c_ - 1] = v_

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

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

if __name__ == "__main__":
    main() import sys sys import math math from collections import defaultdict from collections import deque sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 MOD = 10 ** 9 + 7 MOD 10 ** 9 + 7 10 ** 9 10 9 7 input = lambda: sys.stdin.readline().strip() input lambda: sys.stdin.readline().strip() sys.stdin.readline().strip() sys.stdin.readline().strip sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline strip NI = lambda: int(input()) NI lambda: int(input()) int(input()) int input() input NMI = lambda: map(int, input().split()) NMI lambda: map(int, input().split()) map(int, input().split()) map int input().split() ().split () input split NLI = lambda: list(NMI()) NLI lambda: list(NMI()) list(NMI()) list NMI() NMI SI = lambda: input() SI lambda: input() input() input [int(num)] * w for _ in range(h) for _ in range(h) _ range(h) range h for _ in range(h) [int(num)] * w [int(num)] int(num) int num w def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)] make_grid_int h h w w num num def main():
    R, C, K = NMI()
    grid = make_grid_int(R, C, 0)

    for i in range(K):
        r_, c_, v_, = NMI()
        grid[r_ - 1][c_ - 1] = v_

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

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) main R, C, K = NMI() R NMI() NMI C K grid = make_grid_int(R, C, 0) grid make_grid_int(R, C, 0) make_grid_int R C 0 for i in range(K):
        r_, c_, v_, = NMI()
        grid[r_ - 1][c_ - 1] = v_

     i range(K) range K r_, c_, v_, = NMI() r_ NMI() NMI c_ v_ grid[r_ - 1][c_ - 1] = v_ grid[r_ - 1][c_ - 1] [r_ - 1] grid r_ - 1 r_ 1 c_ - 1 c_ 1 v_ [[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0 for _ in range(C + 2)] for _ in range(R + 2)] dp = [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)] dp [[[0 for _ in range(C + 2)] for _ in range(R + 2)] for _ in range(4)] for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

     i range(R + 1) range R + 1 R 1 for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

     j range(C + 1) range C + 1 C 1 for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

     k range(4) range 4 a = dp[k][i][j] a dp[k][i][j] [i] [k] dp k i j try:
                    v = grid[i][j]
                except:
                    v = 0

                 except:
                    v = 0

                 v = 0 v 0 v = grid[i][j] v grid[i][j] [i] grid i j if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                 k == 3 k 3 dp[0][i + 1][j] = max(a, dp[0][i + 1][j]) dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j max(a, dp[0][i + 1][j]) max a dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j continue dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j]) dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j max(a, a + v, dp[0][i + 1][j]) max a a + v a v dp[0][i + 1][j] [i + 1] [0] dp 0 i + 1 i 1 j dp[k][i][j + 1] = max(a, dp[k][i][j + 1]) dp[k][i][j + 1] [i] [k] dp k i j + 1 j 1 max(a, dp[k][i][j + 1]) max a dp[k][i][j + 1] [i] [k] dp k i j + 1 j 1 dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1]) dp[k + 1][i][j + 1] [i] [k + 1] dp k + 1 k 1 i j + 1 j 1 max(a + v, dp[k + 1][i][j + 1]) max a + v a v dp[k + 1][i][j + 1] [i] [k + 1] dp k + 1 k 1 i j + 1 j 1 print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) print max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]) max dp[0][R][C] [R] [0] dp 0 R C dp[1][R][C] [R] [1] dp 1 R C dp[2][R][C] [R] [2] dp 2 R C dp[3][R][C] [R] [3] dp 3 R C if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main NI = lambda: int(input()) lambda: int(input()) NI input = lambda: sys.stdin.readline().strip() lambda: sys.stdin.readline().strip() input NLI = lambda: list(NMI()) lambda: list(NMI()) NLI def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)] def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)] make_grid_int def main():
    R, C, K = NMI()
    grid = make_grid_int(R, C, 0)

    for i in range(K):
        r_, c_, v_, = NMI()
        grid[r_ - 1][c_ - 1] = v_

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

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) def main():
    R, C, K = NMI()
    grid = make_grid_int(R, C, 0)

    for i in range(K):
        r_, c_, v_, = NMI()
        grid[r_ - 1][c_ - 1] = v_

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

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C])) main MOD = 10 ** 9 + 7 10 ** 9 + 7 MOD NMI = lambda: map(int, input().split()) lambda: map(int, input().split()) NMI SI = lambda: input() lambda: input() SI
import sys
import math
from collections import defaultdict
from collections import deque

sys.setrecursionlimit(1000000)
MOD = 10 ** 9 + 7
input = lambda: sys.stdin.readline().strip()
NI = lambda: int(input())
NMI = lambda: map(int, input().split())
NLI = lambda: list(NMI())
SI = lambda: input()
def make_grid_int(h, w, num): return [[int(num)] * w for _ in range(h)]
def main():
    R, C, K = NMI()
    grid = make_grid_int(R, C, 0)

    for i in range(K):
        r_, c_, v_, = NMI()
        grid[r_ - 1][c_ - 1] = v_

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

    for i in range(R + 1):
        for j in range(C + 1):
            for k in range(4):
                a = dp[k][i][j]
                try:
                    v = grid[i][j]
                except:
                    v = 0

                if k == 3:
                    dp[0][i + 1][j] = max(a, dp[0][i + 1][j])
                    continue
                dp[0][i + 1][j] = max(a, a + v, dp[0][i + 1][j])
                dp[k][i][j + 1] = max(a, dp[k][i][j + 1])
                dp[k + 1][i][j + 1] = max(a + v, dp[k + 1][i][j + 1])

    print(max(dp[0][R][C], dp[1][R][C], dp[2][R][C], dp[3][R][C]))

if __name__ == "__main__":
    main()