

r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri - 1][ci - 1] = vi

dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
    for j in range(c):
        dpj = dp[j][:]
        if j == 0:
            dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
        else:
            dp[j][0] = max(max(dpj), dp[j - 1][0])
            dp[j][1] = dp[j - 1][1]
            dp[j][2] = dp[j - 1][2]
            dp[j][3] = dp[j - 1][3]
            if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])

print(max(dp[c - 1])) r, c, k = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c k [0 for _ in range(c)] for _ in range(r) for _ in range(r) _ range(r) range r for _ in range(r) [0 for _ in range(c)] v = [[0 for _ in range(c)] for _ in range(r)] v [[0 for _ in range(c)] for _ in range(r)] for _ in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri - 1][ci - 1] = vi _ range(k) range k ri, ci, vi = map(int, input().split()) ri map(int, input().split()) map int input().split() ().split () input split ci vi v[ri - 1][ci - 1] = vi v[ri - 1][ci - 1] [ri - 1] v ri - 1 ri 1 ci - 1 ci 1 vi [0, 0, 0, 0] for _ in range(c) for _ in range(c) _ range(c) range c for _ in range(c) [0, 0, 0, 0] 0 0 0 0 dp = [[0, 0, 0, 0] for _ in range(c)] dp [[0, 0, 0, 0] for _ in range(c)] for i in range(r):
    for j in range(c):
        dpj = dp[j][:]
        if j == 0:
            dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
        else:
            dp[j][0] = max(max(dpj), dp[j - 1][0])
            dp[j][1] = dp[j - 1][1]
            dp[j][2] = dp[j - 1][2]
            dp[j][3] = dp[j - 1][3]
            if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j]) i range(r) range r for j in range(c):
        dpj = dp[j][:]
        if j == 0:
            dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
        else:
            dp[j][0] = max(max(dpj), dp[j - 1][0])
            dp[j][1] = dp[j - 1][1]
            dp[j][2] = dp[j - 1][2]
            dp[j][3] = dp[j - 1][3]
            if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j]) j range(c) range c dpj = dp[j][:] dpj dp[j][:] [j] dp j : if j == 0:
            dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
        else:
            dp[j][0] = max(max(dpj), dp[j - 1][0])
            dp[j][1] = dp[j - 1][1]
            dp[j][2] = dp[j - 1][2]
            dp[j][3] = dp[j - 1][3]
            if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j]) j == 0 j 0 dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0] dp[j] dp j [max(dpj), max(dpj) + v[i][j], 0, 0] max(dpj) max dpj max(dpj) + v[i][j] max(dpj) max dpj v[i][j] [i] v i j 0 0 dp[j][0] = max(max(dpj), dp[j - 1][0]) dp[j][0] [j] dp j 0 max(max(dpj), dp[j - 1][0]) max max(dpj) max dpj dp[j - 1][0] [j - 1] dp j - 1 j 1 0 dp[j][1] = dp[j - 1][1] dp[j][1] [j] dp j 1 dp[j - 1][1] [j - 1] dp j - 1 j 1 1 dp[j][2] = dp[j - 1][2] dp[j][2] [j] dp j 2 dp[j - 1][2] [j - 1] dp j - 1 j 1 2 dp[j][3] = dp[j - 1][3] dp[j][3] [j] dp j 3 dp[j - 1][3] [j - 1] dp j - 1 j 1 3 if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j]) v[i][j] > 0 v[i][j] [i] v i j 0 dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j]) dp[j][1] [j] dp j 1 max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j]) max dp[j][1] [j] dp j 1 dp[j - 1][0] + v[i][j] dp[j - 1][0] [j - 1] dp j - 1 j 1 0 v[i][j] [i] v i j max(dpj) + v[i][j] max(dpj) max dpj v[i][j] [i] v i j dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j]) dp[j][2] [j] dp j 2 max(dp[j][2], dp[j - 1][1] + v[i][j]) max dp[j][2] [j] dp j 2 dp[j - 1][1] + v[i][j] dp[j - 1][1] [j - 1] dp j - 1 j 1 1 v[i][j] [i] v i j dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j]) dp[j][3] [j] dp j 3 max(dp[j][3], dp[j - 1][2] + v[i][j]) max dp[j][3] [j] dp j 3 dp[j - 1][2] + v[i][j] dp[j - 1][2] [j - 1] dp j - 1 j 1 2 v[i][j] [i] v i j print(max(dp[c - 1])) print max(dp[c - 1]) max dp[c - 1] dp c - 1 c 1 ci, vi = map(int, input().split()) map(int, input().split()) ci vi = map(int, input().split()) map(int, input().split()) vi dp = [[0, 0, 0, 0] for _ in range(c)] [[0, 0, 0, 0] for _ in range(c)] dp r, c, k = map(int, input().split()) map(int, input().split()) r ri, ci, vi = map(int, input().split()) map(int, input().split()) ri c, k = map(int, input().split()) map(int, input().split()) c k = map(int, input().split()) map(int, input().split()) k dpj = dp[j][:] dp[j][:] dpj v = [[0 for _ in range(c)] for _ in range(r)] [[0 for _ in range(c)] for _ in range(r)] v


r, c, k = map(int, input().split())
v = [[0 for _ in range(c)] for _ in range(r)]
for _ in range(k):
    ri, ci, vi = map(int, input().split())
    v[ri - 1][ci - 1] = vi

dp = [[0, 0, 0, 0] for _ in range(c)]
for i in range(r):
    for j in range(c):
        dpj = dp[j][:]
        if j == 0:
            dp[j] = [max(dpj), max(dpj) + v[i][j], 0, 0]
        else:
            dp[j][0] = max(max(dpj), dp[j - 1][0])
            dp[j][1] = dp[j - 1][1]
            dp[j][2] = dp[j - 1][2]
            dp[j][3] = dp[j - 1][3]
            if v[i][j] > 0:
                dp[j][1] = max(dp[j][1], dp[j - 1][0] + v[i][j], max(dpj) + v[i][j])
                dp[j][2] = max(dp[j][2], dp[j - 1][1] + v[i][j])
                dp[j][3] = max(dp[j][3], dp[j - 1][2] + v[i][j])

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