import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit('i8[:](i8[:],i8[:,:])')
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype='int64')
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
    print(dp[-1])


if __name__ == '__main__':
    main() import sys sys import numpy as np numpy from collections import defaultdict from numba import njit def input(): return sys.stdin.readline().rstrip() input def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3 koushin dptmp1 = np.copy(dp) dptmp1 np.copy(dp) np.copy np copy dp dptmp2 = np.copy(dp) dptmp2 np.copy(dp) np.copy np copy dp dptmp3 = np.copy(dp) dptmp3 np.copy(dp) np.copy np copy dp for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
     i range(len(item)) range len(item) len item dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1]) dptmp3[item[i][0]:] dptmp3 item[i][0]: item[i][0] [i] item i 0 np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1]) np.fmax np fmax dptmp3[item[i][0]:] dptmp3 item[i][0]: item[i][0] [i] item i 0 dptmp2[item[i][0]]+item[i][1] dptmp2[item[i][0]] dptmp2 item[i][0] [i] item i 0 item[i][1] [i] item i 1 dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1]) dptmp2[item[i][0]:] dptmp2 item[i][0]: item[i][0] [i] item i 0 np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1]) np.fmax np fmax dptmp2[item[i][0]:] dptmp2 item[i][0]: item[i][0] [i] item i 0 dptmp1[item[i][0]]+item[i][1] dptmp1[item[i][0]] dptmp1 item[i][0] [i] item i 0 item[i][1] [i] item i 1 dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1]) dptmp1[item[i][0]:] dptmp1 item[i][0]: item[i][0] [i] item i 0 np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1]) np.fmax np fmax dptmp1[item[i][0]:] dptmp1 item[i][0]: item[i][0] [i] item i 0 dp[item[i][0]]+item[i][1] dp[item[i][0]] dp item[i][0] [i] item i 0 item[i][1] [i] item i 1 return dptmp3 dptmp3 dp dp item item @njit('i8[:](i8[:],i8[:,:])') koushin 'i8[:](i8[:],i8[:,:])' @njit('i8[:](i8[:],i8[:,:])') njit 'i8[:](i8[:],i8[:,:])' koushin def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype='int64')
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
    print(dp[-1]) main R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K items = defaultdict(list) items defaultdict(list) defaultdict list for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
     _ range(K) range K r, c, v = map(int, input().split()) r map(int, input().split()) map int input().split() ().split () input split c v items[r-1].append([c-1, v]) [r-1].append [r-1] items r-1 r 1 append [c-1, v] c-1 c 1 v dp = np.zeros(C, dtype='int64') dp np.zeros(C, dtype='int64') np.zeros np zeros C dtype='int64' dtype 'int64' for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
     RR range(R) range R if items[RR]==[]:
          continue
         items[RR]==[] items[RR] items RR [] continue items[RR].sort(key=lambda x: x[0]) [RR].sort [RR] items RR sort key=lambda x: x[0] key lambda x: x[0] x[0] x 0 x dp=koushin(dp,np.array(items[RR],dtype='int64')) dp koushin(dp,np.array(items[RR],dtype='int64')) koushin dp np.array(items[RR],dtype='int64') np.array np array items[RR] items RR dtype='int64' dtype 'int64' print(dp[-1]) print dp[-1] dp -1 if __name__ == '__main__':
    main() __name__ == '__main__' __name__ '__main__' main() main def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype='int64')
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
    print(dp[-1]) def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype='int64')
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
    print(dp[-1]) main def input(): return sys.stdin.readline().rstrip() def input(): return sys.stdin.readline().rstrip() input def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3 def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3 koushin
import sys
import numpy as np
from collections import defaultdict
from numba import njit
def input(): return sys.stdin.readline().rstrip()

@njit('i8[:](i8[:],i8[:,:])')
def koushin(dp,item):
    dptmp1 = np.copy(dp)
    dptmp2 = np.copy(dp)
    dptmp3 = np.copy(dp)
    for i in range(len(item)):
        dptmp3[item[i][0]:] = np.fmax(dptmp3[item[i][0]:], dptmp2[item[i][0]]+item[i][1])
        dptmp2[item[i][0]:] = np.fmax(dptmp2[item[i][0]:], dptmp1[item[i][0]]+item[i][1])
        dptmp1[item[i][0]:] = np.fmax(dptmp1[item[i][0]:], dp[item[i][0]]+item[i][1])
    return dptmp3

def main():
    R, C, K = map(int, input().split())
    items = defaultdict(list)
    for _ in range(K):
        r, c, v = map(int, input().split())
        items[r-1].append([c-1, v])
    dp = np.zeros(C, dtype='int64')
    for RR in range(R):
        if items[RR]==[]:
          continue
        items[RR].sort(key=lambda x: x[0])
        dp=koushin(dp,np.array(items[RR],dtype='int64'))
    print(dp[-1])


if __name__ == '__main__':
    main()
