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

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

pre = [[0]*(3+1) for _ in range(C+1)]
for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        for k in range(3+1):
            if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

            if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
    pre = now

print(max(now[C])) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0]*(C+1) for _ in range(R+1) for _ in range(R+1) _ range(R+1) range R+1 R 1 for _ in range(R+1) [0]*(C+1) [0] 0 C+1 C 1 V = [[0]*(C+1) for _ in range(R+1)] V [[0]*(C+1) for _ in range(R+1)] for _ in range(K):
    r, c, v = map(int, input().split())
    V[r][c] = v _ range(K) range K r, c, v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c v V[r][c] = v V[r][c] [r] V r c v [0]*(3+1) for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0]*(3+1) [0] 0 3+1 3 1 pre = [[0]*(3+1) for _ in range(C+1)] pre [[0]*(3+1) for _ in range(C+1)] for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        for k in range(3+1):
            if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

            if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
    pre = now i range(R+1) range R+1 R 1 [0]*(3+1) for _ in range(C+1) for _ in range(C+1) _ range(C+1) range C+1 C 1 for _ in range(C+1) [0]*(3+1) [0] 0 3+1 3 1 now = [[0]*(3+1) for _ in range(C+1)] now [[0]*(3+1) for _ in range(C+1)] for j in range(C+1):
        for k in range(3+1):
            if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

            if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
     j range(C+1) range C+1 C 1 for k in range(3+1):
            if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

            if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
     k range(3+1) range 3+1 3 1 if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

             i-1 >= 0 i-1 i 1 0 now[j][0] = max(now[j][0], pre[j][k]) now[j][0] [j] now j 0 max(now[j][0], pre[j][k]) max now[j][0] [j] now j 0 pre[j][k] [j] pre j k now[j][1] = max(now[j][1], pre[j][k] + V[i][j]) now[j][1] [j] now j 1 max(now[j][1], pre[j][k] + V[i][j]) max now[j][1] [j] now j 1 pre[j][k] + V[i][j] pre[j][k] [j] pre j k V[i][j] [i] V i j if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
     j-1 >= 0 j-1 j 1 0 now[j][k] = max(now[j][k], now[j-1][k]) now[j][k] [j] now j k max(now[j][k], now[j-1][k]) max now[j][k] [j] now j k now[j-1][k] [j-1] now j-1 j 1 k if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
     k-1 >= 0 k-1 k 1 0 now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j]) now[j][k] [j] now j k max(now[j][k], now[j-1][k-1] + V[i][j]) max now[j][k] [j] now j k now[j-1][k-1] + V[i][j] now[j-1][k-1] [j-1] now j-1 j 1 k-1 k 1 V[i][j] [i] V i j pre = now pre now print(max(now[C])) print max(now[C]) max now[C] now C K = map(int, input().split()) map(int, input().split()) K R, C, K = map(int, input().split()) map(int, input().split()) R r, c, v = map(int, input().split()) map(int, input().split()) r now = [[0]*(3+1) for _ in range(C+1)] [[0]*(3+1) for _ in range(C+1)] now V = [[0]*(C+1) for _ in range(R+1)] [[0]*(C+1) for _ in range(R+1)] V C, K = map(int, input().split()) map(int, input().split()) C pre = now now pre v = map(int, input().split()) map(int, input().split()) v pre = [[0]*(3+1) for _ in range(C+1)] [[0]*(3+1) for _ in range(C+1)] pre c, v = map(int, input().split()) map(int, input().split()) c
R, C, K = map(int, input().split())

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

pre = [[0]*(3+1) for _ in range(C+1)]
for i in range(R+1):
    now = [[0]*(3+1) for _ in range(C+1)]
    for j in range(C+1):
        for k in range(3+1):
            if i-1 >= 0:
                now[j][0] = max(now[j][0], pre[j][k])
                now[j][1] = max(now[j][1], pre[j][k] + V[i][j])

            if j-1 >= 0:
                now[j][k] = max(now[j][k], now[j-1][k])
                if k-1 >= 0:
                    now[j][k] = max(now[j][k], now[j-1][k-1] + V[i][j])
    pre = now

print(max(now[C]))
