r,c,k = map(int,input().split())
t = [[0 for i in range(c)] for i in range(r)]
for i in range(k):
    a,b,z = map(int,input().split())
    t[a-1][b-1] = z
dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)]
dp[0][0][0] = 0
dp[1][0][0] = t[0][0]
dp[2][0][0] = t[0][0]
dp[3][0][0] = t[0][0]
for i in range(r-1):
    dp[0][i+1][0] = dp[1][i][0]
    for j in range(1,4):
        dp[j][i+1][0] = dp[1][i][0]+t[i+1][0]
for i in range(c-1):
    dp[0][0][i+1] = 0
    for j in range(1,4):
        dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
    for j in range(2,4):
        dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
    dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1])
for i in range(r-1):
    for j in range(c-1):
        u = max(dp[0][i+1][j],dp[3][i][j+1])
        for s in range(0,4):
            dp[s][i+1][j+1] =  u
        u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(1,4):
            dp[s][i+1][j+1] = u
        u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(2,4):
            dp[s][i+1][j+1] = u
        dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
print(dp[3][r-1][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 i in range(c)] for i in range(r) for i in range(r) i range(r) range r for i in range(r) [0 for i in range(c)] t = [[0 for i in range(c)] for i in range(r)] t [[0 for i in range(c)] for i in range(r)] for i in range(k):
    a,b,z = map(int,input().split())
    t[a-1][b-1] = z i range(k) range k a,b,z = map(int,input().split()) a map(int,input().split()) map int input().split() ().split () input split b z t[a-1][b-1] = z t[a-1][b-1] [a-1] t a-1 a 1 b-1 b 1 z [[0 for i in range(c)]for i in range(r)]for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[0 for i in range(c)]for i in range(r)] dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)] dp [[[0 for i in range(c)]for i in range(r)]for i in range(4)] dp[0][0][0] = 0 dp[0][0][0] [0] [0] dp 0 0 0 0 dp[1][0][0] = t[0][0] dp[1][0][0] [0] [1] dp 1 0 0 t[0][0] [0] t 0 0 dp[2][0][0] = t[0][0] dp[2][0][0] [0] [2] dp 2 0 0 t[0][0] [0] t 0 0 dp[3][0][0] = t[0][0] dp[3][0][0] [0] [3] dp 3 0 0 t[0][0] [0] t 0 0 for i in range(r-1):
    dp[0][i+1][0] = dp[1][i][0]
    for j in range(1,4):
        dp[j][i+1][0] = dp[1][i][0]+t[i+1][0] i range(r-1) range r-1 r 1 dp[0][i+1][0] = dp[1][i][0] dp[0][i+1][0] [i+1] [0] dp 0 i+1 i 1 0 dp[1][i][0] [i] [1] dp 1 i 0 for j in range(1,4):
        dp[j][i+1][0] = dp[1][i][0]+t[i+1][0] j range(1,4) range 1 4 dp[j][i+1][0] = dp[1][i][0]+t[i+1][0] dp[j][i+1][0] [i+1] [j] dp j i+1 i 1 0 dp[1][i][0]+t[i+1][0] dp[1][i][0] [i] [1] dp 1 i 0 t[i+1][0] [i+1] t i+1 i 1 0 for i in range(c-1):
    dp[0][0][i+1] = 0
    for j in range(1,4):
        dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
    for j in range(2,4):
        dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
    dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1]) i range(c-1) range c-1 c 1 dp[0][0][i+1] = 0 dp[0][0][i+1] [0] [0] dp 0 0 i+1 i 1 0 for j in range(1,4):
        dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
     j range(1,4) range 1 4 dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1]) dp[j][0][i+1] [0] [j] dp j 0 i+1 i 1 max(dp[1][0][i],t[0][i+1]) max dp[1][0][i] [0] [1] dp 1 0 i t[0][i+1] [0] t 0 i+1 i 1 for j in range(2,4):
        dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
     j range(2,4) range 2 4 dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1]) dp[j][0][i+1] [0] [j] dp j 0 i+1 i 1 max(dp[2][0][i],dp[1][0][i]+t[0][i+1]) max dp[2][0][i] [0] [2] dp 2 0 i dp[1][0][i]+t[0][i+1] dp[1][0][i] [0] [1] dp 1 0 i t[0][i+1] [0] t 0 i+1 i 1 dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1]) dp[3][0][i+1] [0] [3] dp 3 0 i+1 i 1 max(dp[3][0][i],dp[2][0][i]+t[0][i+1]) max dp[3][0][i] [0] [3] dp 3 0 i dp[2][0][i]+t[0][i+1] dp[2][0][i] [0] [2] dp 2 0 i t[0][i+1] [0] t 0 i+1 i 1 for i in range(r-1):
    for j in range(c-1):
        u = max(dp[0][i+1][j],dp[3][i][j+1])
        for s in range(0,4):
            dp[s][i+1][j+1] =  u
        u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(1,4):
            dp[s][i+1][j+1] = u
        u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(2,4):
            dp[s][i+1][j+1] = u
        dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) i range(r-1) range r-1 r 1 for j in range(c-1):
        u = max(dp[0][i+1][j],dp[3][i][j+1])
        for s in range(0,4):
            dp[s][i+1][j+1] =  u
        u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(1,4):
            dp[s][i+1][j+1] = u
        u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(2,4):
            dp[s][i+1][j+1] = u
        dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) j range(c-1) range c-1 c 1 u = max(dp[0][i+1][j],dp[3][i][j+1]) u max(dp[0][i+1][j],dp[3][i][j+1]) max dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j dp[3][i][j+1] [i] [3] dp 3 i j+1 j 1 for s in range(0,4):
            dp[s][i+1][j+1] =  u
         s range(0,4) range 0 4 dp[s][i+1][j+1] =  u dp[s][i+1][j+1] [i+1] [s] dp s i+1 i 1 j+1 j 1 u u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) u max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) max dp[0][i+1][j]+t[i+1][j+1] dp[0][i+1][j] [i+1] [0] dp 0 i+1 i 1 j t[i+1][j+1] [i+1] t i+1 i 1 j+1 j 1 dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j dp[3][i][j+1]+t[i+1][j+1] dp[3][i][j+1] [i] [3] dp 3 i j+1 j 1 t[i+1][j+1] [i+1] t i+1 i 1 j+1 j 1 for s in range(1,4):
            dp[s][i+1][j+1] = u
         s range(1,4) range 1 4 dp[s][i+1][j+1] = u dp[s][i+1][j+1] [i+1] [s] dp s i+1 i 1 j+1 j 1 u u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) u max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) max dp[1][i+1][j]+t[i+1][j+1] dp[1][i+1][j] [i+1] [1] dp 1 i+1 i 1 j t[i+1][j+1] [i+1] t i+1 i 1 j+1 j 1 dp[2][i+1][j] [i+1] [2] dp 2 i+1 i 1 j dp[3][i][j+1]+t[i+1][j+1] dp[3][i][j+1] [i] [3] dp 3 i j+1 j 1 t[i+1][j+1] [i+1] t i+1 i 1 j+1 j 1 for s in range(2,4):
            dp[s][i+1][j+1] = u
         s range(2,4) range 2 4 dp[s][i+1][j+1] = u dp[s][i+1][j+1] [i+1] [s] dp s i+1 i 1 j+1 j 1 u dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) dp[3][i+1][j+1] [i+1] [3] dp 3 i+1 i 1 j+1 j 1 max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) max dp[2][i+1][j]+t[i+1][j+1] dp[2][i+1][j] [i+1] [2] dp 2 i+1 i 1 j t[i+1][j+1] [i+1] t i+1 i 1 j+1 j 1 dp[3][i+1][j] [i+1] [3] dp 3 i+1 i 1 j dp[3][i][j+1]+t[i+1][j+1] dp[3][i][j+1] [i] [3] dp 3 i j+1 j 1 t[i+1][j+1] [i+1] t i+1 i 1 j+1 j 1 print(dp[3][r-1][c-1]) print dp[3][r-1][c-1] [r-1] [3] dp 3 r-1 r 1 c-1 c 1 z = map(int,input().split()) map(int,input().split()) z k = map(int,input().split()) map(int,input().split()) k a,b,z = map(int,input().split()) map(int,input().split()) a u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) u c,k = map(int,input().split()) map(int,input().split()) c u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1]) u r,c,k = map(int,input().split()) map(int,input().split()) r t = [[0 for i in range(c)] for i in range(r)] [[0 for i in range(c)] for i in range(r)] t b,z = map(int,input().split()) map(int,input().split()) b dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)] [[[0 for i in range(c)]for i in range(r)]for i in range(4)] dp u = max(dp[0][i+1][j],dp[3][i][j+1]) max(dp[0][i+1][j],dp[3][i][j+1]) u
