using
System;
using
System.Collections.Generic;
class
Program
{
static
List<
int
> FindPathsAndMaxAdventure(List<List<
int
>> maze)
{
const
int
MOD = 1000000007;
int
n = maze.Count;
List<List<
int
>> paths =
new
List<List<
int
>>();
List<List<
int
>> adventure =
new
List<List<
int
>>();
for
(
int
i = 0; i < n + 5; i++)
{
paths.Add(
new
List<
int
>(
new
int
[n + 5]));
adventure.Add(
new
List<
int
>(
new
int
[n + 5]));
}
paths[n - 1][n - 1] = 0;
adventure[n - 1][n - 1] = maze[n - 1][n - 1];
for
(
int
i = n - 1; i >= 0; i--)
{
for
(
int
j = n - 1; j >= 0; j--)
{
if
(i == n - 1 && j == i)
{
paths[i][j] = 1;
continue
;
}
if
(maze[i][j] == 1)
{
paths[i][j] = paths[i][j + 1];
if
(paths[i][j] > 0)
{
adventure[i][j] = maze[i][j] + adventure[i][1 + j];
}
}
else
if
(maze[i][j] == 3)
{
paths[i][j] = (paths[i + 1][j] + paths[i][j + 1]) % MOD;
if
(paths[i][j] != 0)
{
adventure[i][j] = maze[i][j] + Math.Max(adventure[i + 1][j], adventure[i][j + 1]);
}
}
else
if
(maze[i][j] == 2)
{
paths[i][j] = paths[i + 1][j];
if
(paths[i][j] > 0)
{
adventure[i][j] = maze[i][j] + adventure[i + 1][j];
}
}
}
}
return
new
List<
int
> { paths[0][0], adventure[0][0] };
}
static
void
Main()
{
List<List<
int
>> maze =
new
List<List<
int
>> {
new
List<
int
> { 1, 1, 3, 2, 1 },
new
List<
int
> { 3, 2, 2, 1, 2 },
new
List<
int
> { 1, 3, 3, 1, 3 },
new
List<
int
> { 1, 2, 3, 1, 2 },
new
List<
int
> { 1, 1, 1, 3, 1 }
};
List<
int
> result = FindPathsAndMaxAdventure(maze);
Console.WriteLine(result[0] +
" "
+ result[1]);
}
}