<p>You are given a square <code>board</code>&nbsp;of characters. You can move on the board starting at the bottom right square marked with the character&nbsp;<code>&#39;S&#39;</code>.</p>

<p>You need&nbsp;to reach the top left square marked with the character <code>&#39;E&#39;</code>. The rest of the squares are labeled either with a numeric character&nbsp;<code>1, 2, ..., 9</code> or with an obstacle <code>&#39;X&#39;</code>. In one move you can go up, left or up-left (diagonally) only if there is no obstacle there.</p>

<p>Return a list of two integers: the first integer is the maximum sum of numeric characters you can collect, and the second is the number of such paths that you can take to get that maximum sum, <strong>taken modulo <code>10^9 + 7</code></strong>.</p>

<p>In case there is no path, return&nbsp;<code>[0, 0]</code>.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>
<pre><strong>Input:</strong> board = ["E23","2X2","12S"]
<strong>Output:</strong> [7,1]
</pre><p><strong class="example">Example 2:</strong></p>
<pre><strong>Input:</strong> board = ["E12","1X1","21S"]
<strong>Output:</strong> [4,2]
</pre><p><strong class="example">Example 3:</strong></p>
<pre><strong>Input:</strong> board = ["E11","XXX","11S"]
<strong>Output:</strong> [0,0]
</pre>
<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
	<li><code>2 &lt;= board.length == board[i].length &lt;= 100</code></li>
</ul>
class Solution:
    def pathsWithMaxScore(self, board):
        def inBounds(i, j):
            return 0 <= i < len(board) and 0 <= j < len(board)

        def get(c):
            return int(c) if c != 'S' else 0

        def isValid(i, j):
            return inBounds(i, j) and board[i][j] != 'X'

        def helper(i, j):
            if board[i][j] == 'E':
                return 0, 1
            if board[i][j] == 'X':
                return 0, 0

            if (i, j) in memo:
                return memo[(i, j)]

            s1, count1, s2, count2, s3, count3 = 0, 0, 0, 0, 0, 0
            c = board[i][j]

            if isValid(i - 1, j):  # go left
                s1, count1 = helper(i - 1, j)
                if count1 > 0:
                    s1 += get(c)

            if isValid(i, j - 1):  # go up
                s2, count2 = helper(i, j - 1)
                if count2 > 0:
                    s2 += get(c)

            if isValid(i - 1, j - 1):  # go up-left
                s3, count3 = helper(i - 1, j - 1)
                if count3 > 0:
                    s3 += get(c)

            if s1 == s2 and s2 == s3:
                s, count = s1, count1 + count2 + count3
            elif s1 == s2:
                s, count = max((s1, (count1 + count2)), (s3, count3))
            elif s2 == s3:
                s, count = max((s2, (count2 + count3)), (s1, count1))
            else:
                s, count = max((s1, count1), (s2, count2), (s3, count3))

            memo[(i, j)] = s, count % mod
            return memo[(i, j)]

        memo = {}
        mod = 10 ** 9 + 7
        return helper(len(board) - 1, len(board) - 1)
28300