Tetromino

Given an N x M grid of positive integers, place one of the 5 tetrominoes (with rotations and reflections) to maximize the sum of covered cells.

Medium5Brute forceImplementationArraySimulationInterviewNo attempts yetTime limit2sMemory limit512 MB

Problem

A polyomino is a shape made by joining several 1×11 \times 1 squares. It must satisfy the following conditions.

  • The squares must not overlap.
  • The whole shape must be connected.
  • Squares must be joined edge to edge. Two squares that touch only at a corner are not connected.

A polyomino made of 4 squares is called a tetromino. There are 5 tetrominoes, shown below.

Areum wants to place one tetromino on a sheet of paper of size N×MN \times M. The paper is divided into 1×11 \times 1 cells, and each cell has one integer written on it.

Write a program that places one tetromino so that the sum of the numbers in the cells it covers is as large as possible.

Each square of the tetromino must cover exactly one cell. You may rotate or reflect the tetromino.

Input

The first line contains the height NN and the width MM of the paper. (4N,M5004 \le N, M \le 500)

Each of the next NN lines contains the numbers written on the paper. The jj-th number on the ii-th line is the number in the cell that is ii-th from the top and jj-th from the left. Every number in the input is a positive integer not exceeding 1,000.

Output

Print, on the first line, the maximum sum of the numbers in the cells covered by the tetromino.