R,C,k = map(int,input().split())
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
item = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
    r,c,v = map(int,input().split())
    dp1[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        a = dp1[i][j]
        dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
        dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
        dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a)

print(max(dp1[R][C],dp2[R][C],dp3[R][C])) 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 dp1 = [[0]*(C+1) for i in range(R+1)] dp1 [[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 dp2 = [[0]*(C+1) for i in range(R+1)] dp2 [[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 dp3 = [[0]*(C+1) for i in range(R+1)] dp3 [[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 item = [[0]*(C+1) for i in range(R+1)] item [[0]*(C+1) for i in range(R+1)] for i in range(k):
    r,c,v = map(int,input().split())
    dp1[r][c] = v i 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 dp1[r][c] = v dp1[r][c] [r] dp1 r c v for i in range(1,R+1):
    for j in range(1,C+1):
        a = dp1[i][j]
        dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
        dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
        dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a) i range(1,R+1) range 1 R+1 R 1 for j in range(1,C+1):
        a = dp1[i][j]
        dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
        dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
        dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a) j range(1,C+1) range 1 C+1 C 1 a = dp1[i][j] a dp1[i][j] [i] dp1 i j dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1]) dp3[i][j] [i] dp3 i j max(dp2[i][j-1]+a,dp3[i][j-1]) max dp2[i][j-1]+a dp2[i][j-1] [i] dp2 i j-1 j 1 a dp3[i][j-1] [i] dp3 i j-1 j 1 dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1]) dp2[i][j] [i] dp2 i j max(dp1[i][j-1]+a,dp2[i][j-1]) max dp1[i][j-1]+a dp1[i][j-1] [i] dp1 i j-1 j 1 a dp2[i][j-1] [i] dp2 i j-1 j 1 dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a) dp1[i][j] [i] dp1 i j max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a) max dp1[i-1][j]+a dp1[i-1][j] [i-1] dp1 i-1 i 1 j a dp2[i-1][j]+a dp2[i-1][j] [i-1] dp2 i-1 i 1 j a dp3[i-1][j]+a dp3[i-1][j] [i-1] dp3 i-1 i 1 j a dp1[i][j-1] [i] dp1 i j-1 j 1 a print(max(dp1[R][C],dp2[R][C],dp3[R][C])) print max(dp1[R][C],dp2[R][C],dp3[R][C]) max dp1[R][C] [R] dp1 R C dp2[R][C] [R] dp2 R C dp3[R][C] [R] dp3 R C C,k = map(int,input().split()) map(int,input().split()) C dp2 = [[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp2 v = map(int,input().split()) map(int,input().split()) v dp1 = [[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp1 k = map(int,input().split()) map(int,input().split()) k c,v = map(int,input().split()) map(int,input().split()) c item = [[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] item R,C,k = map(int,input().split()) map(int,input().split()) R dp3 = [[0]*(C+1) for i in range(R+1)] [[0]*(C+1) for i in range(R+1)] dp3 r,c,v = map(int,input().split()) map(int,input().split()) r a = dp1[i][j] dp1[i][j] a
R,C,k = map(int,input().split())
dp1 = [[0]*(C+1) for i in range(R+1)]
dp2 = [[0]*(C+1) for i in range(R+1)]
dp3 = [[0]*(C+1) for i in range(R+1)]
item = [[0]*(C+1) for i in range(R+1)]
for i in range(k):
    r,c,v = map(int,input().split())
    dp1[r][c] = v

for i in range(1,R+1):
    for j in range(1,C+1):
        a = dp1[i][j]
        dp3[i][j] = max(dp2[i][j-1]+a,dp3[i][j-1])
        dp2[i][j] = max(dp1[i][j-1]+a,dp2[i][j-1])
        dp1[i][j] = max(dp1[i-1][j]+a,dp2[i-1][j]+a,dp3[i-1][j]+a,dp1[i][j-1],a)

print(max(dp1[R][C],dp2[R][C],dp3[R][C]))