#include <unistd.h>
#include <cstdio>
#include <x86intrin.h>
#include <algorithm>

typedef long long ll;
int mat[190][3072 * 16] __attribute((aligned(32)));; 
ll dp0[3024];

char buf[1048576];
int lim = 0;
int cur = 0;

void refill()
{
    lim = read(STDIN_FILENO, buf, sizeof buf);
    cur = 0;
}

int rd()
{
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return -1;
        } else {
            if (buf[cur] >= '0' && buf[cur] <= '9') break;
            cur++;
        }
    }
    int acc = buf[cur++] - '0';
    while (true) {
        if (cur == lim) {
            refill();
            if (lim == 0) return acc;
        } else {
            if (buf[cur] < '0' || buf[cur] > '9') return acc;
            acc = acc * 10 + buf[cur++] - '0';
        }
    }
}

#pragma clang attribute push(__attribute__((target("avx512vl"))), apply_to=function)
int main(int argc, char **argv)
{
    int rr = rd();
    int cc = rd();
    int k  = rd();

    for (int i = 1; i <= k; i++) {
        int r = rd() - 1;
        int c = rd() - 1;
        int v = rd();
        mat[r / 16][(c + (r & 15)) * 16 + (r & 15)] = v;
    }
    int rlim = (rr + 15) / 16;
    int clim = cc + 15;

    for (int y = 0; y < rlim; y++) {
        __m512i work0 = _mm512_setzero_si512();
        __m512i work1 = _mm512_setzero_si512();
        __m512i work2 = _mm512_setzero_si512();
        __m512i work3 = _mm512_setzero_si512();

        __m512i work4 = _mm512_setzero_si512();
        __m512i work5 = _mm512_setzero_si512();
        __m512i work6 = _mm512_setzero_si512();
        __m512i work7 = _mm512_setzero_si512();

        __m512i prev0  = _mm512_setzero_si512();
        __m512i prev1  = _mm512_setzero_si512();
        __m256i *p = (__m256i *)&mat[y];
        ll *q = dp0;

        for (int x = 0; x < clim; x++) {
            prev0 = _mm512_mask_set1_epi64(prev0, 1, q[15]);
            work0 = _mm512_max_epi64(work0, prev0);
            work4 = _mm512_max_epi64(work4, prev1);

            __m256i v0 = _mm256_load_si256(p);
            __m256i v4 = _mm256_load_si256(p + 1);

            __m512i v1 = _mm512_cvtepi32_epi64(v0);
            __m512i v5 = _mm512_cvtepi32_epi64(v4);

            __m512i tmp2 = _mm512_add_epi64(work2, v1);
                   work3 = _mm512_max_epi64(work3, tmp2);
            __m512i tmp6 = _mm512_add_epi64(work6, v5);
                   work7 = _mm512_max_epi64(work7, tmp6);

            __m512i tmp1 = _mm512_add_epi64(work1, v1);
                   work2 = _mm512_max_epi64(work2, tmp1);
            __m512i tmp5 = _mm512_add_epi64(work5, v5);
                   work6 = _mm512_max_epi64(work6, tmp5);

            __m512i tmp0 = _mm512_add_epi64(work0, v1);
                   work1 = _mm512_max_epi64(work1, tmp0);
            __m512i tmp4 = _mm512_add_epi64(work4, v5);
                   work5 = _mm512_max_epi64(work5, tmp4);


            __m512i max32 = _mm512_max_epi64(work3, work2);
            __m512i max76 = _mm512_max_epi64(work7, work6);
            __m512i max10 = _mm512_max_epi64(work1, work0);
            __m512i max54 = _mm512_max_epi64(work5, work4);
            __m512i max3210 = _mm512_max_epi64(max32, max10);
            __m512i max7654 = _mm512_max_epi64(max76, max54);

            prev1 = _mm512_alignr_epi64(max7654, max3210, 7);
            prev0 = _mm512_alignr_epi64(max3210, max7654, 7);
            
            _mm512_mask_store_epi64(q, 1, prev0);
            
            p += 2;
            ++q;
        }
    }
    std::printf("%lld\n", dp0[clim - 1]);
    return 0;
}
#pragma clang attribute pop

Measured memory_bytes: 40024