import os,io

import sys

input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

r,c,k=list(map(int,input().split()))

dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]

m=[]

for i in range(r):

  m.append([])

  for j in range(c):

    m[i].append(0)

for i in range(k):

  ri,ci,v=list(map(int,input().split()))

  m[ri-1][ci-1]=v

dp[0][0][0]=0

dp[1][0][0]=m[0][0]

dp[2][0][0]=m[0][0]

dp[3][0][0]=m[0][0]

for i in range(r):

  for j in range(c):

    if j+1<c:

      dp[0][i][j+1]=max(dp[0][i][j+1],dp[0][i][j])

      dp[1][i][j+1]=max(dp[1][i][j],max(dp[1][i][j+1],dp[0][i][j]+m[i][j+1]))

      dp[2][i][j+1]=max(dp[2][i][j],max(dp[2][i][j+1],dp[1][i][j]+m[i][j+1]))

      dp[3][i][j+1]=max(dp[3][i][j],max(dp[3][i][j+1],dp[2][i][j]+m[i][j+1]))

    if i+1<r:

      dp[0][i+1][j]=dp[3][i][j]

      dp[1][i+1][j]=dp[3][i][j]+m[i+1][j]

      dp[2][i+1][j]=dp[3][i][j]+m[i+1][j]

      dp[3][i+1][j]=dp[3][i][j]+m[i+1][j]

print((dp[3][r-1][c-1]))

    
import os,io

import sys

input=io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

r,c,k=list(map(int,input().split()))

dp = [0]*(r*c*4)

m=[]

for i in range(r):

  m.append([])

  for j in range(c):

    m[i].append(0)

for i in range(k):

  ri,ci,v=list(map(int,input().split()))

  m[ri-1][ci-1]=v

dp[0*r*c+0*c+0]=0

dp[1*r*c+0*c+0]=m[0][0]

dp[2*r*c+0*c+0]=m[0][0]

dp[3*r*c+0*c+0]=m[0][0]

for i in range(r):

  for j in range(c):

    if j+1<c:

      dp[0*r*c+i*c+j+1]=max(dp[0*r*c+i*c+j+1],dp[0*r*c+i*c+j])

      dp[1*r*c+i*c+j+1]=max(dp[1*r*c+i*c+j],max(dp[1*r*c+i*c+j+1],dp[0*r*c+i*c+j]+m[i][j+1]))

      dp[2*r*c+i*c+j+1]=max(dp[2*r*c+i*c+j],max(dp[2*r*c+i*c+j+1],dp[1*r*c+i*c+j]+m[i][j+1]))

      dp[3*r*c+i*c+j+1]=max(dp[3*r*c+i*c+j],max(dp[3*r*c+i*c+j+1],dp[2*r*c+i*c+j]+m[i][j+1]))

    if i+1<r:

      dp[0*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]

      dp[1*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]+m[i+1][j]

      dp[2*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]+m[i+1][j]

      dp[3*r*c+(i+1)*c+j]=dp[3*r*c+i*c+j]+m[i+1][j]

print((dp[3*r*c+(r-1)*c+c-1]))

    
import os, io
import sys

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
r, c, k = list(map(int, input().split()))
dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)]
m = []
for i in range(r):
    m.append([])
    for j in range(c):
        m[i].append(0)
for i in range(k):
    ri, ci, v = list(map(int, input().split()))
    m[ri - 1][ci - 1] = v
dp[0][0][0] = 0
dp[1][0][0] = m[0][0]
dp[2][0][0] = m[0][0]
dp[3][0][0] = m[0][0]
for i in range(r):
    for j in range(c):
        if j + 1 < c:
            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j])
            dp[1][i][j + 1] = max(
                dp[1][i][j], max(dp[1][i][j + 1], dp[0][i][j] + m[i][j + 1])
            )
            dp[2][i][j + 1] = max(
                dp[2][i][j], max(dp[2][i][j + 1], dp[1][i][j] + m[i][j + 1])
            )
            dp[3][i][j + 1] = max(
                dp[3][i][j], max(dp[3][i][j + 1], dp[2][i][j] + m[i][j + 1])
            )
        if i + 1 < r:
            dp[0][i + 1][j] = dp[3][i][j]
            dp[1][i + 1][j] = dp[3][i][j] + m[i + 1][j]
            dp[2][i + 1][j] = dp[3][i][j] + m[i + 1][j]
            dp[3][i + 1][j] = dp[3][i][j] + m[i + 1][j]
print((dp[3][r - 1][c - 1]))

