#!/usr/bin/env python3

import sys
input=sys.stdin.readline

r,c,k=map(int,input().split())
items=[0]*(r*c)
for _ in range(k):
    tr,tc,tv=map(int,input().split())
    items[c*(tr-1)+tc-1]=tv
dp=[0]*(4*r*c)
for i in range(1,r+1):
    for j in range(1,c+1):
        tv=items[c*(i-1)+j-1]
        change_pos=4*(c*(i-1)+j-1)
        left_pos=4*(c*(i-2)+j-1)
        up_pos=4*(c*(i-1)+j-2)
        if i!=1:
          left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3])
        else:
          left_max=0
        if j!=1:
          dp[change_pos]=max(dp[up_pos],left_max)
          dp[change_pos+1]=max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv)        
          dp[change_pos+2]=max(dp[up_pos+2],dp[up_pos+1]+tv)
          dp[change_pos+3]=max(dp[up_pos+3],dp[up_pos+2]+tv)
        else:
          dp[change_pos]=left_max
          dp[change_pos+1]=left_max+tv
print(max(dp[-1],dp[-2],dp[-3],dp[-4])) import sys sys input=sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline r,c,k=map(int,input().split()) r map(int,input().split()) map int input().split() ().split () input split c k items=[0]*(r*c) items [0]*(r*c) [0] 0 r*c r c for _ in range(k):
    tr,tc,tv=map(int,input().split())
    items[c*(tr-1)+tc-1]=tv _ range(k) range k tr,tc,tv=map(int,input().split()) tr map(int,input().split()) map int input().split() ().split () input split tc tv items[c*(tr-1)+tc-1]=tv items[c*(tr-1)+tc-1] items c*(tr-1)+tc-1 c*(tr-1)+tc c*(tr-1) c tr-1 tr 1 tc 1 tv dp=[0]*(4*r*c) dp [0]*(4*r*c) [0] 0 4*r*c 4*r 4 r c for i in range(1,r+1):
    for j in range(1,c+1):
        tv=items[c*(i-1)+j-1]
        change_pos=4*(c*(i-1)+j-1)
        left_pos=4*(c*(i-2)+j-1)
        up_pos=4*(c*(i-1)+j-2)
        if i!=1:
          left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3])
        else:
          left_max=0
        if j!=1:
          dp[change_pos]=max(dp[up_pos],left_max)
          dp[change_pos+1]=max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv)        
          dp[change_pos+2]=max(dp[up_pos+2],dp[up_pos+1]+tv)
          dp[change_pos+3]=max(dp[up_pos+3],dp[up_pos+2]+tv)
        else:
          dp[change_pos]=left_max
          dp[change_pos+1]=left_max+tv i range(1,r+1) range 1 r+1 r 1 for j in range(1,c+1):
        tv=items[c*(i-1)+j-1]
        change_pos=4*(c*(i-1)+j-1)
        left_pos=4*(c*(i-2)+j-1)
        up_pos=4*(c*(i-1)+j-2)
        if i!=1:
          left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3])
        else:
          left_max=0
        if j!=1:
          dp[change_pos]=max(dp[up_pos],left_max)
          dp[change_pos+1]=max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv)        
          dp[change_pos+2]=max(dp[up_pos+2],dp[up_pos+1]+tv)
          dp[change_pos+3]=max(dp[up_pos+3],dp[up_pos+2]+tv)
        else:
          dp[change_pos]=left_max
          dp[change_pos+1]=left_max+tv j range(1,c+1) range 1 c+1 c 1 tv=items[c*(i-1)+j-1] tv items[c*(i-1)+j-1] items c*(i-1)+j-1 c*(i-1)+j c*(i-1) c i-1 i 1 j 1 change_pos=4*(c*(i-1)+j-1) change_pos 4*(c*(i-1)+j-1) 4 c*(i-1)+j-1 c*(i-1)+j c*(i-1) c i-1 i 1 j 1 left_pos=4*(c*(i-2)+j-1) left_pos 4*(c*(i-2)+j-1) 4 c*(i-2)+j-1 c*(i-2)+j c*(i-2) c i-2 i 2 j 1 up_pos=4*(c*(i-1)+j-2) up_pos 4*(c*(i-1)+j-2) 4 c*(i-1)+j-2 c*(i-1)+j c*(i-1) c i-1 i 1 j 2 if i!=1:
          left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3])
        else:
          left_max=0
         i!=1 i 1 left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3]) left_max max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3]) max dp[left_pos] dp left_pos dp[left_pos+1] dp left_pos+1 left_pos 1 dp[left_pos+2] dp left_pos+2 left_pos 2 dp[left_pos+3] dp left_pos+3 left_pos 3 left_max=0 left_max 0 if j!=1:
          dp[change_pos]=max(dp[up_pos],left_max)
          dp[change_pos+1]=max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv)        
          dp[change_pos+2]=max(dp[up_pos+2],dp[up_pos+1]+tv)
          dp[change_pos+3]=max(dp[up_pos+3],dp[up_pos+2]+tv)
        else:
          dp[change_pos]=left_max
          dp[change_pos+1]=left_max+tv j!=1 j 1 dp[change_pos]=max(dp[up_pos],left_max) dp[change_pos] dp change_pos max(dp[up_pos],left_max) max dp[up_pos] dp up_pos left_max dp[change_pos+1]=max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv) dp[change_pos+1] dp change_pos+1 change_pos 1 max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv) max dp[up_pos+1] dp up_pos+1 up_pos 1 dp[up_pos]+tv dp[up_pos] dp up_pos tv left_max+tv left_max tv dp[change_pos+2]=max(dp[up_pos+2],dp[up_pos+1]+tv) dp[change_pos+2] dp change_pos+2 change_pos 2 max(dp[up_pos+2],dp[up_pos+1]+tv) max dp[up_pos+2] dp up_pos+2 up_pos 2 dp[up_pos+1]+tv dp[up_pos+1] dp up_pos+1 up_pos 1 tv dp[change_pos+3]=max(dp[up_pos+3],dp[up_pos+2]+tv) dp[change_pos+3] dp change_pos+3 change_pos 3 max(dp[up_pos+3],dp[up_pos+2]+tv) max dp[up_pos+3] dp up_pos+3 up_pos 3 dp[up_pos+2]+tv dp[up_pos+2] dp up_pos+2 up_pos 2 tv dp[change_pos]=left_max dp[change_pos] dp change_pos left_max dp[change_pos+1]=left_max+tv dp[change_pos+1] dp change_pos+1 change_pos 1 left_max+tv left_max tv print(max(dp[-1],dp[-2],dp[-3],dp[-4])) print max(dp[-1],dp[-2],dp[-3],dp[-4]) max dp[-1] dp -1 dp[-2] dp -2 dp[-3] dp -3 dp[-4] dp -4 up_pos=4*(c*(i-1)+j-2) 4*(c*(i-1)+j-2) up_pos input=sys.stdin.readline sys.stdin.readline input left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3]) max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3]) left_max left_pos=4*(c*(i-2)+j-1) 4*(c*(i-2)+j-1) left_pos c,k=map(int,input().split()) map(int,input().split()) c tv=items[c*(i-1)+j-1] items[c*(i-1)+j-1] tv r,c,k=map(int,input().split()) map(int,input().split()) r tc,tv=map(int,input().split()) map(int,input().split()) tc tv=map(int,input().split()) map(int,input().split()) tv items=[0]*(r*c) [0]*(r*c) items left_max=0 0 left_max tr,tc,tv=map(int,input().split()) map(int,input().split()) tr k=map(int,input().split()) map(int,input().split()) k dp=[0]*(4*r*c) [0]*(4*r*c) dp change_pos=4*(c*(i-1)+j-1) 4*(c*(i-1)+j-1) change_pos
