R,C,K= map(int,input().split(" "))
original=[[0]*(C+1) for i in range(R+1)]
for _ in range(K):
    r,c,v= map(int,input().split(" "))
    original[r][c]=v
d1=[[0]*(C+1) for i in range(R+1)]
d2=[[0]*(C+1) for i in range(R+1)]
d3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
    for j in range(1,C+1):
        curr= original[i][j]
        d1[i][j]=max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr)
        d2[i][j]=max(d2[i][j-1],d1[i][j-1]+curr)
        d3[i][j]=max(d3[i][j-1],d2[i][j-1]+curr)
print(max(d1[-1][-1],d2[-1][-1],d3[-1][-1])) R,C,K= map(int,input().split(" ")) R map(int,input().split(" ")) map int input().split(" ") ().split () input split " " C K [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 original=[[0]*(C+1) for i in range(R+1)] original [[0]*(C+1) for i in range(R+1)] for _ in range(K):
    r,c,v= map(int,input().split(" "))
    original[r][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 original[r][c]=v original[r][c] [r] original r c v [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 d1=[[0]*(C+1) for i in range(R+1)] d1 [[0]*(C+1) for i in range(R+1)] [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 d2=[[0]*(C+1) for i in range(R+1)] d2 [[0]*(C+1) for i in range(R+1)] [0]*(C+1) for i in range(R+1) for i in range(R+1) i range(R+1) range R+1 R 1 for i in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 d3=[[0]*(C+1) for i in range(R+1)] d3 [[0]*(C+1) for i in range(R+1)] for i in range(1,R+1):
    for j in range(1,C+1):
        curr= original[i][j]
        d1[i][j]=max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr)
        d2[i][j]=max(d2[i][j-1],d1[i][j-1]+curr)
        d3[i][j]=max(d3[i][j-1],d2[i][j-1]+curr) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
        curr= original[i][j]
        d1[i][j]=max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr)
        d2[i][j]=max(d2[i][j-1],d1[i][j-1]+curr)
        d3[i][j]=max(d3[i][j-1],d2[i][j-1]+curr) j range(1,C+1) range 1 C+1 C 1 curr= original[i][j] curr original[i][j] [i] original i j d1[i][j]=max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr) d1[i][j] [i] d1 i j max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr) max d1[i-1][j]+curr d1[i-1][j] [i-1] d1 i-1 i 1 j curr d2[i-1][j]+curr d2[i-1][j] [i-1] d2 i-1 i 1 j curr d3[i-1][j]+curr d3[i-1][j] [i-1] d3 i-1 i 1 j curr d1[i][j-1] [i] d1 i j-1 j 1 curr d2[i][j]=max(d2[i][j-1],d1[i][j-1]+curr) d2[i][j] [i] d2 i j max(d2[i][j-1],d1[i][j-1]+curr) max d2[i][j-1] [i] d2 i j-1 j 1 d1[i][j-1]+curr d1[i][j-1] [i] d1 i j-1 j 1 curr d3[i][j]=max(d3[i][j-1],d2[i][j-1]+curr) d3[i][j] [i] d3 i j max(d3[i][j-1],d2[i][j-1]+curr) max d3[i][j-1] [i] d3 i j-1 j 1 d2[i][j-1]+curr d2[i][j-1] [i] d2 i j-1 j 1 curr print(max(d1[-1][-1],d2[-1][-1],d3[-1][-1])) print max(d1[-1][-1],d2[-1][-1],d3[-1][-1]) max d1[-1][-1] [-1] d1 -1 -1 d2[-1][-1] [-1] d2 -1 -1 d3[-1][-1] [-1] d3 -1 -1 R,C,K= map(int,input().split(" ")) map(int,input().split(" ")) R curr= original[i][j] original[i][j] curr v= map(int,input().split(" ")) map(int,input().split(" ")) v d3=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] d3 C,K= map(int,input().split(" ")) map(int,input().split(" ")) C K= map(int,input().split(" ")) map(int,input().split(" ")) K d1=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] d1 original=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] original r,c,v= map(int,input().split(" ")) map(int,input().split(" ")) r d2=[[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] d2 c,v= map(int,input().split(" ")) map(int,input().split(" ")) c
R,C,K= map(int,input().split(" "))
original=[[0]*(C+1) for i in range(R+1)]
for _ in range(K):
    r,c,v= map(int,input().split(" "))
    original[r][c]=v
d1=[[0]*(C+1) for i in range(R+1)]
d2=[[0]*(C+1) for i in range(R+1)]
d3=[[0]*(C+1) for i in range(R+1)]
for i in range(1,R+1):
    for j in range(1,C+1):
        curr= original[i][j]
        d1[i][j]=max(d1[i-1][j]+curr,d2[i-1][j]+curr,d3[i-1][j]+curr,d1[i][j-1],curr)
        d2[i][j]=max(d2[i][j-1],d1[i][j-1]+curr)
        d3[i][j]=max(d3[i][j-1],d2[i][j-1]+curr)
print(max(d1[-1][-1],d2[-1][-1],d3[-1][-1]))