import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, w, k = map(int, input().split())
    values = np.zeros((h, w), dtype=np.int64)
    items = np.array([list(map(int, input().split())) for _ in range(k)])
    ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2]
    values[ys, xs] = vs

    DP = np.zeros(w + 1, dtype=np.int64)
    for line in values:
        DP[1:] += line
        DP = np.maximum.accumulate(DP)
        for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
    print(DP[-1])


if __name__ == "__main__":
    main() import numpy as np numpy import sys sys input = sys.stdin.readline input sys.stdin.readline sys.stdin sys stdin readline def main():
    h, w, k = map(int, input().split())
    values = np.zeros((h, w), dtype=np.int64)
    items = np.array([list(map(int, input().split())) for _ in range(k)])
    ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2]
    values[ys, xs] = vs

    DP = np.zeros(w + 1, dtype=np.int64)
    for line in values:
        DP[1:] += line
        DP = np.maximum.accumulate(DP)
        for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
    print(DP[-1]) main h, w, k = map(int, input().split()) h map(int, input().split()) map int input().split() ().split () input split w k values = np.zeros((h, w), dtype=np.int64) values np.zeros((h, w), dtype=np.int64) np.zeros np zeros (h, w) h w dtype=np.int64 dtype np.int64 np int64 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 items = np.array([list(map(int, input().split())) for _ in range(k)]) items np.array([list(map(int, input().split())) for _ in range(k)]) np.array np array [list(map(int, input().split())) for _ in range(k)] ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2] ys items[:, 0] - 1 items[:, 0] items : 1 xs items[:, 1] - 1 items[:, 1] items : 1 vs items[:, 2] items : values[ys, xs] = vs values[ys, xs] values ys vs DP = np.zeros(w + 1, dtype=np.int64) DP np.zeros(w + 1, dtype=np.int64) np.zeros np zeros w + 1 w 1 dtype=np.int64 dtype np.int64 np int64 for line in values:
        DP[1:] += line
        DP = np.maximum.accumulate(DP)
        for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
     line values DP[1:] += line DP[1:] DP 1: 1 line DP = np.maximum.accumulate(DP) DP np.maximum.accumulate(DP) np.maximum.accumulate np.maximum np maximum accumulate DP for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
     _ range(2) range 2 DP[1:] = np.maximum(DP[:-1] + line, DP[1:]) DP[1:] DP 1: 1 np.maximum(DP[:-1] + line, DP[1:]) np.maximum np maximum DP[:-1] + line DP[:-1] DP :-1 -1 line DP[1:] DP 1: 1 DP = np.maximum.accumulate(DP) DP np.maximum.accumulate(DP) np.maximum.accumulate np.maximum np maximum accumulate DP print(DP[-1]) print DP[-1] DP -1 if __name__ == "__main__":
    main() __name__ == "__main__" __name__ "__main__" main() main def main():
    h, w, k = map(int, input().split())
    values = np.zeros((h, w), dtype=np.int64)
    items = np.array([list(map(int, input().split())) for _ in range(k)])
    ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2]
    values[ys, xs] = vs

    DP = np.zeros(w + 1, dtype=np.int64)
    for line in values:
        DP[1:] += line
        DP = np.maximum.accumulate(DP)
        for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
    print(DP[-1]) def main():
    h, w, k = map(int, input().split())
    values = np.zeros((h, w), dtype=np.int64)
    items = np.array([list(map(int, input().split())) for _ in range(k)])
    ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2]
    values[ys, xs] = vs

    DP = np.zeros(w + 1, dtype=np.int64)
    for line in values:
        DP[1:] += line
        DP = np.maximum.accumulate(DP)
        for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
    print(DP[-1]) main input = sys.stdin.readline sys.stdin.readline input
import numpy as np
import sys
input = sys.stdin.readline


def main():
    h, w, k = map(int, input().split())
    values = np.zeros((h, w), dtype=np.int64)
    items = np.array([list(map(int, input().split())) for _ in range(k)])
    ys, xs, vs = items[:, 0] - 1, items[:, 1] - 1, items[:, 2]
    values[ys, xs] = vs

    DP = np.zeros(w + 1, dtype=np.int64)
    for line in values:
        DP[1:] += line
        DP = np.maximum.accumulate(DP)
        for _ in range(2):
            DP[1:] = np.maximum(DP[:-1] + line, DP[1:])
            DP = np.maximum.accumulate(DP)
    print(DP[-1])


if __name__ == "__main__":
    main()
