#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n-r)

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    R, C, K = LI()
    rcv = LIR1(K)

    # dp = make_list(R+1, C+1, 4)
    dp = make_list(C+1, 4)
    table = make_list(R, C)

    for r, c, v in rcv: table[r][c] = v + 1

    for r in range(R):
        newdp = [[max(p), 0, 0, 0] for p in dp]
        for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
        dp = newdp

    print(max(dp[C-1]))


if __name__ == '__main__':
    main() from collections import defaultdict, deque, Counter, OrderedDict from bisect import bisect_left, bisect_right from functools import reduce, lru_cache from heapq import heappush, heappop, heapify import itertools itertools import math, fractions math fractions import sys, copy sys copy def L(): return sys.stdin.readline().split() L def I(): return int(sys.stdin.readline().rstrip()) I def SL(): return list(sys.stdin.readline().rstrip()) SL int(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) int x def LI(): return [int(x) for x in sys.stdin.readline().split()] LI int(x) - 1 for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() int(x) - 1 int(x) int x 1 def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] LI1 list(x) for x in sys.stdin.readline().split() for x in sys.stdin.readline().split() x sys.stdin.readline().split() sys.stdin.readline().split sys.stdin.readline() sys.stdin.readline sys.stdin sys stdin readline split for x in sys.stdin.readline().split() list(x) list x def LS(): return [list(x) for x in sys.stdin.readline().split()] LS I() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) I() I def IR(n): return [I() for _ in range(n)] IR n n LI() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI() LI def LIR(n): return [LI() for _ in range(n)] LIR n n LI1() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LI1() LI1 def LIR1(n): return [LI1() for _ in range(n)] LIR1 n n SL() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) SL() SL def SR(n): return [SL() for _ in range(n)] SR n n LS() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) LS() LS def LSR(n): return [LS() for _ in range(n)] LSR n n L() for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) L() L def LR(n): return [L() for _ in range(n)] LR n n def perm(n, r): return math.factorial(n) // math.factorial(r) perm n n r r def comb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n-r) comb n n r r make_list(*args, default=default) for _ in range(n) for _ in range(n) _ range(n) range n for _ in range(n) make_list(*args, default=default) make_list *args args default=default default default def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] make_list n n default=0 default 0 *args alphabets = "abcdefghijklmnopqrstuvwxyz" alphabets "abcdefghijklmnopqrstuvwxyz" ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ALPHABETS "ABCDEFGHIJKLMNOPQRSTUVWXYZ" sys.setrecursionlimit(1000000) sys.setrecursionlimit sys setrecursionlimit 1000000 dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] dire [[1, 0], [0, 1], [-1, 0], [0, -1]] [1, 0] 1 0 [0, 1] 0 1 [-1, 0] -1 0 [0, -1] 0 -1 dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] dire8 [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] [1, 0] 1 0 [1, 1] 1 1 [0, 1] 0 1 [-1, 1] -1 1 [-1, 0] -1 0 [-1, -1] -1 -1 [0, -1] 0 -1 [1, -1] 1 -1 MOD = 1000000007 MOD 1000000007 INF = float("inf") INF float("inf") float "inf" def main():
    R, C, K = LI()
    rcv = LIR1(K)

    # dp = make_list(R+1, C+1, 4)
    dp = make_list(C+1, 4)
    table = make_list(R, C)

    for r, c, v in rcv: table[r][c] = v + 1

    for r in range(R):
        newdp = [[max(p), 0, 0, 0] for p in dp]
        for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
        dp = newdp

    print(max(dp[C-1])) main R, C, K = LI() R LI() LI C K rcv = LIR1(K) rcv LIR1(K) LIR1 K dp = make_list(C+1, 4) dp make_list(C+1, 4) make_list C+1 C 1 4 table = make_list(R, C) table make_list(R, C) make_list R C for r, c, v in rcv: table[r][c] = v + 1

     r c v rcv for r in range(R):
        newdp = [[max(p), 0, 0, 0] for p in dp]
        for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
        dp = newdp

     r range(R) range R [max(p), 0, 0, 0] for p in dp for p in dp p dp for p in dp [max(p), 0, 0, 0] max(p) max p 0 0 0 newdp = [[max(p), 0, 0, 0] for p in dp] newdp [[max(p), 0, 0, 0] for p in dp] for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
         c range(C) range C for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
             i range(1, 4)[::-1] (1, 4) range 1 4 ::-1 -1 newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c]) newdp[c][i] [c] newdp c i max(newdp[c][i], newdp[c][i - 1] + table[r][c]) max newdp[c][i] [c] newdp c i newdp[c][i - 1] + table[r][c] newdp[c][i - 1] [c] newdp c i - 1 i 1 table[r][c] [r] table r c newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i]) newdp[c + 1][i] [c + 1] newdp c + 1 c 1 i max(newdp[c + 1][i], newdp[c][i]) max newdp[c + 1][i] [c + 1] newdp c + 1 c 1 i newdp[c][i] [c] newdp c i newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0]) newdp[c + 1][0] [c + 1] newdp c + 1 c 1 0 max(newdp[c + 1][0], newdp[c][0]) max newdp[c + 1][0] [c + 1] newdp c + 1 c 1 0 newdp[c][0] [c] newdp c 0 dp = newdp dp newdp print(max(dp[C-1])) print max(dp[C-1]) max dp[C-1] dp C-1 C 1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main INF = float("inf") float("inf") INF ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ALPHABETS def LSR(n): return [LS() for _ in range(n)] def LSR(n): return [LS() for _ in range(n)] LSR dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]] dire8 def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()] LI1 MOD = 1000000007 1000000007 MOD def LIR(n): return [LI() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] LIR dire = [[1, 0], [0, 1], [-1, 0], [0, -1]] [[1, 0], [0, 1], [-1, 0], [0, -1]] dire def LI(): return [int(x) for x in sys.stdin.readline().split()] def LI(): return [int(x) for x in sys.stdin.readline().split()] LI def comb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n-r) def comb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n-r) comb def main():
    R, C, K = LI()
    rcv = LIR1(K)

    # dp = make_list(R+1, C+1, 4)
    dp = make_list(C+1, 4)
    table = make_list(R, C)

    for r, c, v in rcv: table[r][c] = v + 1

    for r in range(R):
        newdp = [[max(p), 0, 0, 0] for p in dp]
        for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
        dp = newdp

    print(max(dp[C-1])) def main():
    R, C, K = LI()
    rcv = LIR1(K)

    # dp = make_list(R+1, C+1, 4)
    dp = make_list(C+1, 4)
    table = make_list(R, C)

    for r, c, v in rcv: table[r][c] = v + 1

    for r in range(R):
        newdp = [[max(p), 0, 0, 0] for p in dp]
        for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
        dp = newdp

    print(max(dp[C-1])) main def perm(n, r): return math.factorial(n) // math.factorial(r) def perm(n, r): return math.factorial(n) // math.factorial(r) perm def I(): return int(sys.stdin.readline().rstrip()) def I(): return int(sys.stdin.readline().rstrip()) I def LS(): return [list(x) for x in sys.stdin.readline().split()] def LS(): return [list(x) for x in sys.stdin.readline().split()] LS def LR(n): return [L() for _ in range(n)] def LR(n): return [L() for _ in range(n)] LR alphabets = "abcdefghijklmnopqrstuvwxyz" "abcdefghijklmnopqrstuvwxyz" alphabets def SR(n): return [SL() for _ in range(n)] def SR(n): return [SL() for _ in range(n)] SR def L(): return sys.stdin.readline().split() def L(): return sys.stdin.readline().split() L def SL(): return list(sys.stdin.readline().rstrip()) def SL(): return list(sys.stdin.readline().rstrip()) SL def LIR1(n): return [LI1() for _ in range(n)] def LIR1(n): return [LI1() for _ in range(n)] LIR1 def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)] make_list def IR(n): return [I() for _ in range(n)] def IR(n): return [I() for _ in range(n)] IR
