from sys import stdin
input = stdin.readline

r, c, k = map(int, input().split())
vals = [[0]*c for _ in range(r)]
for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v
dp = [[0]*4 for j in range(c)]
for j in range(c):
    if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
    if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j]
for i in range(1, r):
    tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)]
    for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
    dp = tmp
print(max(dp[-1])) from sys import stdin input = stdin.readline input stdin.readline stdin readline 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 vals = [[0]*c for _ in range(r)] vals [[0]*c for _ in range(r)] for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v _ range(k) range k x, y, v = map(int, input().split()) x map(int, input().split()) map int input().split() ().split () input split y v vals[x-1][y-1] = v vals[x-1][y-1] [x-1] vals x-1 x 1 y-1 y 1 v [0]*4 for j in range(c) for j in range(c) j range(c) range c for j in range(c) [0]*4 [0] 0 4 dp = [[0]*4 for j in range(c)] dp [[0]*4 for j in range(c)] for j in range(c):
    if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
    if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j] j range(c) range c if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
     j > 0 j 0 for k in range(4):
            dp[j][k] = dp[j-1][k]
     k range(4) range 4 dp[j][k] = dp[j-1][k] dp[j][k] [j] dp j k dp[j-1][k] [j-1] dp j-1 j 1 k if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j] vals[0][j] > 0 vals[0][j] [0] vals 0 j 0 for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j] k reversed(range(3)) reversed range(3) range 3 if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j] dp[j][k+1] < dp[j][k] + vals[0][j] dp[j][k+1] [j] dp j k+1 k 1 dp[j][k] + vals[0][j] dp[j][k] [j] dp j k vals[0][j] [0] vals 0 j dp[j][k+1] = dp[j][k] + vals[0][j] dp[j][k+1] [j] dp j k+1 k 1 dp[j][k] + vals[0][j] dp[j][k] [j] dp j k vals[0][j] [0] vals 0 j for i in range(1, r):
    tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)]
    for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
    dp = tmp i range(1, r) range 1 r [max(dp[j]), 0, 0, 0] for j in range(c) for j in range(c) j range(c) range c for j in range(c) [max(dp[j]), 0, 0, 0] max(dp[j]) max dp[j] dp j 0 0 0 tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)] tmp [[max(dp[j]), 0, 0, 0] for j in range(c)] for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
     j range(c) range c if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
         j > 0 j 0 for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
         k range(4) range 4 if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
         tmp[j][k] < tmp[j-1][k] tmp[j][k] [j] tmp j k tmp[j-1][k] [j-1] tmp j-1 j 1 k tmp[j][k] = tmp[j-1][k] tmp[j][k] [j] tmp j k tmp[j-1][k] [j-1] tmp j-1 j 1 k if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
     vals[i][j] > 0 vals[i][j] [i] vals i j 0 for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
     k reversed(range(3)) reversed range(3) range 3 if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
     tmp[j][k+1] < tmp[j][k] + vals[i][j] tmp[j][k+1] [j] tmp j k+1 k 1 tmp[j][k] + vals[i][j] tmp[j][k] [j] tmp j k vals[i][j] [i] vals i j tmp[j][k+1] = tmp[j][k] + vals[i][j] tmp[j][k+1] [j] tmp j k+1 k 1 tmp[j][k] + vals[i][j] tmp[j][k] [j] tmp j k vals[i][j] [i] vals i j dp = tmp dp tmp print(max(dp[-1])) print max(dp[-1]) max dp[-1] dp -1 k = map(int, input().split()) map(int, input().split()) k v = map(int, input().split()) map(int, input().split()) v vals = [[0]*c for _ in range(r)] [[0]*c for _ in range(r)] vals x, y, v = map(int, input().split()) map(int, input().split()) x y, v = map(int, input().split()) map(int, input().split()) y tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)] [[max(dp[j]), 0, 0, 0] for j in range(c)] tmp dp = tmp tmp dp input = stdin.readline stdin.readline input dp = [[0]*4 for j in range(c)] [[0]*4 for j in range(c)] dp r, c, k = map(int, input().split()) map(int, input().split()) r c, k = map(int, input().split()) map(int, input().split()) c
from sys import stdin
input = stdin.readline

r, c, k = map(int, input().split())
vals = [[0]*c for _ in range(r)]
for _ in range(k):
    x, y, v = map(int, input().split())
    vals[x-1][y-1] = v
dp = [[0]*4 for j in range(c)]
for j in range(c):
    if j > 0:
        for k in range(4):
            dp[j][k] = dp[j-1][k]
    if vals[0][j] > 0:
        for k in reversed(range(3)):
            if dp[j][k+1] < dp[j][k] + vals[0][j]:
                dp[j][k+1] = dp[j][k] + vals[0][j]
for i in range(1, r):
    tmp = [[max(dp[j]), 0, 0, 0] for j in range(c)]
    for j in range(c):
        if j > 0:
            for k in range(4):
                if tmp[j][k] < tmp[j-1][k]:
                    tmp[j][k] = tmp[j-1][k]
        if vals[i][j] > 0:
            for k in reversed(range(3)):
                if tmp[j][k+1] < tmp[j][k] + vals[i][j]:
                    tmp[j][k+1] = tmp[j][k] + vals[i][j]
    dp = tmp
print(max(dp[-1]))