#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

r,c,k=map(int,input().split())
v=[[0]*c for _ in range(r)]
for i in range(k):
    ri,ci,val=map(int,input().split())
    v[ri-1][ci-1]=val
d=[[0]*(c*r) for _ in range(4)]
d[1][0]=v[0][0]
for i in range(1,c):
    d[1][i]=max(d[1][i-1],d[0][i-1]+v[0][i])
    d[2][i]=max(d[2][i-1],d[1][i-1]+v[0][i])
    d[3][i]=max(d[3][i-1],d[2][i-1]+v[0][i])
for i in range(c,r*c):
    m=0
    for j in range(4):
        m=max(m,d[j][i-c])
    cx=i%c
    rx=i//c
    d[0][i]=max(0,m)
    d[1][i]=max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) if cx!=0 else max(0,v[rx][cx]+m)
    d[2][i]=max(d[2][i-1],v[rx][cx]+d[1][i-1]) if cx!=0 else 0
    d[3][i]=max(d[3][i-1],v[rx][cx]+d[2][i-1]) if cx!=0 else 0
ans=0
for j in range(4):
  ans=max(ans,d[j][r*c-1])
print(ans) import math math import itertools itertools from collections import deque from collections import Counter import heapq heapq from fractions  import gcd 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 v=[[0]*c for _ in range(r)] v [[0]*c for _ in range(r)] for i in range(k):
    ri,ci,val=map(int,input().split())
    v[ri-1][ci-1]=val i range(k) range k ri,ci,val=map(int,input().split()) ri map(int,input().split()) map int input().split() ().split () input split ci val v[ri-1][ci-1]=val v[ri-1][ci-1] [ri-1] v ri-1 ri 1 ci-1 ci 1 val [0]*(c*r) for _ in range(4) for _ in range(4) _ range(4) range 4 for _ in range(4) [0]*(c*r) [0] 0 c*r c r d=[[0]*(c*r) for _ in range(4)] d [[0]*(c*r) for _ in range(4)] d[1][0]=v[0][0] d[1][0] [1] d 1 0 v[0][0] [0] v 0 0 for i in range(1,c):
    d[1][i]=max(d[1][i-1],d[0][i-1]+v[0][i])
    d[2][i]=max(d[2][i-1],d[1][i-1]+v[0][i])
    d[3][i]=max(d[3][i-1],d[2][i-1]+v[0][i]) i range(1,c) range 1 c d[1][i]=max(d[1][i-1],d[0][i-1]+v[0][i]) d[1][i] [1] d 1 i max(d[1][i-1],d[0][i-1]+v[0][i]) max d[1][i-1] [1] d 1 i-1 i 1 d[0][i-1]+v[0][i] d[0][i-1] [0] d 0 i-1 i 1 v[0][i] [0] v 0 i d[2][i]=max(d[2][i-1],d[1][i-1]+v[0][i]) d[2][i] [2] d 2 i max(d[2][i-1],d[1][i-1]+v[0][i]) max d[2][i-1] [2] d 2 i-1 i 1 d[1][i-1]+v[0][i] d[1][i-1] [1] d 1 i-1 i 1 v[0][i] [0] v 0 i d[3][i]=max(d[3][i-1],d[2][i-1]+v[0][i]) d[3][i] [3] d 3 i max(d[3][i-1],d[2][i-1]+v[0][i]) max d[3][i-1] [3] d 3 i-1 i 1 d[2][i-1]+v[0][i] d[2][i-1] [2] d 2 i-1 i 1 v[0][i] [0] v 0 i for i in range(c,r*c):
    m=0
    for j in range(4):
        m=max(m,d[j][i-c])
    cx=i%c
    rx=i//c
    d[0][i]=max(0,m)
    d[1][i]=max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) if cx!=0 else max(0,v[rx][cx]+m)
    d[2][i]=max(d[2][i-1],v[rx][cx]+d[1][i-1]) if cx!=0 else 0
    d[3][i]=max(d[3][i-1],v[rx][cx]+d[2][i-1]) if cx!=0 else 0 i range(c,r*c) range c r*c r c m=0 m 0 for j in range(4):
        m=max(m,d[j][i-c])
     j range(4) range 4 m=max(m,d[j][i-c]) m max(m,d[j][i-c]) max m d[j][i-c] [j] d j i-c i c cx=i%c cx i%c i c rx=i//c rx i//c i c d[0][i]=max(0,m) d[0][i] [0] d 0 i max(0,m) max 0 m d[1][i]=max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) if cx!=0 else max(0,v[rx][cx]+m) d[1][i] [1] d 1 i max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) if cx!=0 else max(0,v[rx][cx]+m) cx!=0 cx 0 max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) max d[1][i-1] [1] d 1 i-1 i 1 m+v[rx][cx] m v[rx][cx] [rx] v rx cx v[rx][cx]+d[0][i-1] v[rx][cx] [rx] v rx cx d[0][i-1] [0] d 0 i-1 i 1 max(0,v[rx][cx]+m) max 0 v[rx][cx]+m v[rx][cx] [rx] v rx cx m d[2][i]=max(d[2][i-1],v[rx][cx]+d[1][i-1]) if cx!=0 else 0 d[2][i] [2] d 2 i max(d[2][i-1],v[rx][cx]+d[1][i-1]) if cx!=0 else 0 cx!=0 cx 0 max(d[2][i-1],v[rx][cx]+d[1][i-1]) max d[2][i-1] [2] d 2 i-1 i 1 v[rx][cx]+d[1][i-1] v[rx][cx] [rx] v rx cx d[1][i-1] [1] d 1 i-1 i 1 0 d[3][i]=max(d[3][i-1],v[rx][cx]+d[2][i-1]) if cx!=0 else 0 d[3][i] [3] d 3 i max(d[3][i-1],v[rx][cx]+d[2][i-1]) if cx!=0 else 0 cx!=0 cx 0 max(d[3][i-1],v[rx][cx]+d[2][i-1]) max d[3][i-1] [3] d 3 i-1 i 1 v[rx][cx]+d[2][i-1] v[rx][cx] [rx] v rx cx d[2][i-1] [2] d 2 i-1 i 1 0 ans=0 ans 0 for j in range(4):
  ans=max(ans,d[j][r*c-1]) j range(4) range 4 ans=max(ans,d[j][r*c-1]) ans max(ans,d[j][r*c-1]) max ans d[j][r*c-1] [j] d j r*c-1 r*c r c 1 print(ans) print ans m=max(m,d[j][i-c]) max(m,d[j][i-c]) m cx=i%c i%c cx d=[[0]*(c*r) for _ in range(4)] [[0]*(c*r) for _ in range(4)] d val=map(int,input().split()) map(int,input().split()) val ri,ci,val=map(int,input().split()) map(int,input().split()) ri ci,val=map(int,input().split()) map(int,input().split()) ci r,c,k=map(int,input().split()) map(int,input().split()) r v=[[0]*c for _ in range(r)] [[0]*c for _ in range(r)] v m=0 0 m ans=0 0 ans ans=max(ans,d[j][r*c-1]) max(ans,d[j][r*c-1]) ans c,k=map(int,input().split()) map(int,input().split()) c rx=i//c i//c rx k=map(int,input().split()) map(int,input().split()) k
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

r,c,k=map(int,input().split())
v=[[0]*c for _ in range(r)]
for i in range(k):
    ri,ci,val=map(int,input().split())
    v[ri-1][ci-1]=val
d=[[0]*(c*r) for _ in range(4)]
d[1][0]=v[0][0]
for i in range(1,c):
    d[1][i]=max(d[1][i-1],d[0][i-1]+v[0][i])
    d[2][i]=max(d[2][i-1],d[1][i-1]+v[0][i])
    d[3][i]=max(d[3][i-1],d[2][i-1]+v[0][i])
for i in range(c,r*c):
    m=0
    for j in range(4):
        m=max(m,d[j][i-c])
    cx=i%c
    rx=i//c
    d[0][i]=max(0,m)
    d[1][i]=max(d[1][i-1],m+v[rx][cx],v[rx][cx]+d[0][i-1]) if cx!=0 else max(0,v[rx][cx]+m)
    d[2][i]=max(d[2][i-1],v[rx][cx]+d[1][i-1]) if cx!=0 else 0
    d[3][i]=max(d[3][i-1],v[rx][cx]+d[2][i-1]) if cx!=0 else 0
ans=0
for j in range(4):
  ans=max(ans,d[j][r*c-1])
print(ans)