R, C, K = map(int, input().split())
V = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
  r, c, v = map(int, input().split())
  V[r-1][c-1] = v
M = [0] * R * C * 4 
# M[r*C*4 + c*4 + i]
# M[(r-1)*C*4 + c*4 + i]
# M[r*C*4 + (c-1)*4 + i]
# M[r][c][count in column (c)]
for r in range(R):
  for c in range(C):
    for n_pick in [0, 1] if V[r][c] else [0]:
      M[r*C*4 + c*4 +n_pick] = max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c])
      if r > 0:
        for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
      if c > 0:
        for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M)
print(max(M[((R-1)*C*4 + (C-1) *4):((R-1)*C*4 + (C-1) *4+4)])) R, C, K = map(int, input().split()) R map(int, input().split()) map int input().split() ().split () input split C K [0 for _ in range(C)] for _ in range(R) for _ in range(R) _ range(R) range R for _ in range(R) [0 for _ in range(C)] V = [[0 for _ in range(C)] for _ in range(R)] V [[0 for _ in range(C)] for _ in range(R)] for _ in range(K):
  r, c, v = map(int, input().split())
  V[r-1][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 V[r-1][c-1] = v V[r-1][c-1] [r-1] V r-1 r 1 c-1 c 1 v M = [0] * R * C * 4 M [0] * R * C * 4 [0] * R * C [0] * R [0] 0 R C 4 for r in range(R):
  for c in range(C):
    for n_pick in [0, 1] if V[r][c] else [0]:
      M[r*C*4 + c*4 +n_pick] = max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c])
      if r > 0:
        for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
      if c > 0:
        for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M) r range(R) range R for c in range(C):
    for n_pick in [0, 1] if V[r][c] else [0]:
      M[r*C*4 + c*4 +n_pick] = max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c])
      if r > 0:
        for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
      if c > 0:
        for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M) c range(C) range C for n_pick in [0, 1] if V[r][c] else [0]:
      M[r*C*4 + c*4 +n_pick] = max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c])
      if r > 0:
        for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
      if c > 0:
        for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M) n_pick [0, 1] if V[r][c] else [0] V[r][c] [r] V r c [0, 1] 0 1 [0] 0 M[r*C*4 + c*4 +n_pick] = max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c]) M[r*C*4 + c*4 +n_pick] M r*C*4 + c*4 +n_pick r*C*4 + c*4 r*C*4 r*C r C 4 c*4 c 4 n_pick max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c]) max M[r*C*4 + c*4 +n_pick] M r*C*4 + c*4 +n_pick r*C*4 + c*4 r*C*4 r*C r C 4 c*4 c 4 n_pick n_pick*V[r][c] n_pick V[r][c] [r] V r c if r > 0:
        for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
       r > 0 r 0 for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
       n_prev range(4) range 4 if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
       M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0 M[(r-1)*C*4 + c*4 +n_prev] > 0 M[(r-1)*C*4 + c*4 +n_prev] M (r-1)*C*4 + c*4 +n_prev (r-1)*C*4 + c*4 (r-1)*C*4 (r-1)*C r-1 r 1 C 4 c*4 c 4 n_prev 0 n_prev == 0 n_prev 0 M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c]) M[r*C*4 + c*4 +n_pick] M r*C*4 + c*4 +n_pick r*C*4 + c*4 r*C*4 r*C r C 4 c*4 c 4 n_pick max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c]) max M[r*C*4 + c*4 +n_pick] M r*C*4 + c*4 +n_pick r*C*4 + c*4 r*C*4 r*C r C 4 c*4 c 4 n_pick M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c] M[(r-1)*C*4 + c*4 +n_prev] M (r-1)*C*4 + c*4 +n_prev (r-1)*C*4 + c*4 (r-1)*C*4 (r-1)*C r-1 r 1 C 4 c*4 c 4 n_prev n_pick*V[r][c] n_pick V[r][c] [r] V r c if c > 0:
        for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M) c > 0 c 0 for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M) n_prev range(4 - n_pick) range 4 - n_pick 4 n_pick if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M) M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0 M[r*C*4 + (c-1)*4 +n_prev]  > 0 M[r*C*4 + (c-1)*4 +n_prev] M r*C*4 + (c-1)*4 +n_prev r*C*4 + (c-1)*4 r*C*4 r*C r C 4 (c-1)*4 c-1 c 1 4 n_prev 0 n_prev == 0 n_prev 0 M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c]) M[r*C*4 + c*4 +n_prev+n_pick] M r*C*4 + c*4 +n_prev+n_pick r*C*4 + c*4 +n_prev r*C*4 + c*4 r*C*4 r*C r C 4 c*4 c 4 n_prev n_pick max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c]) max M[r*C*4 + c*4 + n_prev+n_pick] M r*C*4 + c*4 + n_prev+n_pick r*C*4 + c*4 + n_prev r*C*4 + c*4 r*C*4 r*C r C 4 c*4 c 4 n_prev n_pick M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c] M[r*C*4 + (c-1)*4 +n_prev] M r*C*4 + (c-1)*4 +n_prev r*C*4 + (c-1)*4 r*C*4 r*C r C 4 (c-1)*4 c-1 c 1 4 n_prev n_pick*V[r][c] n_pick V[r][c] [r] V r c print(max(M[((R-1)*C*4 + (C-1) *4):((R-1)*C*4 + (C-1) *4+4)])) print max(M[((R-1)*C*4 + (C-1) *4):((R-1)*C*4 + (C-1) *4+4)]) max M[((R-1)*C*4 + (C-1) *4):((R-1)*C*4 + (C-1) *4+4)] M ((R-1)*C*4 + (C-1) *4):((R-1)*C*4 + (C-1) *4+4) (R-1)*C*4 + (C-1) *4 (R-1)*C*4 (R-1)*C R-1 R 1 C 4 (C-1) *4 C-1 C 1 4 (R-1)*C*4 + (C-1) *4+4 (R-1)*C*4 + (C-1) *4 (R-1)*C*4 (R-1)*C R-1 R 1 C 4 (C-1) *4 C-1 C 1 4 4 K = map(int, input().split()) map(int, input().split()) K M = [0] * R * C * 4 [0] * R * C * 4 M v = map(int, input().split()) map(int, input().split()) v r, c, v = map(int, input().split()) map(int, input().split()) r R, C, K = map(int, input().split()) map(int, input().split()) R c, v = map(int, input().split()) map(int, input().split()) c C, K = map(int, input().split()) map(int, input().split()) C V = [[0 for _ in range(C)] for _ in range(R)] [[0 for _ in range(C)] for _ in range(R)] V