r,c,k = map(int,input().split())
t = [[0 for i in range(c)] for i in range(r)]
for i in range(k):
    a,b,z = map(int,input().split())
    t[a-1][b-1] = z
dp = [[[0 for i in range(c)]for i in range(r)]for i in range(4)]
dp[0][0][0] = 0
dp[1][0][0] = t[0][0]
dp[2][0][0] = t[0][0]
dp[3][0][0] = t[0][0]
for i in range(r-1):
    dp[0][i+1][0] = dp[1][i][0]
    for j in range(1,4):
        dp[j][i+1][0] = dp[1][i][0]+t[i+1][0]
for i in range(c-1):
    dp[0][0][i+1] = 0
    for j in range(1,4):
        dp[j][0][i+1] = max(dp[1][0][i],t[0][i+1])
    for j in range(2,4):
        dp[j][0][i+1] = max(dp[2][0][i],dp[1][0][i]+t[0][i+1])
    dp[3][0][i+1] = max(dp[3][0][i],dp[2][0][i]+t[0][i+1])
for i in range(r-1):
    for j in range(c-1):
        u = max(dp[0][i+1][j],dp[3][i][j+1])
        for s in range(0,4):
            dp[s][i+1][j+1] =  u
        u = max(dp[0][i+1][j]+t[i+1][j+1],dp[1][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(1,4):
            dp[s][i+1][j+1] = u
        u = max(dp[1][i+1][j]+t[i+1][j+1],dp[2][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
        for s in range(2,4):
            dp[s][i+1][j+1] = u
        dp[3][i+1][j+1] = max(dp[2][i+1][j]+t[i+1][j+1],dp[3][i+1][j],dp[3][i][j+1]+t[i+1][j+1])
print(dp[3][r-1][c-1])