#![allow(non_snake_case, unused_imports, unused_must_use)] use std::io::{self, prelude::*}; use std::str; fn main() { let (stdin, stdout) = (io::stdin(), io::stdout()); let mut scan = Scanner::new(stdin.lock()); let mut out = io::BufWriter::new(stdout.lock()); macro_rules! input { ($T: ty) => { scan.token::<$T>() }; ($T: ty, $N: expr) => { (0..$N).map(|_| scan.token::<$T>()).collect::>() }; } let H = input!(usize); let W = input!(usize); let A = (0..H).map(|_| input!(usize, W)).collect::>(); let mut ans = 0; // цик for i in 0..H + 2 { for j in i + 1..H + 2 { let mut seen = vec![vec![false; W]; H]; if i == 0 { let mut ny = 0; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } ny += 1; nx += 1; } } else if 0 < i && i < H + 1 { let mut ny = i - 1; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } nx += 1; } } else { let mut ny = H - 1; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } if ny == 0 { break; } ny -= 1; nx += 1; } } if j == 0 { let mut ny = 0; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } ny += 1; nx += 1; } } else if 0 < j && j < H + 1 { let mut ny = j - 1; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } nx += 1; } } else { let mut ny = H - 1; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } if ny == 0 { break; } ny -= 1; nx += 1; } } let mut score = 0; for i in 0..H { for j in 0..W { if seen[i][j] { score += A[i][j]; } } } ans = std::cmp::max(ans, score); } } for i in 0..W + 2 { for j in i + 1..W + 2 { let mut seen = vec![vec![false; W]; H]; if i == 0 { let mut ny = 0; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } ny += 1; nx += 1; } } else if 0 < i && i < W + 1 { let mut ny = 0; let mut nx = i - 1; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } ny += 1; } } else { let mut ny = 0; let mut nx = W - 1; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } if nx == 0 { break; } ny += 1; nx -= 1; } } if j == 0 { let mut ny = 0; let mut nx = 0; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } ny += 1; nx += 1; } } else if 0 < j && j < W + 1 { let mut ny = 0; let mut nx = j - 1; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } ny += 1; } } else { let mut ny = 0; let mut nx = W - 1; loop { if ny < H && nx < W { seen[ny][nx] = true; } else { break; } if nx == 0 { break; } ny += 1; nx -= 1; } } let mut score = 0; for i in 0..H { for j in 0..W { if seen[i][j] { score += A[i][j]; } } } ans = std::cmp::max(ans, score); } } writeln!(out, "{}", ans); } struct Scanner { reader: R, buf_str: Vec, buf_iter: str::SplitWhitespace<'static>, } impl Scanner { fn new(reader: R) -> Self { Self { reader, buf_str: vec![], buf_iter: "".split_whitespace(), } } fn token(&mut self) -> T { loop { if let Some(token) = self.buf_iter.next() { return token.parse().ok().expect("Failed parse"); } self.buf_str.clear(); self.reader .read_until(b'\n', &mut self.buf_str) .expect("Failed read"); self.buf_iter = unsafe { let slice = str::from_utf8_unchecked(&self.buf_str); std::mem::transmute(slice.split_whitespace()) } } } }