<p>You are given an <code>n x n</code><code>grid</code> representing a field of cherries, each cell is one of three possible integers.</p>
<ul>
<li><code>0</code> means the cell is empty, so you can pass through,</li>
<li><code>1</code> means the cell contains a cherry that you can pick up and pass through, or</li>
<li><code>-1</code> means the cell contains a thorn that blocks your way.</li>
</ul>
<p>Return <em>the maximum number of cherries you can collect by following the rules below</em>:</p>
<ul>
<li>Starting at the position <code>(0, 0)</code> and reaching <code>(n - 1, n - 1)</code> by moving right or down through valid path cells (cells with value <code>0</code> or <code>1</code>).</li>
<li>After reaching <code>(n - 1, n - 1)</code>, returning to <code>(0, 0)</code> by moving left or up through valid path cells.</li>
<li>When passing through a path cell containing a cherry, you pick it up, and the cell becomes an empty cell <code>0</code>.</li>
<li>If there is no valid path between <code>(0, 0)</code> and <code>(n - 1, n - 1)</code>, then no cherries can be collected.</li>