use proconio::input;

// ABC086C - Traveling
// https://atcoder.jp/contests/abs/fasks/arc089_a

struct Item {
    value: i64,
    memory: [i64; 4],
}

fn main() {
    input! {
        r: usize,
        c: usize,
        k: usize,
        mut plan: [(usize, usize, i64); k],  // Vec<(i32, i32, i32)>
    }

    let mut map: Vec<Vec<Item>> = Vec::with_capacity(r);
    for i in 0..r {
        map.push(Vec::with_capacity(c));
        for j in 0..c {
            map[i].push(Item {
                value: 0,
                memory: [0, 0, 0, 0],
            });
        }
    }

    for p in plan {
        map[p.0 - 1][p.1 - 1].value = p.2;
    }

    map[0][0].memory[1] = map[0][0].value;

    for k in 1..c {
        map[0][k].memory[0] = map[0][k - 1].memory[0];
        map[0][k].memory[1] = if map[0][k - 1].memory[0] + map[0][k].value > map[0][k - 1].memory[1]
        {
            map[0][k - 1].memory[0] + map[0][k].value
        } else {
            map[0][k - 1].memory[1]
        };
        map[0][k].memory[2] = if map[0][k - 1].memory[1] + map[0][k].value > map[0][k - 1].memory[2]
        {
            map[0][k - 1].memory[1] + map[0][k].value
        } else {
            map[0][k - 1].memory[2]
        };
        map[0][k].memory[3] = if map[0][k - 1].memory[2] + map[0][k].value > map[0][k - 1].memory[3]
        {
            map[0][k - 1].memory[2] + map[0][k].value
        } else {
            map[0][k - 1].memory[3]
        };
    }

    for i in 1..r {
        map[i][0].memory[0] = map[i - 1][0].memory[1].max(map[i - 1][0].memory[0]);
        map[i][0].memory[1] = map[i][0].memory[0] + map[i][0].value;
        for j in 1..c {
            map[i][j].memory[0] = if map[i][j - 1].memory[0]
                > map[i - 1][j].memory.iter().fold(0, |a, b| a.max(*b))
            {
                map[i][j - 1].memory[0]
            } else {
                map[i - 1][j].memory.iter().fold(0, |a, b| a.max(*b))
            };
            map[i][j].memory[1] = if map[i][j - 1].memory[0] + map[i][j].value
                > map[i][j - 1].memory[1]
            {
                if map[i][j - 1].memory[0] > map[i - 1][j].memory.iter().fold(0, |a, b| a.max(*b)) {
                    map[i][j - 1].memory[0] + map[i][j].value
                } else {
                    map[i - 1][j].memory.iter().fold(0, |a, b| a.max(*b)) + map[i][j].value
                }
            } else {
                if map[i][j - 1].memory[1]
                    > map[i - 1][j].memory.iter().fold(0, |a, b| a.max(*b)) + map[i][j].value
                {
                    map[i][j - 1].memory[1]
                } else {
                    map[i - 1][j].memory.iter().fold(0, |a, b| a.max(*b)) + map[i][j].value
                }
            };
            map[i][j].memory[2] =
                if map[i][j - 1].memory[1] + map[i][j].value > map[i][j - 1].memory[2] {
                    map[i][j - 1].memory[1] + map[i][j].value
                } else {
                    map[i][j - 1].memory[2]
                };
            map[i][j].memory[3] =
                if map[i][j - 1].memory[2] + map[i][j].value > map[i][j - 1].memory[3] {
                    map[i][j - 1].memory[2] + map[i][j].value
                } else {
                    map[i][j - 1].memory[3]
                };
        }
    }

    println!(
        "{}",
        map[r - 1][c - 1].memory.iter().fold(0, |a, b| a.max(*b))
    );
}


Measured memory_bytes: 361416