def main(R,C,K,V):
    dp = [0]*(4*R*C)
    dp[1+4*0+4*C*0] = V[0][0]
    for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

    print(max(dp[-5:-1]))

if __name__ == '__main__':
    R,C,K = map(int,input().split())
    C += 1
    rcv = [list(map(int,input().split())) for _ in range(K)]
    V = [[0]*C for _ in range(R)]
    for i in range(K):
        r,c,v = rcv[i]
        r -= 1
        c -= 1
        V[r][c] = v
    main(R,C,K,V) def main(R,C,K,V):
    dp = [0]*(4*R*C)
    dp[1+4*0+4*C*0] = V[0][0]
    for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

    print(max(dp[-5:-1])) main dp = [0]*(4*R*C) dp [0]*(4*R*C) [0] 0 4*R*C 4*R 4 R C dp[1+4*0+4*C*0] = V[0][0] dp[1+4*0+4*C*0] dp 1+4*0+4*C*0 1+4*0 1 4*0 4 0 4*C*0 4*C 4 C 0 V[0][0] [0] V 0 0 for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

     k range(4*R*C) range 4*R*C 4*R 4 R C n = k%4 n k%4 k 4 j = k//4%C j k//4%C k//4 k 4 C i = k//(4*C) i k//(4*C) k 4*C 4 C if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
         n!=0 n 0 if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
             i != 0 and n==1 i != 0 i 0 n==1 n 1 dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j] dp[k] dp k max(dp[k-4*C-n:k-4*C-n+4])+V[i][j] max(dp[k-4*C-n:k-4*C-n+4]) max dp[k-4*C-n:k-4*C-n+4] dp k-4*C-n:k-4*C-n+4 k-4*C-n k-4*C k 4*C 4 C n k-4*C-n+4 k-4*C-n k-4*C k 4*C 4 C n 4 V[i][j] [i] V i j if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
         j != 0 j 0 dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j]) dp[k] dp k max(dp[k],dp[k-4],dp[k-5]+V[i][j]) max dp[k] dp k dp[k-4] dp k-4 k 4 dp[k-5]+V[i][j] dp[k-5] dp k-5 k 5 V[i][j] [i] V i j if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

     n==0 n 0 if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

     i != 0 i 0 dp[k] = max(dp[k-4*C-n:k-4*C-n+4]) dp[k] dp k max(dp[k-4*C-n:k-4*C-n+4]) max dp[k-4*C-n:k-4*C-n+4] dp k-4*C-n:k-4*C-n+4 k-4*C-n k-4*C k 4*C 4 C n k-4*C-n+4 k-4*C-n k-4*C k 4*C 4 C n 4 print(max(dp[-5:-1])) print max(dp[-5:-1]) max dp[-5:-1] dp -5:-1 -5 -1 R R C C K K V V if __name__ == '__main__':
    R,C,K = map(int,input().split())
    C += 1
    rcv = [list(map(int,input().split())) for _ in range(K)]
    V = [[0]*C for _ in range(R)]
    for i in range(K):
        r,c,v = rcv[i]
        r -= 1
        c -= 1
        V[r][c] = v
    main(R,C,K,V) __name__ == '__main__' __name__ '__main__' R,C,K = map(int,input().split()) R map(int,input().split()) map int input().split() ().split () input split C K C += 1 C 1 list(map(int,input().split())) for _ in range(K) for _ in range(K) _ range(K) range K for _ in range(K) list(map(int,input().split())) list map(int,input().split()) map int input().split() ().split () input split rcv = [list(map(int,input().split())) for _ in range(K)] rcv [list(map(int,input().split())) for _ in range(K)] [0]*C for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0]*C [0] 0 C V = [[0]*C for _ in range(R)] V [[0]*C for _ in range(R)] for i in range(K):
        r,c,v = rcv[i]
        r -= 1
        c -= 1
        V[r][c] = v
     i range(K) range K r,c,v = rcv[i] r rcv[i] rcv i c v r -= 1 r 1 c -= 1 c 1 V[r][c] = v V[r][c] [r] V r c v main(R,C,K,V) main R C K V R,C,K = map(int,input().split()) map(int,input().split()) R C,K = map(int,input().split()) map(int,input().split()) C V = [[0]*C for _ in range(R)] [[0]*C for _ in range(R)] V c,v = rcv[i] rcv[i] c r,c,v = rcv[i] rcv[i] r r -= 1 1 r rcv = [list(map(int,input().split())) for _ in range(K)] [list(map(int,input().split())) for _ in range(K)] rcv v = rcv[i] rcv[i] v c -= 1 1 c def main(R,C,K,V):
    dp = [0]*(4*R*C)
    dp[1+4*0+4*C*0] = V[0][0]
    for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

    print(max(dp[-5:-1])) def main(R,C,K,V):
    dp = [0]*(4*R*C)
    dp[1+4*0+4*C*0] = V[0][0]
    for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

    print(max(dp[-5:-1])) main K = map(int,input().split()) map(int,input().split()) K C += 1 1 C
def main(R,C,K,V):
    dp = [0]*(4*R*C)
    dp[1+4*0+4*C*0] = V[0][0]
    for k in range(4*R*C):
        n = k%4
        j = k//4%C
        i = k//(4*C)
        if n!=0:
            if i != 0 and n==1:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])+V[i][j]
            if j != 0:
                dp[k] = max(dp[k],dp[k-4],dp[k-5]+V[i][j])
        if n==0:
            if i != 0:
                dp[k] = max(dp[k-4*C-n:k-4*C-n+4])

    print(max(dp[-5:-1]))

if __name__ == '__main__':
    R,C,K = map(int,input().split())
    C += 1
    rcv = [list(map(int,input().split())) for _ in range(K)]
    V = [[0]*C for _ in range(R)]
    for i in range(K):
        r,c,v = rcv[i]
        r -= 1
        c -= 1
        V[r][c] = v
    main(R,C,K,V)