Python, dp solution with explanation
Intuition
the first child only has one path, becuase path length is n-1.
range of activity of the second child is in upper traigle (i < j)
range of activity of
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->
1. the first child only has one path, becuase path length is n-1.
2. range of activity of the second child is in upper traigle (i < j)
3. range of activity of the third child is in lower traigle (i > j)
4. paths of the second and third childs will not intersect.

# Approach
<!-- Describe your approach to solving the problem. -->
use dp to find max score when the second child reach (n-2, n-1) and max score when the third child reach (n-1, n-2).
For the second child and position (i, j), dp_1[i][j] is max score when the second child reach this position.
dp_1[i][j] = max(dp_1[i-1][j] + x, dp_1[i-1][j-1] + x, dp_1[i-1][j+1] + x)
we should care about if the child can reach dp_1[i-1][j], dp_1[i-1][j-1] and dp_1[i-1][j+1], if not, value becomes -1.

the third child is similar to the second.


# Complexity
- Time complexity:
<!-- Add your time complexity here, e.g. $$O(n)$$ -->
O(n^2)
- Space complexity:
<!-- Add your space complexity here, e.g. $$O(n)$$ -->
O(n)
# Code
```python3 []

class Solution:
    def maxCollectedFruits(self, fruits: List[List[int]]) -> int:
        n = len(fruits)
        def dp_1():
            dp_0 = [-1] * n
            dp_0[n-1] = fruits[0][n-1]
            dp_1 = [-1] * n
            for i in range(1, n-1):
                for j in range(i+1, n):
                    x = fruits[i][j]
                    dp_1[j] = max(
                        (dp_0[j-1] + x) if dp_0[j-1] >= 0 else -1, 
                        (dp_0[j] + x) if dp_0[j] >= 0 else -1, 
                        (dp_0[j+1] + x) if j+1 < n and dp_0[j+1] >= 0 else -1
                    )
                dp_0, dp_1 = dp_1, dp_0
            return dp_0[n-1]
        def dp_2():
            dp_0 = [-1] * n
            dp_0[n-1] = fruits[n-1][0]
            dp_1 = [-1] * n
            for j in range(1, n-1):
                for i in range(j+1, n):
                    x = fruits[i][j]
                    dp_1[i] = max(
                        (dp_0[i-1] + x) if dp_0[i-1] >= 0 else -1, 
                        (dp_0[i] + x) if dp_0[i] >= 0 else -1, 
                        (dp_0[i+1] + x) if i+1 < n and dp_0[i+1] >= 0 else -1
                    )
                dp_0, dp_1 = dp_1, dp_0
            return dp_0[n-1]
        return sum(fruits[i][i] for i in range(n)) + dp_1() + dp_2()

        
```
['Dynamic Programming', 'Python3']