#!/usr/bin python3
# -*- coding: utf-8 -*-

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

dp0 = [[0]*4 for c_ in range(3005)]
dp1 = [[0]*4 for c_ in range(3005)]

for i in range(r):
    for j in range(c):
        nowv = itm[i][j]
        dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv)
        dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv)
        dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv)

        dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0])
        dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1])
        dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2])
        dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3])

        dp1[j][0] = max(dp1[j][0], max(dp0[j]))
    dp0 = dp1.copy()

print(max(dp1[c-1])) 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 itm = [[0]*(c) for _ in range(r)] itm [[0]*(c) for _ in range(r)] for i in range(k):
    ri, ci, vi = map(int, input().split())
    itm[ri-1][ci-1] = vi i 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 itm[ri-1][ci-1] = vi itm[ri-1][ci-1] [ri-1] itm ri-1 ri 1 ci-1 ci 1 vi [0]*4 for c_ in range(3005) for c_ in range(3005) c_ range(3005) range 3005 for c_ in range(3005) [0]*4 [0] 0 4 dp0 = [[0]*4 for c_ in range(3005)] dp0 [[0]*4 for c_ in range(3005)] [0]*4 for c_ in range(3005) for c_ in range(3005) c_ range(3005) range 3005 for c_ in range(3005) [0]*4 [0] 0 4 dp1 = [[0]*4 for c_ in range(3005)] dp1 [[0]*4 for c_ in range(3005)] for i in range(r):
    for j in range(c):
        nowv = itm[i][j]
        dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv)
        dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv)
        dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv)

        dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0])
        dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1])
        dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2])
        dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3])

        dp1[j][0] = max(dp1[j][0], max(dp0[j]))
    dp0 = dp1.copy() i range(r) range r for j in range(c):
        nowv = itm[i][j]
        dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv)
        dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv)
        dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv)

        dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0])
        dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1])
        dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2])
        dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3])

        dp1[j][0] = max(dp1[j][0], max(dp0[j]))
     j range(c) range c nowv = itm[i][j] nowv itm[i][j] [i] itm i j dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv) dp0[j][3] [j] dp0 j 3 max(dp0[j][3], dp0[j][2] + nowv) max dp0[j][3] [j] dp0 j 3 dp0[j][2] + nowv dp0[j][2] [j] dp0 j 2 nowv dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv) dp0[j][2] [j] dp0 j 2 max(dp0[j][2], dp0[j][1] + nowv) max dp0[j][2] [j] dp0 j 2 dp0[j][1] + nowv dp0[j][1] [j] dp0 j 1 nowv dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv) dp0[j][1] [j] dp0 j 1 max(dp0[j][1], dp0[j][0] + nowv) max dp0[j][1] [j] dp0 j 1 dp0[j][0] + nowv dp0[j][0] [j] dp0 j 0 nowv dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0]) dp0[j+1][0] [j+1] dp0 j+1 j 1 0 max(dp0[j+1][0], dp0[j][0]) max dp0[j+1][0] [j+1] dp0 j+1 j 1 0 dp0[j][0] [j] dp0 j 0 dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1]) dp0[j+1][1] [j+1] dp0 j+1 j 1 1 max(dp0[j+1][1], dp0[j][1]) max dp0[j+1][1] [j+1] dp0 j+1 j 1 1 dp0[j][1] [j] dp0 j 1 dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2]) dp0[j+1][2] [j+1] dp0 j+1 j 1 2 max(dp0[j+1][2], dp0[j][2]) max dp0[j+1][2] [j+1] dp0 j+1 j 1 2 dp0[j][2] [j] dp0 j 2 dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3]) dp0[j+1][3] [j+1] dp0 j+1 j 1 3 max(dp0[j+1][3], dp0[j][3]) max dp0[j+1][3] [j+1] dp0 j+1 j 1 3 dp0[j][3] [j] dp0 j 3 dp1[j][0] = max(dp1[j][0], max(dp0[j])) dp1[j][0] [j] dp1 j 0 max(dp1[j][0], max(dp0[j])) max dp1[j][0] [j] dp1 j 0 max(dp0[j]) max dp0[j] dp0 j dp0 = dp1.copy() dp0 dp1.copy() dp1.copy dp1 copy print(max(dp1[c-1])) print max(dp1[c-1]) max dp1[c-1] dp1 c-1 c 1 ci, vi = map(int, input().split()) map(int, input().split()) ci itm = [[0]*(c) for _ in range(r)] [[0]*(c) for _ in range(r)] itm k = map(int, input().split()) map(int, input().split()) k nowv = itm[i][j] itm[i][j] nowv dp1 = [[0]*4 for c_ in range(3005)] [[0]*4 for c_ in range(3005)] dp1 ri, ci, vi = map(int, input().split()) map(int, input().split()) ri r, c, k = map(int, input().split()) map(int, input().split()) r dp0 = [[0]*4 for c_ in range(3005)] [[0]*4 for c_ in range(3005)] dp0 dp0 = dp1.copy() dp1.copy() dp0 c, k = map(int, input().split()) map(int, input().split()) c vi = map(int, input().split()) map(int, input().split()) vi
#!/usr/bin python3
# -*- coding: utf-8 -*-

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

dp0 = [[0]*4 for c_ in range(3005)]
dp1 = [[0]*4 for c_ in range(3005)]

for i in range(r):
    for j in range(c):
        nowv = itm[i][j]
        dp0[j][3] = max(dp0[j][3], dp0[j][2] + nowv)
        dp0[j][2] = max(dp0[j][2], dp0[j][1] + nowv)
        dp0[j][1] = max(dp0[j][1], dp0[j][0] + nowv)

        dp0[j+1][0] = max(dp0[j+1][0], dp0[j][0])
        dp0[j+1][1] = max(dp0[j+1][1], dp0[j][1])
        dp0[j+1][2] = max(dp0[j+1][2], dp0[j][2])
        dp0[j+1][3] = max(dp0[j+1][3], dp0[j][3])

        dp1[j][0] = max(dp1[j][0], max(dp0[j]))
    dp0 = dp1.copy()

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