#!usr/bin/env python3
from collections import defaultdict, deque, Counter, OrderedDict
from bisect import bisect_left, bisect_right
from functools import reduce, lru_cache
from heapq import heappush, heappop, heapify

import itertools
import math, fractions
import sys, copy

def L(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline().rstrip())
def SL(): return list(sys.stdin.readline().rstrip())
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return [list(x) for x in sys.stdin.readline().split()]
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def LIR1(n): return [LI1() for _ in range(n)]
def SR(n): return [SL() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
def LR(n): return [L() for _ in range(n)]

def perm(n, r): return math.factorial(n) // math.factorial(r)
def comb(n, r): return math.factorial(n) // math.factorial(r) // math.factorial(n-r)

def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]

alphabets = "abcdefghijklmnopqrstuvwxyz"
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

sys.setrecursionlimit(1000000)
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
MOD = 1000000007
INF = float("inf")

def main():
    R, C, K = LI()
    rcv = LIR1(K)

    # dp = make_list(R+1, C+1, 4)
    dp = make_list(C+1, 4)
    table = make_list(R, C)

    for r, c, v in rcv: table[r][c] = v + 1

    for r in range(R):
        newdp = [[max(p), 0, 0, 0] for p in dp]
        for c in range(C):
            for i in range(1, 4)[::-1]:
                newdp[c][i] = max(newdp[c][i], newdp[c][i - 1] + table[r][c])
                newdp[c + 1][i] = max(newdp[c + 1][i], newdp[c][i])
            newdp[c + 1][0] = max(newdp[c + 1][0], newdp[c][0])
        dp = newdp

    print(max(dp[C-1]))


if __name__ == '__main__':
    main()