#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c])


if __name__ == '__main__':
    main() def next_line():
    return input() next_line return input() input() input def next_int():
    return int(input()) next_int return int(input()) int(input()) int input() input def next_int_array_one_line():
    return list(map(int, input().split())) next_int_array_one_line return list(map(int, input().split())) list(map(int, input().split())) list map(int, input().split()) map int input().split() ().split () input split def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)] next_int_array_multi_lines int(input()) for _ in range(size) for _ in range(size) _ range(size) range size for _ in range(size) int(input()) int input() input return [int(input()) for _ in range(size)] [int(input()) for _ in range(size)] size size def next_str_array(size):
    return [input() for _ in range(size)] next_str_array input() for _ in range(size) for _ in range(size) _ range(size) range size for _ in range(size) input() input return [input() for _ in range(size)] [input() for _ in range(size)] size size def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c]) main 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 i in range(r+1)] for i in range(4) for i in range(4) i range(4) range 4 for i in range(4) [[0] * (c+1) for i in range(r+1)] dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)] dp [[[0] * (c+1) for i in range(r+1)] for i in range(4)] [0] * (c+1) for i in range(r+1) for i in range(r+1) i range(r+1) range r+1 r 1 for i in range(r+1) [0] * (c+1) [0] 0 c+1 c 1 v = [[0] * (c+1) for i in range(r+1)] v [[0] * (c+1) for i in range(r+1)] for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

     i range(k) range k row, col, val = map(int, input().split()) row map(int, input().split()) map int input().split() ().split () input split col val v[row][col] = val v[row][col] [row] v row col val for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
     row range(1, r + 1) range 1 r + 1 r 1 for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
     col range(1, c + 1) range 1 c + 1 c 1 for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
     num range(0, 4) range 0 4 if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
     num == 0 num 0 dp[num][row][col] = dp[3][row-1][col] dp[num][row][col] [row] [num] dp num row col dp[3][row-1][col] [row-1] [3] dp 3 row-1 row 1 col dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            ) dp[num][row][col] [row] [num] dp num row col max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            ) max dp[num-1][row][col] [row] [num-1] dp num-1 num 1 row col dp[num][row][col-1] [row] [num] dp num row col-1 col 1 dp[3][row-1][col] + \
                                            v[row][col] dp[3][row-1][col] [row-1] [3] dp 3 row-1 row 1 col v[row][col] [row] v row col dp[num-1][row][col-1] + \
                                            v[row][col] dp[num-1][row][col-1] [row] [num-1] dp num-1 num 1 row col-1 col 1 v[row][col] [row] v row col print(dp[3][r][c]) print dp[3][r][c] [r] [3] dp 3 r c if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def next_line():
    return input() def next_line():
    return input() next_line def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c]) def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c]) main def next_str_array(size):
    return [input() for _ in range(size)] def next_str_array(size):
    return [input() for _ in range(size)] next_str_array def next_int():
    return int(input()) def next_int():
    return int(input()) next_int def next_int_array_one_line():
    return list(map(int, input().split())) def next_int_array_one_line():
    return list(map(int, input().split())) next_int_array_one_line def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)] def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)] next_int_array_multi_lines
#!/usr/bin/env python3


def next_line():
    return input()


def next_int():
    return int(input())


def next_int_array_one_line():
    return list(map(int, input().split()))


def next_int_array_multi_lines(size):
    return [int(input()) for _ in range(size)]


def next_str_array(size):
    return [input() for _ in range(size)]


def main():
    r, c, k = map(int, input().split())
    dp = [[[0] * (c+1) for i in range(r+1)] for i in range(4)]
    v = [[0] * (c+1) for i in range(r+1)]
    for i in range(k):
        row, col, val = map(int, input().split())
        v[row][col] = val

    for row in range(1, r + 1):
        for col in range(1, c + 1):
            for num in range(0, 4):
                if num == 0:
                    dp[num][row][col] = dp[3][row-1][col]  # simple down
                else:
                    
                    dp[num][row][col] = max(dp[num-1][row][col],  # str
                                            dp[num][row][col-1],  # right x
                                            dp[3][row-1][col] + \
                                            v[row][col],  # down o
                                            dp[num-1][row][col-1] + \
                                            v[row][col],  # right o
                                            )
    print(dp[3][r][c])


if __name__ == '__main__':
    main()