import os, io
import sys

input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
r, c, k = list(map(int, input().split()))
dp = [0] * (r * c * 4)
m = []
for i in range(r):
    m.append([])
    for j in range(c):
        m[i].append(0)
for i in range(k):
    ri, ci, v = list(map(int, input().split()))
    m[ri - 1][ci - 1] = v
dp[0 * r * c + 0 * c + 0] = 0
dp[1 * r * c + 0 * c + 0] = m[0][0]
dp[2 * r * c + 0 * c + 0] = m[0][0]
dp[3 * r * c + 0 * c + 0] = m[0][0]
for i in range(r):
    for j in range(c):
        if j + 1 < c:
            dp[0 * r * c + i * c + j + 1] = max(
                dp[0 * r * c + i * c + j + 1], dp[0 * r * c + i * c + j]
            )
            dp[1 * r * c + i * c + j + 1] = max(
                dp[1 * r * c + i * c + j],
                max(
                    dp[1 * r * c + i * c + j + 1],
                    dp[0 * r * c + i * c + j] + m[i][j + 1],
                ),
            )
            dp[2 * r * c + i * c + j + 1] = max(
                dp[2 * r * c + i * c + j],
                max(
                    dp[2 * r * c + i * c + j + 1],
                    dp[1 * r * c + i * c + j] + m[i][j + 1],
                ),
            )
            dp[3 * r * c + i * c + j + 1] = max(
                dp[3 * r * c + i * c + j],
                max(
                    dp[3 * r * c + i * c + j + 1],
                    dp[2 * r * c + i * c + j] + m[i][j + 1],
                ),
            )
        if i + 1 < r:
            dp[0 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j]
            dp[1 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]
            dp[2 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]
            dp[3 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j]
print((dp[3 * r * c + (r - 1) * c + c - 1]))

-dp = [[[0 for y in range(c)] for z in range(r)] for P in range(4)] +dp = [0] * (r * c * 4) -dp[0][0][0] = 0 -dp[1][0][0] = m[0][0] -dp[2][0][0] = m[0][0] -dp[3][0][0] = m[0][0] +dp[0 * r * c + 0 * c + 0] = 0 +dp[1 * r * c + 0 * c + 0] = m[0][0] +dp[2 * r * c + 0 * c + 0] = m[0][0] +dp[3 * r * c + 0 * c + 0] = m[0][0] -            dp[0][i][j + 1] = max(dp[0][i][j + 1], dp[0][i][j]) -            dp[1][i][j + 1] = max( -                dp[1][i][j], max(dp[1][i][j + 1], dp[0][i][j] + m[i][j + 1]) +            dp[0 * r * c + i * c + j + 1] = max( +                dp[0 * r * c + i * c + j + 1], dp[0 * r * c + i * c + j] -            dp[2][i][j + 1] = max( -                dp[2][i][j], max(dp[2][i][j + 1], dp[1][i][j] + m[i][j + 1]) +            dp[1 * r * c + i * c + j + 1] = max( +                dp[1 * r * c + i * c + j], +                max( +                    dp[1 * r * c + i * c + j + 1], +                    dp[0 * r * c + i * c + j] + m[i][j + 1], +                ), -            dp[3][i][j + 1] = max( -                dp[3][i][j], max(dp[3][i][j + 1], dp[2][i][j] + m[i][j + 1]) +            dp[2 * r * c + i * c + j + 1] = max( +                dp[2 * r * c + i * c + j], +                max( +                    dp[2 * r * c + i * c + j + 1], +                    dp[1 * r * c + i * c + j] + m[i][j + 1], +                ), +            ) +            dp[3 * r * c + i * c + j + 1] = max( +                dp[3 * r * c + i * c + j], +                max( +                    dp[3 * r * c + i * c + j + 1], +                    dp[2 * r * c + i * c + j] + m[i][j + 1], +                ), -            dp[0][i + 1][j] = dp[3][i][j] -            dp[1][i + 1][j] = dp[3][i][j] + m[i + 1][j] -            dp[2][i + 1][j] = dp[3][i][j] + m[i + 1][j] -            dp[3][i + 1][j] = dp[3][i][j] + m[i + 1][j] -print((dp[3][r - 1][c - 1])) +            dp[0 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] +            dp[1 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j] +            dp[2 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j] +            dp[3 * r * c + (i + 1) * c + j] = dp[3 * r * c + i * c + j] + m[i + 1][j] +print((dp[3 * r * c + (r - 1) * c + c - 1]))