 favorite We need a little bit of your help to keep things running, click on this banner to learn more
Problems

# Maximum Sum with number of ways

There is a rectangular grid of size n rows and m columns. Each cell of the grid contains one integer. You can start the route from any cell of the top row. Each time you can move to one of the "lower neighbouring" cells (in other words, from the cell number (i, j) its possible to go either to (i + 1, j - 1), or to (i + 1, j) or to (i + 1, j + 1); in the case j = m the last of the three options becomes impossible, in the case j = 1 the first option becomes impossible). And you can finish the route at any cell of the bottom row.

Write a program that finds the maximum possible sum of the values on the cells traversed among all the possible paths and the number of paths in which this amount is reached.

#### Input

The first line contains numbers n and m (1n, m200) - the number of rows and columns. Each of the next n lines contains m integers (each number is no more than 106 by absolute value) - the values of the cells in the grid.

It is known that the required number of paths with maximum sum does not exceed 109.

#### Output

Print two numbers - the maximum possible sum and the number of paths.

#### Explanation

In the first test the maximum value 42 can be obtained only in one way: 15 + 9 + 9 + 9). In the second test the maximum value 111 can be obtained in three ways: a = 100, a = 1, a = 10, or a = 100, a = 10, a = 1, or a = 100, a = 10, a = 1.

Time limit 2 seconds
Memory limit 128 MiB
Input example #1
4 3
1 15 2
9 7 5
9 2 4
6 9 -1

Output example #1
42 1

Input example #2
3 3
1 1 100
1 1 10
10 1 1

Output example #2
111 3

Author Ilya Porublev
Source 2013 Sevastopol Summer School, Wave 1, Day 2