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

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

for i in range(K):
    r,c,v = list(map(int, input().split()))
    t[r][c] = v

for i in range(R+1):
    for j in range(C+1):
        for k in range(4):
            if i!=0:
                d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
                d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])

            if j!=0:
                d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
                if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j])

a = 0
for i in range(4):
    a = max(a, d[i][-1][-1])
print(a) import sys sys R, C, K = list(map(int, input().split())) R list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split C K [[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)] d = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] d [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] [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 t = [[0] * (C+1) for _ in range(R+1)] t [[0] * (C+1) for _ in range(R+1)] for i in range(K):
    r,c,v = list(map(int, input().split()))
    t[r][c] = v i range(K) range K r,c,v = list(map(int, input().split())) r list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split c v t[r][c] = v t[r][c] [r] t r c v for i in range(R+1):
    for j in range(C+1):
        for k in range(4):
            if i!=0:
                d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
                d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])

            if j!=0:
                d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
                if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) i range(R+1) range R+1 R 1 for j in range(C+1):
        for k in range(4):
            if i!=0:
                d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
                d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])

            if j!=0:
                d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
                if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) j range(C+1) range C+1 C 1 for k in range(4):
            if i!=0:
                d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
                d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])

            if j!=0:
                d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
                if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) k range(4) range 4 if i!=0:
                d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
                d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])

             i!=0 i 0 d[0][i][j] = max(d[0][i][j], d[k][i-1][j]) d[0][i][j] [i] [0] d 0 i j max(d[0][i][j], d[k][i-1][j]) max d[0][i][j] [i] [0] d 0 i j d[k][i-1][j] [i-1] [k] d k i-1 i 1 j d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j]) d[1][i][j] [i] [1] d 1 i j max(d[1][i][j], d[k][i-1][j] + t[i][j]) max d[1][i][j] [i] [1] d 1 i j d[k][i-1][j] + t[i][j] d[k][i-1][j] [i-1] [k] d k i-1 i 1 j t[i][j] [i] t i j if j!=0:
                d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
                if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) j!=0 j 0 d[k][i][j] = max(d[k][i][j], d[k][i][j-1]) d[k][i][j] [i] [k] d k i j max(d[k][i][j], d[k][i][j-1]) max d[k][i][j] [i] [k] d k i j d[k][i][j-1] [i] [k] d k i j-1 j 1 if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) k != 0 k 0 d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) d[k][i][j] [i] [k] d k i j max(d[k][i][j], d[k-1][i][j-1] + t[i][j]) max d[k][i][j] [i] [k] d k i j d[k-1][i][j-1] + t[i][j] d[k-1][i][j-1] [i] [k-1] d k-1 k 1 i j-1 j 1 t[i][j] [i] t i j a = 0 a 0 for i in range(4):
    a = max(a, d[i][-1][-1]) i range(4) range 4 a = max(a, d[i][-1][-1]) a max(a, d[i][-1][-1]) max a d[i][-1][-1] [-1] [i] d i -1 -1 print(a) print a K = list(map(int, input().split())) list(map(int, input().split())) K C, K = list(map(int, input().split())) list(map(int, input().split())) C a = max(a, d[i][-1][-1]) max(a, d[i][-1][-1]) a a = 0 0 a r,c,v = list(map(int, input().split())) list(map(int, input().split())) r c,v = list(map(int, input().split())) list(map(int, input().split())) c R, C, K = list(map(int, input().split())) list(map(int, input().split())) R t = [[0] * (C+1) for _ in range(R+1)] [[0] * (C+1) for _ in range(R+1)] t d = [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] [[[0] * (C+1) for _ in range(R+1)] for _ in range(4)] d v = list(map(int, input().split())) list(map(int, input().split())) v
import sys
R, C, K = list(map(int, input().split()))

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

for i in range(K):
    r,c,v = list(map(int, input().split()))
    t[r][c] = v

for i in range(R+1):
    for j in range(C+1):
        for k in range(4):
            if i!=0:
                d[0][i][j] = max(d[0][i][j], d[k][i-1][j])
                d[1][i][j] = max(d[1][i][j], d[k][i-1][j] + t[i][j])

            if j!=0:
                d[k][i][j] = max(d[k][i][j], d[k][i][j-1])
                if k != 0:
                    d[k][i][j] = max(d[k][i][j], d[k-1][i][j-1] + t[i][j])

a = 0
for i in range(4):
    a = max(a, d[i][-1][-1])
print(a)
