Maximum Sum with number of ways#5855

Maximum Sum with number of ways

2 seconds
128 megabytes
Easy

There is a rectangular grid of size rows and columns. Each cell of the grid contains one integer.

You can start your route from any cell in the top row. At each step, you can move to one of the "lower neighboring" cells (that is, from cell , you may move to (i + 1, j - 1), (i + 1, j), or (i + 1, j + 1); if j = m, the last move becomes impossible; if j = 1, the first move becomes impossible). You may finish your route in any cell of the bottom row.

Write a program that finds the maximum possible sum of the values of the cells along any valid path, as well as the number of such paths that attain this sum.

Input

The first line contains two integers and (1 \le n, m \le 200) — the number of rows and columns in the grid.

Each of the next lines contains exactly integers, each no greater than 10^6 in absolute value — the values of the grid's cells.

It is guaranteed that the required number of paths with the maximal sum does not exceed 10^9.

Output

Print two integers: the maximal possible sum and the number of such paths.

Examples

\begin{example}\exmp{4 115999}{42 1}%\exmp{3 31 1 1001 1 1010 1 1}{111 3}%\end{example}

Example 1

Loading
Loading

Example 2

Loading
Loading

Note

In the first test, the maximal sum can be obtained in only one way: 15 + 9 + 9 + 9.

In the second test, the maximal sum can be obtained in three ways:

  • a_{1,3} = 100, a_{2,2} = 1, a_{3,1} = 10;

  • a_{1,3} = 100, a_{2,3} = 10, a_{3,2} = 1;

  • a_{1,3} = 100, a_{2,3} = 10, a_{3,3} = 1.