Under construction

Still being built. Things may change

Gecko

Interview

Time limit2sMemory limit512 MB

Summary
Pick a top-row tile and move straight down, down-left, or down-right each row to maximize the mosquitoes eaten.
Level

Easy3 of 10

Topics
Dynamic programming, Matrix
Solved
No attempts yet

Problem

During the rainy season one of the walls in the house is covered with mosquitoes. The wall is tiled with h×wh \times w square tiles: hh rows of tiles from top to bottom and ww columns from left to right. Between 11 and 10001000 mosquitoes rest on each tile.

A gecko wants to eat as many mosquitoes as it can under the following rules. It starts by choosing any tile in the top row and eats the mosquitoes on that tile. Then it moves to a tile in the next row down, eats the mosquitoes there, and keeps going the same way until it reaches the floor. When it moves down one row, it may only go straight down, diagonally down to the left, or diagonally down to the right (see Figure 1).

Figure 1 When it moves down one row, the gecko may only go straight down, diagonally down to the left, or diagonally down to the right.

You are given hh, ww, and the number of mosquitoes on every tile. Write a program that computes the largest number of mosquitoes the gecko can eat on one trip from the top of the wall to the bottom.

Input

The first line contains two integers. The first integer hh (1≤h≤5001 \le h \le 500) is the number of tile rows on the wall, and the second integer ww (1≤w≤5001 \le w \le 500) is the number of tile columns.

Then hh lines follow. The ii-th line gives the number of mosquitoes on each tile of the ii-th row from the top. Each line holds ww integers separated by a single space, and each integer mm (1≤m≤10001 \le m \le 1000) is the number of mosquitoes on that tile.

Output

Print a single integer, the largest number of mosquitoes the gecko can eat on one trip from the top of the wall to the bottom.

Examples1

  1. Example 1

    Input
    6 5
    3 1 7 4 2
    2 1 3 1 1
    1 2 2 1 8
    2 2 1 5 3
    2 1 4 4 4
    5 7 2 5 1
    
    Expected output
    32