h,w,k = map(int, input().split())
item = [[0 for _ in range(w)] for _ in range(h)]
for i in range(k):
    y,x,v = list(map(int,input().split()))
    item[y-1][x-1]=v

dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        for i in range(4):
            if y<h-1:
                dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
            if x<w-1:
                dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])

        if item[y][x]>0:
            for i in range(3):
                if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x])

ans=[dp[0][-1][-1] + item[-1][-1],
     dp[1][-1][-1] + item[-1][-1],
     dp[2][-1][-1] + item[-1][-1],
     dp[3][-1][-1]]
print(max(ans)) h,w,k = map(int, input().split()) h map(int, input().split()) map int input().split() ().split () input split w k [0 for _ in range(w)] for _ in range(h) for _ in range(h) _ range(h) range h for _ in range(h) [0 for _ in range(w)] item = [[0 for _ in range(w)] for _ in range(h)] item [[0 for _ in range(w)] for _ in range(h)] for i in range(k):
    y,x,v = list(map(int,input().split()))
    item[y-1][x-1]=v i range(k) range k y,x,v = list(map(int,input().split())) y list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split x v item[y-1][x-1]=v item[y-1][x-1] [y-1] item y-1 y 1 x-1 x 1 v [[0 for _ in range(w)] for _ in range(h)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0 for _ in range(w)] for _ in range(h)] dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)] dp [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)] for y in range(h):
    for x in range(w):
        for i in range(4):
            if y<h-1:
                dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
            if x<w-1:
                dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])

        if item[y][x]>0:
            for i in range(3):
                if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) y range(h) range h for x in range(w):
        for i in range(4):
            if y<h-1:
                dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
            if x<w-1:
                dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])

        if item[y][x]>0:
            for i in range(3):
                if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) x range(w) range w for i in range(4):
            if y<h-1:
                dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
            if x<w-1:
                dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])

         i range(4) range 4 if y<h-1:
                dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
             y<h-1 y h-1 h 1 dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x]) dp[0][y+1][x] [y+1] [0] dp 0 y+1 y 1 x max(dp[0][y+1][x],dp[i][y][x]) max dp[0][y+1][x] [y+1] [0] dp 0 y+1 y 1 x dp[i][y][x] [y] [i] dp i y x if x<w-1:
                dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])

         x<w-1 x w-1 w 1 dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x]) dp[i][y][x+1] [y] [i] dp i y x+1 x 1 max(dp[i][y][x+1],dp[i][y][x]) max dp[i][y][x+1] [y] [i] dp i y x+1 x 1 dp[i][y][x] [y] [i] dp i y x if item[y][x]>0:
            for i in range(3):
                if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) item[y][x]>0 item[y][x] [y] item y x 0 for i in range(3):
                if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) i range(3) range 3 if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                 y<h-1 y h-1 h 1 dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x]) dp[0][y+1][x] [y+1] [0] dp 0 y+1 y 1 x max(dp[0][y+1][x],dp[i][y][x] + item[y][x]) max dp[0][y+1][x] [y+1] [0] dp 0 y+1 y 1 x dp[i][y][x] + item[y][x] dp[i][y][x] [y] [i] dp i y x item[y][x] [y] item y x if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) x<w-1 x w-1 w 1 dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) dp[i+1][y][x+1] [y] [i+1] dp i+1 i 1 y x+1 x 1 max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x]) max dp[i+1][y][x+1] [y] [i+1] dp i+1 i 1 y x+1 x 1 dp[i][y][x] + item[y][x] dp[i][y][x] [y] [i] dp i y x item[y][x] [y] item y x ans=[dp[0][-1][-1] + item[-1][-1],
     dp[1][-1][-1] + item[-1][-1],
     dp[2][-1][-1] + item[-1][-1],
     dp[3][-1][-1]] ans [dp[0][-1][-1] + item[-1][-1],
     dp[1][-1][-1] + item[-1][-1],
     dp[2][-1][-1] + item[-1][-1],
     dp[3][-1][-1]] dp[0][-1][-1] + item[-1][-1] dp[0][-1][-1] [-1] [0] dp 0 -1 -1 item[-1][-1] [-1] item -1 -1 dp[1][-1][-1] + item[-1][-1] dp[1][-1][-1] [-1] [1] dp 1 -1 -1 item[-1][-1] [-1] item -1 -1 dp[2][-1][-1] + item[-1][-1] dp[2][-1][-1] [-1] [2] dp 2 -1 -1 item[-1][-1] [-1] item -1 -1 dp[3][-1][-1] [-1] [3] dp 3 -1 -1 print(max(ans)) print max(ans) max ans y,x,v = list(map(int,input().split())) list(map(int,input().split())) y x,v = list(map(int,input().split())) list(map(int,input().split())) x ans=[dp[0][-1][-1] + item[-1][-1],
     dp[1][-1][-1] + item[-1][-1],
     dp[2][-1][-1] + item[-1][-1],
     dp[3][-1][-1]] [dp[0][-1][-1] + item[-1][-1],
     dp[1][-1][-1] + item[-1][-1],
     dp[2][-1][-1] + item[-1][-1],
     dp[3][-1][-1]] ans v = list(map(int,input().split())) list(map(int,input().split())) v item = [[0 for _ in range(w)] for _ in range(h)] [[0 for _ in range(w)] for _ in range(h)] item dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)] [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)] dp k = map(int, input().split()) map(int, input().split()) k w,k = map(int, input().split()) map(int, input().split()) w h,w,k = map(int, input().split()) map(int, input().split()) h
h,w,k = map(int, input().split())
item = [[0 for _ in range(w)] for _ in range(h)]
for i in range(k):
    y,x,v = list(map(int,input().split()))
    item[y-1][x-1]=v

dp = [[[0 for _ in range(w)] for _ in range(h)] for _ in range(4)]

for y in range(h):
    for x in range(w):
        for i in range(4):
            if y<h-1:
                dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x])
            if x<w-1:
                dp[i][y][x+1]=max(dp[i][y][x+1],dp[i][y][x])

        if item[y][x]>0:
            for i in range(3):
                if y<h-1:
                    dp[0][y+1][x]=max(dp[0][y+1][x],dp[i][y][x] + item[y][x])
                if x<w-1:
                    dp[i+1][y][x+1]=max(dp[i+1][y][x+1],dp[i][y][x] + item[y][x])

ans=[dp[0][-1][-1] + item[-1][-1],
     dp[1][-1][-1] + item[-1][-1],
     dp[2][-1][-1] + item[-1][-1],
     dp[3][-1][-1]]
print(max(ans))