#!/usr/bin/env python3

import sys
input=sys.stdin.readline

r,c,k=map(int,input().split())
items=[0]*(r*c)
for _ in range(k):
    tr,tc,tv=map(int,input().split())
    items[c*(tr-1)+tc-1]=tv
dp=[0]*(4*r*c)
for i in range(1,r+1):
    for j in range(1,c+1):
        tv=items[c*(i-1)+j-1]
        change_pos=4*(c*(i-1)+j-1)
        left_pos=4*(c*(i-2)+j-1)
        up_pos=4*(c*(i-1)+j-2)
        if i!=1:
          left_max=max(dp[left_pos],dp[left_pos+1],dp[left_pos+2],dp[left_pos+3])
        else:
          left_max=0
        if j!=1:
          dp[change_pos]=max(dp[up_pos],left_max)
          dp[change_pos+1]=max(dp[up_pos+1],dp[up_pos]+tv,left_max+tv)        
          dp[change_pos+2]=max(dp[up_pos+2],dp[up_pos+1]+tv)
          dp[change_pos+3]=max(dp[up_pos+3],dp[up_pos+2]+tv)
        else:
          dp[change_pos]=left_max
          dp[change_pos+1]=left_max+tv
print(max(dp[-1],dp[-2],dp[-3],dp[-4]))