import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

R,C,K = LI()
r,c,v = LIR(K,3)

def index(i,j,k):
    return k*C*R + i*C + j

a = [[0]*C for _ in range(R)]
for i in range(K):
    a[r[i]-1][c[i]-1] = v[i]

dp = [0]*(4*C*R)
dp[index(0,0,1)] = a[0][0]

for i in range(R):
    for j in range(C):
        if i == j == 0:
            continue
        upper_max = 0
        if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
        for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4)

ans = 0
for k in range(4):
    ans = max(ans,dp[index(R-1,C-1,k)])

print(ans) import sys sys import math math from collections import defaultdict from bisect import bisect_left, bisect_right sys.setrecursionlimit(10**7) sys.setrecursionlimit sys setrecursionlimit 10**7 10 7 def input():
    return sys.stdin.readline()[:-1] input return sys.stdin.readline()[:-1] sys.stdin.readline()[:-1] sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline :-1 -1 mod = 10**9 + 7 mod 10**9 + 7 10**9 10 9 7 def I(): return int(input()) I def LI(): return list(map(int, input().split())) LI def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

################# LIR if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

################# row <= 0 row 0 [] for _ in range(col) for _ in range(col) _ range(col) range col for _ in range(col) [] return [[] for _ in range(col)] [[] for _ in range(col)] elif col == 1:
        return [I() for _ in range(row)]
     col == 1 col 1 I() for _ in range(row) for _ in range(row) _ range(row) range row for _ in range(row) I() I return [I() for _ in range(row)] [I() for _ in range(row)] LI() for _ in range(row) for _ in range(row) _ range(row) range row for _ in range(row) LI() LI read_all = [LI() for _ in range(row)] read_all [LI() for _ in range(row)] return map(list, zip(*read_all)) map(list, zip(*read_all)) map list zip(*read_all) zip *read_all read_all row row col col R,C,K = LI() R LI() LI C K r,c,v = LIR(K,3) r LIR(K,3) LIR K 3 c v def index(i,j,k):
    return k*C*R + i*C + j index return k*C*R + i*C + j k*C*R + i*C + j k*C*R + i*C k*C*R k*C k C R i*C i C j i i j j k k [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C a = [[0]*C for _ in range(R)] a [[0]*C for _ in range(R)] for i in range(K):
    a[r[i]-1][c[i]-1] = v[i] i range(K) range K a[r[i]-1][c[i]-1] = v[i] a[r[i]-1][c[i]-1] [r[i]-1] a r[i]-1 r[i] r i 1 c[i]-1 c[i] c i 1 v[i] v i dp = [0]*(4*C*R) dp [0]*(4*C*R) [0] 0 4*C*R 4*C 4 C R dp[index(0,0,1)] = a[0][0] dp[index(0,0,1)] dp index(0,0,1) index 0 0 1 a[0][0] [0] a 0 0 for i in range(R):
    for j in range(C):
        if i == j == 0:
            continue
        upper_max = 0
        if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
        for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4) i range(R) range R for j in range(C):
        if i == j == 0:
            continue
        upper_max = 0
        if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
        for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4) j range(C) range C if i == j == 0:
            continue
         i == j == 0 i == j i j 0 continue upper_max = 0 upper_max 0 if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
         i >= 1 i 1 for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
         k range(4) range 4 upper_max = max(upper_max,dp[index(i-1,j,k)]) upper_max max(upper_max,dp[index(i-1,j,k)]) max upper_max dp[index(i-1,j,k)] dp index(i-1,j,k) index i-1 i 1 j k for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4) k range(4) range 4 val1 = 0 val1 0 val2 = 0 val2 0 val3 = 0 val3 0 val4 = 0 val4 0 if j >= 1:
                val1 = dp[index(i,j-1,k)]
             j >= 1 j 1 val1 = dp[index(i,j-1,k)] val1 dp[index(i,j-1,k)] dp index(i,j-1,k) index i j-1 j 1 k if k == 0 and i >= 1:
                val2 = upper_max
             k == 0 and i >= 1 k == 0 k 0 i >= 1 i 1 val2 = upper_max val2 upper_max if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
             a[i][j] != 0 a[i][j] [i] a i j 0 if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                 k == 1 and i >= 1 k == 1 k 1 i >= 1 i 1 val3 = upper_max + a[i][j] val3 upper_max + a[i][j] upper_max a[i][j] [i] a i j if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
             k >= 1 and j >= 1 k >= 1 k 1 j >= 1 j 1 val4 = dp[index(i,j-1,k-1)] + a[i][j] val4 dp[index(i,j-1,k-1)] + a[i][j] dp[index(i,j-1,k-1)] dp index(i,j-1,k-1) index i j-1 j 1 k-1 k 1 a[i][j] [i] a i j dp[index(i,j,k)] = max(val1,val2,val3,val4) dp[index(i,j,k)] dp index(i,j,k) index i j k max(val1,val2,val3,val4) max val1 val2 val3 val4 ans = 0 ans 0 for k in range(4):
    ans = max(ans,dp[index(R-1,C-1,k)]) k range(4) range 4 ans = max(ans,dp[index(R-1,C-1,k)]) ans max(ans,dp[index(R-1,C-1,k)]) max ans dp[index(R-1,C-1,k)] dp index(R-1,C-1,k) index R-1 R 1 C-1 C 1 k print(ans) print ans r,c,v = LIR(K,3) LIR(K,3) r def LI(): return list(map(int, input().split())) def LI(): return list(map(int, input().split())) LI upper_max = 0 0 upper_max upper_max = max(upper_max,dp[index(i-1,j,k)]) max(upper_max,dp[index(i-1,j,k)]) upper_max c,v = LIR(K,3) LIR(K,3) c a = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] a val4 = dp[index(i,j-1,k-1)] + a[i][j] dp[index(i,j-1,k-1)] + a[i][j] val4 def input():
    return sys.stdin.readline()[:-1] def input():
    return sys.stdin.readline()[:-1] input mod = 10**9 + 7 10**9 + 7 mod val1 = 0 0 val1 ans = 0 0 ans val2 = 0 0 val2 val3 = 0 0 val3 val3 = upper_max + a[i][j] upper_max + a[i][j] val3 def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

