from sys import stdin
readline = stdin.readline

R, C, K = map(int, readline().split())

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

n = [0] * (C + 1)
for i in range(R):
    c = [0] * 4
    c[0] = n[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
        for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
        if n[j + 1] > c[0]:
            c[0] = n[j + 1]

print(max(c)) from sys import stdin readline = stdin.readline readline stdin.readline stdin readline R, C, K = map(int, readline().split()) R map(int, readline().split()) map int readline().split() ().split () readline 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 goods = [[0] * C for _ in range(R)] goods [[0] * C for _ in range(R)] for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v _ range(K) range K r, c, v = map(int, readline().split()) r map(int, readline().split()) map int readline().split() ().split () readline split c v goods[r - 1][c - 1] = v goods[r - 1][c - 1] [r - 1] goods r - 1 r 1 c - 1 c 1 v n = [0] * (C + 1) n [0] * (C + 1) [0] 0 C + 1 C 1 for i in range(R):
    c = [0] * 4
    c[0] = n[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
        for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
        if n[j + 1] > c[0]:
            c[0] = n[j + 1] i range(R) range R c = [0] * 4 c [0] * 4 [0] 0 4 c[0] = n[0] c[0] c 0 n[0] n 0 for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
        for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
        if n[j + 1] > c[0]:
            c[0] = n[j + 1] j range(C) range C if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
         goods[i][j] != 0 goods[i][j] [i] goods i j 0 for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
         k range(2, -1, -1) range 2 -1 -1 if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
         c[k] + goods[i][j] > c[k + 1] c[k] + goods[i][j] c[k] c k goods[i][j] [i] goods i j c[k + 1] c k + 1 k 1 c[k + 1] = c[k] + goods[i][j] c[k + 1] c k + 1 k 1 c[k] + goods[i][j] c[k] c k goods[i][j] [i] goods i j for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
         k range(4) range 4 if c[k] > n[j]:
                n[j] = c[k]
         c[k] > n[j] c[k] c k n[j] n j n[j] = c[k] n[j] n j c[k] c k if n[j + 1] > c[0]:
            c[0] = n[j + 1] n[j + 1] > c[0] n[j + 1] n j + 1 j 1 c[0] c 0 c[0] = n[j + 1] c[0] c 0 n[j + 1] n j + 1 j 1 print(max(c)) print max(c) max c K = map(int, readline().split()) map(int, readline().split()) K C, K = map(int, readline().split()) map(int, readline().split()) C c = [0] * 4 [0] * 4 c R, C, K = map(int, readline().split()) map(int, readline().split()) R goods = [[0] * C for _ in range(R)] [[0] * C for _ in range(R)] goods v = map(int, readline().split()) map(int, readline().split()) v readline = stdin.readline stdin.readline readline r, c, v = map(int, readline().split()) map(int, readline().split()) r c, v = map(int, readline().split()) map(int, readline().split()) c n = [0] * (C + 1) [0] * (C + 1) n
from sys import stdin
readline = stdin.readline

R, C, K = map(int, readline().split())

goods = [[0] * C for _ in range(R)]
for _ in range(K):
    r, c, v = map(int, readline().split())
    goods[r - 1][c - 1] = v

n = [0] * (C + 1)
for i in range(R):
    c = [0] * 4
    c[0] = n[0]
    for j in range(C):
        if goods[i][j] != 0:
            for k in range(2, -1, -1):
                if c[k] + goods[i][j] > c[k + 1]:
                    c[k + 1] = c[k] + goods[i][j]
        for k in range(4):
            if c[k] > n[j]:
                n[j] = c[k]
        if n[j + 1] > c[0]:
            c[0] = n[j + 1]

print(max(c))
