Two tetrominoes

Place two non-overlapping tetrominoes anywhere on an N by M grid so the total of the covered cells is maximized.

Hard8Brute forceDynamic programmingImplementationNo attempts yetTime limit2sMemory limit512 MB

Problem

A polyomino is a shape built by joining several squares of size 1×11 \times 1, and it satisfies all of the following conditions.

  • The squares do not overlap.
  • The whole shape is connected.
  • Squares are joined along their edges. Two squares that meet only at a corner do not count as joined.

A polyomino made of four squares is called a tetromino, and there are five of them.

The five tetrominoes

Areum wants to place two tetrominoes on a sheet of paper of size N×MN \times M. The two tetrominoes must not overlap. The paper is divided into cells of size 1×11 \times 1, and each cell holds one integer.

When a tetromino is placed, each of its squares must cover exactly one cell, and the tetromino may be rotated or reflected.

Write a program that places two tetrominoes so that the sum of the numbers in the covered cells is as large as possible.

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 given number is a natural number no greater than 1,000.

Output

On the first line, print the maximum sum of the numbers in the cells covered by the two tetrominoes.