R,C,K=map(int,input().split())
point=[[0]*C for _ in range(R)]
for _ in range(K):
    r,c,v=map(int,input().split())
    point[r-1][c-1]=v

dp=[[[0]*C for _ in range(R)] for _ in range(4)]
dp[1][0][0]=point[0][0]
for i in range(R):
    for j in range(C-1):
        for k in range(4):
            dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
            if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
    if i==R-1:
        break
    for j in range(C):
        mx=0
        for k in range(4):
            mx=max(dp[k][i][j],mx)
        dp[0][i+1][j]=mx
        dp[1][i+1][j]=mx+point[i+1][j]
ans=0
for i in range(4):
    ans=max(ans,dp[i][R-1][C-1])
print(ans) R,C,K=map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C point=[[0]*C for _ in range(R)] point [[0]*C for _ in range(R)] for _ in range(K):
    r,c,v=map(int,input().split())
    point[r-1][c-1]=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 point[r-1][c-1]=v point[r-1][c-1] [r-1] point r-1 r 1 c-1 c 1 v [[0]*C for _ in range(R)] for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [[0]*C for _ in range(R)] dp=[[[0]*C for _ in range(R)] for _ in range(4)] dp [[[0]*C for _ in range(R)] for _ in range(4)] dp[1][0][0]=point[0][0] dp[1][0][0] [0] [1] dp 1 0 0 point[0][0] [0] point 0 0 for i in range(R):
    for j in range(C-1):
        for k in range(4):
            dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
            if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
    if i==R-1:
        break
    for j in range(C):
        mx=0
        for k in range(4):
            mx=max(dp[k][i][j],mx)
        dp[0][i+1][j]=mx
        dp[1][i+1][j]=mx+point[i+1][j] i range(R) range R for j in range(C-1):
        for k in range(4):
            dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
            if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
     j range(C-1) range C-1 C 1 for k in range(4):
            dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
            if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
     k range(4) range 4 dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j]) dp[k][i][j+1] [i] [k] dp k i j+1 j 1 max(dp[k][i][j+1],dp[k][i][j]) max dp[k][i][j+1] [i] [k] dp k i j+1 j 1 dp[k][i][j] [i] [k] dp k i j if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
     k!=0 k 0 dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1]) dp[k][i][j+1] [i] [k] dp k i j+1 j 1 max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1]) max dp[k][i][j+1] [i] [k] dp k i j+1 j 1 dp[k-1][i][j]+point[i][j+1] dp[k-1][i][j] [i] [k-1] dp k-1 k 1 i j point[i][j+1] [i] point i j+1 j 1 if i==R-1:
        break
     i==R-1 i R-1 R 1 break for j in range(C):
        mx=0
        for k in range(4):
            mx=max(dp[k][i][j],mx)
        dp[0][i+1][j]=mx
        dp[1][i+1][j]=mx+point[i+1][j] j range(C) range C mx=0 mx 0 for k in range(4):
            mx=max(dp[k][i][j],mx)
         k range(4) range 4 mx=max(dp[k][i][j],mx) mx max(dp[k][i][j],mx) max dp[k][i][j] [i] [k] dp k i j mx dp[0][i+1][j]=mx dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j mx dp[1][i+1][j]=mx+point[i+1][j] dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j mx+point[i+1][j] mx point[i+1][j] [i+1] point i+1 i 1 j ans=0 ans 0 for i in range(4):
    ans=max(ans,dp[i][R-1][C-1]) i range(4) range 4 ans=max(ans,dp[i][R-1][C-1]) ans max(ans,dp[i][R-1][C-1]) max ans dp[i][R-1][C-1] [R-1] [i] dp i R-1 R 1 C-1 C 1 print(ans) print ans r,c,v=map(int,input().split()) map(int,input().split()) r K=map(int,input().split()) map(int,input().split()) K ans=max(ans,dp[i][R-1][C-1]) max(ans,dp[i][R-1][C-1]) ans C,K=map(int,input().split()) map(int,input().split()) C point=[[0]*C for _ in range(R)] [[0]*C for _ in range(R)] point ans=0 0 ans mx=0 0 mx c,v=map(int,input().split()) map(int,input().split()) c dp=[[[0]*C for _ in range(R)] for _ in range(4)] [[[0]*C for _ in range(R)] for _ in range(4)] dp R,C,K=map(int,input().split()) map(int,input().split()) R mx=max(dp[k][i][j],mx) max(dp[k][i][j],mx) mx v=map(int,input().split()) map(int,input().split()) v
R,C,K=map(int,input().split())
point=[[0]*C for _ in range(R)]
for _ in range(K):
    r,c,v=map(int,input().split())
    point[r-1][c-1]=v

dp=[[[0]*C for _ in range(R)] for _ in range(4)]
dp[1][0][0]=point[0][0]
for i in range(R):
    for j in range(C-1):
        for k in range(4):
            dp[k][i][j+1]=max(dp[k][i][j+1],dp[k][i][j])
            if k!=0:
                dp[k][i][j+1]=max(dp[k][i][j+1],dp[k-1][i][j]+point[i][j+1])
    if i==R-1:
        break
    for j in range(C):
        mx=0
        for k in range(4):
            mx=max(dp[k][i][j],mx)
        dp[0][i+1][j]=mx
        dp[1][i+1][j]=mx+point[i+1][j]
ans=0
for i in range(4):
    ans=max(ans,dp[i][R-1][C-1])
print(ans)