PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#PS0000216. Tổng dấu X lớn nhất (X-Sum)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Tổng dấu X lớn nhất (X-Sum)

X-Sum

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

A rectangular chessboard has mm rows and nn columns, each cell containing a nonnegative integer. Place one bishop on any cell. It attacks every cell on the two diagonals through that cell, continuing to the board boundary in all four directions. The occupied cell counts once. Find the maximum possible sum of attacked cells.

Input

The first line contains two integers m,nm,n. Each of the next mm lines contains exactly nn integers. Each input file describes one board.

Output

Print the maximum attainable sum.

Subtasks

  • Subtask 1 (20 points): 1≤m,n≤121\le m,n\le 12; 0≤ai,j≤10000000\le a_{i,j}\le 1000000.
  • Subtask 2 (30 points): 1≤m,n≤2001\le m,n\le 200; 0≤ai,j≤10000000\le a_{i,j}\le 1000000; m=1m=1.
  • Subtask 3 (50 points): 1≤m,n≤2001\le m,n\le 200; 0≤ai,j≤10000000\le a_{i,j}\le 1000000.

Example 1

Input

4 4
1 2 2 1
2 4 2 4
2 2 3 1
2 4 2 4

Output

20

Explanation

At row 3, column 3, the two diagonal sums are 12 and 11, and the center is 3. The total is 20.

Example 2

Input

2 1
1
0

Output

1

Explanation

Each placement attacks only its own cell because there is one column.

Example 3

Input

3 3
1 1 1
1 1 1
1 1 1

Output

5

Explanation

The center attacks the four corners and itself.

Example 4

Input

3 3
0 1 1
1 0 1
1 1 0

Output

3

Explanation

Row 2, column 1 gives sum 3, and no placement gives more.