################# def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

################# LIR K = LI() LI() K val1 = dp[index(i,j-1,k)] dp[index(i,j-1,k)] val1 val2 = upper_max upper_max val2 def I(): return int(input()) def I(): return int(input()) I def index(i,j,k):
    return k*C*R + i*C + j def index(i,j,k):
    return k*C*R + i*C + j index R,C,K = LI() LI() R C,K = LI() LI() C dp = [0]*(4*C*R) [0]*(4*C*R) dp v = LIR(K,3) LIR(K,3) v ans = max(ans,dp[index(R-1,C-1,k)]) max(ans,dp[index(R-1,C-1,k)]) ans val4 = 0 0 val4
import sys
import math
from collections import defaultdict
from bisect import bisect_left, bisect_right

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def LI(): return list(map(int, input().split()))
def LIR(row,col):
    if row <= 0:
        return [[] for _ in range(col)]
    elif col == 1:
        return [I() for _ in range(row)]
    else:
        read_all = [LI() for _ in range(row)]
        return map(list, zip(*read_all))

#################

R,C,K = LI()
r,c,v = LIR(K,3)

def index(i,j,k):
    return k*C*R + i*C + j

a = [[0]*C for _ in range(R)]
for i in range(K):
    a[r[i]-1][c[i]-1] = v[i]

dp = [0]*(4*C*R)
dp[index(0,0,1)] = a[0][0]

for i in range(R):
    for j in range(C):
        if i == j == 0:
            continue
        upper_max = 0
        if i >= 1:
            for k in range(4):
                upper_max = max(upper_max,dp[index(i-1,j,k)])
        for k in range(4):
            val1 = 0
            val2 = 0
            val3 = 0
            val4 = 0
            if j >= 1:
                val1 = dp[index(i,j-1,k)]
            if k == 0 and i >= 1:
                val2 = upper_max
            if a[i][j] != 0:
                if k == 1 and i >= 1:
                    val3 = upper_max + a[i][j]
                if k >= 1 and j >= 1:
                    val4 = dp[index(i,j-1,k-1)] + a[i][j]
            dp[index(i,j,k)] = max(val1,val2,val3,val4)

ans = 0
for k in range(4):
    ans = max(ans,dp[index(R-1,C-1,k)])

print(ans)