def main():
    r, c, k = map(int, input().split())
    d = [[0]*c for _ in [0]*r]
    for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
    dp = [[0]*4 for _ in [0]*c]
    dp[0][1] = d[0][0]
    for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
    print(max(dp[c-1]))


main() def main():
    r, c, k = map(int, input().split())
    d = [[0]*c for _ in [0]*r]
    for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
    dp = [[0]*4 for _ in [0]*c]
    dp[0][1] = d[0][0]
    for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
    print(max(dp[c-1])) main 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 [0]*r for _ in [0]*r _ [0]*r [0] 0 r for _ in [0]*r [0]*c [0] 0 c d = [[0]*c for _ in [0]*r] d [[0]*c for _ in [0]*r] for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
     _ range(k) range k t1, t2, t3 = map(int, input().split()) t1 map(int, input().split()) map int input().split() ().split () input split t2 t3 d[t1-1][t2-1] = t3 d[t1-1][t2-1] [t1-1] d t1-1 t1 1 t2-1 t2 1 t3 [0]*4 for _ in [0]*c for _ in [0]*c _ [0]*c [0] 0 c for _ in [0]*c [0]*4 [0] 0 4 dp = [[0]*4 for _ in [0]*c] dp [[0]*4 for _ in [0]*c] dp[0][1] = d[0][0] dp[0][1] [0] dp 0 1 d[0][0] [0] d 0 0 for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
     x range(r) range r [0]*4 for _ in [0]*c for _ in [0]*c _ [0]*c [0] 0 c for _ in [0]*c [0]*4 [0] 0 4 dp2 = [[0]*4 for _ in [0]*c] dp2 [[0]*4 for _ in [0]*c] for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
         y range(c) range c for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
             z range(4) range 4 if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
             y != c-1 y c-1 c 1 if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                     z != 3 z 3 dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1]) dp[y+1][z+1] [y+1] dp y+1 y 1 z+1 z 1 max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1]) max dp[y+1]
                                           [z+1] [y+1] dp y+1 y 1 z+1 z 1 dp[y][z]+d[x][y+1] dp[y][z] [y] dp y z d[x][y+1] [x] d x y+1 y 1 dp[y+1][z] = max(dp[y+1][z], dp[y][z]) dp[y+1][z] [y+1] dp y+1 y 1 z max(dp[y+1][z], dp[y][z]) max dp[y+1][z] [y+1] dp y+1 y 1 z dp[y][z] [y] dp y z if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
         x != r-1 x r-1 r 1 dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y]) dp2[y][1] [y] dp2 y 1 max(dp2[y][1],
                                max(dp[y])+d[x+1][y]) max dp2[y][1] [y] dp2 y 1 max(dp[y])+d[x+1][y] max(dp[y]) max dp[y] dp y d[x+1][y] [x+1] d x+1 x 1 y dp2[y][0] = max(dp2[y][0], max(dp[y])) dp2[y][0] [y] dp2 y 0 max(dp2[y][0], max(dp[y])) max dp2[y][0] [y] dp2 y 0 max(dp[y]) max dp[y] dp y if x != r-1:
            dp = dp2
     x != r-1 x r-1 r 1 dp = dp2 dp dp2 print(max(dp[c-1])) print max(dp[c-1]) max dp[c-1] dp c-1 c 1 main() main def main():
    r, c, k = map(int, input().split())
    d = [[0]*c for _ in [0]*r]
    for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
    dp = [[0]*4 for _ in [0]*c]
    dp[0][1] = d[0][0]
    for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
    print(max(dp[c-1])) def main():
    r, c, k = map(int, input().split())
    d = [[0]*c for _ in [0]*r]
    for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
    dp = [[0]*4 for _ in [0]*c]
    dp[0][1] = d[0][0]
    for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
    print(max(dp[c-1])) main
def main():
    r, c, k = map(int, input().split())
    d = [[0]*c for _ in [0]*r]
    for _ in range(k):
        t1, t2, t3 = map(int, input().split())
        d[t1-1][t2-1] = t3
    dp = [[0]*4 for _ in [0]*c]
    dp[0][1] = d[0][0]
    for x in range(r):
        dp2 = [[0]*4 for _ in [0]*c]
        for y in range(c):
            for z in range(4):
                if y != c-1:
                    if z != 3:
                        dp[y+1][z+1] = max(dp[y+1]
                                           [z+1], dp[y][z]+d[x][y+1])
                    dp[y+1][z] = max(dp[y+1][z], dp[y][z])
            if x != r-1:
                dp2[y][1] = max(dp2[y][1],
                                max(dp[y])+d[x+1][y])
                dp2[y][0] = max(dp2[y][0], max(dp[y]))
        if x != r-1:
            dp = dp2
    print(max(dp[c-1]))


main()