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

#PS0000218. Đồng cỏ của cô bò lười (The Lazy Cow (Silver))

HỌC THEO LỘ TRÌNH

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

1 lộ trình

Đồng cỏ của cô bò lười (The Lazy Cow (Silver))

The Lazy Cow (Silver)

Source: USACO

Version: Phuoc Hung OJ Extended

Problem Statement

A field is an N×NN\times N grid with grass amounts Gr,cG_{r,c}. Bessie chooses a starting cell inside the grid. A step moves to a side-adjacent cell. Find the maximum total grass in cells reachable within KK steps from the chosen start, counting each cell once, including the start. This is a Manhattan-distance region, not a single walk.

Input

The first line contains N,KN,K. The following NN lines each contain NN integers Gr,cG_{r,c}.

Output

Print the maximum total grass.

Subtasks

  • Subtask 1 (20 points): 1≤N≤121\le N\le 12; 0≤K≤2N0\le K\le 2N; 0≤Gr,c≤10000\le G_{r,c}\le1000.
  • Subtask 2 (30 points): 1≤N≤4001\le N\le 400; 0≤K≤2N0\le K\le 2N; 0≤Gr,c≤10000\le G_{r,c}\le1000; K=0K=0.
  • Subtask 3 (50 points): 1≤N≤4001\le N\le 400; 0≤K≤2N0\le K\le 2N; 0≤Gr,c≤10000\le G_{r,c}\le1000.

Example 1

Input

5 2
50 5 25 6 17
14 3 2 7 21
99 10 1 2 80
8 7 5 23 11
10 0 78 1 9

Output

342

Explanation

Start at (3,3). The row contributions are 25, 12, 192, 35 and 78.

Example 2

Input

2 0
1 9
4 3

Output

9

Explanation

No movement is allowed; choose cell (1,2).