R, C, K = map(int, input().split())
V = [[0 for _ in range(C)] for _ in range(R)]
for _ in range(K):
  r, c, v = map(int, input().split())
  V[r-1][c-1] = v
M = [0] * R * C * 4 
# M[r*C*4 + c*4 + i]
# M[(r-1)*C*4 + c*4 + i]
# M[r*C*4 + (c-1)*4 + i]
# M[r][c][count in column (c)]
for r in range(R):
  for c in range(C):
    for n_pick in [0, 1] if V[r][c] else [0]:
      M[r*C*4 + c*4 +n_pick] = max(M[r*C*4 + c*4 +n_pick], n_pick*V[r][c])
      if r > 0:
        for n_prev in range(4):
          #print('R++', r, c, n_pick, n_prev)
          if M[(r-1)*C*4 + c*4 +n_prev] > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_pick]=max(M[r*C*4 + c*4 +n_pick],
              M[(r-1)*C*4 + c*4 +n_prev] + n_pick*V[r][c])
      if c > 0:
        for n_prev in range(4 - n_pick):
          #print('C++', r, c, n_pick, n_prev)
          if  M[r*C*4 + (c-1)*4 +n_prev]  > 0 or n_prev == 0:
            M[r*C*4 + c*4 +n_prev+n_pick]=max(M[r*C*4 + c*4 + n_prev+n_pick],
              M[r*C*4 + (c-1)*4 +n_prev] + n_pick*V[r][c])
    #print(candidates)
    #print(r, c, candidates, M)
    #for i in range(4):
    #  M[r][c][i] = max(candidates[i])
    #print(r, c, M)
#print(V, M)
print(max(M[((R-1)*C*4 + (C-1) *4):((R-1)*C*4 + (C-1) *4+4)]))
